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
@@ -31,6 +31,9 @@ export function arrive(h, group) {
31
31
  const back = !p.from && key && a.departed.has(key);
32
32
  if (key) {a.departed.delete(key);}
33
33
  a.visits.set(p.playerId, { at: now, userId: key });
34
+ // A resume that arrives still ended by its door (v1.169) was reported at
35
+ // that end: nothing counts until a stay continues it.
36
+ if (h.players.get(p.playerId)?.ended && !h.place.result) {a.visits.get(p.playerId).ended = true;}
34
37
  if (back) {track(h, p.playerId, 'reconnect', { subject: h.manifest.house ? SUBJECTS.house : SUBJECTS.town });}
35
38
  else if (h.firstVisit && !h.manifest.house) {a.visits.get(p.playerId).arrival = { subject: SUBJECTS.town, value: p.device ?? 0, result: p.from ? 2 : 1 };}
36
39
  else {track(h, p.playerId, h.manifest.house ? 'house_visit' : 'arrive', { subject: h.manifest.house ? SUBJECTS.house : SUBJECTS.town, value: p.device ?? 0, result: p.from ? 2 : 1 });}
@@ -67,6 +70,7 @@ function end(h, playerId, visit, value, result) {
67
70
  export function observe(h) {
68
71
  const now = h.sim.timeMs;
69
72
  for (const [playerId, visit] of h.analytics.visits) {
73
+ if (visit.ended) {continue;}
70
74
  const body = h.sim.players.get(playerId);
71
75
  if (h.session?.players.some((p) => p.playerId === playerId)) {
72
76
  if (visit.droppedAt !== undefined) {resume(h, visit, now);}
@@ -96,10 +100,37 @@ function resume(h, visit, now) {
96
100
  delete visit.droppedWall;
97
101
  delete visit.reported;
98
102
  }
103
+ // A place without a result that ends a visit (`hub.end`: the House's front
104
+ // door, the first room's way back) reports it now, while the player is still
105
+ // connected. The way back can keep this connection open long after the player
106
+ // has gone, and a single-player place's report after the drop never lands:
107
+ // the first room logged no session_end once its way out moved from `hub.go`
108
+ // to `hub.end` (Oct 21).
109
+ export function ended(h, playerId) {
110
+ const visit = h.analytics?.visits.get(playerId);
111
+ if (!visit || visit.ended || visit.reported) {return;}
112
+ const away = visit.droppedAt !== undefined;
113
+ end(h, playerId, visit, (away ? visit.droppedAt : h.sim.timeMs) - visit.at,
114
+ visit.continued ? END.continued : away ? END.dropped : END.left);
115
+ visit.ended = true;
116
+ }
117
+ // The player stayed after that end (v1.169 `hub-stay`): what follows is a
118
+ // continuation.
119
+ export function stayed(h, playerId) {
120
+ const visit = h.analytics?.visits.get(playerId);
121
+ if (!visit?.ended) {return;}
122
+ delete visit.ended;
123
+ delete visit.droppedAt;
124
+ delete visit.droppedWall;
125
+ visit.continued = true;
126
+ visit.at = h.sim.timeMs;
127
+ }
99
128
  export function leave(h, playerId) {
100
129
  const a = h.analytics, visit = a.visits.get(playerId);
101
130
  if (!visit) {return;}
102
- if (visit.droppedAt !== undefined) {
131
+ if (visit.ended) {
132
+ // Reported at the end.
133
+ } else if (visit.droppedAt !== undefined) {
103
134
  if (!visit.reported) {end(h, playerId, visit, visit.droppedAt - visit.at, visit.continued ? END.continued : END.dropped);}
104
135
  } else {end(h, playerId, visit, h.sim.timeMs - visit.at, visit.continued ? END.continued : END.left);}
105
136
  a.visits.delete(playerId);
@@ -111,16 +142,17 @@ export function fps(h, session, player, data) {
111
142
  const entry = h.players.get(player?.playerId);
112
143
  if (h.place?.analytics !== true || !h.place.fpsTelemetry || !entry?.arrived || !session.players.some((p) => p.playerId === player.playerId) ||
113
144
  data.scene !== h.place.fpsTelemetry.scene || typeof data.final !== 'boolean' ||
114
- Object.keys(data).some((key) => !['k', 'scene', 'median', 'p10', 'tier', 'avatars', 'final'].includes(key))) {return false;}
145
+ Object.keys(data).some((key) => !['k', 'scene', 'median', 'p10', 'tier', 'avatars', 'final', 'quality'].includes(key))) {return false;}
115
146
  for (const [key, max] of [['median', 4095], ['p10', 4095], ['tier', 3], ['avatars', 255]]) {
116
147
  if (!Number.isInteger(data[key]) || data[key] < 0 || data[key] > max) {return false;}
117
148
  }
118
- if (data.p10 > data.median) {return false;}
149
+ if (data.p10 > data.median || (Object.hasOwn(data, 'quality') && data.quality !== 'hide' && data.quality !== 'skip')) {return false;}
119
150
  const now = h.sim.timeMs;
120
151
  const field = data.final ? 'fpsFinalAt' : 'fpsAt';
121
152
  if (entry[field] !== undefined && now - entry[field] < 60000) {return false;}
122
153
  entry[field] = now;
123
154
  return send(h.session, player.playerId, {
124
155
  kind: 26, subject: data.tier, value: data.median * 4096 + data.p10, result: data.avatars, flags: 0,
156
+ ...(Object.hasOwn(data, 'quality') ? { quality: data.quality === 'hide' ? 1 : 2 } : {}),
125
157
  });
126
158
  }
@@ -1,6 +1,7 @@
1
1
  // Private text prompts (contract v1.75). Only the place hook receives text;
2
2
  // no answer is retained, echoed, included in state or used in an error line.
3
3
  import { validPrivateText as textOk } from '../privateText.js';
4
+ import * as Held from './heldOffers.js';
4
5
 
5
6
  const ID = /^[a-z][a-z0-9_-]{0,23}$/;
6
7
  const SEND_EVERY_MS = 250;
@@ -51,15 +52,20 @@ export function set(h, playerId, spec) {
51
52
  need(h.place.ask === true, 'this place does not declare ask');
52
53
  need(typeof playerId === 'string', 'playerId must be a string');
53
54
  const checked = check(spec);
54
- if (!arrived(h, playerId)) {
55
+ // v1.180: a held visit away takes the call, recorded unsent.
56
+ const held = Held.on(h) ? Held.take(h, playerId) : null;
57
+ if (held === 'block' || (!held?.away && !arrived(h, playerId))) {
55
58
  return false;
56
59
  }
60
+ if (held && Held.gate(h, playerId, h.askMe?.get(playerId)) === 'drop') {
61
+ h.askMe.delete(playerId);
62
+ }
57
63
  const state = current(h, playerId), json = JSON.stringify(checked);
58
- if (state.json !== json) {
64
+ if (state.json !== json || state.hold !== held?.hold) {
59
65
  // Every change invalidates the old version, even if it changes back
60
66
  // before delivery. Delivery equality includes that new version.
61
67
  const n = version(h);
62
- (h.askMe ??= new Map()).set(playerId, { ...state, spec: checked, json, n });
68
+ (h.askMe ??= new Map()).set(playerId, { ...state, spec: checked, json, n, ...(held ? { hold: held.hold } : {}) });
63
69
  }
64
70
  return true;
65
71
  }
@@ -112,6 +118,16 @@ export function message(h, playerId, data) {
112
118
  return;
113
119
  }
114
120
  const promptId = data.id, n = data.n, state = current(h, playerId);
121
+ // v1.180: a held prompt is answered only by its own account, back on the
122
+ // visit's body and replayed to by a fresh hello.
123
+ const held = Held.on(h) ? Held.gate(h, playerId, h.askMe?.get(playerId)) : null;
124
+ if (held === 'drop' || held === 'block') {
125
+ h.askMe?.delete(playerId);
126
+ return;
127
+ }
128
+ if (held === 'away') {
129
+ return;
130
+ }
115
131
  if (!state.spec || !id(promptId) || promptId !== state.spec.id || promptId !== state.sentId ||
116
132
  !Number.isSafeInteger(n) || n !== state.n || n !== state.sentN) {
117
133
  return;
@@ -133,6 +149,17 @@ export function message(h, playerId, data) {
133
149
  }
134
150
  }
135
151
  export function joinedAfresh(h, playerId) {
152
+ if (Held.on(h)) {
153
+ const held = Held.gate(h, playerId, h.askMe?.get(playerId));
154
+ if (held === 'drop' || held === 'block') {
155
+ h.askMe?.delete(playerId);
156
+ } else if (held === 'away') {
157
+ return;
158
+ } else if (held === 'here' && h.askMe?.has(playerId)) {
159
+ // v1.180: a replay is a new prompt; answers to the old version are refused.
160
+ h.askMe.get(playerId).n = version(h);
161
+ }
162
+ }
136
163
  const state = current(h, playerId);
137
164
  (h.askMe ??= new Map()).set(playerId, state);
138
165
  send(h, playerId, state);
@@ -143,6 +170,15 @@ export function forget(h, playerId) {
143
170
  }
144
171
  export function prune(h) {
145
172
  for (const playerId of new Set([...(h.askMe?.keys() ?? []), ...(h.askBudget?.keys() ?? [])])) {
173
+ const held = Held.on(h) ? Held.gate(h, playerId, h.askMe?.get(playerId)) : null;
174
+ if (held === 'drop' || held === 'block') {
175
+ forget(h, playerId);
176
+ continue;
177
+ }
178
+ if (held === 'away') {
179
+ h.askBudget?.delete(playerId);
180
+ continue;
181
+ }
146
182
  if (!present(h, playerId)) {
147
183
  forget(h, playerId);
148
184
  continue;
@@ -321,7 +321,11 @@ export function ballot(h, playerIds, spec) {
321
321
  // as `words` (line id -> the line as this viewer reads it, only for a line
322
322
  // the redaction changes). A lock on a face they cannot see stays a lock,
323
323
  // `picked: {}`, without naming whom.
324
- // `d` is `{ usernameOf(playerId) | null, avatarOf(playerId) | null, hidden: Set | null, names: [usernames], lines: [manifest lines] }`.
324
+ // v1.179 `ballot.keepAway`: a face of a player the place still retains (away)
325
+ // is on it too, `away: true`, when `d.awayOf(playerId)` gives their snapshot
326
+ // profile for this viewer (the invariant at `rememberSeen`); only faces, never
327
+ // feed rows. Without the key there is no `awayOf`.
328
+ // `d` is `{ usernameOf(playerId) | null, avatarOf(playerId) | null, awayOf?(playerId) | { name, avatar? } | null, hidden: Set | null, names: [usernames], lines: [manifest lines] }`.
325
329
  export function viewFor(card, viewer, d) {
326
330
  if (!card) {
327
331
  return null;
@@ -351,9 +355,22 @@ export function viewFor(card, viewer, d) {
351
355
  if (card.until !== undefined) {
352
356
  view.until = card.until;
353
357
  }
358
+ // An away face's name and avatar: the snapshot `d.awayOf` gives.
359
+ const knowAway = (playerId) => {
360
+ const profile = d.awayOf?.(playerId) ?? null;
361
+ if (!profile) {
362
+ return false;
363
+ }
364
+ who[playerId] = Number.isInteger(profile.avatar) ? { name: profile.name, avatar: profile.avatar } : { name: profile.name };
365
+ return true;
366
+ };
354
367
  view.faces = [];
355
368
  for (const face of card.faces) {
356
- if (hidden?.has(face.playerId) || !know(face.playerId)) {
369
+ if (hidden?.has(face.playerId)) {
370
+ continue;
371
+ }
372
+ const away = !know(face.playerId);
373
+ if (away && !knowAway(face.playerId)) {
357
374
  continue;
358
375
  }
359
376
  const out = { id: face.playerId };
@@ -365,6 +382,9 @@ export function viewFor(card, viewer, d) {
365
382
  out[key] = face[key];
366
383
  }
367
384
  }
385
+ if (away) {
386
+ out.away = true;
387
+ }
368
388
  view.faces.push(out);
369
389
  }
370
390
  view.options = card.options.map((option) => ({ id: option.id, text: redact(option.text) }));
@@ -404,7 +424,8 @@ export function viewFor(card, viewer, d) {
404
424
  // The view of the card a player has now (theirs, else the shared one): a
405
425
  // pure function of the card and of who is connected now. Blocks are the
406
426
  // session's pairs among the players here (`hiddenPair` answers nothing about
407
- // a player who has left), so nothing is remembered between sends.
427
+ // a player who has left), so nothing is remembered between sends -- but for
428
+ // v1.179 `keepAway`, whose away faces go by `h.ballotSeen` (the invariant).
408
429
  function currentView(h, playerId, deps, hidden) {
409
430
  const s = h.ballotState;
410
431
  const card = s.me.get(playerId) ?? s.shared;
@@ -412,18 +433,155 @@ function currentView(h, playerId, deps, hidden) {
412
433
  return viewFor(card, playerId, {
413
434
  usernameOf: deps.usernameOf,
414
435
  avatarOf: deps.avatarOf,
436
+ ...(deps.retained ? { awayOf: (id) => awayProfile(h, deps, playerId, id) } : {}),
415
437
  hidden: hiddenIds,
416
438
  names: hiddenIds ? deps.namesOf(hiddenIds) : [],
417
439
  lines: h.place.ballot.lines,
418
440
  });
419
441
  }
420
442
 
443
+ // v1.179 `ballot.keepAway`. THE INVARIANT, from which every send and every
444
+ // tap is derived, from current state only (never from what a card carried):
445
+ //
446
+ // A face of target T is eligible for viewer V iff
447
+ // (1) T is present now (today's rules: in the world, in the session, and no
448
+ // block among players here hides them from V), or
449
+ // (2) T is retained away now (arrived, dropped, inside the resume
450
+ // deadline as prepareResume reckons it, not forgotten, not let go and
451
+ // not dropped right after their own Back -- read at the tap or send
452
+ // itself, not only when reconcile runs), and T's record -- written at the last
453
+ // send T was present -- holds V as present with T at that send, not
454
+ // hidden from T by a block then, under the account V is signed in as
455
+ // now, and the record's T account is the account T's retained visit is
456
+ // held for now. The away face is drawn from that record's snapshot of
457
+ // T's profile (username and avatar, taken at the same send under T's
458
+ // account then), never from the retained visit's entry.
459
+ // Any account change on either id invalidates its records: each id carries
460
+ // a generation that moves the moment its signed-in account is seen to
461
+ // change (any message from that id, a hello among them; a tap naming it; a
462
+ // send's roster read), from one counter per layer that never goes back, so
463
+ // no generation is ever reused; a record names V and T by generation and
464
+ // account. Blocks for (1) are the session's answer for the accounts on
465
+ // both ids now. A guest (anonymous, dev guests included) has no signed-in
466
+ // account and is never in a record. A tap on a face counts iff the face is eligible at
467
+ // tap time by this same rule, whatever `away` the delivered card had.
468
+ //
469
+ // State (`h.ballotSeen`, only in a keepAway place): `ids` playerId ->
470
+ // { account, gen } as last seen present; `records` T -> { tick, account,
471
+ // gen, name, avatar? }, where `tick` is that send's { keys: V -> "gen:account",
472
+ // hidden } shared by every record written at it. Kept from the first send,
473
+ // before any card, so a card made while someone is away still has their face;
474
+ // entries go once their player is neither present nor retained.
475
+ function seenState(h) {
476
+ h.ballotSeen ??= { counter: 0, ids: new Map(), records: new Map() };
477
+ return h.ballotSeen;
478
+ }
479
+
480
+ // An account change on a player id, the moment anything shows it (a send's
481
+ // roster read, any message from them, a tap naming them): their id takes a
482
+ // new generation and their own record goes. Generations come from one
483
+ // counter per layer that never goes back, so an id forgotten and seen again
484
+ // never takes a generation an older record names. Only for an id in the
485
+ // session roster now; one first seen gets its generation here too.
486
+ export function observe(h, deps, playerId) {
487
+ if (!h.ballotSeen || typeof playerId !== 'string' || !deps.inRoster(playerId)) {
488
+ return;
489
+ }
490
+ const seen = h.ballotSeen;
491
+ const account = deps.identityOf(playerId);
492
+ const id = seen.ids.get(playerId);
493
+ if (!id) {
494
+ seen.counter += 1;
495
+ seen.ids.set(playerId, { account, gen: seen.counter });
496
+ } else if (id.account !== account) {
497
+ seen.counter += 1;
498
+ id.account = account;
499
+ id.gen = seen.counter;
500
+ seen.records.delete(playerId);
501
+ }
502
+ }
503
+
504
+ function rememberSeen(h, deps, hidden) {
505
+ const seen = seenState(h);
506
+ const present = [];
507
+ for (const playerId of h.sim.players.keys()) {
508
+ if (!deps.usernameOf(playerId)) {
509
+ continue;
510
+ }
511
+ present.push(playerId);
512
+ observe(h, deps, playerId);
513
+ }
514
+ const tick = { keys: new Map(), hidden };
515
+ for (const playerId of present) {
516
+ const id = seen.ids.get(playerId);
517
+ if (typeof id.account === 'string') {
518
+ tick.keys.set(playerId, `${id.gen}:${id.account}`);
519
+ }
520
+ }
521
+ for (const playerId of present) {
522
+ const id = seen.ids.get(playerId);
523
+ const profile = typeof id.account === 'string' ? deps.profileOf(playerId, id.account) : null;
524
+ if (profile) {
525
+ seen.records.set(playerId, { tick, account: id.account, gen: id.gen, ...profile });
526
+ } else {
527
+ seen.records.delete(playerId);
528
+ }
529
+ }
530
+ const here = new Set(present);
531
+ for (const map of [seen.ids, seen.records]) {
532
+ for (const playerId of map.keys()) {
533
+ if (!here.has(playerId) && !deps.retained(playerId)) {
534
+ map.delete(playerId);
535
+ }
536
+ }
537
+ }
538
+ }
539
+
540
+ // Rule (2): T's away profile for V, `{ name, avatar? }`, or null.
541
+ function awayProfile(h, deps, viewer, target) {
542
+ const seen = h.ballotSeen;
543
+ const record = seen?.records.get(target);
544
+ if (!record || !deps.retained(target)) {
545
+ return null;
546
+ }
547
+ // V as signed in now: an account that moved since the last send has no
548
+ // generation yet, so nothing recorded can match it.
549
+ const account = deps.identityOf(viewer);
550
+ const id = seen.ids.get(viewer);
551
+ if (typeof account !== 'string' || id?.account !== account || record.tick.keys.get(viewer) !== `${id.gen}:${account}`) {
552
+ return null;
553
+ }
554
+ if (record.tick.hidden?.get(viewer)?.has(target)) {
555
+ return null;
556
+ }
557
+ // T's retained visit is held for the account the snapshot was taken under.
558
+ if (deps.awayIdentityOf(target) !== record.account || seen.ids.get(target)?.gen !== record.gen) {
559
+ return null;
560
+ }
561
+ return record.avatar === undefined ? { name: record.name } : { name: record.name, avatar: record.avatar };
562
+ }
563
+
564
+ // The invariant, for a tap: rule (1) or rule (2), now, after noting any
565
+ // account change either id shows. Blocks are asked of the session as it is
566
+ // now (the pairs are cached by player id and account, never across a switch).
567
+ function eligible(h, deps, viewer, target) {
568
+ observe(h, deps, viewer);
569
+ observe(h, deps, target);
570
+ if (deps.usernameOf(target)) {
571
+ return !deps.blockedPairs()?.get(viewer)?.has(target);
572
+ }
573
+ return awayProfile(h, deps, viewer, target) !== null;
574
+ }
575
+
421
576
  // Each player's card, to them alone, when it changes (and again to a client
422
577
  // that joined afresh). Nothing in a place that has never shown one. Whatever
423
578
  // is kept for a connection no longer in the world goes, whether or not it
424
579
  // ever said hello (`forget` runs only for players who did).
425
580
  export function send(h, deps) {
426
581
  const s = h.ballotState;
582
+ if (deps.retained) {
583
+ rememberSeen(h, deps, deps.blockedPairs());
584
+ }
427
585
  if (!s) {
428
586
  return;
429
587
  }
@@ -483,7 +641,7 @@ function allows(view, face, line, option, lines) {
483
641
  // version of the card they have now, and the ids are allowed by that card as
484
642
  // delivered; then the tap is limited and handed to the deck's `ballot` hook.
485
643
  // Anything else is dropped unheard.
486
- export function message(h, player, data, lines) {
644
+ export function message(h, player, data, lines, deps) {
487
645
  const playerId = player?.playerId;
488
646
  const s = h.ballotState;
489
647
  const delivered = s?.views.get(playerId) ?? null;
@@ -508,6 +666,11 @@ export function message(h, player, data, lines) {
508
666
  if (!allows(delivered, face, line, option, lines)) {
509
667
  return;
510
668
  }
669
+ // v1.179 keepAway: a face counts iff it is eligible now (the invariant
670
+ // above), whatever `away` the delivered card had.
671
+ if (face !== null && deps?.retained && !eligible(h, deps, playerId, face)) {
672
+ return;
673
+ }
511
674
  const now = Date.now();
512
675
  const r = s.rate.get(playerId) ?? { tokens: BURST, at: now };
513
676
  r.tokens = Math.min(BURST, r.tokens + (now - r.at) / EVERY_MS);
@@ -0,0 +1,64 @@
1
+ // v1.205. Server-only Town win moments; no state or wire work before a call.
2
+ import { townDay } from './townDay.js';
3
+
4
+ const GAP_MS = 4000;
5
+ const connected = (h, id) => !h.resumeDeparting?.has(id) && !h.actDeparting?.has(id) && h.players.get(id)?.arrived && !h.players.get(id)?.ended &&
6
+ h.sim?.players.has(id) && h.session?.players.some((p) => p.playerId === id);
7
+ const at = (h, id) => h.sim?.players.get(id)?.at;
8
+
9
+ export function tick(h) {
10
+ const state = h.celebrations;
11
+ if (!state || h.sim.timeMs < state.next) {return;}
12
+ while (state.queue.length) {
13
+ const item = state.queue.shift();
14
+ if (item.session !== h.session || !connected(h, item.player) || item.day !== townDay() || String(h.session.players.find((p) => p.playerId === item.player)?.userId) !== item.user) {continue;}
15
+ const origin = at(h, item.player);
16
+ if (!origin) {continue;}
17
+ const { session, day, user, ...message } = item;
18
+ // Hidden pairs never learn a blocked player's moment or position.
19
+ for (const p of session.players) {
20
+ const target = at(h, p.playerId);
21
+ if (!connected(h, p.playerId) || !target || session.hub?.hiddenPair?.(item.player, p.playerId)) {continue;}
22
+ if (Math.hypot(origin.x - target.x, origin.y - target.y, origin.z - target.z) <= 25) {session.send(p.playerId, { k: 'celebrate', ...message });}
23
+ }
24
+ state.next = h.sim.timeMs + GAP_MS;
25
+ break;
26
+ }
27
+ }
28
+
29
+ export function celebrate(h, playerId, spec, userIdOf) {
30
+ if (h.placeId !== 'main' || h.place.result || !connected(h, playerId) || !spec || typeof spec !== 'object' || Array.isArray(spec) ||
31
+ spec.kind !== 'win' || typeof spec.tokens !== 'number' || !Number.isFinite(spec.tokens) ||
32
+ (spec.streak !== undefined && spec.streak !== 3 && spec.streak !== 5) ||
33
+ Object.keys(spec).some((k) => !['kind', 'door', 'tokens', 'streak', 'unlock'].includes(k))) {return Promise.resolve(false);}
34
+ const door = h.actors.find((a) => a.components.HubDoor?.id === spec.door);
35
+ if (!door || (spec.unlock !== undefined && !h.manifest.unlocks?.some((i) => i.id === spec.unlock))) {return Promise.resolve(false);}
36
+ const user = userIdOf(h, playerId);
37
+ if (!user) {return Promise.resolve(false);}
38
+ const day = townDay(), session = h.session;
39
+ const state = h.celebrations ??= { queue: [], next: -Infinity, day, counts: new Map() };
40
+ if (state.day !== day) { state.day = day; state.counts.clear(); }
41
+ const used = state.counts.get(user) ?? 0;
42
+ if (used >= 6 || (state.counts.size >= 1000 && !state.counts.has(user))) {return Promise.resolve(false);}
43
+ state.counts.set(user, used + 1); // Includes outstanding reservations; reconnect never clears it.
44
+ const message = { player: playerId, kind: 'win', door: spec.door, tokens: Math.max(0, Math.min(40, Math.floor(spec.tokens))),
45
+ ...(spec.streak !== undefined ? { streak: spec.streak } : {}), ...(spec.unlock !== undefined ? { unlock: spec.unlock } : {}) };
46
+ // Atomic daily count also bounds concurrent layers. An ambiguous failure
47
+ // consumes a reservation and shows nothing; it is never retried here.
48
+ const date = new Date(day * 86400000).toISOString().slice(0, 10);
49
+ let reservation;
50
+ try {
51
+ reservation = session.storage?.deck?.increment
52
+ ? session.storage.deck.increment(`earn:${user}:${date}:celebrate`, 1)
53
+ : h.savedDeckId ? Promise.resolve(Infinity) : Promise.resolve(used + 1);
54
+ } catch { return Promise.resolve(false); }
55
+ return Promise.resolve(reservation).then((count) => {
56
+ if (!Number.isSafeInteger(count) || count < 1 || count > 6 || session !== h.session || !connected(h, playerId) || userIdOf(h, playerId) !== user || day !== townDay()) {return false;}
57
+ state.queue.push({ session, day, user, ...message });
58
+ if (state.queue.length > 3) {state.queue.shift();}
59
+ tick(h);
60
+ return true;
61
+ }, () => false);
62
+ }
63
+
64
+ export function clear(h) { if (h.celebrations) { h.celebrations.queue.length = 0; h.celebrations.next = -Infinity; } }
@@ -24,7 +24,14 @@ function current(h, playerId) {
24
24
  return h.companionMe?.get(playerId) ?? { c: null, n: 0, json: 'null', sentJson: 'null', sentN: 0, sentAt: -Infinity };
25
25
  }
26
26
  function send(h, playerId, state) {
27
- h.session?.send(playerId, { k: 'hub-companion', c: state.c, n: state.n });
27
+ // shown selects public dress on the server. Keep it off the private spec:
28
+ // older clients validate that spec strictly and ignore only hubChirp.
29
+ const c = state.c ? { ...state.c } : null;
30
+ if (c) { delete c.shown; }
31
+ h.session?.send(playerId, { k: 'hub-companion', c, n: state.n });
32
+ // Public dress follows the same coalesced version as the owner's follower.
33
+ state.chirp = state.c?.shown === true
34
+ ? ['species', 'wear', 'tint'].map((key) => state.c.dress?.[key] ?? null) : null;
28
35
  state.sentN = state.n;
29
36
  state.sentJson = state.json;
30
37
  state.sentAt = h.sim?.timeMs ?? 0;
@@ -54,6 +61,7 @@ export function set(h, playerId, c) {
54
61
  (h.companionMe ??= new Map()).set(playerId, { ...state, c: checked, json, n });
55
62
  if (checked) {
56
63
  h.companionUsed = true;
64
+ if (checked.shown === true) { h.companionShownUsed = true; }
57
65
  }
58
66
  return true;
59
67
  }
@@ -101,7 +109,14 @@ export function prune(h) {
101
109
  }
102
110
  }
103
111
 
104
- // Public presence alone: never the look, dress, words or target.
112
+ // Public presence alone; opt-in dress travels separately in hubChirp.
105
113
  export function glowOf(h) {
106
114
  return [...(h.companionMe ?? [])].filter(([id, state]) => state.c && h.players.get(id)?.hello && arrived(h, id)).map(([id]) => id).sort();
107
115
  }
116
+
117
+ export function chirpOf(h) {
118
+ return [...(h.companionMe ?? [])]
119
+ .filter(([id, state]) => state.chirp && h.players.get(id)?.hello && arrived(h, id))
120
+ .sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
121
+ .map(([id, state]) => [id, ...state.chirp]);
122
+ }
@@ -108,7 +108,7 @@ export function checkSpec(h, value) {
108
108
  const tabs = new Set(out.tabs.map((tab) => tab.id));
109
109
  list(value.items, MAX_ITEMS, 'items');
110
110
  out.items = value.items.map((item) => {
111
- keys(item, ['id', 'tab', 'label', 'template', 'w', 'd', 'layer', 'count', 'locked'], 'item');
111
+ keys(item, ['id', 'tab', 'label', 'template', 'w', 'd', 'layer', 'count', 'locked', 'action'], 'item');
112
112
  id(item.id, 'item.id');
113
113
  need(tabs.has(item.tab), 'item.tab must name a tab');
114
114
  need(text(item.label, 16), 'item.label must be 1..16 characters');
@@ -118,6 +118,10 @@ export function checkSpec(h, value) {
118
118
  need(h.place.decor.layers.includes(item.layer), 'item.layer must name a decor layer');
119
119
  need(int(item.count, 0, Number.MAX_SAFE_INTEGER), 'item.count must be a non-negative integer');
120
120
  const entry = { id: item.id, tab: item.tab, label: item.label, template: item.template, w: item.w, d: item.d, layer: item.layer, count: item.count };
121
+ if (Object.hasOwn(item, 'action')) {
122
+ need(item.action === true, 'item.action must be true');
123
+ entry.action = true;
124
+ }
121
125
  if (item.locked !== undefined) {
122
126
  keys(item.locked, ['price'], 'item.locked');
123
127
  need(text(item.locked.price, 12), 'locked.price must be 1..12 characters');
@@ -244,7 +248,7 @@ export function message(h, playerId, data) {
244
248
  need(int(data.x, 0, grid.w - 1) && int(data.z, 0, grid.d - 1) && int(data.rot, 0, 3), 'invalid cells or rotation');
245
249
  if (data.op === 'place') {
246
250
  const item = spec.items.find((i) => i.id === data.item);
247
- need(item && !item.locked && item.count > 0, 'item is unavailable');
251
+ need(item && !item.action && !item.locked && item.count > 0, 'item is unavailable');
248
252
  op = { op: 'place', item: data.item, x: data.x, z: data.z, rot: data.rot };
249
253
  } else {
250
254
  need(spec.placed.some((p) => p.key === data.key), 'piece is not in this catalogue');
@@ -252,6 +256,11 @@ export function message(h, playerId, data) {
252
256
  }
253
257
  break;
254
258
  }
259
+ case 'pick':
260
+ keys(data, ['k', 'op', 'item'], 'pick op');
261
+ need(spec.items.some((i) => i.id === data.item && i.action === true && !i.locked), 'action is unavailable');
262
+ op = { op: 'pick', item: data.item };
263
+ break;
255
264
  case 'stash':
256
265
  keys(data, ['k', 'op', 'key'], 'stash op');
257
266
  need(spec.placed.some((p) => p.key === data.key), 'piece is not in this catalogue');
@@ -0,0 +1,63 @@
1
+ // Per-player disguise, contract v1.196. Visit-only, no host calls.
2
+ import { warnOnce } from './actors.js';
3
+ import { vehicle } from './vehicle.js';
4
+
5
+ export function newDisguiseState() {
6
+ return { disguises: new Map(), disguiseOwners: new Map(), disguiseWire: new Map(), disguiseAt: new Map(), disguiseUsed: false };
7
+ }
8
+ const owner = (h, id) => h.session?.players.find(p => p.playerId === id)?.userId ?? null;
9
+ const present = (h, id) => h.players.get(id)?.arrived && !h.players.get(id)?.ended && h.sim?.players.has(id) && h.session?.players.some(p => p.playerId === id);
10
+ function refuse(h, reason) {
11
+ warnOnce(h, `disguise:${reason}`, `hub.disguise: ${reason}`);
12
+ return false;
13
+ }
14
+ export function disguise(h, id, spec) {
15
+ prune(h);
16
+ let value = null;
17
+ if (spec !== null) {
18
+ if (!spec || typeof spec !== 'object' || ![Object.prototype, null].includes(Object.getPrototypeOf(spec))) {return refuse(h, 'expected { look?, to? } or null');}
19
+ const fields = Object.getOwnPropertyDescriptors(spec);
20
+ if (Reflect.ownKeys(fields).some(k => !['look', 'to'].includes(k) || !Object.hasOwn(fields[k], 'value'))) {return refuse(h, 'unknown keys or accessors');}
21
+ if (Object.hasOwn(fields, 'look') && (typeof spec.look !== 'string' || !h.actors.some(a => a.id === spec.look && a.components?.Model))) {return refuse(h, 'look must be a scene Model');}
22
+ if (Object.hasOwn(fields, 'to') && (!Array.isArray(spec.to) || spec.to.length > 256 || Array.from(spec.to).some(v => typeof v !== 'string'))) {return refuse(h, 'to must contain at most 256 playerId strings');}
23
+ value = { look: spec.look ?? null, to: spec.to === undefined ? null : [...new Set(spec.to)].sort() };
24
+ }
25
+ // A clear is always taken: a disguised player may since have been held.
26
+ if (!value) {h.disguiseUsed = true; h.disguises.delete(id); return true;}
27
+ if (!present(h, id) || h.resumeDeparting?.has(id) || h.vehicleDeparting?.has(id)) {return refuse(h, 'requires an arrived player outside a trip');}
28
+ if (vehicle(h, id) || h.held.has(id)) {return refuse(h, 'requires an unheld walker');}
29
+ if (value.look && h.grabs.has(id)) {return refuse(h, 'look requires a player without a grabbed actor');}
30
+ h.disguiseUsed = true;
31
+ h.disguises.set(id, value); h.disguiseOwners.set(id, owner(h, id));
32
+ return true;
33
+ }
34
+ export function disguised(h, id) {
35
+ prune(h);
36
+ const value = h.disguises.get(id);
37
+ return value ? { look: value.look, to: value.to && [...value.to] } : null;
38
+ }
39
+ export function prune(h) {
40
+ for (const id of new Set([...h.disguises.keys(), ...h.disguiseWire.keys()])) {
41
+ if (!h.players.has(id) || h.resumeDeparting?.has(id) ||
42
+ (h.session?.players.some(p => p.playerId === id) && h.disguiseOwners.get(id) !== owner(h, id))) {forget(h, id);}
43
+ }
44
+ }
45
+ export function fields(h) {
46
+ prune(h);
47
+ const now = h.sim?.timeMs ?? 0;
48
+ for (const id of new Set([...h.disguises.keys(), ...h.disguiseWire.keys()])) {
49
+ const value = h.disguises.get(id), tuple = value ? [value.look, value.to] : null;
50
+ if (JSON.stringify(h.disguiseWire.get(id) ?? null) === JSON.stringify(tuple)) {continue;}
51
+ if (now - (h.disguiseAt.get(id) ?? -Infinity) < 250) {continue;}
52
+ if (tuple) {h.disguiseWire.set(id, tuple);} else {h.disguiseWire.delete(id);}
53
+ h.disguiseAt.set(id, now);
54
+ }
55
+ return h.disguiseUsed || h.sent.has('hubDisguise') ? { hubDisguise: [...h.disguiseWire].filter(([id]) => present(h, id))
56
+ .sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([id, [look, to]]) => [id, look, to && [...to]]) } : {};
57
+ }
58
+ export function forget(h, id) {
59
+ h.disguises.delete(id); h.disguiseOwners.delete(id); h.disguiseWire.delete(id); h.disguiseAt.delete(id);
60
+ }
61
+ export function end(h) {
62
+ h.disguises.clear(); h.disguiseOwners.clear(); h.disguiseWire.clear(); h.disguiseAt.clear();
63
+ }
@@ -403,12 +403,16 @@ function drawn(item) {
403
403
  return { class: item.class, shape: item.shape, color: item.color, name: item.name };
404
404
  }
405
405
 
406
+ // Mask held Earned in the projection while a flower is set, including when
407
+ // grabs or coalescing hide the flower. The account's actual value is untouched.
408
+ const heldByFlower = (h, id, item) => item?.class === 'held' && h.holdShows?.has(id);
409
+
406
410
  // Everyone's earned items, for everyone: helloed players only, without the
407
411
  // ones a block hides from someone here.
408
412
  export function earnedForAll(h, hidden) {
409
413
  const out = {};
410
414
  for (const [playerId, item] of h.earned) {
411
- if (h.players.get(playerId)?.hello && !hidden?.has(playerId)) {
415
+ if (h.players.get(playerId)?.hello && !hidden?.has(playerId) && !heldByFlower(h, playerId, item)) {
412
416
  out[playerId] = drawn(item);
413
417
  }
414
418
  }
@@ -433,7 +437,7 @@ export function sendOverrides(h, hidden) {
433
437
  const out = {};
434
438
  for (const shrouded of hidden?.keys() ?? []) {
435
439
  const item = h.earned.get(shrouded);
436
- if (item && h.players.get(shrouded)?.hello && !hidden.get(playerId)?.has(shrouded)) {
440
+ if (item && h.players.get(shrouded)?.hello && !hidden.get(playerId)?.has(shrouded) && !heldByFlower(h, shrouded, item)) {
437
441
  out[shrouded] = drawn(item);
438
442
  }
439
443
  }