castle-web-cli 0.4.157 → 0.4.159
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-failures.d.ts +1 -0
- package/dist/agent-failures.js +6 -4
- package/dist/agent-prompts.js +4 -0
- package/dist/agent.d.ts +11 -0
- package/dist/agent.js +175 -15
- package/dist/bundle.js +8 -2
- package/dist/castle-host/host.js +4 -2
- package/dist/castleJson.js +6 -1
- package/dist/check.d.ts +1 -0
- package/dist/check.js +25 -0
- package/dist/devSessionServer.js +31 -7
- package/dist/imports.js +1 -19
- package/dist/index.js +15 -1
- package/dist/init.d.ts +2 -2
- package/dist/init.js +78 -42
- package/dist/mcpPlaytest.d.ts +1 -0
- package/dist/mcpPlaytest.js +182 -0
- package/dist/metering.d.ts +24 -0
- package/dist/metering.js +87 -0
- package/dist/sdkResolve.d.ts +3 -0
- package/dist/sdkResolve.js +55 -0
- package/dist/serve.js +50 -4
- package/dist/serverBundle.js +8 -3
- package/dist/shell/assets/{index-DsDkYFvP.js → index-DMSoTyXh.js} +64 -64
- package/dist/shell/assets/{index-DwezawBs.css → index-DfZmu3XC.css} +1 -1
- package/dist/shell/index.html +2 -2
- package/dist/vitePlugins.d.ts +1 -0
- package/dist/vitePlugins.js +20 -0
- package/kits/base/CLAUDE.md +196 -0
- package/kits/{blank → base}/castle.json +5 -2
- package/kits/base/editorHost.js +172 -0
- package/kits/{blank → base}/node_modules/.package-lock.json +3 -2
- package/kits/{blank → base}/package-lock.json +7 -4
- package/kits/{blank → base}/package.json +4 -2
- package/kits/base/sdk/README.md +569 -0
- package/kits/base/sdk/castle.d.ts +27 -0
- package/kits/base/sdk/castle.js +16 -0
- package/kits/base/sdk/commands.d.ts +181 -0
- package/kits/base/sdk/commands.js +16 -0
- package/kits/base/sdk/context.d.ts +17 -0
- package/kits/base/sdk/context.js +15 -0
- package/kits/base/sdk/errors.d.ts +22 -0
- package/kits/base/sdk/errors.js +16 -0
- package/kits/base/sdk/files.d.ts +15 -0
- package/kits/base/sdk/files.js +52 -0
- package/kits/base/sdk/haptics.d.ts +6 -0
- package/kits/base/sdk/haptics.js +36 -0
- package/kits/base/sdk/leaderboard.d.ts +26 -0
- package/kits/base/sdk/leaderboard.js +296 -0
- package/kits/base/sdk/lifecycle.d.ts +4 -0
- package/kits/base/sdk/lifecycle.js +13 -0
- package/kits/base/sdk/multiplayer.d.ts +43 -0
- package/kits/base/sdk/multiplayer.js +464 -0
- package/kits/base/sdk/multiplayerProtocol.d.ts +51 -0
- package/kits/base/sdk/multiplayerProtocol.js +5 -0
- package/kits/base/sdk/passes.d.ts +7 -0
- package/kits/base/sdk/passes.js +84 -0
- package/kits/base/sdk/portal.d.ts +7 -0
- package/kits/base/sdk/portal.js +35 -0
- package/kits/base/sdk/runtime.d.ts +62 -0
- package/kits/base/sdk/runtime.js +970 -0
- package/kits/base/sdk/saveQueue.d.ts +27 -0
- package/kits/base/sdk/saveQueue.js +205 -0
- package/kits/base/sdk/server/platformHandle.d.ts +25 -0
- package/kits/base/sdk/server/platformHandle.js +1 -0
- package/kits/base/sdk/server/wrapper.d.ts +28 -0
- package/kits/base/sdk/server/wrapper.js +109 -0
- package/kits/base/sdk/storage.d.ts +16 -0
- package/kits/base/sdk/storage.js +323 -0
- package/kits/base/sdk/time.d.ts +17 -0
- package/kits/base/sdk/time.js +120 -0
- package/kits/base/sdk/transport.d.ts +17 -0
- package/kits/base/sdk/transport.js +141 -0
- package/kits/base/sdk/types.d.ts +3 -0
- package/kits/base/sdk/types.js +1 -0
- package/kits/base/sdk/user.d.ts +10 -0
- package/kits/base/sdk/user.js +45 -0
- package/kits/multiplayer-2d/.prettierrc +5 -0
- package/kits/multiplayer-2d/CLAUDE.md +129 -0
- package/kits/multiplayer-2d/behaviors/Box.jsx +92 -0
- package/kits/multiplayer-2d/behaviors/Player.jsx +86 -0
- package/kits/multiplayer-2d/blueprints/crate.scene +13 -0
- package/kits/multiplayer-2d/blueprints/other-player.scene +13 -0
- package/kits/multiplayer-2d/blueprints/player.scene +15 -0
- package/kits/multiplayer-2d/blueprints/wall.scene +12 -0
- package/kits/multiplayer-2d/castle.json +39 -0
- package/kits/multiplayer-2d/code/client/avatars.js +93 -0
- package/kits/multiplayer-2d/code/client/poses.js +168 -0
- package/kits/multiplayer-2d/code/server/index.js +26 -0
- package/kits/multiplayer-2d/code/server/limits.js +99 -0
- package/kits/multiplayer-2d/code/server/ownership.js +177 -0
- package/kits/multiplayer-2d/code/server/players.js +127 -0
- package/kits/multiplayer-2d/code/server/sceneBodies.js +98 -0
- package/kits/multiplayer-2d/code/server/world.js +337 -0
- package/kits/multiplayer-2d/code/systems/multiplayer.js +424 -0
- package/kits/multiplayer-2d/eslint.config.js +21 -0
- package/kits/multiplayer-2d/fonts.generated.js +9 -0
- package/kits/multiplayer-2d/index.html +25 -0
- package/kits/multiplayer-2d/main.jsx +10 -0
- package/kits/multiplayer-2d/package-lock.json +351 -0
- package/kits/multiplayer-2d/package.json +30 -0
- package/kits/multiplayer-2d/scenes/main.scene +20 -0
- package/kits/multiplayer-2d/test/two-client-test.mjs +341 -0
- package/kits/multiplayer-2d/theme.style +4 -0
- package/kits/multiplayer-3d/.prettierrc +5 -0
- package/kits/multiplayer-3d/CLAUDE.md +215 -0
- package/kits/multiplayer-3d/blueprints/ball.scene +21 -0
- package/kits/multiplayer-3d/blueprints/other-player.scene +21 -0
- package/kits/multiplayer-3d/castle.json +43 -0
- package/kits/multiplayer-3d/code/client/avatars.js +136 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +101 -0
- package/kits/multiplayer-3d/code/client/poses.js +220 -0
- package/kits/multiplayer-3d/code/server/index.js +23 -0
- package/kits/multiplayer-3d/code/server/limits.js +107 -0
- package/kits/multiplayer-3d/code/server/ownership.js +157 -0
- package/kits/multiplayer-3d/code/server/players.js +114 -0
- package/kits/multiplayer-3d/code/server/sceneBodies.js +88 -0
- package/kits/multiplayer-3d/code/server/world.js +306 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +427 -0
- package/kits/multiplayer-3d/eslint.config.js +20 -0
- package/kits/multiplayer-3d/fonts.generated.js +9 -0
- package/kits/multiplayer-3d/index.html +22 -0
- package/kits/multiplayer-3d/main.jsx +9 -0
- package/kits/multiplayer-3d/package-lock.json +368 -0
- package/kits/multiplayer-3d/package.json +32 -0
- package/kits/multiplayer-3d/scenes/main.scene +409 -0
- package/kits/multiplayer-3d/theme.style +3 -0
- package/kits/physics-2d/CLAUDE.md +6 -0
- package/kits/physics-2d/castle.json +7 -1
- package/kits/physics-2d/editors/behaviorRegistry.js +5 -0
- package/kits/physics-2d/editors/editorRegistry.jsx +3 -1
- package/kits/physics-2d/engine/files.js +9 -5
- package/kits/physics-2d/engine/systemRegistry.js +2 -0
- package/kits/physics-2d/engine/ui.module.css +11 -0
- package/kits/physics-2d/package-lock.json +8 -2
- package/kits/physics-2d/package.json +2 -2
- package/kits/physics-3d/CLAUDE.md +4 -4
- package/kits/physics-3d/behaviors/Shape.jsx +1 -1
- package/kits/physics-3d/blueprints/crate.scene +1 -1
- package/kits/physics-3d/blueprints/door.scene +4 -4
- package/kits/physics-3d/blueprints/pillar.scene +1 -1
- package/kits/physics-3d/blueprints/platform.scene +1 -1
- package/kits/physics-3d/blueprints/statue.scene +1 -1
- package/kits/physics-3d/blueprints/wall.scene +1 -1
- package/kits/physics-3d/castle.json +8 -11
- package/kits/physics-3d/docs/pxmodel-format.md +1 -1
- package/kits/physics-3d/engine3d/materials.js +3 -3
- package/kits/physics-3d/engine3d/modelFiles.js +4 -2
- package/kits/physics-3d/engine3d/world3d.js +1 -1
- package/kits/physics-3d/fonts.generated.js +9 -0
- package/kits/physics-3d/main.jsx +1 -1
- package/kits/physics-3d/package-lock.json +85 -2
- package/kits/physics-3d/package.json +6 -2
- package/kits/physics-3d/scenes/main.scene +1 -1
- package/kits/physics-3d/scenes/model-lab.scene +1 -1
- package/kits/real-time/.prettierrc +5 -0
- package/kits/real-time/CLAUDE.md +60 -0
- package/kits/real-time/castle.json +19 -0
- package/kits/real-time/code/client/clock.js +68 -0
- package/kits/real-time/code/client/connection.js +134 -0
- package/kits/real-time/code/client/gameHooks.js +50 -0
- package/kits/real-time/code/client/interpolate.js +82 -0
- package/kits/real-time/code/client/messages.js +55 -0
- package/kits/real-time/code/client/ownership.js +94 -0
- package/kits/real-time/code/client/smooth.js +54 -0
- package/kits/real-time/code/server/blockDelta.js +48 -0
- package/kits/real-time/code/server/gameHooks.js +47 -0
- package/kits/real-time/code/server/limits.js +35 -0
- package/kits/real-time/code/server/session.js +251 -0
- package/kits/real-time/eslint.config.js +22 -0
- package/kits/real-time/index.html +45 -0
- package/kits/real-time/package.json +14 -0
- package/kits/{tabletop → turn-based}/CLAUDE.md +42 -49
- package/kits/turn-based/blueprints/board.scene +15 -0
- package/kits/turn-based/blueprints/square.scene +25 -0
- package/kits/turn-based/castle.json +37 -0
- package/kits/turn-based/code/behaviors/Board.jsx +169 -0
- package/kits/turn-based/code/behaviors/Square.jsx +26 -0
- package/kits/turn-based/code/server/index.js +152 -0
- package/kits/turn-based/drawings/square.sprite +25 -0
- package/kits/turn-based/eslint.config.js +12 -0
- package/kits/turn-based/fonts.generated.js +9 -0
- package/kits/{tabletop → turn-based}/index.html +5 -3
- package/kits/{tabletop → turn-based}/main.jsx +2 -2
- package/kits/{tabletop → turn-based}/package-lock.json +17 -4
- package/kits/{tabletop → turn-based}/package.json +5 -2
- package/kits/turn-based/room.js +289 -0
- package/kits/turn-based/scenes/main.scene +227 -0
- package/kits/{tabletop → turn-based}/testing.js +131 -99
- package/kits/turn-based/theme.style +3 -0
- package/package.json +1 -1
- package/kits/blank/CLAUDE.md +0 -198
- package/kits/tabletop/castle.json +0 -34
- package/kits/tabletop/room.js +0 -269
- /package/kits/{blank → base}/index.html +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/README.md +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/catalog.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/catalog.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/face.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/face.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/Bore.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/Bore.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/CourierPrime.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/CourierPrime.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/DMSans.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/DMSans.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/Glacier.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/Glacier.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/HelicoCentrica.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/HelicoCentrica.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/Piazzolla.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/Piazzolla.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/Synco.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/Synco.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/Tektur.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/Tektur.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/YatraOne.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/faces/YatraOne.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/index.d.ts +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/dist/index.js +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/licenses/CC-BY-ND-4.0.txt +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/licenses/FONTS.md +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/licenses/OFL-1.1.txt +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/package.json +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/woff2/Bore.woff2 +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/woff2/CourierPrime.woff2 +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/woff2/DMSans.woff2 +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/woff2/Glacier.woff2 +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/woff2/HelicoCentrica.woff2 +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/woff2/Piazzolla.woff2 +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/woff2/SOURCE.txt +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/woff2/Synco.woff2 +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/woff2/Tektur.woff2 +0 -0
- /package/kits/{blank → base}/node_modules/castle-web-fonts/woff2/YatraOne.woff2 +0 -0
- /package/kits/physics-3d/drawings/{crate.pxart → crate.sprite} +0 -0
- /package/kits/physics-3d/drawings/{door-edge.pxart → door-edge.sprite} +0 -0
- /package/kits/physics-3d/drawings/{door.pxart → door.sprite} +0 -0
- /package/kits/physics-3d/drawings/{face.pxart → face.sprite} +0 -0
- /package/kits/physics-3d/drawings/{floor.pxart → floor.sprite} +0 -0
- /package/kits/physics-3d/drawings/{platform.pxart → platform.sprite} +0 -0
- /package/kits/physics-3d/drawings/{statue.pxart → statue.sprite} +0 -0
- /package/kits/physics-3d/drawings/{wall.pxart → wall.sprite} +0 -0
- /package/kits/{tabletop → turn-based}/.prettierrc +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { readCastleJson } from './castleJson.js';
|
|
4
|
+
import { IMPORTS_DIR } from './imports.js';
|
|
5
|
+
// Where `castle-web-sdk` comes from now: an imported deck that says it provides
|
|
6
|
+
// it (`castle.json` `provides`), which in practice is the `base` kit every deck
|
|
7
|
+
// imports. The specifier deck code writes does NOT change -- a published deck,
|
|
8
|
+
// a doc, and every line already written keep saying `castle-web-sdk` -- so the
|
|
9
|
+
// move is a resolution detail rather than a rewrite of everything in the wild.
|
|
10
|
+
//
|
|
11
|
+
// A deck with no such import falls through to ordinary node resolution, which
|
|
12
|
+
// is what keeps decks predating the move (and the kits' own workspace checkouts)
|
|
13
|
+
// building against the npm package.
|
|
14
|
+
export const SDK_PACKAGE = 'castle-web-sdk';
|
|
15
|
+
// Subpath -> the file inside a provider's `sdk/` that answers it. Mirrors
|
|
16
|
+
// sdk/package.json `exports`; the kit copy is that package's dist, flattened one
|
|
17
|
+
// level (see scripts/copy-sdk-to-kit.mjs).
|
|
18
|
+
const SUBPATH_ENTRIES = {
|
|
19
|
+
'': 'castle.js',
|
|
20
|
+
'/server': 'server/wrapper.js',
|
|
21
|
+
};
|
|
22
|
+
function providersIn(deckDir) {
|
|
23
|
+
let aliases;
|
|
24
|
+
try {
|
|
25
|
+
aliases = fs.readdirSync(path.join(deckDir, IMPORTS_DIR)).sort();
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
return aliases.filter((alias) => {
|
|
31
|
+
const provides = readCastleJson(path.join(deckDir, IMPORTS_DIR, alias))?.provides;
|
|
32
|
+
return Array.isArray(provides) && provides.includes(SDK_PACKAGE);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
// The file a `castle-web-sdk[/subpath]` specifier means in this deck, or null
|
|
36
|
+
// when no import provides it. Deck-root-absolute, so callers can hand it
|
|
37
|
+
// straight to vite or to node.
|
|
38
|
+
export function resolveSdkSpecifier(deckDir, specifier) {
|
|
39
|
+
if (specifier !== SDK_PACKAGE && !specifier.startsWith(`${SDK_PACKAGE}/`))
|
|
40
|
+
return null;
|
|
41
|
+
const entry = SUBPATH_ENTRIES[specifier.slice(SDK_PACKAGE.length)];
|
|
42
|
+
if (!entry)
|
|
43
|
+
return null;
|
|
44
|
+
for (const alias of providersIn(deckDir)) {
|
|
45
|
+
const file = path.join(deckDir, IMPORTS_DIR, alias, 'sdk', entry);
|
|
46
|
+
if (fs.existsSync(file))
|
|
47
|
+
return file;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
// Whether this deck gets the SDK from an import rather than node_modules. What
|
|
52
|
+
// `init` asks before writing a dependency the deck does not need.
|
|
53
|
+
export function hasSdkProvider(deckDir) {
|
|
54
|
+
return resolveSdkSpecifier(deckDir, SDK_PACKAGE) !== null;
|
|
55
|
+
}
|
package/dist/serve.js
CHANGED
|
@@ -8,7 +8,7 @@ import { WebSocketServer, WebSocket } from 'ws';
|
|
|
8
8
|
import { isIP } from 'net';
|
|
9
9
|
import { createIdeServer, FAVICON_FILES, FAVICON_LINK_TAGS } from './ide.js';
|
|
10
10
|
import { createAgentServer } from './agent.js';
|
|
11
|
-
import { sceneFilesPlugin, importsAliasPlugin, forksOverlayPlugin } from './vitePlugins.js';
|
|
11
|
+
import { sceneFilesPlugin, importsAliasPlugin, forksOverlayPlugin, sdkAliasPlugin, } from './vitePlugins.js';
|
|
12
12
|
import { installFilesChangedWatcher } from './filesChanged.js';
|
|
13
13
|
import { autoUpdateImports, IMPORTS_DIR, lockImportTree } from './imports.js';
|
|
14
14
|
import { ensureAgentsSymlink } from './init.js';
|
|
@@ -118,6 +118,15 @@ function listenLocalContentServer(bindHost, upstreamHost, upstreamPort, role, se
|
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
120
|
function proxyViteClientUpgrade(req, socket, head, upstreamHost, upstreamPort, headers) {
|
|
121
|
+
// Both ends live for the whole HMR session, and `pipe` does not forward
|
|
122
|
+
// 'error' -- so a reset on either side (a closed tab, a sleeping laptop)
|
|
123
|
+
// reaches a raw socket with no listener, which takes the serve process down.
|
|
124
|
+
let paired = null;
|
|
125
|
+
const teardown = () => {
|
|
126
|
+
socket.destroy();
|
|
127
|
+
paired?.destroy();
|
|
128
|
+
};
|
|
129
|
+
socket.on('error', teardown);
|
|
121
130
|
const upstream = http.request({
|
|
122
131
|
hostname: upstreamHost,
|
|
123
132
|
port: upstreamPort,
|
|
@@ -126,6 +135,8 @@ function proxyViteClientUpgrade(req, socket, head, upstreamHost, upstreamPort, h
|
|
|
126
135
|
headers,
|
|
127
136
|
});
|
|
128
137
|
upstream.on('upgrade', (response, upstreamSocket, upstreamHead) => {
|
|
138
|
+
paired = upstreamSocket;
|
|
139
|
+
upstreamSocket.on('error', teardown);
|
|
129
140
|
const responseHeaders = [];
|
|
130
141
|
for (let i = 0; i < response.rawHeaders.length; i += 2) {
|
|
131
142
|
responseHeaders.push(`${response.rawHeaders[i]}: ${response.rawHeaders[i + 1]}`);
|
|
@@ -150,7 +161,7 @@ function proxyViteClientUpgrade(req, socket, head, upstreamHost, upstreamPort, h
|
|
|
150
161
|
socket.write(`HTTP/1.1 ${response.statusCode || 502} ${response.statusMessage || ''}\r\n\r\n`);
|
|
151
162
|
response.pipe(socket);
|
|
152
163
|
});
|
|
153
|
-
upstream.on('error',
|
|
164
|
+
upstream.on('error', teardown);
|
|
154
165
|
upstream.end();
|
|
155
166
|
}
|
|
156
167
|
export function isViteClientUpgrade(req) {
|
|
@@ -708,7 +719,11 @@ export async function serve(dir, options = {}) {
|
|
|
708
719
|
// The WS server forwards `restart` to the browser, but it also needs the
|
|
709
720
|
// Vite instance so it can drop transform caches first (see invalidateModuleCaches).
|
|
710
721
|
const viteHolder = { vite: null };
|
|
711
|
-
|
|
722
|
+
// Same late-binding trick as viteHolder: the control WS is up before
|
|
723
|
+
// createAgentServer exists, and `playtest_request` needs the agent server's
|
|
724
|
+
// warm Chromium and task store.
|
|
725
|
+
const playtestHolder = { run: null };
|
|
726
|
+
const { broadcast, handleUpgrade: handleCastleUpgrade } = startWSServer(projectDir, logFile, screenshotsDir, viteHolder, security, devSession, playtestHolder);
|
|
712
727
|
broadcastDevLog = broadcast;
|
|
713
728
|
// The deck root `/` serves a split-view shell: the deck in an iframe plus a
|
|
714
729
|
// toggle button for an xterm.js terminal. The terminal's PTY is lazy -- it
|
|
@@ -776,12 +791,14 @@ export async function serve(dir, options = {}) {
|
|
|
776
791
|
authorizeUpgrade: (req) => security.consumeTicket(req, 'agent'),
|
|
777
792
|
});
|
|
778
793
|
process.on('exit', () => agentServer.shutdown());
|
|
794
|
+
playtestHolder.run = (req) => agentServer.runPlaytestFor(req);
|
|
779
795
|
const vite = await createViteServer({
|
|
780
796
|
root: projectDir,
|
|
781
797
|
plugins: [
|
|
782
798
|
castlePlugin(security, ideServer, agentServer, options.host),
|
|
783
799
|
forksOverlayPlugin(),
|
|
784
800
|
importsAliasPlugin(),
|
|
801
|
+
sdkAliasPlugin(),
|
|
785
802
|
sceneFilesPlugin(),
|
|
786
803
|
],
|
|
787
804
|
server: {
|
|
@@ -986,7 +1003,32 @@ async function serveDetached(projectDir, options) {
|
|
|
986
1003
|
}
|
|
987
1004
|
throw new Error(`Detached serve did not write ${serveJsonPath} within 15s; check ${logPath} for startup errors.`);
|
|
988
1005
|
}
|
|
989
|
-
|
|
1006
|
+
// Answered by the SERVE itself (the agent server owns the warm Chromium),
|
|
1007
|
+
// unlike screenshot_request which a browser tab answers -- so no
|
|
1008
|
+
// requestOrigins bookkeeping and no forwarding to other clients.
|
|
1009
|
+
function handlePlaytestRequest(ws, msg, playtestHolder) {
|
|
1010
|
+
const { requestId } = msg;
|
|
1011
|
+
const reply = (body) => {
|
|
1012
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
1013
|
+
ws.send(JSON.stringify({ type: 'playtest_response', requestId, ...body }));
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
const run = playtestHolder.run;
|
|
1017
|
+
if (!run) {
|
|
1018
|
+
reply({ ok: false, output: 'Error: this serve has no agent server to playtest with.' });
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
void run({
|
|
1022
|
+
taskId: typeof msg.taskId === 'string' ? msg.taskId : undefined,
|
|
1023
|
+
args: (msg.args ?? {}),
|
|
1024
|
+
onProgress: (label) => {
|
|
1025
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
1026
|
+
ws.send(JSON.stringify({ type: 'playtest_progress', requestId, label }));
|
|
1027
|
+
}
|
|
1028
|
+
},
|
|
1029
|
+
}).then((result) => reply(result), (err) => reply({ ok: false, output: `Error: ${err instanceof Error ? err.message : String(err)}` }));
|
|
1030
|
+
}
|
|
1031
|
+
function startWSServer(projectDir, logFile, screenshotsDir, viteHolder, security, multiplayer, playtestHolder) {
|
|
990
1032
|
// The control socket is upgraded directly on Vite's HTTP server. Browser
|
|
991
1033
|
// shell clients use the named path and a one-use ticket; pre-bridge SDKs use
|
|
992
1034
|
// a separate ticket carrying their content role. The root path is accepted
|
|
@@ -1099,6 +1141,10 @@ function startWSServer(projectDir, logFile, screenshotsDir, viteHolder, security
|
|
|
1099
1141
|
c.send(fwd);
|
|
1100
1142
|
}
|
|
1101
1143
|
}
|
|
1144
|
+
if (msg.type === 'playtest_request' && typeof msg.requestId === 'string') {
|
|
1145
|
+
handlePlaytestRequest(ws, msg, playtestHolder);
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1102
1148
|
// Things one client asks the OTHERS to answer: a tab's canvas for
|
|
1103
1149
|
// `screenshot`, and the browser's signed-in deck listing for
|
|
1104
1150
|
// `list-decks` (a cloud sandbox holds no Castle token; the browser
|
package/dist/serverBundle.js
CHANGED
|
@@ -3,7 +3,8 @@ import { createRequire } from 'module';
|
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import { build } from 'vite';
|
|
5
5
|
import { resolveServerConfig, } from './castleJson.js';
|
|
6
|
-
import { forksOverlayPlugin, importsAliasPlugin } from './vitePlugins.js';
|
|
6
|
+
import { forksOverlayPlugin, importsAliasPlugin, sdkAliasPlugin } from './vitePlugins.js';
|
|
7
|
+
import { resolveSdkSpecifier, SDK_PACKAGE } from './sdkResolve.js';
|
|
7
8
|
const WARN_BYTES = 1024 * 1024;
|
|
8
9
|
const MAX_BYTES = 5 * 1024 * 1024;
|
|
9
10
|
const VIRTUAL_ENTRY = '\0castle-server-entry';
|
|
@@ -33,7 +34,11 @@ export async function buildServerBundle(projectDir) {
|
|
|
33
34
|
// Dev keeps readable code; the published artifact is minified and checked below
|
|
34
35
|
// for the single-output-file contract.
|
|
35
36
|
export async function bundleServerModule(projectDir, config, minify) {
|
|
36
|
-
|
|
37
|
+
// The synthesized entry names the file directly, so it has to resolve here
|
|
38
|
+
// rather than through the plugin: the deck's `base` import when it has one,
|
|
39
|
+
// node_modules for a deck predating the move.
|
|
40
|
+
const sdkEntry = resolveSdkSpecifier(projectDir, `${SDK_PACKAGE}/server`) ??
|
|
41
|
+
createRequire(path.join(projectDir, 'package.json')).resolve(`${SDK_PACKAGE}/server`);
|
|
37
42
|
const authorEntry = path.resolve(projectDir, config.entry);
|
|
38
43
|
const entryPlugin = {
|
|
39
44
|
name: 'castle-server-entry',
|
|
@@ -52,7 +57,7 @@ export async function bundleServerModule(projectDir, config, minify) {
|
|
|
52
57
|
root: projectDir,
|
|
53
58
|
configFile: false,
|
|
54
59
|
logLevel: 'silent',
|
|
55
|
-
plugins: [forksOverlayPlugin(), importsAliasPlugin(), entryPlugin],
|
|
60
|
+
plugins: [forksOverlayPlugin(), importsAliasPlugin(), sdkAliasPlugin(), entryPlugin],
|
|
56
61
|
ssr: { noExternal: true },
|
|
57
62
|
build: {
|
|
58
63
|
write: false,
|