castle-web-cli 0.4.238 → 0.4.240

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 (404) hide show
  1. package/dist/agent.js +5 -1
  2. package/dist/api.d.ts +20 -0
  3. package/dist/api.js +57 -0
  4. package/dist/bundle.d.ts +38 -1
  5. package/dist/bundle.js +309 -13
  6. package/dist/castle-host/host.js +218 -11
  7. package/dist/castleJson.d.ts +10 -0
  8. package/dist/castleJson.js +46 -2
  9. package/dist/check.js +5 -2
  10. package/dist/devSessionServer.js +4 -1
  11. package/dist/devSessionStorage.d.ts +1 -0
  12. package/dist/devSessionStorage.js +32 -7
  13. package/dist/importOrder.d.ts +2 -0
  14. package/dist/importOrder.js +29 -0
  15. package/dist/index.js +22 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +9 -0
  19. package/dist/platformDoc.js +4 -2
  20. package/dist/playPagePolicy.d.ts +1 -0
  21. package/dist/playPagePolicy.js +12 -3
  22. package/dist/resetLeaderboards.d.ts +8 -1
  23. package/dist/resetLeaderboards.js +43 -8
  24. package/dist/roomLogs.d.ts +39 -0
  25. package/dist/roomLogs.js +166 -0
  26. package/dist/save-deck.d.ts +32 -2
  27. package/dist/save-deck.js +240 -39
  28. package/kits/base/CLAUDE.md +2 -1
  29. package/kits/base/castle.json +1 -1
  30. package/kits/base/sdk/README.md +240 -8
  31. package/kits/base/sdk/analytics.d.ts +8 -0
  32. package/kits/base/sdk/analytics.js +92 -0
  33. package/kits/base/sdk/castle.d.ts +8 -2
  34. package/kits/base/sdk/castle.js +3 -0
  35. package/kits/base/sdk/commands.d.ts +79 -0
  36. package/kits/base/sdk/commands.js +1 -0
  37. package/kits/base/sdk/debugConsole.d.ts +17 -0
  38. package/kits/base/sdk/debugConsole.js +154 -0
  39. package/kits/base/sdk/experiments.js +24 -1
  40. package/kits/base/sdk/hostRetry.d.ts +7 -0
  41. package/kits/base/sdk/hostRetry.js +57 -0
  42. package/kits/base/sdk/hub.d.ts +20 -2
  43. package/kits/base/sdk/hub.js +99 -13
  44. package/kits/base/sdk/multiplayer.d.ts +2 -0
  45. package/kits/base/sdk/multiplayer.js +198 -26
  46. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  47. package/kits/base/sdk/reconnectBudget.js +41 -1
  48. package/kits/base/sdk/rooms.d.ts +11 -0
  49. package/kits/base/sdk/rooms.js +22 -0
  50. package/kits/base/sdk/runtime.js +36 -19
  51. package/kits/base/sdk/server/hub.d.ts +19 -0
  52. package/kits/base/sdk/server/hub.js +12 -0
  53. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  54. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  55. package/kits/base/sdk/server/wrapper.js +26 -1
  56. package/kits/base/sdk/store.d.ts +8 -2
  57. package/kits/base/sdk/store.js +5 -1
  58. package/kits/base/sdk/transport.d.ts +2 -1
  59. package/kits/base/sdk/transport.js +35 -0
  60. package/kits/hub-game/CLAUDE.md +66 -19
  61. package/kits/hub-game/castle.json +4 -4
  62. package/kits/hub-game/code/client/act.js +9 -6
  63. package/kits/hub-game/code/client/actCore.js +26 -6
  64. package/kits/hub-game/code/client/actGateLog.js +36 -0
  65. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  66. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  67. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  68. package/kits/hub-game/code/client/askSurface.js +85 -0
  69. package/kits/hub-game/code/client/askTree.js +51 -0
  70. package/kits/hub-game/code/client/attention.js +31 -6
  71. package/kits/hub-game/code/client/ballot.js +42 -5
  72. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  73. package/kits/hub-game/code/client/ballotTree.js +180 -0
  74. package/kits/hub-game/code/client/catchingUp.js +19 -0
  75. package/kits/hub-game/code/client/celebrate.js +66 -0
  76. package/kits/hub-game/code/client/chrome.js +474 -53
  77. package/kits/hub-game/code/client/companion.js +93 -23
  78. package/kits/hub-game/code/client/companionDress.js +1 -1
  79. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  80. package/kits/hub-game/code/client/cornerTree.js +83 -0
  81. package/kits/hub-game/code/client/decor.js +20 -11
  82. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  83. package/kits/hub-game/code/client/disguise.js +23 -0
  84. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  85. package/kits/hub-game/code/client/dockSurface.js +206 -0
  86. package/kits/hub-game/code/client/dockTree.js +232 -0
  87. package/kits/hub-game/code/client/earned.js +29 -0
  88. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  89. package/kits/hub-game/code/client/emoteTree.js +264 -0
  90. package/kits/hub-game/code/client/farAvatars.js +4 -3
  91. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  92. package/kits/hub-game/code/client/grab.js +121 -50
  93. package/kits/hub-game/code/client/holdShow.js +19 -0
  94. package/kits/hub-game/code/client/hookLayer.js +96 -12
  95. package/kits/hub-game/code/client/hubControls.js +7 -1
  96. package/kits/hub-game/code/client/hudSurface.js +11 -3
  97. package/kits/hub-game/code/client/hudTree.js +7 -4
  98. package/kits/hub-game/code/client/idle.js +21 -3
  99. package/kits/hub-game/code/client/invites.js +24 -3
  100. package/kits/hub-game/code/client/keys.js +15 -0
  101. package/kits/hub-game/code/client/labelsNear.js +8 -1
  102. package/kits/hub-game/code/client/layoutCache.js +57 -8
  103. package/kits/hub-game/code/client/loadingCover.js +53 -4
  104. package/kits/hub-game/code/client/menuIcons.js +15 -0
  105. package/kits/hub-game/code/client/menuRows.js +8 -2
  106. package/kits/hub-game/code/client/menuSurface.js +102 -0
  107. package/kits/hub-game/code/client/menuTree.js +135 -0
  108. package/kits/hub-game/code/client/modelLook.js +41 -0
  109. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  110. package/kits/hub-game/code/client/pickerTree.js +163 -0
  111. package/kits/hub-game/code/client/pushVisit.js +4 -2
  112. package/kits/hub-game/code/client/quality.js +188 -29
  113. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  114. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  115. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  116. package/kits/hub-game/code/client/rehello.js +75 -0
  117. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  118. package/kits/hub-game/code/client/replay.js +118 -0
  119. package/kits/hub-game/code/client/role.js +3 -0
  120. package/kits/hub-game/code/client/safeLayout.js +441 -56
  121. package/kits/hub-game/code/client/safeStyle.js +13 -10
  122. package/kits/hub-game/code/client/say.js +2 -0
  123. package/kits/hub-game/code/client/soundSurface.js +77 -0
  124. package/kits/hub-game/code/client/soundTree.js +74 -0
  125. package/kits/hub-game/code/client/soundscape.js +12 -9
  126. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  127. package/kits/hub-game/code/client/state.js +67 -1
  128. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  129. package/kits/hub-game/code/client/stuckTree.js +67 -0
  130. package/kits/hub-game/code/client/talk.js +42 -12
  131. package/kits/hub-game/code/client/talkTree.js +4 -2
  132. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  133. package/kits/hub-game/code/client/textAskTree.js +67 -0
  134. package/kits/hub-game/code/client/tiers.js +252 -27
  135. package/kits/hub-game/code/client/together.js +4 -1
  136. package/kits/hub-game/code/client/uiDom.js +86 -8
  137. package/kits/hub-game/code/client/uiTree.js +33 -4
  138. package/kits/hub-game/code/client/vehicle.js +75 -52
  139. package/kits/hub-game/code/client/weakestTier.js +75 -31
  140. package/kits/hub-game/code/client/wear.js +159 -5
  141. package/kits/hub-game/code/client/worldLabels.js +215 -26
  142. package/kits/hub-game/code/companionSpec.js +4 -2
  143. package/kits/hub-game/code/server/act.js +3 -0
  144. package/kits/hub-game/code/server/actGate.js +83 -0
  145. package/kits/hub-game/code/server/actions.js +71 -15
  146. package/kits/hub-game/code/server/actors.js +20 -5
  147. package/kits/hub-game/code/server/analytics.js +40 -15
  148. package/kits/hub-game/code/server/ask.js +39 -3
  149. package/kits/hub-game/code/server/ballot.js +167 -4
  150. package/kits/hub-game/code/server/celebrate.js +64 -0
  151. package/kits/hub-game/code/server/companion.js +17 -2
  152. package/kits/hub-game/code/server/decor.js +11 -2
  153. package/kits/hub-game/code/server/disguise.js +63 -0
  154. package/kits/hub-game/code/server/doorAnalytics.js +2 -5
  155. package/kits/hub-game/code/server/earned.js +6 -2
  156. package/kits/hub-game/code/server/friendBests.js +13 -4
  157. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  158. package/kits/hub-game/code/server/grab.js +12 -2
  159. package/kits/hub-game/code/server/heldOffers.js +142 -0
  160. package/kits/hub-game/code/server/holdShow.js +98 -0
  161. package/kits/hub-game/code/server/hub.js +854 -45
  162. package/kits/hub-game/code/server/idle.js +110 -9
  163. package/kits/hub-game/code/server/index.js +9 -0
  164. package/kits/hub-game/code/server/labels.js +13 -3
  165. package/kits/hub-game/code/server/loadAbandon.js +2 -5
  166. package/kits/hub-game/code/server/manifest.js +94 -6
  167. package/kits/hub-game/code/server/menu.js +26 -3
  168. package/kits/hub-game/code/server/npcs.js +55 -9
  169. package/kits/hub-game/code/server/observe.js +67 -6
  170. package/kits/hub-game/code/server/players.js +8 -1
  171. package/kits/hub-game/code/server/replay.js +135 -0
  172. package/kits/hub-game/code/server/storageLimit.js +4 -1
  173. package/kits/hub-game/code/server/townDay.js +74 -0
  174. package/kits/hub-game/code/server/trackQueue.js +29 -0
  175. package/kits/hub-game/code/server/vehicle.js +3 -0
  176. package/kits/hub-game/code/server/vis.js +26 -4
  177. package/kits/hub-game/code/server/wallet.js +677 -0
  178. package/kits/hub-game/code/server/wear.js +13 -3
  179. package/kits/hub-game/code/server/writerLease.js +191 -0
  180. package/kits/hub-game/code/shared/act.js +1 -1
  181. package/kits/hub-game/code/shared/expression.js +6 -0
  182. package/kits/hub-game/code/shared/replay.js +37 -0
  183. package/kits/hub-game/code/systems/hub.js +437 -57
  184. package/kits/hub-game/docs/analytics.md +20 -3
  185. package/kits/hub-game/docs/contract.md +942 -99
  186. package/kits/hub-game/docs/home-pieces.md +5 -6
  187. package/kits/hub-game/docs/observed-progress.md +49 -1
  188. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  189. package/kits/hub-game/index.html +1 -0
  190. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  207. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  208. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  209. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  210. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  211. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  212. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  213. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  214. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  215. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  216. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  217. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  218. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  219. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  220. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  221. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  222. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  223. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  224. package/kits/hub-game/package-lock.json +3 -3
  225. package/kits/hub-game/package.json +4 -3
  226. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  227. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  228. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  229. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  230. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  231. package/kits/hub-game/scripts/pack.mjs +89 -23
  232. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  233. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  234. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  235. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  236. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  237. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  238. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  239. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  240. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  241. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  242. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  243. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  244. package/kits/hub-game/scripts/test-analytics.mjs +80 -1
  245. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  246. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  247. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  248. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  249. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  250. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  251. package/kits/hub-game/scripts/test-ballot.mjs +420 -3
  252. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  253. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  254. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  255. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  256. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  257. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  258. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  259. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  260. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  261. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  262. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  263. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  264. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  265. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  266. package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
  267. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  268. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  269. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  270. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  271. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  272. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  273. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  274. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  275. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  276. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  277. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  278. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  279. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  280. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  281. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  282. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  283. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  284. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  285. package/kits/hub-game/scripts/test-hub-ops.mjs +147 -0
  286. package/kits/hub-game/scripts/test-hub-trip.mjs +260 -5
  287. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  288. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  289. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  290. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  291. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  292. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  293. package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
  294. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  295. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  296. package/kits/hub-game/scripts/test-menu-client.mjs +55 -6
  297. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  298. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  299. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  300. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  301. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  302. package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
  303. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  304. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  305. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  306. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  307. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  308. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  309. package/kits/hub-game/scripts/test-rehello.mjs +237 -0
  310. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  311. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  312. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  313. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  314. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  315. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  316. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  317. package/kits/hub-game/scripts/test-resync.mjs +13 -0
  318. package/kits/hub-game/scripts/test-role-client.mjs +10 -3
  319. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  320. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  321. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  322. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  323. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  324. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  325. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  326. package/kits/hub-game/scripts/test-stuck.mjs +31 -0
  327. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  328. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  329. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  330. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  331. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  332. package/kits/hub-game/scripts/test-together.mjs +11 -0
  333. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  334. package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
  335. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  336. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  337. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  338. package/kits/hub-game/scripts/test-vehicle-client.mjs +77 -1
  339. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  340. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  341. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  342. package/kits/hub-game/scripts/test-world-labels.mjs +380 -0
  343. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  344. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  345. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  346. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  347. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  348. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +48 -2
  349. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +21 -3
  350. package/kits/multiplayer-3d/castle.json +5 -5
  351. package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
  352. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  353. package/kits/multiplayer-3d/code/server/world.js +19 -4
  354. package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
  355. package/kits/multiplayer-3d/package-lock.json +1 -1
  356. package/kits/multiplayer-3d/package.json +2 -1
  357. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  358. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  359. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  360. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
  361. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  362. package/kits/physics-2d/castle.json +2 -2
  363. package/kits/physics-2d/engine/scene.js +10 -2
  364. package/kits/physics-3d/CLAUDE.md +14 -0
  365. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  366. package/kits/physics-3d/castle.json +3 -3
  367. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  368. package/kits/physics-3d/docs/engine-player.md +76 -0
  369. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  370. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  371. package/kits/physics-3d/engine3d/gait.js +16 -8
  372. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  373. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  374. package/kits/physics-3d/engine3d/look.js +110 -17
  375. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  376. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  377. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  378. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  379. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  380. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  381. package/kits/physics-3d/engine3d/optimize.js +20 -9
  382. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  383. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  384. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  385. package/kits/physics-3d/engine3d/world3d.js +211 -17
  386. package/kits/physics-3d/package-lock.json +1 -1
  387. package/kits/physics-3d/package.json +2 -1
  388. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  389. package/kits/physics-3d/scripts/render.mjs +56 -8
  390. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  391. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  392. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  393. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  394. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  395. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  396. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  397. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  398. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  399. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  400. package/kits/physics-3d/systems/physics3d.js +51 -2
  401. package/kits/real-time/castle.json +2 -2
  402. package/kits/real-time/code/client/connection.js +3 -0
  403. package/package.json +2 -2
  404. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -0,0 +1,110 @@
1
+ // Vehicle preset v1.160: real model build, controller seam, seats and cleanup.
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import { register } from 'node:module';
5
+ import { Group, PerspectiveCamera, Raycaster } from 'three';
6
+ const root = new URL('../../', import.meta.url).href;
7
+ register(`data:text/javascript,${encodeURIComponent(`
8
+ export async function resolve(specifier, context, next) {
9
+ if (specifier === '@imports/castle.physics-2d/engine/art') return { url: 'data:text/javascript,export const renderArtFrame=()=>null;export const artReady=()=>false;export const artFrameCount=()=>0;', shortCircuit: true };
10
+ if (specifier.startsWith('@imports/')) {
11
+ const file = specifier.replace('@imports/castle.', '');
12
+ return { url: ${JSON.stringify(root)} + file + (file.endsWith('.js') ? '' : '.js'), shortCircuit: true };
13
+ }
14
+ try {return await next(specifier, context);} catch(e) {
15
+ if (specifier.startsWith('.') && !specifier.endsWith('.js')) return next(specifier + '.js', context);
16
+ throw e;
17
+ }
18
+ }
19
+ `)}`);
20
+ const { makeReplay, replays, sampleTrace } = await import('../code/client/replay.js');
21
+ const { clear } = await import('../code/client/state.js');
22
+ const trace = { v: 1, step: 250, ms: 400, poses: [0, 100, 0, 170, 100, 200, 200, -170, 300, 300, 400, -150] };
23
+ const near = (a, b) => assert.ok(Math.abs(a - b) < 1e-8, `${a} ≈ ${b}`);
24
+ assert.deepEqual(sampleTrace(trace, -5), { x: 0, y: 1, z: 0, yaw: 170 });
25
+ assert.deepEqual(sampleTrace(trace, 125), { x: .5, y: 1.5, z: 1, yaw: -180 });
26
+ assert.deepEqual(sampleTrace(trace, 325), { x: 2, y: 2.5, z: 3, yaw: -160 });
27
+ assert.deepEqual(sampleTrace(trace, 900), { x: 3, y: 3, z: 4, yaw: -150 });
28
+ assert.deepEqual(sampleTrace({ ...trace, ms: 250 }, 250), { x: 3, y: 3, z: 4, yaw: -150 });
29
+ const model = JSON.stringify({ format: 'pxmodel', look: { outline: 0, ao: 0, rim: 0 }, parts: [
30
+ { id: 'paint', kind: 'box', width: 1, height: 1, depth: 1, color: '#00ff00' },
31
+ ] });
32
+ function boot() {
33
+ return { sceneKey: 1, currentScenePath: 'main', three: { scene: new Group(), nodes: new Map() },
34
+ files: { 'look.pxmodel': model }, getActor: id => id === 'look' ? { components: { Model: { file: 'look.pxmodel', scale: 2 } } } : null,
35
+ multiplayer: { generation: 1, net: { closed: () => false, status: () => ({ state: 'connected' }) } } };
36
+ }
37
+ function flags(group) {
38
+ group.traverse(o => {
39
+ assert.equal(o.castShadow, false); assert.equal(o.receiveShadow, false);
40
+ const hits = []; o.raycast(new Raycaster(), hits); assert.deepEqual(hits, []);
41
+ for (const m of [o.material].flat()) if (m) {
42
+ assert.equal(m.transparent, true); near(m.opacity, m.userData?.label ? .95 : .4); assert.equal(m.depthWrite, false);
43
+ }
44
+ });
45
+ }
46
+ {
47
+ const s = boot(), r = makeReplay();
48
+ r.receive(s, 0, { trace }, 1000);
49
+ assert.equal(s.three.scene.children.length, 1); flags(s.three.scene.children[0]);
50
+ const first = s.three.scene.children[0]; let geometryDisposed = 0, materialDisposed = 0;
51
+ first.traverse(o => { o.geometry?.addEventListener('dispose', () => geometryDisposed++); for (const m of [o.material].flat()) m?.addEventListener('dispose', () => materialDisposed++); });
52
+ r.frame(s, 1125); near(first.position.x, .5); near(first.rotation.y, -Math.PI);
53
+ r.receive(s, 1, { trace }, 1000); assert.equal(s.three.scene.children.length, 2);
54
+ r.receive(s, 2, { trace }, 1000); assert.equal(s.three.scene.children.length, 2);
55
+ // Malformed optional fields allocate nothing (a NaN offset would never expire).
56
+ for (const bad of [{ offsetMs: 'bad' }, { offsetMs: -1 }, { offsetMs: trace.ms + 1 }, { label: 7 }, { label: ' ' }, { label: 'x'.repeat(25) }, { color: 'red' }, { look: 3 }]) {
57
+ r.receive(s, 0, { trace, ...bad }, 1000); assert.equal(s.three.scene.children.length, 2);
58
+ }
59
+ r.receive(s, 0, { trace, offsetMs: 250, color: '#ffffff' }, 1125);
60
+ assert.equal(s.three.scene.children.length, 2); assert.equal(first.parent, null); assert.equal(geometryDisposed, 2); assert.ok(materialDisposed);
61
+ const replacement = s.three.scene.children.at(-1); near(replacement.position.x, 1);
62
+ r.receive(s, 1, null, 1125); assert.equal(s.three.scene.children.length, 1);
63
+ r.frame(s, 1775); near(replacement.position.x, 3); near(replacement.children[0].material.opacity, .2);
64
+ r.frame(s, 2275); assert.equal(s.three.scene.children.length, 0);
65
+ r.clear();
66
+ }
67
+ {
68
+ // Real cached Model build. Per-copy translucent materials, shared geometry,
69
+ // and reference-counted release: removing one never breaks the other.
70
+ const s = boot(), r = makeReplay();
71
+ r.receive(s, 0, { trace, look: 'look' }, 0); r.receive(s, 1, { trace, look: 'look' }, 0);
72
+ assert.equal(s.three.scene.children.length, 2);
73
+ const [a, b] = s.three.scene.children;
74
+ flags(a); flags(b); assert.equal(a.children[0].scale.x, 2);
75
+ const meshes = g => { const out = []; g.traverse(o => { if (o.isMesh) out.push(o); }); return out; };
76
+ const ma = meshes(a)[0], mb = meshes(b)[0];
77
+ assert.equal(ma.geometry, mb.geometry); assert.notEqual(ma.material, mb.material);
78
+ let released = 0; ma.geometry.addEventListener('dispose', () => released++);
79
+ r.receive(s, 0, null, 0); assert.equal(released, 0); flags(b);
80
+ r.clear(); assert.ok(released > 0); assert.equal(s.three.scene.children.length, 0);
81
+ }
82
+ for (const change of [s => s.sceneKey++, s => {s.currentScenePath = 'next';}, s => s.multiplayer.generation++, s => {s.multiplayer.net = {};}, s => {s.multiplayer.net.closed = () => true;}]) {
83
+ const s = boot(), r = makeReplay(); r.receive(s, 0, { trace }, 0); change(s); r.frame(s, 10); assert.equal(s.three.scene.children.length, 0);
84
+ }
85
+ {
86
+ const s = boot(); replays.receive(s, 0, { trace }, 0); replays.receive(s, 1, { trace }, 0);
87
+ clear(); assert.equal(s.three.scene.children.length, 0);
88
+ replays.receive(s, 0, { trace }, 0); replays.frame(boot(), 1); assert.equal(s.three.scene.children.length, 0);
89
+ }
90
+ {
91
+ // Simple kit-owned sprite label with owned texture/material cleanup.
92
+ const realDocument = globalThis.document;
93
+ globalThis.document = { createElement: () => ({ getContext: () => ({ fillText() {}, strokeText() {} }) }) };
94
+ try {
95
+ const s = boot(), r = makeReplay(); r.receive(s, 0, { trace, label: 'Your best' }, 0);
96
+ const label = s.three.scene.children[0].children.find(o => o.isSprite); assert.ok(label); flags(label);
97
+ // The label stays readable over a faint figure and is never tinted.
98
+ assert.equal(label.material.opacity, .95);
99
+ let textures = 0; label.material.map.addEventListener('dispose', () => textures++); r.clear(); assert.equal(textures, 1);
100
+ } finally { if (realDocument === undefined) delete globalThis.document; else globalThis.document = realDocument; }
101
+ }
102
+ // Lifecycle integration must include travel/reset, scene disposal and fresh hello.
103
+ for (const [file, expected] of [['../code/client/hookLayer.js', ["case 'hub-replay':", 'replayCleanup.receive(scene, msg.slot, msg.replay)', 'replayCleanup.clear()', "if (msg.k === 'w' && msg.again !== 1) {replayCleanup.clear();}"]],
104
+ ['../code/client/state.js', ['replayCleanup.clear();']],
105
+ ['../code/client/replay.js', ['replayCleanup.receive = replays.receive;']],
106
+ ['../code/systems/hub.js', ['replays.frame(s)', 'if (!again) {this.clearReplays?.();}', 'replays.clear()']]]) {
107
+ const source = fs.readFileSync(new URL(file, import.meta.url), 'utf8');
108
+ for (const needle of expected) assert.ok(source.includes(needle), needle);
109
+ }
110
+ console.log('replay client: interpolation/yaw/final interval, lifecycle/slots, real cached look, translucent/no-picking, label and resource cleanup passed');
@@ -0,0 +1,178 @@
1
+ // Vehicle preset v1.160: real hub layer, fake transport/body, no Rapier needed.
2
+ import assert from 'node:assert/strict';
3
+ import { register } from 'node:module';
4
+ const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
5
+ register(`data:text/javascript,${encodeURIComponent(`
6
+ export async function resolve(specifier, context, next) {
7
+ if (specifier === './replay.js' && context.parentURL.endsWith('?without-replay')) return { url: 'data:text/javascript,export function tick(){};export function forget(){};export function end(){};', shortCircuit: true };
8
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(sceneStub))}, shortCircuit: true };
9
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/players.js') return { url: 'data:text/javascript,export function setPose(sim,id,msg){sim.reports.push([id,msg])}', shortCircuit: true };
10
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/limits.js') return { url: 'data:text/javascript,export const readPoint=()=>null', shortCircuit: true };
11
+ return next(specifier, context);
12
+ }
13
+ `)}`);
14
+ const { layer } = await import('../code/server/hub.js');
15
+ const { layer: baselineLayer } = await import('../code/server/hub.js?without-replay');
16
+ const { hubPlayers } = await import('../code/server/players.js');
17
+ const { cleanTrace } = await import('../code/shared/replay.js');
18
+ const Replay = await import('../code/server/replay.js');
19
+ let clock = 1_800_000_000_000;
20
+ const realNow = Date.now;
21
+ Date.now = () => clock;
22
+ function boot({ retained = false, count = 3, control = false } = {}) {
23
+ globalThis.__hubTestActors = [
24
+ { id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
25
+ { id: 'car', components: { Model: { file: 'car.pxmodel' }, Transform: {} } },
26
+ { id: 'bench', components: { HubSeat: {}, Transform: {}, Shape: { kind: 'box', height: 0.3 } } },
27
+ { id: 'door', components: { HubDoor: { id: 'game', to: 'game' }, Transform: {} } },
28
+ ];
29
+ const sent = [], broadcast = [], left = [];
30
+ const players = Array.from({ length: count }, (_, i) => ({ playerId: `p${i + 1}`, username: `user${i}`, userId: `${i + 1}` }));
31
+ const session = { sessionId: 'dev', players: [...players], send: (id, msg) => sent.push([id, msg]), broadcast: msg => broadcast.push(msg) };
32
+ const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
33
+ const sim = { timeMs: 0, scenePath: retained ? 'scenes/game.scene' : 'scenes/main.scene', players: new Map(players.map(p => [p.playerId, body()])), objects: new Map(), bodies: new Map(), reports: [] };
34
+ let hub;
35
+ const opts = { title: 'Town', contract: 1, stuck: true, idle: { seats: true, sounds: ['sounds/horn.wav'] }, places: { game: { title: 'Game', scene: 'scenes/game.scene', result: {}, ...(retained ? { resume: { keep: true } } : {}) } } };
36
+ if (retained) {session.place = 'game'; opts.places.game.idle = opts.idle;}
37
+ // resolvePlace reads session's authoritative place field.
38
+ const hooks = { ready(ctx) {hub = ctx;}, leave(ctx, id) {left.push(id);} };
39
+ const server = (control ? baselineLayer : layer)({ server: { maxPlayers: Math.max(8, count) }, hub: opts }, hooks, { game: hooks }, () => true);
40
+ server.sceneFor(session); server.ready(sim);
41
+ const say = (id, data) => server.message(session, { playerId: id }, data);
42
+ const tick = (ms = 50) => {sim.timeMs += ms; clock += ms; server.place(sim); server.step(sim, []);};
43
+ players.forEach(p => say(p.playerId, { k: 'hub-hello', avatar: 0, party: 1 }));
44
+ tick(2000); tick(5000);
45
+ for (const p of sim.players.values()) {p.at = { x: 0, y: 1, z: 0 };}
46
+ const drop = id => {session.players.splice(session.players.findIndex(p => p.playerId === id), 1); sim.players.delete(id);};
47
+ const back = id => {session.players.push(players.find(p => p.playerId === id)); sim.players.set(id, body()); say(id, { k: 'hub-hello', avatar: 0, party: 1, resume: true });};
48
+ return { hub, server, sim, session, sent, broadcast, say, tick, drop, back, left };
49
+ }
50
+ const trace = (ms = 500) => ({ v: 1, step: 250, ms, poses: Array.from({ length: Math.ceil(ms / 250) + 1 }, (_, i) => [i * 100, 100, 0, 0]).flat() });
51
+ const messages = r => r.sent.filter(([, m]) => m.k === 'hub-replay');
52
+ let tests = 0;
53
+ function test(name, fn) { fn(); tests++; console.log(`ok: ${name}`); }
54
+ try {
55
+ test('strict trace and spec validation, immutable copies, no change on refusal', () => {
56
+ const r = boot(), t = trace();
57
+ assert.equal(r.hub.replay('p1', 0, { trace: t, label: ' Best ', color: '#AABBCC', look: 'car' }), true);
58
+ const sent = messages(r)[0][1].replay;
59
+ assert.equal(sent.label, 'Best'); assert.equal(sent.color, '#aabbcc');
60
+ t.poses[0] = 999; assert.equal(sent.trace.poses[0], 0);
61
+ for (const bad of [null, {}, { ...trace(), v: 2 }, { ...trace(), step: 251 }, { ...trace(), ms: 600001 }, { ...trace(), ms: 1.5 }, { ...trace(), ms: 10000 },
62
+ { ...trace(), extra: 1 }, { ...trace(), poses: [] }, { ...trace(), poses: [0, 0, 0, 0] }, { ...trace(), poses: Array(772).fill(0) },
63
+ ...[NaN, Infinity, 1.2, 100001, Number.MAX_SAFE_INTEGER + 1].map(n => ({ ...trace(), poses: [n, 0, 0, 0, 0, 0, 0, 0] })),
64
+ ...[-181, 180].map(n => ({ ...trace(250), poses: [0, 0, 0, n, 0, 0, 0, 0] }))]) {
65
+ assert.equal(cleanTrace(bad), null);
66
+ assert.equal(r.hub.replay('p1', 0, { trace: bad }), false);
67
+ }
68
+ for (const extra of [{ label: '' }, { label: 'x'.repeat(25) }, { label: '\u0001' }, { label: '\u0085' }, { color: 'red' }, { offsetMs: -1 }, { offsetMs: 501 }, { offsetMs: 1.1 }, { look: 'bench' }, { nope: 1 }]) {
69
+ assert.equal(r.hub.replay('p1', 0, { trace: trace(), ...extra }), false);
70
+ }
71
+ assert.equal(r.hub.replay('unknown', 0, { trace: trace() }), false);
72
+ assert.equal(r.hub.replay('p1', 2, { trace: trace() }), false);
73
+ assert.equal(messages(r).length, 1);
74
+ assert.ok(Replay.cleanReplay({ actors: [] }, { trace: trace(), label: '🐱'.repeat(24), offsetMs: 500 }));
75
+ });
76
+ test('records server pose, integer cm/yaw, final sample and fresh JSON', () => {
77
+ const r = boot(), b = r.sim.players.get('p1');
78
+ assert.equal(r.hub.record('p1', 'stop'), null);
79
+ b.at = { x: 1.234, y: -2.345, z: .006 }; b.facing = 3 * Math.PI;
80
+ assert.equal(r.hub.record('p1', 'start'), true);
81
+ r.say('p1', { k: 'deck-pose', at: { x: 999 } });
82
+ r.sim.timeMs += 300; b.at = { x: 2, y: 3, z: 4 }; b.facing = -Math.PI / 2;
83
+ const t = r.hub.record('p1', 'stop');
84
+ assert.deepEqual(t, { v: 1, step: 250, ms: 300, poses: [123, -235, 1, -180, 200, 300, 400, -90] });
85
+ assert.equal(Object.getPrototypeOf(t), Object.prototype);
86
+ assert.deepEqual(JSON.parse(JSON.stringify(t)), t);
87
+ t.poses[0] = 999; assert.equal(r.hub.record('p1', 'stop'), null);
88
+ r.hub.record('p1', 'start'); assert.equal(r.hub.record('p1', 'stop'), null);
89
+ r.hub.record('p1', 'start'); r.sim.timeMs += 10; assert.equal(r.hub.record('p1', 'stop').poses.length, 8);
90
+ r.hub.record('p1', 'start'); assert.equal(r.hub.record('p1', 'cancel'), true); assert.equal(r.hub.record('p1', 'stop'), null);
91
+ r.hub.record('p1', 'start'); r.sim.timeMs += 333.333333; assert.equal(r.hub.record('p1', 'stop').ms, 333);
92
+ });
93
+ test('samples on kit cadence, bounded decimation preserves the start and doubles step', () => {
94
+ const h = { players: new Map([['p', { hello: true, arrived: true, arrivedAt: 0 }]]), session: { players: [{ playerId: 'p' }] }, sim: { timeMs: 0, players: new Map([['p', { at: { x: 0, y: 1, z: 0 }, facing: 0 }]]) } };
95
+ Replay.record(h, 'p', 'start');
96
+ for (let t = 250; t <= 600000; t += 250) {
97
+ h.sim.timeMs = t; h.sim.players.get('p').at.x = t / 1000;
98
+ Replay.tick(h);
99
+ const r = h.recordings.get('p'); assert.ok(r.poses.length <= 768);
100
+ if (t === 48000) {assert.equal(r.step, 500); assert.equal(r.poses[4], 50);}
101
+ }
102
+ const t = Replay.record(h, 'p', 'stop'); assert.ok(t); assert.equal(t.ms, 600000); assert.equal(t.step, 4000);
103
+ assert.equal(t.poses[0], 0); assert.equal(t.poses.at(-4), 60000);
104
+ Replay.record(h, 'p', 'start'); h.sim.timeMs += 600001; assert.equal(Replay.record(h, 'p', 'stop'), null);
105
+ Replay.record(h, 'p', 'start'); h.sim.timeMs += 600001; Replay.tick(h); assert.equal(h.recordings.size, 0);
106
+ });
107
+ test('nonfinite/out-of-bounds authoritative poses abort; max eight present recordings', () => {
108
+ for (const bad of [NaN, Infinity, 1000.001, -1000.001]) {
109
+ const r = boot(); r.hub.record('p1', 'start'); r.sim.players.get('p1').at.x = bad; r.tick(250); assert.equal(r.hub.record('p1', 'stop'), null);
110
+ }
111
+ const r = boot({ count: 9 });
112
+ for (let i = 1; i <= 8; i++) assert.equal(r.hub.record(`p${i}`, 'start'), true);
113
+ assert.equal(r.hub.record('p9', 'start'), false); r.hub.record('p1', 'cancel'); assert.equal(r.hub.record('p9', 'start'), true);
114
+ });
115
+ test('leave, identity, anonymous flag, body and arrival fences cancel traces and clear private slots', () => {
116
+ for (const change of [r => r.drop('p1'), r => {r.session.players[0].userId = 'else';}, r => {r.session.players[0].isAnonymous = true;},
117
+ r => {r.sim.players.set('p1', { ...r.sim.players.get('p1') });},
118
+ r => r.hub.go('game', ['p1']), r => r.hub.end(['p1'])]) {
119
+ const r = boot(); r.hub.record('p1', 'start'); r.hub.replay('p1', 0, { trace: trace() }); change(r); r.tick(250);
120
+ assert.equal(r.hub.record('p1', 'stop'), null); const previous = messages(r).length; r.tick(4000); assert.equal(messages(r).filter(([, m]) => m.replay).length, 1);
121
+ assert.ok(messages(r).length >= previous);
122
+ }
123
+ // Direct fixture permits an arrival-generation change without teleporting.
124
+ const sent = [], h = { actors: [], players: new Map([['p', { hello: true, arrived: true, arrivedAt: 0 }]]), session: { players: [{ playerId: 'p' }], send: (id, m) => sent.push(m) }, sim: { timeMs: 0, players: new Map([['p', { at: { x: 0, y: 1, z: 0 }, facing: 0 }]]) } };
125
+ Replay.record(h, 'p', 'start'); Replay.replay(h, 'p', 0, { trace: trace() }); h.players.get('p').arrivedAt = 2; h.sim.timeMs = 250; Replay.tick(h);
126
+ assert.equal(Replay.record(h, 'p', 'stop'), null); assert.equal(sent.at(-1).replay, null); assert.equal(h.replays.size, 0);
127
+ });
128
+ test('a transport leave ends recording and ghosts even when the body is kept', () => {
129
+ const r = boot(); r.hub.record('p1', 'start'); r.hub.replay('p1', 0, { trace: trace() }); r.tick(250);
130
+ r.server.replayDeparted(r.session, { playerId: 'p1' }); r.tick(250);
131
+ assert.equal(r.hub.record('p1', 'stop'), null);
132
+ const other = boot(); other.server.replayDeparted(other.session, { playerId: 'p1' }); assert.equal(other.hub.record('p1', 'start'), true);
133
+ });
134
+ test('retained short drop between ticks and fresh hello never resend stale ghosts', () => {
135
+ for (const retained of [false, true]) {
136
+ const r = boot({ retained }); r.hub.record('p1', 'start'); r.hub.replay('p1', 0, { trace: trace() });
137
+ // No transport hook: the fresh hello and the body/roster fence clear it.
138
+ r.drop('p1'); r.back('p1'); r.tick(250);
139
+ assert.equal(r.hub.record('p1', 'stop'), null);
140
+ assert.equal(messages(r).filter(([, m]) => m.replay).length, 1);
141
+ }
142
+ });
143
+ test('private bytes never enter join, snapshot/delta, broadcast, actors or second/late viewers', () => {
144
+ const r = boot(), join = JSON.stringify(r.server.join()); r.server.delta();
145
+ r.hub.replay('p1', 0, { trace: trace() }); r.hub.replay('p1', 1, { trace: trace(), label: 'Secret' });
146
+ assert.equal(JSON.stringify(r.server.join()), join); assert.equal(r.server.delta(), null);
147
+ r.session.players.push({ playerId: 'late', userId: '123' }); r.sim.players.set('late', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
148
+ r.say('late', { k: 'hub-hello', avatar: 0, party: 1 }); r.tick(2000);
149
+ assert.deepEqual(new Set(messages(r).map(([id]) => id)), new Set(['p1']));
150
+ for (const [id, msg] of r.sent) if (id !== 'p1') assert.ok(!JSON.stringify(msg).includes('hub-replay'));
151
+ assert.ok(!JSON.stringify([r.server.join(), r.server.delta(), r.broadcast]).includes('hub-replay'));
152
+ assert.equal(r.sim.players.size, 4); assert.equal(r.sim.objects.size, 0);
153
+ });
154
+ test('rolling rate limit, explicit null, offset expiry and shutdown', () => {
155
+ const r = boot();
156
+ for (let i = 0; i < 4; i++) assert.equal(r.hub.replay('p1', i % 2, { trace: trace(), offsetMs: 250 }), true);
157
+ assert.equal(r.hub.replay('p1', 0, { trace: trace() }), false); r.sim.timeMs += 999;
158
+ assert.equal(r.hub.replay('p1', 0, { trace: trace() }), false);
159
+ // Clears are never budgeted; an empty slot sends nothing.
160
+ assert.equal(r.hub.replay('p1', 0, null), true); assert.equal(messages(r).at(-1)[1].replay, null);
161
+ const count = messages(r).length;
162
+ assert.equal(r.hub.replay('p1', 0, null), true); assert.equal(messages(r).length, count);
163
+ r.sim.timeMs++;
164
+ assert.equal(r.hub.replay('p1', 0, { trace: trace(), offsetMs: 250 }), true);
165
+ r.tick(2251); assert.equal(messages(r).at(-1)[1].slot, 1); assert.equal(messages(r).at(-1)[1].replay, null);
166
+ r.tick(1000); assert.equal(messages(r).at(-1)[1].slot, 0); assert.equal(messages(r).at(-1)[1].replay, null);
167
+ r.hub.record('p1', 'start'); r.hub.replay('p1', 0, { trace: trace() }); r.server.shutdown();
168
+ assert.equal(r.hub.record('p1', 'stop'), null); assert.equal(messages(r).at(-1)[1].replay, null);
169
+ });
170
+ test('unused layer output is byte-identical with replay lifecycle removed', () => {
171
+ const capture = r => { r.server.delta(); r.tick(250); return JSON.stringify([r.sent, r.broadcast, r.server.join(), r.server.delta()]); };
172
+ const before = clock, a = capture(boot()); clock = before;
173
+ // The control follows the pre-v1.163 path: no replay calls at all.
174
+ const b = capture(boot({ control: true })); assert.equal(a, b);
175
+ const h = {}; Replay.tick(h); Replay.end(h); Replay.forget(h, 'p'); assert.deepEqual(h, {});
176
+ });
177
+ } finally { Date.now = realNow; }
178
+ console.log(`${tests} replay server tests passed`);
@@ -129,6 +129,19 @@ for (const ms of [30_000, 180_000]) {
129
129
  });
130
130
  }
131
131
 
132
+ test('v1.184: a held visit replays a solid private hide with its solid list', () => {
133
+ const r = boot();
134
+ assert.equal(r.hub.hide('job-cue', { to: ['p1'], solid: true }), true);
135
+ r.step();
136
+ r.drop();
137
+ r.away(30_000);
138
+ r.back();
139
+ const from = r.sent.length;
140
+ r.hello('p1', { resume: true });
141
+ r.step();
142
+ assert.deepEqual(to(r, 'hub-vis', from), [{ k: 'hub-vis', hide: ['boat-hull', 'boat-sail', 'job-cue'], show: [], solid: ['job-cue'] }]);
143
+ });
144
+
132
145
  test('expiry forgets both: the late return arrives afresh and gets its masks from arrive', () => {
133
146
  const r = boot();
134
147
  r.drop();
@@ -90,10 +90,15 @@ export default Object.fromEntries(Object.entries(callbacks).map(([key, value]) =
90
90
  [key, typeof value === 'function' ? (session, ...rest) => value(wrap(session), ...rest) : value]));
91
91
  `);
92
92
  await writeFile(path.join(dir, 'code/server/game.js'), `
93
+ // Server steps run: the kit records the pose a leave stores on a step.
94
+ let steps = 0;
93
95
  export default {
96
+ step() { steps += 1; },
94
97
  message(h, p, d) {
95
98
  if (d?.test === 'move') h.placeAt(p.playerId, ${JSON.stringify(cold)}, 40);
96
- if (d?.test) h.send(p.playerId, { test: d.test, pose: h.sim.players.get(p.playerId)?.at });
99
+ const body = h.sim.players.get(p.playerId);
100
+ // clamped: false once the server took a report from where the body stands.
101
+ if (d?.test) h.send(p.playerId, { test: d.test, pose: body && { ...body.at }, clamped: body?.clamped, steps });
97
102
  },
98
103
  };
99
104
  `);
@@ -108,11 +113,29 @@ export default {
108
113
  a.local = { ...spawn };
109
114
  a.reporting = true;
110
115
  await a.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
111
- await sleep(300);
112
- await query(a, 'move');
116
+ await world(a);
117
+ // Set up the pose under test without racing the browser-like reports. Until
118
+ // the server has taken one report from where the arrival left the body, it
119
+ // keeps marking that spot as a correction (clamped) in every snapshot, and a
120
+ // snapshot still on its way when the client moved on put the client back at
121
+ // the spawn; the client's next report then pulled the body there too (the
122
+ // movement clamp allows 0.6 m at once, and a whole spawn-to-spot walk after
123
+ // a stall). So: wait for the server to agree with the client at the spawn;
124
+ // this answer is read after every snapshot sent before it. Then the client
125
+ // stands at the moved spot from the moment it asks to be put there, so no
126
+ // report after the ask names the spawn (taking the spot up only on the
127
+ // reply let each spawn report in between pull the body back a step, and the
128
+ // clamped row sent back put the client there too: 0.6 to 1.2 m under load).
129
+ const agreed = await until(a, 'state', {}, s => s.clamped === false);
130
+ assert.equal(agreed.clamped, false, `server takes the client's reports at the spawn ${JSON.stringify(agreed)}`);
113
131
  a.local = { ...cold };
114
- await sleep(600);
115
- const before = (await query(a, 'state')).pose;
132
+ await query(a, 'move');
133
+ // Done when the server has taken a report from the moved spot and then run
134
+ // a step with the body there: the leave stores the pose its last step
135
+ // recorded, so a close before that step stored the spawn.
136
+ const near = s => s.clamped === false && Math.hypot(s.pose.x - cold.x, s.pose.z - cold.z) < 0.3;
137
+ const moved = await until(a, 'state', {}, near);
138
+ const before = (await until(a, 'state', {}, s => near(s) && s.steps > moved.steps)).pose;
116
139
  assert.ok(Math.hypot(before.x - cold.x, before.z - cold.z) < 0.3, `first visit stands at the moved spot ${JSON.stringify(before)}`);
117
140
  a.socket.close();
118
141
  await new Promise(resolve => a.socket.once('close', resolve));
@@ -155,6 +178,21 @@ export default {
155
178
  await server?.shutdown();
156
179
  await rm(dir, { recursive: true, force: true });
157
180
  }
181
+ // The client's starting WORLD (the frame that places its body; see connect).
182
+ function world(client) {
183
+ return client.wait(f => f.t === 'm' && [].concat(f.d?.batch ?? f.d).some(d => d?.k === 'w' && !d.again));
184
+ }
185
+ // Asks again until `done` holds or the deadline passes, then returns the last
186
+ // answer, so the caller's assertion still decides (and fails) on it.
187
+ async function until(client, test, extra, done, ms = 10000) {
188
+ const deadline = Date.now() + ms;
189
+ let answer = await query(client, test, extra);
190
+ while (!done(answer) && Date.now() < deadline) {
191
+ await sleep(50);
192
+ answer = await query(client, test, extra);
193
+ }
194
+ return answer;
195
+ }
158
196
  async function query(client, test, extra = {}) {
159
197
  client.send({ test, ...extra });
160
198
  return (await client.wait(f => f.t === 'm' && f.d?.test === test)).d;
@@ -180,4 +180,17 @@ async function strand(game) {
180
180
  assert.equal(Rehello.resumed(mp, net, at), 'world', 'a re-admission still is');
181
181
  }
182
182
 
183
+ // The tests above run the kits' source; a deck runs hub-game's pins. A pin from
184
+ // before the resync left the hook here with no client to ask for it: an iPhone
185
+ // back from a 180 s app switch kept the Act prompts the host dropped, and its
186
+ // Talk to Rowan never came (rota harness/server-after/not-acknowledged).
187
+ {
188
+ const { readFileSync } = await import('node:fs');
189
+ const imports = JSON.parse(readFileSync(new URL('../castle.json', import.meta.url), 'utf8')).imports;
190
+ const resyncSince = { 'castle.real-time': '2026-10-21T18:37:16.504Z', 'castle.multiplayer-3d': '2026-10-21T18:38:54.798Z' };
191
+ for (const [kit, since] of Object.entries(resyncSince)) {
192
+ assert.ok(Date.parse(imports[kit]?.version) >= Date.parse(since), `${kit} is pinned before its first resync publish (${since})`);
193
+ }
194
+ }
195
+
183
196
  console.log('test-resync: ok');
@@ -35,6 +35,7 @@ register(`data:text/javascript,${encodeURIComponent(hooks)}`);
35
35
  const THREE = await import('three');
36
36
  const Avatar = await import('../code/client/avatar.js');
37
37
  const Role = await import('../code/client/role.js');
38
+ const HoldShow = await import('../code/client/holdShow.js');
38
39
  const State = await import('../code/client/state.js');
39
40
  const hooksLayer = (await import('../code/client/hookLayer.js')).default;
40
41
  const { makeWear, makeEarned, makeRole } = await import('../code/client/wear.js');
@@ -183,7 +184,7 @@ test('system uses drawn-avatar fit and masks the live earned renderer, restoring
183
184
  const source = fs.readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
184
185
  const method = source.slice(source.indexOf(' applyWear(scene, local) {') + 2, source.indexOf(" // The place's tuning", source.indexOf(' applyWear(scene, local) {')));
185
186
  const Hub = { hub: State.hub };
186
- const apply = new Function('Hub', 'Avatar', 'AvatarCap', 'roleWearing', 'roleEarned', `return ({${method}}).applyWear`)(Hub, { ...Avatar, style: () => 'toon', current: () => 1 }, { shown: () => 2 }, Role.roleWearing, Role.roleEarned);
187
+ const apply = new Function('Hub', 'Avatar', 'AvatarCap', 'roleWearing', 'roleEarned', 'holdShowEarned', 'holdShowVisible', `return ({${method}}).applyWear`)(Hub, { ...Avatar, style: () => 'toon', current: () => 1 }, { shown: () => 2 }, Role.roleWearing, Role.roleEarned, HoldShow.holdShowEarned, HoldShow.holdShowVisible);
187
188
  const scene = sceneOf(); const draw = { wear: makeWear(), earned: makeEarned(), roles: makeRole() };
188
189
  for (const [cls, shape] of [['belt', 'belt-plain'], ['sash', 'sash-plain'], ['held', 'held-lantern'], ['pin', 'pin-round']]) {
189
190
  State.clear(); State.hub.earned.set('me', { class: cls, shape, color: '#abcdef' }); State.hub.roles.set('me', police);
@@ -240,11 +241,15 @@ test('role chips may overlap the viewer body but still clear HUD and controls; o
240
241
  const scene = sceneOf(), roles = new Map([['me', police], ['p2', doctor]]);
241
242
  const items = () => Role.roleItems(scene, scene.local, {}, {}, roles, (cam, x) => ({ x: 287 + x * 50, y: 72 }));
242
243
  const sign = { id: 'sign', x: 287, y: 121, text: 'Sign' };
243
- chrome.setLabels([...items(), sign]);
244
+ // `hub.mark` tags (a Plaster, a Ticket) over the viewer's own head and another's.
245
+ const marks = [{ id: 'mark:me', x: 287, y: 90, text: 'Plaster', color: '#f4efe6' }, { id: 'mark:p2', x: 400, y: 90, text: 'Ticket', color: '#f4c04d' }];
246
+ chrome.setLabels([...items(), sign, ...marks]);
244
247
  const own = dom.made.find((node) => node.textContent === 'Police');
245
248
  const remote = dom.made.find((node) => node.textContent === 'Doctor');
246
249
  const ordinary = dom.made.find((node) => node.textContent === 'Sign');
247
- for (const node of [own, remote, ordinary]) {
250
+ const ownMark = dom.made.find((node) => node.textContent === 'Plaster');
251
+ const remoteMark = dom.made.find((node) => node.textContent === 'Ticket');
252
+ for (const node of [own, remote, ordinary, ownMark, remoteMark]) {
248
253
  Object.defineProperty(node, 'rect', { get: () => {
249
254
  const x = parseFloat(node.style.left), y = parseFloat(node.style.top);
250
255
  return { left: x - 40, right: x + 40, top: y - 24, bottom: y };
@@ -255,6 +260,8 @@ test('role chips may overlap the viewer body but still clear HUD and controls; o
255
260
  assert.notEqual(own.style.visibility, 'hidden', 'own role belongs over the local body');
256
261
  assert.notEqual(remote.style.visibility, 'hidden', 'remote role may overlap the viewer body');
257
262
  assert.equal(ordinary.style.visibility, 'hidden');
263
+ assert.notEqual(ownMark.style.visibility, 'hidden', 'own timed tag is drawn over the local body');
264
+ assert.notEqual(remoteMark.style.visibility, 'hidden', 'remote tag may overlap the viewer body');
258
265
  roles.delete('me');
259
266
  chrome.setLabels([...items(), sign]); chrome.flushWorldLabels();
260
267
  assert.notEqual(remote.style.visibility, 'hidden', 'remote role may overlap the viewer body without the own chip');