castle-web-cli 0.4.229 → 0.4.230
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/agent-prompts.d.ts +2 -0
- package/dist/agent-prompts.js +16 -8
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +21 -21
- package/dist/api.d.ts +28 -2
- package/dist/api.js +74 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +779 -3
- package/dist/castleJson.d.ts +44 -0
- package/dist/castleJson.js +131 -0
- package/dist/check.js +27 -1
- package/dist/contentPack.d.ts +49 -0
- package/dist/contentPack.js +273 -0
- package/dist/devExperiments.d.ts +21 -0
- package/dist/devExperiments.js +139 -0
- package/dist/devHub.d.ts +55 -0
- package/dist/devHub.js +187 -0
- package/dist/devSessionChild.js +3 -1
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +229 -44
- package/dist/experimentAssignment.d.ts +15 -0
- package/dist/experimentAssignment.js +41 -0
- package/dist/importCheckHook.d.ts +40 -0
- package/dist/importCheckHook.js +171 -0
- package/dist/importRegression.d.ts +15 -0
- package/dist/importRegression.js +100 -0
- package/dist/importTrust.d.ts +2 -0
- package/dist/importTrust.js +27 -0
- package/dist/importUpdateHook.d.ts +18 -0
- package/dist/importUpdateHook.js +31 -8
- package/dist/importUpdateHookRunner.js +19 -7
- package/dist/imports.d.ts +16 -0
- package/dist/imports.js +141 -31
- package/dist/index.js +3 -1
- package/dist/init.d.ts +3 -0
- package/dist/init.js +125 -8
- package/dist/install.js +4 -1
- package/dist/localPaths.js +4 -0
- package/dist/login.js +2 -2
- package/dist/platformDoc.js +3 -8
- package/dist/playPagePolicy.js +3 -1
- package/dist/remix.js +5 -0
- package/dist/routerTaskReport.d.ts +28 -0
- package/dist/routerTaskReport.js +56 -0
- package/dist/save-deck.d.ts +18 -0
- package/dist/save-deck.js +142 -6
- package/dist/serve.d.ts +8 -0
- package/dist/serve.js +94 -13
- package/dist/serverBundle.d.ts +1 -1
- package/dist/serverBundle.js +5 -1
- package/dist/webSourceSync.d.ts +2 -0
- package/dist/webSourceSync.js +2 -0
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +258 -52
- package/kits/base/sdk/agent.js +4 -4
- package/kits/base/sdk/avatar.d.ts +12 -0
- package/kits/base/sdk/avatar.js +23 -0
- package/kits/base/sdk/castle.d.ts +5 -0
- package/kits/base/sdk/castle.js +3 -0
- package/kits/base/sdk/commands.d.ts +208 -0
- package/kits/base/sdk/commands.js +16 -0
- package/kits/base/sdk/context.d.ts +6 -0
- package/kits/base/sdk/experiments.d.ts +15 -0
- package/kits/base/sdk/experiments.js +83 -0
- package/kits/base/sdk/hub.d.ts +85 -0
- package/kits/base/sdk/hub.js +107 -0
- package/kits/base/sdk/multiplayer.d.ts +45 -1
- package/kits/base/sdk/multiplayer.js +106 -4
- package/kits/base/sdk/server/hub.d.ts +169 -0
- package/kits/base/sdk/server/hub.js +125 -0
- package/kits/base/sdk/server/platformHandle.d.ts +42 -1
- package/kits/base/sdk/server/storage.d.ts +55 -2
- package/kits/base/sdk/server/wrapper.d.ts +32 -2
- package/kits/base/sdk/server/wrapper.js +90 -11
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +13 -1
- package/kits/hub-game/.prettierrc +5 -0
- package/kits/hub-game/CLAUDE.md +146 -0
- package/kits/hub-game/blueprints/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
- package/kits/hub-game/castle.json +96 -0
- package/kits/hub-game/code/client/attention.js +133 -0
- package/kits/hub-game/code/client/avatar.js +288 -0
- package/kits/hub-game/code/client/cabinets.js +90 -0
- package/kits/hub-game/code/client/chat.js +135 -0
- package/kits/hub-game/code/client/chrome.js +1001 -0
- package/kits/hub-game/code/client/doorFrame.js +15 -0
- package/kits/hub-game/code/client/firstJoin.js +14 -0
- package/kits/hub-game/code/client/grab.js +241 -0
- package/kits/hub-game/code/client/hookLayer.js +230 -0
- package/kits/hub-game/code/client/idle.js +326 -0
- package/kits/hub-game/code/client/keys.js +48 -0
- package/kits/hub-game/code/client/pack.js +232 -0
- package/kits/hub-game/code/client/packFormat.js +397 -0
- package/kits/hub-game/code/client/say.js +127 -0
- package/kits/hub-game/code/client/sha256.js +80 -0
- package/kits/hub-game/code/client/sound.js +147 -0
- package/kits/hub-game/code/client/state.js +131 -0
- package/kits/hub-game/code/client/talk.js +259 -0
- package/kits/hub-game/code/client/together.js +365 -0
- package/kits/hub-game/code/client/wear.js +149 -0
- package/kits/hub-game/code/server/actors.js +627 -0
- package/kits/hub-game/code/server/blocks.js +103 -0
- package/kits/hub-game/code/server/cabinets.js +309 -0
- package/kits/hub-game/code/server/game.js +137 -0
- package/kits/hub-game/code/server/grab.js +247 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1904 -0
- package/kits/hub-game/code/server/idle.js +412 -0
- package/kits/hub-game/code/server/index.js +64 -0
- package/kits/hub-game/code/server/labels.js +59 -0
- package/kits/hub-game/code/server/manifest.js +527 -0
- package/kits/hub-game/code/server/npcs.js +745 -0
- package/kits/hub-game/code/server/party.js +381 -0
- package/kits/hub-game/code/server/place.js +43 -0
- package/kits/hub-game/code/server/say.js +83 -0
- package/kits/hub-game/code/server/wear.js +142 -0
- package/kits/hub-game/code/systems/hub.js +2230 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1139 -0
- package/kits/hub-game/docs/style.md +137 -0
- package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
- package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
- package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
- package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
- package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
- package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
- package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
- package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
- package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
- package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
- package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
- package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
- package/kits/hub-game/eslint.config.js +20 -0
- package/kits/hub-game/fonts.generated.js +9 -0
- package/kits/hub-game/index.html +22 -0
- package/kits/hub-game/main.jsx +6 -0
- package/kits/hub-game/models/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/avatar-2.pxmodel +27 -0
- package/kits/hub-game/models/avatar-3.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
- package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
- package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
- package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
- package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
- package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
- package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
- package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
- package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
- package/kits/hub-game/package-lock.json +365 -0
- package/kits/hub-game/package.json +32 -0
- package/kits/hub-game/scenes/main.scene +318 -0
- package/kits/hub-game/scripts/check.mjs +339 -0
- package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
- package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
- package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
- package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
- package/kits/hub-game/scripts/pack.mjs +192 -0
- package/kits/hub-game/scripts/test-actors.mjs +666 -0
- package/kits/hub-game/scripts/test-attention.mjs +103 -0
- package/kits/hub-game/scripts/test-avatar.mjs +472 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
- package/kits/hub-game/scripts/test-blocks.mjs +351 -0
- package/kits/hub-game/scripts/test-chat.mjs +98 -0
- package/kits/hub-game/scripts/test-classic.mjs +590 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
- package/kits/hub-game/scripts/test-door.mjs +56 -0
- package/kits/hub-game/scripts/test-grab.mjs +331 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +1310 -0
- package/kits/hub-game/scripts/test-idle.mjs +518 -0
- package/kits/hub-game/scripts/test-interest.mjs +413 -0
- package/kits/hub-game/scripts/test-keys.mjs +50 -0
- package/kits/hub-game/scripts/test-manifest.mjs +224 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +714 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +286 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-together.mjs +183 -0
- package/kits/hub-game/theme.style +3 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +101 -1
- package/kits/multiplayer-3d/code/server/players.js +4 -1
- package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
- package/kits/multiplayer-3d/code/server/world.js +20 -7
- package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/art.js +13 -0
- package/kits/physics-2d/engine/assets.js +4 -2
- package/kits/physics-2d/engine/scene.js +25 -5
- package/kits/physics-3d/CLAUDE.md +6 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -4
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- package/kits/physics-3d/engine3d/world3d.js +65 -1
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +77 -7
- package/kits/real-time/code/client/gameHooks.js +63 -3
- package/kits/real-time/code/client/messages.js +7 -0
- package/kits/real-time/code/server/gameHooks.js +24 -0
- package/kits/real-time/code/server/session.js +390 -22
- package/package.json +2 -2
package/dist/save-deck.js
CHANGED
|
@@ -6,11 +6,15 @@ import { nanoid } from 'nanoid';
|
|
|
6
6
|
import * as api from './api.js';
|
|
7
7
|
import * as config from './config.js';
|
|
8
8
|
import { bundleProject } from './bundle.js';
|
|
9
|
-
import { resolveServerConfig } from './castleJson.js';
|
|
9
|
+
import { resolveServerConfig, validateExperiments } from './castleJson.js';
|
|
10
|
+
import { importChecksFailedMessage, runImportChecks } from './importCheckHook.js';
|
|
10
11
|
import { selectSaveCover } from './saveCover.js';
|
|
11
12
|
import { COVER_FILE } from './localPaths.js';
|
|
12
13
|
import { buildServerBundle } from './serverBundle.js';
|
|
13
|
-
import {
|
|
14
|
+
import { buildContentPack } from './contentPack.js';
|
|
15
|
+
import { importRegressionMessage, importRegressions, savedDeckImportPins } from './importRegression.js';
|
|
16
|
+
import { refreshStaleBuiltinImports } from './imports.js';
|
|
17
|
+
import { decideSavePrecondition, EXIT_IMPORTS_OLDER, EXIT_SAVED_DECK_NEWER, fetchServerSourceVersion, readSyncMarker, saveRefusedLine, saveRefusedMessage, WEB_DECK_SOURCE_STALE_CODE, writeSyncMarker, } from './webSourceSync.js';
|
|
14
18
|
import { DeckTooLargeError, MAX_SCENE_DATA_BYTES, MAX_SOURCE_ARCHIVE_BYTES, SAVE_FAILURE_ENV, classifySaveFailure, saveFailedLine, sceneTooLargeMessage, sourceTooLargeMessage, } from './saveFailure.js';
|
|
15
19
|
export { DeckTooLargeError, MAX_SCENE_DATA_BYTES, MAX_SOURCE_ARCHIVE_BYTES, sceneTooLargeMessage, sourceTooLargeMessage, } from './saveFailure.js';
|
|
16
20
|
// `imports/` is derived state like node_modules: a dependency's files belong to
|
|
@@ -247,9 +251,11 @@ function writePublishedServerBundleState(projectDir, state) {
|
|
|
247
251
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
248
252
|
fs.writeFileSync(file, `${JSON.stringify(state, null, 2)}\n`, 'utf8');
|
|
249
253
|
}
|
|
250
|
-
async function publishServerBundle(projectDir, deckId) {
|
|
254
|
+
async function publishServerBundle(projectDir, deckId, pack) {
|
|
251
255
|
const serverConfig = resolveServerConfig(projectDir);
|
|
252
256
|
if (!serverConfig) {
|
|
257
|
+
if (pack)
|
|
258
|
+
console.log('Content pack not published: a pack is paired with a server bundle, and this deck has none.');
|
|
253
259
|
const prior = readPublishedServerBundleState(projectDir);
|
|
254
260
|
if (prior?.deckId !== deckId) {
|
|
255
261
|
console.log('Server bundle skipped: no server entry found.');
|
|
@@ -267,6 +273,7 @@ async function publishServerBundle(projectDir, deckId) {
|
|
|
267
273
|
console.log(`Server bundle size: ${(bundle.sizeBytes / 1024).toFixed(1)}KB`);
|
|
268
274
|
const uploadConfig = await api.createCauldronServerBundleUploadConfig(deckId);
|
|
269
275
|
await uploadPresignedFile(uploadConfig, new Blob([bundle.code], { type: 'application/javascript' }), 'application/javascript', 60_000, 'Server bundle upload');
|
|
276
|
+
const packUploadId = pack ? await uploadContentPack(deckId, pack) : null;
|
|
270
277
|
const saved = await api.saveCauldronServerBundle(deckId, uploadConfig.uploadId, {
|
|
271
278
|
tickRate: serverConfig.tickRate,
|
|
272
279
|
maxPlayers: serverConfig.maxPlayers,
|
|
@@ -275,16 +282,102 @@ async function publishServerBundle(projectDir, deckId) {
|
|
|
275
282
|
...(serverConfig.worldNotifications
|
|
276
283
|
? { worldNotifications: serverConfig.worldNotifications }
|
|
277
284
|
: {}),
|
|
278
|
-
|
|
285
|
+
// Sent only for a deck whose castle.json declares a hub place, so every
|
|
286
|
+
// other deck's config is exactly what it was.
|
|
287
|
+
...(serverConfig.hub ? { hub: serverConfig.hub } : {}),
|
|
288
|
+
}, packUploadId ?? undefined);
|
|
279
289
|
// The server hashes what it actually stored. A mismatch means the bytes that
|
|
280
290
|
// will run in sessions are not the bytes we bundled.
|
|
281
291
|
if (saved && saved.sha256 !== bundle.sha256) {
|
|
282
292
|
throw new Error(`Published server bundle does not match what was built ` +
|
|
283
293
|
`(server ${saved.sha256}, local ${bundle.sha256}). The deck was not updated safely.`);
|
|
284
294
|
}
|
|
295
|
+
if (packUploadId && saved?.contentPackSha256 !== pack?.sha256) {
|
|
296
|
+
throw new Error(`Published content pack does not match what was built ` +
|
|
297
|
+
`(server ${saved?.contentPackSha256 ?? 'none'}, local ${pack?.sha256}). The deck was not updated safely.`);
|
|
298
|
+
}
|
|
299
|
+
if (packUploadId)
|
|
300
|
+
console.log(`Content pack published with it (sha256 ${pack?.sha256}).`);
|
|
285
301
|
writePublishedServerBundleState(projectDir, { deckId, sha256: bundle.sha256 });
|
|
286
302
|
console.log(`Server bundle published${saved ? ` as ${saved.version}` : ''} (sha256 ${bundle.sha256}).`);
|
|
287
303
|
}
|
|
304
|
+
// Checked before anything is bundled or published, so a block Castle would
|
|
305
|
+
// refuse stops the save while the live deck is still untouched.
|
|
306
|
+
function checkedExperiments(castleJson) {
|
|
307
|
+
try {
|
|
308
|
+
return validateExperiments(castleJson?.experiments);
|
|
309
|
+
}
|
|
310
|
+
catch (e) {
|
|
311
|
+
throw new Error(`castle.json ${e instanceof Error ? e.message : String(e)} Nothing was saved.`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// castle.json `experiments` goes to Castle on every save, with or without a
|
|
315
|
+
// server bundle. A declared block is awaited and fails the save loudly when it
|
|
316
|
+
// cannot be stored. Exported for the tests.
|
|
317
|
+
export async function publishExperiments(deckId, title, experiments) {
|
|
318
|
+
let stored;
|
|
319
|
+
try {
|
|
320
|
+
stored = await api.setCauldronDeckExperiments(deckId, experiments);
|
|
321
|
+
}
|
|
322
|
+
catch (e) {
|
|
323
|
+
const reason = e instanceof Error ? e.message : String(e);
|
|
324
|
+
throw new Error(`Experiments NOT saved (${reason}). ` +
|
|
325
|
+
`"${title}" is live on the new client but its experiments are unchanged.`);
|
|
326
|
+
}
|
|
327
|
+
const names = Object.keys(experiments).join(', ');
|
|
328
|
+
console.log(stored
|
|
329
|
+
? `Experiments saved (${names}).`
|
|
330
|
+
: `Experiments not saved (${names}): this Castle server does not support experiments yet. ` +
|
|
331
|
+
'Every player reads null until it does and the deck is saved again.');
|
|
332
|
+
}
|
|
333
|
+
// How long the end of a save waits for the clearing call below.
|
|
334
|
+
export const EXPERIMENTS_CLEAR_SETTLE_MS = 2_000;
|
|
335
|
+
/**
|
|
336
|
+
* A deck that declares no experiments sends null, which is what ends the
|
|
337
|
+
* experiments of a deck whose block was removed: the folder cannot tell whether
|
|
338
|
+
* the saved deck still has one (it may have been saved from another machine),
|
|
339
|
+
* and Ghost writes nothing when there was none.
|
|
340
|
+
*
|
|
341
|
+
* That call is not the save's business, so it is started here and never
|
|
342
|
+
* awaited: the rest of the save goes on at once, and nothing it does can fail
|
|
343
|
+
* the save or print a line. `settle` is for the very end of the save: it gives
|
|
344
|
+
* the call a short while to finish, so the process exiting does not routinely
|
|
345
|
+
* cut it off, then drops it. Exported for the tests.
|
|
346
|
+
*/
|
|
347
|
+
export function startClearingExperiments(deckId) {
|
|
348
|
+
const controller = new AbortController();
|
|
349
|
+
const cleared = api
|
|
350
|
+
.setCauldronDeckExperiments(deckId, null, { signal: controller.signal })
|
|
351
|
+
.then(() => undefined, () => undefined);
|
|
352
|
+
return {
|
|
353
|
+
async settle(capMs = EXPERIMENTS_CLEAR_SETTLE_MS) {
|
|
354
|
+
let timer;
|
|
355
|
+
await Promise.race([
|
|
356
|
+
cleared,
|
|
357
|
+
new Promise((resolve) => {
|
|
358
|
+
timer = setTimeout(resolve, capMs);
|
|
359
|
+
timer.unref();
|
|
360
|
+
}),
|
|
361
|
+
]);
|
|
362
|
+
clearTimeout(timer);
|
|
363
|
+
// A request still out would hold the process open until its own timeout.
|
|
364
|
+
controller.abort();
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
// A content pack is published as part of the server bundle's own release
|
|
369
|
+
// (contentPack.ts): uploaded first, then named in the same save, so Ghost writes
|
|
370
|
+
// both in one row. A Ghost that does not host packs yet gets the bundle alone,
|
|
371
|
+
// as before; the pack stays in `.castle/content-pack/`.
|
|
372
|
+
async function uploadContentPack(deckId, pack) {
|
|
373
|
+
const config = await api.createCauldronContentPackUploadConfig(deckId);
|
|
374
|
+
if (!config) {
|
|
375
|
+
console.log(`Content pack built (${pack.sha256.slice(0, 12)}) but not published: Castle does not host content packs yet.`);
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
await uploadPresignedFile(config, new Blob([new Uint8Array(pack.bytes)], { type: 'application/json' }), 'application/json', LARGE_UPLOAD_TIMEOUT_MS, 'Content pack upload');
|
|
379
|
+
return config.uploadId;
|
|
380
|
+
}
|
|
288
381
|
async function uploadLocalCover(projectDir) {
|
|
289
382
|
try {
|
|
290
383
|
const selected = await selectSaveCover(projectDir, { onProgress: (message) => console.log(message) });
|
|
@@ -371,8 +464,13 @@ export async function saveDeck(dir, opts = {}) {
|
|
|
371
464
|
}
|
|
372
465
|
}
|
|
373
466
|
async function saveDeckAfterValidation(dir, opts, projectDir, visibility) {
|
|
467
|
+
// A builtin kit that changed under the same CLI version is this CLI's again
|
|
468
|
+
// before anything is read, packed or bundled: a save never ships a stale copy
|
|
469
|
+
// of it, and the pins a refreshed kit adds are in the castle.json read here.
|
|
470
|
+
await refreshStaleBuiltinImports(projectDir);
|
|
374
471
|
const castleJson = readCastleJson(projectDir);
|
|
375
472
|
const existingDeckId = typeof castleJson?.deckId === 'string' && castleJson.deckId ? castleJson.deckId : null;
|
|
473
|
+
const experiments = checkedExperiments(castleJson);
|
|
376
474
|
// A deck without an id is new: the source commit sends no precondition, as before.
|
|
377
475
|
let expectedS3Key;
|
|
378
476
|
let markerVia = 'save-deck';
|
|
@@ -384,13 +482,47 @@ async function saveDeckAfterValidation(dir, opts, projectDir, visibility) {
|
|
|
384
482
|
}
|
|
385
483
|
expectedS3Key = precondition.expectedS3Key;
|
|
386
484
|
markerVia = precondition.via;
|
|
485
|
+
if (precondition.adopt && opts.force !== true) {
|
|
486
|
+
// An unsynced folder adopting the saved copy: refused if it would roll an
|
|
487
|
+
// import back (a stale repo copy of a live deck). A check that cannot run
|
|
488
|
+
// (offline, an older Ghost) leaves the save to the server.
|
|
489
|
+
const regressions = await savedDeckImportPins(existingDeckId)
|
|
490
|
+
.then((saved) => (saved ? importRegressions(projectDir, (castleJson?.imports ?? {}), saved) : []))
|
|
491
|
+
.catch((e) => {
|
|
492
|
+
console.warn(`Could not compare imports with the saved deck: ${e instanceof Error ? e.message : String(e)}`);
|
|
493
|
+
return [];
|
|
494
|
+
});
|
|
495
|
+
if (regressions.length > 0) {
|
|
496
|
+
console.error(importRegressionMessage(dir, regressions));
|
|
497
|
+
// castle-www's cloud save understands only its own refusal (exit 5 and
|
|
498
|
+
// its stdout line): there this is a warning, and the save goes ahead.
|
|
499
|
+
if (process.env[SAVE_FAILURE_ENV] !== '1') {
|
|
500
|
+
process.exitCode = EXIT_IMPORTS_OLDER;
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
console.error('Saving anyway (cloud save).');
|
|
504
|
+
}
|
|
505
|
+
}
|
|
387
506
|
if (precondition.adopt) {
|
|
388
507
|
console.error('Note: this folder has no record of which saved copy it came from; adopting it as the ' +
|
|
389
508
|
"deck's saved copy. Later saves are refused if someone else saves this deck in between.");
|
|
390
509
|
}
|
|
391
510
|
}
|
|
392
511
|
console.log('Bundling...');
|
|
393
|
-
|
|
512
|
+
// The imports' `onCheck`s run inside the bundle stage, after the bundle and
|
|
513
|
+
// before anything is uploaded: a deck its kit refuses is a deck that did not
|
|
514
|
+
// build, as far as publishing is concerned (and as castle-www's failed_at
|
|
515
|
+
// reports it).
|
|
516
|
+
const built = await traceSaveStage('bundle', async () => {
|
|
517
|
+
const built = await bundleProject(projectDir);
|
|
518
|
+
const { errors } = await runImportChecks(projectDir);
|
|
519
|
+
if (errors.length > 0)
|
|
520
|
+
throw new Error(importChecksFailedMessage(errors));
|
|
521
|
+
return { html: built, pack: await buildContentPack(projectDir) };
|
|
522
|
+
}, (value) => ({ bytes: Buffer.byteLength(value.html) }));
|
|
523
|
+
const { html: bundle, pack } = built;
|
|
524
|
+
if (pack)
|
|
525
|
+
console.log(`Content pack: ${pack.summary ?? `${pack.bytes.byteLength} bytes`} (${pack.sha256.slice(0, 12)}).`);
|
|
394
526
|
const sizeKB = bundle.length / 1024;
|
|
395
527
|
console.log(`Bundle size: ${sizeKB.toFixed(1)}KB`);
|
|
396
528
|
if (sizeKB > 1024) {
|
|
@@ -491,13 +623,16 @@ async function saveDeckAfterValidation(dir, opts, projectDir, visibility) {
|
|
|
491
623
|
else {
|
|
492
624
|
console.log(`Saved "${title}" to Castle.`);
|
|
493
625
|
}
|
|
626
|
+
const clearingExperiments = experiments ? null : startClearingExperiments(result.deckId);
|
|
627
|
+
if (experiments)
|
|
628
|
+
await publishExperiments(result.deckId, title, experiments);
|
|
494
629
|
// The deck went live above, so anything failing here leaves it skewed: the
|
|
495
630
|
// published client runs against whatever server was last deployed. Say that
|
|
496
631
|
// in the thrown message -- it is the only line the cloud editor gets back
|
|
497
632
|
// (it forwards stderr), and "not valid JSON" reads as a glitch, not as a
|
|
498
633
|
// deck that is now half-published.
|
|
499
634
|
try {
|
|
500
|
-
await traceSaveStage('server_publish', () => publishServerBundle(projectDir, result.deckId));
|
|
635
|
+
await traceSaveStage('server_publish', () => publishServerBundle(projectDir, result.deckId, pack));
|
|
501
636
|
}
|
|
502
637
|
catch (e) {
|
|
503
638
|
const reason = e instanceof Error ? e.message : String(e);
|
|
@@ -518,6 +653,7 @@ async function saveDeckAfterValidation(dir, opts, projectDir, visibility) {
|
|
|
518
653
|
// The save itself succeeded; a missing marker only means the next save adopts again.
|
|
519
654
|
console.error(`Could not record the saved version: ${e instanceof Error ? e.message : String(e)}`);
|
|
520
655
|
}
|
|
656
|
+
await clearingExperiments?.settle();
|
|
521
657
|
}
|
|
522
658
|
catch (e) {
|
|
523
659
|
const code = e?.extensions?.code ?? '';
|
package/dist/serve.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import * as http from 'http';
|
|
2
|
+
import { type Plugin } from 'vite';
|
|
3
|
+
import { type IdeServer } from './ide.js';
|
|
4
|
+
import { type AgentServer } from './agent.js';
|
|
5
|
+
import { type ScriptErrors } from './scriptErrors.js';
|
|
6
|
+
import { DevExperiments } from './devExperiments.js';
|
|
7
|
+
import { ServeSecurity } from './serveSecurity.js';
|
|
2
8
|
export declare function appendCapped(file: string, line: string): void;
|
|
3
9
|
export declare function isViteClientUpgrade(req: http.IncomingMessage): boolean;
|
|
4
10
|
export declare function isAllowedShellHost(hostHeader: string | undefined, configuredHost?: string): boolean;
|
|
5
11
|
export declare function isAllowedContentFilesRequest(role: 'edit' | 'play' | null, method: string | undefined, reqPath: string): boolean;
|
|
6
12
|
export declare function injectDeckHead(html: string, play?: boolean): string;
|
|
13
|
+
export declare function castlePlugin(security: ServeSecurity, ideServer: IdeServer, agentServer: AgentServer, scriptErrors: ScriptErrors, projectDir: string, configuredHost?: string): Plugin;
|
|
14
|
+
export declare function devExperimentsFor(projectDir: string): DevExperiments;
|
|
7
15
|
export declare function serve(dir: string, options?: {
|
|
8
16
|
port?: string;
|
|
9
17
|
host?: string;
|
package/dist/serve.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { handleContentPackRequest } from './contentPack.js';
|
|
1
2
|
import { placeCoverBridge } from './playCoverPlacement.js';
|
|
2
3
|
import * as fs from 'fs';
|
|
3
4
|
import * as http from 'http';
|
|
@@ -19,13 +20,15 @@ import { createScriptErrors, scriptErrorsPlugin } from './scriptErrors.js';
|
|
|
19
20
|
import { installFilesChangedWatcher } from './filesChanged.js';
|
|
20
21
|
import { installGitHeadWatcher } from './gitHeadWatcher.js';
|
|
21
22
|
import { applyDeckWrite, createTuneLedger } from './paramsTunes.js';
|
|
22
|
-
import { autoUpdateImports, IMPORTS_DIR, lockImportTree } from './imports.js';
|
|
23
|
+
import { autoUpdateImports, IMPORTS_DIR, lockImportTree, refreshStaleBuiltinImports } from './imports.js';
|
|
23
24
|
import { ensureAgentsSymlink } from './init.js';
|
|
24
25
|
import { migrateClaudeMd, PLATFORM_DOC_REL, writePlatformDocs } from './platformDoc.js';
|
|
25
26
|
import { FORKS_DIR, ownForkFile, splitImportRel } from './forks.js';
|
|
26
27
|
import * as config from './config.js';
|
|
27
28
|
import { graphql as castleGraphql } from './api.js';
|
|
28
29
|
import { executeCommand } from './castle-host/host.js';
|
|
30
|
+
import { DevHubVisit, readDevHubDoors } from './devHub.js';
|
|
31
|
+
import { DevExperiments } from './devExperiments.js';
|
|
29
32
|
import { serveOracleStream } from './deckAgentRoute.js';
|
|
30
33
|
import { ServeSecurity } from './serveSecurity.js';
|
|
31
34
|
import { atomicWriteFileSync } from './atomicFile.js';
|
|
@@ -34,7 +37,7 @@ import { createAssetCompression } from './assetCompression.js';
|
|
|
34
37
|
import { playCoverHeadInjection } from './playCoverGate.js';
|
|
35
38
|
import { isPlayPageUrl, playPageHeadInjection } from './playPagePolicy.js';
|
|
36
39
|
import { resolveServerConfig } from './castleJson.js';
|
|
37
|
-
import { startDevSessionServer, } from './devSessionServer.js';
|
|
40
|
+
import { startDevSessionServer, devSessionIdFor, } from './devSessionServer.js';
|
|
38
41
|
// The log is a tail, not an archive: append, and once it passes the cap drop
|
|
39
42
|
// whole lines off the front until it is back under.
|
|
40
43
|
const LOG_MAX_BYTES = 2 * 1024 * 1024;
|
|
@@ -623,7 +626,8 @@ window.__castleShellOrigin=(function(){
|
|
|
623
626
|
const page = injectIntoHead(html, injected);
|
|
624
627
|
return cover ? placeCoverBridge(page, cover) : page;
|
|
625
628
|
}
|
|
626
|
-
|
|
629
|
+
// Exported for the tests.
|
|
630
|
+
export function castlePlugin(security, ideServer, agentServer, scriptErrors, projectDir, configuredHost) {
|
|
627
631
|
return {
|
|
628
632
|
name: 'castle-dev',
|
|
629
633
|
transformIndexHtml: {
|
|
@@ -727,12 +731,22 @@ function castlePlugin(security, ideServer, agentServer, scriptErrors, configured
|
|
|
727
731
|
if (reqPath === '/')
|
|
728
732
|
req.url = `/index.html${req.url?.includes('?') ? req.url.slice(req.url.indexOf('?')) : ''}`;
|
|
729
733
|
const allowedFilesRequest = isAllowedContentFilesRequest(contentRole, req.method, reqPath);
|
|
734
|
+
// Doors to other local decks (contentPack.ts): read-only, and limited to
|
|
735
|
+
// the decks this deck's castle.json lists. Either content role: a
|
|
736
|
+
// phone plays from the play URL.
|
|
737
|
+
if (reqPath.startsWith('/__castle/content-pack/')) {
|
|
738
|
+
void handleContentPackRequest(projectDir, req, res, reqPath);
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
730
741
|
const allowedVendor = reqPath.startsWith('/__castle/vendor/');
|
|
731
742
|
const allowedFavicon = FAVICON_FILES.some((name) => reqPath === `/${name}`);
|
|
732
743
|
if (reqPath.startsWith('/__castle/') && !allowedFilesRequest && !allowedVendor) {
|
|
733
744
|
res.writeHead(403).end('content capability does not allow this endpoint');
|
|
734
745
|
return;
|
|
735
746
|
}
|
|
747
|
+
// Only a request that got this far may force an A/B arm
|
|
748
|
+
// (devExperiments.ts): one refused above changes nothing.
|
|
749
|
+
devExperimentsFor(projectDir).noteUrl(req.url);
|
|
736
750
|
if ((allowedFilesRequest || allowedVendor || allowedFavicon) &&
|
|
737
751
|
ideServer.handleHttpRequest(req, res, reqPath))
|
|
738
752
|
return;
|
|
@@ -749,6 +763,7 @@ function castlePlugin(security, ideServer, agentServer, scriptErrors, configured
|
|
|
749
763
|
security.rejectHttpAuth(res);
|
|
750
764
|
return;
|
|
751
765
|
}
|
|
766
|
+
devExperimentsFor(projectDir).noteUrl(req.url);
|
|
752
767
|
// The split-view shell (`/`) + its static assets are served outside
|
|
753
768
|
// Vite's module pipeline; the deck itself loads in the iframe via
|
|
754
769
|
// `/index.html`, which Vite still serves normally.
|
|
@@ -783,19 +798,63 @@ async function devMe() {
|
|
|
783
798
|
}
|
|
784
799
|
return cachedDevMe;
|
|
785
800
|
}
|
|
786
|
-
|
|
801
|
+
// A/B experiments per served deck (devExperiments.ts): the arms forced through
|
|
802
|
+
// `?experiment.<name>=` live here, for the serve's lifetime.
|
|
803
|
+
const devExperiments = new Map();
|
|
804
|
+
// Exported for the tests.
|
|
805
|
+
export function devExperimentsFor(projectDir) {
|
|
806
|
+
let experiments = devExperiments.get(projectDir);
|
|
807
|
+
if (!experiments) {
|
|
808
|
+
experiments = new DevExperiments(projectDir, (text) => console.warn(`[experiments] ${text}`));
|
|
809
|
+
devExperiments.set(projectDir, experiments);
|
|
810
|
+
}
|
|
811
|
+
return experiments;
|
|
812
|
+
}
|
|
813
|
+
// The SDK prefixes every request id with a value drawn once per page load
|
|
814
|
+
// (transport.ts), which is what makes a page load nameable here.
|
|
815
|
+
function commandPageLoad(requestId) {
|
|
816
|
+
return /^(csdk_[a-z0-9]+)_\d+$/.exec(requestId)?.[1] ?? null;
|
|
817
|
+
}
|
|
818
|
+
async function devHostContext(projectDir, requestId) {
|
|
787
819
|
const ctx = readDeckContext(projectDir);
|
|
788
820
|
const me = await devMe();
|
|
821
|
+
const userId = config.getUserId() ?? me.userId;
|
|
789
822
|
return {
|
|
790
823
|
deckId: ctx.deckId ?? null,
|
|
791
824
|
sessionId: null,
|
|
792
|
-
userId
|
|
825
|
+
userId,
|
|
793
826
|
username: me.username,
|
|
827
|
+
// Assigned under the id local multiplayer gives this player, and held for
|
|
828
|
+
// the page load, so the page and the deck's server read the same arm.
|
|
829
|
+
experimentVariants: devExperimentsFor(projectDir).variantsForPage(commandPageLoad(requestId), userId ?? DEV_ANONYMOUS_USER_ID, ctx.deckId ?? null),
|
|
794
830
|
};
|
|
795
831
|
}
|
|
796
832
|
// Agent.chat's route to deck-agent: the CLI's login token locally, the sandbox
|
|
797
833
|
// host's llm-proxy inside a cloud sandbox (deckAgentRoute.ts).
|
|
798
834
|
const oracleStream = serveOracleStream(() => config.getToken());
|
|
835
|
+
// Hub doors per connected page (devHub.ts), and the pads gathering across all
|
|
836
|
+
// of them. The local multiplayer URL depends on which origin the page came
|
|
837
|
+
// through, so each command hands its visit the current one.
|
|
838
|
+
// Play panels share the shell's socket, so a visit is per socket and panel.
|
|
839
|
+
const hubVisits = new WeakMap();
|
|
840
|
+
const devPadGroups = new Map();
|
|
841
|
+
function devHubVisit(ws, playSessionSlot, projectDir, multiplayer, multiplayerUrl) {
|
|
842
|
+
const panels = hubVisits.get(ws) ?? new Map();
|
|
843
|
+
hubVisits.set(ws, panels);
|
|
844
|
+
let entry = panels.get(playSessionSlot ?? '');
|
|
845
|
+
if (!entry) {
|
|
846
|
+
const mp = { url: multiplayerUrl };
|
|
847
|
+
const visit = new DevHubVisit(() => readDevHubDoors(projectDir, (text) => console.warn(`[hub] ${text}`)), {
|
|
848
|
+
url: () => (multiplayer ? mp.url : null),
|
|
849
|
+
mintNonce: (ctx, key) => multiplayer.mintNonce(devMultiplayerIdentity(ctx), key, ctx.experimentVariants ?? undefined),
|
|
850
|
+
sessionIdFor: (key) => devSessionIdFor(key),
|
|
851
|
+
}, devPadGroups);
|
|
852
|
+
entry = { visit, mp };
|
|
853
|
+
panels.set(playSessionSlot ?? '', entry);
|
|
854
|
+
}
|
|
855
|
+
entry.mp.url = multiplayerUrl;
|
|
856
|
+
return entry.visit;
|
|
857
|
+
}
|
|
799
858
|
// Commands in flight on each socket, so a deck's cancel or a closed socket can
|
|
800
859
|
// abort a streaming one.
|
|
801
860
|
const commandAborts = new WeakMap();
|
|
@@ -815,7 +874,7 @@ async function handleCastleCommand(ws, projectDir, broadcast, multiplayer, multi
|
|
|
815
874
|
commandAborts.set(ws, aborts);
|
|
816
875
|
const controller = new AbortController();
|
|
817
876
|
aborts.set(requestId, controller);
|
|
818
|
-
const ctx = await devHostContext(projectDir);
|
|
877
|
+
const ctx = await devHostContext(projectDir, requestId);
|
|
819
878
|
const onStream = (event) => {
|
|
820
879
|
if (ws.readyState === WebSocket.OPEN) {
|
|
821
880
|
ws.send(JSON.stringify({ type: 'castle_command_stream', castleSdk: 1, requestId, stream: event }));
|
|
@@ -830,7 +889,8 @@ async function handleCastleCommand(ws, projectDir, broadcast, multiplayer, multi
|
|
|
830
889
|
graphqlFetch: castleGraphql,
|
|
831
890
|
oracleStream,
|
|
832
891
|
showLeaderboard: (payload) => broadcast({ type: 'castle_leaderboard_show', payload }),
|
|
833
|
-
|
|
892
|
+
hub: devHubVisit(ws, playSessionSlot, projectDir, multiplayer, multiplayerUrl),
|
|
893
|
+
getMultiplayerSession: (request) => {
|
|
834
894
|
if (!multiplayer || !multiplayerUrl) {
|
|
835
895
|
return Promise.resolve({
|
|
836
896
|
status: 'unavailable',
|
|
@@ -840,11 +900,13 @@ async function handleCastleCommand(ws, projectDir, broadcast, multiplayer, multi
|
|
|
840
900
|
soloReason: null,
|
|
841
901
|
});
|
|
842
902
|
}
|
|
903
|
+
// Each named key runs its own local session; public and party share 'dev'.
|
|
904
|
+
const key = request.mode === 'named' ? (request.key ?? null) : null;
|
|
843
905
|
return Promise.resolve({
|
|
844
906
|
status: 'ok',
|
|
845
907
|
url: multiplayerUrl,
|
|
846
|
-
nonce: multiplayer.mintNonce(devMultiplayerIdentity(ctx)),
|
|
847
|
-
sessionId: multiplayer.
|
|
908
|
+
nonce: multiplayer.mintNonce(devMultiplayerIdentity(ctx), key, ctx.experimentVariants ?? undefined),
|
|
909
|
+
sessionId: multiplayer.sessionIdFor(key),
|
|
848
910
|
soloReason: null,
|
|
849
911
|
...(playSessionSlot ? { devReconnectScope: playSessionSlot } : {}),
|
|
850
912
|
});
|
|
@@ -855,13 +917,18 @@ async function handleCastleCommand(ws, projectDir, broadcast, multiplayer, multi
|
|
|
855
917
|
ws.send(JSON.stringify({ type: 'castle_command_response', castleSdk: 1, requestId, ...result }));
|
|
856
918
|
}
|
|
857
919
|
}
|
|
920
|
+
const DEV_ANONYMOUS_USER_ID = 'dev-user';
|
|
858
921
|
function devMultiplayerIdentity(ctx) {
|
|
859
922
|
return {
|
|
860
|
-
userId: ctx.userId ??
|
|
923
|
+
userId: ctx.userId ?? DEV_ANONYMOUS_USER_ID,
|
|
861
924
|
username: ctx.username ?? 'Developer',
|
|
862
925
|
isAnonymous: ctx.userId === null,
|
|
863
926
|
};
|
|
864
927
|
}
|
|
928
|
+
function isLoopbackRequest(req) {
|
|
929
|
+
const address = req.socket.remoteAddress;
|
|
930
|
+
return address === '127.0.0.1' || address === '::1' || address === '::ffff:127.0.0.1';
|
|
931
|
+
}
|
|
865
932
|
function devMultiplayerUrl(req) {
|
|
866
933
|
const base = typeof req.headers.origin === 'string' ? req.headers.origin : null;
|
|
867
934
|
if (!base)
|
|
@@ -1074,6 +1141,12 @@ export async function serve(dir, options = {}) {
|
|
|
1074
1141
|
let importsChangedAtStartup = false;
|
|
1075
1142
|
if (!existingServe(projectDir)) {
|
|
1076
1143
|
const importsBeforeUpdate = importPinsFingerprint(projectDir);
|
|
1144
|
+
// A builtin kit that changed under the same CLI version replaces the deck's
|
|
1145
|
+
// copy here too, where nothing is running yet.
|
|
1146
|
+
const refreshed = await refreshStaleBuiltinImports(projectDir).catch((e) => {
|
|
1147
|
+
console.warn(`builtin kits: left as they are -- ${e instanceof Error ? e.message : String(e)}`);
|
|
1148
|
+
return [];
|
|
1149
|
+
});
|
|
1077
1150
|
// A failure to check must never keep the deck from opening.
|
|
1078
1151
|
const updated = await autoUpdateImports(projectDir).catch((e) => {
|
|
1079
1152
|
console.warn(`auto-update: skipped -- ${e instanceof Error ? e.message : String(e)}`);
|
|
@@ -1082,7 +1155,9 @@ export async function serve(dir, options = {}) {
|
|
|
1082
1155
|
// Comparing pins as well as the returned list preserves the invalidation
|
|
1083
1156
|
// if a later step throws after one or more imported trees were replaced.
|
|
1084
1157
|
importsChangedAtStartup =
|
|
1085
|
-
|
|
1158
|
+
refreshed.length > 0 ||
|
|
1159
|
+
updated.length > 0 ||
|
|
1160
|
+
importsBeforeUpdate !== importPinsFingerprint(projectDir);
|
|
1086
1161
|
}
|
|
1087
1162
|
// Start pulling the headless browser now, in the background.
|
|
1088
1163
|
//
|
|
@@ -1263,7 +1338,7 @@ export async function serve(dir, options = {}) {
|
|
|
1263
1338
|
// HMR is off (below), but Vite still injects and imports `/@vite/client`.
|
|
1264
1339
|
// Serve a socket-free stub of it so no page logs a failed HMR connection.
|
|
1265
1340
|
viteClientStubPlugin(),
|
|
1266
|
-
castlePlugin(security, ideServer, agentServer, scriptErrors, options.host),
|
|
1341
|
+
castlePlugin(security, ideServer, agentServer, scriptErrors, projectDir, options.host),
|
|
1267
1342
|
forksOverlayPlugin(),
|
|
1268
1343
|
importsAliasPlugin(),
|
|
1269
1344
|
sdkAliasPlugin(),
|
|
@@ -1590,7 +1665,13 @@ function startWSServer(projectDir, logFile, screenshotsDir, viteHolder, security
|
|
|
1590
1665
|
};
|
|
1591
1666
|
wss.on('connection', (ws, req) => {
|
|
1592
1667
|
clients.add(ws);
|
|
1593
|
-
|
|
1668
|
+
// A loopback client with no Origin (a CLI or a script, which is all the
|
|
1669
|
+
// root path admits) has no content origin to proxy through, so it joins
|
|
1670
|
+
// the dev session server directly: how script-driven test players get in.
|
|
1671
|
+
const multiplayerUrl = devMultiplayerUrl(req) ??
|
|
1672
|
+
(multiplayer && !req.headers.origin && isLoopbackRequest(req)
|
|
1673
|
+
? `ws://127.0.0.1:${multiplayer.port}/__castle/mp`
|
|
1674
|
+
: null);
|
|
1594
1675
|
const legacyRole = legacyRoles.get(ws) ?? null;
|
|
1595
1676
|
ws.on('message', (raw) => {
|
|
1596
1677
|
try {
|
package/dist/serverBundle.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export interface ServerBundle {
|
|
|
5
5
|
sizeBytes: number;
|
|
6
6
|
}
|
|
7
7
|
export declare function buildServerBundle(projectDir: string): Promise<ServerBundle | null>;
|
|
8
|
-
export declare function bundleServerModule(projectDir: string, config: ResolvedServerConfig, minify: boolean): Promise<string>;
|
|
8
|
+
export declare function bundleServerModule(projectDir: string, config: ResolvedServerConfig, minify: boolean, define?: Record<string, string>): Promise<string>;
|
package/dist/serverBundle.js
CHANGED
|
@@ -33,7 +33,10 @@ export async function buildServerBundle(projectDir) {
|
|
|
33
33
|
// Dev and publish deliberately share the synthesized entry and Vite semantics.
|
|
34
34
|
// Dev keeps readable code; the published artifact is minified and checked below
|
|
35
35
|
// for the single-output-file contract.
|
|
36
|
-
export async function bundleServerModule(projectDir, config, minify
|
|
36
|
+
export async function bundleServerModule(projectDir, config, minify,
|
|
37
|
+
// Compile-time constants for this build only (the dev serve's
|
|
38
|
+
// `import.meta.env.CASTLE_DEV_DECKS`); a published bundle has none.
|
|
39
|
+
define = {}) {
|
|
37
40
|
// The synthesized entry names the file directly, so it has to resolve here
|
|
38
41
|
// rather than through the plugin: the deck's `base` import when it has one,
|
|
39
42
|
// node_modules for a deck predating the move.
|
|
@@ -57,6 +60,7 @@ export async function bundleServerModule(projectDir, config, minify) {
|
|
|
57
60
|
root: projectDir,
|
|
58
61
|
configFile: false,
|
|
59
62
|
logLevel: 'silent',
|
|
63
|
+
define,
|
|
60
64
|
plugins: [forksOverlayPlugin(), importsAliasPlugin(), sdkAliasPlugin(), entryPlugin],
|
|
61
65
|
ssr: { noExternal: true },
|
|
62
66
|
build: {
|
package/dist/webSourceSync.d.ts
CHANGED
|
@@ -48,6 +48,8 @@ export declare function fetchServerSourceVersion(deckId: string): Promise<Server
|
|
|
48
48
|
export declare function humanTime(iso: string): string;
|
|
49
49
|
/** save-deck's exit code when the saved copy is newer than this folder (1-4 are taken). */
|
|
50
50
|
export declare const EXIT_SAVED_DECK_NEWER = 5;
|
|
51
|
+
/** save-deck's exit code when an unsynced folder would move the saved deck's imports back. */
|
|
52
|
+
export declare const EXIT_IMPORTS_OLDER = 6;
|
|
51
53
|
export declare const SAVE_REFUSED_PREFIX = "CASTLE_SAVE_REFUSED ";
|
|
52
54
|
export declare const SAVED_DECK_NEWER_CODE = "SAVED_DECK_NEWER";
|
|
53
55
|
/** Ghost's code when its own check (primary, under lock) refuses the source commit. */
|
package/dist/webSourceSync.js
CHANGED
|
@@ -125,6 +125,8 @@ export function humanTime(iso) {
|
|
|
125
125
|
// --- save-deck refusal --------------------------------------------------------
|
|
126
126
|
/** save-deck's exit code when the saved copy is newer than this folder (1-4 are taken). */
|
|
127
127
|
export const EXIT_SAVED_DECK_NEWER = 5;
|
|
128
|
+
/** save-deck's exit code when an unsynced folder would move the saved deck's imports back. */
|
|
129
|
+
export const EXIT_IMPORTS_OLDER = 6;
|
|
128
130
|
export const SAVE_REFUSED_PREFIX = 'CASTLE_SAVE_REFUSED ';
|
|
129
131
|
export const SAVED_DECK_NEWER_CODE = 'SAVED_DECK_NEWER';
|
|
130
132
|
/** Ghost's code when its own check (primary, under lock) refuses the source commit. */
|
package/kits/base/CLAUDE.md
CHANGED
|
@@ -15,7 +15,7 @@ that framework provides. This one is true either way.
|
|
|
15
15
|
<!-- Injected into Castle's create assistant every turn; keep this compact and factual. -->
|
|
16
16
|
|
|
17
17
|
- `import { setup, initCard } from 'castle-web-sdk'`. Call `setup()` first, once; `initCard()` returns the element to render into (a React tree mounted at `#root` needs no `initCard`). Castle services — `Store`, `Leaderboard`, `Time`, `User`, `Haptics`, `Pass`, `Snapshot`, `Portal`, `Multiplayer`, `Lifecycle` — come from the same package. `Store` is how a deck saves anything; the older `Storage`/`SharedStorage` still work but should not be used in new decks; the full reference is `imports/castle.base/sdk/README.md`.
|
|
18
|
-
- `Agent.chat({ messages, tools?, toolChoice?, model?, maxTokens?, reasoning?, onDelta?, signal? })` gets one chat completion from a language model (OpenAI message and tool format, default model `meta/muse-spark-1.3-contributor`; any OpenRouter model id with a per-token price) through Castle's deck-agent service, paid from the player's daily play allowance that characters share. `onDelta` streams text and reasoning pieces and each finished tool call; `signal` cancels; `reasoning: { effort: 'minimal' | 'low' | 'medium' | 'high' }` sets how hard the model thinks, and minimal answers soonest. It resolves with the whole `message`: the deck runs any `tool_calls` itself, appends the message unchanged (it can carry the model's `reasoning_details`) and the `tool` results, and calls again.
|
|
18
|
+
- `Agent.chat({ messages, tools?, toolChoice?, model?, maxTokens?, reasoning?, onDelta?, signal? })` gets one chat completion from a language model (OpenAI message and tool format, default model `meta/muse-spark-1.3-contributor`; any OpenRouter model id with a per-token price) through Castle's deck-agent service, paid from the player's daily play allowance that characters share. `onDelta` streams text and reasoning pieces and each finished tool call; `signal` cancels; `reasoning: { effort: 'minimal' | 'low' | 'medium' | 'high' }` sets how hard the model thinks, and minimal answers soonest. It resolves with the whole `message`: the deck runs any `tool_calls` itself, appends the message unchanged (it can carry the model's `reasoning_details`) and the `tool` results, and calls again. Castle admins and players given access only: other players get `refused`; a player whose allowance for the day is spent gets `allowance_exhausted` (it resets at midnight UTC).
|
|
19
19
|
- `Decks.mine({ limit? })` and `Decks.saved({ limit? })` list decks a portal can lead to (the player's published decks; their bookmarks and playlists) as `{ deckId, title, creator, coverUrl }`, with `coverUrl` a `data:` url. Use them to offer a portal destination picker. Admin only: other players get a `PERMISSION_DENIED` error.
|
|
20
20
|
- What each service cannot do is in that README beside the service: `Store` / `Storage` size caps (no media in storage), the Castle app build a command needs (older builds reject it with `UNKNOWN_COMMAND`), no clipboard command, no call that sets the deck's cover. Read it before telling someone a service can or cannot do something.
|
|
21
21
|
- The SDK is a file of this import, not an npm package: `castle-web-sdk` resolves here. Nothing needs installing, and nothing in a deck's `package.json` names it.
|
|
@@ -35,8 +35,7 @@ named in the bullet above.
|
|
|
35
35
|
|
|
36
36
|
The three calls almost every deck makes:
|
|
37
37
|
|
|
38
|
-
- `setup()` — once, before anything else. Mounts the Castle card
|
|
39
|
-
whole stage for a deck that declares `castle-display` fill) and, while
|
|
38
|
+
- `setup()` — once, before anything else. Mounts the 5:7 Castle card and, while
|
|
40
39
|
serving locally, forwards `console` output to the CLI.
|
|
41
40
|
- `initCard()` — the element to draw into, when the deck renders into a
|
|
42
41
|
`<canvas>` or raw DOM rather than a React tree at `#root`.
|