castle-web-cli 0.4.241 → 0.4.243

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.
@@ -118,7 +118,7 @@ ${runningTaskRules}
118
118
  - Never claim the board is cleared without actually emitting the fence.
119
119
  - Tasks are one-and-done -- when the user gives feedback on a finished task, spawn a new fix task (and \`castle-done\` the old row) rather than reopening it -- unless their words ask to go back to an earlier state, which is the version-history rule below.
120
120
  - Task agents are capable coding agents working in this same deck directory, but they know nothing about this conversation beyond your prompt.
121
- - 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 run \`restore-version\` only when the user's own words ask to put the whole deck back to an earlier state ("go back", "revert it", "undo all that"): that decision is theirs, and they have made it. Never restore on your own judgment, because a fix looks wrong, or on "that looks worse" alone; bringing back or undoing one thing inside newer work ("put the leaderboard back", "undo that color") is a targeted fix, as a task, since a restore would take out the rest. While any task is running, do not restore: its edits would land on top of the old version, so say it has to wait until they finish, or offer to stop them first. To restore, read \`list-versions\` (and \`show-version\` where it helps) for the version that matches what they described; when more than one could match, ask which, naming each as a choice, instead of guessing. Then run \`castle-web restore-version <id>\` yourself -- never with \`--force\`, never through a task -- and say which version you restored and which later changes it took out of the deck (they stay in the version history, so the restore can itself be undone). If it refuses or restores nothing (unsaved changes, tasks still running, already at that version), tell them what it said rather than forcing it. No task you spawn may ever revert, replace, or re-scaffold the deck's scenes, scripts, or behaviors back to kit or starter content -- a fix is always a targeted edit, and every task prompt you write has to be readable that way.
121
+ - 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 run \`restore-version\` only when the user's own words ask to put the whole deck back to an earlier state ("go back", "revert it", "undo all that"): that decision is theirs, and they have made it. Never restore on your own judgment, because a fix looks wrong, or on "that looks worse" alone; bringing back or undoing one thing inside newer work ("put the leaderboard back", "undo that color") is a targeted fix, as a task, since a restore would take out the rest. While any task is running, do not restore: its edits would land on top of the old version, so say it has to wait until they finish, or offer to stop them first. To restore, read \`list-versions\` (and \`show-version\` where it helps) for the version that matches what they described; when more than one could match, ask which, naming each as a choice, instead of guessing. Then run \`castle-web restore-version <id>\` yourself -- never with \`--force\`, never through a task -- and say which version you restored and which later changes it took out of the deck (they stay in the version history, so the restore can itself be undone). If it refuses or restores nothing (unsaved changes, tasks still running, already at that version), tell them what it said rather than forcing it. Never edit or delete anything under \`.castle/versions/\` yourself, and never ask a task to: removing versions or their blobs by hand corrupts the history and the cloud stops saving the deck. When the user asks to remove old versions, or the deck is too large to save and old versions are what is big, run \`castle-web prune-versions --keep <n> --dry-run\` yourself, tell them how many versions and how much space it would free, and once they agree run it without \`--dry-run\` (never through a task); if it refuses, tell them what it said. No task you spawn may ever revert, replace, or re-scaffold the deck's scenes, scripts, or behaviors back to kit or starter content -- a fix is always a targeted edit, and every task prompt you write has to be readable that way.
122
122
 
123
123
  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 when their ask is vague ("make me a game" -> ask what kind), NOT to interrogate.
124
124
 
@@ -1274,7 +1274,7 @@ phase: wiring the paddle to touch
1274
1274
  }
1275
1275
  // How a task agent records its work: a version in the deck's own store, or a
1276
1276
  // commit when the deck is on git. The version wording is the prompt's original
1277
- // text, unchanged.
1277
+ // text, plus the rule that only prune-versions shrinks the store.
1278
1278
  function taskSaveWording(git) {
1279
1279
  if (!git) {
1280
1280
  return {
@@ -1282,7 +1282,7 @@ function taskSaveWording(git) {
1282
1282
  rule: '- SAVE A VERSION when your change is done, so the user can see and undo it: `castle-web save-version -m "<short description of what you changed>" <each path you touched>`. Name those paths explicitly -- a bare `save-version` with no paths records the WHOLE deck, including files a sibling agent is still working on. One version for the whole task, at the end; not one per file.',
1283
1283
  listing: '`save-version -m "<message>" <paths...>` -- as above: your own paths, named explicitly, once at the end.',
1284
1284
  before: '- Before any change that overwrites or deletes MORE THAN ONE existing file of theirs, save a version first so they can restore: `castle-web save-version -m "<what is about to change>" <those paths>`. That is on top of the end-of-task version below, not instead of it.',
1285
- store: "(The version store lives there too, but you never edit it by hand -- `castle-web save-version` writes it for you.)",
1285
+ store: "(The version store lives there too, but you never edit or delete it by hand, not even to save space -- `castle-web save-version` writes it for you, and only `castle-web prune-versions` may shrink it.)",
1286
1286
  };
1287
1287
  }
1288
1288
  return {
@@ -1290,7 +1290,7 @@ function taskSaveWording(git) {
1290
1290
  rule: '- COMMIT when your change is done, so the user can see and undo it: `castle-web commit --reason task -m "<short description of what you changed>" <each path you touched>`. Name those paths explicitly -- a bare `commit` with no paths records the WHOLE deck, including files a sibling agent is still working on. One commit for the whole task, at the end; not one per file. It is pushed to the deck\'s git remote for you: never run `git commit`, `git push`, `git reset`, `git rebase` or `git checkout` yourself.',
1291
1291
  listing: '`commit --reason task -m "<message>" <paths...>` -- as above: your own paths, named explicitly, once at the end.',
1292
1292
  before: '- Before any change that overwrites or deletes MORE THAN ONE existing file of theirs, commit them first so they can restore: `castle-web commit --reason task -m "<what is about to change>" <those paths>`. That is on top of the end-of-task commit below, not instead of it.',
1293
- store: "(The deck's history is git, in .git -- you never edit it by hand; `castle-web commit` writes it for you.)",
1293
+ store: "(The deck's history is git, in .git -- you never edit it by hand; `castle-web commit` writes it for you. The older version store in .castle/versions is never edited or deleted by hand either; only `castle-web prune-versions` may shrink it.)",
1294
1294
  };
1295
1295
  }
1296
1296
  // Appended to claude task agents' system prompt (portable replacement for the
package/dist/bundle.d.ts CHANGED
@@ -17,19 +17,27 @@ export interface ExternalMediaAsset {
17
17
  bytes: Buffer;
18
18
  /** The file it came from, relative to the deck where known, for messages. */
19
19
  source: string;
20
+ /** URLs of the assets this one names in its own bytes (a .gltf's buffers and textures). */
21
+ deps?: string[];
20
22
  }
21
23
  export declare class ExternalMedia {
22
24
  private readonly baseUrl;
23
25
  private readonly exclude;
24
26
  private readonly byUrl;
27
+ private readonly inlined;
25
28
  /** `exclude`: sha256s that stay inline (Ghost refused to store them). */
26
29
  constructor(baseUrl?: string, exclude?: ReadonlySet<string>);
27
30
  /** The deck build's two plugins: the loader (ahead of Vite's) and the late swap (ahead of InlineAssets). */
28
31
  plugin(): Plugin[];
29
32
  private loadedUrl;
33
+ private loadedGltf;
34
+ private rewriteGltf;
30
35
  private record;
31
36
  private urlFor;
32
- /** Every asset the finished page names (a module the build dropped names none). */
37
+ /**
38
+ * Every asset the finished page names (a module the build dropped names
39
+ * none), and each one those name in turn (a .gltf's buffers and textures).
40
+ */
33
41
  assetsIn(html: string): ExternalMediaAsset[];
34
42
  }
35
43
  export declare class InlineAssets {
package/dist/bundle.js CHANGED
@@ -44,12 +44,13 @@ const INLINE_ASSET_MIN_PAYLOAD = 1024;
44
44
  */
45
45
  const INLINE_ASSET_MAX_CHECKED_CODE = 10 * 1024 * 1024;
46
46
  // ---------------------------------------------------------------------------
47
- // Audio and video served by URL, on save.
47
+ // Audio, video, images and 3D models served by URL, on save.
48
48
  //
49
49
  // Inlining keeps a published deck one file, but a 30 MB .wav inlines to 40 MB
50
50
  // of base64, past Ghost's 50 MB scene cap with little else in the deck, and
51
51
  // rolldown holds that 40 MB string many times over (the 30 MB deck peaked at
52
- // 1.35 GB). So when save-deck asks, each audio or video file of
52
+ // 1.35 GB). So when save-deck asks, each audio, video, image (png, jpg, webp,
53
+ // gif) or 3D model (glb, gltf) file of
53
54
  // EXTERNAL_MEDIA_MIN_BYTES or more that Vite would inline is named by its URL
54
55
  // on Castle's CDN instead (`https://hosted.castle.games/cauldron-assets/
55
56
  // <sha256>.<ext>`, immutable, which save-deck stores before it publishes the
@@ -58,13 +59,24 @@ const INLINE_ASSET_MAX_CHECKED_CODE = 10 * 1024 * 1024;
58
59
  // Where InlineAssets swaps a payload for a stand-in that has to come back, the
59
60
  // URL here is the literal's true final value: the minifier may fold, alias or
60
61
  // compare it as it likes, so there is nothing to check. What changes is the
61
- // value itself. A deck that plays it (`new Audio(url)`, `video.src = url`,
62
- // `fetch(url)` then `decodeAudioData`) never notices; a deck that reads the
63
- // bytes out of the data: URI string itself would break. That is why this is
64
- // media only (the one kind a deck hands to a loader rather than inspects),
65
- // save only (the serve and `check` keep the data: URI), and only for the MIME
66
- // types Ghost stores. A Ghost that refuses a type (video, before it stores
67
- // video) or a file keeps that file inline; the save goes on.
62
+ // value itself. A deck that plays or loads it (`new Audio(url)`,
63
+ // `video.src = url`, `img.src = url`, a texture or glTF loader, `fetch(url)`)
64
+ // never notices; a deck that reads the bytes out of the data: URI string
65
+ // itself would break. That is why this is files a deck hands to a loader
66
+ // rather than inspects (never SVG, which decks also inline as markup), save
67
+ // only (the serve and `check` keep the data: URI), and only for the MIME types
68
+ // Ghost stores. A Ghost that refuses a type (images and models, before it
69
+ // stores them) or a file keeps that file inline; the save goes on.
70
+ //
71
+ // A .gltf names its buffers and textures by URI, usually relative to itself,
72
+ // which resolves against neither a data: URI nor the CDN's hash-named URL. So
73
+ // a .gltf imported with `?url` is rewritten first: each relative reference
74
+ // that is a file in the deck becomes that file's own CDN URL (an image of the
75
+ // minimum or more, uploaded beside it) or a data: URI (a .bin buffer, anything
76
+ // smaller, or a type Ghost does not store), and the rewritten file is what is
77
+ // uploaded, whatever its size, since it now carries the references. Excluded
78
+ // (Ghost refused it), the rewritten file goes inline with every reference a
79
+ // data: URI, which loads where the original never could.
68
80
  //
69
81
  // Two places, one rule. A media file imported plainly or with `?url` -- the
70
82
  // way nearly every deck imports one, globs included -- is loaded here, ahead
@@ -76,6 +88,10 @@ const INLINE_ASSET_MAX_CHECKED_CODE = 10 * 1024 * 1024;
76
88
  // own MIME and bytes give. An `?inline` import asked for a data: URI by name,
77
89
  // and keeps it; so does a file Ghost refused to store (`exclude`).
78
90
  //
91
+ // An <img> drawn into a WebGL texture or read back from a canvas (getImageData)
92
+ // taints it unless it loaded with CORS, which a data: URI never needed; the
93
+ // shim below sets CORS on one given an asset URL the same way as on a video.
94
+ //
79
95
  // A media element loads a cross-origin URL without CORS unless told to, and
80
96
  // Web Audio then hears silence from it (`createMediaElementSource`), where the
81
97
  // data: URI played; a video drawn into a WebGL texture taints it. The CDN
@@ -104,10 +120,17 @@ export const EXTERNAL_MEDIA_TYPES = {
104
120
  // lookup), a .weba audio/webm, though both are the same container.
105
121
  'video/mp4': 'mp4',
106
122
  'video/webm': 'webm',
123
+ 'image/png': 'png',
124
+ 'image/jpeg': 'jpg',
125
+ 'image/webp': 'webp',
126
+ 'image/gif': 'gif',
127
+ 'model/gltf-binary': 'glb',
128
+ 'model/gltf+json': 'gltf',
107
129
  };
108
130
  // The MIME Vite's own lookup gives each media extension (its data: URI
109
131
  // header), for the files loaded here. Every one is in EXTERNAL_MEDIA_TYPES.
110
132
  // No .mov or .m4v: Chromium and Android WebView do not play them reliably.
133
+ // No .svg: a deck may read one as markup.
111
134
  const MEDIA_EXTENSION_TYPES = {
112
135
  wav: 'audio/wav',
113
136
  mp3: 'audio/mpeg',
@@ -120,10 +143,37 @@ const MEDIA_EXTENSION_TYPES = {
120
143
  weba: 'audio/webm',
121
144
  mp4: 'video/mp4',
122
145
  webm: 'video/webm',
146
+ png: 'image/png',
147
+ jpg: 'image/jpeg',
148
+ jpeg: 'image/jpeg',
149
+ webp: 'image/webp',
150
+ gif: 'image/gif',
151
+ glb: 'model/gltf-binary',
152
+ gltf: 'model/gltf+json',
123
153
  };
124
154
  // The media extensions Vite treats as assets without a `?url` (its KNOWN_ASSET_TYPES).
125
- const VITE_MEDIA_ASSETS = new Set(['wav', 'mp3', 'ogg', 'opus', 'm4a', 'aac', 'flac', 'mp4', 'webm']);
126
- const MEDIA_ID = /\.(wav|mp3|ogg|oga|opus|m4a|aac|flac|weba|mp4|webm)(\?url)?$/i;
155
+ // Not glb or gltf: a deck imports those with `?url`.
156
+ const VITE_MEDIA_ASSETS = new Set([
157
+ 'wav', 'mp3', 'ogg', 'opus', 'm4a', 'aac', 'flac', 'mp4', 'webm', 'png', 'jpg', 'jpeg', 'webp', 'gif',
158
+ ]);
159
+ const MEDIA_ID = /\.(wav|mp3|ogg|oga|opus|m4a|aac|flac|weba|mp4|webm|png|jpe?g|webp|gif|glb|gltf)(\?url)?$/i;
160
+ const GLTF_TYPE = 'model/gltf+json';
161
+ // The type a .gltf's referenced file is uploaded or inlined as, by extension. A
162
+ // type outside EXTERNAL_MEDIA_TYPES is always inlined: a KTX2 texture, and a
163
+ // .bin buffer, which Ghost does not store (it has no signature to check, and
164
+ // any bytes served as an octet-stream could run as a script).
165
+ const GLTF_REFERENCE_TYPES = {
166
+ bin: 'application/octet-stream',
167
+ png: 'image/png',
168
+ jpg: 'image/jpeg',
169
+ jpeg: 'image/jpeg',
170
+ webp: 'image/webp',
171
+ gif: 'image/gif',
172
+ ktx2: 'image/ktx2',
173
+ };
174
+ // A URI with a scheme (data:, https:, blob:) or a root-relative or
175
+ // protocol-relative one: not a file beside the .gltf.
176
+ const NOT_RELATIVE_URI = /^(?:[a-z][a-z0-9+.-]*:|\/)/i;
127
177
  /**
128
178
  * Smaller media stays inline. 64 KiB is the knee on the largest live deck:
129
179
  * 78 of its 91 media files move and its page goes from 35.2 MB to 1.4 MB; the
@@ -132,7 +182,35 @@ const MEDIA_ID = /\.(wav|mp3|ogg|oga|opus|m4a|aac|flac|weba|mp4|webm)(\?url)?$/i
132
182
  export const EXTERNAL_MEDIA_MIN_BYTES = 64 * 1024;
133
183
  // Where Ghost serves stored assets. The override is for tests against a fake API.
134
184
  export const EXTERNAL_MEDIA_BASE_URL = process.env.CASTLE_ASSET_BASE_URL || 'https://hosted.castle.games/cauldron-assets/';
135
- // Run before any deck script. CORS matters only where a media element is
185
+ function parseGltf(bytes) {
186
+ try {
187
+ const json = JSON.parse(bytes.toString('utf8').replace(/^\uFEFF/, ''));
188
+ return json && typeof json === 'object' && !Array.isArray(json) ? json : null;
189
+ }
190
+ catch {
191
+ return null;
192
+ }
193
+ }
194
+ /** Every `uri` a glTF names for its buffers and images, as objects to rewrite in place. */
195
+ function gltfReferences(json) {
196
+ const out = [];
197
+ for (const list of [json.buffers, json.images]) {
198
+ if (!Array.isArray(list))
199
+ continue;
200
+ for (const holder of list) {
201
+ if (holder && typeof holder === 'object' && typeof holder.uri === 'string')
202
+ out.push({ uri: holder.uri, holder });
203
+ }
204
+ }
205
+ return out;
206
+ }
207
+ const isRelativeReference = (uri) => uri !== '' && !NOT_RELATIVE_URI.test(uri);
208
+ // Run before any deck script. An <img> given an asset URL by its `src`
209
+ // property or `setAttribute('src')` is made `anonymous` before it fetches, so
210
+ // a deck can draw it into a WebGL texture or read a canvas it was drawn into;
211
+ // one that named an asset past them (markup) is reloaded in CORS mode where
212
+ // its pixels are first read, and that one upload or draw skipped, as for a
213
+ // video below. CORS matters for audio only where a media element is
136
214
  // routed into Web Audio (createMediaElementSource), so that is where it is
137
215
  // made sure of: any element given to it with no crossOrigin of its own becomes
138
216
  // `anonymous`, whatever it names now or is given later (a detached <source>
@@ -157,13 +235,21 @@ export const EXTERNAL_MEDIA_BASE_URL = process.env.CASTLE_ASSET_BASE_URL || 'htt
157
235
  // the frame fetched without CORS would taint the canvas for good.
158
236
  // Anything unexpected leaves the page as it was.
159
237
  function mediaCorsShim(prefix) {
160
- return `(function(){try{var P=${JSON.stringify(prefix)},M=window.HTMLMediaElement,S=window.HTMLSourceElement;if(!M)return;var H=M.prototype;` +
238
+ return `(function(){try{var P=${JSON.stringify(prefix)},M=window.HTMLMediaElement,S=window.HTMLSourceElement,I=window.HTMLImageElement;if(!M)return;var H=M.prototype;` +
161
239
  // A pending restore per element; anything the deck does to it cancels it.
162
240
  'var R=new WeakMap();function z(e){try{R.delete(e)}catch(x){}}' +
163
- 'function c(e,u){try{if(e instanceof M&&typeof u=="string"&&u.indexOf(P)===0&&e.getAttribute("crossorigin")===null)e.crossOrigin="anonymous"}catch(x){}}' +
241
+ // An <img> made CORS here is put back when it is given another URL (unless
242
+ // the deck has written its crossOrigin since, any value), and one
243
+ // inside a <picture> or with a srcset (which may pick another host) is left alone.
244
+ // O holds the <img> elements whose crossorigin the shim wrote and the deck has
245
+ // not written since (k marks the shim's own writes).
246
+ 'var O=new WeakSet(),k=false;function a(e){k=true;try{e.crossOrigin="anonymous"}finally{k=false}O.add(e)}' +
247
+ 'function c(e,u){try{if(typeof u!="string")return;var im=I&&e instanceof I;if(im&&O.has(e)&&u.indexOf(P)!==0){O.delete(e);e.removeAttribute("crossorigin");return}' +
248
+ 'if(im&&(e.hasAttribute("srcset")||e.parentNode&&e.parentNode.nodeName==="PICTURE"))return;' +
249
+ 'if((e instanceof M||im)&&u.indexOf(P)===0&&e.getAttribute("crossorigin")===null){if(im)a(e);else e.crossOrigin="anonymous"}}catch(x){}}' +
164
250
  'function w(T,k,f){var d=T&&Object.getOwnPropertyDescriptor(T.prototype,k);if(d&&d.set&&d.configurable)Object.defineProperty(T.prototype,k,{configurable:true,enumerable:d.enumerable,get:d.get,set:function(v){try{f(this,v)}catch(x){}d.set.call(this,v)}});return d}' +
165
- 'w(M,"src",function(e,v){z(e);c(e,String(v))});w(S,"src",function(e,v){c(e.parentNode,String(v))});var T=w(M,"currentTime",z);' +
166
- 'var g=Element.prototype.setAttribute;Element.prototype.setAttribute=function(n,v){try{if(String(n).toLowerCase()==="src"){if(this instanceof M)z(this);c(this instanceof M?this:S&&this instanceof S?this.parentNode:null,String(v))}}catch(x){}return g.apply(this,arguments)};' +
251
+ 'w(M,"src",function(e,v){z(e);c(e,String(v))});w(S,"src",function(e,v){c(e.parentNode,String(v))});w(I,"src",function(e,v){c(e,String(v))});w(I,"crossOrigin",function(e){if(!k)O.delete(e)});var T=w(M,"currentTime",z);' +
252
+ 'var g=Element.prototype.setAttribute;Element.prototype.setAttribute=function(n,v){try{if(I&&this instanceof I&&String(n).toLowerCase()==="crossorigin")O.delete(this);if(String(n).toLowerCase()==="src"){if(this instanceof M)z(this);c(this instanceof M||I&&this instanceof I?this:S&&this instanceof S?this.parentNode:null,String(v))}}catch(x){}return g.apply(this,arguments)};' +
167
253
  'var L=H.load;["play","pause","load"].forEach(function(k){var f=H[k];if(f)H[k]=function(){z(this);return f.apply(this,arguments)}});' +
168
254
  'var A=window.Audio;if(A){var W=function Audio(u){var e=new A();if(u!==undefined){c(e,String(u));e.src=u}return e};W.prototype=A.prototype;window.Audio=W}' +
169
255
  'function r(e){if(!(e instanceof M)||e.getAttribute("crossorigin")!==null)return;var u=e.currentSrc||e.src||"";e.crossOrigin="anonymous";' +
@@ -176,12 +262,16 @@ function mediaCorsShim(prefix) {
176
262
  // that names an asset without CORS: reloaded in CORS mode on its first read,
177
263
  // and that one texture upload or draw skipped, so nothing is tainted.
178
264
  'var V=window.HTMLVideoElement;function n(e){if(!V||!(e instanceof V)||e.getAttribute("crossorigin")!==null)return false;if((e.currentSrc||e.src||"").indexOf(P)===0)return true;var s=e.querySelectorAll("source");for(var i=0;i<s.length;i++)if((s[i].src||"").indexOf(P)===0)return true;return false}' +
179
- 'function y(C,k){var K=C&&C.prototype,o=K&&K[k];if(typeof o!="function"||o.__castle)return;var h=function(){for(var i=0;i<arguments.length;i++){var e=arguments[i];if(V&&e instanceof V){try{if(n(e)&&r(e))return}catch(x){}break}}return o.apply(this,arguments)};h.__castle=1;K[k]=h}' +
265
+ // An <img> the same way: setting crossorigin makes it fetch again, in CORS mode.
266
+ // The reload is one promise per image, which every createImageBitmap of it waits on.
267
+ 'var Q=new WeakMap();function j(e){return!!I&&e instanceof I&&e.getAttribute("crossorigin")===null&&!e.hasAttribute("srcset")&&!(e.parentNode&&e.parentNode.nodeName==="PICTURE")&&(e.currentSrc||e.src||"").indexOf(P)===0}' +
268
+ 'function q(e){Q.set(e,new Promise(function(ok){var f=function(){e.removeEventListener("load",f);e.removeEventListener("error",f);Q.delete(e);ok()};e.addEventListener("load",f);e.addEventListener("error",f)}));a(e);return true}' +
269
+ 'function y(C,k){var K=C&&C.prototype,o=K&&K[k];if(typeof o!="function"||o.__castle)return;var h=function(){for(var i=0;i<arguments.length;i++){var e=arguments[i];if(V&&e instanceof V){try{if(n(e)&&r(e))return}catch(x){}break}if(I&&e instanceof I){try{if(j(e)&&q(e))return}catch(x){}break}}return o.apply(this,arguments)};h.__castle=1;K[k]=h}' +
180
270
  '[window.WebGLRenderingContext,window.WebGL2RenderingContext].forEach(function(C){["texImage2D","texSubImage2D","texImage3D","texSubImage3D"].forEach(function(k){y(C,k)})});' +
181
271
  '[window.CanvasRenderingContext2D,window.OffscreenCanvasRenderingContext2D].forEach(function(C){y(C,"drawImage")});' +
182
272
  // createImageBitmap answers a promise, so it waits out the reload (a CORS
183
273
  // frame, and the restored time settled) and then reads, instead of skipping.
184
- 'var B=window.createImageBitmap;if(B&&!B.__castle){window.createImageBitmap=function(e){var a=arguments,s=this;try{if(n(e)&&r(e))return new Promise(function(ok){var E=["loadeddata","seeked","canplay","error"],t,d=function(){if(!(e.readyState>=2&&!e.seeking)&&!e.error&&d!==t)return;E.forEach(function(k){e.removeEventListener(k,d)});clearTimeout(t);ok()};t=setTimeout(function(){t=d;d()},10000);E.forEach(function(k){e.addEventListener(k,d)})}).then(function(){return B.apply(s,a)})}catch(x){}return B.apply(this,arguments)};window.createImageBitmap.__castle=1}' +
274
+ 'var B=window.createImageBitmap;if(B&&!B.__castle){window.createImageBitmap=function(e){var a=arguments,s=this;try{if(j(e))q(e);var w8=Q.get(e);if(w8)return w8.then(function(){return B.apply(s,a)});if(n(e)&&r(e))return new Promise(function(ok){var E=["loadeddata","seeked","canplay","error"],t,d=function(){if(!(e.readyState>=2&&!e.seeking)&&!e.error&&d!==t)return;E.forEach(function(k){e.removeEventListener(k,d)});clearTimeout(t);ok()};t=setTimeout(function(){t=d;d()},10000);E.forEach(function(k){e.addEventListener(k,d)})}).then(function(){return B.apply(s,a)})}catch(x){}return B.apply(this,arguments)};window.createImageBitmap.__castle=1}' +
185
275
  '[window.AudioContext,window.webkitAudioContext].forEach(function(C){var K=C&&C.prototype,o=K&&K.createMediaElementSource;if(!o||o.__castle)return;var h=function(e){try{r(e)}catch(x){}return o.apply(this,arguments)};h.__castle=1;K.createMediaElementSource=h});' +
186
276
  '}catch(x){}})();';
187
277
  }
@@ -189,6 +279,9 @@ export class ExternalMedia {
189
279
  baseUrl;
190
280
  exclude;
191
281
  byUrl = new Map();
282
+ // sha256s of the self-contained .gltf files written inline for a refused
283
+ // one, which the late swap would otherwise take for a new asset.
284
+ inlined = new Set();
192
285
  /** `exclude`: sha256s that stay inline (Ghost refused to store them). */
193
286
  constructor(baseUrl = EXTERNAL_MEDIA_BASE_URL, exclude = new Set()) {
194
287
  this.baseUrl = baseUrl;
@@ -238,7 +331,7 @@ export class ExternalMedia {
238
331
  },
239
332
  transform: {
240
333
  order: 'post',
241
- filter: { code: /"data:(?:audio|video)\// },
334
+ filter: { code: /"data:(?:audio|video|image|model)\// },
242
335
  handler: (code, id) => {
243
336
  // An `?inline` import's module: a data: URI asked for by name.
244
337
  if (/[?&]inline(?:[&=]|$)/.test(id))
@@ -279,17 +372,94 @@ export class ExternalMedia {
279
372
  catch {
280
373
  return null;
281
374
  }
375
+ if (mime === GLTF_TYPE)
376
+ return this.loadedGltf(file, size, root);
282
377
  if (size < EXTERNAL_MEDIA_MIN_BYTES)
283
378
  return null;
284
379
  return this.record(mime, fs.readFileSync(file), relativeSource(root, file));
285
380
  }
286
- record(mime, bytes, source) {
381
+ // A .gltf with no relative references is any other asset. One with them is
382
+ // rewritten (see the top of this section): its references become URLs or
383
+ // data: URIs, and it is named by its URL whatever its size -- or, when Ghost
384
+ // refused the rewritten file, inline with every reference a data: URI.
385
+ loadedGltf(file, size, root) {
386
+ const bytes = fs.readFileSync(file);
387
+ const source = relativeSource(root, file);
388
+ const json = parseGltf(bytes);
389
+ if (!json || !gltfReferences(json).some((ref) => isRelativeReference(ref.uri))) {
390
+ return size < EXTERNAL_MEDIA_MIN_BYTES ? null : this.record(GLTF_TYPE, bytes, source);
391
+ }
392
+ const deps = new Map();
393
+ const rewritten = this.rewriteGltf(file, root, parseGltf(bytes), deps, false);
394
+ const sha256 = createHash('sha256').update(rewritten).digest('hex');
395
+ if (!this.exclude.has(sha256)) {
396
+ for (const dep of deps.values())
397
+ if (!this.byUrl.has(dep.url))
398
+ this.byUrl.set(dep.url, dep);
399
+ return this.record(GLTF_TYPE, rewritten, source, [...deps.keys()]);
400
+ }
401
+ const inline = this.rewriteGltf(file, root, parseGltf(bytes), new Map(), true);
402
+ this.inlined.add(createHash('sha256').update(inline).digest('hex'));
403
+ return `data:${GLTF_TYPE};base64,${inline.toString('base64')}`;
404
+ }
405
+ // Each relative reference that is a file under the deck becomes its asset
406
+ // URL (collected in `deps`) or, when it is small, a type Ghost does not
407
+ // store, excluded, or `inlineAll`, a data: URI. Any other reference is left
408
+ // as it was.
409
+ rewriteGltf(file, root, json, deps, inlineAll) {
410
+ const dir = path.dirname(file);
411
+ // Real paths on both sides: a symlink in the deck must not reach a file outside it.
412
+ let within;
413
+ try {
414
+ within = fs.realpathSync(root) + path.sep;
415
+ }
416
+ catch {
417
+ return Buffer.from(JSON.stringify(json));
418
+ }
419
+ for (const { uri, holder } of gltfReferences(json)) {
420
+ if (!isRelativeReference(uri))
421
+ continue;
422
+ let target;
423
+ try {
424
+ target = path.resolve(dir, decodeURIComponent(uri.split(/[?#]/, 1)[0]));
425
+ }
426
+ catch {
427
+ continue;
428
+ }
429
+ let refBytes;
430
+ try {
431
+ target = fs.realpathSync(target);
432
+ if (!target.startsWith(within) || !fs.statSync(target).isFile())
433
+ continue;
434
+ refBytes = fs.readFileSync(target);
435
+ }
436
+ catch {
437
+ continue;
438
+ }
439
+ const type = GLTF_REFERENCE_TYPES[path.extname(target).slice(1).toLowerCase()] ?? 'application/octet-stream';
440
+ const sha256 = createHash('sha256').update(refBytes).digest('hex');
441
+ if (!inlineAll &&
442
+ EXTERNAL_MEDIA_TYPES[type] &&
443
+ refBytes.byteLength >= EXTERNAL_MEDIA_MIN_BYTES &&
444
+ !this.exclude.has(sha256)) {
445
+ const url = `${this.baseUrl}${sha256}.${EXTERNAL_MEDIA_TYPES[type]}`;
446
+ deps.set(url, { sha256, contentType: type, url, bytes: refBytes, source: relativeSource(root, target) });
447
+ holder.uri = url;
448
+ }
449
+ else {
450
+ holder.uri = `data:${type};base64,${refBytes.toString('base64')}`;
451
+ }
452
+ }
453
+ return Buffer.from(JSON.stringify(json));
454
+ }
455
+ record(mime, bytes, source, deps) {
287
456
  const sha256 = createHash('sha256').update(bytes).digest('hex');
288
- if (this.exclude.has(sha256))
457
+ if (this.exclude.has(sha256) || this.inlined.has(sha256))
289
458
  return null;
290
459
  const url = `${this.baseUrl}${sha256}.${EXTERNAL_MEDIA_TYPES[mime]}`;
291
- if (!this.byUrl.has(url))
292
- this.byUrl.set(url, { sha256, contentType: mime, url, bytes, source });
460
+ if (!this.byUrl.has(url)) {
461
+ this.byUrl.set(url, { sha256, contentType: mime, url, bytes, source, ...(deps?.length ? { deps } : {}) });
462
+ }
293
463
  return url;
294
464
  }
295
465
  urlFor(header, payload, source) {
@@ -302,11 +472,30 @@ export class ExternalMedia {
302
472
  const bytes = Buffer.from(payload, 'base64');
303
473
  if (bytes.byteLength < EXTERNAL_MEDIA_MIN_BYTES)
304
474
  return null;
475
+ // A .gltf met only as a data: URI has no file to resolve references against:
476
+ // one that has any stays as it is.
477
+ if (mime === GLTF_TYPE) {
478
+ const json = parseGltf(bytes);
479
+ if (json && gltfReferences(json).some((ref) => isRelativeReference(ref.uri)))
480
+ return null;
481
+ }
305
482
  return this.record(mime, bytes, source);
306
483
  }
307
- /** Every asset the finished page names (a module the build dropped names none). */
484
+ /**
485
+ * Every asset the finished page names (a module the build dropped names
486
+ * none), and each one those name in turn (a .gltf's buffers and textures).
487
+ */
308
488
  assetsIn(html) {
309
- return [...this.byUrl.values()].filter((asset) => html.includes(asset.url));
489
+ const named = [...this.byUrl.values()].filter((asset) => html.includes(asset.url));
490
+ const out = new Map(named.map((asset) => [asset.url, asset]));
491
+ for (const asset of named) {
492
+ for (const url of asset.deps ?? []) {
493
+ const dep = this.byUrl.get(url);
494
+ if (dep && !out.has(url))
495
+ out.set(url, dep);
496
+ }
497
+ }
498
+ return [...out.values()];
310
499
  }
311
500
  }
312
501
  function relativeSource(root, id) {
package/dist/index.js CHANGED
@@ -209,6 +209,7 @@ function usage() {
209
209
  castle-web list-versions [version] [--dir DIR] (defaults to the latest version)
210
210
  castle-web show-version <version> [--dir DIR] (diffs of the files that version changed)
211
211
  castle-web restore-version <version> [--force] [--dir DIR]
212
+ castle-web prune-versions --keep N [--dry-run] [--dir DIR] (keeps the newest N versions, drops the rest and their stored files, after checking the result against the cloud save's version-history rules; never hand-edit .castle/versions)
212
213
  castle-web git init [dir] [--dir DIR] [--staging] (connects the deck to its Castle git remote: git push castle <branch>)
213
214
  castle-web git clone <deckId|url> [dir] [--staging] (clones a deck's Castle repo; the remote is "castle")
214
215
  castle-web git setup [--force|--remove] (lets plain git use your Castle login for git.castle.xyz; login does this)
@@ -689,6 +690,15 @@ async function main() {
689
690
  restoreVersion(getFlagValue('--dir') ?? '.', target, { force: hasFlag('--force') });
690
691
  break;
691
692
  }
693
+ case 'prune-versions': {
694
+ const keep = Number(getFlagValue('--keep'));
695
+ if (!getFlagValue('--keep') || !Number.isInteger(keep) || keep < 1) {
696
+ console.error('Usage: castle-web prune-versions --keep N [--dry-run] (N is at least 1)');
697
+ process.exit(1);
698
+ }
699
+ (await import('./versionPrune.js')).pruneVersions(getFlagValue('--dir') ?? '.', { keep, dryRun: hasFlag('--dry-run') });
700
+ break;
701
+ }
692
702
  case 'restart': {
693
703
  const dir = findPositionalDir();
694
704
  const servePort = getServeSocketPort(dir);
package/dist/init.js CHANGED
@@ -64,7 +64,7 @@ const BARE_SCAFFOLDS = [
64
64
  // Registry version of castle-web-sdk to inject when scaffolding from a
65
65
  // globally-installed castle-web (not from inside the workspace). Bumped
66
66
  // alongside cli/sdk version bumps.
67
- const PUBLISHED_SDK_VERSION = '0.4.55';
67
+ const PUBLISHED_SDK_VERSION = '0.4.56';
68
68
  // Range, not a pin: `castle-web-fonts` is its own package precisely so a tenth
69
69
  // face can ship without a cli release, and a caret range means an existing
70
70
  // deck's next install picks it up. Nothing here has to move when it does.
@@ -54,11 +54,12 @@ const MODE_BULLET = "- Unprompted, an editor is an offer, never a build: when th
54
54
  export function everyDeckBullets(deckDir) {
55
55
  return [
56
56
  "- **Castle's Parameters panel is where a creator tunes the deck.** It is one of Castle's own panels, beside Play and Files: it shows the `PARAMS` values of every file that has one as live fields the creator drags while the deck runs, which is how they change the way it plays without putting a cursor in code.",
57
- `- **Supported media formats are exactly**: ${mediaList(deckDir)}. Nothing else — a published deck inlines every asset as a \`data:\` URI, where the browser trusts the declared type instead of sniffing the bytes, so a format that merely works while serving (\`.mov\` is the classic case) can be dead once published. Convert, don't improvise. Audio and video (\`.mp4\`, \`.webm\`) of 64 KB or more are the assets not inlined: a published deck serves them from Castle's CDN by URL, so play them with \`new Audio(url)\`, \`video.src = url\` or \`fetch\` + \`decodeAudioData\`, never by reading the string (an \`?inline\` import keeps the \`data:\` URI).`,
57
+ `- **Supported media formats are exactly**: ${mediaList(deckDir)}. Nothing else — a published deck inlines every asset as a \`data:\` URI, where the browser trusts the declared type instead of sniffing the bytes, so a format that merely works while serving (\`.mov\` is the classic case) can be dead once published. Convert, don't improvise. Audio, video (\`.mp4\`, \`.webm\`), images (\`.png\`, \`.jpg\`, \`.webp\`, \`.gif\`) and 3D models (\`.glb\`, and \`.gltf\` with the \`.bin\` and textures it references, imported with \`?url\`) of 64 KB or more are the assets not inlined: a published deck serves them from Castle's CDN by URL, so hand the URL to a loader (\`new Audio(url)\`, \`video.src = url\`, \`img.src = url\`, a texture or glTF loader, \`fetch\`), never read the string itself (an \`?inline\` import keeps the \`data:\` URI).`,
58
58
  "- To add an npm package, put it in `package.json` `dependencies` and run `castle-web install .` (the install `init` ran; it uses whichever package manager made the lockfile).",
59
59
  "- Do not reload the deck after an edit. Nothing auto-reloads: the person applies your changes when they are ready, from the Play panel's restart button or a panel's own reload control. `npm run restart` reloads every open panel at once and breaks their flow — only when asked.",
60
60
  '- If the browser console shows `[vite] failed to connect to websocket` (or a "Direct websocket connection fallback" line), ignore it. Vite HMR is deliberately off on this serve, so the line is expected and harmless: it is never why a scene is blank, a game is not running, or multiplayer is not connecting. Do not investigate or "fix" it.',
61
61
  "- Never revert, replace, or re-scaffold the deck's scenes, scripts, or behaviors back to kit, starter, or imported content, and never delete or rewrite a whole scene to diagnose a problem -- those files are the person's own work. Fix forward with targeted edits, and treat a request to diagnose or explain as read-only unless they asked for a fix.",
62
+ "- **Never hand-edit, move or delete anything under `.castle/versions/`**, the deck's saved version history -- not to save space, not to fix `list-versions`. Each version is stored as a change against the one before it, so removing versions or blobs by hand corrupts the history and the cloud stops saving the deck. To shrink it, run `castle-web prune-versions --keep <n> --dry-run` to see what would go, then the same without `--dry-run`: it keeps the newest n versions, rewrites the oldest kept one so it stands on its own, and checks the result against the cloud save's version-history rules before it changes anything. Removing old versions is the person's call, so ask first.",
62
63
  "- The deck can define its own editors: declare a file type in `castle.json` (`editor.fileTypes`: ext, label, icon, and an `editors/` module) and the Files panel opens that type in it — whole recipe under `## Editors` in the deck's guide (its kit's `CLAUDE.md` under `imports/`). Editors under `imports/` are read-only; add or fork, don't edit.",
63
64
  '- An editor is for content FILES the creator keeps coming back to (catalogs, dialogue, level tables) that nothing already opens. One-off or generated data stays code.',
64
65
  "- **Put the values someone would tune while playtesting in a `PARAMS` object**: `export const PARAMS = { jumpHeight: 4.2, coyoteTime: 0.08 };` near the top of the file that uses them. The Parameters panel lists every file in the deck that has one and renders their values as fields -- a number scrubs, a boolean toggles, a `'#rrggbb'` string opens a color picker -- and writes the edit back into the file. It edits every file's params in one place, so nobody has to remember which file a setting lives in, and a file that has params says so above its code with a way in. That is how a creator tunes a game on a phone without putting a cursor inside an expression. Nested one level deep (`player: { speed: 5 }`) renders as a group. **Write each value as a plain number, not as arithmetic** (`0.333`, not `1 / 3`): the panel folds arithmetic over plain numbers into a field and replaces it with the tuned literal on the first edit, so the expression you wrote does not survive the first tune. A value that NAMES something (`speed: BASE * 2`) shows read-only, as a link onto its own line in the code.",
@@ -79,7 +80,7 @@ export function everyDeckBullets(deckDir) {
79
80
  export const HOST_LIMIT_BULLETS = [
80
81
  "- **Where a deck runs decides what it can do.** The Play panel runs it from this serve; players run the published deck in the Castle app (iOS, Android) or castle.xyz's web player. When something works in one and fails in another, check it against the limits below before another fix: if one covers it, name that limit instead of retrying, and ask where they run it if you do not know. If none does, it is an ordinary deck bug (a runtime `fetch` of a loose file, a control that only answers a mouse) and gets fixed.",
81
82
  "- **Microphone and camera are blocked in the Play panel and on castle.xyz**: neither frame is granted them, so `getUserMedia` rejects with `NotAllowedError` whatever the person allows, and no deck change helps. The Android app's published deck can use them; the iOS app is untested.",
82
- "- **A published deck loads almost nothing from the network.** Its CSP allows images, audio and video only from the deck itself, `data:` or `blob:`, `fetch` only to esm.sh, cdnjs.cloudflare.com and Castle's multiplayer hosts, and no iframes. The Play panel enforces the same CSP, so a URL it blocks fails in Play too, and `.castle/logs.txt` names each URL and directive the page blocked with a `[csp] blocked` line. Bundle the file, or let the player pick one with `<input type=\"file\">`.",
83
+ "- **A published deck loads almost nothing from the network.** Its CSP allows images, audio and video only from the deck itself, `data:`, `blob:` and Castle's own CDN (where save-deck puts the deck's large media, images and models), `fetch` only to esm.sh, cdnjs.cloudflare.com, that CDN and Castle's multiplayer hosts, and no iframes. The Play panel enforces the same CSP, so a URL it blocks fails in Play too, and `.castle/logs.txt` names each URL and directive the page blocked with a `[csp] blocked` line. Bundle the file, or let the player pick one with `<input type=\"file\">`.",
83
84
  "- **On castle.xyz a published deck's frame has no origin of its own, and on a device its console reaches no devtools.** Browser storage throws a `SecurityError` there, and so do history calls that pass a URL. Don't build on browser storage; the SDK's replacements, how `setup()` keeps history calls working, and the on-screen console for debugging on a device are in the SDK reference, `imports/castle.base/sdk/README.md`.",
84
85
  "- **An older Castle app build rejects SDK commands newer than the build**, with a `CastleError` whose `code` is `UNKNOWN_COMMAND`; only an app update fixes that, so the deck should catch it and keep working. Which commands need which app build, and every other limit of a Castle service, is in the SDK reference, `imports/castle.base/sdk/README.md`.",
85
86
  ];
@@ -12,17 +12,18 @@ const CONTENT_PACK_HOSTS = 'https://hosted.castle.games';
12
12
  // `Access-Control-Allow-Origin: *`, so a fetch from the opaque srcdoc origin can read
13
13
  // them. img-src, media-src and connect-src only: an asset is data, never script.
14
14
  export const CASTLE_ASSET_HOSTS = 'https://castle.imgix.net https://image.castle.xyz https://audio.castle.xyz';
15
- // A published deck's audio and video, which save-deck stores there instead of
16
- // inlining it (bundle.ts ExternalMedia). Path-scoped and media-src only: a fetch
17
- // for decodeAudioData is already covered by CONTENT_PACK_HOSTS in connect-src.
18
- const MEDIA_ASSET_SRC = 'https://hosted.castle.games/cauldron-assets/';
15
+ // A published deck's audio, video and images, which save-deck stores there
16
+ // instead of inlining them (bundle.ts ExternalMedia). Path-scoped, img-src and
17
+ // media-src only: a fetch (decodeAudioData, a glTF or texture loader) is
18
+ // already covered by CONTENT_PACK_HOSTS in connect-src.
19
+ const ASSET_SRC = 'https://hosted.castle.games/cauldron-assets/';
19
20
  const DECK_CSP = [
20
21
  "default-src 'self' data: blob:",
21
22
  `script-src 'self' 'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' data: blob: ${CDN_HOSTS}`,
22
23
  "style-src 'self' 'unsafe-inline' data: blob: https://fonts.googleapis.com",
23
24
  "font-src 'self' data: blob: https://fonts.gstatic.com",
24
- `img-src 'self' data: blob: ${CASTLE_ASSET_HOSTS}`,
25
- `media-src 'self' data: blob: ${CASTLE_ASSET_HOSTS} ${MEDIA_ASSET_SRC}`,
25
+ `img-src 'self' data: blob: ${CASTLE_ASSET_HOSTS} ${ASSET_SRC}`,
26
+ `media-src 'self' data: blob: ${CASTLE_ASSET_HOSTS} ${ASSET_SRC}`,
26
27
  `connect-src 'self' data: blob: ${CDN_HOSTS} ${PLAY_HOSTS} ${CONTENT_PACK_HOSTS} ${CASTLE_ASSET_HOSTS}`,
27
28
  "frame-src 'none'",
28
29
  "child-src 'self' blob:",
package/dist/save-deck.js CHANGED
@@ -534,11 +534,28 @@ async function storeMediaAsset(deckId, asset, busyRetryMs) {
534
534
  // write. Each newly stored asset is fetched once through the CDN, these waits
535
535
  // apart, before a page naming it is published.
536
536
  export const ASSET_SERVED_RETRY_MS = [1000, 2000];
537
+ // A deck reads an asset cross-origin (fetch, a CORS <img>, Web Audio), so served
538
+ // means served with CORS: asked with an Origin, as the deck's browser asks.
539
+ const ASSET_PROBE_ORIGIN = 'https://castle.xyz';
540
+ const servedWithCors = (res) => (res.status === 200 || res.status === 206) && res.headers.get('access-control-allow-origin') === '*';
537
541
  async function assetServed(url) {
538
542
  try {
539
- const res = await fetch(url, { headers: { Range: 'bytes=0-0' }, signal: AbortSignal.timeout(15_000) });
543
+ const res = await fetch(url, {
544
+ headers: { Range: 'bytes=0-0', Origin: ASSET_PROBE_ORIGIN },
545
+ signal: AbortSignal.timeout(15_000),
546
+ });
540
547
  await res.body?.cancel();
541
- return res.status === 200 || res.status === 206;
548
+ return servedWithCors(res);
549
+ }
550
+ catch {
551
+ return false;
552
+ }
553
+ }
554
+ /** An asset already stored and served with CORS (HEAD); anything else is stored again and probed. */
555
+ async function assetAlreadyServed(url) {
556
+ try {
557
+ const res = await fetch(url, { method: 'HEAD', headers: { Origin: ASSET_PROBE_ORIGIN }, signal: AbortSignal.timeout(15_000) });
558
+ return res.status === 200 && servedWithCors(res);
542
559
  }
543
560
  catch {
544
561
  return false;
@@ -575,7 +592,7 @@ export async function uploadMediaAssets(deckId, assets, { busyRetryMs = CHUNK_BU
575
592
  result.refused.push({ asset, code: ASSET_TOO_LARGE });
576
593
  return;
577
594
  }
578
- if (await alreadyStored(asset.url)) {
595
+ if (await assetAlreadyServed(asset.url)) {
579
596
  result.skipped++;
580
597
  return;
581
598
  }