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,488 @@
1
+ // v1.74 private action state, phone chrome, taps and reconnect cleanup.
2
+ import assert from 'node:assert/strict';
3
+ import { setMaxListeners } from 'node:events';
4
+ import { register } from 'node:module';
5
+
6
+ register(`data:text/javascript,${encodeURIComponent(`
7
+ import { readFile } from 'node:fs/promises';
8
+ import { fileURLToPath } from 'node:url';
9
+ export async function resolve(specifier, context, next) {
10
+ 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 };
11
+ 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 };
12
+ if (specifier === 'castle-web-sdk') return { url: 'data:text/javascript,export {};', shortCircuit: true };
13
+ if (specifier === '@imports/castle.multiplayer-3d/code/client/avatars.js') return { url: 'data:text/javascript,export const dropMissing = () => {};', shortCircuit: true };
14
+ if (specifier.startsWith('@imports/castle.physics-2d/engine/')) return { url: 'data:text/javascript,export const initialMedia = {}; export const playMedia = () => {}; export const stopMedia = () => {};', shortCircuit: true };
15
+ 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 };
16
+ return next(specifier, context);
17
+ }
18
+ export async function load(url, context, next) {
19
+ if (url.endsWith('/code/client/hookLayer.js')) {
20
+ const source = await readFile(fileURLToPath(url), 'utf8');
21
+ return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
22
+ }
23
+ return next(url, context);
24
+ }
25
+ `)}`);
26
+ const State = await import('../code/client/state.js');
27
+ const hook = (await import('../code/client/hookLayer.js')).default;
28
+ const { installSystem } = await import('../code/systems/hub.js');
29
+ const { makeChrome } = await import('../code/client/chrome.js');
30
+ function fakeDom(view) {
31
+ const log = [];
32
+ let ids = 0;
33
+ const made = [];
34
+ const chipSize = (chip, maxWidth) => {
35
+ const width = Math.min(chip.textContent.length * 7 + 40, maxWidth);
36
+ const lines = Math.ceil(chip.textContent.length * 7 / Math.max(1, width - 40));
37
+ return { width, height: 44 + Math.max(0, lines - 1) * 20 };
38
+ };
39
+ function node(tag) {
40
+ const id = `${tag}#${(ids += 1)}`;
41
+ const styles = {};
42
+ let text = '';
43
+ const self = {
44
+ id,
45
+ tag,
46
+ children: [],
47
+ parent: null,
48
+ dataset: {},
49
+ attrs: {},
50
+ rect: null,
51
+ size: null,
52
+ style: new Proxy(styles, {
53
+ get: (target, key) => target[key] ?? '',
54
+ set(target, key, value) {
55
+ target[key] = String(value);
56
+ log.push(`${id} style.${String(key)}=${value}`);
57
+ return true;
58
+ },
59
+ }),
60
+ styles,
61
+ get textContent() {
62
+ return text;
63
+ },
64
+ set textContent(value) {
65
+ text = String(value);
66
+ log.push(`${id} text=${text}`);
67
+ },
68
+ appendChild(child) {
69
+ child.parent = self;
70
+ self.children.push(child);
71
+ log.push(`${id} +${child.id}`);
72
+ return child;
73
+ },
74
+ append(...kids) {
75
+ kids.forEach((kid) => self.appendChild(kid));
76
+ },
77
+ insertBefore(child, before) {
78
+ if (child.parent) {
79
+ child.parent.children = child.parent.children.filter((c) => c !== child);
80
+ }
81
+ child.parent = self;
82
+ const at = self.children.indexOf(before);
83
+ self.children.splice(at < 0 ? self.children.length : at, 0, child);
84
+ return child;
85
+ },
86
+ remove() {
87
+ if (self.parent) {
88
+ self.parent.children = self.parent.children.filter((c) => c !== self);
89
+ log.push(`${id} removed`);
90
+ }
91
+ },
92
+ replaceChildren(...kids) {
93
+ self.children = [];
94
+ log.push(`${id} emptied`);
95
+ kids.forEach((kid) => self.appendChild(kid));
96
+ },
97
+ handlers: {},
98
+ addEventListener(type, fn, options) {
99
+ self.handlers[type] = fn;
100
+ if (options?.signal) {
101
+ setMaxListeners(0, options.signal);
102
+ options.signal.addEventListener('abort', () => { delete self.handlers[type]; }, { once: true });
103
+ }
104
+ },
105
+ removeEventListener() {},
106
+ setAttribute(key, value) {
107
+ self.attrs[key] = String(value);
108
+ },
109
+ getAttribute: (key) => self.attrs[key] ?? null,
110
+ focus() { document.activeElement = self; },
111
+ blur() { if (document.activeElement === self) document.activeElement = null; },
112
+ // A stand-in layout: 7 px a character and 20 of padding, one 24 px line.
113
+ get offsetWidth() {
114
+ log.push(`${id} read`);
115
+ return (typeof self.size === 'function' ? self.size(self) : self.size)?.w ?? text.length * 7 + 20;
116
+ },
117
+ get offsetHeight() {
118
+ log.push(`${id} read`);
119
+ return (typeof self.size === 'function' ? self.size(self) : self.size)?.h ?? 24;
120
+ },
121
+ get offsetLeft() {
122
+ return parseFloat(styles.left) || 0;
123
+ },
124
+ get clientWidth() {
125
+ return self.client ?? self.offsetWidth;
126
+ },
127
+ get scrollWidth() {
128
+ return self.scroll ?? self.offsetWidth;
129
+ },
130
+ getBoundingClientRect() {
131
+ let r = self.rect ?? { left: 0, right: 0, top: 0, bottom: 0 };
132
+ if (styles.flexDirection === 'column-reverse') {
133
+ const sizes = self.children.filter((child) => child.style.display !== 'none').map((child) => chipSize(child, parseFloat(styles.maxWidth) || view.viewW - 24));
134
+ const height = sizes.reduce((sum, size) => sum + size.height, 0) + Math.max(0, sizes.length - 1) * 6;
135
+ const width = Math.max(0, ...sizes.map((size) => size.width));
136
+ const bottom = styles.bottom.startsWith('max') ? 132 : parseFloat(styles.bottom);
137
+ const right = view.viewW - parseFloat(styles.right);
138
+ r = { left: right - width, right, top: view.viewH - bottom - height, bottom: view.viewH - bottom };
139
+ } else if (self.parent?.style.flexDirection === 'column-reverse') {
140
+ const stack = self.parent.getBoundingClientRect();
141
+ const maxWidth = parseFloat(self.parent.style.maxWidth) || view.viewW - 24;
142
+ const size = chipSize(self, maxWidth);
143
+ let bottom = stack.bottom;
144
+ for (const child of self.parent.children) {
145
+ if (child === self) break;
146
+ if (child.style.display !== 'none') bottom -= chipSize(child, maxWidth).height + 6;
147
+ }
148
+ r = { left: stack.right - size.width, right: stack.right, top: bottom - size.height, bottom };
149
+ }
150
+ return { ...r, width: r.right - r.left, height: r.bottom - r.top };
151
+ },
152
+ };
153
+ made.push(self);
154
+ return self;
155
+ }
156
+ const body = node('body');
157
+ globalThis.document = { body, createElement: node, activeElement: null };
158
+ globalThis.window = { innerWidth: view.viewW, innerHeight: view.viewH };
159
+ globalThis.innerWidth = view.viewW;
160
+ return { log, body, made };
161
+ }
162
+ const items = [{ id: 'start', label: 'Start' }, { id: 'sit', label: 'Sit' }, { id: 'watch', label: 'Watch' }];
163
+ const find = (dom, text) => dom.made.findLast((node) => node.textContent === text);
164
+ const tap = (node) => node.handlers.click?.({ stopPropagation() {} });
165
+ let passed = 0;
166
+ function test(name, fn) { fn(); passed += 1; console.log(`ok: ${name}`); }
167
+ function rig(width = 360, height = 780) {
168
+ const dom = fakeDom({ viewW: width, viewH: height }), sent = [];
169
+ const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
170
+ return { dom, chrome, sent, draw: (value = items, can = true, n = 1) => chrome.setActions(value, (id, n) => sent.push({ k: 'hub-action', id, n }), can, n) };
171
+ }
172
+
173
+ test('private messages may precede WORLD; known keyless place ignores and clears them', () => {
174
+ State.clear();
175
+ assert(!Object.hasOwn(State.hub, 'actions'));
176
+ hook.message({}, { k: 'hub-actions', items, n: 1 }); assert.deepEqual(State.hub.actions, { items, n: 1 });
177
+ hook.state({}, { hubPlace: { id: 'main', actions: true } }); assert.deepEqual(State.hub.actions, { items, n: 1 });
178
+ hook.message({}, { k: 'hub-actions', items: null, n: 1 }); assert.deepEqual(State.hub.actions, { items: null, n: 1 });
179
+ hook.message({}, { k: 'hub-actions', items, n: 1 });
180
+ hook.state({}, { hubPlace: { id: 'plain' } }); assert(!Object.hasOwn(State.hub, 'actions'));
181
+ hook.message({}, { k: 'hub-actions', items, n: 1 }); assert(!Object.hasOwn(State.hub, 'actions'));
182
+ State.clear();
183
+ });
184
+ test('chrome is lazy, labels are text, phone targets stack upward and taps echo id and offer version', () => {
185
+ for (const width of [360, 412, 1100]) {
186
+ const r = rig(width), n = r.dom.made.length;
187
+ r.draw(null); assert.equal(r.dom.made.length, n);
188
+ r.draw();
189
+ const buttons = items.map((item) => find(r.dom, item.label));
190
+ assert.equal(buttons[0].parent.style.flexDirection, 'column-reverse');
191
+ for (const node of buttons) {
192
+ assert.equal(node.style.minHeight, '44px');
193
+ assert.equal(node.style.touchAction, 'manipulation');
194
+ tap(node);
195
+ }
196
+ assert.deepEqual(r.sent, items.map(({ id }) => ({ k: 'hub-action', id, n: 1 })));
197
+ const made = r.dom.made.length; r.draw(); assert.equal(r.dom.made.length, made);
198
+ r.draw([{ id: 'literal', label: '<b>Go</b>' }]); assert.equal(find(r.dom, '<b>Go</b>').innerHTML, undefined);
199
+ r.chrome.dispose();
200
+ }
201
+ });
202
+ test('chips clear old listeners on replacement, null, keyless travel and disposal', () => {
203
+ const r = rig(); r.draw(); const old = find(r.dom, 'Start');
204
+ r.draw([{ id: 'new', label: 'New' }]); tap(old); assert.deepEqual(r.sent, []);
205
+ const current = find(r.dom, 'New'); r.draw(null); tap(current); assert.deepEqual(r.sent, []);
206
+ assert(!r.dom.body.children[0].children.includes(current.parent));
207
+ r.draw(); const gone = find(r.dom, 'Start'); r.chrome.clearActions(); tap(gone); assert.deepEqual(r.sent, []);
208
+ r.draw(); const disposed = find(r.dom, 'Start'); r.chrome.dispose(); tap(disposed); assert.deepEqual(r.sent, []);
209
+ });
210
+ test('chips sit above all right-hand chrome; short views use the fallback', () => {
211
+ const r = rig();
212
+ r.chrome.showPicker(true, 0); r.chrome.grabPrompt('Grab'); r.chrome.setEmotes([['wave', '👋']]); r.chrome.setSay({ reactions: [], phrases: [] });
213
+ // Existing controls in a 360 px phone viewport, including a safe-area inset.
214
+ find(r.dom, 'Character').parent.rect = { left: 240, right: 350, top: 706, bottom: 770 };
215
+ find(r.dom, 'Grab').rect = { left: 270, right: 346, top: 624, bottom: 700 };
216
+ const emote = r.dom.made.find((node) => node.attrs['aria-label'] === 'Emote');
217
+ emote.rect = { left: 288, right: 340, top: 550, bottom: 602 };
218
+ const speech = r.dom.made.find((node) => node.style.borderRadius === '26px' && node !== emote && node.tag === 'button');
219
+ assert(speech); speech.rect = { left: 288, right: 340, top: 490, bottom: 542 };
220
+ r.draw();
221
+ const box = find(r.dom, 'Start').parent.getBoundingClientRect();
222
+ assert(box.bottom <= 490 - 12); assert(box.bottom <= 780 - 132);
223
+ r.draw(items, false); assert.equal(find(r.dom, 'Start').parent.style.display, 'none');
224
+ r.draw(); assert.equal(find(r.dom, 'Start').parent.style.display, 'flex');
225
+ emote.handlers.pointerdown({ stopPropagation() {}, preventDefault() {} }); r.draw(); assert.equal(find(r.dom, 'Start').parent.style.display, 'none');
226
+ r.chrome.dispose();
227
+ const short = rig(780, 220); short.draw(); assert.equal(find(short.dom, 'Start').parent.style.display, 'flex'); short.chrome.dispose();
228
+ });
229
+ test('a top-right sound button is an upper bound, never something to stack above', () => {
230
+ const r = rig(360, 780);
231
+ r.chrome.soundControl(true, { volume: 0.5, muted: false });
232
+ const sound = r.dom.made.find((node) => node.dataset.hub === 'sound');
233
+ sound.rect = { left: 308, right: 348, top: 12, bottom: 52 };
234
+ r.chrome.showPicker(true, 0); r.chrome.grabPrompt('Grab');
235
+ find(r.dom, 'Character').parent.rect = { left: 240, right: 350, top: 706, bottom: 770 };
236
+ const grab = find(r.dom, 'Grab'); grab.rect = { left: 270, right: 346, top: 624, bottom: 700 };
237
+ r.draw();
238
+ const stack = find(r.dom, 'Start').parent;
239
+ assert.equal(stack.style.display, 'flex');
240
+ assert(stack.getBoundingClientRect().top >= sound.rect.bottom + 12);
241
+ assert(stack.getBoundingClientRect().bottom <= grab.rect.top - 12);
242
+ // Grab is still a lower bound in the top half; the chips move beside it.
243
+ grab.rect = { left: 270, right: 346, top: 80, bottom: 156 }; r.draw();
244
+ assert.equal(stack.style.display, 'flex');
245
+ assert(stack.getBoundingClientRect().right <= grab.rect.left);
246
+ r.chrome.dispose();
247
+ });
248
+ function phoneRig(height = 475) {
249
+ const r = rig(360, height), shift = height - 475;
250
+ r.chrome.showPicker(true, 0);
251
+ r.chrome.setEmotes([['wave', '👋']]);
252
+ r.chrome.setSay({ reactions: [], phrases: [] });
253
+ r.chrome.setDoors([{ id: 'town', title: 'Town' }]);
254
+ r.chrome.soundControl(true, { volume: 0.5, muted: false });
255
+ const controls = [
256
+ [find(r.dom, 'Character').parent, 246, 427 + shift, 96, 38],
257
+ [r.dom.made.find((node) => node.attrs['aria-label'] === 'Emote'), 280, 276 + shift, 52, 52],
258
+ [r.dom.made.find((node) => node.attrs['aria-label'] === 'Quick chat'), 280, 216 + shift, 52, 52],
259
+ [find(r.dom, 'Doors'), 10, 427 + shift, 70, 38],
260
+ [r.dom.made.find((node) => node.dataset.hub === 'sound'), 300, 12, 40, 40],
261
+ ];
262
+ for (const [node, x, y, w, h] of controls) node.rect = { left: x, right: x + w, top: y, bottom: y + h };
263
+ find(r.dom, 'Doors').parent.rect = find(r.dom, 'Doors').rect;
264
+ r.controls = controls.map(([node]) => node);
265
+ return r;
266
+ }
267
+ function assertClearChips(r, offered) {
268
+ const stack = find(r.dom, offered[0].label).parent;
269
+ assert.equal(stack.style.display, 'flex');
270
+ const shown = offered.map(({ label }) => find(r.dom, label)).filter((node) => node.style.display !== 'none');
271
+ assert(shown.includes(find(r.dom, offered[0].label)), 'first offer remains shown');
272
+ for (const chip of shown) {
273
+ const box = chip.getBoundingClientRect();
274
+ assert(box.left >= 12 && box.right <= window.innerWidth - 12 && box.top >= 12 && box.bottom <= window.innerHeight - 12, 'chip stays inside view margins');
275
+ for (const node of r.controls) {
276
+ const control = node.getBoundingClientRect();
277
+ assert(!(box.left < control.right && box.right > control.left && box.top < control.bottom && box.bottom > control.top), `chip overlaps ${node.textContent || node.id}`);
278
+ }
279
+ }
280
+ return shown;
281
+ }
282
+ const carrot = [{ id: 'pick', label: 'Pick Carrot' }];
283
+ test('360 x 475 phone shows Pick Carrot inside the frame and clear of every control', () => {
284
+ const r = phoneRig(); r.draw(carrot);
285
+ const [chip] = assertClearChips(r, carrot);
286
+ assert.deepEqual(chip.getBoundingClientRect(), { left: 231, right: 348, top: 160, bottom: 204, width: 117, height: 44 });
287
+ r.chrome.dispose();
288
+ });
289
+ test('360 x 475 phone moves three chips to the second position without control overlaps', () => {
290
+ const r = phoneRig(); r.draw();
291
+ assert.equal(assertClearChips(r, items).length, 3);
292
+ assert.equal(find(r.dom, 'Start').parent.style.right, '92px');
293
+ r.chrome.dispose();
294
+ });
295
+ test('360 x 780 phone keeps the right column', () => {
296
+ const r = phoneRig(780); r.draw();
297
+ assert.equal(assertClearChips(r, items).length, 3);
298
+ assert.equal(find(r.dom, 'Start').parent.style.right, '12px');
299
+ r.chrome.dispose();
300
+ });
301
+ test('second position trims only top chips, restores them, and yields only if one cannot fit', () => {
302
+ const r = phoneRig();
303
+ r.chrome.setHud({ title: 'Harvest', text: 'Pick a carrot' }, null);
304
+ const hud = find(r.dom, 'Harvest').parent;
305
+ hud.rect = { left: 30, right: 290, top: 12, bottom: 310 };
306
+ r.controls.push(hud);
307
+ r.draw();
308
+ const chips = items.map(({ label }) => find(r.dom, label));
309
+ assert.equal(assertClearChips(r, items).length, 1);
310
+ assert.equal(chips[1].style.display, 'none'); assert.equal(chips[2].style.display, 'none');
311
+ // Each frame retries the full offer, even when items and n have not changed.
312
+ hud.rect.bottom = 40; r.draw(); assert.equal(assertClearChips(r, items).length, 3);
313
+ hud.rect.bottom = 410; r.draw(); assert.equal(chips[0].parent.style.display, 'none');
314
+ r.chrome.dispose();
315
+ });
316
+ test('shown decor bounds chips; hidden decor does not', () => {
317
+ const r = phoneRig();
318
+ const decorLayer = document.createElement('div'); decorLayer.style.zIndex = '3';
319
+ r.chrome.decorRoot().appendChild(decorLayer);
320
+ const decor = document.createElement('button'); decorLayer.appendChild(decor);
321
+ decor.rect = { left: 220, right: 348, top: 150, bottom: 194 };
322
+ r.controls.push(decor);
323
+ const wide = [{ id: 'wide', label: 'abcdefghijklmnop' }, ...items.slice(0, 2)];
324
+ r.draw(wide); assert.equal(assertClearChips(r, wide).length, 2);
325
+ assert(find(r.dom, wide[0].label).getBoundingClientRect().bottom <= decor.rect.top - 12);
326
+ decorLayer.style.display = 'none'; r.controls = r.controls.filter((node) => node !== decor);
327
+ r.draw(wide); assert.equal(assertClearChips(r, wide).length, 3);
328
+ r.chrome.dispose();
329
+ });
330
+ test('fallback measures wrapped chips and respects ask and Back upper bounds', () => {
331
+ const r = rig(240, 475);
332
+ r.chrome.grabPrompt('Grab');
333
+ const grab = find(r.dom, 'Grab'); grab.rect = { left: 150, right: 226, top: 80, bottom: 156 };
334
+ r.chrome.setAsk({ key: 'ask', text: 'Choose', yes: 'Yes', no: 'No' });
335
+ const ask = find(r.dom, 'Choose').parent; ask.rect = { left: 12, right: 140, top: 92, bottom: 340 };
336
+ r.chrome.showBack(true);
337
+ const back = find(r.dom, '‹ Back'); back.rect = { left: 12, right: 100, top: 12, bottom: 50 };
338
+ r.controls = [grab, ask, back];
339
+ const wide = [{ id: 'wide', label: 'abcdefghijklmnop' }, ...items.slice(0, 2)];
340
+ r.draw(wide); const [chip] = assertClearChips(r, wide);
341
+ assert.equal(assertClearChips(r, wide).length, 1);
342
+ assert.equal(chip.getBoundingClientRect().width, 126);
343
+ assert.equal(chip.getBoundingClientRect().height, 64);
344
+ assert(chip.getBoundingClientRect().top >= ask.rect.bottom + 12);
345
+ ask.rect.bottom = 430; r.draw(wide); assert.equal(chip.parent.style.display, 'none');
346
+ r.chrome.setAsk(null); r.controls = [grab, back];
347
+ r.draw(wide); assert.equal(assertClearChips(r, wide).length, 3);
348
+ back.rect.bottom = 430; r.draw(wide); assert.equal(chip.parent.style.display, 'none');
349
+ r.chrome.dispose();
350
+ });
351
+ test('640 x 300 fallback clears the measured left edge of the round column', () => {
352
+ const r = rig(640, 300);
353
+ r.chrome.showPicker(true, 0); r.chrome.setEmotes([['wave', '👋']]); r.chrome.setSay({ reactions: [], phrases: [] });
354
+ const picker = find(r.dom, 'Character').parent;
355
+ const speech = r.dom.made.find((node) => node.attrs['aria-label'] === 'Quick chat');
356
+ const emote = r.dom.made.find((node) => node.attrs['aria-label'] === 'Emote');
357
+ picker.rect = { left: 526, right: 622, top: 252, bottom: 290 };
358
+ speech.rect = { left: 560, right: 612, top: 41, bottom: 93 };
359
+ emote.rect = { left: 560, right: 612, top: 101, bottom: 153 };
360
+ r.controls = [picker, speech, emote];
361
+ r.draw(carrot); const [chip] = assertClearChips(r, carrot);
362
+ assert.deepEqual(chip.getBoundingClientRect(), { left: 431, right: 548, top: 196, bottom: 240, width: 117, height: 44 });
363
+ assert(chip.getBoundingClientRect().right <= speech.rect.left - 12);
364
+ r.chrome.dispose();
365
+ });
366
+ test('640 x 300 trimming retries the right column when Start alone clears HUD and decor', () => {
367
+ const r = rig(640, 300);
368
+ r.chrome.setHud({ title: 'Harvest' }, null); r.chrome.showPicker(true, 0); r.chrome.setEmotes([['wave', '👋']]);
369
+ const hud = find(r.dom, 'Harvest').parent, picker = find(r.dom, 'Character').parent;
370
+ const emote = r.dom.made.find((node) => node.attrs['aria-label'] === 'Emote');
371
+ hud.rect = { left: 96, right: 544, top: 12, bottom: 140 };
372
+ emote.rect = { left: 568, right: 620, top: 102, bottom: 154 };
373
+ picker.rect = { left: 534, right: 630, top: 252, bottom: 290 };
374
+ const layer = document.createElement('div'); layer.style.zIndex = '3'; r.chrome.decorRoot().appendChild(layer);
375
+ const decor = document.createElement('button'); layer.appendChild(decor);
376
+ decor.rect = { left: 468, right: 628, top: 180, bottom: 224 };
377
+ r.controls = [hud, emote, picker, decor];
378
+ const offered = [items[0], { id: 'wide', label: 'abcdefghijklmnop' }, items[2]];
379
+ r.draw(offered); const [chip] = assertClearChips(r, offered);
380
+ assert.equal(assertClearChips(r, offered).length, 1);
381
+ assert.deepEqual(chip.getBoundingClientRect(), { left: 553, right: 628, top: 46, bottom: 90, width: 75, height: 44 });
382
+ assert.equal(chip.parent.style.right, '12px');
383
+ r.chrome.dispose();
384
+ });
385
+ test('open Sound card bounds every shown chip, including after trimming', () => {
386
+ const r = phoneRig();
387
+ const sound = r.dom.made.find((node) => node.dataset.hub === 'sound');
388
+ sound.handlers.pointerdown({ stopPropagation() {}, preventDefault() {} });
389
+ const card = r.dom.made.find((node) => node.dataset.hub === 'sound-card');
390
+ assert.equal(card.style.display, 'flex');
391
+ card.rect = { left: 140, right: 348, top: 58, bottom: 106 }; r.controls.push(card);
392
+ r.draw(); assertClearChips(r, items);
393
+ // Force the stack into the card's vertical span unless it trims.
394
+ const picker = find(r.dom, 'Character').parent;
395
+ picker.rect = { left: 246, right: 342, top: 174, bottom: 212 };
396
+ r.draw(); const [chip] = assertClearChips(r, items);
397
+ assert.equal(assertClearChips(r, items).length, 1);
398
+ assert(chip.getBoundingClientRect().top >= card.rect.bottom + 12);
399
+ r.chrome.dispose();
400
+ });
401
+ test('duplicate items and n keep DOM; version-only changes echo the new n', () => {
402
+ const r = rig(); State.clear(); State.hub.place = { actions: true };
403
+ const receive = (n) => {
404
+ hook.message({}, { k: 'hub-actions', items: structuredClone(items), n });
405
+ r.draw(State.hub.actions.items, true, State.hub.actions.n);
406
+ };
407
+ receive(7); const node = find(r.dom, 'Start'), count = r.dom.made.length;
408
+ for (let i = 0; i < 100; i++) receive(7);
409
+ assert.equal(r.dom.made.length, count); assert.equal(find(r.dom, 'Start'), node);
410
+ tap(node); assert.deepEqual(r.sent, [{ k: 'hub-action', id: 'start', n: 7 }]);
411
+ receive(8); tap(node); tap(find(r.dom, 'Start'));
412
+ assert.deepEqual(r.sent.at(-1), { k: 'hub-action', id: 'start', n: 8 }); assert.equal(r.sent.length, 2);
413
+ r.chrome.dispose(); State.clear();
414
+ });
415
+ test('pointer presses leave no focus; focused chips contain Space/Enter down/up and blur on click', () => {
416
+ const r = rig(); r.draw(); const chip = find(r.dom, 'Start');
417
+ assert.equal(chip.tabIndex, -1);
418
+ const event = (code) => ({ code, stopped: false, prevented: false, stopPropagation() { this.stopped = true; }, preventDefault() { this.prevented = true; } });
419
+ for (const type of ['pointerdown', 'mousedown']) {
420
+ const e = event(); chip.handlers[type](e);
421
+ if (!e.prevented) chip.focus();
422
+ assert(e.prevented); assert(e.stopped); assert.equal(document.activeElement, null);
423
+ }
424
+ let gameKeys = 0;
425
+ chip.focus();
426
+ for (const code of ['Space', 'Enter']) {
427
+ for (const type of ['keydown', 'keyup']) {
428
+ const e = event(code); chip.handlers[type](e);
429
+ if (!e.stopped) gameKeys += 1;
430
+ if (!e.prevented) tap(chip);
431
+ assert(e.stopped); assert(e.prevented);
432
+ }
433
+ }
434
+ assert.equal(gameKeys, 0); assert.deepEqual(r.sent, []);
435
+ tap(chip); assert.equal(document.activeElement, null);
436
+ assert.deepEqual(r.sent, [{ k: 'hub-action', id: 'start', n: 1 }]);
437
+ r.chrome.dispose();
438
+ });
439
+ test('frame wiring only draws in opted-in places and clears once on keyless travel', () => {
440
+ State.clear(); fakeDom({ viewW: 360, viewH: 780 });
441
+ let system; installSystem({ registerSystem(value) { system = value; } });
442
+ const calls = [], sent = [];
443
+ system.chrome = new Proxy({ peopleOpen: () => false, chatFocused: () => false }, { get(target, name) { return target[name] ?? ((...args) => calls.push([name, ...args])); } });
444
+ system.talk = { frame() {}, talking: () => false, typing: () => false, talkingWith: () => null };
445
+ system.idle = { frame() {}, draw() {}, labels: () => [] };
446
+ system.grab = { frame() {} }; system.sound = { frame() {} }; system.sayHooked = true;
447
+ system.together.frame = () => {};
448
+ for (const method of ['keepResident', 'wearAvatar', 'applyTune', 'watchSession', 'sayHello', 'followPlace', 'holdFall', 'turnSpinners', 'applySpawns', 'applyTints', 'registerInterest', 'applyVisibility', 'applyWear', 'adoptLate', 'runCommands', 'askFriends', 'stepEnd', 'faceArrival', 'measure']) system[method] = () => {};
449
+ system.sceneKey = 'main';
450
+ const scene = { sceneKey: 'main', currentScenePath: 'scenes/main.scene', multiplayer: { net: { selfId: () => 'p1', send: (msg) => sent.push(msg) } }, actorWith: () => null, persistent: { hubTickets: [], hubAvatar: 0 }, getActors: () => [] };
451
+ hook.message({}, { k: 'hub-actions', items, n: 1 });
452
+ assert.equal(State.hub.place, null);
453
+ system.afterBehaviors(scene, 0.05);
454
+ assert(!calls.some(([name]) => name === 'setActions' || name === 'clearActions'), 'buffered offers do not draw before WORLD');
455
+ assert(!Object.hasOwn(system, 'actionsDrawn'));
456
+ hook.state({}, { hubPlace: { id: 'main', title: 'Town', scene: 'scenes/main.scene', result: null } });
457
+ assert(!Object.hasOwn(State.hub, 'actions'));
458
+ system.afterBehaviors(scene, 0.05);
459
+ assert(!calls.some(([name]) => name === 'setActions' || name === 'clearActions'));
460
+ assert(!Object.hasOwn(system, 'actionsDrawn'));
461
+ State.hub.place.actions = true; State.hub.actions = { items, n: 1 };
462
+ system.afterBehaviors(scene, 0.05);
463
+ const draw = calls.findLast(([name]) => name === 'setActions');
464
+ assert.deepEqual(draw[1], items); assert.equal(draw[3], true);
465
+ assert.equal(draw[4], 1);
466
+ draw[2]('start', draw[4]); assert.deepEqual(sent, [{ k: 'hub-action', id: 'start', n: 1 }]);
467
+ hook.state({}, { hubPlace: { id: 'main' } }); system.afterBehaviors(scene, 0.05);
468
+ assert.equal(calls.filter(([name]) => name === 'clearActions').length, 1);
469
+ system.afterBehaviors(scene, 0.05);
470
+ assert.equal(calls.filter(([name]) => name === 'clearActions').length, 1);
471
+ assert(!Object.hasOwn(system, 'actionsDrawn'));
472
+ });
473
+ test('rehello drops stale chips, identity clear drops them, avatar hello keeps them', () => {
474
+ let system; installSystem({ registerSystem(value) { system = value; } });
475
+ State.clear(); State.hub.place = { actions: true }; State.hub.actions = { items, n: 1 };
476
+ const scene = { persistent: {} }, sent = [];
477
+ let playerId = 'p1';
478
+ const net = { selfId: () => playerId, send: (msg) => sent.push(msg), drain: () => [] }, mp = { net };
479
+ system.sendHello(scene, mp, net, 0, { again: true }); assert.deepEqual(State.hub.actions, { items, n: 1 });
480
+ system.sendHello(scene, mp, net, 0, { resume: true }); assert(!Object.hasOwn(State.hub, 'actions'));
481
+ assert.equal(sent.at(-1).resume, true);
482
+ hook.message({}, { k: 'hub-actions', items, n: 1 }); assert.deepEqual(State.hub.actions, { items, n: 1 });
483
+ playerId = 'p2'; net.drain(); assert(!Object.hasOwn(State.hub, 'actions'));
484
+ hook.message({}, { k: 'hub-actions', items, n: 1 }); assert.deepEqual(State.hub.actions, { items, n: 1 });
485
+ State.clear(); assert(!Object.hasOwn(State.hub, 'actions'));
486
+ system.sendHello(scene, mp, net, 0, {}); assert(!Object.hasOwn(State.hub, 'actions'));
487
+ });
488
+ console.log(`${passed} action client tests passed`);