castle-web-cli 0.4.229 → 0.4.231
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 +860 -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/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +25 -13
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +237 -46
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- 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 +126 -9
- 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 +99 -14
- 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 +406 -53
- 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 +9 -0
- package/kits/base/sdk/castle.js +5 -0
- package/kits/base/sdk/commands.d.ts +223 -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 +158 -8
- package/kits/base/sdk/save.d.ts +197 -0
- package/kits/base/sdk/save.js +525 -0
- package/kits/base/sdk/saveCoordinator.d.ts +39 -0
- package/kits/base/sdk/saveCoordinator.js +252 -0
- 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 +58 -4
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +36 -2
- package/kits/base/sdk/server/wrapper.js +92 -11
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- 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 +149 -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 +1035 -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 +376 -0
- package/kits/hub-game/code/client/hookLayer.js +236 -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 +143 -0
- package/kits/hub-game/code/client/talk.js +233 -0
- package/kits/hub-game/code/client/tiers.js +480 -0
- package/kits/hub-game/code/client/together.js +440 -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 +248 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1998 -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 +554 -0
- package/kits/hub-game/code/server/npcs.js +733 -0
- package/kits/hub-game/code/server/party.js +439 -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 +2347 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1209 -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-client.mjs +328 -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 +1518 -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 +270 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +724 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +369 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-tiers.mjs +666 -0
- package/kits/hub-game/scripts/test-together.mjs +215 -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/CLAUDE.md +2 -0
- 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 +117 -5
- package/kits/physics-2d/package.json +1 -1
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +254 -0
- package/kits/physics-3d/CLAUDE.md +285 -1
- package/kits/physics-3d/behaviors/Player.jsx +74 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -5
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- package/kits/physics-3d/engine3d/nearshadows.js +600 -0
- package/kits/physics-3d/engine3d/unchanged.js +153 -0
- package/kits/physics-3d/engine3d/world3d.js +527 -5
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/test-camera-follow.mjs +533 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +662 -0
- package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
- package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
- package/kits/physics-3d/systems/physics3d.js +187 -5
- 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/imports.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
1
2
|
import * as fs from 'fs';
|
|
2
3
|
import * as path from 'path';
|
|
3
4
|
import { nanoid } from 'nanoid';
|
|
@@ -7,6 +8,7 @@ import { normalizeDeckPackageJson } from './normalize.js';
|
|
|
7
8
|
import { getKitsDir } from './localPaths.js';
|
|
8
9
|
import { shippedFrameworkKit, shippedKitAlias } from './kitCatalog.js';
|
|
9
10
|
import { SDK_PACKAGE } from './sdkResolve.js';
|
|
11
|
+
import { importIsOnTrustedAccount, TRUSTED_IMPORT_ACCOUNT } from './importTrust.js';
|
|
10
12
|
import { writePlatformDocs } from './platformDoc.js';
|
|
11
13
|
import { findImportUpdateHook, runImportUpdateHook, } from './importUpdateHook.js';
|
|
12
14
|
import { IMPORTS_DIR, IMPORT_VERSION_FILE, STARTER_THEME_FILES, readCastleJson as tryReadCastleJson, readCastleJsonOrThrow as readCastleJson, } from './castleJson.js';
|
|
@@ -46,6 +48,129 @@ export function readImportVersion(deckDir, alias) {
|
|
|
46
48
|
return null;
|
|
47
49
|
}
|
|
48
50
|
}
|
|
51
|
+
// --- builtin kits -----------------------------------------------------------
|
|
52
|
+
//
|
|
53
|
+
// A builtin pin (`source: 'builtin'`) is a copy of a kit this CLI ships, and its
|
|
54
|
+
// version is the CLI's version. A kit changes on main far more often than that
|
|
55
|
+
// version string does, so a deck's copy is stamped with a digest of the kit's
|
|
56
|
+
// files, and a CLI of the same version whose own copy differs replaces it
|
|
57
|
+
// (`refreshStaleBuiltinImports`) before the deck is installed, served or saved
|
|
58
|
+
// -- otherwise a save ships whatever kit the deck happened to copy first. A copy
|
|
59
|
+
// from another CLI version is left alone: that is never a move to make silently.
|
|
60
|
+
const BUILTIN_COPY_EXCLUDE = new Set(['node_modules', '.castle', 'dist', '.git']);
|
|
61
|
+
function builtinCopyFilter(kitDir) {
|
|
62
|
+
// The kit's own `imports/` is derived state, re-placed at the deck root.
|
|
63
|
+
const nested = path.join(kitDir, IMPORTS_DIR);
|
|
64
|
+
return (src) => src === kitDir || (src !== nested && !BUILTIN_COPY_EXCLUDE.has(path.basename(src)));
|
|
65
|
+
}
|
|
66
|
+
/** A kit tree's files, as a builtin copy takes them: relative path and bytes, hashed. */
|
|
67
|
+
export function builtinKitDigest(kitDir) {
|
|
68
|
+
const hash = crypto.createHash('sha256');
|
|
69
|
+
const keep = builtinCopyFilter(kitDir);
|
|
70
|
+
const walk = (dir) => {
|
|
71
|
+
for (const name of fs.readdirSync(dir).sort()) {
|
|
72
|
+
const abs = path.join(dir, name);
|
|
73
|
+
if (!keep(abs) || name === IMPORT_VERSION_FILE)
|
|
74
|
+
continue;
|
|
75
|
+
const stat = fs.lstatSync(abs);
|
|
76
|
+
const rel = path.relative(kitDir, abs).split(path.sep).join('/');
|
|
77
|
+
if (stat.isDirectory())
|
|
78
|
+
walk(abs);
|
|
79
|
+
else if (stat.isSymbolicLink())
|
|
80
|
+
hash.update(`L ${rel}\0${fs.readlinkSync(abs)}\0`);
|
|
81
|
+
else if (stat.isFile()) {
|
|
82
|
+
hash.update(`F ${rel}\0`);
|
|
83
|
+
hash.update(fs.readFileSync(abs));
|
|
84
|
+
hash.update('\0');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
walk(kitDir);
|
|
89
|
+
return hash.digest('hex');
|
|
90
|
+
}
|
|
91
|
+
export function writeBuiltinStamp(importDir, stamp) {
|
|
92
|
+
fs.writeFileSync(path.join(importDir, IMPORT_VERSION_FILE), JSON.stringify(stamp, null, 2) + '\n', 'utf-8');
|
|
93
|
+
}
|
|
94
|
+
function readBuiltinStamp(importDir) {
|
|
95
|
+
try {
|
|
96
|
+
const value = JSON.parse(fs.readFileSync(path.join(importDir, IMPORT_VERSION_FILE), 'utf-8'));
|
|
97
|
+
return value?.source === 'builtin' && typeof value.digest === 'string' ? value : null;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** A builtin kit copied into a deck, stamped. `destDir` must not exist. */
|
|
104
|
+
export function copyBuiltinKit(kitDir, destDir, kit, version) {
|
|
105
|
+
fs.mkdirSync(path.dirname(destDir), { recursive: true });
|
|
106
|
+
fs.cpSync(kitDir, destDir, { recursive: true, verbatimSymlinks: true, filter: builtinCopyFilter(kitDir) });
|
|
107
|
+
writeBuiltinStamp(destDir, { source: 'builtin', kit, version, digest: builtinKitDigest(kitDir) });
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Builtin imports whose copy differs from this CLI's kit of the same version,
|
|
111
|
+
* replaced with this CLI's. Returns the aliases replaced.
|
|
112
|
+
*/
|
|
113
|
+
export async function refreshStaleBuiltinImports(deckDir, log = (message) => console.log(message)) {
|
|
114
|
+
const pins = tryReadCastleJson(deckDir)?.imports ?? {};
|
|
115
|
+
const { getCliVersion } = await import('./init.js');
|
|
116
|
+
const cliVersion = getCliVersion();
|
|
117
|
+
const refreshed = [];
|
|
118
|
+
// Never throws: a kit that cannot be refreshed is left as it is and named,
|
|
119
|
+
// and the ones that were are still returned (serve invalidates on them).
|
|
120
|
+
for (const [alias, pin] of Object.entries(pins)) {
|
|
121
|
+
if (pin?.source !== 'builtin' || pin.version !== cliVersion)
|
|
122
|
+
continue;
|
|
123
|
+
const destDir = path.join(deckDir, IMPORTS_DIR, alias);
|
|
124
|
+
const kitDir = path.join(getKitsDir(), pin.kit ?? alias);
|
|
125
|
+
try {
|
|
126
|
+
if (!fs.existsSync(destDir) || !fs.existsSync(kitDir))
|
|
127
|
+
continue;
|
|
128
|
+
const digest = builtinKitDigest(kitDir);
|
|
129
|
+
const stamp = readBuiltinStamp(destDir);
|
|
130
|
+
if (stamp?.digest === digest)
|
|
131
|
+
continue;
|
|
132
|
+
if (!stamp && builtinKitDigest(destDir) === digest) {
|
|
133
|
+
// A copy from before stamps, already this kit: stamp it and move on.
|
|
134
|
+
unlockImportTree(destDir);
|
|
135
|
+
writeBuiltinStamp(destDir, { source: 'builtin', kit: pin.kit ?? alias, version: cliVersion, digest });
|
|
136
|
+
lockImportTree(destDir);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
// Staged beside the old copy and swapped in whole, so a failed copy
|
|
140
|
+
// leaves the deck's import as it was.
|
|
141
|
+
const staged = `${destDir}.refresh-${process.pid}`;
|
|
142
|
+
fs.rmSync(staged, { recursive: true, force: true });
|
|
143
|
+
copyBuiltinKit(kitDir, staged, pin.kit ?? alias, cliVersion);
|
|
144
|
+
unlockImportTree(destDir);
|
|
145
|
+
fs.rmSync(destDir, { recursive: true, force: true });
|
|
146
|
+
fs.renameSync(staged, destDir);
|
|
147
|
+
lockImportTree(destDir);
|
|
148
|
+
refreshed.push(alias);
|
|
149
|
+
log(`Refreshed ${alias}: this deck's copy differed from the ${pin.kit ?? alias} kit this CLI (${cliVersion}) ships.`);
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
log(`Left ${alias} as it is: ${e instanceof Error ? e.message : String(e)}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (refreshed.length) {
|
|
156
|
+
// A newer copy can name imports and packages the old one did not.
|
|
157
|
+
try {
|
|
158
|
+
const { addKitDependencies } = await import('./init.js');
|
|
159
|
+
for (const alias of refreshed) {
|
|
160
|
+
const pin = pins[alias];
|
|
161
|
+
for (const added of addKitDependencies(deckDir, path.join(getKitsDir(), pin?.kit ?? alias))) {
|
|
162
|
+
log(`Added import ${added}, which the refreshed ${alias} needs.`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
await restoreMissingImports(deckDir);
|
|
166
|
+
await installAddedDependencies(deckDir, syncImportDependencies(deckDir));
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
log(`Refreshed kits' dependencies were not all added -- run \`castle-web install\`. ${e instanceof Error ? e.message : String(e)}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return refreshed;
|
|
173
|
+
}
|
|
49
174
|
// A match proves the files on disk are the ones the pin names -- same deck, same
|
|
50
175
|
// version. No marker, or one that disagrees, proves nothing about them, so the
|
|
51
176
|
// only way to be sure of what is there is to fetch it again.
|
|
@@ -361,13 +486,7 @@ export async function restoreMissingImports(deckDir) {
|
|
|
361
486
|
console.warn(`Could not restore import "${alias}": this CLI ships no kit by that name.`);
|
|
362
487
|
continue;
|
|
363
488
|
}
|
|
364
|
-
|
|
365
|
-
fs.cpSync(kitDir, destDir, {
|
|
366
|
-
recursive: true,
|
|
367
|
-
verbatimSymlinks: true,
|
|
368
|
-
filter: (src) => src === kitDir ||
|
|
369
|
-
!['node_modules', '.castle', 'dist', '.git'].includes(path.basename(src)),
|
|
370
|
-
});
|
|
489
|
+
copyBuiltinKit(kitDir, destDir, pin.kit ?? alias, pin.version);
|
|
371
490
|
}
|
|
372
491
|
else {
|
|
373
492
|
console.warn(`Import "${alias}" has no deckId to fetch from; skipping.`);
|
|
@@ -654,10 +773,11 @@ export async function addImportTo(dir, options = {}) {
|
|
|
654
773
|
const declaredMain = tryReadCastleJson(importDir)?.main;
|
|
655
774
|
let adoptedMain = null;
|
|
656
775
|
if (typeof declaredMain === 'string' && declaredMain.trim()) {
|
|
657
|
-
const { isPristineBareDeck, adoptImportEntry, writeStarterScene, writeStarterTheme, retargetBareClaudeMd, adoptKitConfig, } = await import('./init.js');
|
|
776
|
+
const { isPristineBareDeck, adoptImportEntry, writeStarterScene, writeStarterTheme, retargetBareClaudeMd, adoptKitConfig, adoptStarterConfig, writeStarterFiles, } = await import('./init.js');
|
|
658
777
|
if (isPristineBareDeck(targetDir)) {
|
|
659
778
|
adoptImportEntry(targetDir, alias, declaredMain.trim());
|
|
660
779
|
adoptKitConfig(targetDir, importDir, alias);
|
|
780
|
+
adoptStarterConfig(targetDir, importDir);
|
|
661
781
|
adoptedMain = declaredMain.trim();
|
|
662
782
|
retargetBareClaudeMd(targetDir, alias);
|
|
663
783
|
// A kit's runtime with no scene to run is a blank screen, and the agent
|
|
@@ -679,6 +799,14 @@ export async function addImportTo(dir, options = {}) {
|
|
|
679
799
|
catch (e) {
|
|
680
800
|
console.warn(`Adopted ${alias} but could not write its starter theme.style: ${e instanceof Error ? e.message : String(e)}`);
|
|
681
801
|
}
|
|
802
|
+
// And the rest of what the kit hands a deck starting from it, same as
|
|
803
|
+
// `init --kit`; each file skips on its own if the deck already has it.
|
|
804
|
+
try {
|
|
805
|
+
writeStarterFiles(targetDir, importDir);
|
|
806
|
+
}
|
|
807
|
+
catch (e) {
|
|
808
|
+
console.warn(`Adopted ${alias} but could not write its starter files: ${e instanceof Error ? e.message : String(e)}`);
|
|
809
|
+
}
|
|
682
810
|
}
|
|
683
811
|
}
|
|
684
812
|
// An import's packages have to be ON DISK, not just named in package.json:
|
|
@@ -798,7 +926,7 @@ async function resolveUpdateHook(deckDir, alias, update, to, log) {
|
|
|
798
926
|
return null;
|
|
799
927
|
const trusted = update.trusted ?? (await importIsOnTrustedAccount(update.deckId));
|
|
800
928
|
if (!trusted) {
|
|
801
|
-
log(`${alias} ships an update hook, which only runs for imports on the ${
|
|
929
|
+
log(`${alias} ships an update hook, which only runs for imports on the ${TRUSTED_IMPORT_ACCOUNT} ` +
|
|
802
930
|
`account -- skipped. Its new files are in place; this deck's own files were not migrated.`);
|
|
803
931
|
return null;
|
|
804
932
|
}
|
|
@@ -850,37 +978,19 @@ function importOptsIntoAutoUpdate(deckDir, alias) {
|
|
|
850
978
|
const config = tryReadCastleJson(path.join(deckDir, IMPORTS_DIR, alias));
|
|
851
979
|
return config?.autoUpdateWhenImported === true;
|
|
852
980
|
}
|
|
853
|
-
// Auto-update is honored only for imports
|
|
854
|
-
//
|
|
855
|
-
//
|
|
856
|
-
// carry some other signal of it, the only ones that get it are the ones we
|
|
857
|
-
// publish (the framework kits -- the same account `init` qualifies their aliases
|
|
858
|
-
// with).
|
|
859
|
-
//
|
|
860
|
-
// Deliberately not a deck setting: nothing in castle.json a person can flip,
|
|
861
|
-
// since that would be the leash undoing itself. Process env is the escape
|
|
862
|
-
// hatch for local kit work and tests:
|
|
981
|
+
// Auto-update is honored only for imports the account gate trusts (importTrust.ts
|
|
982
|
+
// says who, and why it is not a deck setting). Process env is the escape hatch
|
|
983
|
+
// for local kit work and tests:
|
|
863
984
|
// - CASTLE_NO_AUTO_UPDATE=1 -- skip serve-start auto-update entirely (keep
|
|
864
985
|
// whatever is already under imports/, including hand-synced kits from this
|
|
865
986
|
// checkout).
|
|
866
|
-
// - CASTLE_AUTO_UPDATE_TRUSTED_ACCOUNT -- which username counts as trusted
|
|
867
|
-
// (default `castle`). Tests set it to exercise both branches; setting it to
|
|
868
|
-
// a non-matching name also disables updates as a side effect.
|
|
869
|
-
const AUTO_UPDATE_ACCOUNT = process.env.CASTLE_AUTO_UPDATE_TRUSTED_ACCOUNT ?? 'castle';
|
|
987
|
+
// - CASTLE_AUTO_UPDATE_TRUSTED_ACCOUNT -- which username counts as trusted.
|
|
870
988
|
function autoUpdateDisabled() {
|
|
871
989
|
const raw = process.env.CASTLE_NO_AUTO_UPDATE;
|
|
872
990
|
if (raw == null || raw === '')
|
|
873
991
|
return false;
|
|
874
992
|
return raw !== '0' && raw.toLowerCase() !== 'false' && raw.toLowerCase() !== 'no';
|
|
875
993
|
}
|
|
876
|
-
// Who published a deck. Readable without auth for the same decks webDeckSource
|
|
877
|
-
// is, so this answers in a sandbox with no login. A lookup that fails answers
|
|
878
|
-
// "not trusted": the failure direction has to be the one that leaves an import
|
|
879
|
-
// where its deck's author pinned it.
|
|
880
|
-
async function importIsOnTrustedAccount(deckId) {
|
|
881
|
-
const meta = await api.deckMeta(deckId).catch(() => null);
|
|
882
|
-
return meta?.creator?.username === AUTO_UPDATE_ACCOUNT;
|
|
883
|
-
}
|
|
884
994
|
// Move every opted-in import that the account gate allows to the version the
|
|
885
995
|
// server has now.
|
|
886
996
|
//
|
package/dist/index.js
CHANGED
|
@@ -138,6 +138,7 @@ function getServeSocketPort(dir) {
|
|
|
138
138
|
}
|
|
139
139
|
const FALLBACK_KITS = [
|
|
140
140
|
'base',
|
|
141
|
+
'hub-game',
|
|
141
142
|
'multiplayer-2d',
|
|
142
143
|
'multiplayer-3d',
|
|
143
144
|
'physics-2d',
|
|
@@ -147,6 +148,7 @@ const FALLBACK_KITS = [
|
|
|
147
148
|
];
|
|
148
149
|
const KIT_DESCRIPTIONS = {
|
|
149
150
|
base: 'Library kit: shared SDK, editor host, and authoring guide imported by every deck.',
|
|
151
|
+
'hub-game': 'A game behind a door in the Cauldron hub (experimental, not offered to the create assistant): multiplayer-3d with the hub contract, no client code.',
|
|
150
152
|
'multiplayer-2d': 'Real-time multiplayer over physics-2d: a shared matter world with an authoritative server already written.',
|
|
151
153
|
'multiplayer-3d': 'Real-time multiplayer over physics-3d: a shared rapier world with an authoritative server already written.',
|
|
152
154
|
'physics-2d': 'Actor / behavior / scene framework for 2D games with matter-js physics. Default if --kit is omitted.',
|
|
@@ -193,7 +195,7 @@ function usage() {
|
|
|
193
195
|
castle-web revert-import-file <imports/...> [dir]
|
|
194
196
|
castle-web update-import [alias] [dir] [--check] [--revert] (re-fetches imports; no alias means all)
|
|
195
197
|
castle-web install [dir]
|
|
196
|
-
castle-web check [dir] (bundles the deck and its server, the same
|
|
198
|
+
castle-web check [dir] (bundles the deck and its server, then runs each import's onCheck -- the same gates save-deck runs)
|
|
197
199
|
castle-web save-version [-m MESSAGE] [paths...] [--dir DIR] (no paths saves the whole deck)
|
|
198
200
|
castle-web list-versions [version] [--dir DIR] (defaults to the latest version)
|
|
199
201
|
castle-web show-version <version> [--dir DIR] (diffs of the files that version changed)
|
package/dist/init.d.ts
CHANGED
|
@@ -13,7 +13,10 @@ export declare function adoptImportEntry(deckDir: string, alias: string, mainFil
|
|
|
13
13
|
export declare function getCliVersion(): string;
|
|
14
14
|
export declare function writeStarterScene(projectDir: string, kitDir: string, alias: string): void;
|
|
15
15
|
export declare function writeStarterTheme(projectDir: string, kitDir: string): void;
|
|
16
|
+
export declare function writeStarterFiles(projectDir: string, kitDir: string): string[];
|
|
17
|
+
export declare function adoptStarterConfig(deckDir: string, kitDir: string): string[];
|
|
16
18
|
export declare function retargetBareClaudeMd(deckDir: string, alias: string): void;
|
|
19
|
+
export declare function addKitDependencies(deckDir: string, kitDir: string): string[];
|
|
17
20
|
export interface ShippedKitImport {
|
|
18
21
|
alias: string;
|
|
19
22
|
deckId: string;
|
package/dist/init.js
CHANGED
|
@@ -3,13 +3,14 @@ import * as path from 'path';
|
|
|
3
3
|
import { CLAUDE_MD_PLATFORM_SECTION } from './platformDoc.js';
|
|
4
4
|
import { installDeps } from './install.js';
|
|
5
5
|
import { deckMainFile, deckStarterScene, STARTER_THEME_FILES } from './castleJson.js';
|
|
6
|
-
import { addImportTo, IMPORTS_DIR, lockImportTree, restoreMissingImports, syncImportDependencies, writeImportVersion, } from './imports.js';
|
|
6
|
+
import { addImportTo, builtinKitDigest, IMPORTS_DIR, lockImportTree, restoreMissingImports, syncImportDependencies, writeBuiltinStamp, writeImportVersion, } from './imports.js';
|
|
7
7
|
import { discardParentSource, fetchParentSource, unpackParentSource, writeRemixIdentity, } from './remix.js';
|
|
8
8
|
import { kitFromAlias, shippedKitAlias } from './kitCatalog.js';
|
|
9
9
|
import { getCliEntryPath, getKitsDir, getSdkPackagePath, toPosixPath } from './localPaths.js';
|
|
10
10
|
import { SDK_PACKAGE } from './sdkResolve.js';
|
|
11
11
|
import { serve } from './serve.js';
|
|
12
12
|
import { createVersion } from './versions.js';
|
|
13
|
+
import { resolveFileInside } from './importUpdateHook.js';
|
|
13
14
|
// Default kit imported by `init` when no --kit is given. `none`/`bare` skips the
|
|
14
15
|
// framework and produces the minimal index.html + game.js stub below.
|
|
15
16
|
const DEFAULT_KIT = 'physics-2d';
|
|
@@ -19,13 +20,10 @@ const DEFAULT_KIT = 'physics-2d';
|
|
|
19
20
|
// A framework kit imports it too, so a kit deck has it as well.
|
|
20
21
|
export const BASE_KIT = 'base';
|
|
21
22
|
export const BASE_ALIAS = shippedKitAlias(BASE_KIT);
|
|
22
|
-
// A bare deck lays itself out, so it starts as a fill deck (platformDoc.ts,
|
|
23
|
-
// "Fit the stage"); a kit deck's entry is the kit's, and follows its guide.
|
|
24
23
|
const INDEX_HTML = `<!DOCTYPE html>
|
|
25
24
|
<html>
|
|
26
25
|
<head>
|
|
27
26
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
|
28
|
-
<meta name="castle-display" content="layout=fill">
|
|
29
27
|
<title>My Castle Game</title>
|
|
30
28
|
</head>
|
|
31
29
|
<body>
|
|
@@ -43,7 +41,7 @@ function startGame(card) {
|
|
|
43
41
|
el.style.cssText = \`
|
|
44
42
|
width: 100%; height: 100%;
|
|
45
43
|
display: flex; align-items: center; justify-content: center;
|
|
46
|
-
font-family: system-ui; color: #fff; font-size:
|
|
44
|
+
font-family: system-ui; color: #fff; font-size: 24px;
|
|
47
45
|
\`;
|
|
48
46
|
el.textContent = 'Hello Castle!';
|
|
49
47
|
card.appendChild(el);
|
|
@@ -55,18 +53,18 @@ function startGame(card) {
|
|
|
55
53
|
if (!(await mountEditorRoute())) startGame(initCard());
|
|
56
54
|
`;
|
|
57
55
|
// Every bare scaffold `init` has written, so isPristineBareDeck still knows an
|
|
58
|
-
// untouched deck made
|
|
56
|
+
// untouched deck made while the scaffold was a fill deck (Sept 29-30, 2026).
|
|
59
57
|
const BARE_SCAFFOLDS = [
|
|
60
58
|
{ html: INDEX_HTML, js: GAME_JS },
|
|
61
59
|
{
|
|
62
|
-
html: INDEX_HTML.replace(' <meta name="castle-display" content="layout=fill">\n'
|
|
63
|
-
js: GAME_JS.replace('calc(6 * var(--castle-unit))'
|
|
60
|
+
html: INDEX_HTML.replace(' <title>', ' <meta name="castle-display" content="layout=fill">\n <title>'),
|
|
61
|
+
js: GAME_JS.replace('font-size: 24px;', 'font-size: calc(6 * var(--castle-unit));'),
|
|
64
62
|
},
|
|
65
63
|
];
|
|
66
64
|
// Registry version of castle-web-sdk to inject when scaffolding from a
|
|
67
65
|
// globally-installed castle-web (not from inside the workspace). Bumped
|
|
68
66
|
// alongside cli/sdk version bumps.
|
|
69
|
-
const PUBLISHED_SDK_VERSION = '0.4.
|
|
67
|
+
const PUBLISHED_SDK_VERSION = '0.4.46';
|
|
70
68
|
// Range, not a pin: `castle-web-fonts` is its own package precisely so a tenth
|
|
71
69
|
// face can ship without a cli release, and a caret range means an existing
|
|
72
70
|
// deck's next install picks it up. Nothing here has to move when it does.
|
|
@@ -348,6 +346,87 @@ export function writeStarterTheme(projectDir, kitDir) {
|
|
|
348
346
|
fs.copyFileSync(src, dest);
|
|
349
347
|
}
|
|
350
348
|
}
|
|
349
|
+
// The kit's `starterFiles` (castleJson.ts): files it authors that a deck
|
|
350
|
+
// starting from it owns from then on -- a server module to fill in, a blueprint
|
|
351
|
+
// to edit. Each lands at the same relative path in the deck, verbatim, and
|
|
352
|
+
// never over a file the deck already has. A declared path gets the same guard
|
|
353
|
+
// an update hook's does (`resolveFileInside`), since a kit's castle.json is
|
|
354
|
+
// somebody else's word for which files to copy.
|
|
355
|
+
//
|
|
356
|
+
// Read and written rather than `copyFileSync`, which would carry the mode
|
|
357
|
+
// across: when adopting a kit by add-import the source is a locked import, and
|
|
358
|
+
// the deck's copy has to be writable.
|
|
359
|
+
export function writeStarterFiles(projectDir, kitDir) {
|
|
360
|
+
const declared = readJsonFile(path.join(kitDir, 'castle.json'))?.starterFiles;
|
|
361
|
+
if (declared === undefined)
|
|
362
|
+
return [];
|
|
363
|
+
if (!Array.isArray(declared)) {
|
|
364
|
+
console.warn(`Warning: ${kitDir}'s starterFiles is not a list -- skipping it.`);
|
|
365
|
+
return [];
|
|
366
|
+
}
|
|
367
|
+
const written = [];
|
|
368
|
+
for (const entry of declared) {
|
|
369
|
+
const src = typeof entry === 'string' ? resolveFileInside(kitDir, entry) : null;
|
|
370
|
+
if (!src) {
|
|
371
|
+
console.warn(`Warning: starter file ${JSON.stringify(entry)} is not a file inside the kit -- skipping it.`);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
const rel = toPosixPath(path.relative(kitDir, src));
|
|
375
|
+
const dest = path.join(projectDir, rel);
|
|
376
|
+
if (fs.existsSync(dest))
|
|
377
|
+
continue;
|
|
378
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
379
|
+
fs.writeFileSync(dest, fs.readFileSync(src));
|
|
380
|
+
written.push(rel);
|
|
381
|
+
}
|
|
382
|
+
return written;
|
|
383
|
+
}
|
|
384
|
+
// Never taken from a kit's `starterConfig`. The pins and the deck's identity
|
|
385
|
+
// are the deck's own; `editor` and `server` are `adoptKitConfig`'s, which
|
|
386
|
+
// rewrites them for the deck; and the rest are statements a deck makes about
|
|
387
|
+
// ITSELF to the decks importing it, which a deck starting from a kit has not
|
|
388
|
+
// made just because the kit did.
|
|
389
|
+
const STARTER_CONFIG_RESERVED = new Set([
|
|
390
|
+
'imports',
|
|
391
|
+
'editor',
|
|
392
|
+
'server',
|
|
393
|
+
'deckId',
|
|
394
|
+
'cardId',
|
|
395
|
+
'publishedVersion',
|
|
396
|
+
'title',
|
|
397
|
+
'autoUpdateWhenImported',
|
|
398
|
+
'importWhenRemixed',
|
|
399
|
+
'onUpdate',
|
|
400
|
+
'onCheck',
|
|
401
|
+
'main',
|
|
402
|
+
'starterScene',
|
|
403
|
+
'starterFiles',
|
|
404
|
+
'starterConfig',
|
|
405
|
+
]);
|
|
406
|
+
// The kit's `starterConfig` (castleJson.ts), merged into the deck's castle.json
|
|
407
|
+
// one top-level key at a time, for keys the deck does not have yet. Runs after
|
|
408
|
+
// `adoptKitConfig`, so a block that adopts first is kept.
|
|
409
|
+
export function adoptStarterConfig(deckDir, kitDir) {
|
|
410
|
+
const starter = readJsonFile(path.join(kitDir, 'castle.json'))?.starterConfig;
|
|
411
|
+
if (starter === undefined)
|
|
412
|
+
return [];
|
|
413
|
+
if (!starter || typeof starter !== 'object' || Array.isArray(starter)) {
|
|
414
|
+
console.warn(`Warning: ${kitDir}'s starterConfig is not an object -- skipping it.`);
|
|
415
|
+
return [];
|
|
416
|
+
}
|
|
417
|
+
const configPath = path.join(deckDir, 'castle.json');
|
|
418
|
+
const deckConfig = readJsonFile(configPath) ?? {};
|
|
419
|
+
const added = [];
|
|
420
|
+
for (const [key, value] of Object.entries(starter)) {
|
|
421
|
+
if (STARTER_CONFIG_RESERVED.has(key) || key in deckConfig)
|
|
422
|
+
continue;
|
|
423
|
+
deckConfig[key] = value;
|
|
424
|
+
added.push(key);
|
|
425
|
+
}
|
|
426
|
+
if (added.length > 0)
|
|
427
|
+
writeJsonFile(configPath, deckConfig);
|
|
428
|
+
return added;
|
|
429
|
+
}
|
|
351
430
|
// A bare deck's own guide. Its `## Quick reference` is HERE rather than in the
|
|
352
431
|
// base kit for one reason: this is the only place a claim like "there is no
|
|
353
432
|
// scene format" is true. Every deck imports base now, kit decks included, so
|
|
@@ -508,6 +587,9 @@ function copyKitImport(projectDir, kitDir, kit, alias, pins, copied) {
|
|
|
508
587
|
if (typeof pin.deckId === 'string') {
|
|
509
588
|
writeImportVersion(importDir, { deckId: pin.deckId, version: pin.version });
|
|
510
589
|
}
|
|
590
|
+
else if (pin.source === 'builtin' && typeof pin.version === 'string') {
|
|
591
|
+
writeBuiltinStamp(importDir, { source: 'builtin', kit, version: pin.version, digest: builtinKitDigest(kitDir) });
|
|
592
|
+
}
|
|
511
593
|
const kitPins = (kitConfig.imports ?? {});
|
|
512
594
|
for (const [depAlias, depPin] of Object.entries(kitPins)) {
|
|
513
595
|
if (copied.has(depAlias) || pins[depAlias])
|
|
@@ -522,6 +604,37 @@ function copyKitImport(projectDir, kitDir, kit, alias, pins, copied) {
|
|
|
522
604
|
}
|
|
523
605
|
}
|
|
524
606
|
}
|
|
607
|
+
// The imports a kit names that the deck does not pin yet, pinned and placed as
|
|
608
|
+
// `init` would place them (a shipped kit copied, anything else pinned for
|
|
609
|
+
// `install` to fetch). For a builtin kit refreshed under the deck: a newer
|
|
610
|
+
// copy can name dependencies the old one did not. Returns the aliases added.
|
|
611
|
+
export function addKitDependencies(deckDir, kitDir) {
|
|
612
|
+
const configPath = path.join(deckDir, 'castle.json');
|
|
613
|
+
const config = readJsonFile(configPath) ?? {};
|
|
614
|
+
const pins = { ...(config.imports ?? {}) };
|
|
615
|
+
const before = new Set(Object.keys(pins));
|
|
616
|
+
const copied = new Map();
|
|
617
|
+
const kitPins = ((readJsonFile(path.join(kitDir, 'castle.json')) ?? {}).imports ?? {});
|
|
618
|
+
for (const [depAlias, depPin] of Object.entries(kitPins)) {
|
|
619
|
+
if (pins[depAlias])
|
|
620
|
+
continue;
|
|
621
|
+
const depKit = kitFromAlias(depAlias);
|
|
622
|
+
const depKitDir = path.join(getKitsDir(), depKit);
|
|
623
|
+
if (fs.existsSync(depKitDir) && fs.statSync(depKitDir).isDirectory()) {
|
|
624
|
+
copyKitImport(deckDir, depKitDir, depKit, depAlias, pins, copied);
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
pins[depAlias] = depPin;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
const added = Object.keys(pins).filter((alias) => !before.has(alias));
|
|
631
|
+
if (added.length) {
|
|
632
|
+
writeJsonFile(configPath, { ...readJsonFile(configPath), imports: pins });
|
|
633
|
+
for (const alias of copied.keys())
|
|
634
|
+
lockImportTree(path.join(deckDir, IMPORTS_DIR, alias));
|
|
635
|
+
}
|
|
636
|
+
return added;
|
|
637
|
+
}
|
|
525
638
|
// `add-import <kit>`: the same copy `init --kit` makes, into an existing deck
|
|
526
639
|
// that does not have the kit yet (the caller refuses one that does). Kits the
|
|
527
640
|
// deck already pins are left as they are, which is what keeps a bare deck's
|
|
@@ -599,6 +712,7 @@ function scaffoldFromKitImport(kit, projectDir) {
|
|
|
599
712
|
writeStarterTheme(projectDir, kitDir);
|
|
600
713
|
writeJsonFile(path.join(projectDir, 'castle.json'), { imports: pins });
|
|
601
714
|
adoptKitConfig(projectDir, kitDir, alias);
|
|
715
|
+
adoptStarterConfig(projectDir, kitDir);
|
|
602
716
|
// The kit's code runs from THIS deck's node_modules, so its dependencies are
|
|
603
717
|
// declared here (see syncImportDependencies, which does the same for imports
|
|
604
718
|
// added later). Every copied kit contributes, the scaffolding kit first, so
|
|
@@ -628,6 +742,9 @@ function scaffoldFromKitImport(kit, projectDir) {
|
|
|
628
742
|
fs.writeFileSync(path.join(projectDir, 'CLAUDE.md'), makeImportedKitClaudeMd(alias, !!kitConfig.server));
|
|
629
743
|
appendPlatformSection(projectDir);
|
|
630
744
|
ensureAgentsSymlink(projectDir);
|
|
745
|
+
// Last, so a starter file never stands in for one the scaffold writes
|
|
746
|
+
// (package.json, CLAUDE.md) -- it skips any path already on disk.
|
|
747
|
+
writeStarterFiles(projectDir, kitDir);
|
|
631
748
|
for (const importedAlias of copied.keys()) {
|
|
632
749
|
lockImportTree(path.join(projectDir, IMPORTS_DIR, importedAlias));
|
|
633
750
|
}
|
package/dist/install.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execSync, spawn } from 'child_process';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
-
import { restoreMissingImports, syncImportDependencies } from './imports.js';
|
|
4
|
+
import { refreshStaleBuiltinImports, restoreMissingImports, syncImportDependencies, } from './imports.js';
|
|
5
5
|
import { normalizeDeckPackageJson } from './normalize.js';
|
|
6
6
|
import { writePlatformDocs } from './platformDoc.js';
|
|
7
7
|
// Probed in the deck, where the install itself runs: Corepack's pnpm shim refuses
|
|
@@ -74,6 +74,9 @@ export async function install(dir) {
|
|
|
74
74
|
const restored = await restoreMissingImports(projectDir);
|
|
75
75
|
for (const alias of restored)
|
|
76
76
|
console.log(`Restored import ${alias}`);
|
|
77
|
+
// A builtin kit changes under an unchanged CLI version: a copy that differs
|
|
78
|
+
// from this CLI's is replaced, so the deck runs (and later saves) this kit.
|
|
79
|
+
await refreshStaleBuiltinImports(projectDir);
|
|
77
80
|
// A fetched deck's CLAUDE.md already @imports the platform guide; write it
|
|
78
81
|
// now rather than leaving the reference dangling until the first serve.
|
|
79
82
|
writePlatformDocs(projectDir);
|
package/dist/localPaths.js
CHANGED
|
@@ -21,6 +21,10 @@ export function getSdkPackagePath() {
|
|
|
21
21
|
return path.join(getRepoRoot(), 'sdk');
|
|
22
22
|
}
|
|
23
23
|
export function getKitsDir() {
|
|
24
|
+
// Tests stand in a kits directory of their own (scripts/tests/kit-starter-and-check.mjs).
|
|
25
|
+
const override = process.env.CASTLE_WEB_KITS_DIR;
|
|
26
|
+
if (override)
|
|
27
|
+
return override;
|
|
24
28
|
// Prefer bundled kits (shipped inside the published cli package);
|
|
25
29
|
// fall back to the workspace `kits/` alongside cli/.
|
|
26
30
|
const bundled = path.join(getPackageRoot(), 'kits');
|
package/dist/login.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as api from './api.js';
|
|
2
2
|
import * as config from './config.js';
|
|
3
3
|
export async function login() {
|
|
4
|
-
const { pollToken, url } = await api.startCLILogin();
|
|
4
|
+
const { pollToken, url, verifier } = await api.startCLILogin();
|
|
5
5
|
console.log(`Opening browser to log in: ${url}`);
|
|
6
6
|
const { default: open } = await import('open');
|
|
7
7
|
await open(url);
|
|
@@ -9,7 +9,7 @@ export async function login() {
|
|
|
9
9
|
const MAX_POLLS = 600;
|
|
10
10
|
for (let i = 0; i < MAX_POLLS; i++) {
|
|
11
11
|
await new Promise((r) => setTimeout(r, 1000));
|
|
12
|
-
const user = await api.pollForCLILogin(pollToken);
|
|
12
|
+
const user = await api.pollForCLILogin(pollToken, verifier);
|
|
13
13
|
if (user) {
|
|
14
14
|
config.setAuth(user.token, user.userId);
|
|
15
15
|
console.log(`Logged in as @${user.username}`);
|
package/dist/platformDoc.js
CHANGED
|
@@ -232,14 +232,9 @@ const COMMON_SECTIONS = `## Imports are read-only
|
|
|
232
232
|
|
|
233
233
|
- **Playable on a touchscreen, with only the controls the game actually needs.** Castle decks are played on phones, so whatever input a game does use must work by touch — direct tap/drag on the game itself wherever possible, and on-screen buttons only where the mechanics genuinely call for them. Do NOT add controls a game doesn't need: never drop in a generic d-pad or movement overlay by default. Prefer touching the game directly over an overlay that just mirrors keyboard keys. Keyboard input is fine to support on top for desktop play. Match the controls to the actual mechanics — a game with no directional movement should have no movement controls at all.
|
|
234
234
|
|
|
235
|
-
## Fit the
|
|
236
|
-
|
|
237
|
-
- **
|
|
238
|
-
- **Declare fill for a deck you lay out yourself**, unless it is built around a fixed portrait board (a card game, a vertical puzzle) that would only gain empty margins: that is the default for new bare decks, and Castle's web player gives a fill deck a bigger stage and a fullscreen button. A kit deck keeps whatever its kit guide says; don't add the tag to a kit deck whose guide doesn't mention it. Fullscreen belongs to the host: never build a fullscreen button or call \`requestFullscreen\` in a deck.
|
|
239
|
-
- **A fill deck has no fixed shape, and must look right at every shape in its range -- including 5:7, which it still gets from hosts that ignore the tag.** Lay out with flex/grid against the stage -- the element \`initCard()\` returns (its \`clientWidth\`/\`clientHeight\`), or \`var(--castle-card-w)\`/\`var(--castle-card-h)\` in CSS -- not against the window: the stage is smaller than the window whenever the host frame is outside the deck's range, and inside \`castle-web serve\`'s own page. Re-layout on \`resize\`; let the playfield use the extra room (a wider view of the world, a bigger board), and anchor HUD to the stage's edges and corners. Don't letterbox the game back into a 5:7 box inside a fill stage -- that just gives up the space.
|
|
240
|
-
- **A deck that lays itself out sizes HUD, buttons and text in the card unit, \`var(--castle-unit)\`, not \`vw\`, \`vh\` or \`cqw\`**: \`font-size: calc(5 * var(--castle-unit))\`. It is 1% of the width of the largest 5:7 card that fits in the stage -- the same as \`1vw\` on a card -- so a HUD keeps its card size on a wide stage, where anything in \`vw\` grows to fill a monitor. Canvas code gets the same px value from \`cardUnit(width, height)\` of the stage. A kit deck sizes things the way its kit guide says: a kit's scene editor draws the stage smaller inside the editor, where the unit follows the window instead.
|
|
241
|
-
- **A 3D camera keeps its framing across shapes with \`fovForAspect(fov, aspect)\`**: \`camera.fov = fovForAspect(50, width / height)\` on every resize. It keeps \`fov\` at 5:7 and wider and widens it on a stage taller than 5:7, so a tall phone doesn't crop the sides of the scene.
|
|
242
|
-
- **The Play panel shows a card deck as a 5:7 card, and a fill deck at the shape picked under it**: Fit (the whole panel), Phone, Card or Landscape, each clamped into the deck's range the way a host would, with the frame's size beside the picker. A new or changed tag takes effect with the next run (Restart), like any other change to the deck. \`npm run screenshot\` captures whatever shape the open deck tab has. Those are a few shapes of many: make the layout's rules (anchors, the card unit, the camera) hold at any shape rather than tuning it pixel by pixel to what the Play panel shows. A fill deck's cover is taken at the card shape (the nearest one its range allows), since a cover is shown as a card.
|
|
235
|
+
## Fit the card
|
|
236
|
+
|
|
237
|
+
- **The deck plays inside a fixed 5:7 portrait card, not the full window.** The card is sized to fit the screen (at most about 450x630px), clips overflow, and does not scroll. Design the whole layout to fit inside that portrait box: size UI relative to the card with percentages, flex/grid, \`min()\`, \`clamp()\`, or viewport-relative units instead of fixed tall panels. Let playfields scale down on smaller cards rather than overflowing; anything outside the card edges is cut off. The SDK exports \`CARD_RATIO\` (= 5 / 7) if you need the exact ratio.
|
|
243
238
|
- **Hand-rolled \`<canvas>\` elements must account for devicePixelRatio, or the game looks blurry on phones.** Size the backing store to the CSS layout size times \`devicePixelRatio\` (e.g. \`canvas.width = rect.width * dpr\`), keep the CSS width/height as the layout size, and scale the 2D context (\`ctx.scale(dpr, dpr)\`) so drawing code stays in CSS units — re-apply on resize. Kit decks don't need to do this by hand; the kit's engine already configures its canvas for DPR.
|
|
244
239
|
- Exception: deliberate pixel art wants a fixed low-resolution backing store with \`image-rendering: pixelated\` CSS instead — don't DPR-scale that; the crisp chunky look is the point.
|
|
245
240
|
- **A WebGL canvas must be created with \`preserveDrawingBuffer: true\`, or every in-page capture of the deck comes back blank** — the Play panel's Snap and \`npm run screenshot\` both read the canvas after the frame has been shown, and by then the browser has cleared it, so the image is just the card's background. Pass it through whatever library makes the canvas: \`new THREE.WebGLRenderer({ preserveDrawingBuffer: true })\`, PixiJS \`app.init({ preserveDrawingBuffer: true })\`, or \`canvas.getContext('webgl2', { preserveDrawingBuffer: true })\`. A 2D canvas needs nothing, and kit decks already set it.
|
package/dist/playPagePolicy.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
// published bundle gets. The two must match; change both together.
|
|
6
6
|
const CDN_HOSTS = 'https://esm.sh https://cdnjs.cloudflare.com';
|
|
7
7
|
const PLAY_HOSTS = 'wss://*.play.castle.xyz';
|
|
8
|
+
// Content packs a hub door mounts (kits/hub-game/docs/content-pack.md); connect-src only.
|
|
9
|
+
const CONTENT_PACK_HOSTS = 'https://hosted.castle.games';
|
|
8
10
|
const DECK_CSP = [
|
|
9
11
|
"default-src 'self' data: blob:",
|
|
10
12
|
`script-src 'self' 'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' data: blob: ${CDN_HOSTS}`,
|
|
@@ -12,7 +14,7 @@ const DECK_CSP = [
|
|
|
12
14
|
"font-src 'self' data: blob: https://fonts.gstatic.com",
|
|
13
15
|
"img-src 'self' data: blob:",
|
|
14
16
|
"media-src 'self' data: blob:",
|
|
15
|
-
`connect-src 'self' data: blob: ${CDN_HOSTS} ${PLAY_HOSTS}`,
|
|
17
|
+
`connect-src 'self' data: blob: ${CDN_HOSTS} ${PLAY_HOSTS} ${CONTENT_PACK_HOSTS}`,
|
|
16
18
|
"frame-src 'none'",
|
|
17
19
|
"child-src 'self' blob:",
|
|
18
20
|
"worker-src 'self' blob:",
|
package/dist/remix.js
CHANGED
|
@@ -7,6 +7,11 @@ import { downloadSourceArchive, runTar } from './save-deck.js';
|
|
|
7
7
|
// promise to ITS importers, which a remix hasn't made -- and `onUpdate` is the
|
|
8
8
|
// migration it runs in them, naming a module the remix keeps as ordinary source
|
|
9
9
|
// rather than as a hook.
|
|
10
|
+
//
|
|
11
|
+
// `onCheck`, `starterScene`, `starterFiles` and `starterConfig` are kept on
|
|
12
|
+
// purpose: each names files the remix copied along with it, so they stay true
|
|
13
|
+
// of the remix. A remix of a kit that runs its own check (alias `self`) or that
|
|
14
|
+
// someone starts a deck from should behave as the kit did.
|
|
10
15
|
const PARENT_ONLY_KEYS = [
|
|
11
16
|
'deckId',
|
|
12
17
|
'cardId',
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PromptTask } from './agent-prompts.js';
|
|
2
|
+
export declare const RESULT_SUMMARY_CHARS = 600;
|
|
3
|
+
export declare const HANDOFF_MAX_CHARS = 200;
|
|
4
|
+
export declare const HANDOFF_MAX_LIST = 8;
|
|
5
|
+
interface TaskReportTarget {
|
|
6
|
+
status: string;
|
|
7
|
+
rejected?: boolean;
|
|
8
|
+
handoffNoDeckFiles?: boolean;
|
|
9
|
+
resultSummary?: string;
|
|
10
|
+
resultSummaryStartsMidWord?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function summarizeTaskResult(finalText: string): {
|
|
13
|
+
resultSummary: string;
|
|
14
|
+
resultSummaryStartsMidWord?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function noDeckFiles(filesLine: string | undefined): boolean;
|
|
17
|
+
export declare function routerTaskReport(task: TaskReportTarget): string | undefined;
|
|
18
|
+
export declare function routerPromptTask(task: TaskReportTarget & {
|
|
19
|
+
id: string;
|
|
20
|
+
title: string;
|
|
21
|
+
progress: number;
|
|
22
|
+
notes: string;
|
|
23
|
+
model?: string;
|
|
24
|
+
effort?: string;
|
|
25
|
+
item?: string;
|
|
26
|
+
}): PromptTask;
|
|
27
|
+
export declare function quotableTaskText(row: Pick<PromptTask, 'error' | 'interrupted' | 'notes' | 'report'>, durable?: string): string;
|
|
28
|
+
export {};
|