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,457 @@
1
+ // v1.67 owner and decorating: real hub hooks, private wire, validation and
2
+ // a keyless trace captured from 18e9a2fb's server and generated SDK.
3
+ import assert from 'node:assert/strict';
4
+ import fs from 'node:fs';
5
+ import os from 'node:os';
6
+ import path from 'node:path';
7
+ import { register } from 'node:module';
8
+
9
+ register(`data:text/javascript,${encodeURIComponent(`
10
+ export async function resolve(specifier, context, next) {
11
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: 'data:text/javascript,export const readScene = () => globalThis.__hubTestActors;', shortCircuit: true };
12
+ if (context.parentURL?.includes('/kits/base/sdk/') && specifier.startsWith('.') && !specifier.endsWith('.js')) return next(specifier + '.js', context);
13
+ return next(specifier, context);
14
+ }
15
+
16
+ `)}`);
17
+ const { layer } = await import('../code/server/hub.js');
18
+ const Manifest = await import('../code/server/manifest.js');
19
+ const { createServerHub } = await import('../../base/sdk/server/hub.js');
20
+ const Decor = await import('../code/server/decor.js');
21
+ const { fits, freeCell, footprint } = await import('../code/shared/decor.js');
22
+ const check = (await import('./check.mjs')).default;
23
+ const decor = { grid: { origin: 'floor', w: 8, d: 7, cell: 1 }, layers: ['rug', 'floor'] };
24
+ const actors = [
25
+ { id: 'player', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
26
+ { id: 'floor', components: { Transform: { x: -4, y: 0, z: -3 }, Shape: { kind: 'box', width: 8, height: 0.1, depth: 7 } } },
27
+ { id: 'chair', components: { Transform: { x: 0, y: 0.25, z: 0 }, Shape: { kind: 'box', width: 1, height: 0.5, depth: 1 }, Body: { type: 'kinematic' }, HubSeat: {} } },
28
+ { id: 'rug', components: { Transform: { x: 0, y: 0.01, z: 0 }, Shape: { kind: 'box', width: 2, height: 0.02, depth: 2 } } },
29
+ ];
30
+ const players = [
31
+ { playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false },
32
+ { playerId: 'p2', userId: '102', username: 'Bo', isAnonymous: false },
33
+ ];
34
+ const json = (keys = {}) => ({ server: { maxPlayers: 8 }, hub: { contract: 1, title: 'House', ...keys } });
35
+ function boot(keys = {}, options = {}) {
36
+ const sent = [], ops = [], arrivals = [];
37
+ let hub;
38
+ const hooks = { ready(ctx) { hub = ctx; }, arrive(ctx, group) { arrivals.push([ctx.owner ?? null, group.map((p) => p.playerId)]); }, decor(ctx, id, op) { ops.push([id, op]); }, ...(options.hooks ?? {}) };
39
+ const bodies = [];
40
+ const engine = {
41
+ createBody(sim, actor, at) {
42
+ const rb = { at: { ...at }, setEnabled() {}, setNextKinematicTranslation(at) { this.at = { ...at }; }, setNextKinematicRotation() {} };
43
+ bodies.push([actor.id, rb]);
44
+ return rb;
45
+ },
46
+ removeActor(sim, id) { sim.bodies.delete(id); sim.objects.delete(id); },
47
+ };
48
+ globalThis.__hubTestActors = structuredClone(actors);
49
+ const server = layer(json(keys), hooks, {}, () => true, () => null, null, engine);
50
+ 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)]); } };
51
+ 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() {} } }])) };
52
+ server.sceneFor(session);
53
+ server.ready(world);
54
+ const say = (id, data) => server.message(session, { playerId: id }, data);
55
+ if (options.hello !== false) {
56
+ for (const id of options.order ?? ['p1', 'p2']) {
57
+ say(id, { k: 'hub-hello', avatar: 0, party: 2 });
58
+ }
59
+ server.place(world);
60
+ }
61
+ const tick = (ms = 50) => { world.timeMs += ms; server.place(world); server.step(world, []); };
62
+ return { server, session, world, hub, sent, ops, say, tick, bodies, arrivals };
63
+ }
64
+ function sdk(owner) {
65
+ const platform = { hub: { place: 'main', title: 'House', result: null, ...(owner === undefined ? {} : { owner }) }, hubResult() {}, hubPadUpdate() {}, hubResultsRead() {} };
66
+ return createServerHub(platform, new Map());
67
+ }
68
+ function sdkShape(api) {
69
+ return { keys: Object.keys(api), frozen: Object.isFrozen(api), json: JSON.stringify(api), shape: JSON.parse(JSON.stringify(api, (key, value) => typeof value === 'function' ? { fn: value.name, args: value.length } : value)) };
70
+ }
71
+ function keylessTrace() {
72
+ const r = boot();
73
+ const trace = [];
74
+ const capture = () => trace.push({ join: r.server.join(), delta: r.server.delta(), sent: r.sent.splice(0) });
75
+ capture(); r.tick(); capture();
76
+ r.hub.setHud({ title: 'Hello', big: 'HOME', text: 'Walk around' }, 'p1');
77
+ r.hub.hide('rug'); r.tick(); capture();
78
+ r.hub.show('rug'); r.tick(); capture();
79
+ r.say('p1', { k: 'decor', op: 'button' }); r.tick(); capture();
80
+ assert.equal(Object.hasOwn(r.hub, 'decor'), false);
81
+ return JSON.parse(JSON.stringify({ sdk: sdkShape(sdk()), manifest: Manifest.readManifest(json()).manifest, trace }));
82
+ }
83
+ const fixture = new URL('./fixtures/decor-keyless.json', import.meta.url);
84
+ let passed = 0;
85
+ function test(name, fn) {
86
+ fn(); passed += 1; console.log(`ok: ${name}`);
87
+ }
88
+ const item = { id: 'chair', tab: 'furniture', label: 'Chair', template: 'chair', w: 1, d: 1, layer: 'floor', count: 2 };
89
+ const spec = () => ({ title: 'Only you can change your house', tabs: [{ id: 'furniture', label: 'Furniture' }, { id: 'walls', label: 'Walls' }], items: [structuredClone(item)], swatches: [{ id: 'sage', tab: 'walls', label: 'Sage', color: '#779977' }], placed: [] });
90
+ const privateWire = (r) => r.sent.filter(([, msg]) => msg.k === 'hub-decor');
91
+
92
+ test('keys absent: pre-change hub, manifest and every snapshot/delta/message deep- and JSON-equal', () => {
93
+ const expected = JSON.parse(fs.readFileSync(fixture, 'utf8')), actual = keylessTrace();
94
+ assert.deepEqual(actual, expected);
95
+ assert.equal(JSON.stringify(actual), JSON.stringify(expected));
96
+ assert.ok(!JSON.stringify(actual.trace).includes('hub-decor'));
97
+ });
98
+ test('every place greets for a connection it let go that comes back silent (decor or not)', () => {
99
+ for (const keyed of [true, false]) {
100
+ const r = boot(keyed ? { decor } : {});
101
+ r.say('p2', { k: 'hub-hello', avatar: 3, party: 2 });
102
+ r.tick();
103
+ // p2's connection drops long enough for the session to report a leave.
104
+ r.session.players = r.session.players.filter((p) => p.playerId !== 'p2');
105
+ const body = r.world.players.get('p2');
106
+ r.world.players.delete('p2');
107
+ r.tick();
108
+ // It comes back on the same connection (same id) and says nothing.
109
+ r.session.players.push({ playerId: 'p2', username: 'bo' });
110
+ r.world.players.set('p2', body);
111
+ const before = r.arrivals.length;
112
+ const p2Arrived = () => r.arrivals.slice(before).some(([, ids]) => ids.includes('p2'));
113
+ r.tick(1000);
114
+ r.tick(1000);
115
+ assert.equal(p2Arrived(), false, 'not within 3 s: a client greets on its own first');
116
+ r.tick(2500);
117
+ r.tick();
118
+ assert.equal(p2Arrived(), true, 'arrived again without a client hello');
119
+ const n = r.arrivals.length;
120
+ r.tick(5000);
121
+ assert.equal(r.arrivals.length, n, 'once');
122
+ // A newcomer who never said hello here is never greeted for: its own hello carries its party.
123
+ r.session.players.push({ playerId: 'p3', username: 'cy' });
124
+ r.world.players.set('p3', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
125
+ for (let i = 0; i < 10; i++) r.tick(1000);
126
+ assert.equal(r.arrivals.slice(n).some(([, ids]) => ids.includes('p3')), false, 'a silent newcomer is waited for');
127
+ r.say('p3', { k: 'hub-hello', avatar: 0, party: 1 });
128
+ r.tick();
129
+ assert(r.arrivals.slice(n).some(([, ids]) => ids.includes('p3')), 'and arrives on its own hello');
130
+ // A client hello that comes later only updates; it does not arrive again.
131
+ const m = r.arrivals.length;
132
+ r.say('p2', { k: 'hub-hello', avatar: 1 });
133
+ r.tick();
134
+ assert.equal(r.arrivals.length, m, 'a late client hello does not re-arrive');
135
+ }
136
+ });
137
+ test('a re-greeted player has stale private HUD and visibility cleared; a game place never re-greets', () => {
138
+ const r = boot({ decor });
139
+ r.hub.setHud({ title: 'Hi', big: 'B2', text: 'Mine' }, 'p2');
140
+ r.hub.hide('chair', { to: ['p2'] });
141
+ r.tick();
142
+ // The place stops saying either while p2 is away (it forgets them on leave).
143
+ r.session.players = r.session.players.filter((p) => p.playerId !== 'p2');
144
+ const body = r.world.players.get('p2');
145
+ r.world.players.delete('p2');
146
+ r.tick();
147
+ r.session.players.push({ playerId: 'p2', username: 'bo' });
148
+ r.world.players.set('p2', body);
149
+ r.sent.splice(0);
150
+ for (let i = 0; i < 5; i++) r.tick(1000);
151
+ const toP2 = r.sent.filter(([id]) => id === 'p2').map(([, m]) => m);
152
+ assert(toP2.some((m) => m.k === 'hub-hud' && m.hud === null), 'the stale private HUD is cleared');
153
+ assert(toP2.some((m) => m.k === 'hub-vis' && m.hide.length === 0 && m.show.length === 0), 'the stale private hide is cleared');
154
+ assert(toP2.some((m) => m.k === 'hub-leaving' && m.text === null), 'a stale leaving line is cleared');
155
+ assert(toP2.some((m) => m.k === 'hub-party' && m.members === null && m.invite === null), 'a stale party or invite is cleared');
156
+
157
+ // A private ballot card the place forgot is cleared too (after hello resets its cache).
158
+ const bb = boot({ decor, ballot: true });
159
+ assert.equal(bb.hub.ballot(['p2'], { mode: 'vote', faces: [{ playerId: 'p1' }, { playerId: 'p2' }] }), true);
160
+ bb.tick();
161
+ bb.session.players = bb.session.players.filter((p) => p.playerId !== 'p2');
162
+ const bbody = bb.world.players.get('p2');
163
+ bb.world.players.delete('p2');
164
+ bb.tick();
165
+ bb.session.players.push({ playerId: 'p2', username: 'bo' });
166
+ bb.world.players.set('p2', bbody);
167
+ bb.sent.splice(0);
168
+ for (let i = 0; i < 5; i++) bb.tick(1000);
169
+ assert(bb.sent.some(([id, m]) => id === 'p2' && m.k === 'hub-ballot-card' && m.card === null), 'a stale private ballot card is cleared');
170
+
171
+ // A game keeps the old way: its round and result belong to the visit that left.
172
+ const g = boot({ decor, result: { score: { unit: 's', better: 'lower' } } });
173
+ g.session.players = g.session.players.filter((p) => p.playerId !== 'p2');
174
+ const gb = g.world.players.get('p2');
175
+ g.world.players.delete('p2');
176
+ g.tick();
177
+ g.session.players.push({ playerId: 'p2', username: 'bo' });
178
+ g.world.players.set('p2', gb);
179
+ const n = g.arrivals.length;
180
+ for (let i = 0; i < 6; i++) g.tick(1000);
181
+ assert.equal(g.arrivals.length, n, 'a game does not re-greet');
182
+ });
183
+ test('SDK owner is copied only for a non-empty string onto the frozen hub', () => {
184
+ for (const absent of [undefined, '', null, 0, {}, []]) {
185
+ const api = sdk(absent);
186
+ assert.deepEqual(sdkShape(api), sdkShape(sdk()));
187
+ assert.equal(Object.hasOwn(api, 'owner'), false);
188
+ }
189
+ assert.equal(sdk('101').owner, '101');
190
+ assert.equal(Object.isFrozen(sdk('101')), true);
191
+ });
192
+ test('kit owner: platform wins; dev first arrival persists; other sessions stay null', () => {
193
+ assert.equal(boot().hub.owner, null);
194
+ assert.equal(boot({ house: { devOwner: 'first' } }, { hello: false }).hub.owner, null);
195
+ const r = boot({ house: { devOwner: 'first' } }, { order: ['p2', 'p1'] });
196
+ assert.equal(r.hub.owner, '102');
197
+ assert.deepEqual(r.arrivals, [['102', ['p2', 'p1']]]);
198
+ r.session.players = [players[0]]; r.world.players.delete('p2'); r.tick();
199
+ assert.equal(r.hub.owner, '102');
200
+ r.session.hub = {};
201
+ assert.equal(r.hub.owner, null, 'a platform hub without an owner never inherits a dev owner');
202
+ r.session.hub = null;
203
+ assert.equal(r.hub.owner, '102');
204
+ assert.equal(boot({ house: { devOwner: 'first' } }, { sessionId: 'public' }).hub.owner, null);
205
+ for (const owner of ['101', '', null, 7]) {
206
+ assert.equal(boot({ house: { devOwner: 'first' } }, { hello: false, platform: { owner } }).hub.owner, typeof owner === 'string' && owner.length ? owner : null);
207
+ }
208
+ const guest = boot({ house: { devOwner: 'first' } }, { hello: false });
209
+ guest.session.players[0] = { ...players[0], userId: 'dev-guest-1', isAnonymous: true };
210
+ guest.say('p1', { k: 'hub-hello', avatar: 0 }); guest.tick();
211
+ assert.equal(guest.hub.owner, 'dev-guest-1');
212
+ });
213
+ test('manifest accepts decor on places and house on the deck, without filling absent defaults', () => {
214
+ const m = Manifest.readManifest(json({ decor, house: { devOwner: 'first' }, places: { room: { title: 'Room', scene: 'scenes/room.scene', decor } } }));
215
+ assert.deepEqual(m.errors, []);
216
+ assert.deepEqual(m.manifest.places.main.decor, decor);
217
+ assert.deepEqual(m.manifest.places.room.decor, decor);
218
+ assert.equal(Manifest.publicPlace('main', m.manifest.places.main).decor.grid.origin, 'floor');
219
+ assert.equal(Object.hasOwn(Manifest.readManifest(json()).manifest.places.main, 'decor'), false);
220
+ });
221
+ test('manifest refuses malformed bounds, layers, ids, unknown fields and house settings', () => {
222
+ const bad = [null, true, {}, { ...decor, extra: true }, { ...decor, layers: [] }, { ...decor, layers: ['a', 'a'] }, { ...decor, layers: ['a', 'b', 'c', 'd'] }, { ...decor, layers: ['not an id'] }];
223
+ for (const grid of [{}, { ...decor.grid, origin: '' }, { ...decor.grid, w: 0 }, { ...decor.grid, w: 17 }, { ...decor.grid, d: 1.5 }, { ...decor.grid, cell: 0.4 }, { ...decor.grid, cell: 2.1 }, { ...decor.grid, cell: '1' }, { ...decor.grid, extra: 1 }]) {
224
+ bad.push({ ...decor, grid });
225
+ }
226
+ for (const value of bad) {
227
+ assert.equal(Manifest.readManifest(json({ decor: value })).manifest, null, JSON.stringify(value));
228
+ }
229
+ for (const house of [null, true, {}, { devOwner: 'last' }, { devOwner: 'first', extra: 1 }]) {
230
+ assert.equal(Manifest.readManifest(json({ house })).manifest, null);
231
+ }
232
+ });
233
+ test('exact catalogue limits are accepted; malformed rotated bounds and duplicate ids are refused', () => {
234
+ const h = { actors, place: { decor: { ...decor, grid: { ...decor.grid, w: 16, d: 16 } } }, spawned: new Map(Array.from({ length: 64 }, (_, i) => [`copy-${i}`, {}])) };
235
+ const max = {
236
+ tabs: Array.from({ length: 6 }, (_, i) => ({ id: `tab-${i}`, label: `Tab ${i}` })),
237
+ items: Array.from({ length: 64 }, (_, i) => ({ ...item, id: `item-${i}`, tab: `tab-${i % 6}` })),
238
+ swatches: Array.from({ length: 24 }, (_, i) => ({ id: `color-${i}`, tab: `tab-${i % 6}`, label: `Colour ${i}`, color: '#abcdef' })),
239
+ placed: Array.from({ length: 64 }, (_, i) => ({ key: `copy-${i}`, item: `item-${i}`, x: i % 16, z: Math.floor(i / 16), rot: 0, layer: 'floor' })),
240
+ };
241
+ assert.equal(Decor.checkSpec(h, max).items.length, 64);
242
+ assert.equal(Decor.checkSpec(h, max).placed.length, 64);
243
+ assert.throws(() => Decor.checkSpec(h, { ...max, items: max.items.map((i) => ({ ...i, id: 'same' })) }), TypeError);
244
+ const r = boot({ decor });
245
+ const key = r.hub.spawn('chair', { x: 0, y: 0.25, z: 0 });
246
+ assert.throws(() => r.hub.decor.open('p1', { ...spec(), items: [{ ...item, w: 2, d: 1 }], placed: [{ key, item: 'chair', x: 7, z: 6, rot: 1, layer: 'floor' }] }), TypeError);
247
+ });
248
+ test('keyless messages retain the existing deck message path', () => {
249
+ const heard = [];
250
+ const r = boot({}, { hooks: { message(ctx, player, data) { heard.push([player.playerId, data]); } } });
251
+ const op = { k: 'decor', op: 'button' };
252
+ r.say('p1', op);
253
+ assert.deepEqual(heard, [['p1', op]]);
254
+ assert.deepEqual(r.ops, []);
255
+ assert.equal(Object.hasOwn(r.hub, 'decor'), false);
256
+ });
257
+ test('private button/open/update/close never enter shared snapshots and reconnect only replays its player', () => {
258
+ const r = boot({ decor });
259
+ const shared = JSON.stringify(r.server.join());
260
+ r.hub.decor.button('p1', 'Decorate');
261
+ r.hub.decor.open('p1', spec());
262
+ assert.deepEqual(privateWire(r).map(([id]) => id), ['p1', 'p1']);
263
+ assert.deepEqual(privateWire(r).at(-1)[1].grid, { x: -4, y: 0, z: -3, w: 8, d: 7, cell: 1 });
264
+ assert.equal(JSON.stringify(r.server.join()), shared);
265
+ r.sent.length = 0;
266
+ r.say('p2', { k: 'hub-hello', avatar: 0 });
267
+ r.say('p1', { k: 'hub-hello', avatar: 0, again: true });
268
+ assert.equal(privateWire(r).length, 0);
269
+ r.say('p1', { k: 'hub-hello', avatar: 0 });
270
+ assert.equal(privateWire(r).length, 1);
271
+ assert.equal(privateWire(r)[0][0], 'p1');
272
+ r.hub.decor.update('p1', { items: [{ ...item, count: 0 }] });
273
+ assert.equal(privateWire(r).at(-1)[1].spec.items[0].count, 0);
274
+ r.hub.decor.close('p1');
275
+ assert.deepEqual(privateWire(r).at(-1), ['p1', { k: 'hub-decor', button: 'Decorate', spec: null }]);
276
+ r.hub.decor.button('p1', null);
277
+ assert.equal(privateWire(r).at(-1)[1].button, null);
278
+ });
279
+ test('API misuse throws atomically: lengths, caps, templates, layers, counts, locks, swatches, placed', () => {
280
+ const r = boot({ decor });
281
+ for (const label of ['', 'x'.repeat(17), 7, undefined]) {
282
+ assert.throws(() => r.hub.decor.button('p1', label), TypeError);
283
+ }
284
+ assert.throws(() => r.hub.decor.button('missing', 'Decorate'), TypeError);
285
+ assert.throws(() => r.hub.decor.update('p1', {}), TypeError);
286
+ const bad = [null, {}, { ...spec(), title: 'x'.repeat(41) }, { ...spec(), tabs: [] }, { ...spec(), tabs: Array(7).fill(spec().tabs[0]) }, { ...spec(), items: Array(65).fill(item) }, { ...spec(), placed: Array(65).fill({}) }, { ...spec(), extra: 1 }, { ...spec(), swatches: Array(25).fill(spec().swatches[0]) }];
287
+ for (const change of [{ label: 'x'.repeat(17) }, { template: 'missing' }, { template: 'player' }, { w: 5 }, { d: 0 }, { w: 1.5 }, { layer: 'wall' }, { tab: 'missing' }, { count: -1 }, { count: 1.5 }, { locked: true }, { locked: { price: 'x'.repeat(13) } }, { extra: 1 }]) {
288
+ bad.push({ ...spec(), items: [{ ...item, ...change }] });
289
+ }
290
+ bad.push({ ...spec(), swatches: [{ ...spec().swatches[0], color: 'red' }] });
291
+ bad.push({ ...spec(), placed: [{ key: 'chair', item: 'chair', x: 0, z: 0, rot: 0, layer: 'floor' }] });
292
+ const before = privateWire(r).length;
293
+ for (const value of bad) {
294
+ assert.throws(() => r.hub.decor.open('p1', value), TypeError, JSON.stringify(value));
295
+ }
296
+ assert.equal(privateWire(r).length, before);
297
+ r.hub.decor.open('p1', spec());
298
+ assert.throws(() => r.hub.decor.update('p1', { items: [{ ...item, count: -1 }] }), TypeError);
299
+ assert.equal(privateWire(r).at(-1)[1].spec.items[0].count, 2);
300
+ });
301
+ test('only an opener reaches the decor hook; button needs an offered button; ids are whitelisted', () => {
302
+ const r = boot({ decor });
303
+ r.say('p1', { k: 'decor', op: 'button' });
304
+ r.hub.decor.button('p1', 'Decorate');
305
+ r.say('p1', { k: 'decor', op: 'button' });
306
+ assert.deepEqual(r.ops, [['p1', { op: 'button' }]]);
307
+ r.ops.length = 0;
308
+ r.hub.decor.open('p1', spec());
309
+ for (const op of [{ op: 'close' }, { op: 'swatch', swatch: 'sage' }, { op: 'place', item: 'chair', x: 2, z: 3, rot: 1 }]) {
310
+ r.say('p2', { k: 'decor', ...op });
311
+ r.say('missing', { k: 'decor', ...op });
312
+ assert.equal(r.ops.length, 0);
313
+ }
314
+ for (const op of [{ op: 'place', item: 'nope', x: 0, z: 0, rot: 0 }, { op: 'place', item: 'chair', x: 1.5, z: 0, rot: 0 }, { op: 'place', item: 'chair', x: 0, z: 0, rot: 4 }, { op: 'move', key: 'chair', x: 0, z: 0, rot: 0 }, { op: 'swatch', swatch: 'missing' }, { op: 'close', extra: true }]) {
315
+ r.say('p1', { k: 'decor', ...op });
316
+ }
317
+ assert.deepEqual(r.ops, []);
318
+ r.say('p1', { k: 'decor', op: 'place', item: 'chair', x: 2, z: 3, rot: 1 });
319
+ r.say('p1', { k: 'decor', op: 'swatch', swatch: 'sage' });
320
+ r.say('p1', { k: 'decor', op: 'close' });
321
+ assert.deepEqual(r.ops.map(([, op]) => op.op), ['place', 'swatch', 'close']);
322
+ assert.equal(r.server.join().spawned && Object.keys(r.server.join().spawned).length, 0, 'kit does not spawn for the hook');
323
+ r.hub.decor.close('p1');
324
+ r.say('p1', { k: 'decor', op: 'close' });
325
+ assert.equal(r.ops.length, 3);
326
+ });
327
+ test('locked and exhausted stock cannot be picked; placed move/stash are validated but deck applies them', () => {
328
+ const r = boot({ decor });
329
+ const key = r.hub.spawn('chair', { x: 0, y: 0.25, z: 0 });
330
+ const placed = [{ key, item: 'chair', x: 4, z: 3, rot: 0, layer: 'floor' }];
331
+ r.hub.decor.open('p1', { ...spec(), placed, items: [{ ...item, count: 0 }] });
332
+ r.say('p1', { k: 'decor', op: 'place', item: 'chair', x: 0, z: 0, rot: 0 });
333
+ assert.equal(r.ops.length, 0);
334
+ r.hub.decor.update('p1', { items: [{ ...item, locked: { price: '120 ▲' } }] });
335
+ r.say('p1', { k: 'decor', op: 'place', item: 'chair', x: 0, z: 0, rot: 0 });
336
+ assert.equal(r.ops.length, 0);
337
+ r.say('p1', { k: 'decor', op: 'move', key, x: 3, z: 2, rot: 2 });
338
+ r.say('p1', { k: 'decor', op: 'stash', key });
339
+ assert.deepEqual(r.ops.map(([, op]) => op.op), ['move', 'stash']);
340
+ assert.equal(Object.keys(r.server.join().spawned).length, 1);
341
+ r.hub.decor.close('p1');
342
+ r.say('p1', { k: 'decor', op: 'stash', key });
343
+ assert.equal(r.ops.length, 2);
344
+ });
345
+ test('op budget permits eight in a burst and six more after a second; disconnected/ended ops are dropped', () => {
346
+ const r = boot({ decor }); r.hub.decor.open('p1', spec());
347
+ for (let i = 0; i < 12; i += 1) { r.say('p1', { k: 'decor', op: 'close' }); }
348
+ assert.equal(r.ops.length, 8);
349
+ r.tick(1000);
350
+ for (let i = 0; i < 8; i += 1) { r.say('p1', { k: 'decor', op: 'close' }); }
351
+ assert.equal(r.ops.length, 14);
352
+ r.tick(1000); r.session.players = [players[1]];
353
+ r.say('p1', { k: 'decor', op: 'close' }); assert.equal(r.ops.length, 14);
354
+ r.session.players = [...players]; r.hub.end(['p1']);
355
+ r.say('p1', { k: 'decor', op: 'close' }); assert.equal(r.ops.length, 14);
356
+ });
357
+ test('departure drops private state and rate budget, returning players have no open catalogue', () => {
358
+ const r = boot({ decor });
359
+ r.hub.decor.button('p1', 'Decorate'); r.hub.decor.open('p1', spec());
360
+ r.session.players = [players[1]]; r.world.players.delete('p1'); r.tick();
361
+ r.session.players.push(players[0]);
362
+ r.world.players.set('p1', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
363
+ r.sent.length = 0; r.say('p1', { k: 'hub-hello', avatar: 0 }); r.tick();
364
+ r.say('p1', { k: 'decor', op: 'close' });
365
+ assert.deepEqual(privateWire(r), []); assert.deepEqual(r.ops, []);
366
+ });
367
+ test('spawned HubSeat works for a guest, follows a move, and a stash stands the guest', () => {
368
+ const r = boot({ decor, idle: true });
369
+ const key = r.hub.spawn('chair', { x: 0, y: 0.25, z: 0, rotationY: 90 });
370
+ r.hub.hide('chair');
371
+ r.world.players.get('p2').at = { x: 0, y: 1, z: 0 };
372
+ r.say('p2', { k: 'hub-sit', seat: key });
373
+ assert.equal(r.hub.seat('p2'), key);
374
+ r.hub.move(key, { x: 1, z: 1, rotationY: 180 }); r.tick(); r.tick();
375
+ assert.equal(r.hub.seat('p2'), null, 'moving the seat gets its sitter up');
376
+ r.world.players.get('p2').at = { x: 1, y: 1, z: 1 };
377
+ r.tick(1000); r.say('p2', { k: 'hub-sit', seat: key });
378
+ assert.equal(r.hub.seat('p2'), key);
379
+ assert.equal(r.world.players.get('p2').facing, Math.PI);
380
+ r.hub.despawn(key); r.tick();
381
+ assert.equal(r.hub.seat('p2'), null);
382
+ const legacy = boot({ idle: true });
383
+ const oldKey = legacy.hub.spawn('chair', { x: 0, y: 0.25, z: 0 });
384
+ legacy.say('p2', { k: 'hub-sit', seat: oldKey });
385
+ assert.equal(legacy.hub.seat('p2'), null, 'keyless seat behavior is preserved');
386
+ });
387
+ test('a fixed spawned seat works too, and explicit face follows the template-relative turn', () => {
388
+ const r = boot({ decor, idle: true });
389
+ globalThis.__hubTestActors.find((a) => a.id === 'chair').components.HubSeat.face = 30;
390
+ const key = r.hub.spawn('chair', { x: 0, y: 0.25, z: 0, rotationY: 90 });
391
+ r.world.players.get('p2').at = { x: 0, y: 1, z: 0 };
392
+ r.say('p2', { k: 'hub-sit', seat: key });
393
+ assert.ok(Math.abs(r.world.players.get('p2').facing - 120 * Math.PI / 180) < 1e-9);
394
+ r.hub.move(key, { rotationY: 180 }); r.tick(); r.tick(); assert.equal(r.hub.seat('p2'), null);
395
+ const chair = globalThis.__hubTestActors.find((a) => a.id === 'chair'); delete chair.components.Body;
396
+ const fixed = r.hub.spawn('chair', { x: 0, y: 0.25, z: 0 });
397
+ r.tick(1000); r.world.players.get('p2').at = { x: 0, y: 1, z: 0 };
398
+ r.say('p2', { k: 'hub-sit', seat: fixed }); assert.equal(r.hub.seat('p2'), fixed);
399
+ });
400
+ test('preview swaps w/d, ignores another layer and its own footprint, and finds a free cell near the player', () => {
401
+ const items = [{ ...item, w: 2, d: 1 }, { ...item, id: 'rug', w: 2, d: 2, layer: 'rug' }];
402
+ const placed = [{ key: 'copy', item: 'chair', x: 0, z: 0, rot: 0, layer: 'floor' }];
403
+ assert.deepEqual(footprint(items[0], 1), { w: 1, d: 2 });
404
+ assert.equal(fits(decor.grid, items, placed, { key: 'copy', item: 'chair', x: 0, z: 0, rot: 0 }), true);
405
+ assert.equal(fits(decor.grid, items, placed, { item: 'chair', x: 0, z: 0, rot: 0 }), false);
406
+ assert.equal(fits(decor.grid, items, placed, { item: 'rug', x: 0, z: 0, rot: 0 }), true);
407
+ assert.equal(fits(decor.grid, items, placed, { item: 'chair', x: 7, z: 6, rot: 1 }), false);
408
+ assert.deepEqual(freeCell(decor.grid, items, placed, items[0], { x: 5, z: 4 }), { x: 5, z: 4 });
409
+ });
410
+
411
+ // Exercise the actual real-time router, which intercepts GONE before hub.message.
412
+ const { makeSession } = await import('../../real-time/code/server/session.js');
413
+ for (const mode of ['keyless', 'decor', 'other-place']) {
414
+ const enabled = mode === 'decor';
415
+ const r = boot(mode === 'other-place' ? { places: { house: { title: 'House', scene: 'scenes/house.scene', decor } } } : enabled ? { decor } : {});
416
+ const key = r.hub.spawn('chair', { x: 0, y: 0.25, z: 0 });
417
+ const handlers = makeSession({ label: 'decor-gone',
418
+ game: { ...r.server, ready() {} },
419
+ world: { async createSimulation() { return r.world; }, removeActor(sim, id) { sim.bodies.delete(id); sim.objects.delete(id); } },
420
+ players: {}, ownership: {}, poses: {},
421
+ });
422
+ handlers.onTick(r.session);
423
+ await new Promise((resolve) => setImmediate(resolve));
424
+ handlers.onMessage(r.session, players[1], { k: 'g', id: key });
425
+ assert.equal(r.world.bodies.has(key), enabled, 'decor refuses guest GONE; keyless honors it');
426
+ assert.equal(Object.hasOwn(r.server, 'allowClientGone'), mode !== 'keyless');
427
+ r.tick();
428
+ if (enabled) {
429
+ r.hub.decor.button('p1', 'Decorate');
430
+ r.hub.decor.open('p1', { ...spec(), placed: [{ key, item: 'chair', x: 0, z: 0, rot: 0, layer: 'floor' }] });
431
+ assert.equal(privateWire(r).at(-1)[1].spec.placed[0].key, key);
432
+ assert(r.hub.decor.has(key));
433
+ r.hub.despawn(key);assert.equal(r.hub.decor.has(key), false);
434
+ } else {
435
+ assert.equal(r.hub.move(key, { x: 1 }), false, 'keyless GONE also removes the kit copy');
436
+ }
437
+ }
438
+ console.log('ok: real-time GONE is opt-in; guest chair survives and owner catalogue opens'); passed += 1;
439
+
440
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'house-decor-check-'));
441
+ try {
442
+ fs.mkdirSync(path.join(dir, 'scenes'));
443
+ fs.writeFileSync(path.join(dir, 'scenes/main.scene'), JSON.stringify({ actors }));
444
+ const manifest = { ...json({ decor }), server: { main: 'code/server/index.js', maxPlayers: 8 } };
445
+ fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify(manifest));
446
+ assert.deepEqual((await check({ deckDir: dir, self: true })).errors, []);
447
+ manifest.hub.decor.grid.origin = 'missing';
448
+ fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify(manifest));
449
+ assert.ok((await check({ deckDir: dir, self: true })).errors.some((e) => e.includes('decor.grid.origin')));
450
+ manifest.hub.decor.grid.origin = 'floor'; manifest.hub.decor.grid.w = 17;
451
+ fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify(manifest));
452
+ assert.ok((await check({ deckDir: dir, self: true })).errors.some((e) => e.includes('decor')));
453
+ console.log('ok: publish check validates grid actor and rejects malformed decor'); passed += 1;
454
+ } finally {
455
+ fs.rmSync(dir, { recursive: true, force: true });
456
+ }
457
+ console.log(`test-decor: ${passed} passed`);