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
@@ -53,6 +53,7 @@ function boot(keys = {}, more = {}) {
53
53
  },
54
54
  fall: more.fall,
55
55
  resume: more.resume,
56
+ message: more.message,
56
57
  leave(ctx, playerId) {
57
58
  leaves.push(playerId);
58
59
  more.leave?.(ctx, playerId);
@@ -1314,7 +1315,9 @@ for (const viaPlace of [false, true]) {
1314
1315
  });
1315
1316
  }
1316
1317
 
1317
- test('a lone door arrival onto an authored floor clears an occupied slot; ground and empty slots keep their placement', () => {
1318
+ // v1.218: ground-backed places clear an occupied slot too (two bodies on one
1319
+ // spot wedge on the client); an empty slot keeps its placement.
1320
+ test('a lone door arrival clears an occupied slot on an authored floor and on ground; empty slots keep their placement', () => {
1318
1321
  const arrival = { x: 3, y: 1, z: -4 };
1319
1322
  const facing = 60 * Math.PI / 180;
1320
1323
  const floor = { id: 'floor', components: { Solid: {}, Transform: { x: 0, y: -0.07, z: 0 }, Shape: { kind: 'box', width: 40, height: 0.14, depth: 40 } } };
@@ -1328,13 +1331,13 @@ test('a lone door arrival onto an authored floor clears an occupied slot; ground
1328
1331
  r.say('p2', { k: 'hub-hello', avatar: 1, from: 'home-1', party: 1 });
1329
1332
  r.tick(2000); r.tick();
1330
1333
  const guest = r.world.players.get('p2');
1331
- if (occupied && ground) {
1334
+ if (occupied) {
1332
1335
  const step = 2 * 0.35 + 0.1;
1333
1336
  assert.ok(Math.abs(guest.at.x - arrival.x - Math.cos(facing) * step) < 1e-9, 'first free slot on the positive side');
1334
1337
  assert.ok(Math.abs(guest.at.z - arrival.z + Math.sin(facing) * step) < 1e-9, 'stays along the arrival row');
1335
1338
  assert.ok(Math.hypot(guest.at.x - arrival.x, guest.at.z - arrival.z) >= 0.7, 'no overlapping players');
1336
1339
  } else {
1337
- assert.deepEqual([guest.at.x, guest.at.z], [arrival.x, arrival.z], occupied ? 'a ground-backed place keeps the spawn WORLD showed' : 'empty arrival placement is unchanged');
1340
+ assert.deepEqual([guest.at.x, guest.at.z], [arrival.x, arrival.z], 'empty arrival placement is unchanged');
1338
1341
  }
1339
1342
  assert.equal(guest.facing, facing, 'keeps the arrival facing');
1340
1343
  }
@@ -1631,6 +1634,51 @@ for (const readFirst of [true, false]) {
1631
1634
  }
1632
1635
  }
1633
1636
 
1637
+ // A sign-up's account read that never settles lets the placed player go at
1638
+ // five seconds, logged, and a read landing afterwards keeps the carried look.
1639
+ {
1640
+ const realNow = Date.now, warn = console.warn, warned = [];
1641
+ let now = realNow();
1642
+ Date.now = () => now;
1643
+ console.warn = (...args) => warned.push(args.join(' '));
1644
+ try {
1645
+ const r = boot({ anonymousEntry: true, avatarColors: true }, { players: guestRoster() });
1646
+ const at = { x: 21, y: 2, z: -4 };
1647
+ r.ctx().placeAt('p2', at, 40);
1648
+ r.say('p2', { k: 'hub-hello', avatar: 7, color: 11, again: true });
1649
+ r.tick();
1650
+ let resolveRead;
1651
+ const read = new Promise((resolve) => { resolveRead = resolve; });
1652
+ r.session.hub = { arrival: () => null, readResults: (input) => input.userIds ? read : Promise.resolve({ boards: {} }) };
1653
+ Object.assign(r.session.players.find((p) => p.playerId === 'p2'), { username: 'Bo', isAnonymous: false });
1654
+ r.say('p2', { k: 'hub-hello', avatar: 0, color: 0, party: 1 });
1655
+ r.tick();
1656
+ const arrivals = r.arrivedTimes('p2');
1657
+ now += 2000; r.tick();
1658
+ assert.equal(r.arrivedTimes('p2'), arrivals, 'placed, still waiting on the read');
1659
+ assert.ok(r.server.join().held.includes('p2'));
1660
+ now += 4999; r.tick();
1661
+ assert.equal(r.arrivedTimes('p2'), arrivals, 'a read that settles in time holds as before');
1662
+ assert.equal(warned.some((line) => line.startsWith('[hub] arrival hold released')), false);
1663
+ now += 1; r.tick();
1664
+ assert.equal(r.arrivedTimes('p2'), arrivals + 1, 'the sign-up hold lets go at the bound');
1665
+ assert.equal(r.server.join().held.includes('p2'), false);
1666
+ assert.deepEqual(r.world.players.get('p2').at, at);
1667
+ assert.equal(r.server.join().hubAv2.p2, 7);
1668
+ assert.deepEqual(warned.filter((line) => line.startsWith('[hub] arrival hold released')), ['[hub] arrival hold released after 5 s: signup-results']);
1669
+ resolveRead({ players: { 102: { avatar: 0, avatarColor: 0 } }, boards: {} });
1670
+ await new Promise((resolve) => setImmediate(resolve));
1671
+ r.tick();
1672
+ assert.equal(r.server.join().hubAv2.p2, 7, 'a late read cannot replace the carried avatar');
1673
+ assert.equal(r.server.join().hubAvC.p2, 11);
1674
+ assert.equal(r.arrivedTimes('p2'), arrivals + 1, 'the late read replays no arrival');
1675
+ console.log('ok: an unsettled sign-up read releases at 5 s');
1676
+ } finally {
1677
+ Date.now = realNow;
1678
+ console.warn = warn;
1679
+ }
1680
+ }
1681
+
1634
1682
  // Terminal carry regression matrix against the real hub server: both orders,
1635
1683
  // success/empty/rejection, delayed reads, repeated hellos, explicit choices,
1636
1684
  // account switches and throwing authored arrivals. Carry is consumed once.
@@ -1776,6 +1824,25 @@ test('pose-only explicit travel cannot return to its old pose', () => {
1776
1824
  assert.notEqual(r.world.players.get('p2').at.x, -3);
1777
1825
  });
1778
1826
 
1827
+ test('v1.173 pose-only: a drop right after hub-back keeps no arrival pose; a stale or other-account mark does not', () => keeping((advance) => {
1828
+ for (const [how, restores] of [['back', false], ['stale', true], ['account', true]]) {
1829
+ const r = boot({ resumeArrivalPose: true });
1830
+ r.ctx().placeAt('p2', { x: -3, y: 1, z: -2 }, 40); r.tick();
1831
+ r.say('p2', { k: 'hub-back' }); r.tick();
1832
+ if (how === 'stale') {advance(36_000); r.tick();}
1833
+ // A new hello under another account on the same socket drops the mark.
1834
+ if (how === 'account') {
1835
+ r.session.players.find(p => p.playerId === 'p2').userId = '103';
1836
+ r.say('p2', rehello); r.tick(); r.tick();
1837
+ r.ctx().placeAt('p2', { x: -3, y: 1, z: -2 }, 40); r.tick();
1838
+ }
1839
+ r.drop(); r.tick(); r.back();
1840
+ if (how === 'account') {r.session.players.find(p => p.playerId === 'p2').userId = '103';}
1841
+ r.say('p2', rehello); r.tick();
1842
+ assert.equal(r.world.players.get('p2').at.x === -3, restores, how);
1843
+ }
1844
+ }));
1845
+
1779
1846
  test('pose-only mode fails closed across changed or anonymous identity', () => {
1780
1847
  for (const identity of [{ userId: '103', isAnonymous: false }, { userId: '102', isAnonymous: true }]) {
1781
1848
  const r = boot({ resumeArrivalPose: true });
@@ -1985,4 +2052,176 @@ test('a lone arrival stepping off an occupied slot keeps clear of placed furnitu
1985
2052
  console.log('ok: a drop without an end still restores its pose');
1986
2053
  }
1987
2054
 
2055
+ // v1.173: the player's own Back (`hub-back`, said just before Hub.back) ends
2056
+ // the visit, so the next entry is a fresh arrival; a drop with no word still
2057
+ // resumes. A game, a repeat, an earlier trip and a player not here change
2058
+ // nothing, and the place's own message hook never hears it.
2059
+ {
2060
+ const floor = { id: 'floor', components: { Solid: {}, Transform: { x: 0, y: -0.07, z: 0 }, Shape: { kind: 'box', width: 40, height: 0.14, depth: 40 } } };
2061
+ const arrival = { x: 3, y: 1, z: -4 };
2062
+ const spot = { x: -3.5, y: 1, z: 2.3 };
2063
+ const heard = [];
2064
+ // One visit by p2: arrive, move to `spot`, then `before(r)` (the Back, or
2065
+ // nothing), a drop, and a return under the same account: a resume of the
2066
+ // same player id, or (`fresh`) a new connection with a new id.
2067
+ async function visit(keys, { before = () => {}, fresh = true, door = false } = {}) {
2068
+ const storage = makePoseStorage();
2069
+ const r = boot({ resumePose: true, arrival: { actor: 'arrival', spread: 0.65, face: 60 }, ...(door ? { places: { lobby: { title: 'Lobby', scene: 'scenes/lobby.scene' } } } : {}), ...keys }, {
2070
+ actors: [...actors, floor, { id: 'arrival', components: { Transform: arrival } },
2071
+ ...(door ? [{ id: 'door', components: { HubDoor: { id: 'out', to: 'lobby' }, Transform: { x: 5, y: 0, z: 5 } } }] : [])],
2072
+ ground: { none: true }, storage, message: (c, player, data) => heard.push(data.k),
2073
+ });
2074
+ await flushPose(); r.tick(2000); r.tick();
2075
+ r.ctx().placeAt('p2', spot); r.tick();
2076
+ const from = r.sent.length;
2077
+ await before(r);
2078
+ const answered = toP2(r, from);
2079
+ r.tick(); r.drop(); r.tick(); await flushPose();
2080
+ const stored = [...storage.rows.keys()].filter((k) => k.includes('"102"')).length;
2081
+ let id = 'p2';
2082
+ if (fresh) {
2083
+ id = 'new-p2';
2084
+ r.session.players.push({ playerId: id, userId: '102', username: 'Bo', isAnonymous: false });
2085
+ r.world.players.set(id, body());
2086
+ r.say(id, { k: 'hub-hello', avatar: 1, party: 1 });
2087
+ } else {
2088
+ r.back(); r.say('p2', rehello);
2089
+ }
2090
+ await flushPose(); r.tick(2000); r.tick();
2091
+ const at = r.world.players.get(id).at;
2092
+ return { r, stored, answered, restored: Math.hypot(at.x - spot.x, at.z - spot.z) < 0.01 };
2093
+ }
2094
+ const backOnce = (r) => r.say('p2', { k: 'hub-back' });
2095
+
2096
+ for (const fresh of [true, false]) {
2097
+ const how = fresh ? 'a new connection' : 'a same-id resume';
2098
+ const control = await visit({}, { fresh });
2099
+ assert.equal(control.restored, true, `${how}: a drop with no hub-back restores the stored pose`);
2100
+ const backed = await visit({}, { fresh, before: backOnce });
2101
+ assert.equal(backed.restored, false, `${how}: after hub-back the return is placed at the arrival`);
2102
+ assert.deepEqual(backed.answered, [], 'hub-back is answered with nothing');
2103
+ assert.equal(backed.stored, 0, 'hub-back leaves no durable pose');
2104
+ if (!fresh) {assert.equal(backed.r.arrivedTimes('p2'), 2, 'the same-id return arrives afresh');}
2105
+ console.log(`ok: hub-back ends the visit: ${how} after it is a fresh arrival; without it the pose is restored`);
2106
+ }
2107
+
2108
+ const twice = await visit({}, { before: (r) => { backOnce(r); r.tick(); backOnce(r); backOnce(r); } });
2109
+ assert.equal(twice.restored, false);
2110
+ assert.deepEqual(twice.answered, [], 'a repeat sends nothing');
2111
+ console.log('ok: a repeated hub-back is harmless');
2112
+
2113
+ const gone = await visit({}, { door: true, before: (r) => { assert.ok(r.ctx().go('out', ['p2'])); const n = r.sent.length; backOnce(r); assert.deepEqual(toP2(r, n), [], 'hub-back after the trip sends nothing'); } });
2114
+ const goneAlone = await visit({}, { door: true, before: (r) => { assert.ok(r.ctx().go('out', ['p2'])); } });
2115
+ const kinds = (ms) => ms.map((m) => [m.k, m.door]);
2116
+ assert.deepEqual(kinds(gone.answered), kinds(goneAlone.answered), 'the trip says the same with or without a hub-back after it');
2117
+ assert.equal(gone.restored, false); assert.equal(goneAlone.restored, false);
2118
+ console.log('ok: hub-back after a kit trip (sendGo) is a no-op');
2119
+
2120
+ // A player the session does not list (an id it never had, or one briefly
2121
+ // out of the roster) ends no visit: the later drop still resumes.
2122
+ const unlisted = await visit({}, { fresh: false, before: (r) => {
2123
+ r.say('ghost', { k: 'hub-back' });
2124
+ const row = r.session.players.find((p) => p.playerId === 'p2');
2125
+ r.session.players = r.session.players.filter((p) => p !== row);
2126
+ backOnce(r);
2127
+ r.session.players.push(row);
2128
+ } });
2129
+ assert.equal(unlisted.restored, true, 'the unlisted hub-back is ignored');
2130
+ console.log('ok: hub-back from a player not in the roster is ignored');
2131
+
2132
+ // A session that shuts down before any tick saw the drop still lets the
2133
+ // Back's visit go, and keeps a plain drop's pose as before.
2134
+ for (const backed of [false, true]) {
2135
+ const storage = makePoseStorage();
2136
+ const r = boot({ resumePose: true, arrival: { actor: 'arrival', spread: 0.65, face: 60 } }, {
2137
+ actors: [...actors, floor, { id: 'arrival', components: { Transform: arrival } }], ground: { none: true }, storage,
2138
+ });
2139
+ await flushPose(); r.tick(2000); r.tick();
2140
+ r.ctx().placeAt('p2', spot); r.tick();
2141
+ if (backed) {backOnce(r);}
2142
+ r.drop();
2143
+ await r.server.shutdown(r.session); await flushPose();
2144
+ const stored = [...storage.rows.keys()].filter((k) => k.includes('"102"')).length;
2145
+ assert.equal(stored, backed ? 0 : 1, backed ? 'a Back before shutdown keeps no pose' : 'a plain drop at shutdown keeps its pose');
2146
+ }
2147
+ console.log('ok: hub-back then a shutdown before the next tick keeps no pose');
2148
+
2149
+ // The Back only arms: with no drop inside the window (Hub.back refused or
2150
+ // timed out, the player still here), a later genuine drop resumes.
2151
+ {
2152
+ const realNow = Date.now;
2153
+ let now = realNow();
2154
+ Date.now = () => now;
2155
+ try {
2156
+ for (const fresh of [true, false]) {
2157
+ const stale = await visit({}, { fresh, before: (r) => { backOnce(r); r.tick(); now += 36_000; r.tick(); } });
2158
+ assert.equal(stale.restored, true, `${fresh ? 'a new connection' : 'a same-id resume'}: a Back whose window passed leaves the visit as it was`);
2159
+ assert.equal(stale.stored, 1, 'the drop stores the pose as usual');
2160
+ if (!fresh) {assert.equal(stale.r.arrivedTimes('p2'), 1, 'resumed, not arrived again');}
2161
+ const inside = await visit({}, { fresh, before: (r) => { backOnce(r); r.tick(); now += 30_000; r.tick(); } });
2162
+ assert.equal(inside.restored, false, 'a drop inside the window is the Back leaving');
2163
+ // A repeat refreshes the mark: 20 s + 20 s is still inside.
2164
+ const refreshed = await visit({}, { fresh, before: (r) => { backOnce(r); now += 20_000; r.tick(); backOnce(r); now += 20_000; r.tick(); } });
2165
+ assert.equal(refreshed.restored, false, 'a repeated hub-back refreshes the window');
2166
+ }
2167
+ } finally {
2168
+ Date.now = realNow;
2169
+ }
2170
+ console.log('ok: hub-back only arms: a drop inside 35 s ends the visit, one after it resumes');
2171
+ }
2172
+
2173
+ // A pending pose read holds the whole arrival group. A hub-back before
2174
+ // arrival is ignored, and a read discarded by a departure still ends its
2175
+ // wait, so the others in the group arrive.
2176
+ for (const how of ['back', 'end']) {
2177
+ const base = makePoseStorage();
2178
+ let release = null;
2179
+ const storage = { ...base, rows: base.rows, snapshot: async (a) => { if (release) {await release.promise;} return base.snapshot(a); } };
2180
+ const r = boot({ resumePose: true }, { storage });
2181
+ await flushPose(); r.tick(2000); r.tick();
2182
+ release = Promise.withResolvers();
2183
+ for (const [id, userId] of [['p3', '103'], ['p4', '104']]) {
2184
+ r.session.players.push({ playerId: id, userId, username: id, isAnonymous: false });
2185
+ r.world.players.set(id, body());
2186
+ r.say(id, { k: 'hub-hello', avatar: 1, party: 1 });
2187
+ }
2188
+ if (how === 'back') {r.say('p3', { k: 'hub-back' });} else {r.ctx().end(['p3']);}
2189
+ r.tick(2000); r.tick();
2190
+ assert.equal(r.arrivedTimes('p4'), 0, 'the group waits on the reads');
2191
+ const resolve = release.resolve; release = null; resolve();
2192
+ await flushPose(); r.tick(2000); r.tick();
2193
+ assert.equal(r.arrivedTimes('p4'), 1, `the group arrives after a ${how} during p3's read`);
2194
+ if (how === 'back') {assert.equal(r.arrivedTimes('p3'), 1, 'and the early hub-back changed nothing for p3');}
2195
+ }
2196
+ console.log('ok: hub-back before arrival is ignored, and a discarded pose read never holds the group');
2197
+
2198
+ // A game (`result`) is unchanged by it: the same bytes, and a retained
2199
+ // hello still reaches the resume hook (a departing player's would not).
2200
+ for (const keys of [result, { ...result, resume: true }]) {
2201
+ const run = (backFirst) => {
2202
+ const calls = [];
2203
+ const r = boot(keys, { resume: (c, { playerId }) => calls.push(playerId), message: (c, player, data) => heard.push(data.k) });
2204
+ if (backFirst) {backOnce(r); backOnce(r);}
2205
+ r.tick(); r.say('p2', rehello); r.tick(); r.tick();
2206
+ return { calls, sent: r.sent, arrivals: r.arrivals };
2207
+ };
2208
+ const plain = run(false);
2209
+ const backed = run(true);
2210
+ assert.deepEqual(plain.calls, ['p2'], 'the game resumes the retained hello');
2211
+ assert.deepEqual(backed.calls, plain.calls, 'hub-back in a game does not mark the player departing');
2212
+ assert.deepEqual(backed.sent, plain.sent, 'a game sends the same bytes');
2213
+ assert.deepEqual(backed.arrivals, plain.arrivals);
2214
+ }
2215
+ console.log('ok: hub-back in a place with result changes nothing');
2216
+
2217
+ // A place that retains no visit: nothing to end, and still never the hook's.
2218
+ {
2219
+ const r = boot({}, { message: (c, player, data) => heard.push(data.k) });
2220
+ r.say('p2', { k: 'hub-back' }); r.tick();
2221
+ r.drop(); r.tick(); r.back(); r.say('p2', rehello); r.tick(2000); r.tick();
2222
+ }
2223
+ assert.equal(heard.includes('hub-back'), false, 'the place message hook never hears hub-back');
2224
+ console.log('ok: hub-back is consumed by the kit, never passed to the place hook');
2225
+ }
2226
+
1988
2227
  console.log(`rehello: ${passed} tests passed`);
@@ -0,0 +1,138 @@
1
+ // A rejoin under a new player id on the same connection (the page away past
2
+ // the place's reconnect window) keeps the camera yaw; a fresh arrival, a trip's
3
+ // arrival and another connection's arrival still face the arrival.
4
+ import assert from 'node:assert/strict';
5
+ import { register } from 'node:module';
6
+
7
+ register(`data:text/javascript,${encodeURIComponent(`
8
+ import { readFile } from 'node:fs/promises';
9
+ import { fileURLToPath } from 'node:url';
10
+ export async function resolve(specifier, context, next) {
11
+ if (['pxmodel', 'optimize', 'look', 'lookbake'].some((m) => specifier === '@imports/castle.physics-3d/engine3d/' + m)) return { url: ${JSON.stringify(new URL('./fixtures/engine-models-stub.mjs', import.meta.url).href)}, shortCircuit: true };
12
+ if (specifier === '@imports/castle.physics-3d/engine3d/orbitlens.js') return { url: ${JSON.stringify(new URL('../../physics-3d/engine3d/orbitlens.js', import.meta.url).href)}, shortCircuit: true };
13
+ if (specifier === 'castle-web-sdk') return { url: 'data:text/javascript,export {};', shortCircuit: true };
14
+ if (specifier === '@imports/castle.multiplayer-3d/code/client/avatars.js') return { url: 'data:text/javascript,export const dropMissing = () => {};', shortCircuit: true };
15
+ if (specifier.startsWith('@imports/castle.physics-2d/engine/')) return { url: 'data:text/javascript,export const initialMedia = {}; export const playMedia = () => {}; export const stopMedia = () => {};', shortCircuit: true };
16
+ if (specifier === '../client/pack.js') return { url: 'data:text/javascript,export const cachedPacks = () => []; export const loadPack = () => {}; export const matchesOwn = () => false; export const resolveDeckDoor = () => {};', shortCircuit: true };
17
+ return next(specifier, context);
18
+ }
19
+ export async function load(url, context, next) {
20
+ if (url.endsWith('/code/client/hookLayer.js')) {
21
+ const source = await readFile(fileURLToPath(url), 'utf8');
22
+ return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
23
+ }
24
+ return next(url, context);
25
+ }
26
+ `)}`);
27
+ const State = await import('../code/client/state.js');
28
+ const { installSystem } = await import('../code/systems/hub.js');
29
+
30
+ let system;
31
+ installSystem({ registerSystem(value) { system = value; } });
32
+ const net = { selfId: () => 'p2' };
33
+ const scene = (camAngle, n = net) => ({ persistent: { camAngle }, multiplayer: { net: n } });
34
+ const log = console.log;
35
+ console.log = () => {};
36
+
37
+ // Fresh arrival: the camera starts behind the arrival facing.
38
+ State.clear();
39
+ State.hub.arrivedFacing = 0.5;
40
+ let s = scene(1);
41
+ system.faceArrival(s);
42
+ assert.equal(s.persistent.camAngle, Math.PI - 0.5);
43
+ assert.equal(State.hub.faced, true);
44
+
45
+ // A page that never arrived keeps nothing: its first arrival faces.
46
+ system.helloNet = net;
47
+ State.clear();
48
+ system.newIdentity();
49
+ State.hub.arrivedFacing = 0.5;
50
+ s = scene(1);
51
+ system.faceArrival(s);
52
+ assert.equal(s.persistent.camAngle, Math.PI - 0.5, 'no arrival yet: faces');
53
+
54
+ // A rejoin during a trip keeps nothing, even if the arrival lands after it.
55
+ system.trip = {};
56
+ system.newIdentity();
57
+ system.trip = null;
58
+ State.hub.arrivedFacing = 0.5;
59
+ s = scene(1);
60
+ system.faceArrival(s);
61
+ assert.equal(s.persistent.camAngle, Math.PI - 0.5, 'rejoin under a trip: faces');
62
+
63
+ // Rejoin on the same connection: the yaw the player had is kept.
64
+ system.newIdentity();
65
+ assert.equal(State.hub.faced, false);
66
+ State.hub.arrivedFacing = -0.443;
67
+ s = scene(1);
68
+ system.faceArrival(s);
69
+ assert.equal(s.persistent.camAngle, 1, 'rejoin keeps the camera yaw');
70
+ assert.equal(State.hub.faced, true);
71
+ assert.equal(s.faceRequest, undefined, 'and the avatar facing');
72
+
73
+ // Once only: the next arrival on that connection faces again.
74
+ State.hub.faced = false;
75
+ system.faceArrival(s);
76
+ assert.equal(s.persistent.camAngle, Math.PI + 0.443);
77
+
78
+ // A trip's arrival after a rejoin faces, and spends the keep.
79
+ State.hub.faced = true;
80
+ system.newIdentity();
81
+ State.hub.arrivedFacing = 0.25;
82
+ system.trip = {};
83
+ s = scene(1);
84
+ system.faceArrival(s);
85
+ assert.equal(s.persistent.camAngle, Math.PI - 0.25);
86
+ system.trip = null;
87
+ State.hub.faced = false;
88
+ s = scene(1);
89
+ system.faceArrival(s);
90
+ assert.equal(s.persistent.camAngle, Math.PI - 0.25);
91
+
92
+ // An arrival on another connection faces.
93
+ State.hub.faced = true;
94
+ system.newIdentity();
95
+ State.hub.arrivedFacing = 0.25;
96
+ s = scene(1, { selfId: () => 'p3' });
97
+ system.faceArrival(s);
98
+ assert.equal(s.persistent.camAngle, Math.PI - 0.25);
99
+
100
+ // No yaw yet on the page: faces.
101
+ State.hub.faced = true;
102
+ system.newIdentity();
103
+ State.hub.arrivedFacing = 0.25;
104
+ s = { persistent: {}, multiplayer: { net } };
105
+ system.faceArrival(s);
106
+ assert.equal(s.persistent.camAngle, Math.PI - 0.25);
107
+
108
+ // A fixed-view arrival still waiting for its shot does not turn a kept rejoin.
109
+ const { faceArrivalCamera, seedArrivalShot } = await import('../code/client/arrivalCamera.js');
110
+ s = { persistent: { camAngle: 0 }, multiplayer: { net, generation: 1 }, cameraControl: 'orbit',
111
+ data: { engine: { camera: { arrivalFromShot: { yaw: -38 } } } }, currentScenePath: 'a', sceneKey: 'k' };
112
+ State.clear();
113
+ faceArrivalCamera(s, 0.2);
114
+ State.hub.faced = true;
115
+ system.newIdentity();
116
+ s.persistent.camAngle = 1;
117
+ State.hub.arrivedFacing = 0.2;
118
+ system.faceArrival(s);
119
+ assert.equal(s.persistent.camAngle, 1);
120
+ seedArrivalShot(s, { yaw: -38, pitch: 30, distance: 10 });
121
+ assert.equal(s.persistent.camAngle, 1, 'the earlier wait for a shot was cancelled');
122
+
123
+ // Nor does the new session's shot when it comes before the arrival.
124
+ State.clear();
125
+ faceArrivalCamera(s, 0.2);
126
+ State.hub.faced = true;
127
+ system.scene = s;
128
+ system.freshSession = () => {};
129
+ system.newIdentity();
130
+ s.persistent.camAngle = 1;
131
+ seedArrivalShot(s, { yaw: -38, pitch: 30, distance: 10 });
132
+ assert.equal(s.persistent.camAngle, 1, 'a shot before the rejoin arrival does not turn it');
133
+ State.hub.arrivedFacing = 0.2;
134
+ system.faceArrival(s);
135
+ assert.equal(s.persistent.camAngle, 1);
136
+
137
+ console.log = log;
138
+ console.log('test-rejoin-yaw: ok');
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert/strict';
2
2
  import { register } from 'node:module';
3
- import { friendsAmong, prime, tick } from '../code/server/friendsAmong.js';
3
+ import { EARLY_EMPTY_MS, EARLY_WINDOW_MS, friendsAmong, prime, tick } from '../code/server/friendsAmong.js';
4
4
 
5
5
  // Exercise SDK source without a build or changing the generated base kit.
6
6
  register(`data:text/javascript,${encodeURIComponent(`
@@ -55,7 +55,9 @@ let now = 100000;
55
55
  Date.now = () => now;
56
56
  console.warn = () => {};
57
57
  const flush = () => new Promise((resolve) => setImmediate(resolve));
58
- function room(on = true, relations = async (_id, ids) => ({ friends: [], follows: ids, followedBy: [] })) {
58
+ // `seen`: accounts that already read in this session, so none of their reads is the
59
+ // session's provisional first (v1.166); the cases that predate it describe those.
60
+ function room(on = true, relations = async (_id, ids) => ({ friends: [], follows: ids, followedBy: [] }), seen = ['1']) {
59
61
  const identities = new Map([['a', '1'], ['b', '2'], ['guest', null], ['dev', 'dev-guest-1']]);
60
62
  const calls = [], sent = [];
61
63
  const h = {
@@ -66,6 +68,7 @@ function room(on = true, relations = async (_id, ids) => ({ friends: [], follows
66
68
  friendsAmong: async (id, ids) => { calls.push({ op: 'friends', id, ids, at: now }); return ids; },
67
69
  relationsAmong: (id, ids) => { calls.push({ op: 'relations', id, ids, at: now }); return relations(id, ids); },
68
70
  } },
71
+ friendsRead: new Map(seen.map((userId) => [userId, -Infinity])),
69
72
  };
70
73
  const identity = (_h, id) => identities.get(id);
71
74
  return { h, calls, sent, identity, add(id, userId = id) {
@@ -142,10 +145,12 @@ try {
142
145
  assert.equal(capped.calls[0].ids.length, 100);
143
146
  assert.deepEqual(capped.calls[0].ids.slice(0, 4), ['999', '998', '2', '10']);
144
147
 
145
- // Five minutes of arrivals, both nonempty and empty answers: background
146
- // traffic respects the minimum read gap for every signed-in player.
148
+ // Five minutes of arrivals, both nonempty and empty answers, every account new
149
+ // to the session: background traffic respects the minimum read gap for every
150
+ // signed-in player, except one early re-read of a provisional first empty
151
+ // answer (v1.166), and never more than two reads in an account's first minute.
147
152
  for (const empty of [false, true]) {
148
- const rate = room(true, async (_id, ids) => ({ friends: [], follows: empty ? [] : ids, followedBy: [] }));
153
+ const rate = room(true, async (_id, ids) => ({ friends: [], follows: empty ? [] : ids, followedBy: [] }), []);
149
154
  const start = now;
150
155
  for (let seconds = 0; seconds <= 300; seconds += 5) {
151
156
  now = start + seconds * 1000;
@@ -155,8 +160,9 @@ try {
155
160
  }
156
161
  for (const id of new Set(rate.calls.map((call) => call.id))) {
157
162
  const times = rate.calls.filter((call) => call.id === id).map((call) => call.at);
158
- assert.ok(times.every((at, i) => i === 0 || at - times[i - 1] >= 31000), `${id}: minimum read gap`);
159
- assert.ok(times.length <= Math.floor(300000 / 31000) + 1, `${id}: five minute count bound`);
163
+ assert.ok(times.every((at, i) => i === 0 || at - times[i - 1] >= (i === 1 ? EARLY_EMPTY_MS : 31000)), `${id}: minimum read gap`);
164
+ assert.ok(times.filter((at) => at - times[0] < EARLY_WINDOW_MS).length <= 2, `${id}: two reads in the first minute`);
165
+ assert.ok(times.length <= Math.floor(300000 / 31000) + 2, `${id}: five minute count bound`);
160
166
  }
161
167
  assert.ok(rate.calls.every(({ id, op }) => !['guest', 'dev'].includes(id) && op === 'relations'));
162
168
  }
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
2
2
  import test from 'node:test';
3
3
  import { execFile } from 'node:child_process';
4
4
  import { promisify } from 'node:util';
5
- import { friendsAmong, prime, tick } from '../code/server/friendsAmong.js';
5
+ import { EARLY_EMPTY_MS, EARLY_WINDOW_MS, emptyFor, forget, friendsAmong, prime, tick } from '../code/server/friendsAmong.js';
6
6
  import { friendBests } from '../code/server/friendBests.js';
7
7
 
8
8
  const { stdout } = await promisify(execFile)('git', [
@@ -18,7 +18,9 @@ Date.now = () => now;
18
18
  console.warn = () => {};
19
19
  const flush = () => new Promise((resolve) => setImmediate(resolve));
20
20
  const empty = () => ({ friends: [], follows: [], followedBy: [] });
21
- function room(relations, on = true) {
21
+ // `seen`: both accounts read earlier in this session, so no read is a session's
22
+ // provisional first (v1.166); the cases below that predate it describe those reads.
23
+ function room(relations, on = true, seen = true) {
22
24
  const calls = [], sent = [];
23
25
  const identity = (_h, id) => ({ a: '1', b: '2' })[id] ?? null;
24
26
  const h = {
@@ -34,6 +36,7 @@ function room(relations, on = true) {
34
36
  },
35
37
  },
36
38
  ctx: {},
39
+ ...(seen ? { friendsRead: new Map([['1', -Infinity], ['2', -Infinity]]) } : {}),
37
40
  };
38
41
  h.ctx.friendsAmong = (id, ids) => friendsAmong(h, id, ids, identity);
39
42
  return { h, calls, sent, identity };
@@ -154,6 +157,91 @@ try {
154
157
  }
155
158
  });
156
159
 
160
+ await test('v1.166: a session\'s first empty prime is redone after 5 s, then nothing until a minute after the first', async () => {
161
+ let marked = false;
162
+ const r = room(async (_id, ids) => ({ ...empty(), friends: marked ? ids.filter((id) => id === '2') : [] }), true, false);
163
+ const start = now;
164
+ for (let elapsed = 0; elapsed <= 120000; elapsed += 1000) {
165
+ now = start + elapsed;
166
+ // Deck asks naming new off-place ids every few seconds press for reads.
167
+ if (elapsed % 3000 === 0) await r.h.ctx.friendsAmong('a', [String(100 + elapsed)]);
168
+ tick(r.h, r.identity);
169
+ await flush();
170
+ }
171
+ for (const id of ['a', 'b']) {
172
+ const reads = r.calls.filter((call) => call.id === id).map((call) => call.at - start);
173
+ assert.ok(reads[1] - reads[0] >= EARLY_EMPTY_MS && reads[1] - reads[0] < GAP, `${id}: one early re-read`);
174
+ assert.equal(reads.filter((at) => at - reads[0] < EARLY_WINDOW_MS).length, 2, `${id}: two reads in the first minute`);
175
+ assert.ok(reads[2] - reads[0] >= EARLY_WINDOW_MS, `${id}: the third waits out the window`);
176
+ assert.ok(reads.slice(2).every((at, i) => at - reads[i + 1] >= GAP), `${id}: then the usual gap`);
177
+ }
178
+ // The early re-read sees a friend ghost marked meanwhile.
179
+ const late = room(async (_id, ids) => (marked ? ids : []), false, false);
180
+ marked = false;
181
+ const begin = now;
182
+ assert.deepEqual(await late.h.ctx.friendsAmong('a', ['2']), []);
183
+ assert.equal(late.h.friendsCache.get('a').ttl, EARLY_EMPTY_MS);
184
+ marked = true;
185
+ now = begin + EARLY_EMPTY_MS - 1;
186
+ assert.deepEqual(await late.h.ctx.friendsAmong('a', ['2']), []);
187
+ now = begin + EARLY_EMPTY_MS;
188
+ assert.deepEqual(await late.h.ctx.friendsAmong('a', ['2']), ['2']);
189
+ assert.equal(late.calls.length, 2);
190
+ });
191
+
192
+ await test('v1.166: keyless, a later empty after the early re-read waits out the first minute; a rejoin is no new first', async () => {
193
+ const r = room(async () => [], false, false);
194
+ const start = now;
195
+ assert.deepEqual(await r.h.ctx.friendsAmong('a', ['2']), []);
196
+ now = start + EARLY_EMPTY_MS;
197
+ assert.deepEqual(await r.h.ctx.friendsAmong('a', ['2']), []);
198
+ assert.equal(r.calls.length, 2);
199
+ now = start + EARLY_WINDOW_MS - 1;
200
+ assert.deepEqual(await r.h.ctx.friendsAmong('a', ['2']), []);
201
+ assert.equal(r.calls.length, 2);
202
+ now = start + EARLY_WINDOW_MS;
203
+ assert.deepEqual(await r.h.ctx.friendsAmong('a', ['2']), []);
204
+ assert.equal(r.calls.length, 3);
205
+ assert.equal(r.h.friendsCache.get('a').ttl, EMPTY, 'outside the window, empties keep 40 s');
206
+ // Leaving and coming back in the same session is not another first read.
207
+ forget(r.h, 'a');
208
+ r.h.friendsCache.delete('a');
209
+ now += 1;
210
+ assert.deepEqual(await r.h.ctx.friendsAmong('a', ['2']), []);
211
+ assert.equal(r.h.friendsCache.get('a').ttl, EMPTY);
212
+ assert.equal(r.h.friendsCache.get('a').provisional, false);
213
+ });
214
+
215
+ await test('an ask waiting on a prime starts no read once the account has changed', async () => {
216
+ let settle;
217
+ const r = room(() => new Promise((resolve) => { settle = resolve; }), true, false);
218
+ let who = '1';
219
+ const identity = (_h, id) => (id === 'a' ? who : { b: '2' }[id]);
220
+ prime(r.h, 'a', identity);
221
+ const ask = friendsAmong(r.h, 'a', ['9'], identity);
222
+ who = '3';
223
+ now += EARLY_EMPTY_MS;
224
+ settle(empty());
225
+ assert.deepEqual(await ask, []);
226
+ assert.equal(r.calls.filter(({ id }) => id === 'a').length, 1, 'no covering read for another account');
227
+ assert.equal(r.h.friendsCache.get('a').owner, '1');
228
+ });
229
+
230
+ await test('v1.166: friendBests keeps an empty answer only until friendsAmong may read again, even after a friend', async () => {
231
+ const r = room(async (_id, ids) => ({ ...empty(), friends: r.calls.length > 1 ? ids.filter((id) => id === '2') : [] }), true, false);
232
+ const start = now;
233
+ prime(r.h, 'a', r.identity);
234
+ await flush();
235
+ assert.equal(emptyFor(r.h, 'a', '1'), EARLY_EMPTY_MS);
236
+ now = start + EARLY_EMPTY_MS;
237
+ prime(r.h, 'a', r.identity);
238
+ await flush();
239
+ assert.deepEqual(r.h.friendsCache.get('a').ids, ['2']);
240
+ // Uncovered candidates may be read at the end of the first minute, not in 10 min.
241
+ assert.equal(emptyFor(r.h, 'a', '1'), EARLY_WINDOW_MS - EARLY_EMPTY_MS);
242
+ assert.equal(emptyFor(r.h, 'a', '2'), EMPTY);
243
+ });
244
+
157
245
  await test('keyless answers, calls, args and timestamps equal origin/main', async () => {
158
246
  async function trace(api) {
159
247
  now = 100000;