castle-web-cli 0.4.188 → 0.4.190
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.js +4 -2
- package/dist/agent.js +30 -12
- package/dist/castleJson.d.ts +1 -0
- package/dist/castleJson.js +6 -0
- package/dist/forks.js +5 -3
- package/dist/ide.js +9 -2
- package/dist/imports.d.ts +8 -2
- package/dist/imports.js +67 -7
- package/dist/init.js +12 -2
- package/dist/shell/assets/index-Bo8dx2Ps.js +449 -0
- package/dist/shell/assets/index-DrFIFZVh.css +1 -0
- package/dist/shell/index.html +2 -2
- package/kits/physics-2d/castle.json +1 -1
- package/kits/physics-2d/editors/PxArtEditor.jsx +6 -28
- package/kits/physics-2d/editors/SceneEditor.jsx +16 -67
- package/kits/physics-2d/editors/editorHistory.js +27 -0
- package/kits/physics-2d/editors/pixelEditorChrome.jsx +7 -19
- package/kits/physics-2d/engine/icons.js +0 -2
- package/kits/physics-2d/eslint.config.js +1 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/PxModelEditor.jsx +2 -2
- package/kits/physics-3d/engine3d/Scene3DEditor.jsx +2 -2
- package/kits/physics-3d/engine3d/editorChrome.jsx +23 -51
- package/package.json +2 -2
- package/dist/shell/assets/index-BHS1yecn.js +0 -449
- package/dist/shell/assets/index-BaqrGZkv.css +0 -1
package/dist/agent-prompts.js
CHANGED
|
@@ -72,13 +72,15 @@ comma-separated active-task titles or ids, or \`all\`
|
|
|
72
72
|
- Task agents are capable coding agents working in this same deck directory, but they know nothing about this conversation beyond your prompt.
|
|
73
73
|
- The deck keeps its own version history, and you may READ it: \`castle-web list-versions\` shows the versions newest first, and \`castle-web show-version <id>\` shows what one changed, as diffs of just those files. Use them to answer "what changed" or to ground a claim about recent work. You NEVER run \`save-version\` -- you did not make the changes, so a version of yours would not correspond to a unit of work -- and you NEVER run \`restore-version\`: going back is the user's own decision, not something you do on their behalf.
|
|
74
74
|
|
|
75
|
-
Asking with options (the \`\`\`ask block). When you need the user to settle a few choices at once, emit ONE fenced block tagged \`ask\` containing JSON -- it renders inline in the chat as grouped options they tap and submit together (far better than stacking questions they can only half-answer). Reach for it to pin a direction fast when their ask is vague ("make me a game" -> ask what kind), NOT to interrogate.
|
|
75
|
+
Asking with options (the \`\`\`ask block). When you need the user to settle a few choices at once, emit ONE fenced block tagged \`ask\` containing JSON -- it renders inline in the chat as grouped options they tap and submit together (far better than stacking questions they can only half-answer). Reach for it to pin a direction fast when their ask is vague ("make me a game" -> ask what kind), NOT to interrogate.
|
|
76
76
|
|
|
77
77
|
\`\`\`ask
|
|
78
78
|
{ "questions": [ { "id": "kind", "q": "What kind of game?", "options": ["Arcade", "Puzzle", "Platformer"] }, { "id": "feel", "q": "What should it feel like?", "options": ["Cozy", "Frantic"], "multi": true } ] }
|
|
79
79
|
\`\`\`
|
|
80
80
|
|
|
81
|
-
- Per question: \`q\` (the text, required), \`options\` (
|
|
81
|
+
- Per question: \`q\` (the text, required), \`options\` (named choices, required), \`multi\` (optional -- false/omitted = pick one, true = pick any that apply), \`id\` (optional answer handle). Keep it to a few high-leverage questions.
|
|
82
|
+
- Skip and Other are always on the widget: Skip sits beside the question so they can pass on it, Other is a free-text field at the bottom of the list. Do NOT add "Other" or "Skip" to \`options\` -- they are already there. Named options only.
|
|
83
|
+
- A skipped question comes back as \`skipped\`. Other comes back as whatever they typed. Act on those the same as a named pick.
|
|
82
84
|
- The user's picks come back as their next message, which you then act on (usually by spawning the first build tasks). Don't pair an \`\`\`ask block with task directives in the same reply -- ask first, build once they answer. Don't use one when a single plain question would do, and never re-ask something already settled.
|
|
83
85
|
|
|
84
86
|
Conversation style:
|
package/dist/agent.js
CHANGED
|
@@ -804,16 +804,18 @@ function humanizeAskBlocks(text) {
|
|
|
804
804
|
return null;
|
|
805
805
|
const opts = q.options
|
|
806
806
|
.filter((o) => typeof o === 'string' && o.trim() !== '')
|
|
807
|
+
.filter((o) => {
|
|
808
|
+
const t = o.trim().toLowerCase();
|
|
809
|
+
return t !== 'other' && t !== 'skip';
|
|
810
|
+
})
|
|
807
811
|
.join(' / ');
|
|
808
|
-
if (!opts)
|
|
809
|
-
return null;
|
|
810
812
|
const mode = q.multi === true ? 'pick any' : 'pick one';
|
|
811
|
-
return `- ${q.q} (${mode}): ${opts}`;
|
|
813
|
+
return opts ? `- ${q.q} (${mode}): ${opts}` : `- ${q.q} (${mode})`;
|
|
812
814
|
})
|
|
813
815
|
.filter((l) => l !== null);
|
|
814
816
|
if (lines.length === 0)
|
|
815
817
|
return whole;
|
|
816
|
-
return `[You asked the user to choose:\n${lines.join('\n')}]`;
|
|
818
|
+
return `[You asked the user to choose. Skip and Other are always on the picker -- do not add them to options:\n${lines.join('\n')}]`;
|
|
817
819
|
}
|
|
818
820
|
catch {
|
|
819
821
|
return whole;
|
|
@@ -2684,6 +2686,8 @@ function createMessageLog(messagesPath, broadcast, welcomeMessage, forClient) {
|
|
|
2684
2686
|
function add(message) {
|
|
2685
2687
|
messages.push(message);
|
|
2686
2688
|
persist();
|
|
2689
|
+
if (message.hideFromUi)
|
|
2690
|
+
return;
|
|
2687
2691
|
broadcast({ type: 'message-add', message: forClient(message) });
|
|
2688
2692
|
}
|
|
2689
2693
|
function addLog(text) {
|
|
@@ -3311,6 +3315,7 @@ function loadRecoverableSends(deckDir, pendingPath, committedIds) {
|
|
|
3311
3315
|
// predates @-mentions wrote none at all, which is a send worth
|
|
3312
3316
|
// recovering for its words, not a malformed one.
|
|
3313
3317
|
refs: validMessageRefs(deckDir, refsOrLegacyFiles(item)),
|
|
3318
|
+
...(item.hideFromUi === true ? { hideFromUi: true } : {}),
|
|
3314
3319
|
});
|
|
3315
3320
|
}
|
|
3316
3321
|
}
|
|
@@ -3345,7 +3350,10 @@ function persistPendingSends(ctx) {
|
|
|
3345
3350
|
atomicWriteFileSync(ctx.pendingPath, JSON.stringify(ctx.state.pendingSends, null, 2) + '\n');
|
|
3346
3351
|
}
|
|
3347
3352
|
function computeQueuedSnippets(pendingSends) {
|
|
3348
|
-
return pendingSends
|
|
3353
|
+
return pendingSends
|
|
3354
|
+
.filter((p) => !p.hideFromUi)
|
|
3355
|
+
.map((p) => p.text.trim())
|
|
3356
|
+
.filter(Boolean);
|
|
3349
3357
|
}
|
|
3350
3358
|
function broadcastQueueState(ctx) {
|
|
3351
3359
|
ctx.broadcast({
|
|
@@ -3411,6 +3419,8 @@ function commitDrainedSends(drained, log) {
|
|
|
3411
3419
|
message.attachments = item.attachments;
|
|
3412
3420
|
if (item.refs.length > 0)
|
|
3413
3421
|
message.refs = item.refs;
|
|
3422
|
+
if (item.hideFromUi)
|
|
3423
|
+
message.hideFromUi = true;
|
|
3414
3424
|
log.add(message);
|
|
3415
3425
|
}
|
|
3416
3426
|
if (item.text.trim())
|
|
@@ -3496,7 +3506,7 @@ function safeClientMessageId(clientId) {
|
|
|
3496
3506
|
return null;
|
|
3497
3507
|
return /^[A-Za-z0-9_-]{1,32}$/.test(clientId) ? clientId : null;
|
|
3498
3508
|
}
|
|
3499
|
-
function handleQueueUserMessage(ctx, text, images, refs, clientId) {
|
|
3509
|
+
function handleQueueUserMessage(ctx, text, images, refs, clientId, hideFromUi) {
|
|
3500
3510
|
const { state } = ctx;
|
|
3501
3511
|
// Mid-run: queue (don't interrupt). It shows as a queued row in the
|
|
3502
3512
|
// composer and flushes when the current turn settles. Idle: start now.
|
|
@@ -3524,6 +3534,7 @@ function handleQueueUserMessage(ctx, text, images, refs, clientId) {
|
|
|
3524
3534
|
text,
|
|
3525
3535
|
attachments,
|
|
3526
3536
|
refs: validMessageRefs(ctx.deckDir, refs),
|
|
3537
|
+
...(hideFromUi ? { hideFromUi: true } : {}),
|
|
3527
3538
|
});
|
|
3528
3539
|
persistPendingSends(ctx);
|
|
3529
3540
|
if (state.routerRunning) {
|
|
@@ -3574,9 +3585,13 @@ function interruptRouterQueue(ctx) {
|
|
|
3574
3585
|
}
|
|
3575
3586
|
function cancelQueuedSend(ctx, index) {
|
|
3576
3587
|
const { state } = ctx;
|
|
3577
|
-
|
|
3588
|
+
const visible = state.pendingSends.filter((p) => !p.hideFromUi);
|
|
3589
|
+
if (!Number.isInteger(index) || index < 0 || index >= visible.length)
|
|
3578
3590
|
return;
|
|
3579
|
-
state.pendingSends.
|
|
3591
|
+
const real = state.pendingSends.indexOf(visible[index]);
|
|
3592
|
+
if (real < 0)
|
|
3593
|
+
return;
|
|
3594
|
+
state.pendingSends.splice(real, 1);
|
|
3580
3595
|
persistPendingSends(ctx);
|
|
3581
3596
|
broadcastQueueState(ctx);
|
|
3582
3597
|
}
|
|
@@ -3608,7 +3623,7 @@ function createRouterQueue(deps) {
|
|
|
3608
3623
|
persistPendingSends(ctx);
|
|
3609
3624
|
maybeStartRouterQueueTurn(ctx);
|
|
3610
3625
|
return {
|
|
3611
|
-
handleUserMessage: (text, images, refs, clientId) => handleQueueUserMessage(ctx, text, images, refs, clientId),
|
|
3626
|
+
handleUserMessage: (text, images, refs, clientId, hideFromUi) => handleQueueUserMessage(ctx, text, images, refs, clientId, hideFromUi),
|
|
3612
3627
|
interruptRouter: () => interruptRouterQueue(ctx),
|
|
3613
3628
|
cancelQueued: (index) => cancelQueuedSend(ctx, index),
|
|
3614
3629
|
isRunning: () => ctx.state.routerRunning,
|
|
@@ -3790,8 +3805,9 @@ export function createAgentServer(opts) {
|
|
|
3790
3805
|
log.persist();
|
|
3791
3806
|
broadcast({ type: 'message-picker', id, pickerAnswers: msg.pickerAnswers });
|
|
3792
3807
|
}
|
|
3793
|
-
if (text.trim())
|
|
3794
|
-
routerQueue.handleUserMessage(text.trim(), undefined, undefined);
|
|
3808
|
+
if (text.trim()) {
|
|
3809
|
+
routerQueue.handleUserMessage(text.trim(), undefined, undefined, undefined, true);
|
|
3810
|
+
}
|
|
3795
3811
|
}
|
|
3796
3812
|
function handleTaskAck(id, rejected) {
|
|
3797
3813
|
taskStore.acknowledge(id, rejected);
|
|
@@ -3837,7 +3853,9 @@ export function createAgentServer(opts) {
|
|
|
3837
3853
|
clients.add(socket);
|
|
3838
3854
|
const hello = {
|
|
3839
3855
|
type: 'hello',
|
|
3840
|
-
messages: messages
|
|
3856
|
+
messages: messages
|
|
3857
|
+
.filter((message) => !message.hideFromUi)
|
|
3858
|
+
.map((message) => asClientMessage(message, opts.signPath)),
|
|
3841
3859
|
tasks: taskStore.sorted().map((task) => asClientTask(task, opts.signPath)),
|
|
3842
3860
|
settings,
|
|
3843
3861
|
feeds: Object.fromEntries(taskFeeds.map),
|
package/dist/castleJson.d.ts
CHANGED
package/dist/castleJson.js
CHANGED
|
@@ -20,6 +20,12 @@ import picomatch from 'picomatch';
|
|
|
20
20
|
// renders in the fallback while claiming otherwise.
|
|
21
21
|
export const STARTER_THEME_FILES = ['theme.style', 'fonts.generated.js'];
|
|
22
22
|
export const IMPORTS_DIR = 'imports';
|
|
23
|
+
// Written into every placed import (`imports/<alias>/`) naming the deck and
|
|
24
|
+
// version whose files these are. Derived state like the tree it sits in: it
|
|
25
|
+
// is never deck content, so the files API hides it and forking refuses it.
|
|
26
|
+
// Defined here rather than in imports.ts so forks.ts can name it without a
|
|
27
|
+
// cycle.
|
|
28
|
+
export const IMPORT_VERSION_FILE = '.castle-import-version.json';
|
|
23
29
|
export const DEFAULT_STARTER_SCENE = 'scenes/main.scene';
|
|
24
30
|
export const DEFAULT_SERVER_TICK_RATE = 20;
|
|
25
31
|
export const DEFAULT_SERVER_MAX_PLAYERS = 8;
|
package/dist/forks.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as crypto from 'crypto';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
-
import { IMPORTS_DIR, readCastleJson } from './castleJson.js';
|
|
4
|
+
import { IMPORTS_DIR, IMPORT_VERSION_FILE, readCastleJson, } from './castleJson.js';
|
|
5
5
|
// A fork is this deck's own version of one file from an import, kept at the same
|
|
6
6
|
// path under `forks/` and substituted for the imported file wherever it is
|
|
7
7
|
// loaded. Same path, not a copy elsewhere, so every existing reference to it --
|
|
@@ -91,8 +91,10 @@ export function resolveForkedFile(deckDir, relPosix) {
|
|
|
91
91
|
// honest answer until forking one of these means something.
|
|
92
92
|
//
|
|
93
93
|
// Matched against the path INSIDE the import, so this is the import's own root
|
|
94
|
-
// manifest and not some `scenes/castle.json` a deck happens to have.
|
|
95
|
-
|
|
94
|
+
// manifest and not some `scenes/castle.json` a deck happens to have. The
|
|
95
|
+
// version marker is the same kind of thing: a record about the import, and
|
|
96
|
+
// forking it would copy that record into forks/, which IS archived.
|
|
97
|
+
const NON_FORKABLE = new Set(['castle.json', IMPORT_VERSION_FILE]);
|
|
96
98
|
/** Whether a path inside an import may be forked. */
|
|
97
99
|
export function isForkable(inner) {
|
|
98
100
|
return !NON_FORKABLE.has(inner);
|
package/dist/ide.js
CHANGED
|
@@ -17,7 +17,7 @@ import headlessPkg from '@xterm/headless';
|
|
|
17
17
|
import { SerializeAddon } from '@xterm/addon-serialize';
|
|
18
18
|
import { WebSocketServer } from 'ws';
|
|
19
19
|
import { rawDataToString } from './rawData.js';
|
|
20
|
-
import { IMPORTS_DIR, importStatuses, updateImport } from './imports.js';
|
|
20
|
+
import { IMPORTS_DIR, IMPORT_VERSION_FILE, importStatuses, updateImport, } from './imports.js';
|
|
21
21
|
import { FORKS_DIR, forkImportFile, forkStateOf, listOwnForks, ownForkFile, resolveForkedFile, revertImportFile, } from './forks.js';
|
|
22
22
|
import { ensureVisibleGlob, ensureVisiblePath } from './castleJson.js';
|
|
23
23
|
import { readEditorConfig, resolveFileTypes, } from './editorConfig.js';
|
|
@@ -263,6 +263,11 @@ export function resolveDeckPath(deckDir, requestedPath, opts = {}) {
|
|
|
263
263
|
return { ok: false, error: `Path outside the deck: ${requestedPath}` };
|
|
264
264
|
}
|
|
265
265
|
const relPosix = rel.split(path.sep).join('/');
|
|
266
|
+
// The marker describes derived import state, not deck content, so the files
|
|
267
|
+
// API must not expose it even to a client that guesses its hidden name.
|
|
268
|
+
if (isImportPath(relPosix) && parts.includes(IMPORT_VERSION_FILE)) {
|
|
269
|
+
return { ok: false, error: `Protected deck path: ${requestedPath}` };
|
|
270
|
+
}
|
|
266
271
|
// An imported path answers with whatever overrides it, keeping `rel` as the
|
|
267
272
|
// imports path -- that is what the deck calls this file everywhere else, and
|
|
268
273
|
// only the file on disk changes.
|
|
@@ -297,7 +302,9 @@ function listDeckFiles(deckDir) {
|
|
|
297
302
|
return;
|
|
298
303
|
}
|
|
299
304
|
for (const entry of entries) {
|
|
300
|
-
|
|
305
|
+
// The version marker is derived import state, not a deck file; every
|
|
306
|
+
// other dotfile (.gitignore, .prettierrc) stays listed as before.
|
|
307
|
+
if (entry.name === '.DS_Store' || entry.name === IMPORT_VERSION_FILE)
|
|
301
308
|
continue;
|
|
302
309
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
303
310
|
if (entry.isDirectory()) {
|
package/dist/imports.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { IMPORTS_DIR } from './castleJson.js';
|
|
2
|
-
export { IMPORTS_DIR };
|
|
1
|
+
import { IMPORTS_DIR, IMPORT_VERSION_FILE } from './castleJson.js';
|
|
2
|
+
export { IMPORTS_DIR, IMPORT_VERSION_FILE };
|
|
3
|
+
export interface ImportVersion {
|
|
4
|
+
deckId: string;
|
|
5
|
+
version: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function writeImportVersion(importDir: string, value: ImportVersion): void;
|
|
8
|
+
export declare function readImportVersion(deckDir: string, alias: string): ImportVersion | null;
|
|
3
9
|
export type ImportErrorCode = 'no-deck-ref' | 'bad-deck-ref' | 'no-such-dir' | 'self-import' | 'no-source' | 'bad-alias';
|
|
4
10
|
export declare class ImportError extends Error {
|
|
5
11
|
code: ImportErrorCode;
|
package/dist/imports.js
CHANGED
|
@@ -5,8 +5,9 @@ import * as api from './api.js';
|
|
|
5
5
|
import { runTar } from './save-deck.js';
|
|
6
6
|
import { normalizeDeckPackageJson } from './normalize.js';
|
|
7
7
|
import { getKitsDir } from './localPaths.js';
|
|
8
|
+
import { SDK_PACKAGE } from './sdkResolve.js';
|
|
8
9
|
import { writePlatformDocs } from './platformDoc.js';
|
|
9
|
-
import { ensureVisibleGlob, IMPORTS_DIR, STARTER_THEME_FILES, readCastleJson as tryReadCastleJson, readCastleJsonOrThrow as readCastleJson, } from './castleJson.js';
|
|
10
|
+
import { ensureVisibleGlob, IMPORTS_DIR, IMPORT_VERSION_FILE, STARTER_THEME_FILES, readCastleJson as tryReadCastleJson, readCastleJsonOrThrow as readCastleJson, } from './castleJson.js';
|
|
10
11
|
// Adding another deck as a dependency (`castle-web add-import`; removing one is a
|
|
11
12
|
// later command). Deliberately NOT `get-deck`: that one
|
|
12
13
|
// replaces THIS deck's own source from the server (and carries guards for the
|
|
@@ -25,7 +26,31 @@ import { ensureVisibleGlob, IMPORTS_DIR, STARTER_THEME_FILES, readCastleJson as
|
|
|
25
26
|
// dependency, and the files are re-fetchable from them -- same treatment
|
|
26
27
|
// node_modules gets. That also means `get-deck` leaves an existing `imports/`
|
|
27
28
|
// alone when it refreshes a deck.
|
|
28
|
-
export { IMPORTS_DIR };
|
|
29
|
+
export { IMPORTS_DIR, IMPORT_VERSION_FILE };
|
|
30
|
+
// The marker (IMPORT_VERSION_FILE, see castleJson.ts) stays with the placed
|
|
31
|
+
// files so their provenance can be checked. The separate .castle-import-pin.json
|
|
32
|
+
// remains backup-only rollback state and is removed when that backup is restored.
|
|
33
|
+
export function writeImportVersion(importDir, value) {
|
|
34
|
+
fs.writeFileSync(path.join(importDir, IMPORT_VERSION_FILE), JSON.stringify(value, null, 2) + '\n', 'utf-8');
|
|
35
|
+
}
|
|
36
|
+
export function readImportVersion(deckDir, alias) {
|
|
37
|
+
try {
|
|
38
|
+
const value = JSON.parse(fs.readFileSync(path.join(deckDir, IMPORTS_DIR, alias, IMPORT_VERSION_FILE), 'utf-8'));
|
|
39
|
+
return typeof value.deckId === 'string' && typeof value.version === 'string'
|
|
40
|
+
? { deckId: value.deckId, version: value.version }
|
|
41
|
+
: null;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// A match proves the files on disk are the ones the pin names -- same deck, same
|
|
48
|
+
// version. No marker, or one that disagrees, proves nothing about them, so the
|
|
49
|
+
// only way to be sure of what is there is to fetch it again.
|
|
50
|
+
function importFilesMatchPin(deckDir, alias, pin) {
|
|
51
|
+
const recorded = readImportVersion(deckDir, alias);
|
|
52
|
+
return !!pin.deckId && recorded?.deckId === pin.deckId && recorded?.version === pin.version;
|
|
53
|
+
}
|
|
29
54
|
export class ImportError extends Error {
|
|
30
55
|
code;
|
|
31
56
|
constructor(code, message) {
|
|
@@ -226,6 +251,11 @@ export function syncImportDependencies(deckDir) {
|
|
|
226
251
|
continue; // an import without a package.json declares nothing
|
|
227
252
|
}
|
|
228
253
|
for (const [name, range] of Object.entries(importPkg.dependencies ?? {})) {
|
|
254
|
+
// The SDK is a file of the base kit every deck imports, resolved by
|
|
255
|
+
// sdkResolve. A kit declaration is either a devDependency for its own
|
|
256
|
+
// check or a mistake, and neither belongs in the deck.
|
|
257
|
+
if (name === SDK_PACKAGE)
|
|
258
|
+
continue;
|
|
229
259
|
if (deps[name] !== undefined)
|
|
230
260
|
continue;
|
|
231
261
|
deps[name] = range;
|
|
@@ -260,6 +290,11 @@ export async function restoreMissingImports(deckDir) {
|
|
|
260
290
|
continue;
|
|
261
291
|
}
|
|
262
292
|
await fetchDeckSourceInto(source.archiveUrl, destDir);
|
|
293
|
+
// The server only serves its latest archive, so what landed here is
|
|
294
|
+
// `source.updatedAt`, not necessarily what the pin says. Record the
|
|
295
|
+
// truth: the pin stays as committed, and publish-kits compares the two
|
|
296
|
+
// to refuse bundling against files no pin describes.
|
|
297
|
+
writeImportVersion(destDir, { deckId: pin.deckId, version: source.updatedAt });
|
|
263
298
|
}
|
|
264
299
|
else if (pin?.source === 'builtin') {
|
|
265
300
|
// Scaffolded from the kit shipped with the CLI: the same copy is still
|
|
@@ -353,10 +388,13 @@ export async function importStatuses(deckDir) {
|
|
|
353
388
|
const source = await api.webDeckSource(pin.deckId).catch(() => null);
|
|
354
389
|
if (!source)
|
|
355
390
|
return base;
|
|
391
|
+
// Files that can't prove they are the pinned version are an update too,
|
|
392
|
+
// even at the same version: refetching is how such a tree gets a marker,
|
|
393
|
+
// and until it has one the deck can't be published.
|
|
356
394
|
return {
|
|
357
395
|
...base,
|
|
358
396
|
latest: source.updatedAt,
|
|
359
|
-
updateAvailable: source.updatedAt !== pin.version,
|
|
397
|
+
updateAvailable: source.updatedAt !== pin.version || !importFilesMatchPin(deckDir, alias, pin),
|
|
360
398
|
};
|
|
361
399
|
}));
|
|
362
400
|
statusCache.set(deckDir, { at: Date.now(), value });
|
|
@@ -408,6 +446,7 @@ async function placeImport(deckDir, alias, deckId, source, via) {
|
|
|
408
446
|
if (replaced)
|
|
409
447
|
backupImport(deckDir, alias);
|
|
410
448
|
await fetchDeckSourceInto(source.archiveUrl, destDir);
|
|
449
|
+
writeImportVersion(destDir, { deckId, version: source.updatedAt });
|
|
411
450
|
lockImportTree(destDir);
|
|
412
451
|
clearStatusCache(deckDir);
|
|
413
452
|
writeImportPin(deckDir, alias, {
|
|
@@ -716,7 +755,12 @@ export async function autoUpdateImports(deckDir) {
|
|
|
716
755
|
if (!(await importIsOnTrustedAccount(pin.deckId)))
|
|
717
756
|
continue;
|
|
718
757
|
const source = await api.webDeckSource(pin.deckId);
|
|
719
|
-
if (!source
|
|
758
|
+
if (!source)
|
|
759
|
+
continue;
|
|
760
|
+
// A pin moved without the files -- get-deck replaces castle.json and
|
|
761
|
+
// leaves `imports/` alone -- leaves the tree stale at what looks like the
|
|
762
|
+
// current version, so a marker that doesn't match is reason to refetch.
|
|
763
|
+
if (source.updatedAt === pin.version && importFilesMatchPin(deckDir, alias, pin))
|
|
720
764
|
continue;
|
|
721
765
|
await applyImportUpdate(deckDir, alias, { deckId: pin.deckId, from: pin.version, via: pin.via }, source, (message) => console.log(`auto-update: ${message}`));
|
|
722
766
|
updated.push({ alias, from: pin.version, to: source.updatedAt });
|
|
@@ -774,12 +818,19 @@ export async function updateImport(dir, options = {}) {
|
|
|
774
818
|
console.warn(`Could not check "${alias}" (${pin.deckId}); it has no source on the server.`);
|
|
775
819
|
continue;
|
|
776
820
|
}
|
|
777
|
-
|
|
821
|
+
// Up to date means the pin is current AND the files on disk say they are
|
|
822
|
+
// that version. A tree placed before markers existed, or left behind by a
|
|
823
|
+
// pull that moved the pin, has no way to prove what it is, so it is
|
|
824
|
+
// refetched even when the pin needs no change -- that is how such a tree
|
|
825
|
+
// ever gets a marker, and what publish-kits sends people here for.
|
|
826
|
+
if (source.updatedAt === pin.version && importFilesMatchPin(deckDir, alias, pin)) {
|
|
778
827
|
console.log(`${alias} is up to date.`);
|
|
779
828
|
continue;
|
|
780
829
|
}
|
|
781
830
|
if (options.check) {
|
|
782
|
-
console.log(
|
|
831
|
+
console.log(source.updatedAt === pin.version
|
|
832
|
+
? `${alias}: the files on disk do not record version ${pin.version}; an update refetches them`
|
|
833
|
+
: `${alias}: update available (have ${pin.version}, latest ${source.updatedAt})`);
|
|
783
834
|
changed = true;
|
|
784
835
|
continue;
|
|
785
836
|
}
|
|
@@ -812,10 +863,16 @@ function revertImport(deckDir, alias) {
|
|
|
812
863
|
fs.rmSync(destDir, { recursive: true, force: true });
|
|
813
864
|
}
|
|
814
865
|
fs.cpSync(backup, destDir, { recursive: true, verbatimSymlinks: true });
|
|
866
|
+
// The backup carries the old version marker with the old files. Restoring its
|
|
867
|
+
// saved pin below therefore puts both records back on the same version. A
|
|
868
|
+
// backup taken before markers existed carries no marker, and nothing here can
|
|
869
|
+
// supply one: the saved pin says what the deck believed, not what these files
|
|
870
|
+
// are, so writing it would invent provenance the publish guard then trusts.
|
|
815
871
|
const pinFile = path.join(destDir, '.castle-import-pin.json');
|
|
816
872
|
if (fs.existsSync(pinFile)) {
|
|
817
873
|
try {
|
|
818
|
-
|
|
874
|
+
const saved = JSON.parse(fs.readFileSync(pinFile, 'utf-8'));
|
|
875
|
+
writeImportPin(deckDir, alias, saved);
|
|
819
876
|
}
|
|
820
877
|
catch {
|
|
821
878
|
/* an unreadable pin file just means the version stays as recorded */
|
|
@@ -827,4 +884,7 @@ function revertImport(deckDir, alias) {
|
|
|
827
884
|
lockImportTree(destDir);
|
|
828
885
|
clearStatusCache(deckDir);
|
|
829
886
|
console.log(`Reverted ${alias} to its previous version.`);
|
|
887
|
+
if (!fs.existsSync(path.join(destDir, IMPORT_VERSION_FILE))) {
|
|
888
|
+
console.log(`That copy predates version records; run \`castle-web update-import ${alias}\` to refetch it before it can be published.`);
|
|
889
|
+
}
|
|
830
890
|
}
|
package/dist/init.js
CHANGED
|
@@ -3,9 +3,10 @@ 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, } from './imports.js';
|
|
6
|
+
import { addImportTo, IMPORTS_DIR, lockImportTree, restoreMissingImports, syncImportDependencies, writeImportVersion, } from './imports.js';
|
|
7
7
|
import { discardParentSource, fetchParentSource, unpackParentSource, writeRemixIdentity, } from './remix.js';
|
|
8
8
|
import { getCliEntryPath, getKitsDir, getSdkPackagePath, toPosixPath } from './localPaths.js';
|
|
9
|
+
import { SDK_PACKAGE } from './sdkResolve.js';
|
|
9
10
|
import { serve } from './serve.js';
|
|
10
11
|
import { createVersion } from './versions.js';
|
|
11
12
|
// Default kit imported by `init` when no --kit is given. `none`/`bare` skips the
|
|
@@ -480,7 +481,11 @@ function copyKitImport(projectDir, kitDir, kit, alias, pins, copied) {
|
|
|
480
481
|
filter: (src) => src === kitDir || (src !== nestedImports && !KIT_COPY_EXCLUDE.has(path.basename(src))),
|
|
481
482
|
});
|
|
482
483
|
const kitConfig = readJsonFile(path.join(kitDir, 'castle.json')) ?? {};
|
|
483
|
-
|
|
484
|
+
const pin = makeKitPin(kitConfig, kit);
|
|
485
|
+
pins[alias] = pin;
|
|
486
|
+
if (typeof pin.deckId === 'string') {
|
|
487
|
+
writeImportVersion(importDir, { deckId: pin.deckId, version: pin.version });
|
|
488
|
+
}
|
|
484
489
|
const kitPins = (kitConfig.imports ?? {});
|
|
485
490
|
for (const [depAlias, depPin] of Object.entries(kitPins)) {
|
|
486
491
|
if (copied.has(depAlias) || pins[depAlias])
|
|
@@ -550,6 +555,11 @@ function scaffoldFromKitImport(kit, projectDir) {
|
|
|
550
555
|
for (const depKitDir of copied.values()) {
|
|
551
556
|
const depPkg = readJsonFile(path.join(depKitDir, 'package.json')) ?? {};
|
|
552
557
|
for (const [name, range] of Object.entries(depPkg.dependencies ?? {})) {
|
|
558
|
+
// The SDK is a file of the base kit every deck imports, resolved by
|
|
559
|
+
// sdkResolve. A kit declaration is either a devDependency for its own
|
|
560
|
+
// check or a mistake, and neither belongs in the deck.
|
|
561
|
+
if (name === SDK_PACKAGE)
|
|
562
|
+
continue;
|
|
553
563
|
if (dependencies[name] !== undefined)
|
|
554
564
|
continue;
|
|
555
565
|
dependencies[name] = String(range);
|