castle-web-cli 0.4.238 → 0.4.240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. package/dist/agent.js +5 -1
  2. package/dist/api.d.ts +20 -0
  3. package/dist/api.js +57 -0
  4. package/dist/bundle.d.ts +38 -1
  5. package/dist/bundle.js +309 -13
  6. package/dist/castle-host/host.js +218 -11
  7. package/dist/castleJson.d.ts +10 -0
  8. package/dist/castleJson.js +46 -2
  9. package/dist/check.js +5 -2
  10. package/dist/devSessionServer.js +4 -1
  11. package/dist/devSessionStorage.d.ts +1 -0
  12. package/dist/devSessionStorage.js +32 -7
  13. package/dist/importOrder.d.ts +2 -0
  14. package/dist/importOrder.js +29 -0
  15. package/dist/index.js +22 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +9 -0
  19. package/dist/platformDoc.js +4 -2
  20. package/dist/playPagePolicy.d.ts +1 -0
  21. package/dist/playPagePolicy.js +12 -3
  22. package/dist/resetLeaderboards.d.ts +8 -1
  23. package/dist/resetLeaderboards.js +43 -8
  24. package/dist/roomLogs.d.ts +39 -0
  25. package/dist/roomLogs.js +166 -0
  26. package/dist/save-deck.d.ts +32 -2
  27. package/dist/save-deck.js +240 -39
  28. package/kits/base/CLAUDE.md +2 -1
  29. package/kits/base/castle.json +1 -1
  30. package/kits/base/sdk/README.md +240 -8
  31. package/kits/base/sdk/analytics.d.ts +8 -0
  32. package/kits/base/sdk/analytics.js +92 -0
  33. package/kits/base/sdk/castle.d.ts +8 -2
  34. package/kits/base/sdk/castle.js +3 -0
  35. package/kits/base/sdk/commands.d.ts +79 -0
  36. package/kits/base/sdk/commands.js +1 -0
  37. package/kits/base/sdk/debugConsole.d.ts +17 -0
  38. package/kits/base/sdk/debugConsole.js +154 -0
  39. package/kits/base/sdk/experiments.js +24 -1
  40. package/kits/base/sdk/hostRetry.d.ts +7 -0
  41. package/kits/base/sdk/hostRetry.js +57 -0
  42. package/kits/base/sdk/hub.d.ts +20 -2
  43. package/kits/base/sdk/hub.js +99 -13
  44. package/kits/base/sdk/multiplayer.d.ts +2 -0
  45. package/kits/base/sdk/multiplayer.js +198 -26
  46. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  47. package/kits/base/sdk/reconnectBudget.js +41 -1
  48. package/kits/base/sdk/rooms.d.ts +11 -0
  49. package/kits/base/sdk/rooms.js +22 -0
  50. package/kits/base/sdk/runtime.js +36 -19
  51. package/kits/base/sdk/server/hub.d.ts +19 -0
  52. package/kits/base/sdk/server/hub.js +12 -0
  53. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  54. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  55. package/kits/base/sdk/server/wrapper.js +26 -1
  56. package/kits/base/sdk/store.d.ts +8 -2
  57. package/kits/base/sdk/store.js +5 -1
  58. package/kits/base/sdk/transport.d.ts +2 -1
  59. package/kits/base/sdk/transport.js +35 -0
  60. package/kits/hub-game/CLAUDE.md +66 -19
  61. package/kits/hub-game/castle.json +4 -4
  62. package/kits/hub-game/code/client/act.js +9 -6
  63. package/kits/hub-game/code/client/actCore.js +26 -6
  64. package/kits/hub-game/code/client/actGateLog.js +36 -0
  65. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  66. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  67. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  68. package/kits/hub-game/code/client/askSurface.js +85 -0
  69. package/kits/hub-game/code/client/askTree.js +51 -0
  70. package/kits/hub-game/code/client/attention.js +31 -6
  71. package/kits/hub-game/code/client/ballot.js +42 -5
  72. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  73. package/kits/hub-game/code/client/ballotTree.js +180 -0
  74. package/kits/hub-game/code/client/catchingUp.js +19 -0
  75. package/kits/hub-game/code/client/celebrate.js +66 -0
  76. package/kits/hub-game/code/client/chrome.js +474 -53
  77. package/kits/hub-game/code/client/companion.js +93 -23
  78. package/kits/hub-game/code/client/companionDress.js +1 -1
  79. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  80. package/kits/hub-game/code/client/cornerTree.js +83 -0
  81. package/kits/hub-game/code/client/decor.js +20 -11
  82. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  83. package/kits/hub-game/code/client/disguise.js +23 -0
  84. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  85. package/kits/hub-game/code/client/dockSurface.js +206 -0
  86. package/kits/hub-game/code/client/dockTree.js +232 -0
  87. package/kits/hub-game/code/client/earned.js +29 -0
  88. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  89. package/kits/hub-game/code/client/emoteTree.js +264 -0
  90. package/kits/hub-game/code/client/farAvatars.js +4 -3
  91. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  92. package/kits/hub-game/code/client/grab.js +121 -50
  93. package/kits/hub-game/code/client/holdShow.js +19 -0
  94. package/kits/hub-game/code/client/hookLayer.js +96 -12
  95. package/kits/hub-game/code/client/hubControls.js +7 -1
  96. package/kits/hub-game/code/client/hudSurface.js +11 -3
  97. package/kits/hub-game/code/client/hudTree.js +7 -4
  98. package/kits/hub-game/code/client/idle.js +21 -3
  99. package/kits/hub-game/code/client/invites.js +24 -3
  100. package/kits/hub-game/code/client/keys.js +15 -0
  101. package/kits/hub-game/code/client/labelsNear.js +8 -1
  102. package/kits/hub-game/code/client/layoutCache.js +57 -8
  103. package/kits/hub-game/code/client/loadingCover.js +53 -4
  104. package/kits/hub-game/code/client/menuIcons.js +15 -0
  105. package/kits/hub-game/code/client/menuRows.js +8 -2
  106. package/kits/hub-game/code/client/menuSurface.js +102 -0
  107. package/kits/hub-game/code/client/menuTree.js +135 -0
  108. package/kits/hub-game/code/client/modelLook.js +41 -0
  109. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  110. package/kits/hub-game/code/client/pickerTree.js +163 -0
  111. package/kits/hub-game/code/client/pushVisit.js +4 -2
  112. package/kits/hub-game/code/client/quality.js +188 -29
  113. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  114. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  115. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  116. package/kits/hub-game/code/client/rehello.js +75 -0
  117. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  118. package/kits/hub-game/code/client/replay.js +118 -0
  119. package/kits/hub-game/code/client/role.js +3 -0
  120. package/kits/hub-game/code/client/safeLayout.js +441 -56
  121. package/kits/hub-game/code/client/safeStyle.js +13 -10
  122. package/kits/hub-game/code/client/say.js +2 -0
  123. package/kits/hub-game/code/client/soundSurface.js +77 -0
  124. package/kits/hub-game/code/client/soundTree.js +74 -0
  125. package/kits/hub-game/code/client/soundscape.js +12 -9
  126. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  127. package/kits/hub-game/code/client/state.js +67 -1
  128. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  129. package/kits/hub-game/code/client/stuckTree.js +67 -0
  130. package/kits/hub-game/code/client/talk.js +42 -12
  131. package/kits/hub-game/code/client/talkTree.js +4 -2
  132. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  133. package/kits/hub-game/code/client/textAskTree.js +67 -0
  134. package/kits/hub-game/code/client/tiers.js +252 -27
  135. package/kits/hub-game/code/client/together.js +4 -1
  136. package/kits/hub-game/code/client/uiDom.js +86 -8
  137. package/kits/hub-game/code/client/uiTree.js +33 -4
  138. package/kits/hub-game/code/client/vehicle.js +75 -52
  139. package/kits/hub-game/code/client/weakestTier.js +75 -31
  140. package/kits/hub-game/code/client/wear.js +159 -5
  141. package/kits/hub-game/code/client/worldLabels.js +215 -26
  142. package/kits/hub-game/code/companionSpec.js +4 -2
  143. package/kits/hub-game/code/server/act.js +3 -0
  144. package/kits/hub-game/code/server/actGate.js +83 -0
  145. package/kits/hub-game/code/server/actions.js +71 -15
  146. package/kits/hub-game/code/server/actors.js +20 -5
  147. package/kits/hub-game/code/server/analytics.js +40 -15
  148. package/kits/hub-game/code/server/ask.js +39 -3
  149. package/kits/hub-game/code/server/ballot.js +167 -4
  150. package/kits/hub-game/code/server/celebrate.js +64 -0
  151. package/kits/hub-game/code/server/companion.js +17 -2
  152. package/kits/hub-game/code/server/decor.js +11 -2
  153. package/kits/hub-game/code/server/disguise.js +63 -0
  154. package/kits/hub-game/code/server/doorAnalytics.js +2 -5
  155. package/kits/hub-game/code/server/earned.js +6 -2
  156. package/kits/hub-game/code/server/friendBests.js +13 -4
  157. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  158. package/kits/hub-game/code/server/grab.js +12 -2
  159. package/kits/hub-game/code/server/heldOffers.js +142 -0
  160. package/kits/hub-game/code/server/holdShow.js +98 -0
  161. package/kits/hub-game/code/server/hub.js +854 -45
  162. package/kits/hub-game/code/server/idle.js +110 -9
  163. package/kits/hub-game/code/server/index.js +9 -0
  164. package/kits/hub-game/code/server/labels.js +13 -3
  165. package/kits/hub-game/code/server/loadAbandon.js +2 -5
  166. package/kits/hub-game/code/server/manifest.js +94 -6
  167. package/kits/hub-game/code/server/menu.js +26 -3
  168. package/kits/hub-game/code/server/npcs.js +55 -9
  169. package/kits/hub-game/code/server/observe.js +67 -6
  170. package/kits/hub-game/code/server/players.js +8 -1
  171. package/kits/hub-game/code/server/replay.js +135 -0
  172. package/kits/hub-game/code/server/storageLimit.js +4 -1
  173. package/kits/hub-game/code/server/townDay.js +74 -0
  174. package/kits/hub-game/code/server/trackQueue.js +29 -0
  175. package/kits/hub-game/code/server/vehicle.js +3 -0
  176. package/kits/hub-game/code/server/vis.js +26 -4
  177. package/kits/hub-game/code/server/wallet.js +677 -0
  178. package/kits/hub-game/code/server/wear.js +13 -3
  179. package/kits/hub-game/code/server/writerLease.js +191 -0
  180. package/kits/hub-game/code/shared/act.js +1 -1
  181. package/kits/hub-game/code/shared/expression.js +6 -0
  182. package/kits/hub-game/code/shared/replay.js +37 -0
  183. package/kits/hub-game/code/systems/hub.js +437 -57
  184. package/kits/hub-game/docs/analytics.md +20 -3
  185. package/kits/hub-game/docs/contract.md +942 -99
  186. package/kits/hub-game/docs/home-pieces.md +5 -6
  187. package/kits/hub-game/docs/observed-progress.md +49 -1
  188. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  189. package/kits/hub-game/index.html +1 -0
  190. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  207. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  208. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  209. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  210. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  211. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  212. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  213. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  214. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  215. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  216. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  217. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  218. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  219. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  220. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  221. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  222. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  223. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  224. package/kits/hub-game/package-lock.json +3 -3
  225. package/kits/hub-game/package.json +4 -3
  226. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  227. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  228. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  229. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  230. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  231. package/kits/hub-game/scripts/pack.mjs +89 -23
  232. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  233. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  234. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  235. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  236. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  237. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  238. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  239. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  240. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  241. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  242. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  243. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  244. package/kits/hub-game/scripts/test-analytics.mjs +80 -1
  245. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  246. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  247. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  248. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  249. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  250. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  251. package/kits/hub-game/scripts/test-ballot.mjs +420 -3
  252. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  253. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  254. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  255. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  256. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  257. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  258. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  259. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  260. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  261. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  262. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  263. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  264. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  265. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  266. package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
  267. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  268. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  269. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  270. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  271. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  272. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  273. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  274. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  275. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  276. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  277. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  278. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  279. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  280. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  281. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  282. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  283. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  284. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  285. package/kits/hub-game/scripts/test-hub-ops.mjs +147 -0
  286. package/kits/hub-game/scripts/test-hub-trip.mjs +260 -5
  287. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  288. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  289. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  290. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  291. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  292. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  293. package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
  294. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  295. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  296. package/kits/hub-game/scripts/test-menu-client.mjs +55 -6
  297. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  298. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  299. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  300. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  301. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  302. package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
  303. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  304. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  305. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  306. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  307. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  308. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  309. package/kits/hub-game/scripts/test-rehello.mjs +237 -0
  310. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  311. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  312. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  313. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  314. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  315. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  316. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  317. package/kits/hub-game/scripts/test-resync.mjs +13 -0
  318. package/kits/hub-game/scripts/test-role-client.mjs +10 -3
  319. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  320. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  321. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  322. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  323. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  324. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  325. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  326. package/kits/hub-game/scripts/test-stuck.mjs +31 -0
  327. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  328. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  329. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  330. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  331. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  332. package/kits/hub-game/scripts/test-together.mjs +11 -0
  333. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  334. package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
  335. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  336. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  337. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  338. package/kits/hub-game/scripts/test-vehicle-client.mjs +77 -1
  339. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  340. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  341. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  342. package/kits/hub-game/scripts/test-world-labels.mjs +380 -0
  343. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  344. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  345. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  346. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  347. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  348. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +48 -2
  349. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +21 -3
  350. package/kits/multiplayer-3d/castle.json +5 -5
  351. package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
  352. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  353. package/kits/multiplayer-3d/code/server/world.js +19 -4
  354. package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
  355. package/kits/multiplayer-3d/package-lock.json +1 -1
  356. package/kits/multiplayer-3d/package.json +2 -1
  357. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  358. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  359. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  360. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
  361. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  362. package/kits/physics-2d/castle.json +2 -2
  363. package/kits/physics-2d/engine/scene.js +10 -2
  364. package/kits/physics-3d/CLAUDE.md +14 -0
  365. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  366. package/kits/physics-3d/castle.json +3 -3
  367. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  368. package/kits/physics-3d/docs/engine-player.md +76 -0
  369. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  370. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  371. package/kits/physics-3d/engine3d/gait.js +16 -8
  372. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  373. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  374. package/kits/physics-3d/engine3d/look.js +110 -17
  375. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  376. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  377. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  378. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  379. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  380. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  381. package/kits/physics-3d/engine3d/optimize.js +20 -9
  382. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  383. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  384. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  385. package/kits/physics-3d/engine3d/world3d.js +211 -17
  386. package/kits/physics-3d/package-lock.json +1 -1
  387. package/kits/physics-3d/package.json +2 -1
  388. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  389. package/kits/physics-3d/scripts/render.mjs +56 -8
  390. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  391. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  392. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  393. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  394. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  395. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  396. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  397. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  398. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  399. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  400. package/kits/physics-3d/systems/physics3d.js +51 -2
  401. package/kits/real-time/castle.json +2 -2
  402. package/kits/real-time/code/client/connection.js +3 -0
  403. package/package.json +2 -2
  404. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -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);
@@ -1631,6 +1632,51 @@ for (const readFirst of [true, false]) {
1631
1632
  }
1632
1633
  }
1633
1634
 
1635
+ // A sign-up's account read that never settles lets the placed player go at
1636
+ // five seconds, logged, and a read landing afterwards keeps the carried look.
1637
+ {
1638
+ const realNow = Date.now, warn = console.warn, warned = [];
1639
+ let now = realNow();
1640
+ Date.now = () => now;
1641
+ console.warn = (...args) => warned.push(args.join(' '));
1642
+ try {
1643
+ const r = boot({ anonymousEntry: true, avatarColors: true }, { players: guestRoster() });
1644
+ const at = { x: 21, y: 2, z: -4 };
1645
+ r.ctx().placeAt('p2', at, 40);
1646
+ r.say('p2', { k: 'hub-hello', avatar: 7, color: 11, again: true });
1647
+ r.tick();
1648
+ let resolveRead;
1649
+ const read = new Promise((resolve) => { resolveRead = resolve; });
1650
+ r.session.hub = { arrival: () => null, readResults: (input) => input.userIds ? read : Promise.resolve({ boards: {} }) };
1651
+ Object.assign(r.session.players.find((p) => p.playerId === 'p2'), { username: 'Bo', isAnonymous: false });
1652
+ r.say('p2', { k: 'hub-hello', avatar: 0, color: 0, party: 1 });
1653
+ r.tick();
1654
+ const arrivals = r.arrivedTimes('p2');
1655
+ now += 2000; r.tick();
1656
+ assert.equal(r.arrivedTimes('p2'), arrivals, 'placed, still waiting on the read');
1657
+ assert.ok(r.server.join().held.includes('p2'));
1658
+ now += 4999; r.tick();
1659
+ assert.equal(r.arrivedTimes('p2'), arrivals, 'a read that settles in time holds as before');
1660
+ assert.equal(warned.some((line) => line.startsWith('[hub] arrival hold released')), false);
1661
+ now += 1; r.tick();
1662
+ assert.equal(r.arrivedTimes('p2'), arrivals + 1, 'the sign-up hold lets go at the bound');
1663
+ assert.equal(r.server.join().held.includes('p2'), false);
1664
+ assert.deepEqual(r.world.players.get('p2').at, at);
1665
+ assert.equal(r.server.join().hubAv2.p2, 7);
1666
+ assert.deepEqual(warned.filter((line) => line.startsWith('[hub] arrival hold released')), ['[hub] arrival hold released after 5 s: signup-results']);
1667
+ resolveRead({ players: { 102: { avatar: 0, avatarColor: 0 } }, boards: {} });
1668
+ await new Promise((resolve) => setImmediate(resolve));
1669
+ r.tick();
1670
+ assert.equal(r.server.join().hubAv2.p2, 7, 'a late read cannot replace the carried avatar');
1671
+ assert.equal(r.server.join().hubAvC.p2, 11);
1672
+ assert.equal(r.arrivedTimes('p2'), arrivals + 1, 'the late read replays no arrival');
1673
+ console.log('ok: an unsettled sign-up read releases at 5 s');
1674
+ } finally {
1675
+ Date.now = realNow;
1676
+ console.warn = warn;
1677
+ }
1678
+ }
1679
+
1634
1680
  // Terminal carry regression matrix against the real hub server: both orders,
1635
1681
  // success/empty/rejection, delayed reads, repeated hellos, explicit choices,
1636
1682
  // account switches and throwing authored arrivals. Carry is consumed once.
@@ -1776,6 +1822,25 @@ test('pose-only explicit travel cannot return to its old pose', () => {
1776
1822
  assert.notEqual(r.world.players.get('p2').at.x, -3);
1777
1823
  });
1778
1824
 
1825
+ 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) => {
1826
+ for (const [how, restores] of [['back', false], ['stale', true], ['account', true]]) {
1827
+ const r = boot({ resumeArrivalPose: true });
1828
+ r.ctx().placeAt('p2', { x: -3, y: 1, z: -2 }, 40); r.tick();
1829
+ r.say('p2', { k: 'hub-back' }); r.tick();
1830
+ if (how === 'stale') {advance(36_000); r.tick();}
1831
+ // A new hello under another account on the same socket drops the mark.
1832
+ if (how === 'account') {
1833
+ r.session.players.find(p => p.playerId === 'p2').userId = '103';
1834
+ r.say('p2', rehello); r.tick(); r.tick();
1835
+ r.ctx().placeAt('p2', { x: -3, y: 1, z: -2 }, 40); r.tick();
1836
+ }
1837
+ r.drop(); r.tick(); r.back();
1838
+ if (how === 'account') {r.session.players.find(p => p.playerId === 'p2').userId = '103';}
1839
+ r.say('p2', rehello); r.tick();
1840
+ assert.equal(r.world.players.get('p2').at.x === -3, restores, how);
1841
+ }
1842
+ }));
1843
+
1779
1844
  test('pose-only mode fails closed across changed or anonymous identity', () => {
1780
1845
  for (const identity of [{ userId: '103', isAnonymous: false }, { userId: '102', isAnonymous: true }]) {
1781
1846
  const r = boot({ resumeArrivalPose: true });
@@ -1985,4 +2050,176 @@ test('a lone arrival stepping off an occupied slot keeps clear of placed furnitu
1985
2050
  console.log('ok: a drop without an end still restores its pose');
1986
2051
  }
1987
2052
 
2053
+ // v1.173: the player's own Back (`hub-back`, said just before Hub.back) ends
2054
+ // the visit, so the next entry is a fresh arrival; a drop with no word still
2055
+ // resumes. A game, a repeat, an earlier trip and a player not here change
2056
+ // nothing, and the place's own message hook never hears it.
2057
+ {
2058
+ const floor = { id: 'floor', components: { Solid: {}, Transform: { x: 0, y: -0.07, z: 0 }, Shape: { kind: 'box', width: 40, height: 0.14, depth: 40 } } };
2059
+ const arrival = { x: 3, y: 1, z: -4 };
2060
+ const spot = { x: -3.5, y: 1, z: 2.3 };
2061
+ const heard = [];
2062
+ // One visit by p2: arrive, move to `spot`, then `before(r)` (the Back, or
2063
+ // nothing), a drop, and a return under the same account: a resume of the
2064
+ // same player id, or (`fresh`) a new connection with a new id.
2065
+ async function visit(keys, { before = () => {}, fresh = true, door = false } = {}) {
2066
+ const storage = makePoseStorage();
2067
+ const r = boot({ resumePose: true, arrival: { actor: 'arrival', spread: 0.65, face: 60 }, ...(door ? { places: { lobby: { title: 'Lobby', scene: 'scenes/lobby.scene' } } } : {}), ...keys }, {
2068
+ actors: [...actors, floor, { id: 'arrival', components: { Transform: arrival } },
2069
+ ...(door ? [{ id: 'door', components: { HubDoor: { id: 'out', to: 'lobby' }, Transform: { x: 5, y: 0, z: 5 } } }] : [])],
2070
+ ground: { none: true }, storage, message: (c, player, data) => heard.push(data.k),
2071
+ });
2072
+ await flushPose(); r.tick(2000); r.tick();
2073
+ r.ctx().placeAt('p2', spot); r.tick();
2074
+ const from = r.sent.length;
2075
+ await before(r);
2076
+ const answered = toP2(r, from);
2077
+ r.tick(); r.drop(); r.tick(); await flushPose();
2078
+ const stored = [...storage.rows.keys()].filter((k) => k.includes('"102"')).length;
2079
+ let id = 'p2';
2080
+ if (fresh) {
2081
+ id = 'new-p2';
2082
+ r.session.players.push({ playerId: id, userId: '102', username: 'Bo', isAnonymous: false });
2083
+ r.world.players.set(id, body());
2084
+ r.say(id, { k: 'hub-hello', avatar: 1, party: 1 });
2085
+ } else {
2086
+ r.back(); r.say('p2', rehello);
2087
+ }
2088
+ await flushPose(); r.tick(2000); r.tick();
2089
+ const at = r.world.players.get(id).at;
2090
+ return { r, stored, answered, restored: Math.hypot(at.x - spot.x, at.z - spot.z) < 0.01 };
2091
+ }
2092
+ const backOnce = (r) => r.say('p2', { k: 'hub-back' });
2093
+
2094
+ for (const fresh of [true, false]) {
2095
+ const how = fresh ? 'a new connection' : 'a same-id resume';
2096
+ const control = await visit({}, { fresh });
2097
+ assert.equal(control.restored, true, `${how}: a drop with no hub-back restores the stored pose`);
2098
+ const backed = await visit({}, { fresh, before: backOnce });
2099
+ assert.equal(backed.restored, false, `${how}: after hub-back the return is placed at the arrival`);
2100
+ assert.deepEqual(backed.answered, [], 'hub-back is answered with nothing');
2101
+ assert.equal(backed.stored, 0, 'hub-back leaves no durable pose');
2102
+ if (!fresh) {assert.equal(backed.r.arrivedTimes('p2'), 2, 'the same-id return arrives afresh');}
2103
+ console.log(`ok: hub-back ends the visit: ${how} after it is a fresh arrival; without it the pose is restored`);
2104
+ }
2105
+
2106
+ const twice = await visit({}, { before: (r) => { backOnce(r); r.tick(); backOnce(r); backOnce(r); } });
2107
+ assert.equal(twice.restored, false);
2108
+ assert.deepEqual(twice.answered, [], 'a repeat sends nothing');
2109
+ console.log('ok: a repeated hub-back is harmless');
2110
+
2111
+ 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'); } });
2112
+ const goneAlone = await visit({}, { door: true, before: (r) => { assert.ok(r.ctx().go('out', ['p2'])); } });
2113
+ const kinds = (ms) => ms.map((m) => [m.k, m.door]);
2114
+ assert.deepEqual(kinds(gone.answered), kinds(goneAlone.answered), 'the trip says the same with or without a hub-back after it');
2115
+ assert.equal(gone.restored, false); assert.equal(goneAlone.restored, false);
2116
+ console.log('ok: hub-back after a kit trip (sendGo) is a no-op');
2117
+
2118
+ // A player the session does not list (an id it never had, or one briefly
2119
+ // out of the roster) ends no visit: the later drop still resumes.
2120
+ const unlisted = await visit({}, { fresh: false, before: (r) => {
2121
+ r.say('ghost', { k: 'hub-back' });
2122
+ const row = r.session.players.find((p) => p.playerId === 'p2');
2123
+ r.session.players = r.session.players.filter((p) => p !== row);
2124
+ backOnce(r);
2125
+ r.session.players.push(row);
2126
+ } });
2127
+ assert.equal(unlisted.restored, true, 'the unlisted hub-back is ignored');
2128
+ console.log('ok: hub-back from a player not in the roster is ignored');
2129
+
2130
+ // A session that shuts down before any tick saw the drop still lets the
2131
+ // Back's visit go, and keeps a plain drop's pose as before.
2132
+ for (const backed of [false, true]) {
2133
+ const storage = makePoseStorage();
2134
+ const r = boot({ resumePose: true, arrival: { actor: 'arrival', spread: 0.65, face: 60 } }, {
2135
+ actors: [...actors, floor, { id: 'arrival', components: { Transform: arrival } }], ground: { none: true }, storage,
2136
+ });
2137
+ await flushPose(); r.tick(2000); r.tick();
2138
+ r.ctx().placeAt('p2', spot); r.tick();
2139
+ if (backed) {backOnce(r);}
2140
+ r.drop();
2141
+ await r.server.shutdown(r.session); await flushPose();
2142
+ const stored = [...storage.rows.keys()].filter((k) => k.includes('"102"')).length;
2143
+ assert.equal(stored, backed ? 0 : 1, backed ? 'a Back before shutdown keeps no pose' : 'a plain drop at shutdown keeps its pose');
2144
+ }
2145
+ console.log('ok: hub-back then a shutdown before the next tick keeps no pose');
2146
+
2147
+ // The Back only arms: with no drop inside the window (Hub.back refused or
2148
+ // timed out, the player still here), a later genuine drop resumes.
2149
+ {
2150
+ const realNow = Date.now;
2151
+ let now = realNow();
2152
+ Date.now = () => now;
2153
+ try {
2154
+ for (const fresh of [true, false]) {
2155
+ const stale = await visit({}, { fresh, before: (r) => { backOnce(r); r.tick(); now += 36_000; r.tick(); } });
2156
+ assert.equal(stale.restored, true, `${fresh ? 'a new connection' : 'a same-id resume'}: a Back whose window passed leaves the visit as it was`);
2157
+ assert.equal(stale.stored, 1, 'the drop stores the pose as usual');
2158
+ if (!fresh) {assert.equal(stale.r.arrivedTimes('p2'), 1, 'resumed, not arrived again');}
2159
+ const inside = await visit({}, { fresh, before: (r) => { backOnce(r); r.tick(); now += 30_000; r.tick(); } });
2160
+ assert.equal(inside.restored, false, 'a drop inside the window is the Back leaving');
2161
+ // A repeat refreshes the mark: 20 s + 20 s is still inside.
2162
+ const refreshed = await visit({}, { fresh, before: (r) => { backOnce(r); now += 20_000; r.tick(); backOnce(r); now += 20_000; r.tick(); } });
2163
+ assert.equal(refreshed.restored, false, 'a repeated hub-back refreshes the window');
2164
+ }
2165
+ } finally {
2166
+ Date.now = realNow;
2167
+ }
2168
+ console.log('ok: hub-back only arms: a drop inside 35 s ends the visit, one after it resumes');
2169
+ }
2170
+
2171
+ // A pending pose read holds the whole arrival group. A hub-back before
2172
+ // arrival is ignored, and a read discarded by a departure still ends its
2173
+ // wait, so the others in the group arrive.
2174
+ for (const how of ['back', 'end']) {
2175
+ const base = makePoseStorage();
2176
+ let release = null;
2177
+ const storage = { ...base, rows: base.rows, snapshot: async (a) => { if (release) {await release.promise;} return base.snapshot(a); } };
2178
+ const r = boot({ resumePose: true }, { storage });
2179
+ await flushPose(); r.tick(2000); r.tick();
2180
+ release = Promise.withResolvers();
2181
+ for (const [id, userId] of [['p3', '103'], ['p4', '104']]) {
2182
+ r.session.players.push({ playerId: id, userId, username: id, isAnonymous: false });
2183
+ r.world.players.set(id, body());
2184
+ r.say(id, { k: 'hub-hello', avatar: 1, party: 1 });
2185
+ }
2186
+ if (how === 'back') {r.say('p3', { k: 'hub-back' });} else {r.ctx().end(['p3']);}
2187
+ r.tick(2000); r.tick();
2188
+ assert.equal(r.arrivedTimes('p4'), 0, 'the group waits on the reads');
2189
+ const resolve = release.resolve; release = null; resolve();
2190
+ await flushPose(); r.tick(2000); r.tick();
2191
+ assert.equal(r.arrivedTimes('p4'), 1, `the group arrives after a ${how} during p3's read`);
2192
+ if (how === 'back') {assert.equal(r.arrivedTimes('p3'), 1, 'and the early hub-back changed nothing for p3');}
2193
+ }
2194
+ console.log('ok: hub-back before arrival is ignored, and a discarded pose read never holds the group');
2195
+
2196
+ // A game (`result`) is unchanged by it: the same bytes, and a retained
2197
+ // hello still reaches the resume hook (a departing player's would not).
2198
+ for (const keys of [result, { ...result, resume: true }]) {
2199
+ const run = (backFirst) => {
2200
+ const calls = [];
2201
+ const r = boot(keys, { resume: (c, { playerId }) => calls.push(playerId), message: (c, player, data) => heard.push(data.k) });
2202
+ if (backFirst) {backOnce(r); backOnce(r);}
2203
+ r.tick(); r.say('p2', rehello); r.tick(); r.tick();
2204
+ return { calls, sent: r.sent, arrivals: r.arrivals };
2205
+ };
2206
+ const plain = run(false);
2207
+ const backed = run(true);
2208
+ assert.deepEqual(plain.calls, ['p2'], 'the game resumes the retained hello');
2209
+ assert.deepEqual(backed.calls, plain.calls, 'hub-back in a game does not mark the player departing');
2210
+ assert.deepEqual(backed.sent, plain.sent, 'a game sends the same bytes');
2211
+ assert.deepEqual(backed.arrivals, plain.arrivals);
2212
+ }
2213
+ console.log('ok: hub-back in a place with result changes nothing');
2214
+
2215
+ // A place that retains no visit: nothing to end, and still never the hook's.
2216
+ {
2217
+ const r = boot({}, { message: (c, player, data) => heard.push(data.k) });
2218
+ r.say('p2', { k: 'hub-back' }); r.tick();
2219
+ r.drop(); r.tick(); r.back(); r.say('p2', rehello); r.tick(2000); r.tick();
2220
+ }
2221
+ assert.equal(heard.includes('hub-back'), false, 'the place message hook never hears hub-back');
2222
+ console.log('ok: hub-back is consumed by the kit, never passed to the place hook');
2223
+ }
2224
+
1988
2225
  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;