castle-web-cli 0.4.239 → 0.4.241

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 (396) 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 +163 -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 +6 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +2 -0
  19. package/dist/platformDoc.js +3 -2
  20. package/dist/playPagePolicy.js +5 -1
  21. package/dist/resetLeaderboards.d.ts +8 -1
  22. package/dist/resetLeaderboards.js +43 -8
  23. package/dist/roomLogs.d.ts +1 -0
  24. package/dist/roomLogs.js +30 -6
  25. package/dist/save-deck.d.ts +32 -2
  26. package/dist/save-deck.js +240 -39
  27. package/kits/base/CLAUDE.md +1 -1
  28. package/kits/base/castle.json +1 -1
  29. package/kits/base/sdk/README.md +174 -6
  30. package/kits/base/sdk/analytics.d.ts +8 -0
  31. package/kits/base/sdk/analytics.js +92 -0
  32. package/kits/base/sdk/castle.d.ts +5 -1
  33. package/kits/base/sdk/castle.js +2 -0
  34. package/kits/base/sdk/commands.d.ts +48 -0
  35. package/kits/base/sdk/commands.js +1 -0
  36. package/kits/base/sdk/debugConsole.d.ts +17 -0
  37. package/kits/base/sdk/debugConsole.js +154 -0
  38. package/kits/base/sdk/experiments.js +24 -1
  39. package/kits/base/sdk/hostRetry.d.ts +7 -0
  40. package/kits/base/sdk/hostRetry.js +57 -0
  41. package/kits/base/sdk/hub.d.ts +20 -2
  42. package/kits/base/sdk/hub.js +99 -13
  43. package/kits/base/sdk/multiplayer.d.ts +2 -0
  44. package/kits/base/sdk/multiplayer.js +168 -26
  45. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  46. package/kits/base/sdk/reconnectBudget.js +41 -1
  47. package/kits/base/sdk/runtime.js +36 -19
  48. package/kits/base/sdk/server/hub.d.ts +19 -0
  49. package/kits/base/sdk/server/hub.js +12 -0
  50. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  51. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  52. package/kits/base/sdk/server/wrapper.js +26 -1
  53. package/kits/base/sdk/transport.d.ts +2 -1
  54. package/kits/base/sdk/transport.js +35 -0
  55. package/kits/hub-game/CLAUDE.md +66 -19
  56. package/kits/hub-game/code/client/act.js +9 -6
  57. package/kits/hub-game/code/client/actCore.js +26 -6
  58. package/kits/hub-game/code/client/actGateLog.js +36 -0
  59. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  60. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  61. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  62. package/kits/hub-game/code/client/askSurface.js +85 -0
  63. package/kits/hub-game/code/client/askTree.js +51 -0
  64. package/kits/hub-game/code/client/attention.js +31 -6
  65. package/kits/hub-game/code/client/ballot.js +42 -5
  66. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  67. package/kits/hub-game/code/client/ballotTree.js +180 -0
  68. package/kits/hub-game/code/client/catchingUp.js +19 -0
  69. package/kits/hub-game/code/client/celebrate.js +66 -0
  70. package/kits/hub-game/code/client/chrome.js +481 -57
  71. package/kits/hub-game/code/client/companion.js +93 -23
  72. package/kits/hub-game/code/client/companionDress.js +1 -1
  73. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  74. package/kits/hub-game/code/client/cornerTree.js +83 -0
  75. package/kits/hub-game/code/client/decor.js +20 -11
  76. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  77. package/kits/hub-game/code/client/disguise.js +23 -0
  78. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  79. package/kits/hub-game/code/client/dockSurface.js +206 -0
  80. package/kits/hub-game/code/client/dockTree.js +232 -0
  81. package/kits/hub-game/code/client/earned.js +29 -0
  82. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  83. package/kits/hub-game/code/client/emoteTree.js +264 -0
  84. package/kits/hub-game/code/client/farAvatars.js +4 -3
  85. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  86. package/kits/hub-game/code/client/grab.js +121 -50
  87. package/kits/hub-game/code/client/holdShow.js +19 -0
  88. package/kits/hub-game/code/client/hookLayer.js +96 -12
  89. package/kits/hub-game/code/client/hubControls.js +7 -1
  90. package/kits/hub-game/code/client/hudSurface.js +11 -3
  91. package/kits/hub-game/code/client/hudTree.js +7 -4
  92. package/kits/hub-game/code/client/idle.js +21 -3
  93. package/kits/hub-game/code/client/invites.js +24 -3
  94. package/kits/hub-game/code/client/keys.js +15 -0
  95. package/kits/hub-game/code/client/labelsNear.js +8 -1
  96. package/kits/hub-game/code/client/layoutCache.js +57 -8
  97. package/kits/hub-game/code/client/loadingCover.js +53 -4
  98. package/kits/hub-game/code/client/menuIcons.js +15 -0
  99. package/kits/hub-game/code/client/menuSurface.js +102 -0
  100. package/kits/hub-game/code/client/menuTree.js +135 -0
  101. package/kits/hub-game/code/client/modelLook.js +41 -0
  102. package/kits/hub-game/code/client/padCues.js +11 -7
  103. package/kits/hub-game/code/client/padReadability.js +3 -3
  104. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  105. package/kits/hub-game/code/client/pickerTree.js +163 -0
  106. package/kits/hub-game/code/client/pushVisit.js +4 -2
  107. package/kits/hub-game/code/client/quality.js +188 -29
  108. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  109. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  110. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  111. package/kits/hub-game/code/client/rehello.js +75 -0
  112. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  113. package/kits/hub-game/code/client/replay.js +118 -0
  114. package/kits/hub-game/code/client/role.js +3 -0
  115. package/kits/hub-game/code/client/safeLayout.js +441 -56
  116. package/kits/hub-game/code/client/safeStyle.js +13 -10
  117. package/kits/hub-game/code/client/say.js +2 -0
  118. package/kits/hub-game/code/client/soundSurface.js +77 -0
  119. package/kits/hub-game/code/client/soundTree.js +74 -0
  120. package/kits/hub-game/code/client/soundscape.js +12 -9
  121. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  122. package/kits/hub-game/code/client/state.js +67 -1
  123. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  124. package/kits/hub-game/code/client/stuckTree.js +67 -0
  125. package/kits/hub-game/code/client/talk.js +42 -12
  126. package/kits/hub-game/code/client/talkTree.js +4 -2
  127. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  128. package/kits/hub-game/code/client/textAskTree.js +67 -0
  129. package/kits/hub-game/code/client/tiers.js +252 -27
  130. package/kits/hub-game/code/client/together.js +4 -1
  131. package/kits/hub-game/code/client/uiDom.js +86 -8
  132. package/kits/hub-game/code/client/uiTree.js +33 -4
  133. package/kits/hub-game/code/client/vehicle.js +72 -51
  134. package/kits/hub-game/code/client/weakestTier.js +75 -31
  135. package/kits/hub-game/code/client/wear.js +159 -5
  136. package/kits/hub-game/code/client/worldLabels.js +205 -25
  137. package/kits/hub-game/code/companionSpec.js +4 -2
  138. package/kits/hub-game/code/server/act.js +3 -0
  139. package/kits/hub-game/code/server/actGate.js +83 -0
  140. package/kits/hub-game/code/server/actions.js +71 -15
  141. package/kits/hub-game/code/server/actors.js +20 -5
  142. package/kits/hub-game/code/server/analytics.js +35 -3
  143. package/kits/hub-game/code/server/ask.js +39 -3
  144. package/kits/hub-game/code/server/ballot.js +167 -4
  145. package/kits/hub-game/code/server/celebrate.js +64 -0
  146. package/kits/hub-game/code/server/companion.js +17 -2
  147. package/kits/hub-game/code/server/decor.js +11 -2
  148. package/kits/hub-game/code/server/disguise.js +63 -0
  149. package/kits/hub-game/code/server/earned.js +6 -2
  150. package/kits/hub-game/code/server/friendBests.js +13 -4
  151. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  152. package/kits/hub-game/code/server/grab.js +12 -2
  153. package/kits/hub-game/code/server/heldOffers.js +142 -0
  154. package/kits/hub-game/code/server/holdShow.js +98 -0
  155. package/kits/hub-game/code/server/hub.js +991 -72
  156. package/kits/hub-game/code/server/idle.js +110 -9
  157. package/kits/hub-game/code/server/index.js +9 -0
  158. package/kits/hub-game/code/server/labels.js +13 -3
  159. package/kits/hub-game/code/server/manifest.js +94 -6
  160. package/kits/hub-game/code/server/menu.js +26 -3
  161. package/kits/hub-game/code/server/npcs.js +55 -9
  162. package/kits/hub-game/code/server/observe.js +67 -6
  163. package/kits/hub-game/code/server/players.js +14 -2
  164. package/kits/hub-game/code/server/replay.js +135 -0
  165. package/kits/hub-game/code/server/standing.js +7 -3
  166. package/kits/hub-game/code/server/storageLimit.js +4 -1
  167. package/kits/hub-game/code/server/townDay.js +74 -0
  168. package/kits/hub-game/code/server/vehicle.js +3 -0
  169. package/kits/hub-game/code/server/vis.js +26 -4
  170. package/kits/hub-game/code/server/wallet.js +677 -0
  171. package/kits/hub-game/code/server/wear.js +13 -3
  172. package/kits/hub-game/code/server/writerLease.js +191 -0
  173. package/kits/hub-game/code/shared/act.js +1 -1
  174. package/kits/hub-game/code/shared/expression.js +6 -0
  175. package/kits/hub-game/code/shared/replay.js +37 -0
  176. package/kits/hub-game/code/systems/hub.js +429 -55
  177. package/kits/hub-game/docs/analytics.md +16 -2
  178. package/kits/hub-game/docs/contract.md +956 -101
  179. package/kits/hub-game/docs/home-pieces.md +5 -6
  180. package/kits/hub-game/docs/observed-progress.md +49 -1
  181. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  182. package/kits/hub-game/index.html +1 -0
  183. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  184. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  185. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  186. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  187. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  188. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  189. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  190. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  207. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  208. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  209. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  210. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  211. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  212. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  213. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  214. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  215. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  216. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  217. package/kits/hub-game/package-lock.json +3 -3
  218. package/kits/hub-game/package.json +4 -3
  219. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  220. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  221. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  222. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  223. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  224. package/kits/hub-game/scripts/pack.mjs +89 -23
  225. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  226. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  227. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  228. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  229. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  230. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  231. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  232. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  233. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  234. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  235. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  236. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  237. package/kits/hub-game/scripts/test-analytics.mjs +79 -0
  238. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  239. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  240. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  241. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  242. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  243. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  244. package/kits/hub-game/scripts/test-ballot.mjs +421 -4
  245. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  246. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  247. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  248. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  249. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  250. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  251. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  252. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  253. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  254. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  255. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  256. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  257. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  258. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  259. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  260. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  261. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  262. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  263. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  264. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  265. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  266. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  267. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  268. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  269. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  270. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  271. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  272. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  273. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  274. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  275. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  276. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  277. package/kits/hub-game/scripts/test-hub-ops.mjs +119 -0
  278. package/kits/hub-game/scripts/test-hub-trip.mjs +240 -4
  279. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  280. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  281. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  282. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  283. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  284. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  285. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  286. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  287. package/kits/hub-game/scripts/test-menu-client.mjs +54 -5
  288. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  289. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  290. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  291. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  292. package/kits/hub-game/scripts/test-pad-cues.mjs +39 -0
  293. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  294. package/kits/hub-game/scripts/test-placeat-server.mjs +648 -0
  295. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  296. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  297. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  298. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  299. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  300. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  301. package/kits/hub-game/scripts/test-rehello.mjs +242 -3
  302. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  303. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  304. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  305. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  306. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  307. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  308. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  309. package/kits/hub-game/scripts/test-role-client.mjs +2 -1
  310. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  311. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  312. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  313. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  314. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  315. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  316. package/kits/hub-game/scripts/test-standing.mjs +135 -2
  317. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  318. package/kits/hub-game/scripts/test-stuck.mjs +36 -1
  319. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  320. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  321. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  322. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  323. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  324. package/kits/hub-game/scripts/test-together.mjs +11 -0
  325. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  326. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  327. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  328. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  329. package/kits/hub-game/scripts/test-vehicle-client.mjs +68 -1
  330. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  331. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  332. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  333. package/kits/hub-game/scripts/test-world-labels.mjs +340 -0
  334. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  335. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  336. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  337. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  338. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  339. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +36 -2
  340. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +10 -2
  341. package/kits/multiplayer-3d/castle.json +5 -5
  342. package/kits/multiplayer-3d/code/client/resumeGate.js +66 -2
  343. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  344. package/kits/multiplayer-3d/code/server/world.js +19 -4
  345. package/kits/multiplayer-3d/code/systems/multiplayer.js +108 -18
  346. package/kits/multiplayer-3d/package-lock.json +1 -1
  347. package/kits/multiplayer-3d/package.json +2 -1
  348. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  349. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  350. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  351. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +417 -5
  352. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  353. package/kits/physics-2d/castle.json +2 -2
  354. package/kits/physics-2d/engine/scene.js +10 -2
  355. package/kits/physics-3d/CLAUDE.md +14 -0
  356. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  357. package/kits/physics-3d/castle.json +3 -3
  358. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  359. package/kits/physics-3d/docs/engine-player.md +76 -0
  360. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  361. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  362. package/kits/physics-3d/engine3d/gait.js +16 -8
  363. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  364. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  365. package/kits/physics-3d/engine3d/look.js +110 -17
  366. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  367. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  368. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  369. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  370. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  371. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  372. package/kits/physics-3d/engine3d/optimize.js +20 -9
  373. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  374. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  375. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  376. package/kits/physics-3d/engine3d/world3d.js +211 -17
  377. package/kits/physics-3d/package-lock.json +1 -1
  378. package/kits/physics-3d/package.json +2 -1
  379. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  380. package/kits/physics-3d/scripts/render.mjs +56 -8
  381. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  382. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  383. package/kits/physics-3d/scripts/test-coaxial-escape.mjs +176 -0
  384. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  385. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  386. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  387. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  388. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  389. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  390. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  391. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  392. package/kits/physics-3d/systems/physics3d.js +59 -2
  393. package/kits/real-time/castle.json +2 -2
  394. package/kits/real-time/code/client/connection.js +3 -0
  395. package/package.json +2 -2
  396. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -30,16 +30,29 @@ const stubs = {
30
30
  'export const connectSession = async (options) => { globalThis.__connect = options; return globalThis.__net; };',
31
31
  '@imports/castle.real-time/code/client/soloBadge.js': 'export const showSoloBadge = () => {}; export const updateSoloBadge = () => {};',
32
32
  '@imports/castle.real-time/code/client/joinOverlay.js':
33
- 'export const showJoinOverlay = (visible, text) => { globalThis.__cover = visible ? (text ?? "Joining…") : null; };',
33
+ // A cover with no words (a return's quiet first QUIET_RETURN_MS) is still a cover.
34
+ 'export const showJoinOverlay = (visible, text) => { globalThis.__cover = visible ? (text ?? "Joining…") || "(no words)" : null; };',
34
35
  '@imports/castle.real-time/code/client/gameHooks.js': 'export const game = {};',
35
36
  };
36
37
  register(
37
38
  `data:text/javascript,${encodeURIComponent(`
38
39
  import { readFile } from 'node:fs/promises';
40
+ import { existsSync } from 'node:fs';
41
+ import { fileURLToPath } from 'node:url';
39
42
  const stubs = ${JSON.stringify(stubs)};
40
43
  const kits = ${JSON.stringify(kits)};
41
44
  const baseline = ${JSON.stringify(baseline)};
42
45
  export async function resolve(s, c, next) {
46
+ // Exercise the live physics step/writeBack/API with a stationary stand-in
47
+ // Rapier body. Frozen rendering is outside this interpolation regression.
48
+ if (c.parentURL?.endsWith('/physics-3d/systems/physics3d.js')) {
49
+ if (s === '../engine3d/rapier.js') return { url: 'data:text/javascript,' + encodeURIComponent('export const init = async () => {}; export const RigidBodyType = { Dynamic: 0 };'), shortCircuit: true };
50
+ if (s === '../engine3d/frozenphysics.js') return { url: 'data:text/javascript,export class FrozenPhysics {}', shortCircuit: true };
51
+ }
52
+ if (c.parentURL?.endsWith('/real-time/code/client/connection.js')) {
53
+ if (s === 'castle-web-sdk') return { url: 'data:text/javascript,' + encodeURIComponent('export const Multiplayer = { join: async () => globalThis.__rateConnection };'), shortCircuit: true };
54
+ if (s === './joinOverlay.js') return { url: 'data:text/javascript,export const showLoadFailed = () => {};', shortCircuit: true };
55
+ }
43
56
  if (c.parentURL?.endsWith('/systems/multiplayer.js') && stubs[s]) {
44
57
  return { url: 'data:text/javascript,' + encodeURIComponent(stubs[s]), shortCircuit: true };
45
58
  }
@@ -50,6 +63,10 @@ register(
50
63
  if (baseline && c.parentURL === baseline && s.startsWith('../')) {
51
64
  return next(new URL(s, kits + 'multiplayer-3d/code/systems/multiplayer.js').href, c);
52
65
  }
66
+ if (s.startsWith('.') && c.parentURL?.includes('/physics-3d/')) {
67
+ const url = new URL(s, c.parentURL);
68
+ if (existsSync(fileURLToPath(url) + '.js')) return next(url.href + '.js', c);
69
+ }
53
70
  return next(s, c);
54
71
  }
55
72
  export async function load(u, c, next) {
@@ -73,8 +90,12 @@ globalThis.document = {
73
90
  removeEventListener: (type) => listeners.delete(type),
74
91
  };
75
92
  const quiet = console.log;
93
+ const warnings = [];
76
94
  console.log = (...args) => (String(args[0]).startsWith('[multiplayer]') ? undefined : quiet(...args));
77
- console.warn = (...args) => (String(args[0]).startsWith('[multiplayer]') ? undefined : quiet(...args));
95
+ console.warn = (...args) => {
96
+ warnings.push(args);
97
+ if (!String(args[0]).startsWith('[multiplayer]')) quiet(...args);
98
+ };
78
99
 
79
100
  const { installSystem } = await import('../code/systems/multiplayer.js');
80
101
 
@@ -118,6 +139,7 @@ async function makeRoom({ objects, players = {} }) {
118
139
  frames: [],
119
140
  // What the client sent the session.
120
141
  outbox: [],
142
+ forcedReconnects: 0,
121
143
  };
122
144
  for (const id of Object.keys(objects)) {
123
145
  room.actors.set(id, { id, components: { Transform: { x: 0, y: 0, z: 0 } } });
@@ -133,6 +155,12 @@ async function makeRoom({ objects, players = {} }) {
133
155
  send: (msg) => room.outbox.push(msg),
134
156
  closed: () => false,
135
157
  close() {},
158
+ reconnect: () => {
159
+ room.forcedReconnects++;
160
+ room.state = 'reconnecting';
161
+ room.socket = false;
162
+ return true;
163
+ },
136
164
  };
137
165
  // This player, whose body the session's WORLD placement moves.
138
166
  const local = { id: 'local', components: { Transform: { x: 0, y: 0, z: 0 } } };
@@ -325,7 +353,7 @@ async function prismReturn(awayMs, { reconnectEvent = true } = {}) {
325
353
 
326
354
  hide(room);
327
355
  if (!baseline) {
328
- assert.equal(globalThis.__cover, 'Reconnecting…', 'the cover is up before the page goes');
356
+ assert.equal(globalThis.__cover, '(no words)', 'the cover is up, with no words, before the page goes');
329
357
  }
330
358
  run(room, pageMs + 500);
331
359
  room.socket = false;
@@ -627,7 +655,7 @@ if (baseline) {
627
655
  room.lastFrame = pageMs - FRAME_MS;
628
656
  frame(room);
629
657
  assert.equal(room.system.resume.armed, true, 'a long frame gap arms the gate');
630
- assert.equal(globalThis.__cover, 'Reconnecting…');
658
+ assert.equal(globalThis.__cover, '(no words)', 'a return says nothing at first');
631
659
  assert.equal(room.system.resume.since, paused);
632
660
  room.sentObjects.clear();
633
661
  run(room, pageMs + 200);
@@ -692,5 +720,389 @@ if (baseline) {
692
720
  assert.equal(room.system.resume.armed, false, 'solo play has nothing to wait for');
693
721
  }
694
722
 
723
+ // A half-open socket: it still reports connected after a long app switch,
724
+ // accepts the resync, and delivers nothing. Keep page time deterministic so
725
+ // the deadline and the order of receive versus recovery are checked exactly.
726
+ async function silentReturn({ resyncs = true, limit = 3000 } = {}) {
727
+ const room = await makeRoom({ objects: { 'b0-beam-3': BEAM_OLD } });
728
+ assert.equal(room.system.resyncReplyMs, 3000);
729
+ room.system.resyncReplyMs = limit;
730
+ deliver(room, world(room, { rs: resyncs ? 1 : 0 }), pageMs);
731
+ run(room, pageMs + 2000);
732
+ hide(room);
733
+ room.socket = false;
734
+ pageMs += 180000;
735
+ show(room);
736
+ frame(room);
737
+ return room;
738
+ }
739
+
740
+ {
741
+ const room = await silentReturn();
742
+ const askedAt = room.system.resume.askedAt;
743
+ const warned = warnings.length;
744
+ run(room, askedAt + 2999);
745
+ assert.equal(room.forcedReconnects, 0, 'no forced recovery before the reply deadline');
746
+ pageMs = askedAt + 3000;
747
+ frame(room);
748
+ assert.equal(room.forcedReconnects, 1, 'a silent return forces recovery at the deadline');
749
+ assert.equal(room.state, 'reconnecting');
750
+ assert.deepEqual(warnings.slice(warned), [['[multiplayer] resync unanswered; reconnecting']]);
751
+ run(room, pageMs + 100);
752
+ assert.equal(room.system.resume.dropped, true, 'the next frame notes the SDK drop');
753
+ let named = 0, returned = 0;
754
+ const nameScene = room.system.nameScene.bind(room.system);
755
+ const reconnected = room.system.reconnected.bind(room.system);
756
+ room.system.nameScene = (...args) => { named++; nameScene(...args); };
757
+ room.system.reconnected = () => { returned++; reconnected(); };
758
+ reconnect(room);
759
+ assert.equal(named, 1, 'onConnected names the scene again');
760
+ assert.equal(returned, 1, 'onConnected runs the ordinary reconnect handler');
761
+ deliver(room, world(room), askedAt - 1);
762
+ run(room, pageMs + 500);
763
+ assert.equal(room.system.resume.armed, true, 'broadcasts and a WORLD from before return do not release it');
764
+ assert.equal(room.outbox.filter((m) => m.k === 'r').length, 1, 'recovery does not ask for another resync');
765
+ room.objects['b0-beam-3'] = BEAM_NOW;
766
+ deliver(room, world(room, { rs: 1 }));
767
+ run(room, pageMs + 800);
768
+ assert.equal(room.system.resume.armed, false, 'only the WORLD after return releases it');
769
+ assert.equal(room.forcedReconnects, 1);
770
+ assert.equal(globalThis.__cover, null);
771
+ assert.ok(offBy(room.frames.at(-1).drawn['b0-beam-3'], BEAM_NOW) < TOLERANCE);
772
+ }
773
+
774
+ // Drain before checking the timer: even a reply queued at the deadline wins.
775
+ for (const elapsed of [2999, 3000]) {
776
+ const room = await silentReturn();
777
+ run(room, room.system.resume.askedAt + elapsed - FRAME_MS);
778
+ pageMs = room.system.resume.askedAt + elapsed;
779
+ deliver(room, world(room, { rs: 1, again: 1 }), pageMs);
780
+ frame(room);
781
+ run(room, pageMs + 4000);
782
+ assert.equal(room.system.resume.armed, false, 'a current resync WORLD releases the gate');
783
+ assert.equal(room.forcedReconnects, 0, 'a timely WORLD prevents recovery');
784
+ }
785
+
786
+ // These sessions retain the existing ten-second give-up and never force a
787
+ // reconnect: no resync support, a disabled limit, or a drop already observed.
788
+ for (const options of [{ resyncs: false }, { limit: 0 }, { limit: -1 }, { dropped: true }]) {
789
+ const room = await silentReturn(options);
790
+ if (options.dropped) room.state = 'reconnecting';
791
+ run(room, pageMs + 11000);
792
+ assert.equal(room.forcedReconnects, 0, JSON.stringify(options));
793
+ assert.equal(room.system.resume.armed, false, 'the ordinary give-up remains');
794
+ assert.equal(room.outbox.filter((m) => m.k === 'r').length, options.resyncs === false ? 0 : 1);
795
+ }
796
+
797
+ {
798
+ const room = await silentReturn();
799
+ hide(room);
800
+ pageMs += 11000; // longer than the give-up, which must not be spent while hidden
801
+ frame(room); // a hidden page can still get a frame
802
+ assert.equal(room.forcedReconnects, 0, 'a hidden page never forces recovery');
803
+ show(room);
804
+ frame(room);
805
+ assert.equal(room.forcedReconnects, 0, 'hiding restarts the wait, so a return is not condemned on its first frame');
806
+ pageMs += 2999;
807
+ frame(room);
808
+ assert.equal(room.forcedReconnects, 0);
809
+ pageMs += 1;
810
+ frame(room);
811
+ assert.equal(room.forcedReconnects, 1, 'the restarted wait still ends in one forced recovery');
812
+ run(room, pageMs + 11000);
813
+ assert.equal(room.forcedReconnects, 1, 'a failed reconnect is attempted only once per away');
814
+ assert.equal(room.system.resume.armed, false, 'failed recovery still reaches the ten-second give-up');
815
+ assert.equal(room.system.gaveUp, true);
816
+ assert.equal(globalThis.__cover, null);
817
+ }
818
+
819
+ {
820
+ // Hiding over and over reaches both limits on visible time alone.
821
+ const room = await silentReturn();
822
+ for (let i = 0; i < 100 && room.system.resume.armed; i += 1) {
823
+ hide(room);
824
+ pageMs += 2000;
825
+ show(room);
826
+ frame(room);
827
+ pageMs += 1000;
828
+ frame(room);
829
+ }
830
+ assert.equal(room.forcedReconnects, 1, 'repeated hides still force recovery once');
831
+ assert.equal(room.system.resume.armed, false, 'repeated hides still reach the give-up');
832
+ assert.equal(room.system.gaveUp, true);
833
+ }
834
+
835
+ {
836
+ const room = await silentReturn();
837
+ delete room.system.net.reconnect; // the optional wrapper may itself be older
838
+ const warned = warnings.length;
839
+ run(room, pageMs + 11000);
840
+ assert.equal(warnings.slice(warned).filter(([m]) => m === '[multiplayer] resync unanswered; reconnecting').length, 1);
841
+ assert.equal(room.system.resume.armed, false, 'an older wrapper still gives up normally');
842
+ }
843
+
844
+ for (const action of ['close', 'switch']) {
845
+ const room = await silentReturn();
846
+ const old = room.system.net;
847
+ if (action === 'close') {
848
+ old.closed = () => true;
849
+ } else {
850
+ room.system.switchSession(room.scene, { mode: 'named', key: 'next' }, { quiet: true });
851
+ await Promise.resolve();
852
+ assert.equal(room.system.resume.askedAt, null, 'switching clears the old reply deadline');
853
+ }
854
+ pageMs += 4000;
855
+ frame(room);
856
+ assert.equal(room.forcedReconnects, 0, `${action} never recovers the old session`);
857
+ }
858
+
859
+ // A return's cover says nothing for QUIET_RETURN_MS after the page shows
860
+ // again, then that it is reconnecting; hiding again starts the quiet over.
861
+ {
862
+ const room = await makeRoom({ objects: { 'b0-beam-3': BEAM_OLD } });
863
+ deliver(room, world(room), pageMs);
864
+ run(room, pageMs + 2000);
865
+ hide(room);
866
+ room.socket = false;
867
+ room.state = 'reconnecting';
868
+ pageMs += 180000;
869
+ room.nextTick = pageMs;
870
+ room.lastFrame = pageMs - FRAME_MS;
871
+ show(room);
872
+ const shown = pageMs;
873
+ run(room, shown + 2400);
874
+ assert.equal(globalThis.__cover, '(no words)', 'quiet for the first 2.5 s after the return');
875
+ run(room, shown + 2600);
876
+ assert.equal(globalThis.__cover, 'Reconnecting…', 'then it says so');
877
+ // A frame stall while still away is another return: quiet again.
878
+ pageMs += 2000;
879
+ room.nextTick = pageMs;
880
+ frame(room);
881
+ assert.equal(room.system.resume.armed, true);
882
+ assert.equal(globalThis.__cover, '(no words)', 'a stall return is quiet again');
883
+ run(room, pageMs + 2600);
884
+ assert.equal(globalThis.__cover, 'Reconnecting…');
885
+ // Hidden and shown: the words go at each event, before any frame.
886
+ hide(room);
887
+ assert.equal(globalThis.__cover, '(no words)', 'quiet as the page hides');
888
+ pageMs += 5000;
889
+ room.nextTick = pageMs;
890
+ room.lastFrame = pageMs - FRAME_MS;
891
+ show(room);
892
+ assert.equal(room.frames.at(-1).cover, '(no words)', 'the first composited frame says nothing');
893
+ frame(room);
894
+ assert.equal(globalThis.__cover, '(no words)', 'a second return is quiet again');
895
+ }
896
+ // A resumed transport retains joined, but its old local pose must not count
897
+ // as acknowledgement of a placement this connection has not applied yet.
898
+ const { game: reportHooks } = await import(`data:text/javascript,${encodeURIComponent(stubs['@imports/castle.real-time/code/client/gameHooks.js'])}`);
899
+ for (const event of [true, false]) for (const placement of ['world', 'self row']) {
900
+ const room = await makeRoom({ objects: { crate: [4, 1, 0, 0, 0, 0, 1] } });
901
+ deliver(room, world(room), pageMs);
902
+ run(room, pageMs + 100);
903
+ const local = room.scene.actorWith('Player');
904
+ Object.assign(local.components.Transform, { x: -1, y: 1, z: 12.844 });
905
+ room.scene.physics3d.bodyOf(local).setTranslation(local.components.Transform);
906
+ const reports = [];
907
+ room.system.net.sendMove = pose => { reports.push(pose); return true; };
908
+ let delegated = 0;
909
+ // Same delegation as hub-game's hookLayer.report for a player on foot.
910
+ reportHooks.report = (scene, actor, system) => { delegated++; system.report(scene, actor); };
911
+ try {
912
+ frame(room);
913
+ assert.equal(reports.length, 1, 'an already placed connection reports normally');
914
+ reports.length = 0;
915
+ delegated = 0;
916
+ room.socket = false;
917
+ room.state = 'reconnecting';
918
+ frame(room);
919
+ reconnect(room, { event });
920
+ room.actors.delete('crate');
921
+ frame(room);
922
+ assert.equal(room.system.joined, true, 'joined is retained across reconnect');
923
+ assert.equal(reports.length, 0, 'the old body is not reported on the new connection');
924
+ assert.equal(delegated, 0, 'the hub report override waits too');
925
+ room.system.report(room.scene, local);
926
+ assert.equal(reports.length, 0, 'direct calls through the override cannot bypass the gate');
927
+ assert.ok(!room.outbox.some(msg => msg.k === 'g'), 'gone reports wait with moves');
928
+ deliver(room, world(room, { again: 1 }), pageMs);
929
+ frame(room);
930
+ assert.equal(reports.length, 0, 'a resync WORLD does not place this connection');
931
+ const bodyOf = room.scene.physics3d.bodyOf;
932
+ room.scene.physics3d.bodyOf = () => null;
933
+ const ps = [['self', 0, 1, 9, 0]];
934
+ deliver(room, placement === 'world' ? world(room, { ps }) : { k: 's', t: simNow(), ps }, pageMs);
935
+ frame(room);
936
+ assert.equal(reports.length, 0, 'receipt alone is not enough while the body is missing');
937
+ room.scene.physics3d.bodyOf = bodyOf;
938
+ frame(room);
939
+ assert.equal(reports.length, 1, 'the frame applying placement can report');
940
+ assert.deepEqual(reports[0].slice(0, 3), [0, 1, 9], 'the first report carries the applied placement');
941
+ frame(room);
942
+ assert.ok(room.outbox.some(msg => msg.k === 'g'), 'gone reports resume after placement');
943
+ } finally { delete reportHooks.report; }
944
+ }
945
+ for (const release of ['timeout', 'endAway']) {
946
+ const room = await makeRoom({ objects: {} });
947
+ deliver(room, world(room), pageMs);
948
+ run(room, pageMs + 100);
949
+ const reports = [];
950
+ room.system.net.sendMove = pose => { reports.push(pose); return true; };
951
+ reconnect(room);
952
+ // The cover can release without a placement, but the report wait still
953
+ // has its own copy of the existing visible-time deadline.
954
+ deliver(room, world(room, { again: 1 }), pageMs);
955
+ frame(room);
956
+ assert.equal(reports.length, 0);
957
+ if (release === 'timeout') run(room, pageMs + 10100);
958
+ else { room.system.endAway(); frame(room); }
959
+ assert.ok(reports.length > 0, `${release}: reporting does not wait forever`);
960
+ }
961
+ // The report wait counts visible time only: an away after the wait started
962
+ // (hidden, or frames stopped) does not spend it, so a return cannot report the
963
+ // retained pose before this connection's placement.
964
+ for (const away of ['hidden', 'stall']) {
965
+ const room = await makeRoom({ objects: {} });
966
+ deliver(room, world(room), pageMs);
967
+ run(room, pageMs + 100);
968
+ const reports = [];
969
+ room.system.net.sendMove = pose => { reports.push(pose); return true; };
970
+ reconnect(room);
971
+ deliver(room, world(room, { again: 1 }), pageMs);
972
+ frame(room);
973
+ run(room, pageMs + 2000);
974
+ assert.equal(room.system.reportPlacement.armed, true, `${away}: still waiting for placement`);
975
+ if (away === 'hidden') { hide(room); pageMs += 30000; show(room); }
976
+ else { pageMs += 30000; }
977
+ frame(room);
978
+ assert.equal(room.system.reportPlacement.armed, true, `${away}: time away does not release the report wait`);
979
+ assert.equal(reports.length, 0, `${away}: no report of the retained pose on return`);
980
+ run(room, pageMs + 7000);
981
+ assert.equal(reports.length, 0, `${away}: still held inside the visible wait`);
982
+ run(room, pageMs + 1500);
983
+ assert.ok(reports.length > 0, `${away}: the visible wait still ends`);
984
+ }
985
+ console.log('test-resume-gate: reconnect reports wait for applied placement; WORLD, self row, body delay, hook, timeout, endAway and visible-time wait pass');
986
+
987
+ // Clamp application and reporting share one frame, before physics can sync
988
+ // the Transform again. The hub's report hook delegates to this same report.
989
+ for (const correction of ['placement', 'snap', 'ease', 'placement then ease']) {
990
+ const room = await makeRoom({ objects: {} });
991
+ deliver(room, world(room), pageMs);
992
+ run(room, pageMs + 100);
993
+ const local = room.scene.actorWith('Player');
994
+ const body = room.scene.physics3d.bodyOf(local);
995
+ const before = { x: -1, y: 1, z: 12.656 };
996
+ Object.assign(local.components.Transform, before, { rotationY: 90 });
997
+ body.setTranslation(before, true);
998
+ let expected;
999
+ if (correction === 'placement' || correction === 'placement then ease') {
1000
+ room.system.placedTo = { x: 0, y: 1, z: 9 };
1001
+ expected = { x: 0, y: 1, z: 9 };
1002
+ }
1003
+ if (correction === 'snap') {
1004
+ room.system.clampedTo = { x: 8, y: 2, z: 20 };
1005
+ expected = { x: 8, y: 2, z: 20 };
1006
+ }
1007
+ if (correction === 'ease') {
1008
+ room.system.clampedTo = { x: 0, y: 2, z: 9 };
1009
+ expected = { x: -0.75, y: 1.25, z: 11.742 };
1010
+ }
1011
+ if (correction === 'placement then ease') {
1012
+ room.system.clampedTo = { x: -1, y: 1, z: 12.656 };
1013
+ expected = { x: -0.25, y: 1, z: 9.914 };
1014
+ }
1015
+ const reports = [];
1016
+ room.system.net.sendMove = pose => { reports.push(pose); return true; };
1017
+ frame(room);
1018
+ assert.equal(reports.length, 1, `${correction}: one report in the corrected frame`);
1019
+ assert.deepEqual(reports[0].slice(0, 3), [expected.x, expected.y, expected.z], `${correction}: the report carries the applied pose`);
1020
+ for (const axis of ['x', 'y', 'z']) {
1021
+ assert.ok(Math.abs(local.components.Transform[axis] - expected[axis]) < 1e-9, `${correction}: Transform ${axis} agrees`);
1022
+ assert.ok(Math.abs(body.translation()[axis] - expected[axis]) < 1e-9, `${correction}: body ${axis} agrees`);
1023
+ }
1024
+ assert.equal(local.components.Transform.rotationY, 90, 'corrections preserve facing');
1025
+ assert.equal(reports[0][3], 1.571, 'report retains Transform facing');
1026
+ if (correction.startsWith('placement')) assert.equal(room.system.settleFrames, 1);
1027
+ }
1028
+ console.log('test-resume-gate: same-frame placement, clamp snap and clamp ease reports carry the applied position');
1029
+
1030
+ // A rate-limited correction frame can be followed by several render frames
1031
+ // before physics steps again. Use the LIVE engine's history/writeback and
1032
+ // the real MOVE_HZ transport, rather than making every send succeed.
1033
+ const { Physics3DSystem } = await import('../../physics-3d/systems/physics3d.js');
1034
+ const { connectSession: rateLimitedSession } = await import('../../real-time/code/client/connection.js');
1035
+ const { MOVE_HZ } = await import('../../real-time/code/client/messages.js');
1036
+ const fastFrameMs = 1000 / 240;
1037
+ for (const correction of ['placement', 'snap', 'ease', 'placement then ease']) {
1038
+ const room = await makeRoom({ objects: {} });
1039
+ deliver(room, world(room), pageMs);
1040
+ run(room, pageMs + 100);
1041
+ const local = room.scene.actorWith('Player');
1042
+ const body = room.scene.physics3d.bodyOf(local);
1043
+ const before = { x: 0, y: 1, z: 1 };
1044
+ Object.assign(local.components.Transform, before, { rotationY: 90 });
1045
+ local.components.Body = { lockRotations: true };
1046
+ body.setTranslation(before, true);
1047
+ body.bodyType = () => 0;
1048
+ room.scene.getActors = () => [local];
1049
+ const physics = new Physics3DSystem();
1050
+ physics.attach(room.scene);
1051
+ physics.bodies.set(local.id, { body });
1052
+ let fixedSteps = 0;
1053
+ physics.world = { step: () => fixedSteps++ };
1054
+ physics.eventQueue = { drainCollisionEvents() {} };
1055
+ physics.step(1 / 60);
1056
+ physics.writeBack(room.scene);
1057
+ assert.equal(physics.bodies.get(local.id).prev.z, before.z, 'a fixed step recorded the old pose');
1058
+
1059
+ const packets = [];
1060
+ globalThis.__rateConnection = {
1061
+ playerId: 'self', state: 'connected', isSolo: false,
1062
+ send: packet => packets.push(packet), onMessage() {}, onRoster() {}, onStateChange() {},
1063
+ };
1064
+ const transport = await rateLimitedSession();
1065
+ // The correction narrowly misses a send slot; the next frame gets it,
1066
+ // still before a single new fixed physics step has run.
1067
+ const correctionAt = pageMs;
1068
+ pageMs -= 1000 / MOVE_HZ - fastFrameMs / 2;
1069
+ assert.equal(transport.sendMove([0, 1, 1, 0], [], [], []), true);
1070
+ pageMs = correctionAt;
1071
+ packets.length = 0;
1072
+ room.system.net.sendMove = transport.sendMove;
1073
+ let expected;
1074
+ if (correction === 'placement' || correction === 'placement then ease') {
1075
+ room.system.placedTo = { x: 0, y: 1, z: 0 };
1076
+ expected = [0, 1, 0];
1077
+ }
1078
+ if (correction === 'snap') {
1079
+ room.system.clampedTo = { x: 5, y: 1, z: -5 };
1080
+ expected = [5, 1, -5];
1081
+ }
1082
+ if (correction === 'ease') {
1083
+ room.system.clampedTo = { x: 0, y: 1, z: -2 };
1084
+ expected = [0, 1, 0.25];
1085
+ }
1086
+ if (correction === 'placement then ease') {
1087
+ room.system.clampedTo = { x: 0, y: 1, z: 1 };
1088
+ expected = [0, 1, 0.25];
1089
+ }
1090
+ frame(room);
1091
+ assert.equal(packets.length, 0, `${correction}: the correction frame's report is rate-limited`);
1092
+ for (let i = 1; i <= 16; i++) {
1093
+ pageMs += fastFrameMs;
1094
+ physics.step(fastFrameMs / 1000);
1095
+ physics.writeBack(room.scene);
1096
+ if (i < 4) assert.equal(fixedSteps, 1, 'writeback runs without a new physics step');
1097
+ const t = local.components.Transform;
1098
+ assert.deepEqual([t.x, t.y, t.z], expected, `${correction}: frame ${i} never interpolates from the old pose`);
1099
+ frame(room);
1100
+ if (i === 1) assert.equal(packets.length, 1, 'the next actual send precedes the next physics step');
1101
+ for (const packet of packets) assert.deepEqual(packet.p.slice(0, 3), expected, `${correction}: outgoing reports keep the corrected position`);
1102
+ }
1103
+ assert.ok(packets.length >= 2, 'the rate limiter also sends a later report');
1104
+ }
1105
+ console.log('test-resume-gate: 240 Hz live physics writeback and rate-limited reports keep placement, snap and ease corrections');
1106
+
695
1107
  console.table(results);
696
- console.log('test-resume-gate: every return covered until current, then drawn at current poses with no easing');
1108
+ console.log('test-resume-gate: current snapshots release returns; silent resyncs recover once');
@@ -0,0 +1,68 @@
1
+ // Run with: node kits/multiplayer-3d/scripts/test-resync-reconnect.mjs
2
+ import assert from 'node:assert/strict';
3
+ import { register } from 'node:module';
4
+ import * as Gate from '../code/client/resumeGate.js';
5
+
6
+ const gate = Gate.makeGate();
7
+ const limit = Gate.RESYNC_REPLY_MS;
8
+ assert.equal(limit, 3000);
9
+ assert.equal(Gate.unanswered(gate, 10000, limit), false, 'an unarmed gate does nothing');
10
+ Gate.arm(gate, 0, 0);
11
+ assert.equal(Gate.unanswered(gate, 10000, limit), false, 'no request means no timeout');
12
+ assert.equal(Gate.ask(gate, Gate.RESYNC_AWAY_MS - 1), false, 'a short away needs no resync');
13
+ assert.equal(Gate.ask(gate, 5000), true);
14
+ assert.equal(gate.askedAt, 5000);
15
+ assert.equal(Gate.ask(gate, 6000), false);
16
+ assert.equal(gate.askedAt, 5000, 'a repeat ask does not move the deadline');
17
+ assert.equal(Gate.unanswered(gate, 5000 + limit - 1, limit), false);
18
+ assert.equal(Gate.unanswered(gate, 5000 + limit, 0), false, 'zero disables forced recovery');
19
+ assert.equal(Gate.unanswered(gate, 5000 + limit, -1), false, 'negative limits disable it too');
20
+ assert.equal(Gate.unanswered(gate, 5000 + limit, limit), true, 'the exact deadline counts');
21
+ assert.equal(Gate.unanswered(gate, 5000 + 2 * limit, limit), false, 'only once per away');
22
+ assert.equal(Gate.arm(gate, 7000, 0), false, 'an overlapping away keeps that decision');
23
+ assert.equal(Gate.unanswered(gate, 20000, limit), false);
24
+ Gate.clear(gate);
25
+ assert.equal(gate.askedAt, null);
26
+ assert.equal(Gate.unanswered(gate, 20000, limit), false);
27
+ Gate.arm(gate, 10000, 0);
28
+ assert.equal(gate.askedAt, null);
29
+ assert.equal(Gate.ask(gate, 15000), true);
30
+ assert.equal(Gate.unanswered(gate, 15000 + limit, limit), true, 'a later away gets its own attempt');
31
+ Gate.clear(gate);
32
+ Gate.arm(gate, 20000, 0);
33
+ Gate.ask(gate, 25000);
34
+ Gate.noteConnection(gate, false, 26000);
35
+ assert.equal(Gate.unanswered(gate, 30000, limit), false, 'a natural drop needs no forced recovery');
36
+ Gate.noteConnection(gate, true, 30000);
37
+ assert.equal(Gate.unanswered(gate, 31000, limit), false, 'nor does that drop returning');
38
+
39
+ // The real transport wrapper, with only SDK acquisition replaced. Calling a
40
+ // method on the connection must preserve its receiver; old SDKs have no method.
41
+ register(`data:text/javascript,${encodeURIComponent(`
42
+ export async function resolve(s, c, next) {
43
+ if (s === 'castle-web-sdk') {
44
+ return { url: 'data:text/javascript,export const Multiplayer = { join: () => globalThis.__sdkConnection };', shortCircuit: true };
45
+ }
46
+ return next(s, c);
47
+ }
48
+ `)}`);
49
+ const { connectSession } = await import('../../real-time/code/client/connection.js');
50
+ for (const support of ['absent', 'non-function', false, true]) {
51
+ let calls = 0;
52
+ const connection = {
53
+ onMessage() {}, onRoster() {}, onStateChange() {},
54
+ ...(support === 'absent' ? {} : {
55
+ reconnect: support === 'non-function' ? null : function () {
56
+ assert.equal(this, connection);
57
+ calls++;
58
+ return support;
59
+ },
60
+ }),
61
+ };
62
+ globalThis.__sdkConnection = connection;
63
+ const net = await connectSession();
64
+ assert.equal(net.reconnect(), support === true);
65
+ assert.equal(calls, typeof support === 'boolean' ? 1 : 0);
66
+ }
67
+ delete globalThis.__sdkConnection;
68
+ console.log('test-resync-reconnect: one-shot reply deadline and SDK feature detection passed');
@@ -68,11 +68,11 @@
68
68
  "onUpdate": "scripts/onUpdate.mjs",
69
69
  "title": "physics-2d",
70
70
  "description": "Scene Editor. Works like classic Castle: actors, blueprints, behaviors and drawing tools, with physics built in.",
71
- "publishedVersion": "2026-10-17T06:02:29.713Z",
71
+ "publishedVersion": "2026-11-15T00:41:50.817Z",
72
72
  "imports": {
73
73
  "castle.base": {
74
74
  "deckId": "yRcmH4_aYllE",
75
- "version": "2026-10-16T11:44:02.771Z"
75
+ "version": "2026-11-15T00:40:25.157Z"
76
76
  }
77
77
  }
78
78
  }
@@ -602,10 +602,17 @@ export class SceneRuntime {
602
602
  // visit awake actors. Spawns wake their ID and loads discard the sleep set.
603
603
  #awakeActors = null;
604
604
  #sleepingActors = null;
605
+ // Rendering caches can finish work for a sleep set without polling actors.
606
+ // Loads and replacement/removal of a sleeper invalidate that completion too.
607
+ #sleepVersion = 0;
608
+
609
+ get sleepVersion() { return this.#sleepVersion; }
610
+ get sleepingActorCount() { return this.#sleepingActors?.size ?? 0; }
605
611
 
606
612
  setActorSleeping(actorOrId, sleeping) {
607
613
  const actor = typeof actorOrId === 'string' ? this.actors.get(actorOrId) : actorOrId;
608
614
  if (!actor || this.actors.get(actor.id) !== actor) return false;
615
+ if (this.isActorSleeping(actor) !== Boolean(sleeping)) this.#sleepVersion++;
609
616
  this.#frozen?.mark(actor);
610
617
  if (!sleeping && !this.#awakeActors) return true;
611
618
  this.#awakeActors ??= new Map(this.actors);
@@ -647,6 +654,7 @@ export class SceneRuntime {
647
654
  for (const system of this.systems) system.reset?.(this);
648
655
  this.#awakeActors = null;
649
656
  this.#sleepingActors = null;
657
+ this.#sleepVersion++;
650
658
  this.data = structuredClone(sceneData);
651
659
  this.#skipUnchanged = sceneSkipsUnchangedActors(this.data);
652
660
  this.#nearShadowDistance = sceneNearShadowDistance(this.data);
@@ -835,7 +843,7 @@ export class SceneRuntime {
835
843
  this.#initActor(next);
836
844
  this.data.actors.push(next);
837
845
  this.actors.set(id, next);
838
- this.#sleepingActors?.delete(id);
846
+ if (this.#sleepingActors?.delete(id)) this.#sleepVersion++;
839
847
  this.#awakeActors?.set(id, next);
840
848
  this.#frozen?.add(next, true);
841
849
  return next;
@@ -857,7 +865,7 @@ export class SceneRuntime {
857
865
  this.#frozen?.remove(actor);
858
866
  if (this.#still !== null && this.#still.delete(actor)) this.#stillVersion = nextStillVersion();
859
867
  this.actors.delete(actorId);
860
- this.#sleepingActors?.delete(actorId);
868
+ if (this.#sleepingActors?.delete(actorId)) this.#sleepVersion++;
861
869
  this.#awakeActors?.delete(actorId);
862
870
  const idx = this.data.actors.findIndex((a) => a.id === actorId);
863
871
  if (idx !== -1) this.data.actors.splice(idx, 1);
@@ -7,6 +7,12 @@ behavior / scene / blueprint model, deck file map, live reload, and the
7
7
  `imports/castle.physics-2d/` and work exactly as that kit's CLAUDE.md
8
8
  describes. This file covers what is different in 3D.
9
9
 
10
+ ## Welcome message
11
+
12
+ Welcome to an early test of Castle's new engine, in 3D with real physics! You're starting with Castle's 3D scene editor. Open `scenes/main.scene` to try it out, or I can start building something for you — a physics playground, a little obstacle course, a 3D puzzle, whatever you like.
13
+
14
+ Do you already know what you want to make, or do you want to figure it out together?
15
+
10
16
  ## Quick reference
11
17
 
12
18
  <!-- Injected into Castle's create assistant every turn; keep this compact and factual. -->
@@ -59,12 +65,18 @@ bottom }`; any ref can pick a frame of a multi-frame sprite with
59
65
  "tile": 2, "color": "#..." }` at the scene file's top level (`tile` = meters
60
66
  per texture repeat). `"ground": { "none": true }` has no ground at all, drawn
61
67
  or stood on: whatever is not on an actor falls (pits, lava, sky islands).
68
+ `"ground": { "half": 150 }` sizes it: the collider reaches that many meters
69
+ each way (default 100, clamped 1..200, multiplayer-3d's server slab too)
70
+ and the drawn plane is twice as wide (default 60 m square);
71
+ engine3d/groundsize.js has the rule.
62
72
  `Shape.artRepeat: [u, v]` tiles a texture across a
63
73
  face so long walls don't stretch.
64
74
  - A scene file's top level may carry an `engine` object, beside `ground`.
65
75
  Every key in it is opt-in: a scene without the key runs the engine exactly
66
76
  as before. Each key's terms are in a file under `docs/`; read that file
67
77
  before setting the key, or before changing code in a scene that sets it.
78
+ - `modelCache: { maxBytes }` -- reuse complete model templates across opens,
79
+ bounded on-device storage: docs/engine-model-cache.md.
68
80
  - `load` -- builds the models near the player before the first frame and
69
81
  the rest in slices after it: docs/engine-load.md.
70
82
  - `skipUnchangedActors`, `dropEmptyParts`, `skipEmptyNodes`,
@@ -79,6 +91,8 @@ bottom }`; any ref can pick a frame of a multi-frame sprite with
79
91
  - `camera` -- `follow: "rigid"`, the `control: "orbit"` third-person
80
92
  camera, and its `pitch`, `minPitch`, `distance` and `fov`; also the rule
81
93
  for steady forces: docs/engine-camera.md.
94
+ - `player.slideOnWalls: true` -- project the built-in grounded walk along
95
+ nearby fixed solid walls: docs/engine-player.md.
82
96
  - `view` -- view distance and fog: docs/engine-view.md.
83
97
  - `look` -- models drawn first and their look baked after:
84
98
  docs/engine-look.md.