castle-web-cli 0.4.232 → 0.4.233

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 (355) hide show
  1. package/dist/agent-failures.d.ts +8 -0
  2. package/dist/agent-failures.js +19 -2
  3. package/dist/agent-prompts.d.ts +1 -1
  4. package/dist/agent-prompts.js +10 -3
  5. package/dist/agent.d.ts +64 -3
  6. package/dist/agent.js +170 -81
  7. package/dist/castle-host/host.d.ts +1 -0
  8. package/dist/castle-host/host.js +51 -3
  9. package/dist/castleJson.d.ts +4 -2
  10. package/dist/castleJson.js +2 -0
  11. package/dist/check.d.ts +3 -1
  12. package/dist/check.js +11 -1
  13. package/dist/devSessionStorage.js +47 -1
  14. package/dist/importPinMismatch.d.ts +22 -0
  15. package/dist/importPinMismatch.js +77 -0
  16. package/dist/importRegression.js +3 -15
  17. package/dist/imports.d.ts +10 -3
  18. package/dist/imports.js +88 -20
  19. package/dist/index.js +5 -4
  20. package/dist/init.js +1 -1
  21. package/dist/platformDoc.js +22 -0
  22. package/dist/routerFences.d.ts +5 -0
  23. package/dist/routerFences.js +12 -2
  24. package/dist/save-deck.d.ts +5 -0
  25. package/dist/save-deck.js +37 -4
  26. package/dist/serve.js +3 -0
  27. package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
  28. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  29. package/dist/shell/index.html +2 -2
  30. package/dist/taskSteer.d.ts +13 -0
  31. package/dist/taskSteer.js +22 -2
  32. package/kits/base/castle.json +1 -1
  33. package/kits/base/package-lock.json +1 -1
  34. package/kits/base/sdk/README.md +79 -2
  35. package/kits/base/sdk/avatar.d.ts +6 -2
  36. package/kits/base/sdk/avatar.js +12 -4
  37. package/kits/base/sdk/castle.d.ts +1 -1
  38. package/kits/base/sdk/commands.d.ts +14 -0
  39. package/kits/base/sdk/hub.d.ts +6 -2
  40. package/kits/base/sdk/hub.js +13 -0
  41. package/kits/base/sdk/multiplayer.js +17 -1
  42. package/kits/base/sdk/save.js +2 -1
  43. package/kits/base/sdk/server/hub.d.ts +87 -0
  44. package/kits/base/sdk/server/hub.js +70 -0
  45. package/kits/base/sdk/server/platformHandle.d.ts +31 -1
  46. package/kits/base/sdk/server/storage.d.ts +13 -0
  47. package/kits/base/sdk/server/storage.js +46 -0
  48. package/kits/base/sdk/server/wrapper.d.ts +36 -5
  49. package/kits/base/sdk/server/wrapper.js +83 -8
  50. package/kits/hub-game/CLAUDE.md +329 -11
  51. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  52. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  53. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  54. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  55. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  56. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  57. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  58. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  59. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  60. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  61. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  62. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  63. package/kits/hub-game/code/client/actorBudget.js +47 -0
  64. package/kits/hub-game/code/client/attention.js +11 -2
  65. package/kits/hub-game/code/client/avatar.js +309 -35
  66. package/kits/hub-game/code/client/avatarCap.js +228 -0
  67. package/kits/hub-game/code/client/avatarColors.js +70 -0
  68. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  69. package/kits/hub-game/code/client/avatarShare.js +251 -0
  70. package/kits/hub-game/code/client/ballot.js +467 -0
  71. package/kits/hub-game/code/client/build.js +22 -0
  72. package/kits/hub-game/code/client/chrome.js +1144 -50
  73. package/kits/hub-game/code/client/companion.js +716 -0
  74. package/kits/hub-game/code/client/companionDress.js +99 -0
  75. package/kits/hub-game/code/client/decor.js +509 -0
  76. package/kits/hub-game/code/client/earned.js +131 -0
  77. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  78. package/kits/hub-game/code/client/grab.js +339 -20
  79. package/kits/hub-game/code/client/hookLayer.js +299 -13
  80. package/kits/hub-game/code/client/idle.js +163 -22
  81. package/kits/hub-game/code/client/interestCap.js +81 -0
  82. package/kits/hub-game/code/client/keys.js +36 -0
  83. package/kits/hub-game/code/client/labelsNear.js +205 -0
  84. package/kits/hub-game/code/client/menuIcons.js +34 -0
  85. package/kits/hub-game/code/client/pack.js +6 -2
  86. package/kits/hub-game/code/client/packFormat.js +3 -3
  87. package/kits/hub-game/code/client/rehello.js +167 -0
  88. package/kits/hub-game/code/client/shot.js +92 -0
  89. package/kits/hub-game/code/client/sound.js +63 -8
  90. package/kits/hub-game/code/client/soundscape.js +1151 -0
  91. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  92. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  93. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  94. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  95. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  96. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  97. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  98. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  99. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  100. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  101. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  102. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  103. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  104. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  105. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  106. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  107. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  108. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  109. package/kits/hub-game/code/client/spin.js +101 -0
  110. package/kits/hub-game/code/client/state.js +109 -1
  111. package/kits/hub-game/code/client/stuck.js +259 -0
  112. package/kits/hub-game/code/client/talk.js +538 -47
  113. package/kits/hub-game/code/client/tiers.js +516 -27
  114. package/kits/hub-game/code/client/toastBand.js +37 -0
  115. package/kits/hub-game/code/client/together.js +32 -0
  116. package/kits/hub-game/code/client/visibility.js +43 -0
  117. package/kits/hub-game/code/client/wear.js +461 -170
  118. package/kits/hub-game/code/client/yours.js +199 -0
  119. package/kits/hub-game/code/companionSpec.js +45 -0
  120. package/kits/hub-game/code/privateText.js +7 -0
  121. package/kits/hub-game/code/server/actions.js +133 -0
  122. package/kits/hub-game/code/server/actors.js +9 -1
  123. package/kits/hub-game/code/server/ask.js +155 -0
  124. package/kits/hub-game/code/server/ballot.js +539 -0
  125. package/kits/hub-game/code/server/cells.js +100 -0
  126. package/kits/hub-game/code/server/companion.js +82 -0
  127. package/kits/hub-game/code/server/cues.js +70 -0
  128. package/kits/hub-game/code/server/decor.js +269 -0
  129. package/kits/hub-game/code/server/earned.js +461 -0
  130. package/kits/hub-game/code/server/friendBests.js +166 -0
  131. package/kits/hub-game/code/server/friendsAmong.js +232 -0
  132. package/kits/hub-game/code/server/history.js +5 -0
  133. package/kits/hub-game/code/server/hub.js +1254 -50
  134. package/kits/hub-game/code/server/idle.js +30 -11
  135. package/kits/hub-game/code/server/index.js +2 -2
  136. package/kits/hub-game/code/server/labels.js +28 -2
  137. package/kits/hub-game/code/server/manifest.js +378 -7
  138. package/kits/hub-game/code/server/menu.js +133 -0
  139. package/kits/hub-game/code/server/npcs.js +830 -80
  140. package/kits/hub-game/code/server/party.js +2 -2
  141. package/kits/hub-game/code/server/players.js +22 -0
  142. package/kits/hub-game/code/server/shot.js +110 -0
  143. package/kits/hub-game/code/server/standing.js +124 -0
  144. package/kits/hub-game/code/server/vis.js +113 -0
  145. package/kits/hub-game/code/server/wear.js +12 -0
  146. package/kits/hub-game/code/server/yours.js +59 -0
  147. package/kits/hub-game/code/shared/cues.js +9 -0
  148. package/kits/hub-game/code/shared/decor.js +41 -0
  149. package/kits/hub-game/code/shared/shot.js +19 -0
  150. package/kits/hub-game/code/shared/spin.js +57 -0
  151. package/kits/hub-game/code/systems/hub.js +845 -95
  152. package/kits/hub-game/docs/content-pack.md +1 -1
  153. package/kits/hub-game/docs/contract.md +2244 -61
  154. package/kits/hub-game/docs/home-pieces.md +64 -0
  155. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  156. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  157. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  158. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  159. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  160. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  161. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  162. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  163. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  164. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  165. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  166. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  167. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  168. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  169. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  170. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  171. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  172. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  173. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  174. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  175. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  176. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  177. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  178. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  179. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  180. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  181. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  182. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  183. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  184. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  185. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  186. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  187. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  188. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  189. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  190. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  191. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  192. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  193. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  194. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  195. package/kits/hub-game/package-lock.json +2 -0
  196. package/kits/hub-game/package.json +2 -1
  197. package/kits/hub-game/scripts/check.mjs +78 -11
  198. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  199. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
  200. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  201. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
  202. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
  203. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  204. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  205. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  206. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  207. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  208. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  209. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  210. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  211. package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
  212. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  213. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  214. package/kits/hub-game/scripts/test-actors.mjs +19 -17
  215. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  216. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  217. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  218. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  219. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  220. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  221. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  222. package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
  223. package/kits/hub-game/scripts/test-avatar.mjs +540 -7
  224. package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
  225. package/kits/hub-game/scripts/test-build.mjs +31 -0
  226. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  227. package/kits/hub-game/scripts/test-chat.mjs +662 -0
  228. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  229. package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
  230. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  231. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  232. package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
  233. package/kits/hub-game/scripts/test-decor.mjs +457 -0
  234. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  235. package/kits/hub-game/scripts/test-earned.mjs +1194 -0
  236. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  237. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  238. package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
  239. package/kits/hub-game/scripts/test-grab.mjs +7 -0
  240. package/kits/hub-game/scripts/test-hats.mjs +422 -168
  241. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  242. package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
  243. package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
  244. package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
  245. package/kits/hub-game/scripts/test-idle.mjs +361 -1
  246. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  247. package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
  248. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  249. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  250. package/kits/hub-game/scripts/test-labels.mjs +596 -0
  251. package/kits/hub-game/scripts/test-manifest.mjs +207 -0
  252. package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
  253. package/kits/hub-game/scripts/test-menu.mjs +296 -0
  254. package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
  255. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  256. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  257. package/kits/hub-game/scripts/test-picker.mjs +314 -0
  258. package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
  259. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  260. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  261. package/kits/hub-game/scripts/test-shot.mjs +756 -0
  262. package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
  263. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  264. package/kits/hub-game/scripts/test-standing.mjs +416 -0
  265. package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
  266. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  267. package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
  268. package/kits/hub-game/scripts/test-tiers.mjs +477 -2
  269. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  270. package/kits/hub-game/scripts/test-try-on.mjs +22 -22
  271. package/kits/hub-game/scripts/test-vis.mjs +343 -0
  272. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  273. package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
  274. package/kits/hub-game/scripts/test-yours.mjs +372 -0
  275. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  276. package/kits/multiplayer-3d/castle.json +5 -5
  277. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  278. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  279. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  280. package/kits/multiplayer-3d/code/options.js +5 -0
  281. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  282. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  283. package/kits/multiplayer-3d/code/server/world.js +7 -0
  284. package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
  285. package/kits/multiplayer-3d/package.json +2 -1
  286. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  287. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  288. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  289. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  290. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  291. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  292. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  293. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  294. package/kits/physics-2d/CLAUDE.md +9 -0
  295. package/kits/physics-2d/castle.json +2 -2
  296. package/kits/physics-2d/engine/scene.js +253 -1
  297. package/kits/physics-2d/engine/skyKey.js +129 -0
  298. package/kits/physics-2d/engine/stillClock.js +106 -0
  299. package/kits/physics-2d/engine/updateBudget.js +21 -0
  300. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
  301. package/kits/physics-3d/CLAUDE.md +1169 -30
  302. package/kits/physics-3d/behaviors/Player.jsx +629 -72
  303. package/kits/physics-3d/castle.json +3 -3
  304. package/kits/physics-3d/docs/pxmodel-format.md +8 -0
  305. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
  306. package/kits/physics-3d/engine3d/actornode.js +86 -0
  307. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  308. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  309. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  310. package/kits/physics-3d/engine3d/framecap.js +96 -0
  311. package/kits/physics-3d/engine3d/gait.js +118 -0
  312. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  313. package/kits/physics-3d/engine3d/look.js +507 -48
  314. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  315. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  316. package/kits/physics-3d/engine3d/motion.js +39 -10
  317. package/kits/physics-3d/engine3d/nearshadows.js +37 -19
  318. package/kits/physics-3d/engine3d/optimize.js +9 -5
  319. package/kits/physics-3d/engine3d/orbitinput.js +487 -9
  320. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  321. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  322. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  323. package/kits/physics-3d/engine3d/shadowfade.js +882 -0
  324. package/kits/physics-3d/engine3d/sky.js +547 -0
  325. package/kits/physics-3d/engine3d/skylife.js +306 -0
  326. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  327. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  328. package/kits/physics-3d/engine3d/world3d.js +796 -69
  329. package/kits/physics-3d/main.jsx +5 -0
  330. package/kits/physics-3d/package.json +1 -1
  331. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  332. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
  333. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  334. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
  335. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  336. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  337. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  338. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  339. package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
  340. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
  341. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
  342. package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
  343. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  344. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  345. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  346. package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
  347. package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
  348. package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
  349. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  350. package/kits/physics-3d/systems/physics3d.js +383 -6
  351. package/kits/real-time/castle.json +2 -2
  352. package/kits/real-time/code/server/gameHooks.js +7 -0
  353. package/kits/real-time/code/server/session.js +97 -19
  354. package/package.json +2 -2
  355. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -0,0 +1,259 @@
1
+ // v1.71 companion: real place hooks, private delivery and public presence.
2
+ import assert from 'node:assert/strict';
3
+ import { register } from 'node:module';
4
+
5
+ register(`data:text/javascript,${encodeURIComponent(`
6
+ import { readFile } from 'node:fs/promises';
7
+ import { fileURLToPath } from 'node:url';
8
+ export async function load(url, context, next) {
9
+ if (url.endsWith('/code/server/hub.js?without-companion')) {
10
+ let source = await readFile(fileURLToPath(url), 'utf8');
11
+ source = source.split('\\n').filter((line) => !line.includes('import * as Companion') && !line.includes('...(' + 'h.place.companion')).join('\\n');
12
+ source = source.replace(/\\s*if \\(h.place.companion === true(?: && h.companionUsed)?\\) \\{[^{}]*\\}(?: else \\{[^{}]*\\})?/g, '');
13
+ if (source.includes('Companion.')) throw new Error('baseline still has a companion code path');
14
+ return { format: 'module', source, shortCircuit: true };
15
+ }
16
+ return next(url, context);
17
+ }
18
+ export async function resolve(specifier, context, next) {
19
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: 'data:text/javascript,export const readScene = () => globalThis.__hubTestActors;', shortCircuit: true };
20
+ if (context.parentURL?.includes('/kits/base/sdk/') && specifier.startsWith('.') && !specifier.endsWith('.js')) return next(specifier + '.js', context);
21
+ return next(specifier, context);
22
+ }
23
+
24
+ `)}`);
25
+ const { layer } = await import('../code/server/hub.js');
26
+ const { layer: baseline } = await import('../code/server/hub.js?without-companion');
27
+ const Manifest = await import('../code/server/manifest.js');
28
+ const actors = [
29
+ { id: 'player', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
30
+ { id: 'floor', components: { Transform: { x: 0, y: 0, z: 0 } } },
31
+ ];
32
+ const players = [
33
+ { playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false },
34
+ { playerId: 'p2', userId: '102', username: 'Bo', isAnonymous: false },
35
+ ];
36
+ const json = (keys = {}) => ({ server: { maxPlayers: 8 }, hub: { contract: 1, title: 'House', ...keys } });
37
+ function boot(keys = {}, options = {}) {
38
+ const sent = [], ops = [], arrivals = [];
39
+ let hub;
40
+ const hooks = { ready(ctx) { hub = ctx; }, arrive(ctx, group) { arrivals.push([ctx.owner ?? null, group.map((p) => p.playerId)]); }, action(ctx, id, actionId) { ops.push([id, actionId]); }, ...(options.hooks ?? {}) };
41
+ const bodies = [];
42
+ const engine = {
43
+ createBody(sim, actor, at) {
44
+ const rb = { at: { ...at }, setEnabled() {}, setNextKinematicTranslation(at) { this.at = { ...at }; }, setNextKinematicRotation() {} };
45
+ bodies.push([actor.id, rb]);
46
+ return rb;
47
+ },
48
+ removeActor(sim, id) { sim.bodies.delete(id); sim.objects.delete(id); },
49
+ };
50
+ globalThis.__hubTestActors = structuredClone(actors);
51
+ const server = (options.layer ?? layer)(json(keys), hooks, {}, () => true, () => null, null, engine);
52
+ const session = { sessionId: options.sessionId ?? 'dev', players: [...players], hub: options.platform ?? null, send(id, msg) { sent.push([id, structuredClone(msg)]); }, broadcast(msg) { sent.push(['all', structuredClone(msg)]); } };
53
+ const world = { timeMs: 0, scenePath: 'scenes/main.scene', objects: new Map(), bodies: new Map(), players: new Map(players.map((p) => [p.playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } }])) };
54
+ server.sceneFor(session);
55
+ server.ready(world);
56
+ const say = (id, data) => server.message(session, { playerId: id }, data);
57
+ if (options.hello !== false) {
58
+ for (const id of options.order ?? ['p1', 'p2']) {
59
+ say(id, { k: 'hub-hello', avatar: 0, party: 2 });
60
+ }
61
+ server.place(world);
62
+ }
63
+ const tick = (ms = 50) => { world.timeMs += ms; server.place(world); server.step(world, []); };
64
+ return { server, session, world, hub, sent, ops, say, tick, bodies, arrivals, hooks };
65
+ }
66
+
67
+ const spec = { look: 'lantern', say: 'Come this way', at: 'unknown-is-fine' };
68
+ const wire = (r) => r.sent.filter(([, msg]) => msg.k === 'hub-companion');
69
+ const offer = (r, playerId = 'p1') => wire(r).findLast(([id]) => id === playerId)?.[1];
70
+ let passed = 0;
71
+ async function test(name, fn) { await fn(); passed += 1; console.log(`ok: ${name}`); }
72
+
73
+ await test('v1.78 dress enums, defaults, validation and private delivery', async () => {
74
+ const { check, DRESS } = await import('../code/companionSpec.js');
75
+ for (const [key, ids] of Object.entries(DRESS)) {
76
+ for (const id of ids) { assert.doesNotThrow(() => check({ look: 'bird', dress: { [key]: id } })); }
77
+ for (const bad of [undefined, null, false, '', 'unknown', 1, [], {}]) {
78
+ assert.throws(() => check({ look: 'bird', dress: { [key]: bad } }), TypeError);
79
+ }
80
+ }
81
+ for (const dress of [{}, { species: 'songbird' }]) { assert.deepEqual(check({ look: 'bird', dress }), { look: 'bird' }); }
82
+ for (const dress of [undefined, null, [], Object.create({ species: 'owl' }), { extra: 'owl' }, { [Symbol()]: 'owl' }]) {
83
+ assert.throws(() => check({ look: 'bird', dress }), TypeError);
84
+ }
85
+ assert.throws(() => check({ look: 'lantern', dress: {} }), TypeError);
86
+ const dress = { species: 'owl', wear: 'bow', tint: 'mint' };
87
+ const r = boot({ companion: true });
88
+ assert.equal(r.hub.companionDress, true);
89
+ assert.equal(r.hub.companionPose, true);
90
+ r.hub.companion('p1', { look: 'bird', dress }); r.tick(250);
91
+ assert.deepEqual(wire(r), [['p1', { k: 'hub-companion', c: { look: 'bird', dress }, n: 1 }]]);
92
+ dress.wear = 'scarf';
93
+ assert.equal(offer(r).c.dress.wear, 'bow');
94
+ for (const state of [r.server.join(), r.server.delta()]) { assert(!JSON.stringify(state).includes('dress')); }
95
+ assert(!Object.hasOwn(boot().hub, 'companionDress'));
96
+ assert(!Object.hasOwn(boot().hub, 'companionPose'));
97
+ });
98
+ await test('v1.78 show pose validates privately and absent pose preserves literal wire bytes', async () => {
99
+ const { check } = await import('../code/companionSpec.js');
100
+ assert.deepEqual(check({ look: 'bird', pose: 'show' }), { look: 'bird', pose: 'show' });
101
+ for (const pose of [undefined, null, false, '', 'quiet', 1, [], {}]) {
102
+ assert.throws(() => check({ look: 'bird', pose }), TypeError);
103
+ }
104
+ assert.throws(() => check({ look: 'lantern', pose: 'show' }), TypeError);
105
+ let reads = 0;
106
+ check({ look: 'bird', get pose() { reads++; return 'show'; } }); assert.equal(reads, 1);
107
+ const r = boot({ companion: true });
108
+ r.hub.companion('p1', { look: 'bird', say: 'Chirp!', at: 'goal' }); r.tick(250);
109
+ assert.equal(JSON.stringify(wire(r)), '[["p1",{"k":"hub-companion","c":{"look":"bird","say":"Chirp!","at":"goal"},"n":1}]]');
110
+ r.hub.companion('p1', { look: 'bird', pose: 'show' }); r.tick(250);
111
+ assert.deepEqual(offer(r).c, { look: 'bird', pose: 'show' });
112
+ for (const state of [r.server.join(), r.server.delta()]) { assert(!JSON.stringify(state).includes('pose')); }
113
+ const count = wire(r).length;
114
+ r.hub.companion('p1', { look: 'bird', pose: 'show' }); r.tick(250);
115
+ assert.equal(wire(r).length, count);
116
+ assert.throws(() => r.hub.companion('p1', { look: 'bird', pose: 'bad' }), TypeError);
117
+ assert.deepEqual(offer(r).c, { look: 'bird', pose: 'show' });
118
+ });
119
+ await test('manifest: place-only true or absent, including explicit undefined', () => {
120
+ for (const named of [false, true]) {
121
+ for (const value of [true, false, null, 0, 1, '', 'true', [], {}, undefined]) {
122
+ const keys = named ? { places: { porch: { title: 'Porch', scene: 'scenes/porch.scene', companion: value } } } : { companion: value };
123
+ const read = Manifest.readManifest(json(keys));
124
+ assert.equal(read.errors.some((e) => e.includes('.companion')), value !== true);
125
+ if (value === true) {
126
+ const place = read.manifest.places[named ? 'porch' : 'main'];
127
+ assert.equal(Manifest.publicPlace('main', place).companion, true);
128
+ if (named) assert(!Object.hasOwn(read.manifest.places.main, 'companion'));
129
+ }
130
+ }
131
+ }
132
+ const place = Manifest.readManifest(json()).manifest.places.main;
133
+ assert(!Object.hasOwn(place, 'companion'));
134
+ assert(!Object.hasOwn(Manifest.publicPlace('main', place), 'companion'));
135
+ });
136
+ await test('eligible in arrive; no API in another place, captured API is gated', () => {
137
+ let took;
138
+ boot({ companion: true }, { hooks: { arrive(ctx, group) { took = ctx.companion(group[0].playerId, spec); } } });
139
+ assert.equal(took, true);
140
+ const r = boot({ companion: true, places: { porch: { title: 'Porch', scene: 'scenes/porch.scene' } } });
141
+ const captured = r.hub.companion;
142
+ r.session.place = 'porch'; r.server.sceneFor(r.session);
143
+ assert(!Object.hasOwn(r.hub, 'companion'));
144
+ assert.throws(() => captured('p1', spec), TypeError);
145
+ const waiting = boot({ companion: true }, { hello: false });
146
+ assert.equal(waiting.hub.companion('p1', spec), false);
147
+ });
148
+ await test('one copied follower per player; every private send targets its owner, public is ids alone', () => {
149
+ const r = boot({ companion: true });
150
+ assert(!Object.hasOwn(r.server.join(), 'hubGlow'));
151
+ r.sent.length = 0;
152
+ const copy = { ...spec };
153
+ r.hub.companion('p1', copy); copy.say = 'mutated';
154
+ r.tick(250);
155
+ assert.deepEqual(wire(r), [['p1', { k: 'hub-companion', c: spec, n: 1 }]]);
156
+ const snapshot = r.server.join();
157
+ assert.deepEqual(snapshot.hubGlow, ['p1']);
158
+ assert(!JSON.stringify(snapshot).includes(spec.say));
159
+ assert(!JSON.stringify(snapshot).includes(spec.at));
160
+ assert(!Object.hasOwn(snapshot, 'companion'));
161
+ assert.deepEqual(r.server.delta().hubGlow, ['p1']);
162
+ r.hub.companion('p1', { look: 'bird' }); r.hub.companion('p2', spec); r.tick(250);
163
+ assert.deepEqual(wire(r).slice(1), [['p1', { k: 'hub-companion', c: { look: 'bird' }, n: 2 }], ['p2', { k: 'hub-companion', c: spec, n: 3 }]]);
164
+ assert.deepEqual(r.server.join().hubGlow, ['p1', 'p2']);
165
+ assert.deepEqual(r.server.delta().hubGlow, ['p1', 'p2']);
166
+ assert.equal(r.server.delta(), null);
167
+ r.hub.companion('p1', null); r.tick(250);
168
+ assert.deepEqual(offer(r), { k: 'hub-companion', c: null, n: 4 });
169
+ assert.deepEqual(r.server.delta().hubGlow, ['p2']);
170
+ r.hub.companion('p2', null); r.tick(250);
171
+ assert.deepEqual(r.server.join().hubGlow, []);
172
+ assert.deepEqual(r.server.delta().hubGlow, []);
173
+ const cleared = offer(r, 'p2'); r.sent.length = 0;
174
+ r.say('p2', { k: 'hub-hello', resume: true });
175
+ assert.deepEqual(wire(r), [['p2', cleared]]);
176
+ assert(wire(r).every(([id]) => id === 'p1' || id === 'p2'));
177
+ });
178
+ await test('public glow sorts ids regardless of insertion order', () => {
179
+ const r = boot({ companion: true });
180
+ r.hub.companion('p2', spec); r.hub.companion('p1', { look: 'bird' });
181
+ assert.deepEqual(r.server.join().hubGlow, ['p1', 'p2']);
182
+ });
183
+ await test('validation table is atomic; own fields read once; code point and control rules', () => {
184
+ const r = boot({ companion: true });
185
+ r.hub.companion('p1', spec); r.tick(250);
186
+ const invalid = [undefined, false, [], {}, 'bird', new Date(), Object.create(spec), { look: 'other' }, { look: 'bird', unknown: true }, Object.defineProperty({ look: 'bird' }, 'extra', { value: true }), { look: 'bird', [Symbol()]: 1 }, { look: 'bird', say: undefined }, { look: 'bird', at: undefined }, ...['', ' ', '\u00a0', 'x'.repeat(81), '😀'.repeat(81), 1, 'a\nline', 'a\u2028line', 'a\u2029line', ...Array.from({ length: 32 }, (_, i) => String.fromCodePoint(i)), ...Array.from({ length: 33 }, (_, i) => String.fromCodePoint(0x7f + i)), ...[0x061c, 0x200b, 0x200c, 0x200d, 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e, 0x2060, 0x2061, 0x2062, 0x2063, 0x2064, 0x2065, 0x2066, 0x2067, 0x2068, 0x2069, 0xfeff].map((cp) => `a${String.fromCodePoint(cp)}b`)].map((say) => ({ look: 'bird', say })), ...['', 'x'.repeat(65), 1, null].map((at) => ({ look: 'bird', at }))];
187
+ for (const bad of invalid) assert.throws(() => r.hub.companion('p1', bad), TypeError);
188
+ r.tick(250); assert.deepEqual(offer(r), { k: 'hub-companion', c: spec, n: 1 });
189
+ assert.throws(() => r.hub.companion(null, spec), TypeError);
190
+ assert.throws(() => r.hub.companion('missing', {}), TypeError);
191
+ assert.equal(r.hub.companion('missing', spec), false);
192
+ const reads = { look: 0, say: 0, at: 0 }, record = {};
193
+ for (const key of Object.keys(reads)) Object.defineProperty(record, key, { get() { reads[key]++; return spec[key]; } });
194
+ r.hub.companion('p1', record);
195
+ assert.deepEqual(reads, { look: 1, say: 1, at: 1 });
196
+ r.hub.companion('p1', Object.assign(Object.create(null), { look: 'bird', say: '😀'.repeat(80), at: 'x'.repeat(64) }));
197
+ r.tick(250); assert.equal(offer(r).c.say, '😀'.repeat(80)); assert.equal(offer(r).n, 2);
198
+ });
199
+ await test('equal specs send nothing; newest wins, at most four tick sends/s per player', () => {
200
+ const r = boot({ companion: true }); r.sent.length = 0;
201
+ for (let i = 0; i < 10000; i++) r.hub.companion('p1', { look: i % 2 ? 'bird' : 'lantern' });
202
+ assert.deepEqual(wire(r), []); r.tick(250);
203
+ assert.deepEqual(offer(r), { k: 'hub-companion', c: { look: 'bird' }, n: 10000 });
204
+ r.hub.companion('p1', { look: 'bird' }); r.tick(250); assert.equal(wire(r).length, 1);
205
+ r.hub.companion('p1', { look: 'lantern' }); r.hub.companion('p1', { look: 'bird' }); r.tick(250); assert.equal(wire(r).length, 1);
206
+ const times = [], original = r.session.send;
207
+ r.session.send = (id, msg) => { if (msg.k === 'hub-companion') times.push([id, r.world.timeMs]); original(id, msg); };
208
+ for (let i = 0; i < 100; i++) { r.hub.companion('p1', { look: 'bird', say: String(i) }); r.hub.companion('p2', { look: 'lantern', say: String(i) }); r.tick(10); }
209
+ for (const id of ['p1', 'p2']) {
210
+ const own = times.filter(([target]) => target === id).map(([, t]) => t);
211
+ assert.equal(own.length, 4); assert(own.slice(1).every((t, i) => t - own[i] >= 250));
212
+ }
213
+ assert.equal(offer(r).c.say, '75');
214
+ });
215
+ await test('fresh hello replays; avatar hello does not; leave and absent pruning forget and remove glow', () => {
216
+ const r = boot({ companion: true }); r.hub.companion('p1', spec); r.tick(250);
217
+ r.server.delta(); r.sent.length = 0;
218
+ r.say('p1', { k: 'hub-hello', resume: true }); r.tick(250);
219
+ assert.deepEqual(wire(r), [['p1', { k: 'hub-companion', c: spec, n: 1 }]]);
220
+ r.sent.length = 0; r.say('p1', { k: 'hub-hello', again: true }); assert.deepEqual(wire(r), []);
221
+ const body = r.world.players.get('p1');
222
+ r.session.players = [players[1]]; r.world.players.delete('p1'); r.tick();
223
+ assert.deepEqual(r.server.delta().hubGlow, []);
224
+ assert.equal(r.hub.companion('p1', spec), false);
225
+ r.session.players.push(players[0]); r.world.players.set('p1', body); r.sent.length = 0;
226
+ r.say('p1', { k: 'hub-hello', resume: true }); r.tick();
227
+ assert.deepEqual(wire(r), []);
228
+ r.hub.companion('p1', spec); r.tick(250); assert.equal(offer(r).n, 2);
229
+ r.sent.length = 0; r.session.players = [players[1]]; r.tick(250);
230
+ assert.deepEqual(wire(r), []);
231
+ assert.deepEqual(r.server.join().hubGlow, []);
232
+ });
233
+ await test('keyless trace is byte-identical to a session with all companion branches removed', () => {
234
+ const trace = (implementation) => {
235
+ const r = boot({}, { layer: implementation }), snapshots = [];
236
+ assert(!Object.hasOwn(r.hub, 'companion'));
237
+ const take = () => { snapshots.push(JSON.stringify(r.server.join()), JSON.stringify(r.server.delta())); r.tick(250); };
238
+ take(); r.say('p1', { k: 'hub-hello', resume: true }); take();
239
+ r.say('p1', { k: 'hub-companion', c: spec, n: 1 }); take();
240
+ r.hub.wear('p2', { kind: 'halo', color: '#ffffff', rarity: 1 }); take();
241
+ r.session.players = [players[1]]; r.world.players.delete('p1'); take();
242
+ assert.deepEqual(wire(r), []);
243
+ assert(snapshots.every((s) => !s.includes('hubGlow') && !s.includes('companion')));
244
+ return JSON.stringify({ sent: r.sent, snapshots });
245
+ };
246
+ const now = Date.now; Date.now = () => 100000;
247
+ try { assert.equal(trace(layer), trace(baseline)); } finally { Date.now = now; }
248
+ });
249
+ console.log(`${passed} companion tests passed`);
250
+
251
+ await test('an ended visit drops the follower: nothing of it is replayed on a later hello', () => {
252
+ const r = boot({ companion: true });
253
+ r.hub.companion('p1', spec); r.tick(250);
254
+ r.hub.end(['p1']); r.tick(250);
255
+ r.sent.length = 0;
256
+ r.say('p1', { k: 'hub-hello', resume: true }); r.tick(250);
257
+ assert.deepEqual(wire(r).filter(([, m]) => m.k === 'hub-companion'), []);
258
+ assert.deepEqual(r.server.delta().hubGlow ?? [], []);
259
+ });
@@ -0,0 +1,303 @@
1
+ // v1.67 private chrome, real three.js grid/ghost geometry and touch/mouse
2
+ // handlers. Keyless chrome calls were captured from 18e9a2fb. The offscreen
3
+ // renderer and DOM are stand-ins; no browser needed.
4
+ import assert from 'node:assert/strict';
5
+ import fs from 'node:fs';
6
+ import { setMaxListeners } from 'node:events';
7
+ import { register } from 'node:module';
8
+ import * as THREE from 'three';
9
+
10
+ register(`data:text/javascript,${encodeURIComponent(`
11
+ import { readFile } from 'node:fs/promises';
12
+ import { fileURLToPath } from 'node:url';
13
+ export async function resolve(specifier, context, next) {
14
+ if (['pxmodel', 'optimize', 'look', 'lookbake'].some((m) => specifier === '@imports/castle.physics-3d/engine3d/' + m)) return { url: ${JSON.stringify(new URL('./fixtures/engine-models-stub.mjs', import.meta.url).href)}, shortCircuit: true };
15
+ if (specifier === '@imports/castle.physics-3d/engine3d/orbitlens.js') return { url: ${JSON.stringify(new URL('../../physics-3d/engine3d/orbitlens.js', import.meta.url).href)}, shortCircuit: true };
16
+ if (specifier === 'castle-web-sdk') return { url: 'data:text/javascript,export {};', shortCircuit: true };
17
+ if (specifier === '@imports/castle.multiplayer-3d/code/client/avatars.js') return { url: 'data:text/javascript,export const dropMissing = () => {};', shortCircuit: true };
18
+ if (specifier.startsWith('@imports/castle.physics-2d/engine/')) return { url: 'data:text/javascript,export const initialMedia = {}; export const playMedia = () => {}; export const stopMedia = () => {};', shortCircuit: true };
19
+ if (specifier === '../client/pack.js') return { url: 'data:text/javascript,export const cachedPacks = () => []; export const loadPack = () => {}; export const matchesOwn = () => false; export const resolveDeckDoor = () => {};', shortCircuit: true };
20
+ return next(specifier, context);
21
+ }
22
+ export async function load(url, context, next) {
23
+ if (url.endsWith('/code/client/hookLayer.js')) {
24
+ const source = await readFile(fileURLToPath(url), 'utf8');
25
+ return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
26
+ }
27
+ return next(url, context);
28
+ }
29
+ `)}`);
30
+ const State = await import('../code/client/state.js');
31
+ const { makeDecor } = await import('../code/client/decor.js');
32
+ const hook = (await import('../code/client/hookLayer.js')).default;
33
+ const { makeIdle } = await import('../code/client/idle.js');
34
+ const { installSystem } = await import('../code/systems/hub.js');
35
+ const Avatar = await import('../code/client/avatar.js');
36
+
37
+ function fakeDom(w = 360, h = 780) {
38
+ function node(tag) {
39
+ const n = { tag, style: {}, children: [], attrs: {}, handlers: {}, textContent: '', disabled: false,
40
+ appendChild(child) { child.parent = this; this.children.push(child); return child; },
41
+ replaceChildren(...children) { this.children = []; children.forEach((child) => this.appendChild(child)); },
42
+ addEventListener(name, fn, options) { this.handlers[name] = fn; if (options?.signal) { setMaxListeners(0, options.signal); options.signal.addEventListener('abort', () => { delete this.handlers[name]; }, { once: true }); } },
43
+ setAttribute(name, value) { this.attrs[name] = String(value); },
44
+ setPointerCapture(id) { this.captured = id; },
45
+ getBoundingClientRect() { return this.style.borderRadius === '18px 18px 0 0' ? { left: 0, top: h - 164, right: w, bottom: h, width: w, height: 164 } : { left: 0, top: 0, right: w, bottom: h, width: w, height: h }; },
46
+ get offsetHeight() { return 54; },
47
+ remove() { if (this.parent) this.parent.children = this.parent.children.filter((c) => c !== this); },
48
+ click() { let at = this; while (at && !at.handlers.click && !at.disabled) at = at.parent; if (at && !at.disabled) at.handlers.click?.({ stopPropagation() {} }); },
49
+ };
50
+ return n;
51
+ }
52
+ const body = node('body');
53
+ globalThis.document = { createElement: node, body };
54
+ globalThis.window = { innerWidth: w, innerHeight: h };
55
+ return { body, w, h };
56
+ }
57
+ function walk(node) {
58
+ return [node, ...node.children.flatMap(walk)];
59
+ }
60
+ const grid = { x: 0, y: 0, z: 0, w: 8, d: 7, cell: 1 };
61
+ function specification() {
62
+ return { title: 'Only you can change your house', tabs: [{ id: 'furniture', label: 'Furniture' }, { id: 'walls', label: 'Walls' }], items: [
63
+ { id: 'chair', tab: 'furniture', label: 'Chair', template: 'chair-template', w: 2, d: 1, layer: 'floor', count: 2 },
64
+ { id: 'sofa', tab: 'furniture', label: 'Sofa', template: 'sofa-template', w: 2, d: 1, layer: 'floor', count: 1, locked: { price: '120 ▲' } },
65
+ { id: 'pot', tab: 'furniture', label: 'Pot', template: 'pot-template', w: 1, d: 1, layer: 'floor', count: 0 },
66
+ ], placed: [{ key: 'copy', item: 'chair', x: 1, z: 1, rot: 0, layer: 'floor' }], swatches: [{ id: 'sage', tab: 'walls', label: 'Sage', color: '#779977' }] };
67
+ }
68
+ function rig(w = 360, h = 780) {
69
+ State.clear();
70
+ const dom = fakeDom(w, h), sent = [], calls = [];
71
+ const camera = new THREE.PerspectiveCamera(50, w / h, 0.1, 1000);
72
+ camera.position.set(11, 13, 12); camera.lookAt(4, 0, 3.5); camera.updateMatrixWorld(true);
73
+ const world = { scene: new THREE.Scene(), camera, nodes: new Map(), models: new Map(), instances: new Map() };
74
+ const objects = new Map();
75
+ for (const [id, width, at] of [['chair-template', 2, [-20, -20, 0]], ['sofa-template', 2, [-20, -20, 2]], ['pot-template', 1, [-20, -20, 4]], ['copy', 2, [2, 0.25, 1.5]]]) {
76
+ const node = new THREE.Group();
77
+ node.add(new THREE.Mesh(new THREE.BoxGeometry(width, 0.5, 1), new THREE.MeshStandardMaterial({ color: '#c07f55' })));
78
+ node.position.set(...at);
79
+ node.updateMatrixWorld(true);
80
+ world.scene.add(node); world.nodes.set(id, { node });
81
+ objects.set(id, { id, components: { Transform: { x: at[0], y: at[1], z: at[2] }, Shape: { kind: 'box', width, height: 0.5, depth: 1 } } });
82
+ }
83
+ const local = { id: 'player', components: { Transform: { x: 4, y: 1, z: 4 } } };
84
+ const scene = { three: world, sceneKey: 'house', currentScenePath: 'scenes/main.scene', getActor(id) { return objects.get(id); }, actorWith() { return local; }, getActors: () => [...objects.values()] };
85
+ const mp = { net: { send(op) { sent.push(op); }, selfId: () => 'p1' }, joinState: () => 'joined' };
86
+ const chrome = { decorRoot: () => dom.body, setDecorating(on) { calls.push(['decorating', on]); } };
87
+ let made = 0, rendered = 0, disposed = 0, lost = 0;
88
+ const ui = makeDecor(chrome, { renderer() {
89
+ made += 1;
90
+ return { setPixelRatio() {}, setSize() {}, setClearColor() {}, render(scene, cam) { rendered += 1; assert.ok(scene.children.some((n) => n.isGroup)); assert.ok(cam.isOrthographicCamera); }, domElement: { toDataURL: () => `data:image/png;base64,thumb${rendered}` }, dispose() { disposed += 1; }, forceContextLoss() { lost += 1; } };
91
+ } });
92
+ const root = dom.body.children[0], worldInput = root.children[2];
93
+ State.hub.place = { decor: { grid: { origin: 'floor', w: 8, d: 7, cell: 1 }, layers: ['rug', 'floor'] } };
94
+ const receive = (spec = specification()) => hook.message({}, { k: 'hub-decor', button: 'Decorate', spec, ...(spec ? { grid } : {}) });
95
+ const frame = (can = true) => { world.scene.updateMatrixWorld(true); ui.frame(scene, mp, local, can); };
96
+ const find = (text) => walk(root).find((n) => n.textContent === text);
97
+ const tile = (label) => walk(root).find((n) => n.attrs['aria-label']?.startsWith(`${label} ·`));
98
+ const pointer = (type, x, z, pointerId = 1, pointerType = 'mouse') => {
99
+ const p = new THREE.Vector3(x, 0, z).project(camera);
100
+ worldInput.handlers[type]({ clientX: (p.x + 1) * w / 2, clientY: (1 - p.y) * h / 2, pointerId, pointerType, button: 0, preventDefault() {}, stopPropagation() {} });
101
+ };
102
+ return { dom, chrome, ui, root, worldInput, scene, mp, local, sent, calls, world, objects, receive, frame, find, tile, pointer, counts: () => ({ made, rendered, disposed, lost }) };
103
+ }
104
+ let passed = 0;
105
+ function test(name, fn) { fn(); passed += 1; console.log(`ok: ${name}`); }
106
+
107
+ function keylessDrawing(travel = null) {
108
+ const previous = travel ? rig() : null;
109
+ if (previous) { previous.receive(); previous.frame(); previous.tile('Chair').click(); previous.frame(); }
110
+ State.clear();
111
+ if (!previous) { fakeDom(); }
112
+ Object.defineProperty(globalThis, 'performance', { configurable: true, value: { now: () => 1000 } });
113
+ const calls = [];
114
+ let system;
115
+ installSystem({ registerSystem(s) { system = s; } });
116
+ const chrome = new Proxy({ peopleOpen: () => false, chatFocused: () => false }, { get(target, name) { return target[name] ?? ((...args) => calls.push([name, ...args])); } });
117
+ system.chrome = chrome;
118
+ if (previous) { previous.chrome.setDecorating = (on) => calls.push(['decorating', on]); }
119
+ system.talk = { frame() {}, talking: () => false, typing: () => false, talkingWith: () => null };
120
+ system.idle = { frame(...args) { calls.push(['idle', args[3]]); }, draw() {}, labels: () => [] };
121
+ system.grab = { frame(...args) { calls.push(['grab', args[3]]); } };
122
+ system.sound = { frame(...args) { calls.push(['sound', args[2]]); } };
123
+ system.sayHooked = true;
124
+ system.together.frame = () => {};
125
+ const skip = ['keepResident', 'wearAvatar', 'applyTune', 'watchSession', 'sayHello', 'followPlace', 'holdFall', 'turnSpinners', 'applySpawns', 'applyTints', 'registerInterest', 'applyVisibility', 'applyWear', 'adoptLate', 'runCommands', 'askFriends', 'stepEnd', 'faceArrival', 'measure'];
126
+ for (const method of skip) { system[method] = () => {}; }
127
+ system.sceneKey = 'keyless';
128
+ if (previous) { system.decor = previous.ui; }
129
+ const scene = { sceneKey: 'keyless', currentScenePath: 'scenes/main.scene', multiplayer: {}, actorWith: () => null, persistent: { hubTickets: [], hubAvatar: 0 }, getActors: () => [] };
130
+ State.hub.place = { id: 'main', title: 'Town', scene: 'scenes/main.scene', result: null };
131
+ State.hub.hud = { title: 'Town', text: 'Welcome' };
132
+ if (previous && travel === 'reset') { system.reset(null); }
133
+ system.afterBehaviors(scene, 0.05);
134
+ assert.equal(system.decor, previous ? null : undefined);
135
+ if (previous) {
136
+ assert.equal(previous.counts().disposed, 1);assert.equal(previous.counts().lost, 1);
137
+ assert.equal(previous.world.scene.children.length, 4);
138
+ assert(walk(previous.root).every((node) => Object.keys(node.handlers).length === 0), 'listeners removed');
139
+ assert.deepEqual(calls[0], ['decorating', false], 'teardown restores the shared chrome');
140
+ calls.length = 0;system.afterBehaviors(scene, 0.05);
141
+ assert(!calls.some(([name]) => name === 'decorating'), 'later keyless frames never call decor chrome');
142
+ }
143
+ assert.equal(domNodeCount(), 0, 'keyless frame creates no decor DOM');
144
+ return JSON.parse(JSON.stringify(calls, (key, value) => typeof value === 'function' ? value.name : value));
145
+ }
146
+ function domNodeCount() { return document.body.children.length; }
147
+ const fixture = new URL('./fixtures/decor-keyless-draw.json', import.meta.url);
148
+ test('keyless frame: every chrome and input call matches the pre-v1.67 drawing trace', () => {
149
+ const expected = JSON.parse(fs.readFileSync(fixture, 'utf8')), actual = keylessDrawing();
150
+ assert.deepEqual(actual, expected); assert.equal(JSON.stringify(actual), JSON.stringify(expected));
151
+ });
152
+ test('decor travel and reset to keyless dispose every resource and restore the pre-change trace', () => {
153
+ const expected = JSON.parse(fs.readFileSync(fixture, 'utf8'));
154
+ for (const transition of ['travel', 'reset']) {
155
+ const actual = keylessDrawing(transition);assert.deepEqual(actual, expected);
156
+ assert.equal(JSON.stringify(actual), JSON.stringify(expected));
157
+ }
158
+ });
159
+ test('stand-in hello omits colours without opt-in and sends them with opt-in', () => {
160
+ let system;
161
+ installSystem({ registerSystem(s) { system = s; } });
162
+ const scene = { persistent: { hubAvatar: 9, hubAvatarColor: 3 } };
163
+ const sent = [];
164
+ const net = { send: (msg) => sent.push(msg) };
165
+ Avatar.resetPlatformForTests(null);
166
+ Avatar.load(scene);
167
+ try {
168
+ for (const avatarColors of [undefined, false]) {
169
+ if (avatarColors === undefined) { delete State.deck.avatarColors; }
170
+ else { State.deck.avatarColors = avatarColors; }
171
+ system.sendHello(scene, {}, net, 9);
172
+ assert.deepEqual(sent.at(-1), { k: 'hub-hello', avatar: 9, from: null, party: 1, carry: null });
173
+ }
174
+ State.deck.avatarColors = true;
175
+ system.sendHello(scene, {}, net, 9);
176
+ assert.equal(sent.at(-1).color, 3);
177
+ } finally {
178
+ delete State.deck.avatarColors;
179
+ Avatar.resetPlatformForTests(null);
180
+ }
181
+ });
182
+
183
+ test('button only creates no preview or thumbnail renderer and sends a private button op', () => {
184
+ const r = rig(); r.receive(null); r.frame();
185
+ assert.equal(r.ui.opened(), false);
186
+ assert.equal(r.world.scene.children.length, 4);
187
+ assert.deepEqual(r.counts(), { made: 0, rendered: 0, disposed: 0, lost: 0 });
188
+ r.find('Decorate').click(); assert.deepEqual(r.sent, [{ k: 'decor', op: 'button' }]); r.ui.dispose();
189
+ });
190
+ test('phone and desktop trays: thumbnail cache, count chips, exhausted/locked stock and labels', () => {
191
+ for (const width of [360, 412, 1100]) {
192
+ const r = rig(width); r.receive(); r.frame();
193
+ assert.equal(r.ui.opened(), true);
194
+ assert.ok(r.find('Decorating')); assert.ok(r.find('Only you can change your house'));
195
+ assert.ok(r.find('×2')); assert.equal(r.find('×0'), undefined); assert.equal(r.find('×1'), undefined); assert.ok(r.find('🔒')); assert.ok(r.find('120 ▲'));
196
+ assert.equal(r.tile('Sofa').disabled, true); assert.equal(r.tile('Pot').disabled, true);
197
+ r.tile('Pot').click(); r.tile('Sofa').click();
198
+ assert.equal(r.find('Cancel'), undefined); assert.deepEqual(r.sent, []);
199
+ assert.equal(r.counts().rendered, 1);
200
+ r.frame(); r.frame(); assert.equal(r.counts().rendered, 3);
201
+ r.frame(); r.find('Walls').click(); r.frame(); r.find('Furniture').click(); r.frame();
202
+ assert.equal(r.counts().rendered, 3, 'returning to a tab uses cached thumbnails');
203
+ assert.equal(r.world.scene.children.length, 5, 'one grid group only');
204
+ r.ui.dispose(); assert.equal(r.counts().disposed, 1); assert.equal(r.counts().lost, 1);
205
+ }
206
+ });
207
+ test('thumbnail cache waits for look baking and refreshes rebuilt templates, one render per frame', () => {
208
+ const r = rig(); r.world.bakesLookLater = true; r.world.lookBake = { shown: false };
209
+ r.receive(); r.frame(); assert.equal(r.counts().rendered, 0);
210
+ r.world.lookBake.shown = true; r.frame(); r.frame(); r.frame(); assert.equal(r.counts().rendered, 3);
211
+ r.world.nodes.get('chair-template').sig = 'new'; r.world.nodes.get('sofa-template').sig = 'new';
212
+ r.frame(); assert.equal(r.counts().rendered, 4);
213
+ r.frame(); assert.equal(r.counts().rendered, 5);
214
+ r.frame(); assert.equal(r.counts().rendered, 5); r.ui.dispose();
215
+ });
216
+ test('picking new stock finds a free cell near the player, rotates and sends place without changing actors', () => {
217
+ const r = rig(); r.receive(); r.frame();
218
+ const original = structuredClone(r.objects.get('copy'));
219
+ r.tile('Chair').click(); r.frame(); r.find('⟳ Rotate').click(); r.frame(); r.find('✓').click();
220
+ assert.deepEqual(r.sent.at(-1), { k: 'decor', op: 'place', item: 'chair', x: 4, z: 4, rot: 1 });
221
+ assert.deepEqual(r.objects.get('copy'), original);
222
+ assert.equal(r.world.nodes.get('copy').node.visible, true);
223
+ r.receive(); r.frame(); assert.equal(r.world.scene.children.length, 5, 'server state clears the ghost');
224
+ r.ui.dispose();
225
+ });
226
+ test('mouse/touch lift and drag use placed key, rotate, and ask move/stash; original draw is restored', () => {
227
+ for (const pointerId of [1, 17]) {
228
+ const r = rig(412); r.receive(); r.frame();
229
+ const source = r.world.nodes.get('copy').node;
230
+ r.pointer('pointerdown', 1.5, 1.5, pointerId); r.frame();
231
+ assert.equal(source.visible, false); assert.equal(r.worldInput.captured, pointerId);
232
+ assert.equal(source.children[0].material.opacity, 1, 'ghost has separate materials');
233
+ r.pointer('pointermove', 4.5, 4.5, pointerId); r.pointer('pointerup', 4.5, 4.5, pointerId);
234
+ r.frame(); r.find('⟳ Rotate').click(); r.frame(); r.find('✓').click();
235
+ assert.deepEqual(r.sent.at(-1), { k: 'decor', op: 'move', key: 'copy', x: 4, z: 4, rot: 1 });
236
+ r.find('Put away').click(); assert.deepEqual(r.sent.at(-1), { k: 'decor', op: 'stash', key: 'copy' });
237
+ r.receive({ ...specification(), placed: [] }); r.frame(); assert.equal(source.visible, true);
238
+ assert.deepEqual(source.position.toArray(), [2, 0.25, 1.5]); r.ui.dispose();
239
+ }
240
+ });
241
+ test('touch taps lift placed pieces; empty floor without a lift does nothing', () => {
242
+ const r = rig(412); r.receive(); r.frame();
243
+ const source = r.world.nodes.get('copy').node;
244
+ r.pointer('pointerdown', 6.5, 5.5, 17, 'touch');
245
+ r.pointer('pointerup', 6.5, 5.5, 17, 'touch'); r.frame();
246
+ assert.equal(source.visible, true); assert.equal(r.world.scene.children.length, 5);
247
+ assert.equal(r.find('Put away').parent.style.display, 'none'); assert.deepEqual(r.sent, []);
248
+ r.pointer('pointerdown', 1.5, 1.5, 18, 'touch');
249
+ r.pointer('pointerup', 1.5, 1.5, 18, 'touch'); r.frame();
250
+ assert.equal(source.visible, false); assert.equal(r.find('Cancel'), undefined);
251
+ assert.equal(r.find('Put away').parent.style.display, 'flex');
252
+ r.find('Put away').click(); assert.deepEqual(r.sent, [{ k: 'decor', op: 'stash', key: 'copy' }]);
253
+ r.ui.dispose();
254
+ });
255
+ test('overlap/outside previews are red and cannot confirm; valid cells are green', () => {
256
+ const r = rig(); r.receive(); r.frame(); r.tile('Chair').click();
257
+ r.pointer('pointerdown', 1.5, 1.5); r.frame();
258
+ const highlight = r.world.scene.children.find((n) => n.isGroup && n.children.some((c) => c.isLineSegments)).children.find((n) => n.isMesh);
259
+ assert.equal(highlight.material.color.getHexString(), 'ef6471'); assert.equal(r.find('✓').disabled, true);
260
+ r.find('✓').click(); assert.deepEqual(r.sent, []);
261
+ r.pointer('pointerdown', 8.5, 7.5); r.frame(); assert.equal(r.find('✓').disabled, true);
262
+ r.pointer('pointerdown', 4.5, 4.5); r.frame(); assert.equal(highlight.material.color.getHexString(), '59df8b');
263
+ assert.equal(r.find('✓').disabled, false); r.find('Cancel').click(); r.frame(); assert.equal(r.world.scene.children.length, 5);
264
+ r.ui.dispose();
265
+ });
266
+ test('swatch and Done are ids/close only; scene, disconnect and disposal clear all preview resources', () => {
267
+ const r = rig(); r.receive(); r.frame(); r.find('Walls').click(); r.find('Sage').click();
268
+ assert.deepEqual(r.sent.at(-1), { k: 'decor', op: 'swatch', swatch: 'sage' });
269
+ r.find('Done ✓').click(); assert.deepEqual(r.sent.at(-1), { k: 'decor', op: 'close' });
270
+ r.find('Furniture').click(); r.tile('Chair').click(); r.frame();
271
+ r.mp.joinState = () => 'disconnected'; r.frame();
272
+ assert.equal(r.ui.opened(), false); assert.equal(Object.hasOwn(State.hub, 'decor'), false); assert.equal(r.world.scene.children.length, 4);
273
+ r.mp.joinState = () => 'joined'; r.receive(); r.frame(); r.tile('Chair').click(); r.frame();
274
+ r.ui.clear(); assert.equal(r.world.scene.children.length, 4); assert.equal(r.root.style.display, 'none');
275
+ r.ui.dispose(); assert.equal(r.dom.body.children.length, 0);
276
+ });
277
+ test('private state arriving before snapshot survives decor snapshots and clears on keyless snapshots/session clear', () => {
278
+ State.clear(); hook.message({}, { k: 'hub-decor', button: 'Decorate', spec: null });
279
+ hook.state({}, { hubPlace: { id: 'main', decor: {} } }); assert.equal(State.hub.decor.button, 'Decorate');
280
+ hook.state({}, { hubPlace: { id: 'main' } }); assert.equal(Object.hasOwn(State.hub, 'decor'), false);
281
+ hook.message({}, { k: 'hub-decor', button: 'Decorate', spec: null }); State.clear(); assert.equal(Object.hasOwn(State.hub, 'decor'), false);
282
+ });
283
+ test('client offers newly spawned kinematic seats in decor places without rebuilding the scene', () => {
284
+ for (const enabled of [false, true]) {
285
+ for (const pose of [undefined, 'sit', 'lie']) {
286
+ State.clear();
287
+ State.hub.place = { idle: { emotes: false, seats: true, sounds: [] }, ...(enabled ? { decor: {} } : {}) };
288
+ State.hub.hidden.add('template');
289
+ const actors = [{ id: 'template', components: { HubSeat: { ...(pose ? { pose } : {}) }, Transform: { x: 0, y: 0.25, z: 0 }, Shape: { kind: 'box', width: 1, depth: 1 } } }];
290
+ let sit, prompt;
291
+ const idle = makeIdle({ onSit(fn) { sit = fn; }, onEmote() {}, sitPrompt(label) { prompt = label; } });
292
+ const sent = [], local = { components: { Transform: { x: 0, y: 1, z: 0 } } };
293
+ const scene = { getActors: () => actors, getActor: (id) => actors.find((a) => a.id === id) };
294
+ const mp = { net: { selfId: () => 'guest', send(op) { sent.push(op); } } };
295
+ idle.frame(scene, mp, local, true, 'house'); assert.equal(prompt, null);
296
+ actors.push({ id: 'copy', components: { ...actors[0].components, Body: { type: 'kinematic' } } }); State.hub.spawned = { copy: { from: 'template' } };
297
+ idle.frame(scene, mp, local, true, 'house'); assert.equal(prompt, enabled ? (pose === 'lie' ? 'Lie down' : 'Sit') : null);
298
+ sit(); idle.frame(scene, mp, local, true, 'house'); assert.deepEqual(sent, enabled ? [{ k: 'hub-sit', seat: 'copy' }] : []);
299
+ idle.dispose();
300
+ }
301
+ }
302
+ });
303
+ State.clear(); console.log(`test-decor-client: ${passed} passed`);