castle-web-cli 0.4.207 → 0.4.209
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/api.d.ts +5 -0
- package/dist/castle-host/host.js +151 -0
- package/dist/castleJson.d.ts +4 -0
- package/dist/castleJson.js +3 -1
- package/dist/devSessionServer.js +1 -0
- package/dist/editorConfig.d.ts +12 -0
- package/dist/editorConfig.js +72 -6
- package/dist/ide.d.ts +18 -0
- package/dist/ide.js +44 -1
- package/dist/init.js +1 -1
- package/dist/native/loop.js +1 -1
- package/dist/native/playtest-executor.js +36 -4
- package/dist/native/playtest-remote.d.ts +1 -0
- package/dist/native/playtest-remote.js +61 -5
- package/dist/native/playtest.d.ts +35 -2
- package/dist/native/playtest.js +162 -18
- package/dist/platformDoc.d.ts +1 -0
- package/dist/platformDoc.js +24 -3
- package/dist/playUrl.d.ts +3 -0
- package/dist/playUrl.js +12 -0
- package/dist/save-deck.js +1 -0
- package/dist/shell/assets/{index-b_bebkRb.css → index-BCrgYh76.css} +1 -1
- package/dist/shell/assets/{index-C6SXXPwm.js → index-DzLbNBc7.js} +68 -68
- package/dist/shell/index.html +2 -2
- package/kits/base/CLAUDE.md +1 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +70 -7
- package/kits/base/sdk/castle.d.ts +1 -0
- package/kits/base/sdk/commands.d.ts +48 -0
- package/kits/base/sdk/commands.js +25 -0
- package/kits/base/sdk/multiplayer.d.ts +3 -0
- package/kits/base/sdk/multiplayer.js +13 -0
- package/kits/base/sdk/multiplayerVoice.d.ts +67 -0
- package/kits/base/sdk/multiplayerVoice.js +309 -0
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +15 -1
- package/kits/multiplayer-2d/castle.json +2 -2
- package/kits/multiplayer-2d/code/systems/multiplayer.js +7 -1
- package/kits/multiplayer-3d/castle.json +2 -2
- package/kits/multiplayer-3d/code/systems/multiplayer.js +8 -4
- package/kits/physics-2d/castle.json +1 -1
- package/kits/physics-2d/editors/SceneEditor.jsx +18 -4
- package/kits/physics-2d/systems/media.js +3 -5
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/engine3d/PxModelEditor.jsx +2 -2
- package/kits/physics-3d/engine3d/pxmodel.js +7 -0
- package/kits/real-time/CLAUDE.md +3 -0
- package/kits/real-time/castle.json +1 -1
- package/kits/real-time/code/client/connection.js +17 -2
- package/kits/real-time/code/client/gameHooks.js +5 -0
- package/kits/real-time/code/client/joinOverlay.js +23 -5
- package/kits/real-time/code/client/messages.js +4 -0
- package/kits/real-time/code/server/persist.js +19 -10
- package/kits/real-time/code/server/session.js +19 -0
- package/package.json +2 -2
package/dist/api.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export type BrowserOperation = {
|
|
|
21
21
|
durationMs?: number;
|
|
22
22
|
}>;
|
|
23
23
|
screenshots: number[];
|
|
24
|
+
input?: 'touch';
|
|
25
|
+
playFile?: string;
|
|
24
26
|
} | {
|
|
25
27
|
kind: 'cover';
|
|
26
28
|
};
|
|
@@ -142,6 +144,9 @@ export declare function createCauldronServerBundleUploadConfig(deckId: string):
|
|
|
142
144
|
export interface CauldronServerConfig {
|
|
143
145
|
tickRate: number;
|
|
144
146
|
maxPlayers: number;
|
|
147
|
+
voice: {
|
|
148
|
+
enabled: boolean;
|
|
149
|
+
};
|
|
145
150
|
}
|
|
146
151
|
export interface CauldronServerBundleResult {
|
|
147
152
|
deckId: string;
|
package/dist/castle-host/host.js
CHANGED
|
@@ -40,6 +40,10 @@ const COMMAND_NAMES = [
|
|
|
40
40
|
"portal.info",
|
|
41
41
|
"haptics.play",
|
|
42
42
|
"multiplayer.getSession",
|
|
43
|
+
"voice.getState",
|
|
44
|
+
"voice.requestJoin",
|
|
45
|
+
"voice.leave",
|
|
46
|
+
"voice.setMix",
|
|
43
47
|
"characters.open",
|
|
44
48
|
"characters.send",
|
|
45
49
|
"characters.status",
|
|
@@ -79,6 +83,29 @@ function isCommandName(value) {
|
|
|
79
83
|
function isPlatformCommand(command) {
|
|
80
84
|
return PLATFORM_COMMAND_NAMES.includes(command);
|
|
81
85
|
}
|
|
86
|
+
// What a host posts to the deck (web: postMessage to the iframe; mobile:
|
|
87
|
+
// window.__castleSdkHost.receive) for a voice state change or a new set of speakers.
|
|
88
|
+
export function voiceEventEnvelope(event) {
|
|
89
|
+
return { castleSdk: 1, voice: event };
|
|
90
|
+
}
|
|
91
|
+
const CAULDRON_VOICE_TOKEN_QUERY = `query CastleCauldronVoiceToken($sessionId: ID!, $deckId: ID!, $env: String) {
|
|
92
|
+
getCauldronVoiceToken(sessionId: $sessionId, deckId: $deckId, env: $env) {
|
|
93
|
+
available
|
|
94
|
+
reason
|
|
95
|
+
url
|
|
96
|
+
token
|
|
97
|
+
roomName
|
|
98
|
+
blockedUserIds
|
|
99
|
+
}
|
|
100
|
+
}`;
|
|
101
|
+
// For a host's voice implementation: a LiveKit token for the session's room, issued
|
|
102
|
+
// only if the signed-in player may be in it. Tokens last about a minute and only gate
|
|
103
|
+
// the join, so fetch one right before connecting.
|
|
104
|
+
export async function fetchCauldronVoiceToken(gql, ctx, sessionId, env) {
|
|
105
|
+
const deckId = requireDeckId(ctx, "voice.requestJoin");
|
|
106
|
+
const data = await graphql(gql, CAULDRON_VOICE_TOKEN_QUERY, { sessionId, deckId, env: env ?? null }, "voice.requestJoin");
|
|
107
|
+
return data.getCauldronVoiceToken;
|
|
108
|
+
}
|
|
82
109
|
class HostCommandError extends Error {
|
|
83
110
|
code;
|
|
84
111
|
command;
|
|
@@ -151,6 +178,14 @@ function runCommand(ctx, command, params, caps, options) {
|
|
|
151
178
|
return passHas(ctx, params, caps);
|
|
152
179
|
case "multiplayer.getSession":
|
|
153
180
|
return multiplayerGetSession(ctx, params, caps);
|
|
181
|
+
case "voice.getState":
|
|
182
|
+
return voiceGetState(ctx, params, caps);
|
|
183
|
+
case "voice.requestJoin":
|
|
184
|
+
return voiceRequestJoin(ctx, params, caps, options.signal);
|
|
185
|
+
case "voice.leave":
|
|
186
|
+
return voiceLeave(ctx, params, caps);
|
|
187
|
+
case "voice.setMix":
|
|
188
|
+
return Promise.resolve(voiceSetMix(ctx, params, caps));
|
|
154
189
|
case "characters.open":
|
|
155
190
|
return charactersOpen(ctx, params, gql);
|
|
156
191
|
case "characters.send":
|
|
@@ -265,6 +300,122 @@ async function passHas(ctx, params, caps) {
|
|
|
265
300
|
const match = (data.passesForDeck ?? []).find((p) => p?.passId === passId);
|
|
266
301
|
return { hasPass: match?.isActive === true };
|
|
267
302
|
}
|
|
303
|
+
// A session id is ghost's: a deck id plus a short suffix, or a nanoid.
|
|
304
|
+
const VOICE_SESSION_ID_MAX_LENGTH = 256;
|
|
305
|
+
// A room holds at most 24 players; anything past this is a confused deck.
|
|
306
|
+
const VOICE_MIX_MAX_ENTRIES = 64;
|
|
307
|
+
const VOICE_JOIN_STATUSES = ["joined", "declined", "unavailable"];
|
|
308
|
+
// After the player declines, a deck asking again within this long gets "declined"
|
|
309
|
+
// without another prompt, so a deck can't nag.
|
|
310
|
+
export const VOICE_DECLINE_COOLDOWN_MS = 10_000;
|
|
311
|
+
// Keys a deck could use to reach Object.prototype through a plain object.
|
|
312
|
+
const RESERVED_MIX_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
313
|
+
const voiceJoinsInFlight = new Map();
|
|
314
|
+
const voiceDeclinedAt = new Map();
|
|
315
|
+
const HOST_VOICE_STATES = ["unavailable", "off", "joining", "live"];
|
|
316
|
+
function voiceSessionId(params, command) {
|
|
317
|
+
const sessionId = asString(params.sessionId, "sessionId", command);
|
|
318
|
+
if (sessionId.length > VOICE_SESSION_ID_MAX_LENGTH) {
|
|
319
|
+
throw new HostCommandError("INVALID_ARGUMENT", `Castle command ${command} requires a valid sessionId.`, command);
|
|
320
|
+
}
|
|
321
|
+
return sessionId;
|
|
322
|
+
}
|
|
323
|
+
async function voiceGetState(ctx, params, caps) {
|
|
324
|
+
const sessionId = voiceSessionId(params, "voice.getState");
|
|
325
|
+
if (!caps.voice)
|
|
326
|
+
return { state: "unavailable" };
|
|
327
|
+
const state = await caps.voice.getState(sessionId, ctx);
|
|
328
|
+
return { state: HOST_VOICE_STATES.includes(state) ? state : "unavailable" };
|
|
329
|
+
}
|
|
330
|
+
async function voiceRequestJoin(ctx, params, caps, signal) {
|
|
331
|
+
const sessionId = voiceSessionId(params, "voice.requestJoin");
|
|
332
|
+
const voice = caps.voice;
|
|
333
|
+
if (!voice)
|
|
334
|
+
return { status: "unavailable" };
|
|
335
|
+
const key = `${ctx.deckId ?? ""}\u0000${sessionId}`;
|
|
336
|
+
const declinedAt = voiceDeclinedAt.get(key);
|
|
337
|
+
if (declinedAt !== undefined) {
|
|
338
|
+
if (Date.now() - declinedAt < VOICE_DECLINE_COOLDOWN_MS)
|
|
339
|
+
return { status: "declined" };
|
|
340
|
+
voiceDeclinedAt.delete(key);
|
|
341
|
+
}
|
|
342
|
+
let inFlight = voiceJoinsInFlight.get(key);
|
|
343
|
+
while (inFlight?.signal?.aborted) {
|
|
344
|
+
// A withdrawn prompt the host hasn't closed yet: this is a new ask, so let the
|
|
345
|
+
// old one finish and prompt afresh rather than hand back its "unavailable".
|
|
346
|
+
await inFlight.request.catch(() => undefined);
|
|
347
|
+
if (signal?.aborted)
|
|
348
|
+
return { status: "unavailable" };
|
|
349
|
+
inFlight = voiceJoinsInFlight.get(key);
|
|
350
|
+
}
|
|
351
|
+
if (inFlight)
|
|
352
|
+
return inFlight.request;
|
|
353
|
+
const request = (async () => {
|
|
354
|
+
const outcome = await voice.requestJoin(sessionId, ctx, signal);
|
|
355
|
+
if (signal?.aborted) {
|
|
356
|
+
// The deck withdrew the request while the player was choosing.
|
|
357
|
+
if (outcome === "joined")
|
|
358
|
+
await voice.leave(sessionId, ctx);
|
|
359
|
+
return { status: "unavailable" };
|
|
360
|
+
}
|
|
361
|
+
const status = VOICE_JOIN_STATUSES.includes(outcome)
|
|
362
|
+
? outcome
|
|
363
|
+
: "declined";
|
|
364
|
+
if (status === "declined") {
|
|
365
|
+
pruneVoiceDeclines();
|
|
366
|
+
voiceDeclinedAt.set(key, Date.now());
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
voiceDeclinedAt.delete(key);
|
|
370
|
+
}
|
|
371
|
+
return { status };
|
|
372
|
+
})().finally(() => {
|
|
373
|
+
if (voiceJoinsInFlight.get(key)?.request === request)
|
|
374
|
+
voiceJoinsInFlight.delete(key);
|
|
375
|
+
});
|
|
376
|
+
voiceJoinsInFlight.set(key, { request, signal });
|
|
377
|
+
return request;
|
|
378
|
+
}
|
|
379
|
+
function pruneVoiceDeclines() {
|
|
380
|
+
const now = Date.now();
|
|
381
|
+
for (const [key, declinedAt] of voiceDeclinedAt) {
|
|
382
|
+
if (now - declinedAt >= VOICE_DECLINE_COOLDOWN_MS)
|
|
383
|
+
voiceDeclinedAt.delete(key);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
async function voiceLeave(ctx, params, caps) {
|
|
387
|
+
const sessionId = voiceSessionId(params, "voice.leave");
|
|
388
|
+
await caps.voice?.leave(sessionId, ctx);
|
|
389
|
+
return { ok: true };
|
|
390
|
+
}
|
|
391
|
+
function voiceSetMix(ctx, params, caps) {
|
|
392
|
+
const sessionId = voiceSessionId(params, "voice.setMix");
|
|
393
|
+
const raw = params.mix;
|
|
394
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
395
|
+
throw new HostCommandError("INVALID_ARGUMENT", "Castle command voice.setMix requires mix.", "voice.setMix");
|
|
396
|
+
}
|
|
397
|
+
const entries = Object.entries(raw).slice(0, VOICE_MIX_MAX_ENTRIES);
|
|
398
|
+
const mix = Object.create(null);
|
|
399
|
+
for (const [userId, entry] of entries) {
|
|
400
|
+
if (!userId || userId.length > 64 || RESERVED_MIX_KEYS.has(userId))
|
|
401
|
+
continue;
|
|
402
|
+
if (typeof entry !== "object" || entry === null)
|
|
403
|
+
continue;
|
|
404
|
+
const record = entry;
|
|
405
|
+
mix[userId] = {
|
|
406
|
+
gain: finiteOr(record.gain, 1, 0, 1),
|
|
407
|
+
pan: finiteOr(record.pan, 0, -1, 1),
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
if (caps.voice && Object.keys(mix).length > 0)
|
|
411
|
+
caps.voice.setMix(sessionId, mix, ctx);
|
|
412
|
+
return { ok: true };
|
|
413
|
+
}
|
|
414
|
+
function finiteOr(value, fallback, min, max) {
|
|
415
|
+
return typeof value === "number" && Number.isFinite(value)
|
|
416
|
+
? Math.min(max, Math.max(min, value))
|
|
417
|
+
: fallback;
|
|
418
|
+
}
|
|
268
419
|
async function passesOffer(ctx, params, caps) {
|
|
269
420
|
const passId = asString(params.passId, "passId", "pass.offer");
|
|
270
421
|
// Hosts without bricks support (dev CLI — no handler at all) get a normalized
|
package/dist/castleJson.d.ts
CHANGED
|
@@ -27,6 +27,9 @@ export interface CastleJson {
|
|
|
27
27
|
tickRate?: number;
|
|
28
28
|
maxPlayers?: number;
|
|
29
29
|
};
|
|
30
|
+
voice?: {
|
|
31
|
+
enabled?: boolean;
|
|
32
|
+
};
|
|
30
33
|
importWhenRemixed?: boolean;
|
|
31
34
|
starterScene?: string;
|
|
32
35
|
[key: string]: unknown;
|
|
@@ -40,6 +43,7 @@ export interface ResolvedServerConfig {
|
|
|
40
43
|
entry: string;
|
|
41
44
|
tickRate: number;
|
|
42
45
|
maxPlayers: number;
|
|
46
|
+
voiceEnabled: boolean;
|
|
43
47
|
}
|
|
44
48
|
export declare function resolveServerConfig(dir: string): ResolvedServerConfig | null;
|
|
45
49
|
export declare function deckStarterScene(dir: string): string;
|
package/dist/castleJson.js
CHANGED
|
@@ -40,7 +40,8 @@ const DEFAULT_SERVER_ENTRIES = [
|
|
|
40
40
|
'code/server/index.mjs',
|
|
41
41
|
];
|
|
42
42
|
export function resolveServerConfig(dir) {
|
|
43
|
-
const
|
|
43
|
+
const castleJson = readCastleJson(dir);
|
|
44
|
+
const server = castleJson?.server;
|
|
44
45
|
const declared = typeof server?.main === 'string' ? server.main.trim() : '';
|
|
45
46
|
const entry = declared ||
|
|
46
47
|
DEFAULT_SERVER_ENTRIES.find((candidate) => fs.existsSync(path.join(dir, candidate)));
|
|
@@ -50,6 +51,7 @@ export function resolveServerConfig(dir) {
|
|
|
50
51
|
entry,
|
|
51
52
|
tickRate: clampNumber(server?.tickRate, DEFAULT_SERVER_TICK_RATE, 0, SERVER_TICK_RATE_CAP),
|
|
52
53
|
maxPlayers: Math.floor(clampNumber(server?.maxPlayers, DEFAULT_SERVER_MAX_PLAYERS, 1, SERVER_MAX_PLAYERS_CAP)),
|
|
54
|
+
voiceEnabled: castleJson?.voice?.enabled !== false,
|
|
53
55
|
};
|
|
54
56
|
}
|
|
55
57
|
function isSafeServerEntry(dir, entry) {
|
package/dist/devSessionServer.js
CHANGED
package/dist/editorConfig.d.ts
CHANGED
|
@@ -33,7 +33,19 @@ export interface EditorConfig {
|
|
|
33
33
|
fileTypes?: FileTypeConfig[];
|
|
34
34
|
extensions?: string[];
|
|
35
35
|
defaultPlayFile?: string;
|
|
36
|
+
defaultPlayFileRefused?: {
|
|
37
|
+
value: string;
|
|
38
|
+
reason: string;
|
|
39
|
+
};
|
|
36
40
|
}
|
|
41
|
+
export declare const MAX_PLAY_FILE_LENGTH = 512;
|
|
42
|
+
export declare function normalizePlayFile(deckDir: string, raw: string): {
|
|
43
|
+
ok: true;
|
|
44
|
+
path: string;
|
|
45
|
+
} | {
|
|
46
|
+
ok: false;
|
|
47
|
+
reason: string;
|
|
48
|
+
};
|
|
37
49
|
export declare function readEditorConfig(deckDir: string): EditorConfig;
|
|
38
50
|
export declare function deckHidesFiles(deckDir: string): boolean;
|
|
39
51
|
export declare function resolveFileTypes(deckDir: string): ResolvedFileType[] | null;
|
package/dist/editorConfig.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// only. `defaultPlayFile` falls back to an import's when the deck names none --
|
|
15
15
|
// see `importedDefaultPlayFile`.
|
|
16
16
|
import * as fs from 'fs';
|
|
17
|
+
import * as os from 'os';
|
|
17
18
|
import * as path from 'path';
|
|
18
19
|
import { readCastleJson } from './castleJson.js';
|
|
19
20
|
import { IMPORTS_DIR } from './imports.js';
|
|
@@ -24,6 +25,61 @@ export function dataModeOf(type) {
|
|
|
24
25
|
return type.data;
|
|
25
26
|
return null;
|
|
26
27
|
}
|
|
28
|
+
// A play file as the Play panel, the playtest and the cloud browser worker all
|
|
29
|
+
// take it: a normalized deck-relative POSIX path. The worker and Ghost refuse
|
|
30
|
+
// anything else outright (castle-sandboxes/ghost-server validPlayFile), and a
|
|
31
|
+
// kit looks the file up by exact key, so a loose spelling is put in this form
|
|
32
|
+
// once, here, or refused with the reason.
|
|
33
|
+
export const MAX_PLAY_FILE_LENGTH = 512;
|
|
34
|
+
const LONE_SURROGATE = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;
|
|
35
|
+
const within = (child, parent) => {
|
|
36
|
+
const rel = path.relative(parent, child);
|
|
37
|
+
return rel === '' || (!rel.startsWith(`..${path.sep}`) && rel !== '..' && !path.isAbsolute(rel));
|
|
38
|
+
};
|
|
39
|
+
// Directories an absolute declaration must not point into: the deck and the
|
|
40
|
+
// home dir, each as given and as its real path (/tmp vs /private/tmp). A home
|
|
41
|
+
// of `/` would claim every leading-slash path, so it is left out.
|
|
42
|
+
function filesystemRoots(deckRoot) {
|
|
43
|
+
const real = (dir) => {
|
|
44
|
+
try {
|
|
45
|
+
return fs.realpathSync(dir);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return dir;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const home = path.resolve(os.homedir());
|
|
52
|
+
const dirs = [deckRoot, real(deckRoot)];
|
|
53
|
+
if (home !== path.parse(home).root)
|
|
54
|
+
dirs.push(home, real(home));
|
|
55
|
+
return dirs.filter((dir) => dir !== path.parse(dir).root);
|
|
56
|
+
}
|
|
57
|
+
export function normalizePlayFile(deckDir, raw) {
|
|
58
|
+
const value = raw.trim();
|
|
59
|
+
if (!value)
|
|
60
|
+
return { ok: false, reason: 'it is empty' };
|
|
61
|
+
if ([...value].some((c) => c.charCodeAt(0) < 0x20 || c === '\u007f')) {
|
|
62
|
+
return { ok: false, reason: 'it contains a control character' };
|
|
63
|
+
}
|
|
64
|
+
if (value.includes('\\'))
|
|
65
|
+
return { ok: false, reason: 'it contains a backslash' };
|
|
66
|
+
if (LONE_SURROGATE.test(value))
|
|
67
|
+
return { ok: false, reason: 'it contains an unpaired surrogate' };
|
|
68
|
+
const root = path.resolve(deckDir);
|
|
69
|
+
if (path.isAbsolute(value) && filesystemRoots(root).some((dir) => within(value, dir))) {
|
|
70
|
+
return { ok: false, reason: 'it is an absolute filesystem path, not a path inside the deck' };
|
|
71
|
+
}
|
|
72
|
+
const inside = path.relative(root, path.resolve(root, value.replace(/^\/+/, '')));
|
|
73
|
+
if (!inside)
|
|
74
|
+
return { ok: false, reason: 'it names the deck folder, not a file' };
|
|
75
|
+
if (!within(path.join(root, inside), root))
|
|
76
|
+
return { ok: false, reason: 'it points outside the deck' };
|
|
77
|
+
const posix = inside.split(path.sep).join('/');
|
|
78
|
+
if (posix.length > MAX_PLAY_FILE_LENGTH) {
|
|
79
|
+
return { ok: false, reason: `it is longer than ${MAX_PLAY_FILE_LENGTH} characters` };
|
|
80
|
+
}
|
|
81
|
+
return { ok: true, path: posix };
|
|
82
|
+
}
|
|
27
83
|
// An array with no usable entries stays an (empty) array rather than becoming
|
|
28
84
|
// undefined: "I declare no file types" is a real answer, distinct from "I say
|
|
29
85
|
// nothing about file types", and only the second one defers to the imports.
|
|
@@ -55,11 +111,20 @@ export function readEditorConfig(deckDir) {
|
|
|
55
111
|
hiddenPaths: asStringArray(editor.hiddenPaths),
|
|
56
112
|
fileTypes: asFileTypes(editor.fileTypes),
|
|
57
113
|
extensions: asStringArray(editor.extensions) ?? asStringArray(data.editorExtensions),
|
|
58
|
-
|
|
59
|
-
? editor.defaultPlayFile
|
|
60
|
-
: importedDefaultPlayFile(deckDir),
|
|
114
|
+
...(typeof editor.defaultPlayFile === 'string'
|
|
115
|
+
? ownDefaultPlayFile(deckDir, editor.defaultPlayFile)
|
|
116
|
+
: { defaultPlayFile: importedDefaultPlayFile(deckDir) }),
|
|
61
117
|
};
|
|
62
118
|
}
|
|
119
|
+
// An empty string keeps its old meaning, "no start file", with nothing refused.
|
|
120
|
+
function ownDefaultPlayFile(deckDir, raw) {
|
|
121
|
+
if (!raw.trim())
|
|
122
|
+
return {};
|
|
123
|
+
const normalized = normalizePlayFile(deckDir, raw);
|
|
124
|
+
return normalized.ok
|
|
125
|
+
? { defaultPlayFile: normalized.path }
|
|
126
|
+
: { defaultPlayFileRefused: { value: raw, reason: normalized.reason } };
|
|
127
|
+
}
|
|
63
128
|
// Which scene the play panel opens with, when the deck names none itself. Only a
|
|
64
129
|
// scene kit has the concept, and a deck that imported one has its scenes without
|
|
65
130
|
// having said so -- without this the panel loads the kit's runtime with no scene
|
|
@@ -74,10 +139,11 @@ function importedDefaultPlayFile(deckDir) {
|
|
|
74
139
|
const declared = value && typeof value === 'object'
|
|
75
140
|
? value.defaultPlayFile
|
|
76
141
|
: undefined;
|
|
77
|
-
if (typeof declared !== 'string'
|
|
142
|
+
if (typeof declared !== 'string')
|
|
78
143
|
continue;
|
|
79
|
-
|
|
80
|
-
|
|
144
|
+
const normalized = normalizePlayFile(deckDir, declared);
|
|
145
|
+
if (normalized.ok && fs.existsSync(path.join(deckDir, normalized.path)))
|
|
146
|
+
return normalized.path;
|
|
81
147
|
}
|
|
82
148
|
return undefined;
|
|
83
149
|
}
|
package/dist/ide.d.ts
CHANGED
|
@@ -4,6 +4,24 @@ import { COVER_FILE } from './localPaths.js';
|
|
|
4
4
|
import { type TuneLedger } from './paramsTunes.js';
|
|
5
5
|
/** Cache only Vite's content-fingerprinted executable, style, and font output. */
|
|
6
6
|
export declare function shellAssetCacheControl(asset: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* The CDN origin that carries this CLI's fingerprinted shell assets, when the
|
|
9
|
+
* environment names one (the sandbox image sets CASTLE_SHELL_ASSET_ORIGIN; its
|
|
10
|
+
* build uploads the assets there first). Only a bare https origin counts.
|
|
11
|
+
*/
|
|
12
|
+
export declare function shellAssetOrigin(value: string | undefined): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Point the shell's fingerprinted script and stylesheet at the CDN, falling back
|
|
15
|
+
* to this serve's own copy if the CDN copy fails to load.
|
|
16
|
+
*
|
|
17
|
+
* Each deck serve is its own origin (`<port>-<sandbox>`), so without this the
|
|
18
|
+
* browser caches the 1.5 MB bundle once per deck port and downloads it again on
|
|
19
|
+
* the first open of every deck: 2.0 s vs 0.83 s to shell load on mobile. The CDN
|
|
20
|
+
* URL is the same for every deck and sandbox, and it is keyed by content hash, so
|
|
21
|
+
* a CLI release that leaves the shell alone keeps the cached copy too. Only names
|
|
22
|
+
* the immutable-asset rule accepts are moved; everything else stays local.
|
|
23
|
+
*/
|
|
24
|
+
export declare function withShellAssetOrigin(html: string, origin: string | null): string;
|
|
7
25
|
export declare const IDE_ASSET_PREFIX = "/__castle/ide/";
|
|
8
26
|
export declare const PTY_WS_PATH = "/__castle/pty";
|
|
9
27
|
export declare const VENDOR_PREFIX = "/__castle/vendor/";
|
package/dist/ide.js
CHANGED
|
@@ -58,6 +58,49 @@ const IMMUTABLE_SHELL_ASSET = /^assets\/[^/\\]+-[A-Za-z0-9_-]{8}\.(?:css|js|woff
|
|
|
58
58
|
export function shellAssetCacheControl(asset) {
|
|
59
59
|
return IMMUTABLE_SHELL_ASSET.test(asset) ? 'public, max-age=31536000, immutable' : 'no-store';
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* The CDN origin that carries this CLI's fingerprinted shell assets, when the
|
|
63
|
+
* environment names one (the sandbox image sets CASTLE_SHELL_ASSET_ORIGIN; its
|
|
64
|
+
* build uploads the assets there first). Only a bare https origin counts.
|
|
65
|
+
*/
|
|
66
|
+
export function shellAssetOrigin(value) {
|
|
67
|
+
if (!value)
|
|
68
|
+
return null;
|
|
69
|
+
try {
|
|
70
|
+
const url = new URL(value);
|
|
71
|
+
if (url.protocol !== 'https:' || url.pathname !== '/' || url.search || url.hash)
|
|
72
|
+
return null;
|
|
73
|
+
if (url.username || url.password)
|
|
74
|
+
return null;
|
|
75
|
+
return url.origin;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Point the shell's fingerprinted script and stylesheet at the CDN, falling back
|
|
83
|
+
* to this serve's own copy if the CDN copy fails to load.
|
|
84
|
+
*
|
|
85
|
+
* Each deck serve is its own origin (`<port>-<sandbox>`), so without this the
|
|
86
|
+
* browser caches the 1.5 MB bundle once per deck port and downloads it again on
|
|
87
|
+
* the first open of every deck: 2.0 s vs 0.83 s to shell load on mobile. The CDN
|
|
88
|
+
* URL is the same for every deck and sandbox, and it is keyed by content hash, so
|
|
89
|
+
* a CLI release that leaves the shell alone keeps the cached copy too. Only names
|
|
90
|
+
* the immutable-asset rule accepts are moved; everything else stays local.
|
|
91
|
+
*/
|
|
92
|
+
export function withShellAssetOrigin(html, origin) {
|
|
93
|
+
if (!origin)
|
|
94
|
+
return html;
|
|
95
|
+
const local = (name) => `${IDE_ASSET_PREFIX}assets/${name}`;
|
|
96
|
+
const isMovable = (name) => IMMUTABLE_SHELL_ASSET.test(`assets/${name}`);
|
|
97
|
+
html = html.replace(/<script type="module" crossorigin src="\/__castle\/ide\/assets\/([^"\/]+)"><\/script>/g, (tag, name) => isMovable(name) && name.endsWith('.js')
|
|
98
|
+
? `<script type="module" crossorigin src="${origin}${local(name)}" onerror="var s=document.createElement('script');s.type='module';s.src='${local(name)}';document.head.appendChild(s)"></script>`
|
|
99
|
+
: tag);
|
|
100
|
+
return html.replace(/<link rel="stylesheet" crossorigin href="\/__castle\/ide\/assets\/([^"\/]+)">/g, (tag, name) => isMovable(name) && name.endsWith('.css')
|
|
101
|
+
? `<link rel="stylesheet" crossorigin href="${origin}${local(name)}" onerror="this.onerror=null;this.href='${local(name)}'">`
|
|
102
|
+
: tag);
|
|
103
|
+
}
|
|
61
104
|
// Does the deck serve this root-level file itself? Vite serves both the deck
|
|
62
105
|
// root and its `public/` dir at `/`, so either location counts.
|
|
63
106
|
function deckHasFile(deckDir, name) {
|
|
@@ -118,7 +161,7 @@ function serveShellIndex(req, res, bootstrap) {
|
|
|
118
161
|
res.writeHead(404).end();
|
|
119
162
|
return true;
|
|
120
163
|
}
|
|
121
|
-
let html = fs.readFileSync(filePath, 'utf8');
|
|
164
|
+
let html = withShellAssetOrigin(fs.readFileSync(filePath, 'utf8'), shellAssetOrigin(process.env.CASTLE_SHELL_ASSET_ORIGIN));
|
|
122
165
|
if (bootstrap)
|
|
123
166
|
html = html.replace(/<head(\s[^>]*)?>/i, (head) => `${head}${bootstrap(req)}`);
|
|
124
167
|
res.writeHead(200, {
|
package/dist/init.js
CHANGED
|
@@ -54,7 +54,7 @@ if (!(await mountEditorRoute())) startGame(initCard());
|
|
|
54
54
|
// Registry version of castle-web-sdk to inject when scaffolding from a
|
|
55
55
|
// globally-installed castle-web (not from inside the workspace). Bumped
|
|
56
56
|
// alongside cli/sdk version bumps.
|
|
57
|
-
const PUBLISHED_SDK_VERSION = '0.4.
|
|
57
|
+
const PUBLISHED_SDK_VERSION = '0.4.36';
|
|
58
58
|
// Range, not a pin: `castle-web-fonts` is its own package precisely so a tenth
|
|
59
59
|
// face can ship without a cli release, and a caret range means an existing
|
|
60
60
|
// deck's next install picks it up. Nothing here has to move when it does.
|
package/dist/native/loop.js
CHANGED
|
@@ -25,7 +25,7 @@ const MAX_ITERATIONS = 40;
|
|
|
25
25
|
// PLAYTEST_MAX_SHOTS frames each -- at most 24 -- small enough to list in
|
|
26
26
|
// full for the task card, with no truncation needed.
|
|
27
27
|
function playtestFrameList(frames) {
|
|
28
|
-
return [...frames].sort();
|
|
28
|
+
return [...frames].sort((a, b) => a.localeCompare(b, "en", { numeric: true }));
|
|
29
29
|
}
|
|
30
30
|
// -- run logging ----------------------------------------------------------------
|
|
31
31
|
// Structured JSONL, one event per line, appended (task retry attempts share
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The real (Playwright-backed) PlaytestExecutor: navigates a fresh
|
|
2
2
|
// browser context + page to the served deck, settles, replays a timeline of
|
|
3
|
-
// mouse/keyboard primitives and screenshot captures on one wall clock, and
|
|
3
|
+
// mouse/touch/keyboard primitives and screenshot captures on one wall clock, and
|
|
4
4
|
// reports console/pageerror output plus rAF-tick capture-health diagnostics.
|
|
5
5
|
// See native/playtest.ts for the browser-free types this implements and
|
|
6
6
|
// native/playtest-browser.ts for the warm-Chromium lifecycle this borrows a
|
|
@@ -65,7 +65,25 @@ function attachConsoleCapture(page, navStart, boundaries) {
|
|
|
65
65
|
page.on("pageerror", (err) => push("pageerror", err.message));
|
|
66
66
|
return log;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
// Playwright's touchscreen only taps, so a touch drag goes through CDP --
|
|
69
|
+
// the same Input.dispatchTouchEvent that touchscreen.tap itself sends. A
|
|
70
|
+
// finger has no hover: Chromium rejects a touchMove or touchEnd with no touch
|
|
71
|
+
// in progress ("Must send a TouchStart first"), failing the whole call, so a
|
|
72
|
+
// move or up with no finger down is dropped rather than sent. One finger only:
|
|
73
|
+
// Chromium delivers a second down while the finger is down as a touchmove.
|
|
74
|
+
function touchDispatcher(cdp) {
|
|
75
|
+
let down = false;
|
|
76
|
+
return async (type, x, y) => {
|
|
77
|
+
if (type !== "touchStart" && !down)
|
|
78
|
+
return;
|
|
79
|
+
down = type !== "touchEnd";
|
|
80
|
+
await cdp.send("Input.dispatchTouchEvent", {
|
|
81
|
+
type,
|
|
82
|
+
touchPoints: type === "touchEnd" ? [] : [{ x, y }],
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
async function runTimeline(page, input, touch) {
|
|
69
87
|
const sessionStart = Date.now();
|
|
70
88
|
const frames = [];
|
|
71
89
|
let framesRequested = 0;
|
|
@@ -87,6 +105,15 @@ async function runTimeline(page, input) {
|
|
|
87
105
|
await page.mouse.move(event.x, event.y);
|
|
88
106
|
await page.mouse.up();
|
|
89
107
|
break;
|
|
108
|
+
case "touchstart":
|
|
109
|
+
await touch("touchStart", event.x, event.y);
|
|
110
|
+
break;
|
|
111
|
+
case "touchmove":
|
|
112
|
+
await touch("touchMove", event.x, event.y);
|
|
113
|
+
break;
|
|
114
|
+
case "touchend":
|
|
115
|
+
await touch("touchEnd", event.x, event.y);
|
|
116
|
+
break;
|
|
90
117
|
case "keydown":
|
|
91
118
|
await page.keyboard.down(event.key);
|
|
92
119
|
break;
|
|
@@ -114,7 +141,11 @@ async function measureDiagnostics(page, wallMs) {
|
|
|
114
141
|
async function runSessionOnBrowser(browser, input) {
|
|
115
142
|
const navStart = Date.now();
|
|
116
143
|
const boundaries = { settleStartRel: null, sessionStartRel: null };
|
|
117
|
-
const
|
|
144
|
+
const touchInput = input.input === "touch";
|
|
145
|
+
const context = await browser.newContext({
|
|
146
|
+
viewport: PLAYTEST_VIEWPORT,
|
|
147
|
+
...(touchInput ? { hasTouch: true, isMobile: true } : {}),
|
|
148
|
+
});
|
|
118
149
|
let consoleLog = [];
|
|
119
150
|
try {
|
|
120
151
|
const page = await context.newPage();
|
|
@@ -134,7 +165,8 @@ async function runSessionOnBrowser(browser, input) {
|
|
|
134
165
|
};
|
|
135
166
|
requestAnimationFrame(tick);
|
|
136
167
|
});
|
|
137
|
-
const
|
|
168
|
+
const touch = touchInput ? touchDispatcher(await context.newCDPSession(page)) : null;
|
|
169
|
+
const { frames, framesRequested, wallMs } = await runTimeline(page, input, touch);
|
|
138
170
|
const diagnostics = await measureDiagnostics(page, wallMs);
|
|
139
171
|
diagnostics.framesRequested = framesRequested;
|
|
140
172
|
diagnostics.framesCaptured = frames.length;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type PlaytestExecutor } from './playtest.js';
|
|
2
2
|
export declare function contentGrantFromBrowserUrl(value: string): string | null;
|
|
3
|
+
export declare const REMOTE_TOUCH_UNAVAILABLE = "touch input is not available in the cloud playtest browser yet, so nothing was run and this call was not counted -- use input \"mouse\", and say that touch was not checked";
|
|
3
4
|
export declare function createRemotePlaytestExecutor(browserContentUrl: () => string | null): PlaytestExecutor;
|
|
@@ -29,7 +29,26 @@ export function contentGrantFromBrowserUrl(value) {
|
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
// Ghost and the browser worker validate a playtest operation key by key, so
|
|
33
|
+
// `input`/`playFile` are sent only when a call needs them, and a refusal of
|
|
34
|
+
// those keys is remembered for the rest of the serve. Ghost answers every
|
|
35
|
+
// validation failure with BROWSER_INVALID_OPERATION; only its unknown-key
|
|
36
|
+
// message, "operation is invalid", is that refusal -- a bad coordinate or
|
|
37
|
+
// timestamp is the call's own mistake and must not switch the extension off.
|
|
38
|
+
// (A worker that refuses the keys after Ghost accepted them fails the job as a
|
|
39
|
+
// generic BROWSER_SERVICE_FAILED, which cannot be told apart, so the host
|
|
40
|
+
// rollout must reach the workers before Ghost.)
|
|
41
|
+
function refusedExtension(error) {
|
|
42
|
+
const { message, extensions } = (error ?? {});
|
|
43
|
+
return (extensions?.code === 'BROWSER_INVALID_OPERATION' &&
|
|
44
|
+
typeof message === 'string' &&
|
|
45
|
+
message.startsWith('operation is invalid ['));
|
|
46
|
+
}
|
|
47
|
+
export const REMOTE_TOUCH_UNAVAILABLE = "touch input is not available in the cloud playtest browser yet, so nothing was run and this call was not counted -- use input \"mouse\", and say that touch was not checked";
|
|
48
|
+
function wantsExtension(input) {
|
|
49
|
+
return input.input === 'touch' || Boolean(input.playFile);
|
|
50
|
+
}
|
|
51
|
+
function operationFromTimeline(input, extended) {
|
|
33
52
|
const actions = [];
|
|
34
53
|
const screenshots = [];
|
|
35
54
|
const keyDown = new Map();
|
|
@@ -59,9 +78,9 @@ function operationFromTimeline(input) {
|
|
|
59
78
|
continue;
|
|
60
79
|
actions.push({
|
|
61
80
|
t: event.t,
|
|
62
|
-
type: event.kind === 'mousedown'
|
|
81
|
+
type: event.kind === 'mousedown' || event.kind === 'touchstart'
|
|
63
82
|
? 'down'
|
|
64
|
-
: event.kind === 'mouseup'
|
|
83
|
+
: event.kind === 'mouseup' || event.kind === 'touchend'
|
|
65
84
|
? 'up'
|
|
66
85
|
: 'move',
|
|
67
86
|
x: event.x,
|
|
@@ -70,7 +89,14 @@ function operationFromTimeline(input) {
|
|
|
70
89
|
}
|
|
71
90
|
}
|
|
72
91
|
actions.sort((a, b) => a.t - b.t);
|
|
73
|
-
return {
|
|
92
|
+
return {
|
|
93
|
+
kind: 'playtest',
|
|
94
|
+
durationMs: input.durationMs,
|
|
95
|
+
actions,
|
|
96
|
+
screenshots,
|
|
97
|
+
...(extended && input.input === 'touch' ? { input: 'touch' } : {}),
|
|
98
|
+
...(extended && input.playFile ? { playFile: input.playFile } : {}),
|
|
99
|
+
};
|
|
74
100
|
}
|
|
75
101
|
function isRecord(value) {
|
|
76
102
|
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -123,6 +149,24 @@ function validRemoteResult(result) {
|
|
|
123
149
|
Boolean(result.diagnostics));
|
|
124
150
|
}
|
|
125
151
|
export function createRemotePlaytestExecutor(browserContentUrl) {
|
|
152
|
+
let extensionRefused = false;
|
|
153
|
+
const submit = async (grant, input) => {
|
|
154
|
+
if (wantsExtension(input) && !extensionRefused) {
|
|
155
|
+
try {
|
|
156
|
+
const result = await api.runBrowserJob(grant, operationFromTimeline(input, true), input.signal);
|
|
157
|
+
return { result: result, degraded: false };
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (!refusedExtension(error))
|
|
161
|
+
throw error;
|
|
162
|
+
extensionRefused = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (input.input === 'touch')
|
|
166
|
+
return { refusedTouch: true };
|
|
167
|
+
const result = await api.runBrowserJob(grant, operationFromTimeline(input, false), input.signal);
|
|
168
|
+
return { result: result, degraded: Boolean(input.playFile) };
|
|
169
|
+
};
|
|
126
170
|
return {
|
|
127
171
|
async runSession(input) {
|
|
128
172
|
const contentUrl = browserContentUrl();
|
|
@@ -130,7 +174,10 @@ export function createRemotePlaytestExecutor(browserContentUrl) {
|
|
|
130
174
|
if (!grant)
|
|
131
175
|
return failed(input, 'the serve could not mint a browser content grant');
|
|
132
176
|
try {
|
|
133
|
-
const
|
|
177
|
+
const submitted = await submit(grant, input);
|
|
178
|
+
if ('refusedTouch' in submitted)
|
|
179
|
+
return { ...failed(input, REMOTE_TOUCH_UNAVAILABLE), unsupported: true };
|
|
180
|
+
const { result, degraded } = submitted;
|
|
134
181
|
if (!result.ok) {
|
|
135
182
|
if (!validFailureDiagnostics(result)) {
|
|
136
183
|
return failed(input, 'browser worker returned invalid failure diagnostics');
|
|
@@ -151,6 +198,15 @@ export function createRemotePlaytestExecutor(browserContentUrl) {
|
|
|
151
198
|
})),
|
|
152
199
|
console: result.console,
|
|
153
200
|
diagnostics: result.diagnostics,
|
|
201
|
+
...(degraded
|
|
202
|
+
? {
|
|
203
|
+
environment: {
|
|
204
|
+
playFile: null,
|
|
205
|
+
input: 'mouse',
|
|
206
|
+
note: `the cloud playtest browser cannot open a play file yet, so it loaded the entry point instead of ${input.playFile}. What the user's Play panel shows may differ.`,
|
|
207
|
+
},
|
|
208
|
+
}
|
|
209
|
+
: {}),
|
|
154
210
|
};
|
|
155
211
|
}
|
|
156
212
|
catch (error) {
|