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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DeckImport } from './castleJson.js';
|
|
2
|
+
export interface ImportRegression {
|
|
3
|
+
alias: string;
|
|
4
|
+
/** The version this folder would save: its files' marker, else its pin. */
|
|
5
|
+
have: string;
|
|
6
|
+
/** The saved deck's pin. */
|
|
7
|
+
saved: string;
|
|
8
|
+
}
|
|
9
|
+
/** The import pins in the saved deck's castle.json, or null when it can't be read. */
|
|
10
|
+
export declare function savedDeckImportPins(deckId: string, fetchArchive?: (url: string) => Promise<Buffer>): Promise<Record<string, DeckImport> | null>;
|
|
11
|
+
/** One regular file's text from an uncompressed tar (ustar, pax `path`), or null. */
|
|
12
|
+
export declare function tarFileText(tar: Buffer, want: string): string | null;
|
|
13
|
+
/** Imports this folder would save at an older version than the saved deck has. */
|
|
14
|
+
export declare function importRegressions(deckDir: string, local: Record<string, DeckImport>, saved: Record<string, DeckImport>): ImportRegression[];
|
|
15
|
+
export declare function importRegressionMessage(dir: string, regressions: ImportRegression[]): string;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as zlib from 'zlib';
|
|
2
|
+
import * as api from './api.js';
|
|
3
|
+
import { readImportVersion } from './imports.js';
|
|
4
|
+
/** The import pins in the saved deck's castle.json, or null when it can't be read. */
|
|
5
|
+
export async function savedDeckImportPins(deckId, fetchArchive = fetchBytes) {
|
|
6
|
+
const source = await api.webDeckSource(deckId);
|
|
7
|
+
if (!source?.archiveUrl)
|
|
8
|
+
return null;
|
|
9
|
+
const text = tarFileText(zlib.gunzipSync(await fetchArchive(source.archiveUrl)), 'castle.json');
|
|
10
|
+
if (text === null)
|
|
11
|
+
return null;
|
|
12
|
+
const imports = JSON.parse(text).imports;
|
|
13
|
+
return imports && typeof imports === 'object' ? imports : {};
|
|
14
|
+
}
|
|
15
|
+
async function fetchBytes(url) {
|
|
16
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(20000) });
|
|
17
|
+
if (!res.ok)
|
|
18
|
+
throw new Error(`archive fetch failed: HTTP ${res.status}`);
|
|
19
|
+
return Buffer.from(await res.arrayBuffer());
|
|
20
|
+
}
|
|
21
|
+
/** One regular file's text from an uncompressed tar (ustar, pax `path`), or null. */
|
|
22
|
+
export function tarFileText(tar, want) {
|
|
23
|
+
let offset = 0;
|
|
24
|
+
let paxName;
|
|
25
|
+
while (offset + 512 <= tar.length) {
|
|
26
|
+
const header = tar.subarray(offset, offset + 512);
|
|
27
|
+
if (header.every((b) => b === 0))
|
|
28
|
+
return null;
|
|
29
|
+
const field = (start, length) => {
|
|
30
|
+
const raw = header.subarray(start, start + length);
|
|
31
|
+
const end = raw.indexOf(0);
|
|
32
|
+
return raw.subarray(0, end === -1 ? length : end).toString('utf-8');
|
|
33
|
+
};
|
|
34
|
+
const size = parseInt(field(124, 12).trim() || '0', 8);
|
|
35
|
+
const type = field(156, 1);
|
|
36
|
+
const prefix = field(345, 155);
|
|
37
|
+
const name = paxName ?? (prefix ? `${prefix}/${field(0, 100)}` : field(0, 100));
|
|
38
|
+
const body = tar.subarray(offset + 512, offset + 512 + size);
|
|
39
|
+
paxName = undefined;
|
|
40
|
+
if (type === 'x') {
|
|
41
|
+
const match = /\d+ path=([^\n]*)\n/.exec(body.toString('utf-8'));
|
|
42
|
+
if (match)
|
|
43
|
+
paxName = match[1];
|
|
44
|
+
}
|
|
45
|
+
else if ((type === '0' || type === '') && name.replace(/^(\.\/)+/, '') === want) {
|
|
46
|
+
return body.toString('utf-8');
|
|
47
|
+
}
|
|
48
|
+
offset += 512 + Math.ceil(size / 512) * 512;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
function semverParts(version) {
|
|
53
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
54
|
+
return match ? match.slice(1, 4).map(Number) : null;
|
|
55
|
+
}
|
|
56
|
+
/** Whether `a` is an older version than `b` of the same kind of pin; false when unsure. */
|
|
57
|
+
function older(a, aVersion, b) {
|
|
58
|
+
if (a.source === 'builtin' && b.source === 'builtin') {
|
|
59
|
+
const x = semverParts(aVersion);
|
|
60
|
+
const y = semverParts(b.version);
|
|
61
|
+
if (!x || !y)
|
|
62
|
+
return false;
|
|
63
|
+
for (let i = 0; i < 3; i += 1)
|
|
64
|
+
if (x[i] !== y[i])
|
|
65
|
+
return x[i] < y[i];
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (a.deckId && a.deckId === b.deckId) {
|
|
69
|
+
const x = Date.parse(aVersion);
|
|
70
|
+
const y = Date.parse(b.version);
|
|
71
|
+
return Number.isFinite(x) && Number.isFinite(y) && x < y;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
/** Imports this folder would save at an older version than the saved deck has. */
|
|
76
|
+
export function importRegressions(deckDir, local, saved) {
|
|
77
|
+
const out = [];
|
|
78
|
+
for (const [alias, pin] of Object.entries(local)) {
|
|
79
|
+
const savedPin = saved[alias];
|
|
80
|
+
if (!pin || !savedPin || typeof pin.version !== 'string' || typeof savedPin.version !== 'string')
|
|
81
|
+
continue;
|
|
82
|
+
// A fetched kit's marker says which files are really here (get-deck moves
|
|
83
|
+
// the pin and leaves imports/ alone); a builtin copy is its pin's.
|
|
84
|
+
const marker = pin.deckId ? readImportVersion(deckDir, alias) : null;
|
|
85
|
+
const have = marker && marker.deckId === pin.deckId ? marker.version : pin.version;
|
|
86
|
+
if (older(pin, have, savedPin))
|
|
87
|
+
out.push({ alias, have, saved: savedPin.version });
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
export function importRegressionMessage(dir, regressions) {
|
|
92
|
+
return [
|
|
93
|
+
'Not saved: this folder has never synced with the saved deck, and saving it would move imports back:',
|
|
94
|
+
...regressions.map((r) => ` ${r.alias}: this folder ${r.have}, the saved deck ${r.saved}`),
|
|
95
|
+
'Either:',
|
|
96
|
+
` castle-web get-deck ${dir} --side fetch the saved copy beside this one to work from`,
|
|
97
|
+
` castle-web update-import <alias> ${dir} move an import forward, then save`,
|
|
98
|
+
` castle-web save-deck ${dir} --force save anyway, rolling those imports back`,
|
|
99
|
+
].join('\n');
|
|
100
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as api from './api.js';
|
|
2
|
+
// The account gate on another deck's code running against THIS deck: an
|
|
3
|
+
// import's `onUpdate` migration, its `onCheck`, and serve-start auto-update all
|
|
4
|
+
// answer to it. Its own module because both imports.ts and the check path need
|
|
5
|
+
// it, and imports.ts already imports save-deck.ts, which runs the checks --
|
|
6
|
+
// living in either would close a cycle.
|
|
7
|
+
//
|
|
8
|
+
// Honored only for decks on the castle account. A deck that pushes new code to
|
|
9
|
+
// everyone who imported it, or runs its code against their files, is asking for
|
|
10
|
+
// a lot of trust, and until decks carry some other signal of it, the only ones
|
|
11
|
+
// that get it are the ones we publish (the framework kits -- the same account
|
|
12
|
+
// `init` qualifies their aliases with).
|
|
13
|
+
//
|
|
14
|
+
// Deliberately not a deck setting: nothing in castle.json a person can flip,
|
|
15
|
+
// since that would be the leash undoing itself. CASTLE_AUTO_UPDATE_TRUSTED_ACCOUNT
|
|
16
|
+
// is the escape hatch for local kit work and tests: which username counts as
|
|
17
|
+
// trusted (default `castle`). Tests set it to exercise both branches; setting
|
|
18
|
+
// it to a non-matching name also disables updates as a side effect.
|
|
19
|
+
export const TRUSTED_IMPORT_ACCOUNT = process.env.CASTLE_AUTO_UPDATE_TRUSTED_ACCOUNT ?? 'castle';
|
|
20
|
+
// Who published a deck. Readable without auth for the same decks webDeckSource
|
|
21
|
+
// is, so this answers in a sandbox with no login. A lookup that fails answers
|
|
22
|
+
// "not trusted": the failure direction has to be the one that leaves an import
|
|
23
|
+
// where its deck's author pinned it, and its code not run.
|
|
24
|
+
export async function importIsOnTrustedAccount(deckId) {
|
|
25
|
+
const meta = await api.deckMeta(deckId).catch(() => null);
|
|
26
|
+
return meta?.creator?.username === TRUSTED_IMPORT_ACCOUNT;
|
|
27
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare function hookTimeoutMs(): number;
|
|
1
2
|
/** What a hook is handed, plus the module to run. */
|
|
2
3
|
export interface ImportUpdateHook {
|
|
3
4
|
/** The declared module, resolved to an absolute path. */
|
|
@@ -9,6 +10,7 @@ export interface ImportUpdateHook {
|
|
|
9
10
|
from: string;
|
|
10
11
|
to: string;
|
|
11
12
|
}
|
|
13
|
+
export declare function resolveFileInside(importDir: string, declared: string): string | null;
|
|
12
14
|
/**
|
|
13
15
|
* The hook module `imports/<alias>` declares, or null when it declares none or
|
|
14
16
|
* the path it names is not usable. Read from the copy ON DISK, which is the
|
|
@@ -16,6 +18,22 @@ export interface ImportUpdateHook {
|
|
|
16
18
|
* has to be the new copy's.
|
|
17
19
|
*/
|
|
18
20
|
export declare function findImportUpdateHook(deckDir: string, alias: string): string | null;
|
|
21
|
+
export declare function outputLines(text: string): string[];
|
|
22
|
+
export declare function failureDetail(e: unknown): string;
|
|
23
|
+
/**
|
|
24
|
+
* Run a hook module in the runner child, under the hook clock. `reportResult`
|
|
25
|
+
* asks the runner to print what the hook returned on a line of its own
|
|
26
|
+
* (HOOK_RESULT_PREFIX) -- an `onUpdate` hook returns nothing, an `onCheck` hook
|
|
27
|
+
* returns its verdict.
|
|
28
|
+
*/
|
|
29
|
+
export declare function execHookModule(modulePath: string, context: Record<string, string | boolean>, cwd: string, options?: {
|
|
30
|
+
reportResult?: boolean;
|
|
31
|
+
}): Promise<{
|
|
32
|
+
stdout: string;
|
|
33
|
+
stderr: string;
|
|
34
|
+
}>;
|
|
35
|
+
/** The line the runner prints a hook's return value on, as JSON. */
|
|
36
|
+
export declare const HOOK_RESULT_PREFIX = "CASTLE_HOOK_RESULT ";
|
|
19
37
|
/**
|
|
20
38
|
* Save a version, run the hook, and put the deck's files back if it fails.
|
|
21
39
|
*
|
package/dist/importUpdateHook.js
CHANGED
|
@@ -19,9 +19,10 @@ const DIST_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
|
19
19
|
const RUNNER = path.join(DIST_DIR, 'importUpdateHookRunner.js');
|
|
20
20
|
// A hook is somebody else's code with the deck's files in front of it, so it
|
|
21
21
|
// gets a wall clock rather than the chance to hang a serve start forever. The
|
|
22
|
-
// env override exists for the
|
|
23
|
-
// (scripts/tests/import-update-hook.mjs); nothing else
|
|
24
|
-
|
|
22
|
+
// env override exists for the tests that prove the clock works
|
|
23
|
+
// (scripts/tests/import-update-hook.mjs, import-check-hook.mjs); nothing else
|
|
24
|
+
// should set it. `onCheck` hooks share it (importCheckHook.ts).
|
|
25
|
+
export function hookTimeoutMs() {
|
|
25
26
|
const raw = Number(process.env.CASTLE_IMPORT_HOOK_TIMEOUT_MS);
|
|
26
27
|
return Number.isFinite(raw) && raw > 0 ? raw : 120_000;
|
|
27
28
|
}
|
|
@@ -44,7 +45,11 @@ function childContext(hook) {
|
|
|
44
45
|
// deck's files in reach, so `../../…` or an absolute path would be a way to run
|
|
45
46
|
// code from anywhere on the machine. POSIX-relative because that is how every
|
|
46
47
|
// other path in a castle.json is written.
|
|
47
|
-
|
|
48
|
+
//
|
|
49
|
+
// Exported because the same rule guards every path a kit's castle.json names
|
|
50
|
+
// for the CLI to act on: `onCheck` (importCheckHook.ts) and `starterFiles`
|
|
51
|
+
// (init.ts `writeStarterFiles`).
|
|
52
|
+
export function resolveFileInside(importDir, declared) {
|
|
48
53
|
const rel = declared.trim();
|
|
49
54
|
if (!rel || rel.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(rel) || rel.includes('\\'))
|
|
50
55
|
return null;
|
|
@@ -72,18 +77,18 @@ export function findImportUpdateHook(deckDir, alias) {
|
|
|
72
77
|
const declared = readCastleJson(importDir)?.onUpdate;
|
|
73
78
|
if (typeof declared !== 'string' || !declared.trim())
|
|
74
79
|
return null;
|
|
75
|
-
const resolved =
|
|
80
|
+
const resolved = resolveFileInside(importDir, declared);
|
|
76
81
|
if (!resolved) {
|
|
77
82
|
console.warn(`"${alias}" declares an update hook at "${declared}", which is not a file inside it -- skipping it.`);
|
|
78
83
|
}
|
|
79
84
|
return resolved;
|
|
80
85
|
}
|
|
81
|
-
function outputLines(text) {
|
|
86
|
+
export function outputLines(text) {
|
|
82
87
|
return text.split('\n').map((line) => line.trimEnd()).filter(Boolean);
|
|
83
88
|
}
|
|
84
89
|
// The last few lines of stderr are what says WHY a hook failed; the whole stack
|
|
85
90
|
// of a 200-line module is not.
|
|
86
|
-
function failureDetail(e) {
|
|
91
|
+
export function failureDetail(e) {
|
|
87
92
|
const stderr = e?.stderr ?? '';
|
|
88
93
|
const tail = outputLines(stderr).slice(-8).join('\n');
|
|
89
94
|
if (tail)
|
|
@@ -92,6 +97,24 @@ function failureDetail(e) {
|
|
|
92
97
|
return `it did not finish in ${hookTimeoutMs()}ms`;
|
|
93
98
|
return e instanceof Error ? e.message : String(e);
|
|
94
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Run a hook module in the runner child, under the hook clock. `reportResult`
|
|
102
|
+
* asks the runner to print what the hook returned on a line of its own
|
|
103
|
+
* (HOOK_RESULT_PREFIX) -- an `onUpdate` hook returns nothing, an `onCheck` hook
|
|
104
|
+
* returns its verdict.
|
|
105
|
+
*/
|
|
106
|
+
export async function execHookModule(modulePath, context, cwd, options = {}) {
|
|
107
|
+
const args = [RUNNER, modulePath, JSON.stringify(context)];
|
|
108
|
+
if (options.reportResult)
|
|
109
|
+
args.push('--report-result');
|
|
110
|
+
return execFileAsync(process.execPath, args, {
|
|
111
|
+
cwd,
|
|
112
|
+
timeout: hookTimeoutMs(),
|
|
113
|
+
maxBuffer: MAX_HOOK_OUTPUT,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** The line the runner prints a hook's return value on, as JSON. */
|
|
117
|
+
export const HOOK_RESULT_PREFIX = 'CASTLE_HOOK_RESULT ';
|
|
95
118
|
/**
|
|
96
119
|
* Save a version, run the hook, and put the deck's files back if it fails.
|
|
97
120
|
*
|
|
@@ -120,7 +143,7 @@ export async function runImportUpdateHook(hook, log) {
|
|
|
120
143
|
`(\`castle-web restore-version ${restorePoint}\` puts them back).`);
|
|
121
144
|
}
|
|
122
145
|
try {
|
|
123
|
-
const { stdout, stderr } = await
|
|
146
|
+
const { stdout, stderr } = await execHookModule(hook.modulePath, childContext(hook), hook.deckDir);
|
|
124
147
|
for (const line of [...outputLines(stdout), ...outputLines(stderr)]) {
|
|
125
148
|
log(`${hook.alias} hook: ${line}`);
|
|
126
149
|
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// The child process one import's `onUpdate` hook runs in. Why a
|
|
3
|
-
// in importUpdateHook.ts; this is only the entry point.
|
|
2
|
+
// The child process one import's `onUpdate` or `onCheck` hook runs in. Why a
|
|
3
|
+
// child at all is in importUpdateHook.ts; this is only the entry point.
|
|
4
4
|
//
|
|
5
|
-
// argv: the hook module's absolute path, then its context as JSON
|
|
6
|
-
// supplied here rather than serialized,
|
|
7
|
-
// process boundary -- the parent reads
|
|
5
|
+
// argv: the hook module's absolute path, then its context as JSON, then
|
|
6
|
+
// optionally `--report-result`. `log` is supplied here rather than serialized,
|
|
7
|
+
// because a function cannot cross the process boundary -- the parent reads
|
|
8
|
+
// stdout back and labels it. For the same reason a hook's return value comes
|
|
9
|
+
// back as one prefixed JSON line on stdout, printed last.
|
|
10
|
+
//
|
|
11
|
+
// The prefix is spelled out rather than imported from importUpdateHook.ts: this
|
|
12
|
+
// entry point stays free of the CLI's module graph, so a hook runs against a
|
|
13
|
+
// fresh process with nothing of ours loaded.
|
|
8
14
|
import { pathToFileURL } from 'url';
|
|
9
15
|
async function main() {
|
|
10
|
-
const [modulePath, contextJson] = process.argv.slice(2);
|
|
16
|
+
const [modulePath, contextJson, flag] = process.argv.slice(2);
|
|
11
17
|
if (!modulePath || !contextJson) {
|
|
12
18
|
throw new Error('usage: importUpdateHookRunner <module> <contextJson>');
|
|
13
19
|
}
|
|
@@ -16,7 +22,13 @@ async function main() {
|
|
|
16
22
|
throw new Error(`${modulePath} does not default-export a function.`);
|
|
17
23
|
}
|
|
18
24
|
const hook = mod.default;
|
|
19
|
-
await hook({
|
|
25
|
+
const result = await hook({
|
|
26
|
+
...JSON.parse(contextJson),
|
|
27
|
+
log: (message) => console.log(message),
|
|
28
|
+
});
|
|
29
|
+
if (flag === '--report-result') {
|
|
30
|
+
console.log(`CASTLE_HOOK_RESULT ${JSON.stringify(result ?? null)}`);
|
|
31
|
+
}
|
|
20
32
|
}
|
|
21
33
|
main().catch((e) => {
|
|
22
34
|
console.error(e instanceof Error ? (e.stack ?? e.message) : String(e));
|
package/dist/imports.d.ts
CHANGED
|
@@ -6,6 +6,22 @@ export interface ImportVersion {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function writeImportVersion(importDir: string, value: ImportVersion): void;
|
|
8
8
|
export declare function readImportVersion(deckDir: string, alias: string): ImportVersion | null;
|
|
9
|
+
export interface BuiltinImportStamp {
|
|
10
|
+
source: 'builtin';
|
|
11
|
+
kit: string;
|
|
12
|
+
version: string;
|
|
13
|
+
digest: string;
|
|
14
|
+
}
|
|
15
|
+
/** A kit tree's files, as a builtin copy takes them: relative path and bytes, hashed. */
|
|
16
|
+
export declare function builtinKitDigest(kitDir: string): string;
|
|
17
|
+
export declare function writeBuiltinStamp(importDir: string, stamp: BuiltinImportStamp): void;
|
|
18
|
+
/** A builtin kit copied into a deck, stamped. `destDir` must not exist. */
|
|
19
|
+
export declare function copyBuiltinKit(kitDir: string, destDir: string, kit: string, version: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Builtin imports whose copy differs from this CLI's kit of the same version,
|
|
22
|
+
* replaced with this CLI's. Returns the aliases replaced.
|
|
23
|
+
*/
|
|
24
|
+
export declare function refreshStaleBuiltinImports(deckDir: string, log?: (message: string) => void): Promise<string[]>;
|
|
9
25
|
export type ImportErrorCode = 'no-deck-ref' | 'bad-deck-ref' | 'not-a-deck-link' | 'link-unreachable' | 'no-such-dir' | 'self-import' | 'classic-deck' | 'no-source' | 'bad-alias' | 'already-imported';
|
|
10
26
|
export declare class ImportError extends Error {
|
|
11
27
|
code: ImportErrorCode;
|
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;
|