castle-web-cli 0.4.234 → 0.4.236

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.
package/dist/init.js CHANGED
@@ -64,7 +64,7 @@ const BARE_SCAFFOLDS = [
64
64
  // Registry version of castle-web-sdk to inject when scaffolding from a
65
65
  // globally-installed castle-web (not from inside the workspace). Bumped
66
66
  // alongside cli/sdk version bumps.
67
- const PUBLISHED_SDK_VERSION = '0.4.49';
67
+ const PUBLISHED_SDK_VERSION = '0.4.50';
68
68
  // Range, not a pin: `castle-web-fonts` is its own package precisely so a tenth
69
69
  // face can ship without a cli release, and a caret range means an existing
70
70
  // deck's next install picks it up. Nothing here has to move when it does.
@@ -82,7 +82,7 @@
82
82
  "title": "base",
83
83
  "deckId": "yRcmH4_aYllE",
84
84
  "cardId": "zkFdingmIm3m",
85
- "publishedVersion": "2026-10-18T06:37:02.597Z",
85
+ "publishedVersion": "2026-10-18T10:34:27.709Z",
86
86
  "provides": [
87
87
  "castle-web-sdk"
88
88
  ]
@@ -1372,6 +1372,12 @@ destination session's content pack hash) and `contentUrl` (that pack's immutable
1372
1372
  URL, or null when the destination has none), or `cancelled`, `full`,
1373
1373
  `unavailable`, `not_found`, `forbidden` or `party_required` with those fields null.
1374
1374
 
1375
+ Castle lists a player at a door only once it has seen them in the place's
1376
+ session, which can take up to 15 seconds after they arrive or after their
1377
+ connection comes back from a break (an app switch, a network drop). In that
1378
+ window `go` and `jump` keep asking and answer once the player is listed, so a
1379
+ `forbidden` they return is final.
1380
+
1375
1381
  A door can also lead to a cabinet: a classic Castle deck the host plays itself.
1376
1382
  `Hub.go` then answers `status: "ok"` with `kind: "classic"` and null `url`, `nonce`
1377
1383
  and `sessionId`: there is no session to join, and the trip is already committed.
@@ -1,5 +1,6 @@
1
1
  import { CastleError } from "./errors";
2
2
  import { hostRequest, setHubEventHandler } from "./transport";
3
+ import { HUB_FORBIDDEN_RETRY_MS, rejoinedRecently } from "./hubRejoin";
3
4
  export const Hub = {
4
5
  go,
5
6
  back,
@@ -36,7 +37,22 @@ async function go(doorId, options = {}) {
36
37
  operation: "Hub.go",
37
38
  });
38
39
  }
39
- return hostRequest("hub.go", ownerUserId === undefined ? { doorId } : { doorId, ownerUserId });
40
+ return untilListed(() => hostRequest("hub.go", ownerUserId === undefined ? { doorId } : { doorId, ownerUserId }));
41
+ }
42
+ // Right after the socket rejoined its session ghost may not list the player
43
+ // yet, and answers `forbidden` until it does. `Hub.cancel` ends the wait.
44
+ let cancels = 0;
45
+ async function untilListed(ask) {
46
+ const asked = cancels;
47
+ for (;;) {
48
+ const result = await ask();
49
+ if (result.status !== "forbidden" || !rejoinedRecently())
50
+ return result;
51
+ await new Promise((resolve) => setTimeout(resolve, HUB_FORBIDDEN_RETRY_MS));
52
+ if (cancels !== asked) {
53
+ return { status: "cancelled", url: null, nonce: null, sessionId: null, bundleHash: null, contentUrl: null };
54
+ }
55
+ }
40
56
  }
41
57
  async function back() {
42
58
  return hostRequest("hub.back", {});
@@ -99,7 +115,7 @@ async function jump(userId) {
99
115
  operation: "Hub.jump",
100
116
  });
101
117
  }
102
- return hostRequest("hub.jump", { userId });
118
+ return untilListed(() => hostRequest("hub.jump", { userId }));
103
119
  }
104
120
  async function report(userId, reason) {
105
121
  if (typeof userId !== "string" || userId.length === 0) {
@@ -135,6 +151,7 @@ async function reportChat(messageId, options) {
135
151
  return hostRequest("hub.reportChat", { messageId, ...(options?.block === true ? { block: true } : {}) });
136
152
  }
137
153
  async function cancel() {
154
+ cancels += 1;
138
155
  return hostRequest("hub.cancel", {});
139
156
  }
140
157
  const backListeners = new Set();
@@ -0,0 +1,4 @@
1
+ export declare const HUB_ROSTER_LAG_MS = 16000;
2
+ export declare const HUB_FORBIDDEN_RETRY_MS = 1000;
3
+ export declare function noteSessionRejoined(): void;
4
+ export declare function rejoinedRecently(): boolean;
@@ -0,0 +1,15 @@
1
+ // Ghost's source check for a door reads the session's heartbeat roster, which
2
+ // drops a player who was away and takes up to 15 s to list them again. The host
3
+ // waits that out after an arrival it saw; a socket that reconnected to the same
4
+ // session is one only the deck sees, so the deck waits it out itself.
5
+ export const HUB_ROSTER_LAG_MS = 16_000;
6
+ export const HUB_FORBIDDEN_RETRY_MS = 1_000;
7
+ let rejoinedAt = null;
8
+ // Monotonic where there is one: a wall-clock correction must not stretch or cut the wait.
9
+ const now = () => globalThis.performance?.now() ?? Date.now();
10
+ export function noteSessionRejoined() {
11
+ rejoinedAt = now();
12
+ }
13
+ export function rejoinedRecently() {
14
+ return rejoinedAt !== null && now() - rejoinedAt < HUB_ROSTER_LAG_MS;
15
+ }
@@ -3,6 +3,7 @@ import { BINARY_MESSAGE_TAG, isBinaryPayload, MAX_CLIENT_FRAME_BYTES, toUint8Arr
3
3
  import { hostRequest } from "./transport";
4
4
  import { MultiplayerVoiceImpl } from "./multiplayerVoice";
5
5
  import { ReconnectBudget } from "./reconnectBudget";
6
+ import { noteSessionRejoined } from "./hubRejoin";
6
7
  const KEEPALIVE_INTERVAL_MS = 25_000;
7
8
  const HELLO_TIMEOUT_MS = 10_000;
8
9
  const RECONNECT_BUDGET_MS = 30_000;
@@ -205,6 +206,7 @@ class MultiplayerConnectionImpl {
205
206
  pongExtensionUsed = false;
206
207
  pongDeadline = null;
207
208
  reAcquisitionUsed = false;
209
+ greeted = false;
208
210
  recovering = false;
209
211
  reconnectBudget = null;
210
212
  hubSettled = false;
@@ -580,6 +582,11 @@ class MultiplayerConnectionImpl {
580
582
  });
581
583
  }
582
584
  acceptHello(frame) {
585
+ // A later hello is a rejoin the host never hears of; doors wait out the
586
+ // roster lag after it (hubRejoin.ts).
587
+ if (this.greeted)
588
+ noteSessionRejoined();
589
+ this.greeted = true;
583
590
  this.currentPlayerId = frame.playerId;
584
591
  this.currentSessionId = frame.sessionId;
585
592
  // Diagnostics never decide whether a hello is accepted. Missing or malformed
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "castle.base": {
26
26
  "deckId": "yRcmH4_aYllE",
27
- "version": "2026-10-18T06:37:02.597Z"
27
+ "version": "2026-10-18T10:34:27.709Z"
28
28
  }
29
29
  },
30
30
  "autoUpdateWhenImported": true,
@@ -533,6 +533,16 @@ export function makeActionOverflow({ root, edgeMax = false, readSafeInsets = nul
533
533
  },
534
534
  watch,
535
535
  invalidate: schedule,
536
+ // v1.152: the safe-layout pass has just placed the controls the rail
537
+ // avoids (Act/Jump arriving restacks the column). Place the rail against
538
+ // those final boxes in the same pass, so neither the next frame nor a
539
+ // debug report shows it over them; layout() falls back to More/Actions or
540
+ // hides it when nothing clears. An unchanged layout key costs one read.
541
+ settle() {
542
+ if (disposed || !canAct || !items.length) {return;}
543
+ if (open) {schedule(); return;}
544
+ layout();
545
+ },
536
546
  cancel: () => closeSheet(),
537
547
  isOpen: () => open,
538
548
  dispose() {
@@ -3192,7 +3192,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
3192
3192
  }
3193
3193
  if (safeInsets) {
3194
3194
  safeLayout = makeSafeLayout({ root, hud: () => hud, entries: surfaces, onLayout: () => {
3195
- if (actionOverflow && actionOverflowObstacles) {actionOverflow.reconcileWatch(actionOverflowObstacles()); actionOverflow.invalidate();}
3195
+ if (actionOverflow && actionOverflowObstacles) {actionOverflow.reconcileWatch(actionOverflowObstacles()); actionOverflow.settle();}
3196
3196
  } });
3197
3197
  debugLayout = () => { safeLayout.flush(); worldLayout?.flush(); return safeLayout.report(); };
3198
3198
  (globalThis.castleHub ??= {}).layout = debugLayout;
@@ -256,15 +256,6 @@ export function makeSafeLayout({ root, entries, view = globalThis.window, hud =
256
256
  if (final && !entry.transient && kind !== 'hud' && kind !== 'label' && kind !== 'pointer') {controls.push(final);}
257
257
  if (final && entry.transient) {transient.push(final);}
258
258
  }
259
- const boxes = [];
260
- for (const entry of current) {
261
- const reported = entry.reportNodes?.() ?? [{ node: entry.node, id: entry.id, kind: entry.kind }];
262
- for (const item of reported) {
263
- const box = visibleRect(item.node);
264
- if (box) {boxes.push({ id: item.id, kind: item.kind, x: box.left, y: box.top, w: box.width, h: box.height });}
265
- }
266
- }
267
- last = { view: viewport, reserved, boxes };
268
259
  sizes?.disconnect();
269
260
  sizes?.observe(root);
270
261
  sizes?.observe(probe);
@@ -278,7 +269,18 @@ export function makeSafeLayout({ root, entries, view = globalThis.window, hud =
278
269
  else {observer.observe(node, { subtree: true, childList: true, attributes: true, characterData: true, attributeOldValue: true, characterDataOldValue: true });}
279
270
  }
280
271
 
272
+ // v1.152: the action rail settles against the final controls here, so
273
+ // the report is read after it.
281
274
  onLayout();
275
+ const boxes = [];
276
+ for (const entry of current) {
277
+ const reported = entry.reportNodes?.() ?? [{ node: entry.node, id: entry.id, kind: entry.kind }];
278
+ for (const item of reported) {
279
+ const box = visibleRect(item.node);
280
+ if (box) {boxes.push({ id: item.id, kind: item.kind, x: box.left, y: box.top, w: box.width, h: box.height });}
281
+ }
282
+ }
283
+ last = { view: viewport, reserved, boxes };
282
284
  return last;
283
285
  }
284
286
  watch(root);
@@ -649,7 +649,7 @@ function open(h, n, playerId, npcId) {
649
649
  const placed = openingOf(h, n, npc, playerId, greeting, talking.conversation);
650
650
  // v1.148: an under-13 speaker taps the place's own authored asks (its
651
651
  // answers, never a mind turn) ahead of any bundle chips.
652
- const taps = mind && under13(h, playerId) && !choicesOnly(h, playerId) && placed?.authored ? placed.asks : null;
652
+ const taps = mind && under13(h, playerId) && placed?.authored ? placed.asks : null;
653
653
  const child = taps ? null : bundled;
654
654
  state.taps = taps;
655
655
  // v1.46: a mind speaks first even where the place gives it no words.
@@ -1082,7 +1082,7 @@ function authoredSay(h, n, playerId, npcId, text, rid) {
1082
1082
  if (taps) {
1083
1083
  text = text.trim();
1084
1084
  }
1085
- if (choicesOnly(h, playerId)) {
1085
+ if (!taps && choicesOnly(h, playerId)) {
1086
1086
  text = text.trim();
1087
1087
  if (!CHILD_ASKS.includes(text)) {
1088
1088
  return;
@@ -140,7 +140,7 @@ reading the saved deck, treats the same list as no unlocks at all.
140
140
  | `resumeArrivalPose` | true | v1.117, optional per place: preserve only the last server pose/facing for a same-player-id, same signed-in account reconnect strictly within 60 wall-clock seconds. Ordinary immediate `leave` and fresh `arrive` still run; the pose replaces normal placement after `arrive`. Result places also require `resume: true`. Cannot combine with `resume: { keep: true }`, `resumePose`, or `houseResume`. Server-only; absent leaves state, lifecycle and wire bytes unchanged. See §12. |
141
141
  | `resumePose` | true | v1.98, per non-result place only: retain a same-id visit and its last pose/facing for strictly less than five wall-clock minutes, restoring before hello replay or the deck step. No leave/arrive on retention; explicit kit travel, expiry and shutdown still leave, and new IDs may restore a server-stored pose for the same account/place within ten minutes of departure; kit travel clears it. Absent: no retention state or behavior change. Server-only; no new wire fields. See §12. |
142
142
  | `talkLog` | true | v1.101, per place: NPC talk input and replies append to the platform’s private indefinite archive. Authored answers/openings wait for durable acknowledgment; model input/reply commit with their jobs. No player read API or TTL. Requires a host/runtime that offers transcript support; unavailable writes stop the answer. Absent key performs no archive requests and preserves existing protocol. |
143
- | `under13Choices` | true | (v1.142) Published mind `childAsks` take precedence in every place (§13); otherwise v1.101, per place: NPC conversations for a player whose trusted server identity has `under13 === true` offer three canned lines and hide the text field. Both authored and model admission paths reject other words. Missing age stamp defaults false. Absent key preserves existing UI and protocol bytes; no client age inference. |
143
+ | `under13Choices` | true | Authored mind taps lead both published `childAsks` and legacy choices, including here (v1.150, §13). Otherwise published mind `childAsks` take precedence in every place (v1.142); otherwise v1.101, per place: NPC conversations for a player whose trusted server identity has `under13 === true` offer three canned lines and hide the text field. Both authored and model admission paths reject other words. Missing age stamp defaults false. Absent key preserves existing UI and protocol bytes; no client age inference. |
144
144
  | `freshFriends` | true | v1.99, per place: positive and negative friend permissions expire after 31 seconds. Expired entries revalidate before returning a friend; refusal, malformed reply or a 900 ms timeout returns no friends. The shared read latch preserves the 31-second minimum read gap. Server-only `hub.freshFriends === true` is exposed only in opted-in places; absent keys retain existing cache, API and wire behavior. |
145
145
  | `menu` | boolean | v1.79, a place's (`hub.menu` or `hub.places.<id>.menu`): only `true` enables a private place menu (§9). Any other value is a manifest error. Absent: no API, menu hook lookup, private state, chrome, message, snapshot or delta key; existing wire bytes stay identical. |
146
146
  | `ask` | boolean | v1.75, a place's (`hub.ask` or `hub.places.<id>.ask`): only `true` enables a private text prompt (§9). Any other value is a manifest error. Absent: no API, answer hook lookup, private state, chrome, message, snapshot or delta key; existing behavior and wire bytes stay identical. |
@@ -1631,7 +1631,10 @@ Safe placement persists through CSS custom properties; animation frames do not
1631
1631
  restore, measure or reapply it. Insets are read on initialization and viewport
1632
1632
  resize/orientation/visual-viewport events. DOM changes coalesce into keep-out
1633
1633
  passes at most twice per second. Loading-cover changes settle before paint;
1634
- explicit debug reports still measure synchronously.
1634
+ explicit debug reports still measure synchronously. v1.152: the action rail is
1635
+ placed in the same pass, against the controls' final boxes, so a column that
1636
+ restacks (Act/Jump arriving) never leaves the rail over it for a frame or a
1637
+ report.
1635
1638
 
1636
1639
  1. Edge-anchored chrome keeps `max(its existing margin, env(safe-area-inset-*))`
1637
1640
  on that edge. This includes People/Doors, Character, the action column and
@@ -3638,8 +3641,9 @@ These additions remain within `hub.contract: 1`.
3638
3641
 
3639
3642
  **Authored taps (v1.148).** Where `npcOpening` returns `authored: true` with
3640
3643
  asks, a speaker whose trusted identity has `under13 === true`, talking to a
3641
- mind (in a place without `under13Choices`), receives those asks as
3642
- `choices: string[]` with `authoredChoices: true`, ahead of any bundle chips.
3644
+ mind, receives those asks as `choices: string[]` with `authoredChoices: true`,
3645
+ ahead of any bundle chips and legacy choices. This also applies in
3646
+ `under13Choices` places (v1.150).
3643
3647
  The panel shows them as tap-only chips, with no text box and no 13+ hint.
3644
3648
  A tap displays its words and sends `hub-npc-say`: the kit admits exactly one
3645
3649
  of that open's asks from that speaker and answers it through `npcLine` with
@@ -4278,6 +4282,7 @@ a deck written before them remains valid.
4278
4282
  | date | change |
4279
4283
  | --- | --- |
4280
4284
  | 2026-10-17 (v1.147) | §5 a joining player's body without a readable saved pose starts on the scene's spawn itself (its x and z, at the v1.48 standing height), not on the multiplayer spawn ring 1.1 m around it. The client starts its own body at the spawn; on the live Town the first WORLD snapped it to its ring slot, and the kit's arrival row back at the spawn then reached it as a correction under the client's 4 m snap distance, eased a quarter of the way a frame: a 1.1 m glide just after the cover lifted (3 of 5 captures, web and TECNO). Players waiting together share the spot until the arrival row spreads them; the row, the v1.40 settle and every later placement are unchanged. Saved and resumed poses are unchanged. A default in every hub place; no key, nothing new sent. |
4285
+ | 2026-10-18 (v1.150) | §12 and §13 authored mind taps also apply in `under13Choices` places: an under-13 speaker receives the place's authored asks ahead of both bundle `childAsks` and the three legacy choices. A matching trimmed `hub-npc-say` is answered through `npcLine` `why: 'authored'`; legacy strings outside those taps are ignored, and mind turns remain refused with `HUB_NPC_CHOICE_REQUIRED`. Mind-less NPCs, minds without authored asks, adults and unknown ages are unchanged. Within `hub.contract: 1`. |
4281
4286
  | 2026-10-17 (v1.148) | §12 and §13 authored taps: `npcOpening` may return `authored: true`, meaning the place answers its asks through `npcLine` `why: 'authored'`. A mind's open for a speaker with trusted `under13 === true` then carries those asks as `choices: string[]` with `authoredChoices: true`, ahead of bundle `childAsks`; a tap goes by `hub-npc-say` to the place's authored line, never a mind turn or ghost, and the kit refuses that speaker's mind turns on that open. Chips clear after the place answers. Over 13s and opens without `authored` are unchanged. Within `hub.contract: 1`. |
4282
4287
  | 2026-10-17 (v1.145) | §12 `resumePose`: a retained signed-in visit keeps its private visibility and companion through the drop (gap-time calls taken, not sent) and replays both to the same account on return; another account gets clears, guests and expiry unchanged. Fixes Town masks and Chirp lost after a same-id token reconnect. Server-only; no manifest or wire change. |
4283
4288
  | 2026-10-17 (v1.146) | Invite a friend rail: when the host's `Hub.canInvite` answer names the account its links belong to (`userId`, newer hosts: a web guest's included), the rail is offered only while that account is this socket's own player; a host that names none is checked against `User.getCurrent` as before, which has no guest account. No manifest or wire change. |
@@ -0,0 +1,118 @@
1
+ // Real CSS geometry for the safe-inset action rail in a crowded Town HUD:
2
+ // a five-item Today checklist wrapping to two lines, Invite/Market offers, a
3
+ // partner's talk prompt beside the player and the snapped avatar reserve, all
4
+ // under hub.act. When Act/Jump arrive (a talk or trip ends) the column
5
+ // restacks, and a layout report taken at once must already show the rail
6
+ // clear of them, labels readable (v1.152). Run with CHROME pointing to the QA
7
+ // browser (and BROWSER_WS when using a remote GPU browser).
8
+ import assert from 'node:assert/strict';
9
+ import { readFile } from 'node:fs/promises';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { chromium } from 'playwright-core';
12
+ import { launchChromium, logRenderer } from '../../../experiments/hub-town/qa/launch.mjs';
13
+
14
+ const root = new URL('../../../', import.meta.url);
15
+ const source = await readFile(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
16
+ const setup = source.slice(source.indexOf(' this.chrome.setWorldLabelFocus'), source.indexOf(' Avatar.load(scene);'));
17
+ const OFFERS = [
18
+ { id: 'invite-friend', label: 'Invite a friend' }, { id: 'market-looks', label: 'Market looks' },
19
+ ];
20
+ const PROMPT = ['Play Gem Rush', 'Stamp your card (0/4)', 'Water the garden', 'Game with a friend (extra)', 'Sit with a friend (extra)']
21
+ .map(item => `○\u00a0${item.replaceAll(' ', '\u00a0')}`).join(' ');
22
+ const browser = await launchChromium(chromium, { executablePath: process.env.CHROME });
23
+ try {
24
+ const page = await browser.newPage();
25
+ await page.route('http://layout.test/**', async route => {
26
+ const path = new URL(route.request().url()).pathname;
27
+ if (path === '/') return route.fulfill({ contentType: 'text/html', body: '<script type="importmap">{"imports":{"three":"/node_modules/three/build/three.module.js"}}</script><body style="margin:0"></body>' });
28
+ const url = new URL(`.${path}`, root);
29
+ assert(fileURLToPath(url).startsWith(fileURLToPath(root)));
30
+ await route.fulfill({ contentType: 'text/javascript', body: await readFile(url, 'utf8') });
31
+ });
32
+ for (const [width, height] of [[844, 390], [390, 844], [1440, 900]]) {
33
+ await page.setViewportSize({ width, height });
34
+ await page.goto('http://layout.test/');
35
+ await logRenderer(page, 'action rail crowded');
36
+ const result = await page.evaluate(async ({ setup, OFFERS, PROMPT }) => {
37
+ const { makeChrome } = await import('/kits/hub-game/code/client/chrome.js');
38
+ const { overlaps } = await import('/kits/hub-game/code/client/safeLayout.js');
39
+ const { makeAct } = await import('/kits/hub-game/code/client/act.js');
40
+ const { hub } = await import('/kits/hub-game/code/client/state.js');
41
+ const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {}, safeInsets: true });
42
+ chrome.soundControl(true, { volume: 0.7, muted: false }, { onMuted() {}, onVolume() {} });
43
+ chrome.showPicker(true, 0);
44
+ chrome.setEmotes([['wave', '👋']]); chrome.setSay({ reactions: [], phrases: [] });
45
+ const scene = { persistent: {}, three: { renderer: { domElement: { parentElement: document.body } } } };
46
+ const Hub = { deck: { safeInsets: false, act: true }, hub: {} };
47
+ const context = { chrome };
48
+ hub.place = { id: 'main', act: true };
49
+ hub.prompts = [{ id: 'partner', verb: 'Talk to Juniper about the shared garden plot' }];
50
+ const partner = { id: 'partner', components: { HubNpc: { name: 'Juniper' }, Transform: { x: 0.6, y: 1, z: 0 } } };
51
+ const act = makeAct(chrome, { perform() {} }, { prepare() {} });
52
+ Object.assign(scene, { getActors: () => [partner], getActor: () => partner, moveInput: { consumeJump() {} } });
53
+ scene.three.camera = { position: { clone: () => ({ set() { return this; }, project: () => ({ x: 0.08, y: -0.1, z: 0 }) }) } };
54
+ const local = { components: { Transform: { x: 0, y: 1, z: 0 } } };
55
+ // The player stands just right of centre, as with a partner beside them.
56
+ let avatar = { left: innerWidth * 0.5 - 30, right: innerWidth * 0.5 + 40, top: innerHeight * 0.3, bottom: innerHeight * 0.62 };
57
+ let can = false, canAct = true;
58
+ const draw = () => {
59
+ new Function('Hub', 'scene', 'worldLabelFocus', setup).call(context, Hub, scene, () => false);
60
+ chrome.setHud({ title: 'Town', text: PROMPT }, null);
61
+ chrome.grabPrompt(null); chrome.sitPrompt(null); chrome.talkPrompt(null);
62
+ chrome.setWorldAvatar(avatar);
63
+ act.frame(scene, { net: { selfId: () => 'p', send() {} } }, local, can);
64
+ chrome.layoutInteractionRail();
65
+ chrome.setActions(OFFERS, () => {}, canAct, 1, true);
66
+ chrome.frameSafeInsets?.();
67
+ };
68
+ // The engine's cached cadence: frames, observer delivery and the rail's
69
+ // own 500 ms throttle, with no forced debug flush before measuring.
70
+ const paint = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
71
+ const settle = async () => {
72
+ for (let round = 0; round < 3; round++) {
73
+ for (let frame = 0; frame < 4; frame++) {draw(); await paint();}
74
+ await new Promise(resolve => setTimeout(resolve, 550));
75
+ }
76
+ for (let frame = 0; frame < 6; frame++) {draw(); await paint();}
77
+ };
78
+ await settle();
79
+ // The Act pair arrives (a talk or trip ends) and the QA capture asks
80
+ // for the layout report at once, then reads the frame: the rail must
81
+ // already clear the pair's final place.
82
+ can = true; draw(); await paint();
83
+ // chrome.layout() is a single flush; castleHub.layout() flushes twice.
84
+ const report = chrome.layout();
85
+ const shown = node => node && node.getBoundingClientRect().width > 0 && getComputedStyle(node).display !== 'none' && getComputedStyle(node).visibility !== 'hidden';
86
+ const box = node => { const r = node.getBoundingClientRect(); return { left: r.left, right: r.right, top: r.top, bottom: r.bottom }; };
87
+ const rail = [...document.querySelectorAll('[data-hub="action-rail"] button')].filter(shown).map(node => ({ name: node.textContent, ...box(node) }));
88
+ const pair = ['act', 'jump'].map(kind => document.querySelector(`[data-hub-act="${kind}"]`)).filter(shown);
89
+ const controls = pair.map(node => ({ name: node.textContent, ...box(node),
90
+ // The label is readable when its own centre takes the tap.
91
+ reachable: node.contains(document.elementFromPoint((box(node).left + box(node).right) / 2, (box(node).top + box(node).bottom) / 2)) }));
92
+ const hits = [];
93
+ for (const offer of rail) for (const control of controls) if (overlaps(offer, control)) hits.push([offer.name, control.name]);
94
+ const prompt = document.querySelector('[data-hub="hud-prompt"]');
95
+ const promptHits = rail.filter(offer => overlaps(offer, box(prompt))).map(offer => offer.name);
96
+ // The report the capture reads agrees with the frame.
97
+ const reported = id => report.boxes.filter(b => b.id === id || b.id.startsWith(`${id}:`)).map(b => ({ name: b.id, left: b.x, top: b.y, right: b.x + b.w, bottom: b.y + b.h }));
98
+ const reportRail = reported('action-overflow');
99
+ const reportHits = [];
100
+ for (const offer of reportRail) for (const control of [...reported('act'), ...reported('jump')]) if (overlaps(offer, control)) reportHits.push([offer.name, control.name]);
101
+ const reportStale = reportRail.some(r => Math.abs(r.top - box(document.querySelector('[data-hub="action-rail"]')).top) > 0.5);
102
+ const outside = rail.filter(r => r.left < 0 || r.top < 0 || r.right > innerWidth || r.bottom > innerHeight).map(r => r.name);
103
+ act.dispose?.(); chrome.dispose();
104
+ return { rail, controls, hits, promptHits, outside, reportHits, reportStale, reportRail: reportRail.length };
105
+ }, { setup, OFFERS, PROMPT });
106
+ const label = `${width}x${height}`;
107
+ assert(result.rail.length > 0, `${label}: the rail shows at least one entry`);
108
+ assert.equal(result.controls.length, 2, `${label}: Act and Jump measured`);
109
+ assert.deepEqual(result.hits, [], `${label}: rail clears Act and Jump`);
110
+ assert(result.controls.every(control => control.reachable), `${label}: Act and Jump labels take their own taps`);
111
+ assert(result.reportRail > 0, `${label}: the report lists the rail`);
112
+ assert.deepEqual(result.reportHits, [], `${label}: reported rail clears Act and Jump`);
113
+ assert.equal(result.reportStale, false, `${label}: report matches the drawn rail`);
114
+ assert.deepEqual(result.promptHits, [], `${label}: rail clears the HUD prompt`);
115
+ assert.deepEqual(result.outside, [], `${label}: rail inside the viewport`);
116
+ console.log(`${label}: rail ${result.rail.map(r => `${r.name}@${Math.round(r.left)},${Math.round(r.top)}`).join(' ')}; act/jump clear`);
117
+ }
118
+ } finally { await browser.close(); }
@@ -2123,7 +2123,7 @@ async function talkRig(options, run) {
2123
2123
  await settle();
2124
2124
  };
2125
2125
  clearClientHub();
2126
- const w = world({ childAsks: options.childAsks, ...(options.name ? { greeterName: options.name } : {}), 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' });
2127
2127
  w.at('p1', 0, 2);
2128
2128
  if (options.child) {
2129
2129
  w.h.place.under13Choices = true;
@@ -2447,6 +2447,104 @@ await test('v1.148: a mind with authored taps hears only those taps, and refuses
2447
2447
  assert.deepEqual(w.lines.filter((l) => l.why === 'authored').map((l) => l.text), ["I'll look myself"]);
2448
2448
  });
2449
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
+
2450
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) => {
2451
2549
  const reopen = async () => { r.handlers.end(); r.net.send({ k: 'hub-npc-open', npc: r.npc }); r.frame(); await r.settle(); };
2452
2550
  assert.equal(r.typing(), false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.234",
3
+ "version": "0.4.236",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/castle-xyz/castle-experimental-web.git"