castle-web-cli 0.4.164 → 0.4.166

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.
Files changed (87) hide show
  1. package/dist/agent-prompts.d.ts +3 -0
  2. package/dist/agent-prompts.js +15 -7
  3. package/dist/agent.js +14 -1
  4. package/dist/castle-host/host.js +276 -0
  5. package/dist/devSessionChild.js +66 -1
  6. package/dist/devSessionServer.js +21 -2
  7. package/dist/devSessionStorage.d.ts +9 -0
  8. package/dist/devSessionStorage.js +139 -0
  9. package/dist/forks.js +1 -1
  10. package/dist/ide.d.ts +0 -2
  11. package/dist/ide.js +1 -7
  12. package/dist/imports.js +5 -0
  13. package/dist/init.js +1 -1
  14. package/dist/platformDoc.js +14 -2
  15. package/dist/rawData.d.ts +2 -0
  16. package/dist/rawData.js +10 -0
  17. package/dist/serve.js +98 -0
  18. package/dist/shell/assets/{index-QtCau5vM.js → index-CG9TrvCm.js} +1 -1
  19. package/dist/shell/index.html +1 -1
  20. package/kits/base/CLAUDE.md +1 -1
  21. package/kits/base/castle.json +1 -1
  22. package/kits/base/node_modules/.package-lock.json +28 -0
  23. package/kits/base/node_modules/castle-web-fonts/README.md +114 -0
  24. package/kits/base/node_modules/castle-web-fonts/dist/catalog.d.ts +18 -0
  25. package/kits/base/node_modules/castle-web-fonts/dist/catalog.js +142 -0
  26. package/kits/base/node_modules/castle-web-fonts/dist/face.d.ts +1 -0
  27. package/kits/base/node_modules/castle-web-fonts/dist/face.js +52 -0
  28. package/kits/base/node_modules/castle-web-fonts/dist/faces/Bore.d.ts +3 -0
  29. package/kits/base/node_modules/castle-web-fonts/dist/faces/Bore.js +10 -0
  30. package/kits/base/node_modules/castle-web-fonts/dist/faces/CourierPrime.d.ts +3 -0
  31. package/kits/base/node_modules/castle-web-fonts/dist/faces/CourierPrime.js +10 -0
  32. package/kits/base/node_modules/castle-web-fonts/dist/faces/DMSans.d.ts +3 -0
  33. package/kits/base/node_modules/castle-web-fonts/dist/faces/DMSans.js +10 -0
  34. package/kits/base/node_modules/castle-web-fonts/dist/faces/Glacier.d.ts +3 -0
  35. package/kits/base/node_modules/castle-web-fonts/dist/faces/Glacier.js +10 -0
  36. package/kits/base/node_modules/castle-web-fonts/dist/faces/HelicoCentrica.d.ts +3 -0
  37. package/kits/base/node_modules/castle-web-fonts/dist/faces/HelicoCentrica.js +10 -0
  38. package/kits/base/node_modules/castle-web-fonts/dist/faces/Piazzolla.d.ts +3 -0
  39. package/kits/base/node_modules/castle-web-fonts/dist/faces/Piazzolla.js +10 -0
  40. package/kits/base/node_modules/castle-web-fonts/dist/faces/Synco.d.ts +3 -0
  41. package/kits/base/node_modules/castle-web-fonts/dist/faces/Synco.js +10 -0
  42. package/kits/base/node_modules/castle-web-fonts/dist/faces/Tektur.d.ts +3 -0
  43. package/kits/base/node_modules/castle-web-fonts/dist/faces/Tektur.js +10 -0
  44. package/kits/base/node_modules/castle-web-fonts/dist/faces/YatraOne.d.ts +3 -0
  45. package/kits/base/node_modules/castle-web-fonts/dist/faces/YatraOne.js +10 -0
  46. package/kits/base/node_modules/castle-web-fonts/dist/index.d.ts +16 -0
  47. package/kits/base/node_modules/castle-web-fonts/dist/index.js +15 -0
  48. package/kits/base/node_modules/castle-web-fonts/licenses/CC-BY-ND-4.0.txt +393 -0
  49. package/kits/base/node_modules/castle-web-fonts/licenses/FONTS.md +64 -0
  50. package/kits/base/node_modules/castle-web-fonts/licenses/OFL-1.1.txt +95 -0
  51. package/kits/base/node_modules/castle-web-fonts/package.json +47 -0
  52. package/kits/base/node_modules/castle-web-fonts/woff2/Bore.woff2 +0 -0
  53. package/kits/base/node_modules/castle-web-fonts/woff2/CourierPrime.woff2 +0 -0
  54. package/kits/base/node_modules/castle-web-fonts/woff2/DMSans.woff2 +0 -0
  55. package/kits/base/node_modules/castle-web-fonts/woff2/Glacier.woff2 +0 -0
  56. package/kits/base/node_modules/castle-web-fonts/woff2/HelicoCentrica.woff2 +0 -0
  57. package/kits/base/node_modules/castle-web-fonts/woff2/Piazzolla.woff2 +0 -0
  58. package/kits/base/node_modules/castle-web-fonts/woff2/SOURCE.txt +2 -0
  59. package/kits/base/node_modules/castle-web-fonts/woff2/Synco.woff2 +0 -0
  60. package/kits/base/node_modules/castle-web-fonts/woff2/Tektur.woff2 +0 -0
  61. package/kits/base/node_modules/castle-web-fonts/woff2/YatraOne.woff2 +0 -0
  62. package/kits/base/package-lock.json +1 -1
  63. package/kits/base/sdk/README.md +181 -36
  64. package/kits/base/sdk/castle.d.ts +2 -0
  65. package/kits/base/sdk/castle.js +1 -0
  66. package/kits/base/sdk/chunk.d.ts +1 -0
  67. package/kits/base/sdk/chunk.js +15 -0
  68. package/kits/base/sdk/commands.d.ts +86 -0
  69. package/kits/base/sdk/runtime.js +21 -12
  70. package/kits/base/sdk/server/platformHandle.d.ts +10 -0
  71. package/kits/base/sdk/server/storage.d.ts +46 -0
  72. package/kits/base/sdk/server/storage.js +218 -0
  73. package/kits/base/sdk/server/wrapper.d.ts +14 -1
  74. package/kits/base/sdk/server/wrapper.js +4 -1
  75. package/kits/base/sdk/storage.d.ts +15 -0
  76. package/kits/base/sdk/storage.js +29 -86
  77. package/kits/base/sdk/storageJson.d.ts +5 -0
  78. package/kits/base/sdk/storageJson.js +69 -0
  79. package/kits/base/sdk/store.d.ts +67 -0
  80. package/kits/base/sdk/store.js +313 -0
  81. package/kits/base/sdk/unloadFlush.d.ts +3 -0
  82. package/kits/base/sdk/unloadFlush.js +30 -0
  83. package/kits/physics-2d/castle.json +1 -1
  84. package/kits/physics-2d/editors/SceneEditor.jsx +2 -1
  85. package/kits/physics-2d/engine/blueprint.js +29 -28
  86. package/kits/physics-2d/package-lock.json +1 -6
  87. package/package.json +1 -1
@@ -0,0 +1,313 @@
1
+ import { chunked } from "./chunk";
2
+ import { decodeStorageValue, encodeStorageValue, storageError } from "./storageJson";
3
+ import { hostRequest } from "./transport";
4
+ import { onUnloadFlush } from "./unloadFlush";
5
+ // Per-key deck storage for Cauldron decks.
6
+ //
7
+ // The older Storage/SharedStorage keep one document per bucket and rewrite the
8
+ // whole thing on every change, which loses concurrent writes and stops at 2 MB.
9
+ // This keeps one row per key instead: two players writing different keys no
10
+ // longer overwrite each other, a counter can be incremented atomically, and a
11
+ // deck can hold far more than one document's worth and read back a slice of it.
12
+ //
13
+ // Every operation here is a bounded request. A deck never supplies a filter or
14
+ // an ordering, which is what lets the platform promise that no deck can make the
15
+ // database do expensive work.
16
+ // Writes coalesce by key for this long before being sent, so a deck that saves
17
+ // on every change costs one request per burst rather than one per change.
18
+ const FLUSH_INTERVAL_MS = 200;
19
+ // The platform takes at most this many keys per call. A buffer that coalesced
20
+ // past it goes out as several requests rather than as one the server rejects,
21
+ // so a deck that saves many small keys in a burst never has to know the limit.
22
+ const MAX_KEYS_PER_REQUEST = 32;
23
+ const buckets = new Map();
24
+ function bucketKey(scope, subject) {
25
+ return `${scope}|${subject ?? "self"}`;
26
+ }
27
+ function pendingBucket(scope, subject) {
28
+ const id = bucketKey(scope, subject);
29
+ let bucket = buckets.get(id);
30
+ if (!bucket) {
31
+ bucket = {
32
+ scope,
33
+ subject,
34
+ values: new Map(),
35
+ waiters: [],
36
+ timer: null,
37
+ inFlight: Promise.resolve(),
38
+ pending: 0,
39
+ };
40
+ buckets.set(id, bucket);
41
+ }
42
+ return bucket;
43
+ }
44
+ function queueWrite(scope, subject, values, unload = false) {
45
+ const bucket = pendingBucket(scope, subject);
46
+ for (const [key, value] of values)
47
+ bucket.values.set(key, value);
48
+ const settled = new Promise((resolve, reject) => {
49
+ bucket.waiters.push({ keys: Array.from(values.keys()), resolve, reject });
50
+ });
51
+ // A stable reference, so registering on every write leaves one handler.
52
+ onUnloadFlush(flushAllNow);
53
+ if (unload) {
54
+ void flushBucket(bucket, true);
55
+ }
56
+ else if (!bucket.timer) {
57
+ bucket.timer = setTimeout(() => {
58
+ bucket.timer = null;
59
+ void flushBucket(bucket, false);
60
+ }, FLUSH_INTERVAL_MS);
61
+ }
62
+ return settled;
63
+ }
64
+ // Never rejects: a failed request is reported to the waiters whose keys it
65
+ // carried, which is what the deck is holding. Callers can `void` it safely.
66
+ function flushBucket(bucket, unload) {
67
+ bucket.pending += 1;
68
+ // An unload flush does not wait its turn. Queueing it behind a request that
69
+ // may not come back before the frame does would lose the last save outright,
70
+ // and the host finishes an `unload` write with fetch keepalive, so what
71
+ // matters is that the message reaches it at all. The cost is that this one
72
+ // write can race the request already in flight: if they touch the same key
73
+ // and land out of order, the older value stays stored. Ordering that
74
+ // correctly needs a revision token the server checks, which does not exist
75
+ // yet -- a stale key beats a lost one until it does.
76
+ const run = unload
77
+ ? guarded(sendBucket(bucket, true))
78
+ : guarded(bucket.inFlight.then(() => sendBucket(bucket, false)));
79
+ // Later flushes queue behind this one either way, so only the unload write
80
+ // itself skips the queue. Counting it in `pending` matters as much: a bucket
81
+ // dropped while its request is still out would let the next write build a
82
+ // second bucket for the same scope, and the two would flush concurrently.
83
+ bucket.inFlight = Promise.all([bucket.inFlight, run]).then(() => {
84
+ bucket.pending -= 1;
85
+ pruneBucket(bucket);
86
+ });
87
+ return run;
88
+ }
89
+ // A rejection must never reach `inFlight`. The chain is built with `then`, so a
90
+ // rejected link makes every later flush for this bucket skip its send and
91
+ // reject in turn: the scope stops writing, permanently and silently. Failed
92
+ // requests are already reported to their waiters, so anything arriving here is
93
+ // a bug in this file rather than a write that did not land.
94
+ function guarded(run) {
95
+ return run.catch(reportWriteError);
96
+ }
97
+ function reportWriteError(error) {
98
+ console.warn("Castle store flush failed unexpectedly", error);
99
+ }
100
+ async function sendBucket(bucket, unload) {
101
+ // Take the buffer before awaiting: writes made while this request is in flight
102
+ // belong to the next one, not to this one's waiters.
103
+ const values = bucket.values;
104
+ const waiters = bucket.waiters;
105
+ bucket.values = new Map();
106
+ bucket.waiters = [];
107
+ if (bucket.timer) {
108
+ clearTimeout(bucket.timer);
109
+ bucket.timer = null;
110
+ }
111
+ if (values.size === 0 && waiters.length === 0)
112
+ return;
113
+ const entries = [];
114
+ const removals = [];
115
+ for (const [key, value] of values) {
116
+ if (value === null)
117
+ removals.push(key);
118
+ else
119
+ entries.push({ key, value });
120
+ }
121
+ // Which keys failed to store, and why. Set and delete never share a key here:
122
+ // a key written and then removed inside one window is a single null in
123
+ // `values`, so the two lists are disjoint and their outcomes independent.
124
+ const failures = new Map();
125
+ // Anything escaping the per-request catch is a bug, not a write that failed.
126
+ // It still has to reach the waiters: an unsettled one is a deck awaiting a
127
+ // promise that will never resolve.
128
+ let unexpected = null;
129
+ try {
130
+ for (const request of buildRequests(bucket, entries, removals, unload)) {
131
+ try {
132
+ await request.send();
133
+ }
134
+ catch (error) {
135
+ for (const key of request.keys)
136
+ failures.set(key, error);
137
+ }
138
+ }
139
+ }
140
+ catch (error) {
141
+ unexpected = error;
142
+ }
143
+ for (const waiter of waiters) {
144
+ if (unexpected !== null) {
145
+ waiter.reject(unexpected);
146
+ continue;
147
+ }
148
+ // `find`, not `some`: the first failing key supplies the error the deck sees.
149
+ const failed = waiter.keys.find((key) => failures.has(key));
150
+ // A caller that contributed no keys -- `set({})`, `remove([])` -- has nothing
151
+ // that can fail, and must still be settled rather than left hanging.
152
+ if (failed === undefined)
153
+ waiter.resolve();
154
+ else
155
+ waiter.reject(failures.get(failed));
156
+ }
157
+ }
158
+ function buildRequests(bucket, entries, removals, unload) {
159
+ const requests = [];
160
+ // Removals go first: within one window a key that was set and then removed
161
+ // should end up removed, and sending the set afterwards would resurrect it.
162
+ for (const keys of chunked(removals, MAX_KEYS_PER_REQUEST)) {
163
+ requests.push({
164
+ keys,
165
+ send: () => hostRequest("cauldronStorage.delete", {
166
+ scope: bucket.scope,
167
+ subject: bucket.subject,
168
+ keys,
169
+ unload,
170
+ }),
171
+ });
172
+ }
173
+ for (const chunk of chunked(entries, MAX_KEYS_PER_REQUEST)) {
174
+ requests.push({
175
+ keys: chunk.map((entry) => entry.key),
176
+ send: () => hostRequest("cauldronStorage.set", {
177
+ scope: bucket.scope,
178
+ subject: bucket.subject,
179
+ entries: chunk,
180
+ unload,
181
+ }),
182
+ });
183
+ }
184
+ return requests;
185
+ }
186
+ // A deck that reads many players' buckets would otherwise leave one empty entry
187
+ // per user id behind for the life of the page.
188
+ function pruneBucket(bucket) {
189
+ if (bucket.pending > 0 ||
190
+ bucket.values.size > 0 ||
191
+ bucket.waiters.length > 0 ||
192
+ bucket.timer) {
193
+ return;
194
+ }
195
+ const id = bucketKey(bucket.scope, bucket.subject);
196
+ if (buckets.get(id) === bucket)
197
+ buckets.delete(id);
198
+ }
199
+ function flushAllNow() {
200
+ for (const bucket of buckets.values()) {
201
+ // Nothing awaits these: the page is going away. The host is what finishes
202
+ // the request, and it outlives the deck's frame.
203
+ void flushBucket(bucket, true);
204
+ }
205
+ }
206
+ // ---------------------------------------------------------------------------
207
+ function assertKeys(keys, operation) {
208
+ if (!Array.isArray(keys) || keys.some((key) => typeof key !== "string")) {
209
+ throw storageError("CASTLE_STORE_INVALID_KEYS", "Store keys must be an array of strings.", operation);
210
+ }
211
+ return keys;
212
+ }
213
+ function createScope(scope, subject) {
214
+ return {
215
+ async get(keys) {
216
+ const { entries } = await hostRequest("cauldronStorage.get", {
217
+ scope,
218
+ subject,
219
+ keys: assertKeys(keys, "Store.get"),
220
+ });
221
+ const result = {};
222
+ for (const entry of entries) {
223
+ // defineProperty rather than assignment: a stored key named "__proto__"
224
+ // would otherwise reach the prototype setter instead of becoming an own
225
+ // property, corrupting the object handed back to the deck.
226
+ Object.defineProperty(result, entry.key, {
227
+ value: decodeStorageValue(entry.value, "Store.get"),
228
+ writable: true,
229
+ enumerable: true,
230
+ configurable: true,
231
+ });
232
+ }
233
+ return result;
234
+ },
235
+ set(values) {
236
+ const pending = new Map();
237
+ for (const [key, value] of Object.entries(values)) {
238
+ pending.set(key, encodeStorageValue(value, "Store.set"));
239
+ }
240
+ return queueWrite(scope, subject, pending);
241
+ },
242
+ remove(keys) {
243
+ const pending = new Map();
244
+ for (const key of assertKeys(keys, "Store.remove"))
245
+ pending.set(key, null);
246
+ return queueWrite(scope, subject, pending);
247
+ },
248
+ async increment(key, delta = 1) {
249
+ // Not coalesced. Merging increments locally would mean reporting a total
250
+ // the server has not agreed to, and the point of this verb is that the
251
+ // server is the one doing the adding.
252
+ const { value } = await hostRequest("cauldronStorage.increment", {
253
+ scope,
254
+ subject,
255
+ key,
256
+ delta,
257
+ });
258
+ return Number(value);
259
+ },
260
+ async list(options = {}) {
261
+ const { entries, cursor } = await hostRequest("cauldronStorage.list", {
262
+ scope,
263
+ subject,
264
+ prefix: options.prefix ?? null,
265
+ limit: options.limit ?? null,
266
+ cursor: options.cursor ?? null,
267
+ });
268
+ return {
269
+ entries: entries.map((entry) => ({
270
+ key: entry.key,
271
+ value: decodeStorageValue(entry.value, "Store.list"),
272
+ })),
273
+ cursor,
274
+ };
275
+ },
276
+ };
277
+ }
278
+ function createBoard(name) {
279
+ return {
280
+ async submit(score) {
281
+ const { entry } = await hostRequest("cauldronStorage.boardSubmit", {
282
+ board: name,
283
+ score,
284
+ });
285
+ return entry;
286
+ },
287
+ async top(limit) {
288
+ const { entries } = await hostRequest("cauldronStorage.boardTop", {
289
+ board: name,
290
+ limit: limit ?? null,
291
+ });
292
+ return entries;
293
+ },
294
+ async get(userId) {
295
+ const { entry } = await hostRequest("cauldronStorage.boardGet", {
296
+ board: name,
297
+ subject: userId ?? null,
298
+ });
299
+ return entry;
300
+ },
301
+ };
302
+ }
303
+ export const Store = {
304
+ deck: createScope("deck", null),
305
+ me: createScope("user", null),
306
+ user(userId) {
307
+ return createScope("user", userId);
308
+ },
309
+ private: createScope("private", null),
310
+ board(name) {
311
+ return createBoard(name);
312
+ },
313
+ };
@@ -0,0 +1,3 @@
1
+ type FlushHandler = () => void;
2
+ export declare function onUnloadFlush(handler: FlushHandler): void;
3
+ export {};
@@ -0,0 +1,30 @@
1
+ // Somewhere to hang "flush before the page goes away".
2
+ //
3
+ // Writes batch on a timer, so leaving the page inside that window would lose
4
+ // them, and a deck saving progress as someone quits is exactly when it matters.
5
+ // `pagehide` is the reliable signal on iOS, where unload often never fires, and
6
+ // visibilitychange covers backgrounding without a navigation.
7
+ //
8
+ // Listeners are registered on the first write, so a deck that never stores
9
+ // anything hooks nothing.
10
+ //
11
+ // Handlers are held in a Set, so registering on every write is fine as long as
12
+ // the caller passes a STABLE function reference. A fresh closure per call would
13
+ // accumulate, and every one of them would run at unload.
14
+ const handlers = new Set();
15
+ let hooked = false;
16
+ export function onUnloadFlush(handler) {
17
+ handlers.add(handler);
18
+ if (hooked || typeof window === "undefined")
19
+ return;
20
+ hooked = true;
21
+ const flushAll = () => {
22
+ for (const flush of handlers)
23
+ flush();
24
+ };
25
+ window.addEventListener("pagehide", flushAll);
26
+ document.addEventListener("visibilitychange", () => {
27
+ if (document.visibilityState === "hidden")
28
+ flushAll();
29
+ });
30
+ }
@@ -132,7 +132,7 @@
132
132
  "main": "main.jsx",
133
133
  "autoUpdateWhenImported": true,
134
134
  "title": "physics-2d",
135
- "publishedVersion": "2026-09-04T00:11:30.979Z",
135
+ "publishedVersion": "2026-09-04T18:30:34.333Z",
136
136
  "imports": {
137
137
  "castle.base": {
138
138
  "deckId": "yRcmH4_aYllE",
@@ -6,7 +6,8 @@ import * as castleSdk from 'castle-web-sdk';
6
6
  // a kit update keeps whatever SDK it already installed, so these may be absent.
7
7
  // Without openFile, view-source/edit-sprite taps do nothing; without renameFile,
8
8
  // a blueprint rename throws inside its try and keeps the old paths -- degraded,
9
- // not broken.
9
+ // not broken. renameFile rides the local bridge (same as writeFile); an older
10
+ // SDK that only had the HTTP path still fails from a content iframe.
10
11
  const openFile = castleSdk.openFile ?? (() => undefined);
11
12
  const renameFile =
12
13
  castleSdk.renameFile ??
@@ -239,8 +239,10 @@ function humanizeActorId(id) {
239
239
  .join(' ');
240
240
  }
241
241
 
242
- // "Auto Tetris" -> "auto-tetris" for the filename slug. Kept independent of
243
- // the actor id's own formatting (an id could already be any casing/shape).
242
+ // "Auto Tetris" -> "auto-tetris" for an actor id. Kept independent of the
243
+ // display-name filename rule below: ids stay lowercase-hyphen for code refs
244
+ // (`Joints.target`, `getActor`), while blueprint/drawing files keep the
245
+ // creator's casing.
244
246
  function slugifyActorId(id) {
245
247
  return id
246
248
  .trim()
@@ -249,6 +251,18 @@ function slugifyActorId(id) {
249
251
  .replace(/^-+|-+$/g, '');
250
252
  }
251
253
 
254
+ // Display name -> filename stem: keep the creator's capitalization, turn
255
+ // spaces into `_`. "PlayerWrapper" -> "PlayerWrapper", "Player Wrapper" ->
256
+ // "Player_Wrapper". Other punctuation is dropped so the path stays a single
257
+ // segment.
258
+ function filenameFromDisplayName(name) {
259
+ return (typeof name === 'string' ? name : '')
260
+ .trim()
261
+ .replace(/\s+/g, '_')
262
+ .replace(/[^A-Za-z0-9_-]+/g, '')
263
+ .replace(/^_+|_+$/g, '');
264
+ }
265
+
252
266
  // Mint a readable, unique actor id from a display name (a blueprint's `name`):
253
267
  // slugified and slug-suffix-deduped against `existing` (`cauldron`,
254
268
  // `cauldron-2`, ...). This is the editor's placement/creation default, so a
@@ -460,7 +474,6 @@ export function blankPxArtText() {
460
474
 
461
475
  // `.pxart` is the legacy spelling and still reads; new art is `.sprite`.
462
476
  const DRAWING_EXT = '.sprite';
463
- const DRAWING_EXT_RE = '\\.(?:pxart|sprite)';
464
477
 
465
478
  // `drawings/drawing-N.sprite` -- next free numbered slug, so repeated adds don't
466
479
  // collide and a deleted drawing's number isn't reused.
@@ -516,14 +529,19 @@ export function addActorWithBlueprint(sceneData, files) {
516
529
  return { sceneData: next, newId, blueprintFile, drawingFile };
517
530
  }
518
531
 
519
- // `blueprints/wall.scene` from a display name: slugified, then suffix-deduped.
532
+ // `blueprints/Player_Wrapper.scene` from a display name: keep casing, spaces
533
+ // become `_`, then suffix-deduped. Case-insensitive collision check so a macOS
534
+ // default volume doesn't 409 on `Player` vs an existing `player.scene`.
520
535
  function mintPathFromName(existingPaths, name, dir, ext) {
521
- const base = slugifyActorId(typeof name === 'string' ? name : '') || 'blueprint';
536
+ const base = filenameFromDisplayName(name) || 'blueprint';
537
+ const takenLower = new Set(
538
+ [...existingPaths].map((path) => String(path).toLowerCase()),
539
+ );
522
540
  const MAX_ATTEMPTS = 1000;
523
541
  for (let suffix = 1; suffix <= MAX_ATTEMPTS; suffix += 1) {
524
542
  const slug = suffix === 1 ? base : `${base}-${suffix}`;
525
543
  const path = `${dir}/${slug}${ext}`;
526
- if (!existingPaths.has(path)) return path;
544
+ if (!takenLower.has(path.toLowerCase())) return path;
527
545
  }
528
546
  // Callers treat null as "couldn't name it" and fall back to the counter.
529
547
  return null;
@@ -763,26 +781,6 @@ function countSpriteRefs(files, drawingPath) {
763
781
  return count;
764
782
  }
765
783
 
766
- // Is `drawingPath` this blueprint's OWN auto-minted art -- the blank we made
767
- // for it at creation, under either the anonymous counter (`drawing-3.sprite`,
768
- // the zero-prompt path) or the blueprint's own slug (`wall.sprite`, the modal
769
- // pairing a name with its drawing)? Those two shapes are ours to keep in sync
770
- // with the name. A drawing the creator picked from the grid, or drew and named
771
- // themselves, is not: it may be shared, and its name means something to them.
772
- // Both spellings match, so a blueprint made before the `.sprite` rename still
773
- // carries its drawing along.
774
- function isOwnMintedDrawing(drawingPath, blueprintPath) {
775
- if (typeof drawingPath !== 'string') return false;
776
- if (new RegExp(`^${DRAWINGS_DIR}/drawing-\\d+${DRAWING_EXT_RE}$`).test(drawingPath)) return true;
777
- // Compared literally rather than by regex: a hand-authored blueprint path
778
- // can hold characters (`.`, `+`) that would match far too much as a pattern.
779
- const slug = blueprintPath.slice(BLUEPRINTS_DIR.length + 1, -'.scene'.length);
780
- return (
781
- drawingPath === `${DRAWINGS_DIR}/${slug}.sprite` ||
782
- drawingPath === `${DRAWINGS_DIR}/${slug}.pxart`
783
- );
784
- }
785
-
786
784
  // Renaming a blueprint means renaming the FILE, not just editing `name` --
787
785
  // that's the whole complaint. Returns the physical moves and the content
788
786
  // writes to apply (renames first, then writes, so a write never lands on a
@@ -792,7 +790,7 @@ function isOwnMintedDrawing(drawingPath, blueprintPath) {
792
790
  //
793
791
  // or null when the blueprint is missing/unparseable. What moves:
794
792
  // - the blueprint file, to its new name-derived slug
795
- // - its auto-minted drawing, when no other blueprint shares it
793
+ // - its Sprite drawing, when no other blueprint shares it
796
794
  // - every `"blueprint"` ref in every `scenes/*.scene`
797
795
  //
798
796
  // Actor ids are deliberately left alone. They're referenced by `Joints.target`,
@@ -809,7 +807,10 @@ export function renameBlueprintCascade(files, blueprintPath, nextName) {
809
807
  const fileRenames = [];
810
808
  const components = structuredClone(template.components ?? {});
811
809
  const drawingPath = components.Sprite?.file;
812
- if (isOwnMintedDrawing(drawingPath, blueprintPath) && countSpriteRefs(files, drawingPath) === 1) {
810
+ // Exclusive use is enough: if only this blueprint points at the drawing,
811
+ // keep its filename in sync with the new name — whether the art was
812
+ // auto-minted, picked from the grid, or drawn by hand.
813
+ if (typeof drawingPath === 'string' && countSpriteRefs(files, drawingPath) === 1) {
813
814
  taken.delete(drawingPath);
814
815
  // Keep the drawing's OWN extension: a deck made before the `.sprite`
815
816
  // rename holds `.pxart` files, and a rename is no place to migrate a
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "../../sdk": {
35
35
  "name": "castle-web-sdk",
36
- "version": "0.4.23",
36
+ "version": "0.4.26",
37
37
  "dev": true,
38
38
  "devDependencies": {
39
39
  "eslint": "^9.0.0",
@@ -216,7 +216,6 @@
216
216
  "resolved": "https://registry.npmjs.org/@dnd-kit/core/-/core-6.3.1.tgz",
217
217
  "integrity": "sha512-xkGBRQQab4RLwgXxoqETICr6S5JlogafbhNsidmrkVv2YRs5MLwpjoF2qpiGjQt8S9AoxtIV603s0GIUpY5eYQ==",
218
218
  "license": "MIT",
219
- "peer": true,
220
219
  "dependencies": {
221
220
  "@dnd-kit/accessibility": "^3.1.1",
222
221
  "@dnd-kit/utilities": "^3.2.2",
@@ -670,7 +669,6 @@
670
669
  "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==",
671
670
  "dev": true,
672
671
  "license": "MIT",
673
- "peer": true,
674
672
  "bin": {
675
673
  "acorn": "bin/acorn"
676
674
  },
@@ -1131,7 +1129,6 @@
1131
1129
  "integrity": "sha512-XoMjdBOwe/esVgEvLmNsD3IRHkm7fbKIUGvrleloJXUZgDHig2IPWNniv+GwjyJXzuNqVjlr5+4yVUZjycJwfQ==",
1132
1130
  "dev": true,
1133
1131
  "license": "MIT",
1134
- "peer": true,
1135
1132
  "dependencies": {
1136
1133
  "@eslint-community/eslint-utils": "^4.8.0",
1137
1134
  "@eslint-community/regexpp": "^4.12.1",
@@ -2441,7 +2438,6 @@
2441
2438
  "resolved": "https://registry.npmjs.org/react/-/react-19.2.7.tgz",
2442
2439
  "integrity": "sha512-HNe9WslTbXmFK8o8cmwgAeJFSBvt1bPdHCVKtaaV+WlAN36mpT4hcRpwbf3fY56ar2oIXzsBpOAiIRHAdY0OlQ==",
2443
2440
  "license": "MIT",
2444
- "peer": true,
2445
2441
  "engines": {
2446
2442
  "node": ">=0.10.0"
2447
2443
  }
@@ -2451,7 +2447,6 @@
2451
2447
  "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.7.tgz",
2452
2448
  "integrity": "sha512-t0BRVXvbiE/o20Hfw669rLbMCDWtYZLvmJigy2f0MxsXF+71pxhR3xOkspmsO8h3ZlNzyibAmtCa3l4lYKk6gQ==",
2453
2449
  "license": "MIT",
2454
- "peer": true,
2455
2450
  "dependencies": {
2456
2451
  "scheduler": "^0.27.0"
2457
2452
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.164",
3
+ "version": "0.4.166",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "castle-web": "./dist/index.js"