castle-web-cli 0.4.233 → 0.4.235

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 (383) hide show
  1. package/dist/api.d.ts +11 -0
  2. package/dist/api.js +43 -0
  3. package/dist/bundle.d.ts +64 -0
  4. package/dist/bundle.js +558 -2
  5. package/dist/castle-host/host.d.ts +17 -2
  6. package/dist/castle-host/host.js +793 -36
  7. package/dist/castleJson.d.ts +20 -1
  8. package/dist/castleJson.js +44 -2
  9. package/dist/check.js +9 -2
  10. package/dist/chunkLoader.d.ts +3 -0
  11. package/dist/chunkLoader.js +111 -0
  12. package/dist/devParty.d.ts +26 -0
  13. package/dist/devParty.js +231 -0
  14. package/dist/devSaveStorage.js +4 -0
  15. package/dist/devSessionStorage.js +3 -1
  16. package/dist/devSocial.d.ts +24 -0
  17. package/dist/devSocial.js +70 -0
  18. package/dist/ide.d.ts +2 -0
  19. package/dist/ide.js +119 -15
  20. package/dist/index.js +8 -2
  21. package/dist/init.js +1 -1
  22. package/dist/save-deck.d.ts +20 -1
  23. package/dist/save-deck.js +141 -5
  24. package/dist/serve.js +29 -11
  25. package/dist/shell/assets/{index-BjOxR-lW.js → index-DulbYIJm.js} +97 -97
  26. package/dist/shell/index.html +1 -1
  27. package/dist/vitePlugins.d.ts +2 -1
  28. package/dist/vitePlugins.js +13 -0
  29. package/kits/base/castle.json +1 -1
  30. package/kits/base/sdk/README.md +266 -3
  31. package/kits/base/sdk/castle.d.ts +7 -3
  32. package/kits/base/sdk/castle.js +2 -0
  33. package/kits/base/sdk/commands.d.ts +162 -1
  34. package/kits/base/sdk/commands.js +3 -0
  35. package/kits/base/sdk/display.d.ts +3 -0
  36. package/kits/base/sdk/display.js +9 -3
  37. package/kits/base/sdk/hub.d.ts +33 -6
  38. package/kits/base/sdk/hub.js +68 -5
  39. package/kits/base/sdk/hubRejoin.d.ts +4 -0
  40. package/kits/base/sdk/hubRejoin.js +15 -0
  41. package/kits/base/sdk/multiplayer.d.ts +7 -1
  42. package/kits/base/sdk/multiplayer.js +147 -40
  43. package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
  44. package/kits/base/sdk/party.d.ts +23 -0
  45. package/kits/base/sdk/party.js +91 -0
  46. package/kits/base/sdk/reconnectBudget.d.ts +23 -0
  47. package/kits/base/sdk/reconnectBudget.js +96 -0
  48. package/kits/base/sdk/save.d.ts +38 -1
  49. package/kits/base/sdk/save.js +79 -6
  50. package/kits/base/sdk/server/hub.d.ts +31 -1
  51. package/kits/base/sdk/server/hub.js +50 -3
  52. package/kits/base/sdk/server/platformHandle.d.ts +13 -1
  53. package/kits/base/sdk/server/storage.d.ts +4 -0
  54. package/kits/base/sdk/server/storage.js +19 -3
  55. package/kits/base/sdk/server/wrapper.d.ts +7 -1
  56. package/kits/base/sdk/server/wrapper.js +10 -1
  57. package/kits/base/sdk/social.d.ts +9 -0
  58. package/kits/base/sdk/social.js +5 -0
  59. package/kits/hub-game/CLAUDE.md +123 -3
  60. package/kits/hub-game/README.md +63 -0
  61. package/kits/hub-game/castle.json +5 -5
  62. package/kits/hub-game/code/client/act.js +312 -0
  63. package/kits/hub-game/code/client/actionLayout.js +147 -0
  64. package/kits/hub-game/code/client/actionOverflow.js +556 -0
  65. package/kits/hub-game/code/client/arrivalCamera.js +50 -0
  66. package/kits/hub-game/code/client/askSlot.js +117 -0
  67. package/kits/hub-game/code/client/avatar.js +4 -2
  68. package/kits/hub-game/code/client/avatarShare.js +2 -0
  69. package/kits/hub-game/code/client/backVisibility.js +13 -0
  70. package/kits/hub-game/code/client/ballot.js +15 -10
  71. package/kits/hub-game/code/client/build.js +16 -0
  72. package/kits/hub-game/code/client/chat.js +41 -5
  73. package/kits/hub-game/code/client/chatModeration.js +5 -0
  74. package/kits/hub-game/code/client/chrome.js +1148 -258
  75. package/kits/hub-game/code/client/crowdNames.js +241 -0
  76. package/kits/hub-game/code/client/decor.js +10 -4
  77. package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
  78. package/kits/hub-game/code/client/doorErrors.js +39 -0
  79. package/kits/hub-game/code/client/fall.js +18 -0
  80. package/kits/hub-game/code/client/farAvatars.js +233 -0
  81. package/kits/hub-game/code/client/firstJoin.js +9 -2
  82. package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
  83. package/kits/hub-game/code/client/frameBatch.js +5 -0
  84. package/kits/hub-game/code/client/grab.js +31 -11
  85. package/kits/hub-game/code/client/hookLayer.js +87 -8
  86. package/kits/hub-game/code/client/hudCopy.js +51 -0
  87. package/kits/hub-game/code/client/hudRate.js +20 -0
  88. package/kits/hub-game/code/client/idle.js +14 -2
  89. package/kits/hub-game/code/client/invites.js +231 -0
  90. package/kits/hub-game/code/client/joinError.js +9 -0
  91. package/kits/hub-game/code/client/labelsNear.js +31 -2
  92. package/kits/hub-game/code/client/landscapeLayout.js +17 -0
  93. package/kits/hub-game/code/client/layoutCache.js +264 -0
  94. package/kits/hub-game/code/client/loadTelemetry.js +20 -0
  95. package/kits/hub-game/code/client/loadingCover.js +148 -0
  96. package/kits/hub-game/code/client/loadingEntry.js +8 -0
  97. package/kits/hub-game/code/client/menuRows.js +43 -0
  98. package/kits/hub-game/code/client/modelReady.js +7 -0
  99. package/kits/hub-game/code/client/padCueArrival.js +23 -0
  100. package/kits/hub-game/code/client/padCues.js +112 -0
  101. package/kits/hub-game/code/client/padOccupancy.js +88 -0
  102. package/kits/hub-game/code/client/padReadability.js +26 -0
  103. package/kits/hub-game/code/client/padRings.js +69 -0
  104. package/kits/hub-game/code/client/pushVisit.js +14 -0
  105. package/kits/hub-game/code/client/quality.js +205 -0
  106. package/kits/hub-game/code/client/qualityEntry.js +55 -0
  107. package/kits/hub-game/code/client/safeLayout.js +338 -0
  108. package/kits/hub-game/code/client/safeStyle.js +42 -0
  109. package/kits/hub-game/code/client/say.js +12 -3
  110. package/kits/hub-game/code/client/shot.js +64 -10
  111. package/kits/hub-game/code/client/shotFit.js +56 -0
  112. package/kits/hub-game/code/client/signIn.js +28 -0
  113. package/kits/hub-game/code/client/state.js +53 -0
  114. package/kits/hub-game/code/client/talk.js +209 -45
  115. package/kits/hub-game/code/client/tiers.js +68 -66
  116. package/kits/hub-game/code/client/together.js +7 -2
  117. package/kits/hub-game/code/client/weakestLookBake.js +92 -0
  118. package/kits/hub-game/code/client/weakestTier.js +295 -0
  119. package/kits/hub-game/code/client/worldLabels.js +241 -0
  120. package/kits/hub-game/code/client/yours.js +10 -9
  121. package/kits/hub-game/code/npcDisplayText.js +55 -0
  122. package/kits/hub-game/code/server/act.js +124 -0
  123. package/kits/hub-game/code/server/actions.js +6 -1
  124. package/kits/hub-game/code/server/actors.js +2 -1
  125. package/kits/hub-game/code/server/analytics.js +83 -0
  126. package/kits/hub-game/code/server/anonymousEntry.js +49 -0
  127. package/kits/hub-game/code/server/arrivalPose.js +36 -0
  128. package/kits/hub-game/code/server/companion.js +28 -3
  129. package/kits/hub-game/code/server/doorAnalytics.js +52 -0
  130. package/kits/hub-game/code/server/earned.js +22 -5
  131. package/kits/hub-game/code/server/frameBatch.js +183 -0
  132. package/kits/hub-game/code/server/friendsAmong.js +49 -9
  133. package/kits/hub-game/code/server/history.js +2 -0
  134. package/kits/hub-game/code/server/hub.js +1306 -95
  135. package/kits/hub-game/code/server/idle.js +30 -1
  136. package/kits/hub-game/code/server/index.js +26 -4
  137. package/kits/hub-game/code/server/invites.js +19 -0
  138. package/kits/hub-game/code/server/labels.js +9 -1
  139. package/kits/hub-game/code/server/loadAbandon.js +106 -0
  140. package/kits/hub-game/code/server/manifest.js +211 -3
  141. package/kits/hub-game/code/server/menu.js +31 -3
  142. package/kits/hub-game/code/server/npcs.js +226 -64
  143. package/kits/hub-game/code/server/observe.js +408 -0
  144. package/kits/hub-game/code/server/padOccupancy.js +85 -0
  145. package/kits/hub-game/code/server/players.js +9 -1
  146. package/kits/hub-game/code/server/resumePose.js +152 -0
  147. package/kits/hub-game/code/server/say.js +1 -1
  148. package/kits/hub-game/code/server/standing.js +4 -5
  149. package/kits/hub-game/code/server/storageLimit.js +187 -0
  150. package/kits/hub-game/code/server/vis.js +67 -5
  151. package/kits/hub-game/code/shared/act.js +35 -0
  152. package/kits/hub-game/code/shared/danceIdle.js +28 -0
  153. package/kits/hub-game/code/shared/loadStages.js +12 -0
  154. package/kits/hub-game/code/shared/quality.js +74 -0
  155. package/kits/hub-game/code/shared/say.js +2 -0
  156. package/kits/hub-game/code/shared/shot.js +35 -1
  157. package/kits/hub-game/code/systems/hub.js +970 -169
  158. package/kits/hub-game/docs/analytics.md +279 -0
  159. package/kits/hub-game/docs/contract.md +1259 -42
  160. package/kits/hub-game/docs/home-pieces.md +9 -2
  161. package/kits/hub-game/docs/observed-progress.md +252 -0
  162. package/kits/hub-game/main.jsx +2 -0
  163. package/kits/hub-game/package-lock.json +10 -3
  164. package/kits/hub-game/package.json +6 -3
  165. package/kits/hub-game/play/player.js +142 -0
  166. package/kits/hub-game/play/registry.js +47 -0
  167. package/kits/hub-game/play.jsx +37 -0
  168. package/kits/hub-game/scripts/check.mjs +39 -5
  169. package/kits/hub-game/scripts/companion-follower-wire.json +1 -1
  170. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +11 -0
  171. package/kits/hub-game/scripts/fixtures/decor-keyless.json +5 -5
  172. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +3 -0
  173. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +19 -3
  174. package/kits/hub-game/scripts/fixtures/interest-legacy.json +3 -3
  175. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -1
  176. package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
  177. package/kits/hub-game/scripts/test-act-client.mjs +186 -0
  178. package/kits/hub-game/scripts/test-act.mjs +171 -0
  179. package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
  180. package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
  181. package/kits/hub-game/scripts/test-actions-client.mjs +367 -2
  182. package/kits/hub-game/scripts/test-actors.mjs +20 -7
  183. package/kits/hub-game/scripts/test-analytics.mjs +76 -0
  184. package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
  185. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
  186. package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
  187. package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
  188. package/kits/hub-game/scripts/test-avatar-wire.mjs +49 -10
  189. package/kits/hub-game/scripts/test-avatar.mjs +44 -0
  190. package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
  191. package/kits/hub-game/scripts/test-ballot.mjs +11 -4
  192. package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
  193. package/kits/hub-game/scripts/test-build.mjs +20 -2
  194. package/kits/hub-game/scripts/test-chat.mjs +206 -5
  195. package/kits/hub-game/scripts/test-companion-chat.mjs +20 -2
  196. package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
  197. package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
  198. package/kits/hub-game/scripts/test-decor-client.mjs +45 -4
  199. package/kits/hub-game/scripts/test-decor.mjs +7 -0
  200. package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
  201. package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
  202. package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
  203. package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
  204. package/kits/hub-game/scripts/test-earned.mjs +33 -3
  205. package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
  206. package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
  207. package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
  208. package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
  209. package/kits/hub-game/scripts/test-grab-orbit.mjs +47 -4
  210. package/kits/hub-game/scripts/test-high-only.mjs +170 -0
  211. package/kits/hub-game/scripts/test-hub-ops.mjs +321 -2
  212. package/kits/hub-game/scripts/test-hub-trip.mjs +879 -11
  213. package/kits/hub-game/scripts/test-hud-clear.mjs +162 -59
  214. package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
  215. package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
  216. package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
  217. package/kits/hub-game/scripts/test-idle.mjs +66 -0
  218. package/kits/hub-game/scripts/test-interest-cells.mjs +20 -0
  219. package/kits/hub-game/scripts/test-interest.mjs +15 -0
  220. package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
  221. package/kits/hub-game/scripts/test-invites.mjs +109 -0
  222. package/kits/hub-game/scripts/test-labels.mjs +71 -3
  223. package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
  224. package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
  225. package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
  226. package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
  227. package/kits/hub-game/scripts/test-manifest.mjs +265 -0
  228. package/kits/hub-game/scripts/test-menu-client.mjs +105 -0
  229. package/kits/hub-game/scripts/test-menu.mjs +23 -0
  230. package/kits/hub-game/scripts/test-npcs.mjs +917 -10
  231. package/kits/hub-game/scripts/test-observed.mjs +745 -0
  232. package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
  233. package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
  234. package/kits/hub-game/scripts/test-picker.mjs +234 -7
  235. package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
  236. package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
  237. package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
  238. package/kits/hub-game/scripts/test-quality.mjs +385 -0
  239. package/kits/hub-game/scripts/test-rehello.mjs +699 -5
  240. package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
  241. package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
  242. package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
  243. package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
  244. package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
  245. package/kits/hub-game/scripts/test-say.mjs +1 -1
  246. package/kits/hub-game/scripts/test-shot.mjs +145 -0
  247. package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
  248. package/kits/hub-game/scripts/test-soundscape.mjs +22 -17
  249. package/kits/hub-game/scripts/test-standing.mjs +35 -2
  250. package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
  251. package/kits/hub-game/scripts/test-stuck.mjs +5 -4
  252. package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
  253. package/kits/hub-game/scripts/test-tiers-render.mjs +86 -13
  254. package/kits/hub-game/scripts/test-tiers.mjs +7 -8
  255. package/kits/hub-game/scripts/test-vis.mjs +433 -6
  256. package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
  257. package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
  258. package/kits/hub-game/scripts/test-yours-chrome.mjs +50 -6
  259. package/kits/hub-game/scripts/test-yours.mjs +39 -8
  260. package/kits/multiplayer-3d/castle.json +5 -5
  261. package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
  262. package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
  263. package/kits/multiplayer-3d/code/systems/multiplayer.js +369 -30
  264. package/kits/multiplayer-3d/package-lock.json +8 -1
  265. package/kits/multiplayer-3d/package.json +2 -1
  266. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
  267. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
  268. package/kits/physics-2d/CLAUDE.md +10 -1
  269. package/kits/physics-2d/castle.json +2 -2
  270. package/kits/physics-2d/engine/frozenActors.js +233 -0
  271. package/kits/physics-2d/engine/scene.js +87 -5
  272. package/kits/physics-2d/eslint.config.js +1 -1
  273. package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
  274. package/kits/physics-2d/play/behaviors/Camera.js +40 -0
  275. package/kits/physics-2d/play/behaviors/Collider.js +122 -0
  276. package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
  277. package/kits/physics-2d/play/behaviors/Goal.js +46 -0
  278. package/kits/physics-2d/play/behaviors/Joints.js +126 -0
  279. package/kits/physics-2d/play/behaviors/Layout.js +71 -0
  280. package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
  281. package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
  282. package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
  283. package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
  284. package/kits/physics-2d/play/behaviors/Style.js +209 -0
  285. package/kits/physics-2d/play/behaviors/Text.js +85 -0
  286. package/kits/physics-2d/play/behaviors/Video.js +93 -0
  287. package/kits/physics-3d/CLAUDE.md +25 -1651
  288. package/kits/physics-3d/behaviors/Body.jsx +3 -0
  289. package/kits/physics-3d/behaviors/Model.jsx +3 -0
  290. package/kits/physics-3d/behaviors/Player.jsx +35 -18
  291. package/kits/physics-3d/behaviors/Shape.jsx +3 -0
  292. package/kits/physics-3d/behaviors/Solid.jsx +3 -0
  293. package/kits/physics-3d/behaviors/Transform.jsx +3 -0
  294. package/kits/physics-3d/castle.json +3 -3
  295. package/kits/physics-3d/docs/engine-camera.md +542 -0
  296. package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
  297. package/kits/physics-3d/docs/engine-load.md +149 -0
  298. package/kits/physics-3d/docs/engine-look.md +114 -0
  299. package/kits/physics-3d/docs/engine-shadows.md +372 -0
  300. package/kits/physics-3d/docs/engine-skip-work.md +187 -0
  301. package/kits/physics-3d/docs/engine-sky.md +198 -0
  302. package/kits/physics-3d/docs/engine-static-actors.md +226 -0
  303. package/kits/physics-3d/docs/engine-view.md +37 -0
  304. package/kits/physics-3d/docs/pxmodel-format.md +1 -1
  305. package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
  306. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -333
  307. package/kits/physics-3d/engine3d/actornode.js +1 -0
  308. package/kits/physics-3d/engine3d/branches.js +3 -13
  309. package/kits/physics-3d/engine3d/cage.js +2 -7
  310. package/kits/physics-3d/engine3d/cageops.js +2 -17
  311. package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
  312. package/kits/physics-3d/engine3d/framecap.js +4 -1
  313. package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
  314. package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
  315. package/kits/physics-3d/engine3d/gait.js +8 -0
  316. package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
  317. package/kits/physics-3d/engine3d/look.js +7 -0
  318. package/kits/physics-3d/engine3d/modelFiles.js +3 -17
  319. package/kits/physics-3d/engine3d/modelMath.js +49 -0
  320. package/kits/physics-3d/engine3d/modelready.js +16 -0
  321. package/kits/physics-3d/engine3d/motion.js +3 -3
  322. package/kits/physics-3d/engine3d/nearshadows.js +77 -10
  323. package/kits/physics-3d/engine3d/orbitinput.js +59 -25
  324. package/kits/physics-3d/engine3d/partgeometry.js +1 -16
  325. package/kits/physics-3d/engine3d/paths.js +1 -9
  326. package/kits/physics-3d/engine3d/playTimings.js +50 -0
  327. package/kits/physics-3d/engine3d/playerRun.js +372 -0
  328. package/kits/physics-3d/engine3d/pxmodel.js +3 -3
  329. package/kits/physics-3d/engine3d/rapier.js +27 -0
  330. package/kits/physics-3d/engine3d/scatter.js +1 -11
  331. package/kits/physics-3d/engine3d/shadowfade.js +23 -15
  332. package/kits/physics-3d/engine3d/sky.js +1 -1
  333. package/kits/physics-3d/engine3d/squarefirst.js +177 -0
  334. package/kits/physics-3d/engine3d/stillshadows.js +399 -0
  335. package/kits/physics-3d/engine3d/sweep.js +1 -25
  336. package/kits/physics-3d/engine3d/world3d.js +468 -18
  337. package/kits/physics-3d/eslint.config.js +2 -1
  338. package/kits/physics-3d/main.jsx +6 -3
  339. package/kits/physics-3d/package-lock.json +7 -0
  340. package/kits/physics-3d/package.json +5 -1
  341. package/kits/physics-3d/play/behaviors/Body.js +31 -0
  342. package/kits/physics-3d/play/behaviors/Door.js +37 -0
  343. package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
  344. package/kits/physics-3d/play/behaviors/Model.js +23 -0
  345. package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
  346. package/kits/physics-3d/play/behaviors/Player.js +1204 -0
  347. package/kits/physics-3d/play/behaviors/Shape.js +47 -0
  348. package/kits/physics-3d/play/behaviors/Solid.js +16 -0
  349. package/kits/physics-3d/play/behaviors/Transform.js +29 -0
  350. package/kits/physics-3d/pnpm-lock.yaml +8 -0
  351. package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
  352. package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
  353. package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
  354. package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
  355. package/kits/physics-3d/scripts/test-camera-orbit.mjs +52 -4
  356. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  357. package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
  358. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +6 -3
  359. package/kits/physics-3d/scripts/test-frame-cap.mjs +1 -1
  360. package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
  361. package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
  362. package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
  363. package/kits/physics-3d/scripts/test-look-bake.mjs +1 -1
  364. package/kits/physics-3d/scripts/test-near-shadows.mjs +2 -2
  365. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +88 -7
  366. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +40 -3
  367. package/kits/physics-3d/scripts/test-orbit-shot.mjs +75 -1
  368. package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
  369. package/kits/physics-3d/scripts/test-sky.mjs +1 -1
  370. package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
  371. package/kits/physics-3d/scripts/test-static-actors.mjs +3 -1
  372. package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
  373. package/kits/physics-3d/scripts/test-static-scenery.mjs +5 -2
  374. package/kits/physics-3d/scripts/test-steady-hover.mjs +5 -2
  375. package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
  376. package/kits/physics-3d/systems/physics3d.js +37 -4
  377. package/kits/real-time/castle.json +2 -2
  378. package/kits/real-time/code/client/connection.js +33 -10
  379. package/kits/real-time/code/client/gameHooks.js +2 -0
  380. package/kits/real-time/code/client/joinOverlay.js +9 -4
  381. package/kits/real-time/code/server/session.js +6 -4
  382. package/kits/real-time/package-lock.json +1 -1
  383. package/package.json +2 -2
@@ -4,6 +4,7 @@
4
4
  // budget, who sees a reply, and following only what the world says.
5
5
 
6
6
  import assert from 'node:assert/strict';
7
+ import { npcDisplayText } from '../code/npcDisplayText.js';
7
8
  import { readFileSync } from 'node:fs';
8
9
  import { setLabel, wireLabel } from '../code/server/labels.js';
9
10
  import { firstJoinFor } from '../code/client/firstJoin.js';
@@ -34,7 +35,9 @@ function body(x, z) {
34
35
  // through the route on an older SDK (`session.world.characters` only),
35
36
  // 'layer' a layer of the place (`session.characters`, `session.world` null),
36
37
  // 'world' a world on an SDK with place characters (both, the same object).
37
- function world({ mind = true, turnsPerMinute = 6, turnsAtOnce, bodyTurnsAtOnce, inspect, notes = null, extra = [] } = {}) {
38
+ const bundleAsks = Object.fromEntries(JSON.parse(readFileSync(new URL('../../../experiments/hub-town/castle.json', import.meta.url), 'utf8')).characterBundle.characters.filter((c) => c.childAsks).map((c) => [c.id, c.childAsks]));
39
+
40
+ function world({ childAsks, greeterName = 'Rowan', firstVisit = false, mind = true, turnsPerMinute = 6, turnsAtOnce, bodyTurnsAtOnce, inspect, notes = null, extra = [] } = {}) {
38
41
  const sent = [];
39
42
  const labels = [];
40
43
  const lines = [];
@@ -42,11 +45,13 @@ function world({ mind = true, turnsPerMinute = 6, turnsAtOnce, bodyTurnsAtOnce,
42
45
  const heard = [];
43
46
  const sim = { timeMs: 0, players: new Map(), bodies: new Map([['greeter', body(0, 0)], ...extra.map((e) => [e.id, body(e.x, e.z)])]) };
44
47
  const h = {
48
+ ...(firstVisit ? { firstVisit: { live: ['npc'] } } : {}),
45
49
  sim,
50
+ ...(childAsks ? { characterBundle: { characters: [{ id: 'greeter', childAsks }] } } : {}),
46
51
  players: new Map(),
47
52
  ...Idle.newIdleState(),
48
53
  actors: [
49
- { id: 'greeter', components: { HubNpc: { name: 'Rowan', character: 'greeter', follow: 'greeterFollow', ...(bodyTurnsAtOnce !== undefined ? { turnsAtOnce: bodyTurnsAtOnce } : {}) }, Transform: { x: 0, y: 1, z: 0 } } },
54
+ { id: 'greeter', components: { HubNpc: { name: greeterName, character: 'greeter', follow: 'greeterFollow', ...(bodyTurnsAtOnce !== undefined ? { turnsAtOnce: bodyTurnsAtOnce } : {}) }, Transform: { x: 0, y: 1, z: 0 } } },
50
55
  ...extra.map((e) => ({ id: e.id, components: { HubNpc: { name: e.name, character: e.character }, Transform: { x: e.x, y: 1, z: e.z } } })),
51
56
  ],
52
57
  place: { npcs: mind ? { route: 'town', slot: 'main', turnsPerMinute, ...(turnsAtOnce !== undefined ? { turnsAtOnce } : {}), disclosure: 'participants', followSec: 120 } : null },
@@ -312,6 +317,46 @@ await test("a full place-mind queue is the place's busy line, a spent town-wide
312
317
  }
313
318
  });
314
319
 
320
+ const characterRefusal = () => Object.assign(new Error('characters are unavailable right now'), { code: 'CAULDRON_CHARACTER_UNAVAILABLE' });
321
+
322
+ await test("a turn ghost refused characters gets the kit's calm unavailable line, decided by that turn alone", async () => {
323
+ const w = world();
324
+ w.h.hooks.npcLine = (_hub, npc, playerId, info) => { w.lines.push({ npc: npc.id, playerId, ...info }); return null; };
325
+ w.at('a', 0, 2);
326
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
327
+ for (const [operationId, err, said] of [
328
+ ['op1', characterRefusal(), 'Rowan smiles and nods.'],
329
+ ['op2', Object.assign(new Error('refused'), { code: 'CAULDRON_UPSTREAM' }), "Rowan doesn't catch that. Try again in a moment."],
330
+ ]) {
331
+ const t = turn({ speaker: 'a', operationId });
332
+ t.send = async () => { throw err; };
333
+ await w.npcs.onTurn(t).catch(() => {});
334
+ assert.equal(w.lines.at(-1).why, 'unavailable', 'the hook still hears unavailable');
335
+ const sent = w.sent.findLast((m) => m.k === 'hub-npc-line');
336
+ assert.deepEqual([sent.text, sent.why, sent.op], [said, 'unavailable', operationId]);
337
+ }
338
+ });
339
+
340
+ await test('a refusal in flight across leave leaves nothing for the next speaker', async () => {
341
+ const w = world();
342
+ w.h.hooks.npcLine = () => null;
343
+ w.at('a', 0, 2);
344
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
345
+ let fail;
346
+ const t = turn({ speaker: 'a' });
347
+ t.send = () => new Promise((_resolve, reject) => { fail = reject; });
348
+ const sending = w.npcs.onTurn(t).catch(() => {});
349
+ await Promise.resolve();
350
+ w.npcs.leave('a');
351
+ fail(characterRefusal()); await sending;
352
+ w.at('a', 0, 2);
353
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
354
+ const next = turn({ speaker: 'a', operationId: 'op2' });
355
+ next.send = async () => { throw Object.assign(new Error('refused'), { code: 'CAULDRON_UPSTREAM' }); };
356
+ await w.npcs.onTurn(next).catch(() => {});
357
+ assert.equal(w.sent.findLast((m) => m.k === 'hub-npc-line').text, "Rowan doesn't catch that. Try again in a moment.");
358
+ });
359
+
315
360
  await test('a replayed admission keeps its first record', async () => {
316
361
  const w = world();
317
362
  w.at('a', 0, 2);
@@ -482,6 +527,40 @@ await test('a failed public read backs off and later sees the follow', async ()
482
527
  }
483
528
  });
484
529
 
530
+ await test('failing public reads back off to five minutes, warned once per run', async () => {
531
+ let fail = false;
532
+ const w = world({ inspect: () => (fail ? characterRefusal() : { gameplay: { objects: { greeterFollow: { holderId: 'p-a' } } } }) });
533
+ // A follow that outlasts the test keeps the poll going.
534
+ w.h.place.npcs.followSec = 10_000;
535
+ w.at('a', 0, 2);
536
+ await w.npcs.onRead({ speaker: { playerId: 'a' }, query: { type: 'inspect' }, read: async () => ({ participantId: 'p-a' }), reject() {} });
537
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
538
+ await w.npcs.onTurn(turn({ speaker: 'a' }));
539
+ await w.npcs.onRead(statusRead('a', 'op1', 'Sure!'));
540
+ w.tick();
541
+ await new Promise((resolve) => setImmediate(resolve));
542
+ assert.equal(w.npcs.handle('greeter').following, 'a', 'a follow keeps the poll going');
543
+ fail = true;
544
+ const warn = console.warn, warned = [];
545
+ console.warn = (...args) => warned.push(args.join(' '));
546
+ try {
547
+ const times = [];
548
+ for (let i = 0; i < 3000 && times.length < 12; i++) {
549
+ const before = w.reads.inspect;
550
+ w.tick(1000);
551
+ await new Promise((resolve) => setImmediate(resolve));
552
+ if (w.reads.inspect > before) times.push(w.sim.timeMs);
553
+ }
554
+ const gaps = times.slice(1).map((at, i) => at - times[i]);
555
+ assert(gaps.every((gap, i) => i === 0 || gap >= gaps[i - 1]), `gaps grow: ${gaps}`);
556
+ assert.equal(gaps.at(-1), gaps.at(-2), `the gap is capped: ${gaps}`);
557
+ assert(gaps.at(-1) >= 300_000 && gaps.at(-1) <= 301_000, `capped at five minutes: ${gaps}`);
558
+ assert.equal(warned.length, 1);
559
+ } finally {
560
+ console.warn = warn;
561
+ }
562
+ });
563
+
485
564
  for (const mind of ['layer', 'world']) {
486
565
  await test(`with place characters (${mind}), a mind answers from session.characters and its follow is read there`, async () => {
487
566
  const w = world({ mind, inspect: () => ({ gameplay: { objects: { greeterFollow: { holderId: 'p-a' } } } }) });
@@ -1833,7 +1912,7 @@ await test('v1.76: reserved greeting ids never deliver turns; real turn status s
1833
1912
  const real = turn({ speaker: 'a', operationId: 'af4dd2b6-40ee-4d43-99e9-9479d8e21856' });
1834
1913
  await w.npcs.onTurn(real);
1835
1914
  assert.equal(real.sent, 1);
1836
- await w.npcs.onRead(statusRead('a', real.operationId, 'Real reply.'));
1915
+ await w.npcs.onRead(statusRead('a', real.operationId, '“**Real** *reply*.”'));
1837
1916
  assert.deepEqual(w.labels, [{ id: 'greeter', text: 'Rowan: Real reply.', to: ['a'], about: 'a' }]);
1838
1917
  const disallowed = { ...greetingRead(), query: { type: 'greeting', characterId: 'greeter' }, rejected: null, reject(code) { this.rejected = code; } };
1839
1918
  await w.npcs.onRead(disallowed);
@@ -2029,8 +2108,10 @@ await test('v1.83: handle exposes effective capacity without changing the protoc
2029
2108
  async function talkRig(options, run) {
2030
2109
  const realSetTimeout = globalThis.setTimeout;
2031
2110
  const realClearTimeout = globalThis.clearTimeout;
2111
+ const realNow = Object.getOwnPropertyDescriptor(performance, 'now');
2032
2112
  const timers = new Map();
2033
2113
  let now = 0, timerId = 0;
2114
+ Object.defineProperty(performance, 'now', { configurable: true, value: () => now });
2034
2115
  globalThis.setTimeout = (fn, ms) => { timers.set(++timerId, { fn, at: now + ms }); return timerId; };
2035
2116
  globalThis.clearTimeout = (id) => timers.delete(id);
2036
2117
  const settle = async () => { for (let i = 0; i < 20; i++) await Promise.resolve(); };
@@ -2042,8 +2123,21 @@ async function talkRig(options, run) {
2042
2123
  await settle();
2043
2124
  };
2044
2125
  clearClientHub();
2045
- const w = world({ turnsAtOnce: options.slots, notes: options.noNotes ? null : () => 'fresh place notes' });
2126
+ const w = world({ mind: options.mind ?? true, childAsks: options.childAsks, ...(options.name ? { greeterName: options.name } : {}), turnsAtOnce: options.slots, notes: options.noNotes ? null : () => 'fresh place notes' });
2046
2127
  w.at('p1', 0, 2);
2128
+ if (options.child) {
2129
+ w.h.place.under13Choices = true;
2130
+ w.h.session.players = [{ playerId: 'p1', userId: '101', under13: true }];
2131
+ }
2132
+ if (options.kid) {
2133
+ w.h.session.players = [{ playerId: 'p1', userId: '101', under13: true }];
2134
+ }
2135
+ if (options.guest) {
2136
+ w.h.session.players = [{ playerId: 'p1', userId: '101', isAnonymous: true }];
2137
+ }
2138
+ if (options.opening) {
2139
+ w.h.hooks.npcOpening = () => options.opening;
2140
+ }
2047
2141
  const npc = options.companion ? 'companion:p1' : 'greeter';
2048
2142
  const character = options.companion ? 'companion' : 'greeter';
2049
2143
  if (options.companion) {
@@ -2055,13 +2149,18 @@ async function talkRig(options, run) {
2055
2149
  let handlers, cursor = 0, queue = [], closed = 0, opened = 0, draft = '', forceNotTalking = false;
2056
2150
  let held = [], recoveryRefusal = null, releaseRefusal;
2057
2151
  let turnRefusals = [];
2152
+ let holdInspects = Boolean(options.holdInspects), holdTurns = false;
2153
+ const heldInspects = [], heldTurns = [];
2154
+ const reads = {}, inspectFailures = [...(options.inspectFailures ?? [])], statusFailures = [...(options.statusFailures ?? [])];
2058
2155
  const lines = [], wire = [], requests = [], admitted = [];
2156
+ let typing = null, offered = [], choose = null, hint = null, waiting = false;
2059
2157
  const chrome = {
2060
2158
  onTalk(value) { handlers = value; },
2061
- openTalk() { opened++; lines.length = 0; draft = ''; },
2062
- closeTalk() { closed++; }, talkPrompt() {}, talkAsks() {}, talkWaiting() {}, talkTyping() {},
2159
+ openTalk(_name, opts) { opened++; lines.length = 0; draft = ''; typing = opts.canType; },
2160
+ closeTalk() { closed++; }, talkPrompt() {}, talkAsks(asks, fn) { offered = asks; choose = fn; }, talkWaiting(value) { waiting = value; }, talkTyping(value) { typing = value; },
2063
2161
  talkFocused: () => false, talkLine: (who, text) => lines.push([who, text]),
2064
2162
  talkDraft(text) { if (text !== undefined) draft = text; return draft; },
2163
+ talkHint(text) { hint = text; },
2065
2164
  };
2066
2165
  const net = {
2067
2166
  selfId: () => 'p1', drain: () => { const messages = queue; queue = []; return messages; },
@@ -2069,6 +2168,7 @@ async function talkRig(options, run) {
2069
2168
  characters: {
2070
2169
  async requestCharacterTurn(request) {
2071
2170
  requests.push(request);
2171
+ if (holdTurns) return new Promise((_resolve, reject) => heldTurns.push(reject));
2072
2172
  if (forceNotTalking) throw { code: 'HUB_NPC_NOT_TALKING' };
2073
2173
  if (turnRefusals.length) throw { code: turnRefusals.shift() };
2074
2174
  const event = turn({ speaker: 'p1', ...request, audience: request.audience.playerIds, disclosure: request.audience.disclosure });
@@ -2086,10 +2186,20 @@ async function talkRig(options, run) {
2086
2186
  admitted.push(event);
2087
2187
  },
2088
2188
  async readCharacters({ query }) {
2089
- if (query.type === 'inspect') return {};
2090
- const event = statusRead('p1', query.operationId, 'private mind reply');
2189
+ reads[query.type] = (reads[query.type] ?? 0) + 1;
2190
+ if (query.type === 'inspect') {
2191
+ if (holdInspects) return new Promise((resolve, reject) => heldInspects.push({ resolve, reject }));
2192
+ const failure = inspectFailures.shift();
2193
+ if (failure) throw failure;
2194
+ return {};
2195
+ }
2196
+ const failure = statusFailures.shift();
2197
+ if (failure) throw failure;
2198
+ const status = options.status ?? 'completed';
2199
+ const response = options.reply ?? '**private** *mind* reply';
2200
+ const event = statusRead('p1', query.operationId, response, status);
2091
2201
  await w.npcs.onRead(event);
2092
- return { status: 'completed', response: 'private mind reply' };
2202
+ return { status, response, ...(options.suggestions ? { suggestions: options.suggestions } : {}) };
2093
2203
  },
2094
2204
  },
2095
2205
  };
@@ -2118,14 +2228,17 @@ async function talkRig(options, run) {
2118
2228
  talk.resume();
2119
2229
  };
2120
2230
  await run({ w, npc, talk, handlers, frame, settle, advance, drop, reconnect, net, lines, wire, requests, admitted,
2231
+ typing: () => typing, waiting: () => waiting, offered: () => offered, hint: () => hint, choose: (text) => choose(text),
2121
2232
  opened: () => opened, closed: () => closed, draft: () => draft, setDraft: (text) => { draft = text; }, forceNotTalking: () => { forceNotTalking = true; },
2122
2233
  skipMessages: () => { held = []; cursor = w.sent.length; },
2123
- refuseTurns: (...codes) => { turnRefusals = codes; },
2234
+ refuseTurns: (...codes) => { turnRefusals = codes; }, reads,
2235
+ heldInspects, heldTurns, holdInspects: (on) => { holdInspects = on; }, holdTurns: (on) => { holdTurns = on; },
2124
2236
  deferRecoveryRefusal: (code) => { recoveryRefusal = code; }, releaseRefusal: () => releaseRefusal() });
2125
2237
  } finally {
2126
2238
  talk.reset(); clearClientHub();
2127
2239
  globalThis.setTimeout = realSetTimeout;
2128
2240
  globalThis.clearTimeout = realClearTimeout;
2241
+ if (realNow) {Object.defineProperty(performance, 'now', realNow);} else {delete performance.now;}
2129
2242
  }
2130
2243
  }
2131
2244
 
@@ -2151,6 +2264,387 @@ for (const options of [{ slots: 1 }, { slots: 3 }, { companion: true }]) {
2151
2264
  }));
2152
2265
  }
2153
2266
 
2267
+ // Console lines the panel logs while `run` runs.
2268
+ async function withLogs(run) {
2269
+ const log = console.log, logs = [];
2270
+ console.log = (...args) => logs.push(args.join(' '));
2271
+ try {
2272
+ await run(logs);
2273
+ } finally {
2274
+ console.log = log;
2275
+ }
2276
+ }
2277
+ const npcLogs = (logs) => logs.filter((line) => line.startsWith('[hub] NPC'));
2278
+
2279
+ await test('a failed inspect backs off, offers nothing to type meanwhile, and logs once per code', () => withLogs((logs) => talkRig({ inspectFailures: [characterRefusal(), characterRefusal(), characterRefusal()] }, async (r) => {
2280
+ const reopen = async () => { r.handlers.end(); r.net.send({ k: 'hub-npc-open', npc: r.npc }); r.frame(); await r.settle(); };
2281
+ assert.equal(r.reads.inspect, 1);
2282
+ assert.equal(r.typing(), false);
2283
+ assert.deepEqual(r.offered(), []);
2284
+ assert(r.lines.some(([who]) => who === 'them'), 'the opening stays');
2285
+ await reopen();
2286
+ assert.equal(r.reads.inspect, 1, 'held back');
2287
+ await r.advance(5000); await reopen();
2288
+ assert.equal(r.reads.inspect, 2);
2289
+ await r.advance(5000); await reopen();
2290
+ assert.equal(r.reads.inspect, 2, 'the second failure doubles the wait');
2291
+ await r.advance(5000); await reopen();
2292
+ assert.equal(r.reads.inspect, 3);
2293
+ await r.advance(20_000); await reopen();
2294
+ assert.equal(r.reads.inspect, 4);
2295
+ assert.equal(r.typing(), true, 'a successful inspect lets the player type');
2296
+ await r.advance(300_000);
2297
+ assert.deepEqual(npcLogs(logs), ['[hub] NPC inspect failed: CAULDRON_CHARACTER_UNAVAILABLE']);
2298
+ })));
2299
+
2300
+ await test('a replacement session reads afresh: no backoff, permission or logs carried over', () => withLogs((logs) => talkRig({ inspectFailures: [characterRefusal(), undefined, characterRefusal()] }, async (r) => {
2301
+ assert.equal(r.reads.inspect, 1);
2302
+ r.talk.reset();
2303
+ r.net.send({ k: 'hub-npc-open', npc: r.npc }); r.frame(); await r.settle();
2304
+ assert.equal(r.reads.inspect, 2, 'the new session is not held back');
2305
+ assert.equal(r.typing(), true);
2306
+ r.talk.reset();
2307
+ r.net.send({ k: 'hub-npc-open', npc: r.npc }); r.frame(); await r.settle();
2308
+ assert.equal(r.reads.inspect, 3, 'nor does it inherit the old permission to type');
2309
+ assert.equal(r.typing(), false);
2310
+ assert.equal(npcLogs(logs).length, 2, 'each session logs its own');
2311
+ })));
2312
+
2313
+ // A guest (their own account is anonymous) is over 13 like any other player:
2314
+ // a refusal shows them the opening alone, with no line of their own, as it
2315
+ // does a signed-in player; a later inspect lets them type.
2316
+ for (const [what, options] of [['a guest', { guest: true }], ['a signed-in player', {}]]) {
2317
+ await test(`${what} refused a mind sees only the opening, no sign-in line; a later inspect lets them type`, () => withLogs(() => talkRig({ ...options, name: 'Rowan, the baker', inspectFailures: [characterRefusal()] }, async (r) => {
2318
+ const reopen = async () => { r.handlers.end(); r.net.send({ k: 'hub-npc-open', npc: r.npc }); r.frame(); await r.settle(); };
2319
+ assert.equal(r.reads.inspect, 1);
2320
+ assert.equal(r.typing(), false);
2321
+ r.frame();
2322
+ assert.equal(r.hint() ?? null, null, 'no line under the opening');
2323
+ assert(r.lines.some(([who]) => who === 'them'), 'the opening stays');
2324
+ await r.advance(5000); await reopen();
2325
+ assert.equal(r.typing(), true);
2326
+ assert.equal(r.hint() ?? null, null);
2327
+ })));
2328
+ }
2329
+
2330
+ // The server tells only an under-13 speaker (trusted identity) that a mind's
2331
+ // typing is off for them by age; the client never infers it.
2332
+ await test('a mind\'s open carries ageOff only to its under-13 speaker, by the trusted stamp, in any place', () => {
2333
+ for (const [what, mind, stamp, expected] of [['under 13', true, true, true], ['over 13', true, false, false], ['no stamp', true, undefined, false], ['no mind', false, true, false]]) {
2334
+ for (const choices of [false, true]) {
2335
+ const w = world({ mind });
2336
+ if (choices) w.h.place.under13Choices = true;
2337
+ w.h.session.players = [{ playerId: 'a', userId: '101', ...(stamp === undefined ? {} : { under13: stamp }) }, { playerId: 'b', userId: '102' }];
2338
+ w.at('a', 0, 2);
2339
+ w.at('b', 0, -2);
2340
+ // What a client says of itself counts for nothing.
2341
+ w.npcs.message({ playerId: 'a', under13: !stamp }, { k: 'hub-npc-open', npc: 'greeter' });
2342
+ const opened = w.sent.find((m) => m.k === 'hub-npc' && m.open);
2343
+ assert.equal(opened.playerId, 'a');
2344
+ assert.equal(Object.hasOwn(opened, 'ageOff'), expected, `${what}, choices ${choices}`);
2345
+ if (expected) assert.equal(opened.ageOff, true);
2346
+ assert.ok(w.sent.filter((m) => m.playerId !== 'a').every((m) => !Object.hasOwn(m, 'ageOff')), 'never to anyone else');
2347
+ }
2348
+ }
2349
+ });
2350
+
2351
+ await test('an under-13 speaker on a talkLog place opens a mind without chips and archives nothing', async () => {
2352
+ for (const kid of [true, false]) {
2353
+ const w = world();
2354
+ w.h.place.talkLog = true;
2355
+ const archived = [];
2356
+ w.h.session.hub = { archiveText: async (...args) => { archived.push(args); if (kid) throw new Error('refused'); } };
2357
+ w.h.session.players = [{ playerId: 'a', userId: '101', under13: kid }];
2358
+ w.at('a', 0, 2);
2359
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
2360
+ await new Promise((resolve) => setTimeout(resolve, 0));
2361
+ await new Promise((resolve) => setTimeout(resolve, 0));
2362
+ assert.ok(w.sent.find((m) => m.k === 'hub-npc' && m.open), `opened, kid ${kid}`);
2363
+ assert.ok(w.sent.every((m) => !(m.k === 'hub-npc' && m.open === false)), `not closed, kid ${kid}`);
2364
+ assert.equal(archived.length > 0, !kid, `archive attempted only for over 13, kid ${kid}`);
2365
+ if (kid) {
2366
+ const t = turn({ speaker: 'a', input: 'hello' });
2367
+ await w.npcs.onTurn(t);
2368
+ assert.ok(!t.sendArgs?.some((args) => args.some((a) => a?.hubTextArchive)), 'no archive metadata');
2369
+ }
2370
+ }
2371
+ });
2372
+
2373
+ const AGE_TALK = 'Talking with Rowan is for players 13 and up';
2374
+
2375
+ const WELCOME = { text: 'Welcome to town! Shall I show you around?', asks: ['Show me around', "I'll look myself"], more: [], authored: true };
2376
+ await test('v1.148: an under-13 speaker taps a place\'s authored asks, answered by the place and never a mind turn', () => withLogs(() => talkRig({ kid: true, opening: WELCOME, inspectFailures: [characterRefusal()] }, async (r) => {
2377
+ r.frame();
2378
+ assert.deepEqual(r.offered(), WELCOME.asks);
2379
+ assert.equal(r.typing(), false);
2380
+ assert.equal(r.hint() ?? null, null, 'choices, not the 13+ line');
2381
+ const open = r.w.sent.find((m) => m.k === 'hub-npc' && m.open);
2382
+ assert.equal(open.authoredChoices, true);
2383
+ assert.equal(open.ageOff, true);
2384
+ r.choose('Show me around'); r.frame(); await r.settle();
2385
+ assert.equal(r.requests.length, 0, 'no mind turn');
2386
+ assert.ok(r.wire.some((m) => m.k === 'hub-npc-say' && m.text === 'Show me around'));
2387
+ assert.ok(r.w.lines.some((l) => l.why === 'authored' && l.text === 'Show me around'), 'the place heard the tap');
2388
+ assert.ok(r.lines.some(([who, text]) => who === 'them' && text === 'line:authored'), 'the place answered');
2389
+ assert.deepEqual(r.offered(), [], 'the choice is made; the next open brings the next ones');
2390
+ })));
2391
+
2392
+ await test('v1.148: authored taps lead bundle chips; an adult and a plain opening are unchanged', async () => {
2393
+ await withLogs(() => talkRig({ kid: true, opening: WELCOME, childAsks: [{ id: 'hi', label: 'Hi!', prompt: 'Say hi.' }], inspectFailures: [characterRefusal()] }, async (r) => {
2394
+ r.frame();
2395
+ assert.deepEqual(r.offered(), WELCOME.asks);
2396
+ r.choose("I'll look myself"); r.frame(); await r.settle();
2397
+ assert.ok(r.w.lines.some((l) => l.why === 'authored' && l.text === "I'll look myself"), 'the place hears it despite bundle chips');
2398
+ assert.ok(r.lines.some(([who, text]) => who === 'them' && text === 'line:authored'), 'and its answer arrives');
2399
+ assert.equal(r.requests.length, 0);
2400
+ }));
2401
+ await withLogs(() => talkRig({ opening: WELCOME }, async (r) => {
2402
+ r.frame();
2403
+ const open = r.w.sent.find((m) => m.k === 'hub-npc' && m.open);
2404
+ assert.equal(open.choices, undefined);
2405
+ assert.equal(open.authoredChoices, undefined);
2406
+ assert.equal(r.typing(), true);
2407
+ }));
2408
+ const { authored: _authored, ...plain } = WELCOME;
2409
+ await withLogs(() => talkRig({ kid: true, opening: plain, inspectFailures: [characterRefusal()] }, async (r) => {
2410
+ r.frame();
2411
+ assert.deepEqual(r.offered(), []);
2412
+ assert.equal(r.hint(), AGE_TALK);
2413
+ }));
2414
+ });
2415
+
2416
+ await test('v1.148: a tap queued across a reattach stays authored, and is dropped if the new open no longer offers it', () => withLogs(async () => {
2417
+ let offer = WELCOME;
2418
+ const { authored: _authored, ...plain } = WELCOME;
2419
+ await talkRig({ kid: true, opening: WELCOME, inspectFailures: [characterRefusal(), characterRefusal()] }, async (r) => {
2420
+ r.w.h.hooks.npcOpening = () => offer;
2421
+ r.frame();
2422
+ assert.deepEqual(r.offered(), WELCOME.asks);
2423
+ r.drop();
2424
+ offer = plain;
2425
+ r.reconnect();
2426
+ r.handlers.send('Show me around');
2427
+ r.frame(); await r.settle(); r.frame(); await r.settle();
2428
+ assert.equal(r.requests.length, 0, 'never a mind turn');
2429
+ assert.ok(!r.wire.some((m) => m.k === 'hub-npc-say'), 'not offered any more, so not sent');
2430
+ assert.equal(r.waiting(), false);
2431
+ });
2432
+ }));
2433
+
2434
+ await test('v1.148: a mind with authored taps hears only those taps, and refuses its speaker\'s mind turns', async () => {
2435
+ const w = world();
2436
+ w.h.hooks.npcOpening = () => WELCOME;
2437
+ w.h.session.players = [{ playerId: 'a', userId: '101', under13: true }];
2438
+ w.at('a', 0, 2);
2439
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
2440
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-say', npc: 'greeter', text: 'tell me a secret', rid: 'r1' });
2441
+ assert.equal(w.lines.filter((l) => l.why === 'authored').length, 0, 'free text is dropped');
2442
+ const t = turn({ speaker: 'a', input: 'Show me around' });
2443
+ await w.npcs.onTurn(t);
2444
+ assert.equal(t.rejected, 'HUB_NPC_CHOICE_REQUIRED');
2445
+ w.tick(5000);
2446
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-say', npc: 'greeter', text: " I'll look myself ", rid: 'r2' });
2447
+ assert.deepEqual(w.lines.filter((l) => l.why === 'authored').map((l) => l.text), ["I'll look myself"]);
2448
+ });
2449
+
2450
+ const LEGACY_CHILD_ASKS = ['What can I do here?', 'Tell me about yourself.', 'Where should I go next?'];
2451
+
2452
+ await test('v1.150: under13Choices authored taps lead bundle and legacy choices, without a mind turn', async () => {
2453
+ for (const childAsks of [undefined, bundleAsks.greeter]) {
2454
+ const w = world({ childAsks });
2455
+ w.h.place.under13Choices = true;
2456
+ w.h.hooks.npcOpening = () => WELCOME;
2457
+ w.h.session.players = [{ playerId: 'a', userId: '101', under13: true }];
2458
+ w.at('a', 0, 2);
2459
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
2460
+ const opened = w.sent.find((m) => m.k === 'hub-npc' && m.open);
2461
+ assert.equal(opened.authoredChoices, true);
2462
+ assert.deepEqual(opened.choices, WELCOME.asks);
2463
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-say', npc: 'greeter', text: ` ${WELCOME.asks[0]} `, rid: 'v150-tap' });
2464
+ assert.deepEqual(w.lines.filter((l) => l.why === 'authored').map((l) => l.text), [WELCOME.asks[0]]);
2465
+ assert.deepEqual(w.sent.filter((m) => m.k === 'hub-npc-line' && m.why === 'authored').map(({ text, rid }) => ({ text, rid })), [{ text: 'line:authored', rid: 'v150-tap' }]);
2466
+ // Even a legacy allowed string must not bypass the earlier taps guard.
2467
+ for (const input of [WELCOME.asks[0], LEGACY_CHILD_ASKS[0]]) {
2468
+ const t = turn({ speaker: 'a', input });
2469
+ await w.npcs.onTurn(t);
2470
+ assert.equal(t.rejected, 'HUB_NPC_CHOICE_REQUIRED');
2471
+ assert.equal(t.sent, 0, 'no character turn');
2472
+ }
2473
+ w.tick(5000);
2474
+ const before = [w.lines.length, w.sent.length];
2475
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-say', npc: 'greeter', text: LEGACY_CHILD_ASKS[0], rid: 'v150-legacy' });
2476
+ assert.deepEqual([w.lines.length, w.sent.length], before, 'legacy say is ignored, with no hook or reply');
2477
+ }
2478
+ await withLogs(() => talkRig({ child: true, opening: WELCOME, childAsks: bundleAsks.greeter, inspectFailures: [characterRefusal()] }, async (r) => {
2479
+ r.frame();
2480
+ assert.deepEqual(r.offered(), WELCOME.asks);
2481
+ assert.equal(r.typing(), false, 'authored chips do not need a text box');
2482
+ r.choose(WELCOME.asks[0]); r.frame(); await r.settle();
2483
+ assert.equal(r.requests.length, 0, 'client sends no character turn');
2484
+ assert.ok(r.lines.some(([who, text]) => who === 'them' && text === 'line:authored'));
2485
+ }));
2486
+ });
2487
+
2488
+ await test('v1.150: under13Choices mind-less NPC keeps only the three legacy choices', async () => {
2489
+ const w = world({ mind: false });
2490
+ w.h.place.under13Choices = true;
2491
+ w.h.hooks.npcOpening = () => WELCOME;
2492
+ w.h.session.players = [{ playerId: 'a', userId: '101', under13: true }];
2493
+ w.at('a', 0, 2);
2494
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
2495
+ const opened = w.sent.find((m) => m.k === 'hub-npc' && m.open);
2496
+ assert.equal(opened.mind, false);
2497
+ assert.equal(opened.character, null);
2498
+ assert.deepEqual(opened.choices, LEGACY_CHILD_ASKS);
2499
+ assert.equal(Object.hasOwn(opened, 'authoredChoices'), false);
2500
+ const before = [w.lines.length, w.sent.length];
2501
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-say', npc: 'greeter', text: 'arbitrary words', rid: 'v150-free' });
2502
+ assert.deepEqual([w.lines.length, w.sent.length], before, 'arbitrary say is ignored, with no hook or reply');
2503
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-say', npc: 'greeter', text: LEGACY_CHILD_ASKS[0], rid: 'v150-child' });
2504
+ assert.deepEqual(w.lines.filter((l) => l.why === 'authored').map((l) => l.text), [LEGACY_CHILD_ASKS[0]]);
2505
+ assert.ok(w.sent.some((m) => m.k === 'hub-npc-line' && m.why === 'authored' && m.rid === 'v150-child'));
2506
+ await talkRig({ child: true, mind: false, opening: WELCOME }, async (r) => {
2507
+ r.frame();
2508
+ assert.deepEqual(r.offered(), LEGACY_CHILD_ASKS);
2509
+ assert.equal(r.typing(), false, 'legacy choices hide the text box');
2510
+ });
2511
+ });
2512
+
2513
+ await test('v1.150: under13Choices minds without authored asks keep bundle or legacy choices', () => {
2514
+ for (const childAsks of [undefined, bundleAsks.greeter]) {
2515
+ const w = world({ childAsks });
2516
+ w.h.place.under13Choices = true;
2517
+ w.h.hooks.npcOpening = () => ({ ...WELCOME, authored: false });
2518
+ w.h.session.players = [{ playerId: 'a', userId: '101', under13: true }];
2519
+ w.at('a', 0, 2);
2520
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
2521
+ const opened = w.sent.find((m) => m.k === 'hub-npc' && m.open);
2522
+ assert.deepEqual(opened.choices, childAsks ? childAsks.map(({ id, label }) => ({ id, label })) : LEGACY_CHILD_ASKS);
2523
+ assert.equal(Object.hasOwn(opened, 'authoredChoices'), false);
2524
+ }
2525
+ });
2526
+
2527
+ await test('v1.150: under13Choices adult and unstamped mind opens and turns are unchanged', async () => {
2528
+ for (const stamp of [false, undefined]) {
2529
+ const exercise = async (choices) => {
2530
+ const w = world({ childAsks: bundleAsks.greeter });
2531
+ if (choices) w.h.place.under13Choices = true;
2532
+ w.h.hooks.npcOpening = () => WELCOME;
2533
+ w.h.session.players = [{ playerId: 'a', userId: '101', ...(stamp === undefined ? {} : { under13: stamp }) }];
2534
+ w.at('a', 0, 2);
2535
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
2536
+ const opened = w.sent.find((m) => m.k === 'hub-npc' && m.open);
2537
+ assert.equal(Object.hasOwn(opened, 'choices'), false);
2538
+ assert.equal(Object.hasOwn(opened, 'authoredChoices'), false);
2539
+ const t = turn({ speaker: 'a', input: 'hello' });
2540
+ await w.npcs.onTurn(t);
2541
+ assert.equal(t.sent, 1);
2542
+ return { sent: w.sent, lines: w.lines, sendArgs: t.sendArgs };
2543
+ };
2544
+ assert.deepEqual(await exercise(true), await exercise(false), 'same wire bytes and mind turn');
2545
+ }
2546
+ });
2547
+
2548
+ await test('an under-13 speaker refused a mind reads "Talking with <name> is for players 13 and up"; a later inspect clears it', () => withLogs(() => talkRig({ kid: true, name: 'Rowan, the baker', inspectFailures: [characterRefusal()] }, async (r) => {
2549
+ const reopen = async () => { r.handlers.end(); r.net.send({ k: 'hub-npc-open', npc: r.npc }); r.frame(); await r.settle(); };
2550
+ assert.equal(r.typing(), false);
2551
+ assert.equal(r.hint(), AGE_TALK);
2552
+ r.frame();
2553
+ assert.equal(r.hint(), AGE_TALK);
2554
+ await r.advance(5000); await reopen();
2555
+ assert.equal(r.typing(), true);
2556
+ assert.equal(r.hint(), null);
2557
+ })));
2558
+
2559
+ await test('the under-13 line waits for the inspect: none while it is out, shown when it is refused', () => withLogs(() => talkRig({ kid: true, holdInspects: true }, async (r) => {
2560
+ r.frame();
2561
+ assert.equal(r.hint() ?? null, null, 'not while the inspect is out');
2562
+ r.heldInspects.shift().reject(characterRefusal()); await r.settle();
2563
+ assert.equal(r.hint(), AGE_TALK);
2564
+ })));
2565
+
2566
+ await test('v1.101 places: a refused child sees the opening only -- no chips, no field, no line', () => withLogs(() => talkRig({ child: true, inspectFailures: [characterRefusal()] }, async (r) => {
2567
+ assert.equal(r.typing(), false);
2568
+ assert.deepEqual(r.offered(), []);
2569
+ r.frame();
2570
+ assert.equal(r.hint() ?? null, null);
2571
+ assert(r.lines.some(([who]) => who === 'them'), 'the opening stays');
2572
+ })));
2573
+
2574
+ await test('a body without a mind never shows the under-13 line', () => {
2575
+ clearClientHub();
2576
+ let hint = 'unset';
2577
+ const chrome = {
2578
+ onTalk() {}, openTalk() {}, closeTalk() {}, talkPrompt() {}, talkAsks() {}, talkWaiting() {}, talkTyping() {}, talkLine() {},
2579
+ talkFocused: () => false, talkHint(text) { hint = text; },
2580
+ };
2581
+ const net = { selfId: () => 'p1', send() {}, characters: { readCharacters: async () => { throw characterRefusal(); } } };
2582
+ const mp = { net, joined: true };
2583
+ const scene = { multiplayer: mp, actorWith: () => null, getActors: () => [] };
2584
+ const talk = makeTalk(chrome);
2585
+ try {
2586
+ talk.frame(scene, mp, false);
2587
+ clientHub.npcEvents.push({ k: 'hub-npc', npc: 'baker', open: true, name: 'Rowan, the baker', mind: false, ageOff: true, opening: { text: 'Fresh bread!' } });
2588
+ talk.frame(scene, mp, false);
2589
+ assert.equal(hint, null);
2590
+ } finally {
2591
+ talk.reset(); clearClientHub();
2592
+ }
2593
+ });
2594
+
2595
+ for (const outcome of ['hangs', 'succeeds', 'fails']) {
2596
+ await test(`an inspect in flight across reset ${outcome}: the new session reads for itself and may type`, () => withLogs((logs) => talkRig({ holdInspects: true }, async (r) => {
2597
+ assert.equal(r.heldInspects.length, 1);
2598
+ const old = r.heldInspects.shift();
2599
+ r.talk.reset();
2600
+ r.holdInspects(false);
2601
+ r.net.send({ k: 'hub-npc-open', npc: r.npc }); r.frame(); await r.settle();
2602
+ assert.equal(r.reads.inspect, 2, 'the old read does not block the new one');
2603
+ assert.equal(r.typing(), true);
2604
+ if (outcome === 'succeeds') old.resolve({});
2605
+ if (outcome === 'fails') old.reject(characterRefusal());
2606
+ await r.settle();
2607
+ assert.equal(r.typing(), true);
2608
+ r.handlers.end(); r.net.send({ k: 'hub-npc-open', npc: r.npc }); r.frame(); await r.settle();
2609
+ assert.equal(r.reads.inspect, 2, 'the new success is remembered; an old failure arms no backoff');
2610
+ assert.equal(r.typing(), true);
2611
+ assert.deepEqual(npcLogs(logs), []);
2612
+ })));
2613
+ }
2614
+
2615
+ await test('a turn refused after reset logs nothing into the new session', () => withLogs((logs) => talkRig({}, async (r) => {
2616
+ r.holdTurns(true);
2617
+ r.handlers.send('before reset'); await r.settle();
2618
+ assert.equal(r.heldTurns.length, 1);
2619
+ const old = r.heldTurns.shift();
2620
+ r.talk.reset();
2621
+ old({ code: 'HUB_NPC_BUDGET' }); await r.settle();
2622
+ assert.deepEqual(npcLogs(logs), []);
2623
+ r.net.send({ k: 'hub-npc-open', npc: r.npc }); r.frame(); await r.settle();
2624
+ r.handlers.send('after reset'); await r.settle();
2625
+ r.heldTurns.shift()({ code: 'HUB_NPC_BUDGET' }); await r.settle();
2626
+ assert.deepEqual(npcLogs(logs), ['[hub] NPC turn refused: HUB_NPC_BUDGET'], "the new session's first refusal is logged");
2627
+ })));
2628
+
2629
+ await test("a failing status read gives up that turn's poll; a transient one keeps polling", async () => {
2630
+ await withLogs((logs) => talkRig({ statusFailures: [characterRefusal(), characterRefusal()] }, async (r) => {
2631
+ r.handlers.send('a question'); await r.settle();
2632
+ assert.equal(r.admitted.length, 1);
2633
+ for (let i = 0; i < 10; i++) await r.advance(1200);
2634
+ assert.equal(r.reads.status, 2, 'two failures end the poll');
2635
+ assert.equal(r.talk.talking(), true);
2636
+ r.handlers.send('another question'); await r.settle();
2637
+ assert.equal(r.requests.length, 2, 'the panel takes words again');
2638
+ assert.deepEqual(npcLogs(logs).filter((line) => line.includes('status')), ['[hub] NPC status read failed: CAULDRON_CHARACTER_UNAVAILABLE']);
2639
+ }));
2640
+ await withLogs(() => talkRig({ statusFailures: [new Error('socket hiccup')] }, async (r) => {
2641
+ r.handlers.send('a question'); await r.settle();
2642
+ await r.advance(1200); await r.advance(1200);
2643
+ assert.equal(r.reads.status, 2, 'a single failure is read again');
2644
+ assert(r.lines.some(([who, text]) => who === 'them' && text === 'private mind reply'));
2645
+ }));
2646
+ });
2647
+
2154
2648
  await test('NOT_TALKING fallback re-attaches and retries exactly once', () => talkRig({ slots: 1 }, async (r) => {
2155
2649
  r.drop(); r.w.at('p1', 0, 2);
2156
2650
  r.handlers.send('private fallback'); await r.settle();
@@ -2428,3 +2922,416 @@ await test('movement hold gates queued steps, commands and asynchronous token fo
2428
2922
  w.npcs.replayPreferred('a', true);
2429
2923
  assert.equal(w.sent.length, 4, 'departure forgets preference');
2430
2924
  }
2925
+
2926
+ {
2927
+ const { pongJoin } = await import('../code/client/firstJoin.js');
2928
+ for (const join of [undefined, { mode: 'public' }, { mode: 'named', key: 'room' }, { mode: 'hub', handoff: { nonce: 'handoff' } }]) {
2929
+ for (const ms of [undefined, 0, -1, '45000', Infinity]) assert.equal(pongJoin(join, ms), join);
2930
+ const withDeadline = pongJoin(join, 45000);
2931
+ assert.deepEqual(withDeadline, { ...(join ?? { mode: 'public' }), pongTimeoutMs: 45000 });
2932
+ if (join?.handoff) assert.equal(withDeadline.handoff, join.handoff);
2933
+ }
2934
+ assert.deepEqual(firstJoinFor({ hub: { pongTimeoutMs: 45000 } }, { placeCharacters: true }), { mode: 'public', pongTimeoutMs: 45000 });
2935
+ const legacy = firstJoinFor({ hub: { pongTimeoutMs: 45000, npcs: { route: 'town' } } }, {});
2936
+ assert.deepEqual(legacy.fallback, { mode: 'public', pongTimeoutMs: 45000 });
2937
+ assert.deepEqual(legacy.destination, { routeId: 'town', slot: 'main' });
2938
+ console.log('hub-game pong joins: keyless identity, public, named, handoff and legacy fallback passed');
2939
+ }
2940
+
2941
+ await test('v1.142: bundle chips open in every place without deck text, notes, tools or archives', async () => {
2942
+ for (const legacy of [undefined, false, true]) for (const count of [3, 4]) {
2943
+ const asks = bundleAsks.greeter.slice(0, count);
2944
+ const called = [];
2945
+ const w = world({ childAsks: asks, greeterName: 'Rowan, the greeter', notes: () => { called.push('notes'); return 'Deck notes'; } });
2946
+ w.h.place.under13Choices = legacy;
2947
+ w.h.place.talkLog = true;
2948
+ w.h.hooks.npcOpening = () => { called.push('opening'); return 'Deck opening'; };
2949
+ w.h.hooks.npcTools = () => { called.push('tools'); return []; };
2950
+ const archived = [];
2951
+ w.h.session.hub = { archiveText: async (...args) => archived.push(args) };
2952
+ w.h.session.players = [{ playerId: 'a', userId: '101', under13: true }];
2953
+ w.at('a', 0, 2);
2954
+ w.npcs.message({ playerId: 'a', under13: false }, { k: 'hub-npc-open', npc: 'greeter' });
2955
+ const opened = w.sent.find((m) => m.open);
2956
+ assert.deepEqual(opened.choices, asks.map(({ id, label }) => ({ id, label })));
2957
+ assert.deepEqual(opened.opening, { text: 'Tap a question to talk with Rowan.' });
2958
+ assert(w.sent.every((m) => m.k !== 'hub-npc-notes'));
2959
+ const good = turn({ speaker: 'a', input: 'choice:hi' });
2960
+ await w.npcs.onTurn(good);
2961
+ assert.equal(good.sent, 1);
2962
+ assert.deepEqual(good.sendArgs, [[]], 'no archive metadata or place tools');
2963
+ const replay = turn({ speaker: 'a', input: 'choice:hi' });
2964
+ await w.npcs.onTurn(replay);
2965
+ assert.equal(replay.sent, 1);
2966
+ const busy = turn({ speaker: 'a', input: 'choice:hi', operationId: 'busy' });
2967
+ await w.npcs.onTurn(busy);
2968
+ assert.equal(busy.rejected, 'HUB_NPC_BUSY');
2969
+ assert.equal(w.lines.length, 0, 'scripted line hook suppressed');
2970
+ assert(w.sent.every((m) => m.k !== 'hub-npc-line'));
2971
+ await w.npcs.onRead(statusRead('a', 'op1', 'A checked reply.'));
2972
+ const inspect = { speaker: { playerId: 'a' }, query: { type: 'inspect' }, async read() {
2973
+ return { participantId: 'p1', characters: [{ characterId: 'greeter', privateState: { nextGreeting: { text: 'Unsafe late greeting.' } } }] };
2974
+ } };
2975
+ await w.npcs.onRead(inspect);
2976
+ assert(w.sent.every((m) => m.k !== 'hub-npc-opening'));
2977
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-end', npc: 'greeter' });
2978
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
2979
+ assert.equal(w.sent.filter((m) => m.open).at(-1).opening.text, opened.opening.text);
2980
+ await new Promise((resolve) => setImmediate(resolve));
2981
+ assert.deepEqual(archived, []);
2982
+ // v1.148: the opening hook is asked (for authored taps), its words unused.
2983
+ assert.deepEqual(called, ['opening', 'opening']);
2984
+ }
2985
+ });
2986
+
2987
+ await test('v1.142: child admission checks exact bundle tokens, including replays', async () => {
2988
+ const w = world({ childAsks: bundleAsks.greeter, notes: () => 'place notes' });
2989
+ w.h.place.under13Choices = true;
2990
+ w.h.session.players = [{ playerId: 'a', under13: true }];
2991
+ w.at('a', 0, 2);
2992
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
2993
+ for (const input of ['free text', 'Hi Rowan!', 'What can I do here?', 'choice:missing', ' choice:hi', 'choice:hi\n', 'choice:HI', 'choice:hi extra', NOTES_HEAD + 'notes' + NOTES_SAYS + 'choice:hi', null]) {
2994
+ const bad = turn({ speaker: 'a', input });
2995
+ await w.npcs.onTurn(bad);
2996
+ assert.equal(bad.rejected, 'HUB_NPC_CHOICE_REQUIRED', String(input));
2997
+ assert.equal(bad.sent, 0);
2998
+ }
2999
+ await w.npcs.onTurn(turn({ speaker: 'a', input: 'choice:hi' }));
3000
+ const badReplay = turn({ speaker: 'a', input: 'free text' });
3001
+ await w.npcs.onTurn(badReplay);
3002
+ assert.equal(badReplay.rejected, 'HUB_NPC_CHOICE_REQUIRED');
3003
+ assert.equal(badReplay.sent, 0);
3004
+ });
3005
+
3006
+ await test('v1.142: adults and unknown ages retain deck openings, notes, text and archives with bundle chips', async () => {
3007
+ for (const stamp of [false, undefined]) {
3008
+ const w = world({ childAsks: bundleAsks.greeter, notes: () => 'adult context' });
3009
+ w.h.place.under13Choices = true;
3010
+ w.h.place.talkLog = true;
3011
+ w.h.session.players = [{ playerId: 'a', ...(stamp === undefined ? {} : { under13: stamp }) }];
3012
+ w.h.hooks.npcOpening = () => ({ text: 'Deck opening.', asks: ['Ask me?'] });
3013
+ const archived = [];
3014
+ w.h.session.hub = { archiveText: async (_id, entry) => archived.push(entry) };
3015
+ w.at('a', 0, 2);
3016
+ w.npcs.message({ playerId: 'a', under13: true }, { k: 'hub-npc-open', npc: 'greeter' });
3017
+ await new Promise((resolve) => setImmediate(resolve));
3018
+ const opened = w.sent.find((m) => m.open);
3019
+ assert.equal(opened.choices, undefined);
3020
+ assert.equal(opened.opening.text, 'Deck opening.');
3021
+ const prefix = w.sent.find((m) => m.k === 'hub-npc-notes').prefix;
3022
+ const good = turn({ speaker: 'a', input: prefix + 'free text' });
3023
+ await w.npcs.onTurn(good);
3024
+ assert.equal(good.sent, 1);
3025
+ assert.equal(good.sendArgs[0][0].hubTextArchive.input, 'free text');
3026
+ assert.equal(archived[0].reply, 'Deck opening.');
3027
+ }
3028
+ const authored = world({ mind: false, childAsks: bundleAsks.greeter });
3029
+ authored.h.place.under13Choices = true;
3030
+ authored.h.session.players = [{ playerId: 'a', under13: true }];
3031
+ authored.at('a', 0, 2);
3032
+ authored.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
3033
+ assert.deepEqual(authored.sent.find((m) => m.open).choices, ['What can I do here?', 'Tell me about yourself.', 'Where should I go next?']);
3034
+ });
3035
+
3036
+ await test('v1.142: child chips send bare tokens, ignore text channels and suggestions, and survive reconnect', () => talkRig({ kid: true, childAsks: bundleAsks.greeter, suggestions: ['Model suggestion'] }, async (r) => {
3037
+ assert.equal(r.typing(), false);
3038
+ assert.deepEqual(r.offered(), bundleAsks.greeter.map(({ id, label }) => ({ id, label })));
3039
+ r.handlers.send('forged input');
3040
+ r.handlers.send('choice:hi');
3041
+ await r.settle();
3042
+ assert.equal(r.requests.length, 0);
3043
+ clientHub.npcEvents.push({ k: 'hub-npc', npc: r.npc, open: true, mind: true, character: 'greeter', name: 'Rowan', ageOff: true, choices: r.offered(), opening: { text: 'Deck opening', asks: ['Deck question'] } });
3044
+ r.frame(); await r.settle();
3045
+ for (const msg of [{ k: 'hub-npc-opening', text: 'Deck greeting' }, { k: 'hub-npc-line', text: 'Deck line' }, { k: 'hub-npc-notes', prefix: 'Forged notes', persistentAsks: ['Deck ask'] }]) {
3046
+ clientHub.npcEvents.push({ npc: r.npc, ...msg });
3047
+ }
3048
+ r.frame();
3049
+ assert.deepEqual(r.lines, [['them', 'Tap a question to talk with Rowan.']]);
3050
+ assert.equal(r.hint(), null);
3051
+ r.choose(r.offered()[3]); await r.settle();
3052
+ assert.equal(r.requests[0].input, 'choice:fav');
3053
+ assert.equal(r.lines.at(-1)[1], 'What do you like?');
3054
+ await r.advance(1200); r.frame();
3055
+ assert(r.lines.some(([who, text]) => who === 'them' && text === 'private mind reply'));
3056
+ assert.equal(r.offered().length, 4);
3057
+ assert(r.offered().every((ask) => ask.id && ask.label !== 'Model suggestion'));
3058
+ r.drop(); r.reconnect(); r.frame(); await r.settle();
3059
+ assert.equal(r.typing(), false);
3060
+ assert.equal(r.offered().length, 4);
3061
+ r.choose(r.offered()[0]); await r.settle();
3062
+ assert.equal(r.requests.at(-1).input, 'choice:hi');
3063
+ }));
3064
+
3065
+ await test('v1.142: a refused child inspect never shows the 13+ line or enables typing', () => withLogs(() => talkRig({ kid: true, childAsks: bundleAsks.greeter, inspectFailures: [characterRefusal()] }, async (r) => {
3066
+ r.frame();
3067
+ assert.equal(r.typing(), false);
3068
+ assert.equal(r.hint(), null);
3069
+ })));
3070
+
3071
+ await test('v1.142: a refused child turn restores chips without a scripted packet', () => withLogs(() => talkRig({ kid: true, childAsks: bundleAsks.greeter }, async (r) => {
3072
+ r.refuseTurns('HUB_NPC_BUDGET');
3073
+ r.choose(r.offered()[0]); await r.settle();
3074
+ assert.equal(r.offered().length, 0);
3075
+ await r.advance(1500); r.frame();
3076
+ assert.equal(r.offered().length, 4);
3077
+ assert.equal(r.typing(), false);
3078
+ })));
3079
+
3080
+ const recoveredChildChips = (r) => {
3081
+ assert.equal(r.talk.talking(), true);
3082
+ assert.equal(r.typing(), false);
3083
+ assert.equal(r.waiting(), false);
3084
+ assert.deepEqual(r.offered(), bundleAsks.greeter.map(({ id, label }) => ({ id, label })));
3085
+ };
3086
+
3087
+ await test('child chips recover after status retries are exhausted', () => withLogs(() => talkRig({ kid: true, childAsks: bundleAsks.greeter, statusFailures: [new Error('offline'), new Error('offline')] }, async (r) => {
3088
+ r.choose(r.offered()[0]); await r.settle();
3089
+ assert.equal(r.offered().length, 0);
3090
+ await r.advance(1200); await r.advance(1200); r.frame();
3091
+ assert.equal(r.reads.status, 2);
3092
+ recoveredChildChips(r);
3093
+ assert(!r.lines.some(([, text]) => text === 'private mind reply'));
3094
+ r.choose(r.offered()[1]); await r.settle();
3095
+ assert.equal(r.requests.at(-1).input, 'choice:doors');
3096
+ })));
3097
+
3098
+ await test('child chips recover when polling times out without a reply', () => talkRig({ kid: true, childAsks: bundleAsks.greeter, status: 'queued' }, async (r) => {
3099
+ r.choose(r.offered()[0]); await r.settle();
3100
+ assert.equal(r.offered().length, 0);
3101
+ await r.advance(90_000); r.frame();
3102
+ assert.equal(r.reads.status, 1);
3103
+ recoveredChildChips(r);
3104
+ assert(!r.lines.some(([, text]) => text === 'private mind reply'));
3105
+ }));
3106
+
3107
+ for (const code of ['HUB_NPC_CHOICE_REQUIRED', 'HUB_NPC_BUDGET', 'HUB_NPC_NOTES', 'UNKNOWN_FAILURE', undefined]) {
3108
+ await test(`child chips recover after send rejection ${code}`, () => withLogs(() => talkRig({ kid: true, childAsks: bundleAsks.greeter }, async (r) => {
3109
+ r.refuseTurns(code);
3110
+ r.choose(r.offered()[0]); await r.settle();
3111
+ assert.equal(r.offered().length, 0);
3112
+ await r.advance(1500); r.frame();
3113
+ recoveredChildChips(r);
3114
+ r.choose(r.offered()[1]); await r.settle();
3115
+ assert.equal(r.requests.at(-1).input, 'choice:doors');
3116
+ assert.equal(r.admitted.length, 1);
3117
+ })));
3118
+ }
3119
+
3120
+ await test('child chips and the fixed interruption line recover after a reattached send is rejected', () => withLogs(() => talkRig({ kid: true, childAsks: bundleAsks.greeter }, async (r) => {
3121
+ r.drop(); r.reconnect(); r.frame(); await r.settle();
3122
+ r.refuseTurns('HUB_NPC_CHOICE_REQUIRED');
3123
+ r.choose(r.offered()[0]); await r.settle();
3124
+ assert.equal(r.lines.at(-1)[1], 'Lost the thread there. Tap to talk again.');
3125
+ await r.advance(1500); r.frame();
3126
+ recoveredChildChips(r);
3127
+ })));
3128
+
3129
+ await test('child chips recover after the one NOT_TALKING retry is rejected', () => withLogs(() => talkRig({ kid: true, childAsks: bundleAsks.greeter }, async (r) => {
3130
+ r.forceNotTalking();
3131
+ r.choose(r.offered()[0]); await r.settle(); r.frame(); await r.settle();
3132
+ assert.equal(r.requests.length, 2);
3133
+ assert.equal(r.lines.at(-1)[1], 'Lost the thread there. Tap to talk again.');
3134
+ await r.advance(1500); r.frame();
3135
+ recoveredChildChips(r);
3136
+ })));
3137
+
3138
+ for (const pendingSend of [false, true]) {
3139
+ await test(`child reconnect restores chips without replaying a pending ${pendingSend ? 'send' : 'poll'}`, () => withLogs(() => talkRig({ kid: true, childAsks: bundleAsks.greeter }, async (r) => {
3140
+ r.holdTurns(pendingSend);
3141
+ r.choose(r.offered()[0]); await r.settle();
3142
+ assert.equal(r.offered().length, 0);
3143
+ r.drop(); r.reconnect(); r.frame(); await r.settle();
3144
+ recoveredChildChips(r);
3145
+ assert.equal(r.requests.length, 1, 'unknown turn is never replayed');
3146
+ if (pendingSend) {
3147
+ r.holdTurns(false);
3148
+ } else {
3149
+ // Ghost may finish the old admitted turn after the socket is gone.
3150
+ await r.w.npcs.onRead(statusRead('p1', r.requests[0].operationId, 'Old checked reply'));
3151
+ }
3152
+ r.choose(r.offered()[1]); await r.settle();
3153
+ assert.equal(r.requests.at(-1).input, 'choice:doors');
3154
+ assert.equal(r.waiting(), true);
3155
+ if (pendingSend) {
3156
+ r.heldTurns[0]({ code: 'HUB_NPC_CHOICE_REQUIRED' }); await r.settle();
3157
+ }
3158
+ // The old poll or rejected request must not clear the new turn's wait.
3159
+ await r.advance(1200);
3160
+ assert.equal(r.requests.length, 2);
3161
+ assert.equal(r.lines.filter(([who, text]) => who === 'them' && text === 'private mind reply').length, 1);
3162
+ recoveredChildChips(r);
3163
+ await r.advance(1500); r.frame();
3164
+ recoveredChildChips(r);
3165
+ })));
3166
+ }
3167
+
3168
+ await test('v1.101: trusted child stamp requires exact canned words for authored and model paths', async () => {
3169
+ for (const mind of [false, true]) {
3170
+ const w = world({ mind });
3171
+ w.h.place.under13Choices = true;
3172
+ w.h.session.players = [{ playerId: 'a', userId: '101', under13: true }];
3173
+ w.at('a', 0, 2);
3174
+ w.npcs.message({ playerId: 'a', under13: false }, { k: 'hub-npc-open', npc: 'greeter' });
3175
+ const opened = w.sent.find((m) => m.open);
3176
+ assert.equal(opened.choices.length, 3);
3177
+ const question = opened.choices[0];
3178
+ if (mind) {
3179
+ const bad = turn({ speaker: 'a', input: 'a forged free-text message' });
3180
+ await w.npcs.onTurn(bad);
3181
+ assert.equal(bad.rejected, 'HUB_NPC_CHOICE_REQUIRED');
3182
+ assert.equal(bad.sent, 0);
3183
+ const good = turn({ speaker: 'a', input: question, operationId: 'good' });
3184
+ await w.npcs.onTurn(good);
3185
+ assert.equal(good.sent, 1);
3186
+ // A replay keeps its original admission even after notes have aged out.
3187
+ const replay = turn({ speaker: 'a', input: question, operationId: 'good' });
3188
+ await w.npcs.onTurn(replay);
3189
+ assert.equal(replay.sent, 1);
3190
+ } else {
3191
+ const count = w.lines.length;
3192
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-say', npc: 'greeter', text: 'forged' });
3193
+ assert.equal(w.lines.length, count);
3194
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-say', npc: 'greeter', text: ' '.repeat(400) + '\t\n' + question + '\n' });
3195
+ assert.equal(w.lines.at(-1).text, question, 'only canonical allowed bytes reach authored reply');
3196
+ }
3197
+ }
3198
+ });
3199
+
3200
+ await test('v1.101: key absent or trusted stamp absent preserves free text and opening bytes', async () => {
3201
+ for (const [key, stamp] of [[undefined, true], [true, undefined], [true, false]]) {
3202
+ const w = world();
3203
+ if (key !== undefined) w.h.place.under13Choices = key;
3204
+ w.h.session.players = [{ playerId: 'a', userId: '101', ...(stamp === undefined ? {} : { under13: stamp }) }];
3205
+ w.at('a', 0, 2);
3206
+ w.npcs.message({ playerId: 'a', under13: true }, { k: 'hub-npc-open', npc: 'greeter' });
3207
+ assert.ok(!Object.hasOwn(w.sent.find((m) => m.open), 'choices'));
3208
+ const t = turn({ speaker: 'a', input: 'unrestricted words' });
3209
+ await w.npcs.onTurn(t);
3210
+ assert.equal(t.sent, 1);
3211
+ }
3212
+ });
3213
+
3214
+ await test('v1.101: canned UI hides form, answers chips, refills and reconnects without free text', () => talkRig({ child: true }, async (r) => {
3215
+ assert.equal(r.typing(), false);
3216
+ assert.equal(r.offered().length, 3);
3217
+ r.handlers.send('forged input');
3218
+ await r.settle();
3219
+ assert.equal(r.requests.length, 0);
3220
+ const question = r.offered()[0];
3221
+ r.choose(question);
3222
+ await r.settle();
3223
+ assert.equal(r.admitted.length, 1);
3224
+ assert.ok(r.requests[0].input.endsWith(question));
3225
+ await r.advance(1200); r.frame();
3226
+ assert.equal(r.offered().length, 3);
3227
+ r.drop(); r.reconnect(); r.frame(); await r.settle();
3228
+ assert.equal(r.typing(), false);
3229
+ r.handlers.send('still forged'); await r.settle();
3230
+ assert.equal(r.requests.length, 1);
3231
+ }));
3232
+
3233
+ await test('v1.101: archive authored input/reply before delivery; omitted key never calls storage', async () => {
3234
+ for (const enabled of [false, true]) {
3235
+ const w = world({ mind: false });
3236
+ const archived = [];
3237
+ let release;
3238
+ w.h.session.hub = { archiveText: async (playerId, entry) => { archived.push({ playerId, ...entry }); await new Promise((resolve) => { release = resolve; }); } };
3239
+ if (enabled) w.h.place.talkLog = true;
3240
+ w.at('a', 0, 2);
3241
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
3242
+ await new Promise((resolve) => setImmediate(resolve));
3243
+ if (enabled) { assert.equal(archived[0].reply, 'line:hello'); release(); await new Promise((resolve) => setImmediate(resolve)); }
3244
+ const before = w.sent.length;
3245
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-say', npc: 'greeter', text: 'my exact words', rid: 'r1' });
3246
+ await new Promise((resolve) => setImmediate(resolve));
3247
+ if (enabled) {
3248
+ assert.equal(w.sent.length, before, 'no reply before durable archive ack');
3249
+ assert.equal(archived.at(-1).input, 'my exact words');
3250
+ assert.equal(archived.at(-1).reply, 'line:authored');
3251
+ release(); await new Promise((resolve) => setImmediate(resolve));
3252
+ } else assert.equal(archived.length, 0);
3253
+ assert.equal(w.sent.at(-1).text, 'line:authored');
3254
+ }
3255
+ });
3256
+
3257
+ await test('v1.101: model logs words before admission, preserves replay metadata and fails closed', async () => {
3258
+ const w = world({ notes: () => 'trusted context' });
3259
+ w.h.place.talkLog = true;
3260
+ const archived = [];
3261
+ w.h.session.hub = { archiveText: async (playerId, entry) => { archived.push({ playerId, ...entry }); } };
3262
+ w.at('a', 0, 2);
3263
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
3264
+ await new Promise((resolve) => setImmediate(resolve));
3265
+ const prefix = w.sent.find((m) => m.k === 'hub-npc-notes').prefix;
3266
+ const good = turn({ speaker: 'a', input: prefix + 'question', operationId: 'logged' });
3267
+ await w.npcs.onTurn(good);
3268
+ assert.equal(archived.at(-1).input, 'question');
3269
+ assert.equal(good.sendArgs[0][0].hubTextArchive.input, 'question');
3270
+ assert.equal(good.sendArgs[0][0].hubTextArchive.npcId, 'greeter');
3271
+ const count = archived.length;
3272
+ const replay = turn({ speaker: 'a', input: prefix + 'question', operationId: 'logged' });
3273
+ await w.npcs.onTurn(replay);
3274
+ assert.deepEqual(replay.sendArgs, good.sendArgs);
3275
+ assert.equal(archived.length, count);
3276
+ w.h.session.hub.archiveText = async () => { throw new Error('offline'); };
3277
+ const bad = turn({ speaker: 'a', input: prefix + 'second question', operationId: 'failed-log' });
3278
+ await w.npcs.onTurn(bad);
3279
+ assert.equal(bad.rejected, 'HUB_NPC_LOG_UNAVAILABLE');
3280
+ assert.equal(bad.sent, 0);
3281
+ });
3282
+
3283
+ await test('v1.101: authored archive failure closes talk without an unlogged reply', async () => {
3284
+ const w = world({ mind: false });
3285
+ w.h.place.talkLog = true;
3286
+ w.h.session.hub = { archiveText: async () => {} };
3287
+ w.at('a', 0, 2);
3288
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
3289
+ await new Promise((resolve) => setImmediate(resolve));
3290
+ w.h.session.hub.archiveText = async () => { throw new Error('offline'); };
3291
+ const before = w.sent.length;
3292
+ w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-say', npc: 'greeter', text: 'question', rid: 'fail' });
3293
+ await new Promise((resolve) => setImmediate(resolve));
3294
+ assert.ok(w.sent.slice(before).some((m) => m.open === false && m.why === 'unavailable'));
3295
+ assert.ok(!w.sent.slice(before).some((m) => m.k === 'hub-npc-line'));
3296
+ });
3297
+
3298
+ await test('NPC display removes paired emphasis, preserves literal punctuation and identifiers', () => {
3299
+ for (const [input, expected] of [
3300
+ ['“Try **Foot Race**, *Mabel*! _Have fun_ and __come back__.”', 'Try Foot Race, Mabel! Have fun and come back.'],
3301
+ ['***Town*** is open.', 'Town is open.'],
3302
+ ['**Hello *friend* today**', 'Hello friend today'],
3303
+ ['**Hello *friend***', 'Hello friend'],
3304
+ ['***Hello** friend*', 'Hello friend'],
3305
+ ['***Hello* friend**', 'Hello friend'],
3306
+ ['🌼 **Hello *friend***', '🌼 Hello friend'],
3307
+ ['2 * 3 = 6; file_name and hub_game; a lone *', '2 * 3 = 6; file_name and hub_game; a lone *'],
3308
+ ['Plain reply.', 'Plain reply.'],
3309
+ ]) assert.equal(npcDisplayText(input), expected);
3310
+ });
3311
+ await test('NPC panel and private bubble share plain display; player input stays intact', () => talkRig({}, async (r) => {
3312
+ r.handlers.send('I typed *this*'); await r.settle();
3313
+ await r.advance(1200); r.frame(); await r.settle();
3314
+ assert(r.lines.some(([who, text]) => who === 'me' && text === 'I typed *this*'));
3315
+ assert(r.lines.some(([who, text]) => who === 'them' && text === 'private mind reply'));
3316
+ assert(r.w.labels.some(label => label.text === 'Rowan: private mind reply'));
3317
+ }));
3318
+
3319
+ // v1.134: server-started talks use the real conversation boundary, including
3320
+ // range and capacity checks and the existing private panel payload.
3321
+ {
3322
+ const absent = world({ mind: false });
3323
+ assert.equal(absent.npcs.handle('greeter').open, undefined);
3324
+ const w = world({ firstVisit: true, mind: false });
3325
+ w.h.hooks.npcOpening = () => ({ text: 'Welcome!', asks: ['Show me around', "I'll look myself"], more: [] });
3326
+ const npc = w.npcs.handle('greeter');
3327
+ assert.equal(npc.open('missing'), false);
3328
+ w.at('p', 30, 30); assert.equal(npc.open('p'), false);
3329
+ w.at('p', 1, 1); assert.equal(npc.open('p'), true);
3330
+ assert.equal(npc.open('p'), false, 'already open is not restarted');
3331
+ const packet = w.sent.find(x => x.playerId === 'p' && x.open === true);
3332
+ assert(packet, 'existing talk panel receives server opening');
3333
+ assert.equal(packet.opening.text, 'Welcome!');
3334
+ w.at('q', 1, 1); assert.equal(npc.open('q'), false, 'one-turn slot stays bounded');
3335
+ }
3336
+
3337
+ console.log(`hub-game npcs complete: ${n} tests passed`);