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
@@ -0,0 +1,234 @@
1
+ import assert from 'node:assert/strict';
2
+ import { register } from 'node:module';
3
+ import { storeFixture } from './writer-storage-fixture.mjs';
4
+ import { NOTICE } from '../code/server/writerLease.js';
5
+ register(`data:text/javascript,${encodeURIComponent(`
6
+ export async function resolve(specifier, context, next) {
7
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: 'data:text/javascript,export const readScene = () => globalThis.__hubTestActors;', shortCircuit: true };
8
+ if (context.parentURL?.includes('/kits/base/sdk/') && specifier.startsWith('.') && !specifier.endsWith('.js')) return next(specifier + '.js', context);
9
+ return next(specifier, context);
10
+ }
11
+ `)}`);
12
+ const { layer } = await import('../code/server/hub.js');
13
+ const fixture = storeFixture();
14
+ const flush = async () => { for (let i = 0; i < 12; i++) await Promise.resolve(); };
15
+ const deferred = () => { let resolve; const promise = new Promise(r => { resolve = r; }); return { promise, resolve }; };
16
+ const player = id => ({ playerId: id, userId: '101', username: 'Ada', isAnonymous: false });
17
+ const instances = [];
18
+ function boot(id, opted = true, userId = '101', isAnonymous = false, options = {}) {
19
+ globalThis.__hubTestActors = [{ id: 'player', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } }];
20
+ const sent = [], root = fixture.root(id);
21
+ Object.assign(root.storage, options.storage);
22
+ let ctx;
23
+ const server = layer({ ...(options.deckId ? { deckId: options.deckId } : {}), server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Test', ...(opted ? { writerLease: true } : {}), ...options.hub } },
24
+ { ready(hub) { ctx = hub; }, ...options.hooks }, {}, () => true, () => null, null, {});
25
+ const session = { sessionId: `dev-${id}`, players: [player('p1'), player('p2')].map(p => ({ ...p, userId, isAnonymous })), storage: root.storage,
26
+ send(id, msg) { sent.push([id, structuredClone(msg)]); }, broadcast() {} };
27
+ const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
28
+ const world = { timeMs: 0, scenePath: 'scenes/main.scene', objects: new Map(), bodies: new Map(), players: new Map([['p1', body()], ['p2', body()]]) };
29
+ server.sceneFor(session); server.ready(world);
30
+ const hello = (id, extra = {}) => server.message(session, { playerId: id }, { k: 'hub-hello', avatar: 0, party: 1, ...extra });
31
+ hello('p1'); hello('p2');
32
+ const tick = (ms = 50) => { world.timeMs += ms; server.place(world); server.step(world, []); };
33
+ const instance = { ...root, server, session, ctx, sent, tick, hello, world, body };
34
+ instances.push(instance);
35
+ return instance;
36
+ }
37
+
38
+ function drop(s, id) {
39
+ s.session.players = s.session.players.filter(p => p.playerId !== id);
40
+ s.world.players.delete(id);
41
+ s.server.transportLeave?.(s.session, player(id));
42
+ }
43
+
44
+ function connect(s, id, transport = true) {
45
+ s.session.players.push(player(id));
46
+ s.world.players.set(id, s.body());
47
+ if (transport) s.server.transportJoin?.(s.session, player(id));
48
+ }
49
+
50
+ async function retainedReplacement(name, hub, liveElsewhere, entryPath) {
51
+ const events = [], state = new Map(), pending = [], loads = [], leaves = [], arrivalState = [];
52
+ const a = boot(`${name}-old`, true, '101', false, { hub, hooks: {
53
+ arrive(ctx, group) {
54
+ for (const p of group) {
55
+ events.push(`arrive:${p.playerId}`);
56
+ arrivalState.push([p.playerId, state.has(p.userId)]);
57
+ pending.push(ctx.saves.deck(p.userId).get(['progress']).then(value => {
58
+ state.set(p.userId, value.progress);
59
+ loads.push([p.playerId, value.progress]);
60
+ }));
61
+ }
62
+ },
63
+ leave(ctx, id, account) {
64
+ events.push(`leave:${id}`);
65
+ leaves.push([id, ctx.saves.lost(account.userId)]);
66
+ state.delete(account.userId);
67
+ },
68
+ } });
69
+ await flush(); a.tick(2000); a.tick(300);
70
+ await Promise.all(pending);
71
+ assert.ok(state.has('101'), 'the old visits own authored state');
72
+ const b = boot(`${name}-other`);
73
+ await b.ctx.saves.deck('101').set({ progress: 42 });
74
+ await assert.rejects(a.ctx.saves.fence('101'), { code: 'CAULDRON_STORAGE_WRITER_LOST' });
75
+ drop(a, 'p1'); drop(a, 'p2'); a.tick();
76
+ assert.ok(!events.some(e => e.startsWith('leave:')), 'both dropped visits are retained');
77
+ if (!liveElsewhere) await b.server.shutdown();
78
+ events.length = 0;
79
+ const claim = a.storage.claim;
80
+ a.storage.claim = input => { events.push('claim'); return claim(input); };
81
+ a.sent.length = 0;
82
+ connect(a, 'fresh', entryPath === 'transport');
83
+ if (entryPath === 'tick') a.tick();
84
+ a.hello('fresh'); await flush(); a.tick(2000); a.tick(300);
85
+ await Promise.all(pending);
86
+ assert.deepEqual(events, ['leave:p1', 'leave:p2', 'claim', 'arrive:fresh'], `${entryPath}: cleanup and reopening precede arrival`);
87
+ assert.deepEqual(leaves, [['p1', true], ['p2', true]], 'leave hooks ran under the old lost lease');
88
+ assert.deepEqual(arrivalState.at(-1), ['fresh', false], 'leave cleared authored per-account state before arrival');
89
+ assert.deepEqual(loads.at(-1), ['fresh', 42], 'fresh arrival loads the other instance\'s saves');
90
+ assert.equal(a.calls.claim.length, 2);
91
+ assert.equal(a.ctx.saves.lost('101'), false);
92
+ await a.ctx.saves.deck('101').set({ progress: 43 });
93
+ assert.equal(fixture.rows.get('deck:progress'), 43, 'the fresh visit saves successfully');
94
+ assert.ok(!a.sent.some(([id, msg]) => id === 'fresh' && msg.k === 'hub-hud' && msg.hud?.text === NOTICE), 'fresh visit never sees the loss notice');
95
+ a.tick();
96
+ assert.equal(events.filter(e => e.startsWith('leave:')).length, 2, 'held visits were forgotten exactly once');
97
+ if (liveElsewhere) {
98
+ await assert.rejects(b.ctx.saves.fence('101'), { code: 'CAULDRON_STORAGE_WRITER_LOST' });
99
+ assert.equal(b.ctx.saves.lost('101'), true, 'newest instance owns the lease');
100
+ }
101
+ await a.server.shutdown();
102
+ }
103
+
104
+ async function replacementProgress(name, hub, entryPath) {
105
+ const reads = [], resets = [], arrivals = [], leaves = [];
106
+ const marker = deferred(), resetDone = deferred();
107
+ let fresh = false;
108
+ const a = boot(`${name}-progress`, true, '101', false, {
109
+ deckId: 'saved-test', hub,
110
+ storage: { playthrough(userId) {
111
+ reads.push(userId);
112
+ return fresh ? marker.promise : Promise.resolve({ generation: 1, resetGeneration: 1 });
113
+ } },
114
+ hooks: {
115
+ arrive(ctx, group) { for (const p of group) arrivals.push([p.playerId, ctx.progressGeneration(p.playerId)]); },
116
+ leave(ctx, id) { leaves.push(id); },
117
+ progressReset(ctx, id, generation, options) {
118
+ resets.push([id, generation, options.arrived]);
119
+ if (generation === 2) return resetDone.promise;
120
+ },
121
+ },
122
+ });
123
+ await flush(); a.tick(2000); a.tick(300);
124
+ assert.deepEqual(arrivals, [['p1', 1], ['p2', 1]], 'old visits have an applied reset generation');
125
+ assert.equal(a.ctx.progressPending(), false);
126
+ const b = boot(`${name}-progress-other`);
127
+ await b.ctx.saves.ready('101');
128
+ await assert.rejects(a.ctx.saves.fence('101'), { code: 'CAULDRON_STORAGE_WRITER_LOST' });
129
+ drop(a, 'p1'); drop(a, 'p2'); a.tick();
130
+ assert.deepEqual(leaves, [], 'old visits remain retained');
131
+ fresh = true;
132
+ const previousReads = reads.length;
133
+ connect(a, 'fresh', entryPath === 'transport');
134
+ if (entryPath === 'tick') a.tick();
135
+ a.hello('fresh');
136
+ assert.equal(reads.length, previousReads + 1, `${entryPath}: fresh hello must read the marker despite the remembered generation`);
137
+ assert.deepEqual(leaves, ['p1', 'p2']);
138
+ assert.equal(a.calls.claim.length, 2);
139
+ a.tick();
140
+ assert.equal(a.ctx.progressPending('101'), true);
141
+ assert.equal(arrivals.length, 2, 'arrival waits for the new marker');
142
+ marker.resolve({ generation: 2, resetGeneration: 2 });
143
+ await flush(); a.tick();
144
+ assert.deepEqual(resets.filter(([, generation]) => generation === 2), [['fresh', 2, false]], 'fresh visit applies the newer reset before arrival');
145
+ assert.equal(a.ctx.progressPending('101'), true);
146
+ assert.equal(arrivals.length, 2, 'arrival also waits for the reset hook to finish');
147
+ resetDone.resolve(); await flush(); a.tick();
148
+ assert.equal(a.ctx.progressPending('101'), false);
149
+ assert.deepEqual(arrivals.at(-1), ['fresh', 2]);
150
+ assert.equal(a.ctx.saves.lost('101'), false);
151
+ await a.server.shutdown();
152
+ }
153
+ const a = boot('a'), b = boot('b'), disabled = boot('off', false);
154
+ const guest = boot('guest', true, 'dev-guest-1', true), anonymous = boot('anon', true, '102', true);
155
+ try {
156
+ await Promise.all([a.ctx.saves.ready('101'), b.ctx.saves.ready('101')]);
157
+ await guest.ctx.saves.ready('dev-guest-1');
158
+ assert.equal(guest.calls.claim.length, 1, 'dev-guest subjects have save storage');
159
+ assert.equal(anonymous.calls.claim.length, 0, 'anonymous numeric identities do not claim');
160
+ assert.equal(a.calls.claim.length, 1, 'the hub claims once for two visits');
161
+ assert.equal(disabled.ctx.saves.deck('101'), disabled.storage.deck);
162
+ assert.equal(disabled.calls.claim.length, 0);
163
+ await assert.rejects(a.ctx.saves.deck('101').set({ x: 1 }), e => e.code === 'CAULDRON_STORAGE_WRITER_LOST');
164
+ a.tick();
165
+ for (const id of ['p1', 'p2']) assert.ok(a.sent.some(([to, msg]) => to === id && msg.k === 'hub-hud' && msg.hud?.text === NOTICE), `${id} sees loss`);
166
+ a.ctx.setHud({ title: 'Game', text: 'another message' }, 'p1'); a.tick();
167
+ assert.equal(a.sent.filter(([to, msg]) => to === 'p1' && msg.k === 'hub-hud').at(-1)[1].hud.text, NOTICE, 'place HUD cannot overwrite the warning');
168
+ a.sent.length = 0; a.hello('p1'); a.tick();
169
+ assert.ok(a.sent.some(([to, msg]) => to === 'p1' && msg.k === 'hub-hud' && msg.hud?.text === NOTICE), 'reconnect replays warning');
170
+ assert.equal(a.calls.claim.length, 1, 'repeated hello does not reclaim');
171
+ a.session.players = a.session.players.filter(p => p.playerId !== 'p1');
172
+ a.server.transportLeave(a.session, player('p1'));
173
+ a.session.players.push(player('p1'));
174
+ a.server.transportJoin(a.session, player('p1'));
175
+ await flush();
176
+ assert.equal(a.calls.claim.length, 1, 'a visit back beside a stale one does not reclaim');
177
+ assert.equal(a.ctx.saves.lost('101'), true);
178
+ a.session.players = [];
179
+ for (const id of ['p1', 'p2']) a.server.transportLeave(a.session, player(id));
180
+ assert.equal(a.ctx.saves.lost('101'), true, 'held until the place forgets its players');
181
+ for (const id of ['p1', 'p2']) a.world.players.delete(id);
182
+ a.tick();
183
+ a.session.players.push(player('p1'));
184
+ a.world.players.set('p1', a.body());
185
+ a.server.transportJoin(a.session, player('p1'));
186
+ a.sent.length = 0; a.hello('p1');
187
+ await flush(); await a.ctx.saves.fence('101'); a.tick();
188
+ assert.equal(a.calls.claim.length, 2);
189
+ assert.equal(a.ctx.saves.lost('101'), false);
190
+ assert.ok(!a.sent.some(([to, msg]) => to === 'p1' && msg.k === 'hub-hud' && msg.hud?.text === NOTICE), 'a fresh visit is not warned');
191
+ console.log('writer lease hub: opt-in, visits, persistent HUD, reconnect and transport rejoin passed');
192
+
193
+ for (const [mode, hub] of [['pose', { resumePose: true }], ['keep', { resume: { keep: true }, result: { score: { unit: 's', better: 'lower' } } }]]) {
194
+ for (const liveElsewhere of [false, true]) {
195
+ for (const path of ['transport', 'hello', 'tick']) {
196
+ const name = `${mode}-${liveElsewhere ? 'C' : 'D'}-${path}`;
197
+ await retainedReplacement(name, hub, liveElsewhere, path);
198
+ console.log(`writer lease hub: ${name} held visits forgotten, claim reopened, arrival reload and saves passed`);
199
+ }
200
+ }
201
+ for (const path of ['hello', 'transport', 'tick']) {
202
+ await replacementProgress(`${mode}-${path}`, hub, path);
203
+ console.log(`writer lease hub: ${mode}-${path} replacement reads and applies the newer progress reset before arrival`);
204
+ }
205
+ const s = boot(`${mode}-unchanged`, true, '101', false, { hub });
206
+ await flush(); s.tick(2000); s.tick(300);
207
+ const other = boot(`${mode}-unchanged-other`);
208
+ await other.ctx.saves.ready('101');
209
+ await assert.rejects(s.ctx.saves.fence('101'), { code: 'CAULDRON_STORAGE_WRITER_LOST' });
210
+ drop(s, 'p1'); drop(s, 'p2'); s.tick();
211
+ connect(s, 'p1'); s.hello('p1', { resume: true }); s.tick();
212
+ assert.equal(s.calls.claim.length, 1, 'same-playerId retained resume stays lost');
213
+ assert.equal(s.ctx.saves.lost('101'), true);
214
+ connect(s, 'fresh'); s.hello('fresh'); s.tick(2000);
215
+ assert.equal(s.calls.claim.length, 1, 'a fresh visit beside a connected lost visit stays lost');
216
+ assert.equal(s.ctx.saves.lost('101'), true);
217
+ assert.ok(s.sent.some(([id, msg]) => id === 'fresh' && msg.k === 'hub-hud' && msg.hud?.text === NOTICE));
218
+ await other.ctx.saves.fence('101');
219
+ console.log(`writer lease hub: ${mode} same-playerId resume and connected peer stay lost`);
220
+
221
+ const leaves = [];
222
+ const off = boot(`${mode}-disabled`, false, '101', false, { hub, hooks: { leave(ctx, id) { leaves.push(id); } } });
223
+ await flush(); off.tick(2000); off.tick(300);
224
+ drop(off, 'p1'); drop(off, 'p2'); off.tick();
225
+ connect(off, 'fresh'); off.hello('fresh'); await flush(); off.tick(2000);
226
+ assert.deepEqual(leaves, [], 'disabled leases preserve held visits on a new same-account connection');
227
+ assert.equal(off.ctx.saves.deck('101'), off.storage.deck);
228
+ assert.equal(off.calls.claim.length, 0);
229
+ assert.ok(!off.sent.some(([, msg]) => msg.k === 'hub-hud' && msg.hud?.text === NOTICE));
230
+ console.log(`writer lease hub: ${mode} disabled leases keep retention and HUD unchanged`);
231
+ }
232
+ } finally {
233
+ await Promise.all(instances.map(s => s.server.shutdown()));
234
+ }
@@ -0,0 +1,281 @@
1
+ import assert from 'node:assert/strict';
2
+ import { test } from 'node:test';
3
+ import { create, KEEP_MS, CLAIM_WAIT_MS } from '../code/server/writerLease.js';
4
+ import { storeFixture } from './writer-storage-fixture.mjs';
5
+ const lost = error => error.code === 'CAULDRON_STORAGE_WRITER_LOST';
6
+ const deferred = () => { let resolve; const promise = new Promise(r => { resolve = r; }); return { promise, resolve }; };
7
+ function setup(t) {
8
+ const fixture = storeFixture();
9
+ function instance(id) {
10
+ const root = fixture.root(id), lease = create({ storage: root.storage }, true);
11
+ t.after(() => lease.shutdown());
12
+ return { ...root, lease, api: lease.api };
13
+ }
14
+ return { ...fixture, instance };
15
+ }
16
+
17
+ test('newest session fences the old writer without touching legacy rows; loss is sticky', async t => {
18
+ const { instance, rows } = setup(t), a = instance('a'), b = instance('b');
19
+ const notices = [];
20
+ a.api.onLost(user => notices.push(user));
21
+ a.lease.join('p1', '101');
22
+ const deck = a.api.deck('101');
23
+ await deck.set({ 'band:101': 1 });
24
+ a.lease.join('p2', '101');
25
+ await a.api.ready('101');
26
+ assert.equal(a.calls.claim.length, 1, 'second visit reuses the writer');
27
+ b.lease.join('p3', '101');
28
+ await b.api.deck('101').set({ 'band:101': 2 });
29
+ await assert.rejects(deck.set({ 'band:101': 0 }), lost);
30
+ assert.equal(a.calls.set.length, 1);
31
+ assert.equal(rows.get('deck:band:101'), 2);
32
+ assert.equal(a.api.lost('101'), true);
33
+ assert.deepEqual(notices, ['101']);
34
+ const fences = a.calls.transaction.length;
35
+ await assert.rejects(a.api.fence('101'), lost);
36
+ await assert.rejects(deck.remove(['band:101']), lost);
37
+ assert.equal(a.calls.transaction.length, fences, 'lost fences make no network calls');
38
+ // While any visit of a lost account is here, nothing takes it back: those
39
+ // visits hold state from before the other instance's saves.
40
+ a.lease.join('p2', '101');
41
+ a.lease.join('new-tab', '101');
42
+ a.lease.leave('p2'); a.lease.join('p2', '101');
43
+ assert.equal(a.calls.claim.length, 1, 'a visit returning beside others cannot take back a lost account');
44
+ assert.equal(a.api.lost('101'), true);
45
+ // Once every visit has left, a visit back claims afresh at once.
46
+ for (const id of ['p1', 'p2', 'new-tab']) a.lease.leave(id);
47
+ a.lease.join('p2', '101');
48
+ await deck.set({ 'band:101': 3 });
49
+ assert.equal(a.calls.claim.length, 2);
50
+ assert.equal(a.api.lost('101'), false);
51
+ await assert.rejects(b.api.fence('101'), lost);
52
+ });
53
+
54
+ test('disabled and older hosts return raw stores by identity', async () => {
55
+ for (const [storage, opted] of [[{ deck: {} }, true], [storeFixture().root('a').storage, false]]) {
56
+ const lease = create({ storage }, opted);
57
+ assert.equal(lease.api.enabled, false);
58
+ assert.equal(lease.api.deck('101'), storage.deck);
59
+ lease.join('p1', '101');
60
+ lease.sync([['p2', '101']], ['p1'], () => assert.fail('disabled leases never forget visits'));
61
+ await lease.api.fence('101');
62
+ await lease.api.ready('101');
63
+ assert.equal(lease.api.lost('101'), false);
64
+ lease.shutdown();
65
+ }
66
+ });
67
+
68
+ test('concurrent fences share one check; transient failure is retryable by the caller', async t => {
69
+ const a = setup(t).instance('a'); a.lease.join('p1', '101'); await a.api.ready('101');
70
+ const send = a.storage.transaction, hold = deferred();
71
+ a.storage.transaction = async input => { await hold.promise; return send(input); };
72
+ const f1 = a.api.fence('101'), f2 = a.api.fence('101');
73
+ assert.equal(f1, f2);
74
+ hold.resolve(); await f1;
75
+ assert.equal(a.calls.transaction.length, 1);
76
+ assert.deepEqual(a.calls.transaction[0].changes, []);
77
+ a.storage.transaction = async () => { throw Object.assign(Error('busy'), { retryable: true }); };
78
+ await assert.rejects(a.api.fence('101'), /busy/);
79
+ assert.equal(a.api.lost('101'), false);
80
+ a.storage.transaction = send;
81
+ await a.api.fence('101');
82
+ });
83
+
84
+ test('stale access and dev writer-loss suffixes fail closed', async t => {
85
+ for (const code of ['CAULDRON_STORAGE_STALE_ACCESS', 'STALE_ACCESS', 'CAULDRON_STORAGE_STALE_RESET_GENERATION', 'WRITER_LOST']) {
86
+ const a = setup(t).instance(code); a.lease.join('p1', '101'); await a.api.ready('101');
87
+ a.storage.transaction = async () => { throw Object.assign(Error(code), { code }); };
88
+ await assert.rejects(a.api.deck('101').increment('coins'), lost);
89
+ assert.equal(a.api.lost('101'), true);
90
+ assert.equal(a.calls.increment.length, 0);
91
+ }
92
+ });
93
+
94
+ test('reads wait for claim settlement and ordinary writes stay in account order across buckets', async t => {
95
+ const a = setup(t).instance('a'), hold = deferred(), send = a.storage.claim;
96
+ a.storage.claim = async input => { await hold.promise; return send(input); };
97
+ a.lease.join('p1', '101');
98
+ const deck = a.api.deck('101');
99
+ const read = deck.get(['x']), listing = deck.list({ prefix: 'x' });
100
+ const write = deck.set({ x: 1 });
101
+ await Promise.resolve(); assert.equal(a.calls.get.length, 0); assert.equal(a.calls.set.length, 0);
102
+ hold.resolve(); await Promise.all([read, listing, write]);
103
+ const first = deferred(), set = a.storage.deck.set, order = [];
104
+ a.storage.deck.set = async input => { order.push('set'); await first.promise; return set(input); };
105
+ const w1 = deck.set({ x: 4 });
106
+ const w2 = a.api.user('101').set({ own: 5 });
107
+ const w3 = deck.increment('x', 2);
108
+ const w4 = deck.remove(['x']);
109
+ await new Promise(r => setImmediate(r));
110
+ assert.deepEqual(order, ['set']);
111
+ assert.equal(a.calls.increment.length, 0);
112
+ first.resolve(); await Promise.all([w1, w2, w3, w4]);
113
+ assert.deepEqual(await a.api.user('101').get(['own']), { own: 5 });
114
+ assert.deepEqual(await deck.get(['x']), {});
115
+ });
116
+
117
+ test('unknown claim outcome replays its operation instead of stealing ownership back', async t => {
118
+ t.mock.timers.enable({ apis: ['setTimeout'] });
119
+ const { instance } = setup(t), a = instance('a'), b = instance('b'), send = a.storage.claim, ids = [];
120
+ let attempts = 0;
121
+ a.storage.claim = async input => {
122
+ ids.push(input.operationId);
123
+ const reply = await send(input);
124
+ if (++attempts === 1) throw Object.assign(Error('lost reply'), { committed: 'unknown' });
125
+ return reply;
126
+ };
127
+ a.lease.join('p1', '101'); await new Promise(r => setImmediate(r));
128
+ b.lease.join('p2', '101'); await b.api.ready('101');
129
+ t.mock.timers.tick(250);
130
+ await assert.rejects(a.api.fence('101'), { code: 'CAULDRON_STORAGE_WRITER_LOST' });
131
+ assert.equal(ids.length, 2); assert.equal(ids[0], ids[1]);
132
+ assert.equal(a.api.lost('101'), true);
133
+ });
134
+
135
+ test('a refused claim stops saving; a missing save API saves as before; shutdown cancels retry', async t => {
136
+ t.mock.timers.enable({ apis: ['setTimeout'] });
137
+ const a = setup(t).instance('a');
138
+ a.storage.claim = async () => { throw Object.assign(Error('forbidden'), { code: 'CAULDRON_STORAGE_FORBIDDEN', retryable: false, committed: false }); };
139
+ a.lease.join('p1', '101');
140
+ await a.api.deck('101').get(['x']);
141
+ await assert.rejects(a.api.deck('101').set({ x: 1 }), lost);
142
+ assert.equal(a.api.lost('101'), true);
143
+ const old = setup(t).instance('old');
144
+ old.storage.claim = async () => { throw Object.assign(Error('old host'), { code: 'UNKNOWN_COMMAND', retryable: false, committed: false }); };
145
+ old.lease.join('p1', '101');
146
+ await old.api.deck('101').set({ x: 1 });
147
+ assert.deepEqual(await old.api.deck('101').get(['x']), { x: 1 });
148
+ assert.equal(old.api.lost('101'), false);
149
+ const b = setup(t).instance('b'); let claims = 0;
150
+ b.storage.claim = async () => { claims++; throw Error('network'); };
151
+ b.lease.join('p2', '102'); await new Promise(r => setImmediate(r));
152
+ b.lease.shutdown(); t.mock.timers.tick(10000); await b.api.ready('102');
153
+ assert.equal(claims, 1);
154
+ });
155
+
156
+ test('last departure keeps end saves for 60 seconds, then a visit claims afresh', async t => {
157
+ t.mock.timers.enable({ apis: ['setTimeout'] });
158
+ const a = setup(t).instance('a'); a.lease.join('p1', '101'); a.lease.join('p2', '101');
159
+ await a.api.ready('101');
160
+ a.lease.leave('p1'); t.mock.timers.tick(KEEP_MS + 1);
161
+ await a.api.fence('101');
162
+ a.lease.leave('p2'); t.mock.timers.tick(KEEP_MS - 1);
163
+ await a.api.deck('101').set({ ended: true });
164
+ t.mock.timers.tick(1);
165
+ await assert.rejects(a.api.fence('101'), lost);
166
+ a.lease.join('p3', '101'); await a.api.ready('101');
167
+ assert.equal(a.calls.claim.length, 2);
168
+ });
169
+
170
+ test('reads wait for the claim; a claim still failing after CLAIM_WAIT_MS stops saving', async t => {
171
+ t.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
172
+ const a = setup(t).instance('a');
173
+ let claims = 0;
174
+ a.storage.claim = async () => { claims++; throw Object.assign(Error('busy'), { code: 'CAULDRON_STORAGE_RATE_LIMITED', retryable: true, committed: false }); };
175
+ a.lease.join('p1', '101');
176
+ let read = false;
177
+ const reading = a.api.deck('101').get(['x']).then(() => { read = true; });
178
+ for (let i = 0; i < 3; i++) await new Promise(r => setImmediate(r));
179
+ assert.equal(read, false, 'a load does not run before the claim');
180
+ for (let waited = 0; waited <= 2 * CLAIM_WAIT_MS && !read; waited += 1000) {
181
+ t.mock.timers.tick(1000);
182
+ for (let i = 0; i < 3; i++) await new Promise(r => setImmediate(r));
183
+ }
184
+ await reading;
185
+ assert.ok(claims > 1);
186
+ assert.equal(a.api.lost('101'), true);
187
+ await assert.rejects(a.api.deck('101').set({ x: 1 }), lost);
188
+ assert.equal(a.calls.set.length, 0);
189
+ });
190
+
191
+ test('transactions through the view are fenced too', async t => {
192
+ const { instance } = setup(t), a = instance('a'), b = instance('b');
193
+ let sent = 0;
194
+ a.storage.deck.transaction = async () => { sent++; return { operationId: 'x', access: 'y', revisions: [] }; };
195
+ a.lease.join('p1', '101');
196
+ await a.api.deck('101').transaction({ operationId: 'op1', changes: [] });
197
+ assert.equal(sent, 1);
198
+ b.lease.join('p2', '101'); await b.api.ready('101');
199
+ await assert.rejects(a.api.deck('101').transaction({ operationId: 'op2', changes: [] }), lost);
200
+ assert.equal(sent, 1);
201
+ });
202
+
203
+ test('a visit the place still holds keeps a lost account lost across a reconnect', async t => {
204
+ const { instance } = setup(t), a = instance('a'), b = instance('b');
205
+ a.lease.sync([['p1', '101']]);
206
+ await a.api.ready('101');
207
+ b.lease.join('p9', '101'); await b.api.ready('101');
208
+ await assert.rejects(a.api.fence('101'), lost);
209
+ // The socket drops but resume retention keeps p1's authored state.
210
+ a.lease.sync([], ['p1']);
211
+ a.lease.sync([['p1', '101']], ['p1'], () => assert.fail('a same-playerId resume must retain its state'));
212
+ assert.equal(a.calls.claim.length, 1, 'a retained visit returning does not reclaim');
213
+ assert.equal(a.api.lost('101'), true);
214
+ // Only once the place forgets p1 does a visit back claim afresh.
215
+ a.lease.sync([], []);
216
+ a.lease.sync([['p1', '101']], ['p1']);
217
+ await a.api.fence('101');
218
+ assert.equal(a.calls.claim.length, 2);
219
+ assert.equal(a.api.lost('101'), false);
220
+ });
221
+
222
+ for (const liveElsewhere of [false, true]) {
223
+ test(`a fresh connection replaces all lost retained visits (${liveElsewhere ? 'C: other writer live' : 'D: other writer closed'})`, async t => {
224
+ const { instance, rows } = setup(t), a = instance('a'), b = instance('b');
225
+ a.lease.sync([['p1', '101'], ['p2', '101']]);
226
+ await a.api.deck('101').set({ progress: 1 });
227
+ b.lease.join('p9', '101');
228
+ await b.api.deck('101').set({ progress: 2 });
229
+ await assert.rejects(a.api.fence('101'), lost);
230
+ a.lease.sync([], ['p1', 'p2']);
231
+ if (!liveElsewhere) b.lease.shutdown();
232
+ const forgotten = [], notices = [];
233
+ a.api.onLost(userId => notices.push(userId));
234
+ const claim = a.storage.claim, hold = deferred();
235
+ a.storage.claim = async input => {
236
+ assert.deepEqual(forgotten, ['p1', 'p2'], 'every leave finishes before the claim');
237
+ await hold.promise;
238
+ return claim(input);
239
+ };
240
+ a.lease.sync([['fresh', '101']], ['p1', 'p2'], id => {
241
+ forgotten.push(id);
242
+ assert.equal(a.api.lost('101'), true, 'leave runs under the lost lease');
243
+ // Hub forget itself syncs: that must not prematurely join the newcomer.
244
+ a.lease.sync([['fresh', '101']], []);
245
+ assert.equal(a.calls.claim.length, 1);
246
+ });
247
+ const deck = a.api.deck('101');
248
+ const loaded = deck.get(['progress']), listing = deck.list({ prefix: 'progress' });
249
+ await flushMicrotasks();
250
+ assert.equal(a.calls.get.length, 0, 'fresh arrival reads wait for the reopened claim');
251
+ assert.equal(a.calls.list.length, 0);
252
+ hold.resolve();
253
+ assert.deepEqual(await loaded, { progress: 2 });
254
+ await listing;
255
+ await deck.set({ progress: 3 });
256
+ assert.equal(rows.get('deck:progress'), 3);
257
+ assert.equal(a.calls.claim.length, 2);
258
+ assert.equal(a.api.lost('101'), false);
259
+ assert.deepEqual(notices, []);
260
+ if (liveElsewhere) {
261
+ await assert.rejects(b.api.fence('101'), lost);
262
+ assert.equal(b.api.lost('101'), true);
263
+ }
264
+ });
265
+ }
266
+
267
+ async function flushMicrotasks() {
268
+ for (let i = 0; i < 12; i++) await Promise.resolve();
269
+ }
270
+
271
+ test('a fresh connection beside a connected lost visit preserves the stale account', async t => {
272
+ const { instance } = setup(t), a = instance('a'), b = instance('b');
273
+ a.lease.sync([['p1', '101'], ['held', '101']]);
274
+ await a.api.ready('101');
275
+ b.lease.join('p9', '101'); await b.api.ready('101');
276
+ await assert.rejects(a.api.fence('101'), lost);
277
+ a.lease.sync([['p1', '101'], ['fresh', '101']], ['p1', 'held'], () => assert.fail('a connected peer prevents cleanup'));
278
+ assert.equal(a.calls.claim.length, 1);
279
+ assert.equal(a.api.lost('101'), true);
280
+ await b.api.fence('101');
281
+ });
@@ -0,0 +1,37 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { stripTypeScriptTypes } from 'node:module';
3
+
4
+ // Exercise the real dev broker without building the CLI. Each root represents
5
+ // a distinct server session; ordinary game rows share a separate legacy bag.
6
+ const source = stripTypeScriptTypes(readFileSync(new URL('../../../cli/src/devSaveStorage.ts', import.meta.url), 'utf8'), { mode: 'transform' });
7
+ const { DevSaveStorage } = await import(`data:text/javascript,${encodeURIComponent(source)}`);
8
+ export function storeFixture() {
9
+ const saves = new DevSaveStorage();
10
+ const rows = new Map();
11
+ const roots = [];
12
+ function root(binding) {
13
+ const calls = { claim: [], transaction: [], set: [], remove: [], increment: [], get: [], list: [] };
14
+ const caller = { principal: 'server', binding, server: true, deckWritable: true, replyEnvelope: value => value, replyBytes: 1000000 };
15
+ const execute = (verb, input) => {
16
+ calls[verb].push(structuredClone(input));
17
+ const result = saves.execute(verb, input, caller);
18
+ if (!result.ok) throw Object.assign(new Error(result.error.message), result.error);
19
+ return result.value;
20
+ };
21
+ const bucket = prefix => ({
22
+ async get(keys) { calls.get.push(keys); return Object.fromEntries(keys.filter(k => rows.has(prefix + k)).map(k => [k, rows.get(prefix + k)])); },
23
+ async list(input) { calls.list.push(input); return { entries: [], cursor: null }; },
24
+ async set(values) { calls.set.push(values); for (const [k, v] of Object.entries(values)) rows.set(prefix + k, v); },
25
+ async remove(keys) { calls.remove.push(keys); for (const k of keys) rows.delete(prefix + k); },
26
+ async increment(key, amount = 1) { calls.increment.push(key); const n = (rows.get(prefix + key) ?? 0) + amount; rows.set(prefix + key, n); return n; },
27
+ });
28
+ const storage = { deck: bucket('deck:'), user: userId => bucket(`user:${userId}:`),
29
+ async claim(input) { return execute('claim', input); },
30
+ async transaction(input) { return execute('transaction', input); },
31
+ };
32
+ const result = { storage, calls };
33
+ roots.push(result);
34
+ return result;
35
+ }
36
+ return { saves, rows, root, roots };
37
+ }
@@ -47,8 +47,8 @@
47
47
  // component the soundscape names (zones, steps.paths, ambience.spots), whole, with its Transform.
48
48
  // v1.7 (format and version unchanged, as in v1.4/v1.6) always adds `avatarFits` (all styles and
49
49
  // indexes after the client's fallback; earned arrays verbatim, hat fit and top), `wearModels`
50
- // (untinted content-addressed glbs for every hat, earned and role model, square variants included)
51
- // and `wearPieces` (anchors, constant scales, replaceable main colours and fit-dependent placement
50
+ // (untinted content-addressed glbs for every hat, earned, role and v1.182 hold-show flower model,
51
+ // square variants included) and `wearPieces` (anchors, constant scales, replaceable main colours and fit-dependent placement
52
52
  // notes). Wear assets also live in `assets` so cache restaging and upload include them. Fits are
53
53
  // measured over feet; wear.js places them relative to the avatar origin. Ring scale is its
54
54
  // unchanged height scale, with horizontal stretching left to the fit; tops have no constant
@@ -284,7 +284,7 @@ if (sceneEngine.hubSpawnRing === true) {
284
284
  }
285
285
 
286
286
  const deckSounds = readDeckSounds(hubCfg);
287
- const modelFiles = ['hats', 'earned', 'role'].flatMap((dir) =>
287
+ const modelFiles = ['hats', 'earned', 'role', 'hold-show'].flatMap((dir) =>
288
288
  fs.readdirSync(path.join(KITS_DIR, 'hub-game/models', dir), { recursive: true })
289
289
  .filter((file) => file.endsWith('.pxmodel')).sort().map((file) => `models/${dir}/${file.split(path.sep).join('/')}`));
290
290
  const wear = await collectAvatarWear({ files, modelFiles, putShared });
@@ -324,7 +324,8 @@ writeManifest(manifest, sortedInputs);
324
324
  finish(manifest, { cached: false, faults: validateManifest(manifest, path.join(stageDir, hubId)) });
325
325
 
326
326
  // Every short string literal in the code files that address scene actors by id (call hide, show,
327
- // tint, move, despawn or touch) among the deck's code/ and its hub-game's (the deck's pinned copy,
327
+ // tint, move, despawn or touch, or drive, disguise or replay, whose `look` names the actor whose
328
+ // model a car, disguise or replay draws; spaces around the call allowed) among the deck's code/ and its hub-game's (the deck's pinned copy,
328
329
  // else the shipped kit's, which the kits hash covers), plus the literal first argument of every
329
330
  // actor call the publish check's actorReferences reads in any of them (a template `spawn` copies,
330
331
  // which draws the template's own node; an actor `label`, `reset` or `getActor` names), an optional
@@ -334,7 +335,7 @@ finish(manifest, { cached: false, faults: validateManifest(manifest, path.join(s
334
335
  // engine.hubKeepNodes patterns cover those (hubdata.mjs mergeStatic).
335
336
  function quotedInCode() {
336
337
  const found = new Set();
337
- const ADDRESSES = /\.(hide|show|tint|move|despawn|touch)\??\.?\(/;
338
+ const ADDRESSES = /\.\s*(hide|show|tint|move|despawn|touch|drive|disguise|replay)\s*(?:\?\.\s*)?\(/;
338
339
  const LITERAL = /(['"`])([^'"`\\\s$]{1,96})\1/g;
339
340
  const scan = (dir, keyed) => {
340
341
  // The folder itself is an input too (its listing): a code file added later re-exports.
@@ -11,6 +11,7 @@ export async function collectAvatarWear({ files, modelFiles, putShared }) {
11
11
  const Avatar = await import('../../code/client/avatar.js');
12
12
  const Earned = await import('../../code/client/earned.js');
13
13
  const Role = await import('../../code/client/role.js');
14
+ const HoldShow = await import('../../code/client/holdShow.js');
14
15
  const { buildModelNode, parseModelCached } = await import('@imports/castle.physics-3d/engine3d/pxmodel');
15
16
  const { GLTFExporter } = globalThis.__expLib;
16
17
  const avatarFits = Object.fromEntries(Avatar.STYLES.map((style) => [style,
@@ -47,6 +48,7 @@ export async function collectAvatarWear({ files, modelFiles, putShared }) {
47
48
  held: 'Hand [x, y, z] from fit; uniform scale about the model grip.',
48
49
  top: 'Fit-dependent band from waist to just below chest; one-piece bodies get a short band below chest. Width max(waist rx, sash horizontal reach), depth max(waist rz, sash rz); stretch model as roleLook; square model only when fit.square.',
49
50
  tool: 'Hand [x, y, z] from fit; uniform scale about the model grip.',
51
+ flower: 'Right hand [x, y, z] from fit, as holdShowLook; uniform scale about the model grip; use square model only when fit.square. Tinted in the player\'s hubHoldShow colour; hidden under a role tool or a grab, and hides an earned held item.',
50
52
  };
51
53
  for (const shape of Earned.EARNED_SHAPES) {
52
54
  const cls = Earned.EARNED_SHAPE_CLASS[shape];
@@ -65,6 +67,14 @@ export async function collectAvatarWear({ files, modelFiles, putShared }) {
65
67
  ...(kind === 'tool' ? { scale: look.scale[0] } : {}), tint: Role.ROLE_MAIN, placement: placement[kind] };
66
68
  }
67
69
  }
70
+ // v1.182 flowers, only when their models were built (a caller passing older model lists, such as
71
+ // castle-client's export-hub, gets the same pieces as before).
72
+ for (const shape of HoldShow.HOLD_SHOW_SHAPES) {
73
+ const id = `hold-show/${shape}`;
74
+ if (!Object.hasOwn(wearModels, id)) continue;
75
+ const look = HoldShow.holdShowLook({ shape, color: Earned.EARNED_MAIN });
76
+ wearPieces[id] = { anchor: 'hand', scale: look.scale[0], tint: Earned.EARNED_MAIN, placement: placement.flower };
77
+ }
68
78
  return { avatarFits, wearModels, wearPieces };
69
79
  }
70
80