castle-web-cli 0.4.231 → 0.4.233

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 (368) hide show
  1. package/dist/agent-failures.d.ts +8 -0
  2. package/dist/agent-failures.js +19 -2
  3. package/dist/agent-prompts.d.ts +1 -1
  4. package/dist/agent-prompts.js +10 -3
  5. package/dist/agent.d.ts +64 -3
  6. package/dist/agent.js +170 -81
  7. package/dist/castle-host/host.d.ts +1 -0
  8. package/dist/castle-host/host.js +51 -3
  9. package/dist/castleJson.d.ts +4 -2
  10. package/dist/castleJson.js +2 -0
  11. package/dist/check.d.ts +3 -1
  12. package/dist/check.js +11 -1
  13. package/dist/devSessionStorage.js +47 -1
  14. package/dist/importPinMismatch.d.ts +22 -0
  15. package/dist/importPinMismatch.js +77 -0
  16. package/dist/importRegression.js +3 -15
  17. package/dist/imports.d.ts +10 -3
  18. package/dist/imports.js +88 -20
  19. package/dist/index.js +5 -4
  20. package/dist/init.js +1 -1
  21. package/dist/platformDoc.js +22 -0
  22. package/dist/routerFences.d.ts +5 -0
  23. package/dist/routerFences.js +12 -2
  24. package/dist/save-deck.d.ts +5 -0
  25. package/dist/save-deck.js +37 -4
  26. package/dist/serve.js +3 -0
  27. package/dist/serverBundle.js +5 -3
  28. package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
  29. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  30. package/dist/shell/index.html +2 -2
  31. package/dist/taskSteer.d.ts +13 -0
  32. package/dist/taskSteer.js +22 -2
  33. package/kits/base/castle.json +1 -1
  34. package/kits/base/package-lock.json +1 -1
  35. package/kits/base/sdk/README.md +79 -2
  36. package/kits/base/sdk/avatar.d.ts +6 -2
  37. package/kits/base/sdk/avatar.js +12 -4
  38. package/kits/base/sdk/castle.d.ts +1 -1
  39. package/kits/base/sdk/commands.d.ts +14 -0
  40. package/kits/base/sdk/hub.d.ts +6 -2
  41. package/kits/base/sdk/hub.js +13 -0
  42. package/kits/base/sdk/multiplayer.js +17 -1
  43. package/kits/base/sdk/save.js +2 -1
  44. package/kits/base/sdk/server/hub.d.ts +87 -0
  45. package/kits/base/sdk/server/hub.js +70 -0
  46. package/kits/base/sdk/server/platformHandle.d.ts +31 -1
  47. package/kits/base/sdk/server/storage.d.ts +13 -0
  48. package/kits/base/sdk/server/storage.js +46 -0
  49. package/kits/base/sdk/server/wrapper.d.ts +36 -5
  50. package/kits/base/sdk/server/wrapper.js +83 -8
  51. package/kits/hub-game/CLAUDE.md +352 -12
  52. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  53. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  54. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  55. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  56. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  57. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  58. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  59. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  60. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  61. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  62. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  63. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  64. package/kits/hub-game/code/client/actorBudget.js +47 -0
  65. package/kits/hub-game/code/client/attention.js +11 -2
  66. package/kits/hub-game/code/client/avatar.js +345 -32
  67. package/kits/hub-game/code/client/avatarCap.js +228 -0
  68. package/kits/hub-game/code/client/avatarColors.js +70 -0
  69. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  70. package/kits/hub-game/code/client/avatarShare.js +251 -0
  71. package/kits/hub-game/code/client/ballot.js +467 -0
  72. package/kits/hub-game/code/client/build.js +22 -0
  73. package/kits/hub-game/code/client/chat.js +12 -0
  74. package/kits/hub-game/code/client/chrome.js +1334 -50
  75. package/kits/hub-game/code/client/companion.js +716 -0
  76. package/kits/hub-game/code/client/companionDress.js +99 -0
  77. package/kits/hub-game/code/client/decor.js +509 -0
  78. package/kits/hub-game/code/client/earned.js +131 -0
  79. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  80. package/kits/hub-game/code/client/grab.js +363 -20
  81. package/kits/hub-game/code/client/hats.js +26 -0
  82. package/kits/hub-game/code/client/hookLayer.js +328 -15
  83. package/kits/hub-game/code/client/hudClear.js +126 -0
  84. package/kits/hub-game/code/client/idle.js +163 -22
  85. package/kits/hub-game/code/client/interestCap.js +81 -0
  86. package/kits/hub-game/code/client/keys.js +36 -0
  87. package/kits/hub-game/code/client/labelsNear.js +205 -0
  88. package/kits/hub-game/code/client/menuIcons.js +34 -0
  89. package/kits/hub-game/code/client/pack.js +6 -2
  90. package/kits/hub-game/code/client/packFormat.js +3 -3
  91. package/kits/hub-game/code/client/rehello.js +167 -0
  92. package/kits/hub-game/code/client/shot.js +92 -0
  93. package/kits/hub-game/code/client/sound.js +63 -8
  94. package/kits/hub-game/code/client/soundscape.js +1151 -0
  95. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  96. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  97. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  98. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  99. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  100. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  101. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  102. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  103. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  104. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  105. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  106. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  107. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  108. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  109. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  110. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  111. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  112. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  113. package/kits/hub-game/code/client/spin.js +101 -0
  114. package/kits/hub-game/code/client/state.js +131 -1
  115. package/kits/hub-game/code/client/stuck.js +259 -0
  116. package/kits/hub-game/code/client/talk.js +538 -47
  117. package/kits/hub-game/code/client/tiers.js +541 -27
  118. package/kits/hub-game/code/client/toastBand.js +37 -0
  119. package/kits/hub-game/code/client/together.js +98 -1
  120. package/kits/hub-game/code/client/visibility.js +43 -0
  121. package/kits/hub-game/code/client/wear.js +470 -97
  122. package/kits/hub-game/code/client/yours.js +199 -0
  123. package/kits/hub-game/code/companionSpec.js +45 -0
  124. package/kits/hub-game/code/privateText.js +7 -0
  125. package/kits/hub-game/code/server/actions.js +133 -0
  126. package/kits/hub-game/code/server/actors.js +14 -1
  127. package/kits/hub-game/code/server/ask.js +155 -0
  128. package/kits/hub-game/code/server/ballot.js +539 -0
  129. package/kits/hub-game/code/server/cells.js +100 -0
  130. package/kits/hub-game/code/server/companion.js +82 -0
  131. package/kits/hub-game/code/server/cues.js +70 -0
  132. package/kits/hub-game/code/server/decor.js +269 -0
  133. package/kits/hub-game/code/server/earned.js +461 -0
  134. package/kits/hub-game/code/server/friendBests.js +166 -0
  135. package/kits/hub-game/code/server/friendsAmong.js +232 -0
  136. package/kits/hub-game/code/server/grab.js +296 -11
  137. package/kits/hub-game/code/server/history.js +5 -0
  138. package/kits/hub-game/code/server/hub.js +1317 -52
  139. package/kits/hub-game/code/server/idle.js +30 -11
  140. package/kits/hub-game/code/server/index.js +2 -2
  141. package/kits/hub-game/code/server/labels.js +28 -2
  142. package/kits/hub-game/code/server/manifest.js +424 -8
  143. package/kits/hub-game/code/server/menu.js +133 -0
  144. package/kits/hub-game/code/server/npcs.js +830 -80
  145. package/kits/hub-game/code/server/party.js +13 -2
  146. package/kits/hub-game/code/server/players.js +22 -0
  147. package/kits/hub-game/code/server/say.js +8 -2
  148. package/kits/hub-game/code/server/shot.js +110 -0
  149. package/kits/hub-game/code/server/standing.js +124 -0
  150. package/kits/hub-game/code/server/vis.js +113 -0
  151. package/kits/hub-game/code/server/wear.js +128 -11
  152. package/kits/hub-game/code/server/yours.js +59 -0
  153. package/kits/hub-game/code/shared/cues.js +9 -0
  154. package/kits/hub-game/code/shared/decor.js +41 -0
  155. package/kits/hub-game/code/shared/shot.js +19 -0
  156. package/kits/hub-game/code/shared/spin.js +57 -0
  157. package/kits/hub-game/code/systems/hub.js +1083 -85
  158. package/kits/hub-game/docs/content-pack.md +1 -1
  159. package/kits/hub-game/docs/contract.md +2440 -61
  160. package/kits/hub-game/docs/home-pieces.md +64 -0
  161. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  162. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  163. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  164. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  165. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  166. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  167. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  168. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  169. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  170. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  171. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  172. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  173. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  174. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  175. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  176. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  177. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  178. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  179. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  180. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  181. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  182. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  183. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  184. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  185. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  186. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  187. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  188. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  189. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  190. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  191. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  192. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  193. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  194. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  195. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  196. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  197. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  198. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  199. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  200. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  201. package/kits/hub-game/package-lock.json +2 -0
  202. package/kits/hub-game/package.json +2 -1
  203. package/kits/hub-game/scripts/check.mjs +78 -11
  204. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  205. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
  206. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  207. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
  208. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
  209. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  210. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  211. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  212. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  213. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  214. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  215. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  216. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  217. package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
  218. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  219. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  220. package/kits/hub-game/scripts/test-actors.mjs +19 -17
  221. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  222. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  223. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  224. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  225. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  226. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  227. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  228. package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
  229. package/kits/hub-game/scripts/test-avatar.mjs +540 -7
  230. package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
  231. package/kits/hub-game/scripts/test-build.mjs +31 -0
  232. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  233. package/kits/hub-game/scripts/test-chat.mjs +694 -0
  234. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  235. package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
  236. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  237. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  238. package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
  239. package/kits/hub-game/scripts/test-decor.mjs +457 -0
  240. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  241. package/kits/hub-game/scripts/test-earned.mjs +1194 -0
  242. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  243. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  244. package/kits/hub-game/scripts/test-grab-client.mjs +186 -3
  245. package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
  246. package/kits/hub-game/scripts/test-grab.mjs +864 -3
  247. package/kits/hub-game/scripts/test-hats.mjs +483 -0
  248. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  249. package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
  250. package/kits/hub-game/scripts/test-hub-trip.mjs +1228 -1
  251. package/kits/hub-game/scripts/test-hud-clear.mjs +1000 -0
  252. package/kits/hub-game/scripts/test-idle.mjs +361 -1
  253. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  254. package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
  255. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  256. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  257. package/kits/hub-game/scripts/test-labels.mjs +596 -0
  258. package/kits/hub-game/scripts/test-manifest.mjs +282 -0
  259. package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
  260. package/kits/hub-game/scripts/test-menu.mjs +296 -0
  261. package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
  262. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  263. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  264. package/kits/hub-game/scripts/test-party.mjs +22 -1
  265. package/kits/hub-game/scripts/test-picker.mjs +314 -0
  266. package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
  267. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  268. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  269. package/kits/hub-game/scripts/test-say.mjs +59 -2
  270. package/kits/hub-game/scripts/test-shot.mjs +756 -0
  271. package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
  272. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  273. package/kits/hub-game/scripts/test-standing.mjs +416 -0
  274. package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
  275. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  276. package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
  277. package/kits/hub-game/scripts/test-tiers.mjs +666 -3
  278. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  279. package/kits/hub-game/scripts/test-try-on.mjs +940 -0
  280. package/kits/hub-game/scripts/test-vis.mjs +343 -0
  281. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  282. package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
  283. package/kits/hub-game/scripts/test-yours.mjs +372 -0
  284. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  285. package/kits/multiplayer-3d/castle.json +5 -5
  286. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  287. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  288. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  289. package/kits/multiplayer-3d/code/options.js +5 -0
  290. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  291. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  292. package/kits/multiplayer-3d/code/server/world.js +7 -0
  293. package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
  294. package/kits/multiplayer-3d/package.json +2 -1
  295. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  296. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  297. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  298. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  299. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  300. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  301. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  302. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  303. package/kits/physics-2d/CLAUDE.md +9 -0
  304. package/kits/physics-2d/castle.json +2 -2
  305. package/kits/physics-2d/engine/scene.js +288 -1
  306. package/kits/physics-2d/engine/skyKey.js +129 -0
  307. package/kits/physics-2d/engine/stillClock.js +106 -0
  308. package/kits/physics-2d/engine/updateBudget.js +21 -0
  309. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +370 -1
  310. package/kits/physics-3d/CLAUDE.md +1391 -0
  311. package/kits/physics-3d/behaviors/Player.jsx +921 -3
  312. package/kits/physics-3d/castle.json +3 -3
  313. package/kits/physics-3d/docs/pxmodel-format.md +12 -0
  314. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +98 -10
  315. package/kits/physics-3d/engine3d/actornode.js +86 -0
  316. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  317. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  318. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  319. package/kits/physics-3d/engine3d/framecap.js +96 -0
  320. package/kits/physics-3d/engine3d/gait.js +118 -0
  321. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  322. package/kits/physics-3d/engine3d/look.js +507 -48
  323. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  324. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  325. package/kits/physics-3d/engine3d/motion.js +39 -10
  326. package/kits/physics-3d/engine3d/nearshadows.js +37 -19
  327. package/kits/physics-3d/engine3d/optimize.js +58 -5
  328. package/kits/physics-3d/engine3d/orbitinput.js +755 -0
  329. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  330. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  331. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  332. package/kits/physics-3d/engine3d/shadowfade.js +882 -0
  333. package/kits/physics-3d/engine3d/sky.js +547 -0
  334. package/kits/physics-3d/engine3d/skylife.js +306 -0
  335. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  336. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  337. package/kits/physics-3d/engine3d/world3d.js +870 -87
  338. package/kits/physics-3d/main.jsx +5 -0
  339. package/kits/physics-3d/package.json +1 -1
  340. package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
  341. package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
  342. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  343. package/kits/physics-3d/scripts/test-camera-follow.mjs +12 -2
  344. package/kits/physics-3d/scripts/test-camera-orbit.mjs +4588 -0
  345. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
  346. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
  347. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  348. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  349. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  350. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  351. package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
  352. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
  353. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
  354. package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
  355. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  356. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  357. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  358. package/kits/physics-3d/scripts/test-static-actors.mjs +13 -1
  359. package/kits/physics-3d/scripts/test-static-passes.mjs +1 -1
  360. package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
  361. package/kits/physics-3d/scripts/test-steady-hover.mjs +635 -0
  362. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  363. package/kits/physics-3d/systems/physics3d.js +474 -12
  364. package/kits/real-time/castle.json +2 -2
  365. package/kits/real-time/code/server/gameHooks.js +7 -0
  366. package/kits/real-time/code/server/session.js +97 -19
  367. package/package.json +2 -2
  368. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -76,6 +76,38 @@ let n = 0;
76
76
  assert.deepEqual([calls.at(-1), reported], [['report', 'm1'], true]);
77
77
  n += 1;
78
78
 
79
+ // Cues (contract v1.23): someone came in. With peers the 2.5 s cadence is
80
+ // soon enough and nothing moves; with none the idle wait (15 s) is cut to
81
+ // about a second, once however many came in. Never called without cues.
82
+ {
83
+ const before = calls.filter(([k]) => k === 'chat').length;
84
+ const asks = () => calls.filter(([k]) => k === 'chat').length - before;
85
+ c.soon(4100);
86
+ c.frame(true, 5200);
87
+ await flush();
88
+ assert.equal(asks(), 0, 'peers here: the cadence is its own');
89
+ answer = { status: 'ok', canChat: true, peers: [], cursor: 'c2', messages: [] };
90
+ c.frame(true, 7000);
91
+ await flush();
92
+ assert.deepEqual([asks(), c.peers], [1, []]);
93
+ c.frame(true, 12000);
94
+ await flush();
95
+ assert.equal(asks(), 1, 'nobody to chat with: the idle wait');
96
+ c.soon(12000);
97
+ c.soon(12300);
98
+ c.frame(true, 12900);
99
+ await flush();
100
+ assert.equal(asks(), 1, 'not at once: the host is given a moment');
101
+ answer = { status: 'ok', canChat: true, peers: ['102'], cursor: 'c2', messages: [] };
102
+ c.frame(true, 13000);
103
+ await flush();
104
+ assert.deepEqual([asks(), c.peers], [2, ['102']], 'asked a second after they came in');
105
+ c.frame(true, 13500);
106
+ await flush();
107
+ assert.equal(asks(), 2, 'once for all who came in');
108
+ n += 1;
109
+ }
110
+
79
111
  // An answer that lands after the session changed is the old session's.
80
112
  answer = { status: 'ok', canChat: true, peers: ['102'], cursor: 'c3', messages: [{ id: 'late', fromUserId: '102', fromUsername: 'bo', text: 'late', at: '' }] };
81
113
  c.frame(true, 20000);
@@ -95,4 +127,666 @@ let n = 0;
95
127
  n += 1;
96
128
  }
97
129
 
130
+ // v1.46: NPC chips return after a reply, and a refused inspect is retried.
131
+ {
132
+ const { makeTalk } = await import('../code/client/talk.js');
133
+ const { hub } = await import('../code/client/state.js');
134
+ const polls = [];
135
+ const later = globalThis.setTimeout;
136
+ const cancel = globalThis.clearTimeout;
137
+ const now = Object.getOwnPropertyDescriptor(performance, 'now');
138
+ let clock = 0;
139
+ Object.defineProperty(performance, 'now', { configurable: true, value: () => clock });
140
+ globalThis.setTimeout = (fn, ms, ...args) => {
141
+ if (ms !== 1200) {
142
+ return later(fn, ms, ...args);
143
+ }
144
+ const timer = { fn, at: clock + ms, cancelled: false };
145
+ polls.push(timer);
146
+ return timer;
147
+ };
148
+ globalThis.clearTimeout = (timer) => {
149
+ if (timer && typeof timer === 'object' && 'cancelled' in timer) {
150
+ timer.cancelled = true;
151
+ } else {
152
+ cancel(timer);
153
+ }
154
+ };
155
+ const settle = () => new Promise((resolve) => setImmediate(resolve));
156
+ const runWait = async () => {
157
+ let timer = polls.shift();
158
+ while (timer?.cancelled) {
159
+ timer = polls.shift();
160
+ }
161
+ assert.ok(timer, 'there is a pending wait');
162
+ clock = Math.max(clock, timer.at);
163
+ timer.fn();
164
+ await settle();
165
+ };
166
+ try {
167
+ let handlers;
168
+ let canType = false;
169
+ let asks = [];
170
+ const askRows = [];
171
+ let waiting = false;
172
+ let inspectResolve;
173
+ let inspectReject;
174
+ let inspections = 0;
175
+ let turns = 0;
176
+ const requests = [];
177
+ const sent = [];
178
+ const lines = [];
179
+ let panelLines = [];
180
+ let result = { status: 'completed', response: 'Hello.' };
181
+ const chrome = {
182
+ onTalk: (h) => { handlers = h; },
183
+ openTalk: (_name, options) => { canType = options.canType; panelLines = []; },
184
+ closeTalk: () => { canType = false; },
185
+ talkTyping: (allowed) => { canType = allowed; },
186
+ talkAsks: (list) => { asks = list; askRows.push(list); },
187
+ talkLine: (who, text) => { lines.push(text); panelLines.push({ who, text }); },
188
+ talkOpening: (text) => { panelLines[0].text = text; },
189
+ talkPrompt() {},
190
+ talkWaiting: (value) => { waiting = value; },
191
+ talkFocused: () => false,
192
+ };
193
+ const net = {
194
+ send: (msg) => { sent.push(msg); },
195
+ characters: {
196
+ readCharacters: ({ query }) => {
197
+ if (query.type === 'inspect') {
198
+ inspections += 1;
199
+ return new Promise((resolve, reject) => { inspectResolve = resolve; inspectReject = reject; });
200
+ }
201
+ return Promise.resolve(result);
202
+ },
203
+ requestCharacterTurn: async (request) => { turns += 1; requests.push(request); },
204
+ },
205
+ };
206
+ const talk = makeTalk(chrome);
207
+ const frame = () => talk.frame(null, { net }, false);
208
+ const opening = { text: 'Hello.', asks: ['One?', 'Two?', 'Three?'], more: ['Four?', 'Five?'] };
209
+ const open = (mind = true) => {
210
+ hub.npcEvents.push({ k: 'hub-npc', npc: 'greeter', name: 'Rowan', open: true, mind, character: mind ? 'greeter' : null, opening });
211
+ frame();
212
+ };
213
+ const answer = async (text, reply = { status: 'completed', response: 'Hello.' }) => {
214
+ result = reply;
215
+ handlers.send(text);
216
+ assert.equal(waiting, true);
217
+ assert.deepEqual(asks, []);
218
+ await settle();
219
+ assert.equal(polls.length, 1);
220
+ await runWait();
221
+ frame();
222
+ assert.equal(waiting, false);
223
+ };
224
+ open();
225
+ assert.equal(canType, false, 'pending inspect hides typing');
226
+ hub.npcEvents.push({ k: 'hub-npc-opening', npc: 'other', text: 'Someone else.' });
227
+ frame();
228
+ assert.deepEqual(panelLines, [{ who: 'them', text: 'Hello.' }]);
229
+ hub.npcEvents.push({ k: 'hub-npc-opening', npc: 'greeter', text: 'How is your hamster?' });
230
+ frame();
231
+ assert.deepEqual(panelLines, [{ who: 'them', text: 'How is your hamster?' }], 'a pending inspect can replace the opening without appending');
232
+ assert.deepEqual(asks, []);
233
+ handlers.send('blocked');
234
+ assert.equal(turns, 0);
235
+ inspectReject({ code: 'CAULDRON_SHARED_CHARACTER_FORBIDDEN' });
236
+ await settle();
237
+ assert.equal(canType, false);
238
+ handlers.end();
239
+ open();
240
+ assert.equal(inspections, 2, 'a refusal is retried on the next open');
241
+ inspectResolve({ participantId: 'p-a' });
242
+ await settle();
243
+ assert.equal(canType, true);
244
+ assert.deepEqual(asks, ['One?', 'Two?', 'Three?']);
245
+ await answer('One?');
246
+ const firstText = panelLines[0].text;
247
+ const lineCount = panelLines.length;
248
+ hub.npcEvents.push({ k: 'hub-npc-opening', npc: 'greeter', text: 'Too late.' });
249
+ frame();
250
+ assert.equal(panelLines[0].text, firstText, 'a greeting never replaces the opening after sending');
251
+ assert.equal(panelLines.length, lineCount);
252
+ assert.deepEqual(asks, ['Two?', 'Three?', 'Four?'], 'opening asks and more refill the chips');
253
+ const longSuggestion = "What's the most memorable thing you've seen here?";
254
+ await answer('Two?', { status: 'completed', response: 'Sure.', suggestions: ['One?', 'New?', 'New?', longSuggestion, 'Third?', 'Fourth?'] });
255
+ assert.deepEqual(asks, ['New?', longSuggestion, 'Third?'], 'suggestions win, without repeats or sent questions');
256
+ await answer('New?', { status: 'completed', response: { text: 'Yes.', suggestions: ['New?', 'Nested?'] } });
257
+ assert.deepEqual(asks, ['Nested?'], 'nested response suggestions also work');
258
+ await answer('Nested?', { status: 'completed', response: 'Yes.', suggestions: [] });
259
+ assert.deepEqual(asks, [], 'an empty suggestions array offers nothing');
260
+ handlers.send('Three?');
261
+ await settle();
262
+ const refusedOp = requests.at(-1).operationId;
263
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'A moment.', why: 'budget', op: refusedOp });
264
+ frame();
265
+ assert.equal(waiting, false, 'a matching refusal ends the wait');
266
+ assert.deepEqual(asks, ['Four?', 'Five?'], 'scripted replies refill from unused opening questions');
267
+ await runWait();
268
+ handlers.send('Four?');
269
+ await settle();
270
+ assert.notEqual(requests.at(-1).operationId, refusedOp);
271
+ for (const op of [refusedOp, undefined]) {
272
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'An older line.', why: 'unavailable', ...(op ? { op } : {}) });
273
+ frame();
274
+ assert.equal(waiting, true, 'an old or untagged line leaves the current turn waiting');
275
+ assert.deepEqual(asks, [], 'an old line cannot refill chips while a newer turn is in flight');
276
+ }
277
+ result = { status: 'completed', response: 'The newer answer.', suggestions: ['Five?'] };
278
+ await runWait();
279
+ frame();
280
+ assert.equal(waiting, false);
281
+ assert.equal(lines.at(-1), 'The newer answer.', 'the newer turn is still polled');
282
+ assert.deepEqual(asks, ['Five?']);
283
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'No turn pending.', why: 'busy' });
284
+ frame();
285
+ assert.equal(waiting, false, 'an untagged line can clear waiting when no operation is in flight');
286
+ handlers.end();
287
+ hub.npcEvents.push({ k: 'hub-npc-opening', npc: 'greeter', text: 'Closed.' });
288
+ frame();
289
+ assert.equal(panelLines[0].text, firstText, 'a closed panel ignores updates');
290
+ open();
291
+ assert.equal(canType, true, 'a successful inspect is remembered on this net');
292
+ assert.equal(inspections, 2);
293
+ assert.deepEqual(asks, opening.asks, 'a new conversation starts with unused questions');
294
+ handlers.end();
295
+ // v1.80: place offers lead every refill and may be sent again until withdrawn.
296
+ open();
297
+ const notes = (persistentAsks, npc = 'greeter') => {
298
+ hub.npcEvents.push({ k: 'hub-npc-notes', npc, prefix: null, ...(persistentAsks === undefined ? {} : { persistentAsks }) });
299
+ frame();
300
+ };
301
+ notes(['Gift?', 'Keep?']);
302
+ notes(['Someone else?'], 'other');
303
+ await answer('Gift?', { status: 'completed', response: 'Thanks.', suggestions: ['New?', 'Gift?', 'New?', 'More?'] });
304
+ assert.deepEqual(asks, ['Gift?', 'Keep?', 'New?'], 'persistent asks lead suggestions, deduped into the three-chip row');
305
+ await answer('Keep?', { status: 'completed', response: 'Yes.', suggestions: [] });
306
+ assert.deepEqual(asks, ['Gift?', 'Keep?'], 'sent persistent asks return even with no suggestions');
307
+ await answer('One?');
308
+ assert.deepEqual(asks, ['Gift?', 'Keep?', 'Two?'], 'persistent asks also lead unused opening questions');
309
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'A moment.', why: 'budget' });
310
+ frame();
311
+ assert.deepEqual(asks, ['Gift?', 'Keep?', 'Two?'], 'scripted lines use the same refill order');
312
+ notes([]);
313
+ await answer('Two?', { status: 'completed', response: 'Yes.', suggestions: ['Gift?', 'Keep?', 'One?', 'Three?'] });
314
+ assert.deepEqual(asks, ['Three?'], 'withdrawn persistent asks obey the sent-question rule again');
315
+ notes(['Gift?']);
316
+ await answer('Three?');
317
+ assert.deepEqual(asks, ['Gift?', 'Four?', 'Five?']);
318
+ notes(undefined);
319
+ await answer('Four?', { status: 'completed', response: 'Yes.', suggestions: ['Gift?', 'Five?'] });
320
+ assert.deepEqual(asks, ['Five?'], 'notes without offers also clear the latest persistent asks');
321
+ notes(['Gift?']);
322
+ handlers.end();
323
+ open();
324
+ await answer('One?');
325
+ assert.deepEqual(asks, ['Two?', 'Three?', 'Four?'], 'a new conversation has no previous persistent asks');
326
+ handlers.end();
327
+ n += 1;
328
+
329
+ // Offer changes refresh the current suggestions, but never a pending turn.
330
+ open();
331
+ const legacyRows = askRows.length;
332
+ notes(undefined);
333
+ assert.equal(askRows.length, legacyRows, 'notes without npcAsks do not enter the offer refill path');
334
+ notes(['Gift?']);
335
+ assert.deepEqual(asks, ['Gift?', 'One?', 'Two?'], 'new offers refresh the row immediately');
336
+ await answer('One?', { status: 'completed', response: 'Yes.', suggestions: ['Suggestion?', 'Other?'] });
337
+ assert.deepEqual(asks, ['Gift?', 'Suggestion?', 'Other?']);
338
+ notes([]);
339
+ assert.deepEqual(asks, ['Suggestion?', 'Other?'], 'withdrawal immediately removes the chip and keeps current suggestions');
340
+ const unchangedRows = askRows.length;
341
+ notes([]);
342
+ assert.equal(askRows.length, unchangedRows, 'unchanged offers do not redraw the row');
343
+ notes(['Gift?']);
344
+ assert.deepEqual(asks, ['Gift?', 'Suggestion?', 'Other?'], 'a renewed offer also keeps current suggestions');
345
+ handlers.send('Suggestion?');
346
+ const pendingRows = askRows.length;
347
+ notes([]);
348
+ notes(['Pending?']);
349
+ notes([]);
350
+ assert.equal(waiting, true);
351
+ assert.deepEqual(asks, [], 'offer changes keep chips hidden during a pending turn');
352
+ assert.equal(askRows.length, pendingRows, 'pending offer updates do not refill the row');
353
+ result = { status: 'completed', response: 'Yes.', suggestions: ['Other?'] };
354
+ await settle();
355
+ await runWait();
356
+ frame();
357
+ assert.deepEqual(asks, ['Other?']);
358
+ handlers.end();
359
+ n += 1;
360
+
361
+ // Unsent withdrawn offers stay out of every fallback until offered again.
362
+ open();
363
+ notes(['One?', 'Four?']);
364
+ assert.deepEqual(asks, ['One?', 'Four?', 'Two?']);
365
+ notes(['Four?']);
366
+ assert.deepEqual(asks, ['Four?', 'Two?', 'Three?'], 'replacing an offer withdraws the omitted question');
367
+ notes([]);
368
+ assert.deepEqual(asks, ['Two?', 'Three?', 'Five?'], 'unsent withdrawn asks and more are excluded immediately');
369
+ await answer('Two?', { status: 'completed', response: 'Yes.', suggestions: ['One?', 'Four?', 'Status?'] });
370
+ assert.deepEqual(asks, ['Status?'], 'top-level suggestions cannot revive withdrawn offers');
371
+ await answer('Status?', { status: 'completed', response: { text: 'Yes.', suggestions: ['Four?', 'One?', 'Nested?'] } });
372
+ assert.deepEqual(asks, ['Nested?'], 'nested suggestions cannot revive withdrawn offers');
373
+ await answer('Nested?');
374
+ assert.deepEqual(asks, ['Three?', 'Five?'], 'a later opening fallback cannot revive unsent withdrawn offers');
375
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'A moment.', why: 'budget' });
376
+ frame();
377
+ assert.deepEqual(asks, ['Three?', 'Five?'], 'scripted replies also exclude withdrawn offers');
378
+ notes(['Four?']);
379
+ assert.deepEqual(asks, ['Four?', 'Three?', 'Five?'], 'the place may re-offer a withdrawn question without reviving others');
380
+ notes([]);
381
+ assert.deepEqual(asks, ['Three?', 'Five?'], 'a re-offered question can be withdrawn again');
382
+ notes(['One?']);
383
+ assert.deepEqual(asks, ['One?', 'Three?', 'Five?']);
384
+ notes(undefined);
385
+ assert.deepEqual(asks, ['Three?', 'Five?'], 'notes without offers withdraw the previous offer too');
386
+ handlers.end();
387
+ open();
388
+ assert.deepEqual(asks, opening.asks, 'a new conversation forgets withdrawals');
389
+ handlers.end();
390
+ n += 1;
391
+
392
+ open(false);
393
+ assert.equal(canType, true, 'mindless authored conversations need no inspect');
394
+ assert.equal(inspections, 2);
395
+ const sayCount = () => sent.filter((msg) => msg.k === 'hub-npc-say').length;
396
+ handlers.send('One?');
397
+ const firstSay = sayCount();
398
+ assert.equal(waiting, true, 'an authored send waits for its reply');
399
+ assert.deepEqual(asks, []);
400
+ handlers.send('Two?');
401
+ assert.equal(sayCount(), firstSay, 'another send is blocked while waiting');
402
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'Hello.', why: 'authored' });
403
+ frame();
404
+ assert.equal(waiting, false);
405
+ assert.deepEqual(asks, ['Two?', 'Three?', 'Four?']);
406
+ handlers.send('Two?');
407
+ assert.equal(sayCount(), firstSay, 'a fast reply still leaves the server cooldown in effect');
408
+ assert.ok(asks.includes('Two?'), 'a cooldown-blocked chip is not consumed');
409
+ clock += 900;
410
+ handlers.send('Two?');
411
+ assert.equal(sayCount(), firstSay + 1);
412
+ assert.equal(waiting, true);
413
+ await runWait();
414
+ assert.equal(waiting, false, 'a dropped authored turn times out');
415
+ assert.deepEqual(asks, ['Two?', 'Three?', 'Four?'], 'the unanswered question remains available');
416
+ handlers.send('Two?');
417
+ assert.equal(sayCount(), firstSay + 2, 'the unanswered question can be retried');
418
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'Hello.', why: 'authored' });
419
+ frame();
420
+ assert.ok(!asks.includes('Two?'), 'only an answered question is used');
421
+ for (const question of ['Three?', ...opening.more]) {
422
+ clock += 900;
423
+ handlers.send(question);
424
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'Hello.', why: 'authored' });
425
+ frame();
426
+ assert.ok(!asks.includes(question));
427
+ }
428
+ assert.deepEqual(asks, [], 'no questions left means no chips');
429
+ handlers.end();
430
+ n += 1;
431
+
432
+ // A timed-out send's reply may arrive during the next question's wait.
433
+ open(false);
434
+ clock += 900;
435
+ handlers.send('One?');
436
+ const ridA = sent.at(-1).rid;
437
+ assert.equal(typeof ridA, 'string');
438
+ assert.ok(ridA.length > 0 && ridA.length <= 64);
439
+ await runWait();
440
+ assert.equal(waiting, false);
441
+ assert.ok(asks.includes('One?'));
442
+ handlers.send('Two?');
443
+ const ridB = sent.at(-1).rid;
444
+ assert.notEqual(ridB, ridA, 'each authored send has its own request id');
445
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'The late first answer.', why: 'authored', rid: ridA });
446
+ frame();
447
+ assert.equal(waiting, true, 'a late reply to A leaves B pending');
448
+ assert.deepEqual(asks, [], 'the late reply cannot refill or consume B');
449
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'The second answer.', why: 'authored', rid: ridB });
450
+ frame();
451
+ assert.equal(waiting, false, 'the matching reply acknowledges B');
452
+ assert.deepEqual(asks, ['One?', 'Three?', 'Four?'], 'only B is consumed; timed-out A stays available');
453
+ clock += 900;
454
+ handlers.send('One?');
455
+ assert.notEqual(sent.at(-1).rid, ridA, 'retrying A has a fresh request id');
456
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'The old first answer again.', why: 'authored', rid: ridA });
457
+ frame();
458
+ assert.equal(waiting, true, 'the old id cannot acknowledge a retry of the same question');
459
+ hub.npcEvents.push({ k: 'hub-npc-line', npc: 'greeter', text: 'An older server answer.', why: 'authored' });
460
+ frame();
461
+ assert.equal(waiting, false, 'a reply without rid keeps the older-server behaviour');
462
+ assert.deepEqual(asks, ['Three?', 'Four?', 'Five?']);
463
+ handlers.end();
464
+ n += 1;
465
+ } finally {
466
+ globalThis.setTimeout = later;
467
+ globalThis.clearTimeout = cancel;
468
+ if (now) {
469
+ Object.defineProperty(performance, 'now', now);
470
+ } else {
471
+ delete performance.now;
472
+ }
473
+ hub.npcEvents.length = 0;
474
+ }
475
+ }
476
+
477
+ // v1.47: the Chat prompt reads ahead, but never retries a refusal each frame.
478
+ {
479
+ const { makeTalk } = await import('../code/client/talk.js');
480
+ const { hub } = await import('../code/client/state.js');
481
+ const settle = () => new Promise((resolve) => setImmediate(resolve));
482
+ let handlers;
483
+ let inspectResolve;
484
+ let inspectReject;
485
+ let inspections = 0;
486
+ let canType;
487
+ const prompts = [];
488
+ const chrome = {
489
+ onTalk: (h) => { handlers = h; },
490
+ openTalk: (_name, options) => { canType = options.canType; },
491
+ closeTalk() {}, talkAsks() {}, talkLine() {}, talkWaiting() {},
492
+ talkTyping: (allowed) => { canType = allowed; },
493
+ talkFocused: () => false,
494
+ talkPrompt: (name, mind) => prompts.push({ name, mind }),
495
+ };
496
+ const npc = { id: 'greeter', components: { HubNpc: { name: 'Rowan', character: 'greeter' }, Transform: { x: 0, z: 1 } } };
497
+ const scene = { actorWith: () => ({ components: { Transform: { x: 0, z: 0 } } }), getActors: () => [npc] };
498
+ const net = {
499
+ send() {},
500
+ characters: { readCharacters: () => {
501
+ inspections += 1;
502
+ return new Promise((resolve, reject) => { inspectResolve = resolve; inspectReject = reject; });
503
+ } },
504
+ };
505
+ const talk = makeTalk(chrome);
506
+ const frame = () => talk.frame(scene, { net }, true);
507
+ const open = () => {
508
+ hub.npcEvents.push({ k: 'hub-npc', npc: 'greeter', name: 'Rowan', open: true, mind: true });
509
+ frame();
510
+ };
511
+ frame();
512
+ assert.deepEqual(prompts.at(-1), { name: 'Rowan', mind: true });
513
+ assert.equal(inspections, 1, 'approach reads before opening');
514
+ frame();
515
+ open();
516
+ assert.equal(inspections, 1, 'opening shares the pending approach read');
517
+ assert.equal(canType, false);
518
+ inspectReject({ code: 'CAULDRON_SHARED_CHARACTER_FORBIDDEN' });
519
+ await settle();
520
+ handlers.end();
521
+ frame();
522
+ frame();
523
+ assert.equal(inspections, 1, 'a refused approach is not polled');
524
+ open();
525
+ assert.equal(inspections, 2, 'the next open retries');
526
+ inspectResolve({ participantId: 'p-a' });
527
+ await settle();
528
+ assert.equal(canType, true);
529
+ handlers.end();
530
+ open();
531
+ assert.equal(canType, true);
532
+ assert.equal(inspections, 2, 'success is remembered');
533
+ handlers.end();
534
+ const fresh = makeTalk(chrome);
535
+ fresh.frame(scene, { net }, true);
536
+ assert.equal(inspections, 3);
537
+ inspectResolve({ participantId: 'p-a' });
538
+ await settle();
539
+ hub.npcEvents.push({ k: 'hub-npc', npc: 'greeter', name: 'Rowan', open: true, mind: true });
540
+ fresh.frame(scene, { net }, true);
541
+ assert.equal(canType, true, 'a completed approach read permits typing at once');
542
+ handlers.end();
543
+ hub.npcEvents.length = 0;
544
+ n += 1;
545
+ }
546
+
547
+ // A new session on the same connection has no conversation with this player:
548
+ // the old panel closes. A stale panel instead re-attaches once, explaining
549
+ // a refused open before closing.
550
+ {
551
+ const { makeTalk } = await import('../code/client/talk.js');
552
+ const { hub } = await import('../code/client/state.js');
553
+ const settle = () => new Promise((resolve) => setImmediate(resolve));
554
+ let handlers;
555
+ let closed = 0;
556
+ const lines = [];
557
+ const chrome = {
558
+ onTalk: (h) => { handlers = h; },
559
+ openTalk() {}, closeTalk: () => { closed += 1; }, talkAsks() {}, talkWaiting() {}, talkTyping() {},
560
+ talkLine: (who, text) => lines.push(`${who}: ${text}`),
561
+ talkFocused: () => false, talkPrompt() {},
562
+ };
563
+ const npc = { id: 'greeter', components: { HubNpc: { name: 'Rowan', character: 'greeter' }, Transform: { x: 0, z: 1 } } };
564
+ const scene = { actorWith: () => ({ components: { Transform: { x: 0, z: 0 } } }), getActors: () => [npc] };
565
+ let turns = 0;
566
+ let refuse = null;
567
+ const net = {
568
+ send() {},
569
+ characters: {
570
+ readCharacters: async () => ({ participantId: 'p-a' }),
571
+ requestCharacterTurn: async () => {
572
+ turns += 1;
573
+ if (refuse) {
574
+ throw Object.assign(new Error(refuse), { code: refuse });
575
+ }
576
+ },
577
+ },
578
+ };
579
+ const talk = makeTalk(chrome);
580
+ const open = () => {
581
+ hub.npcEvents.push({ k: 'hub-npc', npc: 'greeter', name: 'Rowan', open: true, mind: true });
582
+ talk.frame(scene, { net }, true);
583
+ };
584
+ talk.frame(scene, { net }, true);
585
+ await settle();
586
+ open();
587
+ assert.equal(talk.talking(), true);
588
+ const before = closed;
589
+ talk.reset();
590
+ assert.equal(talk.talking(), false, 'a new session closes the panel');
591
+ assert.equal(closed, before + 1);
592
+ handlers.send('hello?');
593
+ assert.equal(turns, 0, 'nothing is sent from a closed panel');
594
+ open();
595
+ refuse = 'HUB_NPC_NOT_TALKING';
596
+ handlers.send('are you there?');
597
+ await settle();
598
+ assert.equal(turns, 1);
599
+ assert.equal(talk.talking(), true, 'a stale panel waits for its re-attach');
600
+ hub.npcEvents.push({ k: 'hub-npc', npc: 'greeter', open: false, why: 'far' });
601
+ talk.frame(scene, { net }, true);
602
+ assert.equal(lines.at(-1), 'them: Lost the thread there. Tap to talk again.');
603
+ handlers.end();
604
+ open();
605
+ refuse = 'HUB_NPC_AUDIENCE';
606
+ handlers.send('and now?');
607
+ await settle();
608
+ assert.equal(talk.talking(), true, 'any other refusal keeps the panel');
609
+ handlers.end();
610
+ hub.npcEvents.length = 0;
611
+ n += 1;
612
+ }
613
+
614
+ // The real chrome changes the first node, keeping the rest of the log intact.
615
+ {
616
+ const { makeChrome } = await import('../code/client/chrome.js');
617
+ const oldDocument = globalThis.document;
618
+ const nodes = [];
619
+ const element = () => {
620
+ const node = {
621
+ style: {}, dataset: {}, children: [], textContent: '', parentNode: null,
622
+ scrollHeight: 0, scrollTop: 0, clientHeight: 0, offsetTop: 0,
623
+ get childElementCount() { return this.children.length; },
624
+ appendChild(child) { child.parentNode = this; this.children.push(child); return child; },
625
+ insertBefore(child, before) {
626
+ child.remove();
627
+ child.parentNode = this;
628
+ const index = this.children.indexOf(before);
629
+ this.children.splice(index < 0 ? this.children.length : index, 0, child);
630
+ },
631
+ replaceChildren() { this.children = []; },
632
+ remove() { if (this.parentNode) { this.parentNode.children = this.parentNode.children.filter((child) => child !== this); } },
633
+ addEventListener() {}, removeEventListener() {}, setAttribute() {}, focus() {}, blur() {},
634
+ };
635
+ nodes.push(node);
636
+ return node;
637
+ };
638
+ globalThis.document = { body: element(), createElement: element, activeElement: null };
639
+ let chrome;
640
+ try {
641
+ chrome = makeChrome({ onBack() {}, onAvatar() {}, avatarCount: 4 });
642
+ chrome.openTalk('Rowan', { mind: true, canType: false });
643
+ chrome.talkLine('them', 'First words.');
644
+ const first = nodes.find((node) => node.textContent === 'First words.');
645
+ const log = first.parentNode;
646
+ chrome.talkLine('them', 'A later line.');
647
+ const later = log.children[1];
648
+ chrome.talkOpening('Private greeting.');
649
+ assert.equal(log.children.length, 2);
650
+ assert.equal(log.children[0], first);
651
+ assert.equal(first.textContent, 'Private greeting.');
652
+ assert.equal(later.textContent, 'A later line.');
653
+ chrome.closeTalk();
654
+ chrome.talkOpening('Closed.');
655
+ assert.equal(first.textContent, 'Private greeting.');
656
+ chrome.openTalk('Other', { mind: true, canType: false });
657
+ chrome.talkLine('them', 'Other opening.');
658
+ chrome.talkOpening('Other greeting.');
659
+ assert.equal(first.textContent, 'Private greeting.', 'a new panel cannot change the old first node');
660
+ assert.ok(nodes.some((node) => node.textContent === 'Other greeting.'));
661
+ n += 1;
662
+ } finally {
663
+ chrome?.dispose();
664
+ if (oldDocument === undefined) {
665
+ delete globalThis.document;
666
+ } else {
667
+ globalThis.document = oldDocument;
668
+ }
669
+ }
670
+ }
671
+
672
+ // v1.76: approach consumes private greeting hooks, without opening a panel.
673
+ {
674
+ const { makeTalk } = await import('../code/client/talk.js');
675
+ const { hub } = await import('../code/client/state.js');
676
+ const settle = () => new Promise((resolve) => setImmediate(resolve));
677
+ let handlers;
678
+ let opened = 0;
679
+ const chrome = {
680
+ onTalk: (h) => { handlers = h; }, openTalk: () => { opened++; },
681
+ closeTalk() {}, talkAsks() {}, talkLine() {}, talkWaiting() {}, talkTyping() {},
682
+ talkFocused: () => false, talkPrompt() {},
683
+ };
684
+ const npc = { id: 'greeter', components: { HubNpc: { name: 'Rowan', character: 'greeter' }, Transform: { x: 0, z: 1 } } };
685
+ const twin = { id: 'twin', components: { HubNpc: { name: 'Twin', character: 'greeter' }, Transform: { x: 0, z: 2 } } };
686
+ const local = { x: 0, z: 0 };
687
+ const scene = { actorWith: () => ({ components: { Transform: local } }), getActors: () => [npc, twin] };
688
+ const queries = [];
689
+ let fail = false;
690
+ const net = {
691
+ send() {}, characters: { readCharacters: async (request) => {
692
+ queries.push(request);
693
+ if (fail && request.query.type === 'status') {
694
+ throw new Error('Private words must not be logged.');
695
+ }
696
+ return { characterId: 'greeter', greeting: null };
697
+ } },
698
+ };
699
+ let activeNet = net;
700
+ const talk = makeTalk(chrome);
701
+ const frame = (idle = true) => talk.frame(scene, { net: activeNet }, idle);
702
+ const hooks = (npc = 'greeter', character = 'greeter') => hub.npcEvents.push({ k: 'hub-npc-hooks', hooks: [{ npc, character }] });
703
+ const status = () => queries.filter((r) => r.query.type === 'status');
704
+ frame(); await settle();
705
+ assert.equal(queries.length, 1, 'approach still starts inspect');
706
+ hooks(); frame(false); frame(false);
707
+ assert.equal(status().length, 0, 'walking or another input panel defers the greeting');
708
+ local.z = 10; frame();
709
+ assert.equal(status().length, 0, 'far from the Chat prompt sends nothing');
710
+ local.z = 0; frame(); frame(); await settle();
711
+ assert.deepEqual(status().map((r) => r.query), [{ type: 'status', operationId: 'greeting:greeter' }]);
712
+ assert.equal(typeof status()[0].requestId, 'string');
713
+ assert.equal(opened, 0, 'the greeting read never opens chat');
714
+ hooks(); hooks('twin'); frame(); await settle();
715
+ assert.equal(status().length, 1, 'duplicate messages and shared character bodies read once');
716
+ local.z = 10; hooks('greeter', 'new-hook'); frame();
717
+ talk.reset(); local.z = 0; frame(); await settle();
718
+ assert.equal(status().length, 1, 'reset clears offered hooks');
719
+ hooks(); frame(); await settle();
720
+ assert.equal(status().length, 2, 'a fresh session may consume a newly offered hook');
721
+ local.z = 10; hooks('greeter', 'other'); frame();
722
+ activeNet = { ...net }; local.z = 0; frame(); await settle();
723
+ assert.equal(status().length, 2, 'switching nets forgets the old hooks');
724
+
725
+ // Opening first also consumes hooks that arrive from a pending inspect.
726
+ talk.reset(); frame(); await settle();
727
+ handlers.open();
728
+ hooks(); frame(); await settle();
729
+ assert.equal(status().length, 2, 'an opening request suppresses walk-up');
730
+ hub.npcEvents.push({ k: 'hub-npc', npc: 'greeter', character: 'greeter', name: 'Rowan', open: true, mind: true });
731
+ frame();
732
+ hooks(); hooks('twin'); frame();
733
+ assert.equal(status().length, 2, 'an open chat drops late hooks for the same character');
734
+ hooks('twin', 'other'); frame();
735
+ assert.equal(status().length, 2, 'an open panel never sends a walk-up read');
736
+ handlers.end(); frame();
737
+ assert.equal(status().length, 2, 'closing the panel does not revive the greeted character');
738
+
739
+ // The button press consumes hooks queued since the last frame.
740
+ talk.reset(); frame();
741
+ hooks();
742
+ handlers.open();
743
+ frame();
744
+ hub.npcEvents.push({ k: 'hub-npc', npc: 'greeter', character: 'greeter', name: 'Rowan', open: true, mind: true });
745
+ frame(); handlers.end(); frame();
746
+ assert.equal(status().length, 2, 'button press consumes queued hooks without a read');
747
+
748
+ // A refusal logs once, without details, and never retries this character.
749
+ talk.reset(); frame(); await settle();
750
+ fail = true;
751
+ const log = console.log;
752
+ const logs = [];
753
+ console.log = (...args) => logs.push(args.join(' '));
754
+ try {
755
+ hooks(); frame(); await settle();
756
+ frame(); hooks(); frame(); await settle();
757
+ assert.equal(status().length, 3);
758
+ assert.deepEqual(logs, ['[hub] NPC greeting read failed']);
759
+ } finally {
760
+ console.log = log;
761
+ }
762
+ talk.reset(); hub.npcEvents.length = 0;
763
+ n += 1;
764
+ }
765
+
98
766
  console.log(`test-chat: ${n} passed`);
767
+
768
+ // v1.90: the button prefers an in-range NPC, falls back and clears.
769
+ {
770
+ const { makeTalk } = await import('../code/client/talk.js');
771
+ const { hub } = await import('../code/client/state.js');
772
+ let prompt;
773
+ const chrome = { onTalk() {}, closeTalk() {}, talkWaiting() {}, talkPrompt: (value) => { prompt = value; } };
774
+ const net = { send() {} };
775
+ const player = { components: { Transform: { x: 0, z: 0 } } };
776
+ const rowan = { id: 'rowan', components: { HubNpc: { name: 'Rowan' }, Transform: { x: 1.3, z: 0 } } };
777
+ const vela = { id: 'vela', components: { HubNpc: { name: 'Vela' }, Transform: { x: 1.2, z: 0 } } };
778
+ const actors = [rowan, vela];
779
+ const scene = { actorWith: () => player, getActors: () => actors };
780
+ const talk = makeTalk(chrome);
781
+ const frame = () => talk.frame(scene, { net }, true);
782
+ frame();
783
+ assert.equal(prompt, 'Vela');
784
+ hub.npcEvents.push({ k: 'hub-npc-preferred', npc: 'rowan' }); frame();
785
+ assert.equal(prompt, 'Rowan');
786
+ rowan.components.Transform.x = 4; frame();
787
+ assert.equal(prompt, 'Vela');
788
+ rowan.components.Transform.x = 1.3; frame();
789
+ assert.equal(prompt, 'Rowan');
790
+ hub.npcEvents.push({ k: 'hub-npc-preferred', npc: null }); frame();
791
+ assert.equal(prompt, 'Vela');
792
+ }