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
@@ -32,6 +32,8 @@ const COMMAND_NAMES = [
32
32
  "user.getCurrent",
33
33
  "user.get",
34
34
  "experiments.get",
35
+ "experiments.exposed",
36
+ "analytics.event",
35
37
  "time.getServerTime",
36
38
  "pass.has",
37
39
  "avatar.get",
@@ -57,11 +59,14 @@ const COMMAND_NAMES = [
57
59
  "hub.friends",
58
60
  "hub.invite",
59
61
  "hub.canInvite",
62
+ "hub.inviteAvailable",
60
63
  "hub.inviteArrival",
61
64
  "hub.undoInvite",
62
65
  "hub.hearts",
63
66
  "hub.setHearts",
64
67
  "hub.signIn",
68
+ "hub.pushPermission",
69
+ "hub.pushDestination",
65
70
  "hub.jump",
66
71
  "hub.report",
67
72
  "hub.chat",
@@ -99,6 +104,7 @@ const COMMAND_NAMES = [
99
104
  "cauldronStorage.boardTop",
100
105
  "cauldronStorage.boardGet",
101
106
  "cauldronStorage.usage",
107
+ "rooms.list",
102
108
  "lifecycle.restoreState",
103
109
  "localCache.get",
104
110
  "localCache.set",
@@ -180,10 +186,15 @@ export async function executeCommand(ctx, command, params, capabilities, options
180
186
  try {
181
187
  const data = await dispatchCommand(ctx, command, (params ?? {}), capabilities, options);
182
188
  capabilities.hub?.assertActive?.();
183
- noteAcquiredSession(ctx, command, data, capabilities, acquisition);
189
+ // A join the deck gave up on is not the connection it holds.
190
+ if (!options.signal?.aborted)
191
+ noteAcquiredSession(ctx, command, data, capabilities, acquisition);
184
192
  return { ok: true, data };
185
193
  }
186
194
  catch (error) {
195
+ // Availability is a read-only capability probe, including a retired visit.
196
+ if (command === "hub.inviteAvailable")
197
+ return { ok: true, data: { status: "unavailable" } };
187
198
  return { ok: false, error: toSerializedError(error, command) };
188
199
  }
189
200
  }
@@ -215,6 +226,7 @@ const HUB_VISIT_COMMANDS = new Set([
215
226
  "hub.friends",
216
227
  "hub.invite",
217
228
  "hub.canInvite",
229
+ "hub.inviteAvailable",
218
230
  "hub.inviteArrival",
219
231
  "hub.undoInvite",
220
232
  "hub.jump",
@@ -228,6 +240,15 @@ const HUB_VISIT_COMMANDS = new Set([
228
240
  function isHubVisitCommand(command) {
229
241
  return HUB_VISIT_COMMANDS.has(command);
230
242
  }
243
+ function runHubPushCommand(ctx, command, params, caps, signal) {
244
+ if (Reflect.ownKeys(params).length !== 0 ||
245
+ !ctx.deckId || !ctx.sessionId || !ctx.userId || ctx.isAnonymous) {
246
+ return Promise.resolve({ status: "unavailable" });
247
+ }
248
+ return command === "hub.pushPermission"
249
+ ? caps.hubPushPermission?.(ctx, signal) ?? Promise.resolve({ status: "unavailable" })
250
+ : caps.hubPushDestination?.(ctx, signal) ?? Promise.resolve({ status: "unavailable" });
251
+ }
231
252
  function runCommand(ctx, command, params, caps, options) {
232
253
  if (command === "multiplayer.getSession" && caps.getMultiplayerSession) {
233
254
  return caps.getMultiplayerSession(multiplayerSessionRequest(params), ctx);
@@ -245,6 +266,9 @@ function runCommand(ctx, command, params, caps, options) {
245
266
  ? caps.hubSignIn(reason, ctx, options.signal)
246
267
  : Promise.resolve({ status: "unavailable" });
247
268
  }
269
+ if (command === "hub.pushPermission" || command === "hub.pushDestination") {
270
+ return runHubPushCommand(ctx, command, params, caps, options.signal);
271
+ }
248
272
  if (isPlatformCommand(command)) {
249
273
  return runPlatformCommand(ctx, command, params, caps);
250
274
  }
@@ -278,6 +302,10 @@ function runCommand(ctx, command, params, caps, options) {
278
302
  return userGet(params, gql);
279
303
  case "experiments.get":
280
304
  return Promise.resolve(experimentsGet(ctx));
305
+ case "experiments.exposed":
306
+ return experimentsExposed(ctx, params, gql);
307
+ case "analytics.event":
308
+ return analyticsEvent(ctx, params, gql);
281
309
  case "time.getServerTime":
282
310
  return timeGetServerTime(gql);
283
311
  case "pass.has":
@@ -339,6 +367,8 @@ function runCommand(ctx, command, params, caps, options) {
339
367
  return cauldronStorageBoardGet(ctx, params, gql);
340
368
  case "cauldronStorage.usage":
341
369
  return cauldronStorageUsage(ctx, gql);
370
+ case "rooms.list":
371
+ return roomsList(ctx, gql);
342
372
  // Platform commands are handled above; listed here to keep the switch
343
373
  // exhaustive over CommandName.
344
374
  case "pass.offer":
@@ -419,16 +449,31 @@ async function multiplayerGetSession(ctx, params, caps) {
419
449
  const mode = request.mode === "public" && ctx.partyId && !hintedSessionId && !inviteHint
420
450
  ? "party"
421
451
  : request.mode;
422
- const data = await graphql(caps.graphqlFetch, inviteHint ? CAULDRON_INVITE_SESSION_QUERY : CAULDRON_MULTIPLAYER_SESSION_QUERY, {
423
- deckId,
424
- mode,
425
- key: request.key ?? null,
426
- sessionId: request.mode === "public" ? hintedSessionId : null,
427
- partyId: inviteHint ? null : ctx.partyId ?? null,
428
- ...(inviteHint ? { hubInviteToken: inviteHint.token, env: inviteHint.env } : {}),
429
- }, "multiplayer.getSession");
452
+ let data;
453
+ try {
454
+ data = await graphql(caps.graphqlFetch, inviteHint ? CAULDRON_INVITE_SESSION_QUERY : CAULDRON_MULTIPLAYER_SESSION_QUERY, {
455
+ deckId,
456
+ mode,
457
+ key: request.key ?? null,
458
+ sessionId: request.mode === "public" ? hintedSessionId : null,
459
+ partyId: inviteHint ? null : ctx.partyId ?? null,
460
+ ...(inviteHint ? { hubInviteToken: inviteHint.token, env: inviteHint.env } : {}),
461
+ }, "multiplayer.getSession");
462
+ }
463
+ catch (error) {
464
+ // Ghost refuses a signed-out player; the deck gets the documented
465
+ // single-player connection instead. ctx.userId cannot decide this: a host
466
+ // may leave it null for an anonymous account whose credentials ghost accepts.
467
+ if (error instanceof HostCommandError && error.code === "LOGIN_REQUIRED") {
468
+ return signedOutSoloSession();
469
+ }
470
+ throw error;
471
+ }
430
472
  return multiplayerSessionResult(data.getCauldronMultiplayerSession);
431
473
  }
474
+ function signedOutSoloSession() {
475
+ return { status: "solo", url: null, nonce: null, sessionId: null, soloReason: "unavailable" };
476
+ }
432
477
  const MULTIPLAYER_SESSION_ID_MAX_LENGTH = 256;
433
478
  function multiplayerHintedSessionId(ctx, deckId) {
434
479
  const hint = ctx.joinHint;
@@ -1353,6 +1398,58 @@ function experimentsGet(ctx) {
1353
1398
  variants: Object.fromEntries(Object.entries(source).filter((entry) => typeof entry[1] === "string")),
1354
1399
  };
1355
1400
  }
1401
+ const EXPERIMENT_EXPOSURE_MUTATION = `mutation LogDeckExperimentExposure($deckId: ID!, $experiment: String!, $variant: String!) {
1402
+ logDeckExperimentExposure(deckId: $deckId, experiment: $experiment, variant: $variant)
1403
+ }`;
1404
+ // The deck read a variant for the first time. Only an arm this host handed the
1405
+ // deck (experimentVariants, the same context experiments.get answers from) is
1406
+ // reported, so a deck cannot claim another; Castle's server checks it again.
1407
+ async function experimentsExposed(ctx, params, gql) {
1408
+ const name = asString(params.name, "name", "experiments.exposed");
1409
+ const variant = asString(params.variant, "variant", "experiments.exposed");
1410
+ const handed = experimentsGet(ctx).variants;
1411
+ if (!ctx.deckId || !Object.hasOwn(handed, name) || handed[name] !== variant) {
1412
+ return { recorded: false };
1413
+ }
1414
+ const data = await graphql(gql, EXPERIMENT_EXPOSURE_MUTATION, { deckId: ctx.deckId, experiment: name, variant }, "experiments.exposed");
1415
+ return { recorded: data?.logDeckExperimentExposure === true };
1416
+ }
1417
+ const ANALYTICS_EVENT_MUTATION = `mutation LogDeckAnalyticsEvent($deckId: ID!, $name: String!, $properties: Json) {
1418
+ logDeckAnalyticsEvent(deckId: $deckId, name: $name, properties: $properties)
1419
+ }`;
1420
+ // The deck's own rule for a name or a property key (sdk/src/analytics.ts holds
1421
+ // the same one; Castle's server checks it a third time).
1422
+ const ANALYTICS_TOKEN = /^[A-Za-z0-9][A-Za-z0-9 _.:/-]*$/;
1423
+ // A deck's named event, for its creator analytics. The deck is never trusted
1424
+ // with its own id: the event goes to this host's deck, and only when there is
1425
+ // one. Castle's server decides whether the name is registered and drops it if
1426
+ // not, so `recorded` can be false for a well-formed event.
1427
+ async function analyticsEvent(ctx, params, gql) {
1428
+ const name = asString(params.name, "name", "analytics.event").trim();
1429
+ if (name.length > 64 || !ANALYTICS_TOKEN.test(name)) {
1430
+ throw new HostCommandError("INVALID_ARGUMENT", "analytics.event name is not a valid event name.", "analytics.event");
1431
+ }
1432
+ const raw = params.properties ?? {};
1433
+ const proto = typeof raw === "object" && raw !== null ? Object.getPrototypeOf(raw) : undefined;
1434
+ if (proto !== Object.prototype && proto !== null) {
1435
+ throw new HostCommandError("INVALID_ARGUMENT", "analytics.event properties must be a plain object.", "analytics.event");
1436
+ }
1437
+ const properties = {};
1438
+ for (const [key, value] of Object.entries(raw)) {
1439
+ const ok = key.length <= 32 && ANALYTICS_TOKEN.test(key) && typeof value === "number" && Number.isFinite(value);
1440
+ if (!ok) {
1441
+ throw new HostCommandError("INVALID_ARGUMENT", `analytics.event property ${JSON.stringify(key)} is not valid.`, "analytics.event");
1442
+ }
1443
+ properties[key] = value;
1444
+ }
1445
+ if (Object.keys(properties).length > 5) {
1446
+ throw new HostCommandError("INVALID_ARGUMENT", "analytics.event takes at most five properties.", "analytics.event");
1447
+ }
1448
+ if (!ctx.deckId)
1449
+ return { recorded: false };
1450
+ const data = await graphql(gql, ANALYTICS_EVENT_MUTATION, { deckId: ctx.deckId, name, properties }, "analytics.event");
1451
+ return { recorded: data?.logDeckAnalyticsEvent === true };
1452
+ }
1356
1453
  // One user's public profile, or null when there is no such user. The photo and
1357
1454
  // frame are fetched here and handed over as data: urls, since a deck's CSP
1358
1455
  // allows no image host and the host is outside it.
@@ -2396,6 +2493,45 @@ async function cauldronStorageUsage(ctx, gql) {
2396
2493
  const data = await graphql(gql, CAULDRON_STORAGE_USAGE_QUERY, { deckId }, "cauldronStorage.usage");
2397
2494
  return { usage: data.cauldronStorageUsage };
2398
2495
  }
2496
+ async function roomsList(ctx, gql) {
2497
+ const deckId = requireDeckId(ctx, "rooms.list");
2498
+ const data = await graphql(gql, ROOMS_LIST_QUERY, { deckId }, "rooms.list");
2499
+ // Ghost answers null to anyone but the deck's owner, a Castle admin or a
2500
+ // member of the presence gate, and for a deck the player cannot see.
2501
+ const presence = data.cauldronDeckPresence;
2502
+ if (typeof presence !== "object" || presence === null)
2503
+ return null;
2504
+ const record = presence;
2505
+ const rooms = Array.isArray(record.routes) ? record.routes.flatMap(publicRoomSummary) : [];
2506
+ const total = record.total;
2507
+ return {
2508
+ total: isCount(total) ? total : rooms.reduce((sum, room) => sum + room.players, 0),
2509
+ rooms,
2510
+ };
2511
+ }
2512
+ function publicRoomSummary(raw) {
2513
+ if (typeof raw !== "object" || raw === null)
2514
+ return [];
2515
+ const record = raw;
2516
+ const sessionId = asOptionalString(record.sessionId);
2517
+ const { players, maxPlayers } = record;
2518
+ if (!sessionId || !isCount(players) || !isCount(maxPlayers))
2519
+ return [];
2520
+ const routeId = asOptionalString(record.routeId);
2521
+ const slot = asOptionalString(record.slot);
2522
+ return [
2523
+ {
2524
+ sessionId,
2525
+ ...(routeId ? { routeId } : {}),
2526
+ ...(slot ? { slot } : {}),
2527
+ players,
2528
+ maxPlayers,
2529
+ },
2530
+ ];
2531
+ }
2532
+ function isCount(value) {
2533
+ return Number.isSafeInteger(value) && value >= 0;
2534
+ }
2399
2535
  const CHARACTER_OPERATION_FIELDS = `
2400
2536
  operationId
2401
2537
  characterId
@@ -2997,11 +3133,24 @@ const CAULDRON_STORAGE_BOARD_TOP_QUERY = `
2997
3133
  }
2998
3134
  }
2999
3135
  `;
3136
+ const ROOMS_LIST_QUERY = `
3137
+ query CastleRoomsList($deckId: ID!) {
3138
+ cauldronDeckPresence(deckId: $deckId) {
3139
+ total
3140
+ routes { sessionId routeId slot players maxPlayers }
3141
+ }
3142
+ }
3143
+ `;
3000
3144
  const CAULDRON_STORAGE_USAGE_QUERY = `
3001
3145
  query CastleCauldronStorageUsage($deckId: ID!) {
3002
3146
  cauldronStorageUsage(deckId: $deckId) {
3003
3147
  player { keyCount keyLimit byteCount byteLimit }
3004
3148
  shared { keyCount keyLimit byteCount byteLimit }
3149
+ rate {
3150
+ callerClass
3151
+ caller { opsUsed opsLimit bytesUsed bytesLimit }
3152
+ deck { opsUsed opsLimit bytesUsed bytesLimit }
3153
+ }
3005
3154
  }
3006
3155
  }
3007
3156
  `;
@@ -3372,6 +3521,30 @@ export function hubGoEnvelope(go) {
3372
3521
  },
3373
3522
  };
3374
3523
  }
3524
+ // The deck's word that a Go this host sent (hubGoEnvelope) ended without the
3525
+ // player going through the door (SDK `Hub.goFailed`, one-way, the WebView's
3526
+ // message channel): `why` is "refused" (Hub.go gave no handoff), "content"
3527
+ // (the destination's content would not load) or "join" (the join was never
3528
+ // committed). A host that acquired the door from its own session may acquire
3529
+ // it again there and post a fresh Go. Null for any other message.
3530
+ export function hubGoFailedFrom(message) {
3531
+ if (typeof message !== "object" || message === null)
3532
+ return null;
3533
+ const record = message;
3534
+ if (record.castleSdk !== 1)
3535
+ return null;
3536
+ const event = record.hub;
3537
+ if (typeof event !== "object" || event === null || event.type !== "goFailed")
3538
+ return null;
3539
+ const { doorId, owner, why } = event;
3540
+ if (typeof doorId !== "string" || doorId.length === 0 || doorId.length > 128)
3541
+ return null;
3542
+ if (owner !== undefined && (typeof owner !== "string" || !/^[1-9]\d{0,9}$/.test(owner)))
3543
+ return null;
3544
+ if (why !== "refused" && why !== "content" && why !== "join")
3545
+ return null;
3546
+ return { doorId, owner: owner ?? null, why };
3547
+ }
3375
3548
  // Ghost's source check reads the session's heartbeat roster, which can lag an
3376
3549
  // arrival by up to 15 s: a door used in that window answers `forbidden`.
3377
3550
  const HUB_ROSTER_LAG_MS = 16_000;
@@ -3420,6 +3593,9 @@ const CAULDRON_OWNER_GO_MUTATION = CAULDRON_HUB_GO_MUTATION
3420
3593
  const CAULDRON_HUB_BACK_MUTATION = `mutation CastleHubBack($fromDeckId: ID!, $partyId: ID, $env: String) {
3421
3594
  acquireCauldronHubReturn(fromDeckId: $fromDeckId, partyId: $partyId, env: $env) { ${HUB_HANDOFF_FIELDS} }
3422
3595
  }`;
3596
+ const CAULDRON_HUB_INVITE_AVAILABLE_QUERY = `query CastleHubInviteAvailable {
3597
+ me { featureGates }
3598
+ }`;
3423
3599
  const CAULDRON_HUB_FRIENDS_QUERY = `query CastleHubFriends($deckId: ID!, $sessionId: ID, $env: String) {
3424
3600
  cauldronHubFriends(deckId: $deckId, sessionId: $sessionId, env: $env, behindDoors: true) { userId username here door home ownerUserId }
3425
3601
  }`;
@@ -3511,6 +3687,7 @@ export function createGhostHubVisit(options) {
3511
3687
  ? { status: "ok", canInvite: true, userId: String(userId) }
3512
3688
  : { status: "ok", canInvite: options.invite === true });
3513
3689
  },
3690
+ inviteAvailable: (ctx) => visit.inviteAvailable(ctx),
3514
3691
  inviteArrival: (_ctx, signal) => visit.inviteArrival(signal),
3515
3692
  undoInvite: (userId) => visit.undoInvite(userId),
3516
3693
  inviteJoinHint: (ctx) => {
@@ -3617,6 +3794,8 @@ class GhostHubVisitImpl {
3617
3794
  session = null;
3618
3795
  sessionAcquisitions = 0;
3619
3796
  acceptedSessionAcquisition = 0;
3797
+ // The last acquisition started before the player arrived where they stand.
3798
+ placeFence = 0;
3620
3799
  chatSenders = new Map();
3621
3800
  chatBlockPending = null;
3622
3801
  chatBlockNextAt = 0;
@@ -3664,14 +3843,16 @@ class GhostHubVisitImpl {
3664
3843
  // so an earlier join that answers after a later one (ghost placed it in another
3665
3844
  // shard) must not replace its session as the door source, or the player stands
3666
3845
  // in one session while every door names the other. A later join that failed
3667
- // replaces nothing: the deck keeps its earlier connection then.
3846
+ // replaces nothing: the deck keeps its earlier connection then. A join
3847
+ // started before the last arrival belongs to a place the player left, even
3848
+ // when they have come back to it: the arrival named the session.
3668
3849
  sessionAcquisitionStarted() {
3669
3850
  return ++this.sessionAcquisitions;
3670
3851
  }
3671
3852
  sessionAcquired(sessionId, acquisition) {
3672
3853
  this.assertActive();
3673
3854
  if (acquisition !== undefined) {
3674
- if (acquisition < this.acceptedSessionAcquisition)
3855
+ if (acquisition <= this.placeFence || acquisition < this.acceptedSessionAcquisition)
3675
3856
  return;
3676
3857
  this.acceptedSessionAcquisition = acquisition;
3677
3858
  }
@@ -3701,6 +3882,29 @@ class GhostHubVisitImpl {
3701
3882
  const raw = Array.isArray(data.cauldronHubFriends) ? data.cauldronHubFriends : [];
3702
3883
  return { status: "ok", friends: raw.flatMap(publicHubFriend) };
3703
3884
  }
3885
+ async inviteAvailable(ctx) {
3886
+ try {
3887
+ this.assertActive();
3888
+ const userId = ctx.userId;
3889
+ const authenticated = () => ctx.userId === userId && !!userId && ctx.isAnonymous !== true &&
3890
+ !ctx.username?.toLowerCase().startsWith("anonymous-user-");
3891
+ if (!authenticated() || this.options.invite !== true)
3892
+ return { status: "unavailable" };
3893
+ const source = this.session, contextSession = ctx.sessionId;
3894
+ const data = await graphql(this.gql, CAULDRON_HUB_INVITE_AVAILABLE_QUERY, {}, "hub.inviteAvailable");
3895
+ this.assertActive();
3896
+ if (this.session !== source || ctx.sessionId !== contextSession || !authenticated())
3897
+ return { status: "unavailable" };
3898
+ const gates = data.me?.featureGates;
3899
+ if (!gates || typeof gates !== "object" || Array.isArray(gates))
3900
+ return { status: "unavailable" };
3901
+ const available = gates.cauldron_hub_invites;
3902
+ return typeof available === "boolean" ? { status: "ok", available: available === true } : { status: "unavailable" };
3903
+ }
3904
+ catch {
3905
+ return { status: "unavailable" };
3906
+ }
3907
+ }
3704
3908
  async invite(crew, signal) {
3705
3909
  this.assertActive(signal);
3706
3910
  const source = this.session;
@@ -4084,6 +4288,7 @@ class GhostHubVisitImpl {
4084
4288
  this.placeKind = trip.classic ? "classic" : "place";
4085
4289
  this.arrivalDoorId = trip.arrivalDoorId;
4086
4290
  this.chatBlockPending?.abort();
4291
+ this.placeFence = this.sessionAcquisitions;
4087
4292
  this.session = trip.sessionId ? { sessionId: trip.sessionId, at: this.now() } : null;
4088
4293
  }
4089
4294
  changed() {
@@ -4342,6 +4547,8 @@ function runHubCommand(ctx, command, params, caps, signal) {
4342
4547
  return hub?.invite ? hub.invite(params.crew === true, ctx, signal) : Promise.resolve({ status: "unavailable" });
4343
4548
  case "hub.canInvite":
4344
4549
  return hub?.canInvite ? hub.canInvite(ctx) : Promise.resolve({ status: "unavailable", canInvite: false });
4550
+ case "hub.inviteAvailable":
4551
+ return hub?.inviteAvailable ? hub.inviteAvailable(ctx) : Promise.resolve({ status: "unavailable" });
4345
4552
  case "hub.inviteArrival":
4346
4553
  return hub?.inviteArrival ? hub.inviteArrival(ctx, signal) : Promise.resolve({ status: "unavailable" });
4347
4554
  case "hub.undoInvite":
@@ -59,7 +59,17 @@ export interface ExperimentConfig {
59
59
  variants: string[];
60
60
  weights?: number[];
61
61
  winner?: string;
62
+ audience?: ExperimentAudience;
62
63
  }
64
+ export interface ExperimentAudience {
65
+ countries?: string[];
66
+ platforms?: ('web' | 'ios' | 'android')[];
67
+ players?: 'new' | 'returning';
68
+ }
69
+ export declare const EXPERIMENT_AUDIENCE_PLATFORMS: string[];
70
+ export declare const EXPERIMENT_AUDIENCE_PLAYERS: string[];
71
+ export declare const EXPERIMENT_AUDIENCE_COUNTRY: RegExp;
72
+ export declare const EXPERIMENT_AUDIENCE_COUNTRIES_CAP = 300;
63
73
  export declare const EXPERIMENTS_CAP = 8;
64
74
  export declare const EXPERIMENT_VARIANTS_MIN = 2;
65
75
  export declare const EXPERIMENT_VARIANTS_CAP = 8;
@@ -47,6 +47,11 @@ export function resolveBundleChunks(castleJson, flag = false) {
47
47
  }
48
48
  return flag || block?.chunks === 'classic';
49
49
  }
50
+ export const EXPERIMENT_AUDIENCE_PLATFORMS = ['web', 'ios', 'android'];
51
+ export const EXPERIMENT_AUDIENCE_PLAYERS = ['new', 'returning'];
52
+ export const EXPERIMENT_AUDIENCE_COUNTRY = /^[A-Z]{2}$/;
53
+ // Matches ghost-server's limit.
54
+ export const EXPERIMENT_AUDIENCE_COUNTRIES_CAP = 300;
50
55
  export const EXPERIMENTS_CAP = 8;
51
56
  export const EXPERIMENT_VARIANTS_MIN = 2;
52
57
  export const EXPERIMENT_VARIANTS_CAP = 8;
@@ -86,9 +91,9 @@ export function validateExperiments(value) {
86
91
  function validateExperiment(name, value) {
87
92
  if (!isPlainObject(value))
88
93
  throw invalidExperiment(name, 'must be an object');
89
- const unknown = Object.keys(value).find((key) => key !== 'variants' && key !== 'weights' && key !== 'winner');
94
+ const unknown = Object.keys(value).find((key) => key !== 'variants' && key !== 'weights' && key !== 'winner' && key !== 'audience');
90
95
  if (unknown !== undefined) {
91
- throw invalidExperiment(name, `has an unknown key "${unknown}" (use variants, weights, winner)`);
96
+ throw invalidExperiment(name, `has an unknown key "${unknown}" (use variants, weights, winner, audience)`);
92
97
  }
93
98
  const variants = value.variants;
94
99
  if (!Array.isArray(variants) ||
@@ -119,12 +124,51 @@ function validateExperiment(name, value) {
119
124
  if (value.winner !== undefined && (winner === undefined || !variants.includes(winner))) {
120
125
  throw invalidExperiment(name, `winner ${JSON.stringify(value.winner)} must be one of its variants`);
121
126
  }
127
+ const audience = validateAudience(name, value.audience);
122
128
  return {
123
129
  variants: [...variants],
124
130
  ...(weights === undefined ? {} : { weights: [...weights] }),
125
131
  ...(winner === undefined ? {} : { winner }),
132
+ ...(audience === undefined ? {} : { audience }),
126
133
  };
127
134
  }
135
+ // The same rules ghost-server applies (src/utils/deckExperimentAudience.ts).
136
+ function validateAudience(name, value) {
137
+ if (value === undefined || value === null)
138
+ return undefined;
139
+ if (!isPlainObject(value))
140
+ throw invalidExperiment(name, 'audience must be an object');
141
+ const unknown = Object.keys(value).find((key) => key !== 'countries' && key !== 'platforms' && key !== 'players');
142
+ if (unknown !== undefined) {
143
+ throw invalidExperiment(name, `audience has an unknown key "${unknown}" (use countries, platforms, players)`);
144
+ }
145
+ const audience = {};
146
+ const { countries, platforms, players } = value;
147
+ if (countries !== undefined && countries !== null) {
148
+ if (!Array.isArray(countries) ||
149
+ countries.length === 0 ||
150
+ countries.length > EXPERIMENT_AUDIENCE_COUNTRIES_CAP ||
151
+ !countries.every((c) => typeof c === 'string' && EXPERIMENT_AUDIENCE_COUNTRY.test(c))) {
152
+ throw invalidExperiment(name, 'audience.countries must be a list of two-letter country codes in capitals, like ["US", "CA"]');
153
+ }
154
+ audience.countries = [...countries];
155
+ }
156
+ if (platforms !== undefined && platforms !== null) {
157
+ if (!Array.isArray(platforms) ||
158
+ platforms.length === 0 ||
159
+ !platforms.every((p) => EXPERIMENT_AUDIENCE_PLATFORMS.includes(p))) {
160
+ throw invalidExperiment(name, `audience.platforms must be a list of ${EXPERIMENT_AUDIENCE_PLATFORMS.join(', ')}`);
161
+ }
162
+ audience.platforms = [...platforms];
163
+ }
164
+ if (players !== undefined && players !== null) {
165
+ if (typeof players !== 'string' || !EXPERIMENT_AUDIENCE_PLAYERS.includes(players)) {
166
+ throw invalidExperiment(name, `audience.players must be one of ${EXPERIMENT_AUDIENCE_PLAYERS.join(', ')}`);
167
+ }
168
+ audience.players = players;
169
+ }
170
+ return Object.keys(audience).length > 0 ? audience : undefined;
171
+ }
128
172
  function invalidExperiment(name, message) {
129
173
  return new Error(`experiments.${name} ${message}.`);
130
174
  }
package/dist/check.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
- import { bundleProject, bundleProjectChunked } from './bundle.js';
3
+ import { bundleProject, bundleProjectChunked, ExternalMedia } from './bundle.js';
4
4
  import { isSandboxEnv } from './cloudGit.js';
5
5
  import { readCastleJson, resolveBundleChunks, resolveServerConfig, validateExperiments } from './castleJson.js';
6
6
  import { importChecksFailedMessage, runImportChecks } from './importCheckHook.js';
@@ -34,7 +34,10 @@ export async function check(dir, opts = {}) {
34
34
  console.error('Checking anyway (cloud sandbox).');
35
35
  }
36
36
  try {
37
- await bundleProject(deckDir);
37
+ // Media is named by its CDN URL, as save-deck names it: the bundle is
38
+ // thrown away here, and inlining a 30 MB WAV as base64 just to discard it
39
+ // costs a sandbox over a gigabyte. Nothing is uploaded.
40
+ await bundleProject(deckDir, { externalMedia: new ExternalMedia() });
38
41
  console.log('Bundle OK.');
39
42
  // A deck that publishes chunks (castle.json `bundle.chunks`) is checked the way it saves.
40
43
  if (resolveBundleChunks(readCastleJson(deckDir))) {
@@ -9,7 +9,7 @@ import { WebSocketServer, WebSocket } from 'ws';
9
9
  import { readCastleJson, resolveServerConfig } from './castleJson.js';
10
10
  import { OutboundFrameMeter } from './devSessionFrameBudget.js';
11
11
  import { SAVE_VERBS } from './devSaveStorage.js';
12
- import { runDevSave, runDevStorageOperation } from './devSessionStorage.js';
12
+ import { REFUSAL_HOLD_MS, runDevSave, runDevStorageOperation } from './devSessionStorage.js';
13
13
  import { rawDataToString } from './rawData.js';
14
14
  import { bundleServerModule } from './serverBundle.js';
15
15
  import { devDeckCastleJsons, devDeckSessionKey } from './contentPack.js';
@@ -607,6 +607,9 @@ class DevSessionImpl {
607
607
  const result = SAVE_VERBS.has(op)
608
608
  ? runDevSave(this.projectDir, this.sessionId, op, args)
609
609
  : await runDevStorageOperation(deckId, op, args, this.connectedPlayers().map((player) => player.userId));
610
+ if (!result.ok && typeof result.error?.heldUntil === 'number') {
611
+ this.log('error', `storage refused: ${result.error.message} (${result.error.code}). Serve answers this deck's storage calls with that refusal for the next ${REFUSAL_HOLD_MS / 60_000} minutes instead of asking the API again.`);
612
+ }
610
613
  // The child may have restarted while this was out; its replacement never asked, so
611
614
  // there is nobody to tell.
612
615
  if (this.platformSocket !== socket)
@@ -8,6 +8,7 @@ export interface DevStorageResult {
8
8
  [detail: string]: unknown;
9
9
  };
10
10
  }
11
+ export declare const REFUSAL_HOLD_MS: number;
11
12
  /** A session server's save. Its args are what the platform's storage route takes. */
12
13
  export declare function runDevSave(projectDir: string, sessionId: string, op: string, args: Record<string, unknown>): DevStorageResult;
13
14
  /**
@@ -4,6 +4,18 @@ import { DevSaveStorage } from './devSaveStorage.js';
4
4
  // The platform's reply allowance for one storage call: its byte-rate window.
5
5
  const SERVER_REPLY_BYTES = 2 * 1024 * 1024;
6
6
  const CLIENT_REPLY_BYTES = 512 * 1024;
7
+ // A refusal that won't change while serve runs: the author is not the deck's creator,
8
+ // the deck is gone, its storage is off, or the CLI is signed out. A session server that
9
+ // retries its saves would otherwise ask again forever (one did, against a published
10
+ // deck, at ~40 calls a minute for over a week), so serve answers that deck's later calls
11
+ // itself and asks the API again only once the hold has run out.
12
+ export const REFUSAL_HOLD_MS = 5 * 60 * 1000;
13
+ const NOT_CREATOR = 'only the deck creator can act as its session server';
14
+ // The deck's kill switch. The playthrough rollout gate shares its code but not the
15
+ // deck's other storage, so it is not held.
16
+ const DECK_DISABLED = 'storage is disabled for this deck';
17
+ const DECK_REFUSALS = new Set(['DECK_NOT_FOUND', 'LOGIN_REQUIRED']);
18
+ const refusals = new Map();
7
19
  const saveStores = new Map();
8
20
  function saveStoreFor(projectDir) {
9
21
  let store = saveStores.get(projectDir);
@@ -460,6 +472,11 @@ export async function runDevStorageOperation(deckId, op, args, connectedUserIds
460
472
  (typeof args.subject !== 'string' || !connectedUserIds.includes(args.subject))) {
461
473
  return failure('CAULDRON_CHARACTER_UNAVAILABLE', 'the target player is not connected to this session');
462
474
  }
475
+ const asServer = operation.query.includes('asServer: true');
476
+ const held = refusals.get(deckId);
477
+ if (held && Date.now() < held.until && (asServer || !held.serverOnly)) {
478
+ return { ok: false, error: { ...held.error, held: true } };
479
+ }
463
480
  try {
464
481
  const variables = op === 'characterEvaluateInformation'
465
482
  ? {
@@ -502,15 +519,23 @@ export async function runDevStorageOperation(deckId, op, args, connectedUserIds
502
519
  const error = response.errors?.[0];
503
520
  if (error) {
504
521
  const code = error.extensions?.code;
505
- return {
506
- ok: false,
507
- error: {
508
- ...error.extensions,
509
- code: typeof code === 'string' ? code : 'CAULDRON_STORAGE_UNAVAILABLE',
510
- message: error.message ?? 'storage request failed',
511
- },
522
+ const refused = {
523
+ ...error.extensions,
524
+ code: typeof code === 'string' ? code : 'CAULDRON_STORAGE_UNAVAILABLE',
525
+ message: error.message ?? 'storage request failed',
512
526
  };
527
+ const notCreator = refused.code === 'CAULDRON_STORAGE_FORBIDDEN' && refused.message === NOT_CREATOR;
528
+ const deckDisabled = refused.code === 'CAULDRON_STORAGE_DISABLED' && refused.message === DECK_DISABLED;
529
+ if (notCreator || deckDisabled || DECK_REFUSALS.has(refused.code)) {
530
+ const until = Date.now() + REFUSAL_HOLD_MS;
531
+ refusals.set(deckId, { until, serverOnly: notCreator, error: refused });
532
+ return { ok: false, error: { ...refused, heldUntil: until } };
533
+ }
534
+ return { ok: false, error: refused };
513
535
  }
536
+ // A call the hold covered got through, so whatever was refusing it has changed.
537
+ if (held && (asServer || !held.serverOnly))
538
+ refusals.delete(deckId);
514
539
  const value = response.data?.[operation.field] ?? null;
515
540
  return {
516
541
  ok: true,
@@ -0,0 +1,2 @@
1
+ export declare function mostSpecificFirst(preferred: string[], importsOf: (alias: string) => string[]): string[];
2
+ export declare function declaredImports(importDir: string): string[];
@@ -0,0 +1,29 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ // The imports a deck holds, in the order a kit's say should be heard: a kit
4
+ // before every kit it imports. A 3D deck imports castle.physics-2d alongside
5
+ // castle.physics-3d, and physics-3d is built on it, so walking the folder
6
+ // alphabetically let the 2D kit greet a 3D deck with "real 2D physics" and a
7
+ // file it does not have. `preferred` (the entry kit first) breaks ties.
8
+ export function mostSpecificFirst(preferred, importsOf) {
9
+ const remaining = [...preferred];
10
+ const ordered = [];
11
+ while (remaining.length > 0) {
12
+ const next = remaining.find((alias) => !remaining.some((other) => other !== alias && importsOf(other).includes(alias))) ?? remaining[0];
13
+ ordered.push(next);
14
+ remaining.splice(remaining.indexOf(next), 1);
15
+ }
16
+ return ordered;
17
+ }
18
+ // The aliases an imported kit itself declares, read off its castle.json in the
19
+ // deck's imports folder. Unreadable means none.
20
+ export function declaredImports(importDir) {
21
+ try {
22
+ const config = JSON.parse(fs.readFileSync(path.join(importDir, 'castle.json'), 'utf8'));
23
+ const imports = config?.imports;
24
+ return imports && typeof imports === 'object' && !Array.isArray(imports) ? Object.keys(imports) : [];
25
+ }
26
+ catch {
27
+ return [];
28
+ }
29
+ }