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
@@ -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",
@@ -181,10 +186,15 @@ export async function executeCommand(ctx, command, params, capabilities, options
181
186
  try {
182
187
  const data = await dispatchCommand(ctx, command, (params ?? {}), capabilities, options);
183
188
  capabilities.hub?.assertActive?.();
184
- 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);
185
192
  return { ok: true, data };
186
193
  }
187
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" } };
188
198
  return { ok: false, error: toSerializedError(error, command) };
189
199
  }
190
200
  }
@@ -216,6 +226,7 @@ const HUB_VISIT_COMMANDS = new Set([
216
226
  "hub.friends",
217
227
  "hub.invite",
218
228
  "hub.canInvite",
229
+ "hub.inviteAvailable",
219
230
  "hub.inviteArrival",
220
231
  "hub.undoInvite",
221
232
  "hub.jump",
@@ -229,6 +240,15 @@ const HUB_VISIT_COMMANDS = new Set([
229
240
  function isHubVisitCommand(command) {
230
241
  return HUB_VISIT_COMMANDS.has(command);
231
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
+ }
232
252
  function runCommand(ctx, command, params, caps, options) {
233
253
  if (command === "multiplayer.getSession" && caps.getMultiplayerSession) {
234
254
  return caps.getMultiplayerSession(multiplayerSessionRequest(params), ctx);
@@ -246,6 +266,9 @@ function runCommand(ctx, command, params, caps, options) {
246
266
  ? caps.hubSignIn(reason, ctx, options.signal)
247
267
  : Promise.resolve({ status: "unavailable" });
248
268
  }
269
+ if (command === "hub.pushPermission" || command === "hub.pushDestination") {
270
+ return runHubPushCommand(ctx, command, params, caps, options.signal);
271
+ }
249
272
  if (isPlatformCommand(command)) {
250
273
  return runPlatformCommand(ctx, command, params, caps);
251
274
  }
@@ -279,6 +302,10 @@ function runCommand(ctx, command, params, caps, options) {
279
302
  return userGet(params, gql);
280
303
  case "experiments.get":
281
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);
282
309
  case "time.getServerTime":
283
310
  return timeGetServerTime(gql);
284
311
  case "pass.has":
@@ -422,16 +449,31 @@ async function multiplayerGetSession(ctx, params, caps) {
422
449
  const mode = request.mode === "public" && ctx.partyId && !hintedSessionId && !inviteHint
423
450
  ? "party"
424
451
  : request.mode;
425
- const data = await graphql(caps.graphqlFetch, inviteHint ? CAULDRON_INVITE_SESSION_QUERY : CAULDRON_MULTIPLAYER_SESSION_QUERY, {
426
- deckId,
427
- mode,
428
- key: request.key ?? null,
429
- sessionId: request.mode === "public" ? hintedSessionId : null,
430
- partyId: inviteHint ? null : ctx.partyId ?? null,
431
- ...(inviteHint ? { hubInviteToken: inviteHint.token, env: inviteHint.env } : {}),
432
- }, "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
+ }
433
472
  return multiplayerSessionResult(data.getCauldronMultiplayerSession);
434
473
  }
474
+ function signedOutSoloSession() {
475
+ return { status: "solo", url: null, nonce: null, sessionId: null, soloReason: "unavailable" };
476
+ }
435
477
  const MULTIPLAYER_SESSION_ID_MAX_LENGTH = 256;
436
478
  function multiplayerHintedSessionId(ctx, deckId) {
437
479
  const hint = ctx.joinHint;
@@ -1356,6 +1398,58 @@ function experimentsGet(ctx) {
1356
1398
  variants: Object.fromEntries(Object.entries(source).filter((entry) => typeof entry[1] === "string")),
1357
1399
  };
1358
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
+ }
1359
1453
  // One user's public profile, or null when there is no such user. The photo and
1360
1454
  // frame are fetched here and handed over as data: urls, since a deck's CSP
1361
1455
  // allows no image host and the host is outside it.
@@ -3427,6 +3521,30 @@ export function hubGoEnvelope(go) {
3427
3521
  },
3428
3522
  };
3429
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
+ }
3430
3548
  // Ghost's source check reads the session's heartbeat roster, which can lag an
3431
3549
  // arrival by up to 15 s: a door used in that window answers `forbidden`.
3432
3550
  const HUB_ROSTER_LAG_MS = 16_000;
@@ -3475,6 +3593,9 @@ const CAULDRON_OWNER_GO_MUTATION = CAULDRON_HUB_GO_MUTATION
3475
3593
  const CAULDRON_HUB_BACK_MUTATION = `mutation CastleHubBack($fromDeckId: ID!, $partyId: ID, $env: String) {
3476
3594
  acquireCauldronHubReturn(fromDeckId: $fromDeckId, partyId: $partyId, env: $env) { ${HUB_HANDOFF_FIELDS} }
3477
3595
  }`;
3596
+ const CAULDRON_HUB_INVITE_AVAILABLE_QUERY = `query CastleHubInviteAvailable {
3597
+ me { featureGates }
3598
+ }`;
3478
3599
  const CAULDRON_HUB_FRIENDS_QUERY = `query CastleHubFriends($deckId: ID!, $sessionId: ID, $env: String) {
3479
3600
  cauldronHubFriends(deckId: $deckId, sessionId: $sessionId, env: $env, behindDoors: true) { userId username here door home ownerUserId }
3480
3601
  }`;
@@ -3566,6 +3687,7 @@ export function createGhostHubVisit(options) {
3566
3687
  ? { status: "ok", canInvite: true, userId: String(userId) }
3567
3688
  : { status: "ok", canInvite: options.invite === true });
3568
3689
  },
3690
+ inviteAvailable: (ctx) => visit.inviteAvailable(ctx),
3569
3691
  inviteArrival: (_ctx, signal) => visit.inviteArrival(signal),
3570
3692
  undoInvite: (userId) => visit.undoInvite(userId),
3571
3693
  inviteJoinHint: (ctx) => {
@@ -3672,6 +3794,8 @@ class GhostHubVisitImpl {
3672
3794
  session = null;
3673
3795
  sessionAcquisitions = 0;
3674
3796
  acceptedSessionAcquisition = 0;
3797
+ // The last acquisition started before the player arrived where they stand.
3798
+ placeFence = 0;
3675
3799
  chatSenders = new Map();
3676
3800
  chatBlockPending = null;
3677
3801
  chatBlockNextAt = 0;
@@ -3719,14 +3843,16 @@ class GhostHubVisitImpl {
3719
3843
  // so an earlier join that answers after a later one (ghost placed it in another
3720
3844
  // shard) must not replace its session as the door source, or the player stands
3721
3845
  // in one session while every door names the other. A later join that failed
3722
- // 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.
3723
3849
  sessionAcquisitionStarted() {
3724
3850
  return ++this.sessionAcquisitions;
3725
3851
  }
3726
3852
  sessionAcquired(sessionId, acquisition) {
3727
3853
  this.assertActive();
3728
3854
  if (acquisition !== undefined) {
3729
- if (acquisition < this.acceptedSessionAcquisition)
3855
+ if (acquisition <= this.placeFence || acquisition < this.acceptedSessionAcquisition)
3730
3856
  return;
3731
3857
  this.acceptedSessionAcquisition = acquisition;
3732
3858
  }
@@ -3756,6 +3882,29 @@ class GhostHubVisitImpl {
3756
3882
  const raw = Array.isArray(data.cauldronHubFriends) ? data.cauldronHubFriends : [];
3757
3883
  return { status: "ok", friends: raw.flatMap(publicHubFriend) };
3758
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
+ }
3759
3908
  async invite(crew, signal) {
3760
3909
  this.assertActive(signal);
3761
3910
  const source = this.session;
@@ -4139,6 +4288,7 @@ class GhostHubVisitImpl {
4139
4288
  this.placeKind = trip.classic ? "classic" : "place";
4140
4289
  this.arrivalDoorId = trip.arrivalDoorId;
4141
4290
  this.chatBlockPending?.abort();
4291
+ this.placeFence = this.sessionAcquisitions;
4142
4292
  this.session = trip.sessionId ? { sessionId: trip.sessionId, at: this.now() } : null;
4143
4293
  }
4144
4294
  changed() {
@@ -4397,6 +4547,8 @@ function runHubCommand(ctx, command, params, caps, signal) {
4397
4547
  return hub?.invite ? hub.invite(params.crew === true, ctx, signal) : Promise.resolve({ status: "unavailable" });
4398
4548
  case "hub.canInvite":
4399
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" });
4400
4552
  case "hub.inviteArrival":
4401
4553
  return hub?.inviteArrival ? hub.inviteArrival(ctx, signal) : Promise.resolve({ status: "unavailable" });
4402
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
+ }
package/dist/index.js CHANGED
@@ -106,16 +106,19 @@ async function askTerminal(question) {
106
106
  terminal.close();
107
107
  }
108
108
  }
109
- // `castle-web reset-leaderboards [dir] [--deck-id ID] [--yes]`.
109
+ // `castle-web reset-leaderboards [dir] [--deck-id ID] [--yes] [--undo]`.
110
110
  async function resetLeaderboardsCommand() {
111
111
  const deckDir = path.resolve(findPositionalDir());
112
112
  await resetLeaderboards({
113
113
  deckId: getFlagValue('--deck-id') ?? readCastleJson(deckDir)?.deckId,
114
114
  yes: hasFlag('--yes'),
115
+ undo: hasFlag('--undo'),
115
116
  }, {
116
117
  signedIn: !!config.getToken(),
117
118
  deckTitle: async (deckId) => (await api.deckMeta(deckId))?.title ?? null,
118
- clearDeckLeaderboards: api.clearDeckLeaderboards,
119
+ resetDeckLeaderboards: api.resetCauldronDeckLeaderboards,
120
+ undoDeckLeaderboardsReset: api.undoCauldronDeckLeaderboardsReset,
121
+ clearClassicLeaderboards: api.clearDeckLeaderboards,
119
122
  interactive: !!process.stdin.isTTY,
120
123
  confirm: askTerminal,
121
124
  log: (line) => console.log(line),
@@ -193,7 +196,7 @@ function usage() {
193
196
  castle-web source-status <dir> [--adopt] [--notify] [--json] (whether the deck's saved copy is newer than this folder)
194
197
  castle-web list-decks [dir] [--kind mine|saved|kits] (decks this one could import; ids are what add-import takes)
195
198
  castle-web logs [dir] [--deck ID] [--room ROOM] [--rooms] [--json] [--staging] (a published deck's multiplayer room: state, end reason, exit code, out-of-memory kill and its last server log lines; no --room means the newest room; --rooms lists recent rooms; creator only)
196
- castle-web reset-leaderboards [dir] [--deck-id ID] [--yes] (clears every leaderboard on the deck, for good; creator only; --yes skips the prompt)
199
+ castle-web reset-leaderboards [dir] [--deck-id ID] [--yes] [--undo] (clears every leaderboard on the deck, saved data kept; creator only; --undo puts the scores back for a day; --yes skips the prompt)
197
200
  castle-web add-import <deckId|url|kit> [dir] [--as ALIAS] (adds another deck, or a kit this CLI ships, as a read-only dependency in imports/)
198
201
  castle-web fork-import-file <imports/...> [dir] (this deck's own version of one imported file)
199
202
  castle-web revert-import-file <imports/...> [dir]
package/dist/init.js CHANGED
@@ -64,7 +64,7 @@ const BARE_SCAFFOLDS = [
64
64
  // Registry version of castle-web-sdk to inject when scaffolding from a
65
65
  // globally-installed castle-web (not from inside the workspace). Bumped
66
66
  // alongside cli/sdk version bumps.
67
- const PUBLISHED_SDK_VERSION = '0.4.52';
67
+ const PUBLISHED_SDK_VERSION = '0.4.55';
68
68
  // Range, not a pin: `castle-web-fonts` is its own package precisely so a tenth
69
69
  // face can ship without a cli release, and a caret range means an existing
70
70
  // deck's next install picks it up. Nothing here has to move when it does.
@@ -265,6 +265,28 @@ export function getCliVersion() {
265
265
  const pkg = readJsonFile(path.join(getKitsDir(), '..', 'package.json'));
266
266
  return typeof pkg?.version === 'string' ? pkg.version : '0.0.0';
267
267
  }
268
+ // The castle-display the kit's own page declares, as a tag for the deck's page,
269
+ // or '' when it declares none. The host reads the tag from the deck's
270
+ // index.html, never the import's, so a kit that plays full-screen has to hand
271
+ // its declaration on or every deck made from it plays as a card.
272
+ function kitDisplayMeta(projectDir, alias) {
273
+ let html;
274
+ try {
275
+ html = fs.readFileSync(path.join(projectDir, IMPORTS_DIR, alias, 'index.html'), 'utf8');
276
+ }
277
+ catch {
278
+ return '';
279
+ }
280
+ for (const tag of html.match(/<meta\b[^>]*>/gi) ?? []) {
281
+ if (!/\bname\s*=\s*["']castle-display["']/i.test(tag))
282
+ continue;
283
+ const content = tag.match(/\bcontent\s*=\s*(["'])(.*?)\1/i)?.[2];
284
+ if (!content || /["<>&]/.test(content))
285
+ return '';
286
+ return `\n <meta name="castle-display" content="${content}" />`;
287
+ }
288
+ return '';
289
+ }
268
290
  // The deck's entry point is the KIT's -- the deck has no engine code of its own
269
291
  // -- so index.html points into the import. Everything the kit's main.jsx imports
270
292
  // is relative to itself, so it needs no rewriting to run from there.
@@ -272,7 +294,7 @@ function writeDeckIndexHtml(projectDir, alias, title, mainFile) {
272
294
  fs.writeFileSync(path.join(projectDir, 'index.html'), `<!doctype html>
273
295
  <html>
274
296
  <head>
275
- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
297
+ <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />${kitDisplayMeta(projectDir, alias)}
276
298
  <meta name="color-scheme" content="dark" />
277
299
  <title>${title}</title>
278
300
  <!-- Declare the dark scheme before the JS-imported CSS loads, so the frame