pixelkiln 0.92.3 → 0.93.0

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/index.cjs CHANGED
@@ -145,6 +145,7 @@ __export(index_exports, {
145
145
  availableProviders: () => availableProviders,
146
146
  backoffMs: () => backoffMs,
147
147
  buildGallerySnapshot: () => buildGallerySnapshot,
148
+ buildImportedEntry: () => buildImportedEntry,
148
149
  buildManifest: () => buildManifest,
149
150
  buildPlan: () => buildPlan,
150
151
  buildWorkspaceGallerySnapshot: () => buildWorkspaceGallerySnapshot,
@@ -207,6 +208,7 @@ __export(index_exports, {
207
208
  historyLimit: () => historyLimit,
208
209
  idFromPrompt: () => idFromPrompt,
209
210
  imageMetadata: () => imageMetadata,
211
+ importLocal: () => importLocal,
210
212
  inspectCaches: () => inspectCaches,
211
213
  inspectQualityProfile: () => inspectQualityProfile,
212
214
  inspectRevisionReadiness: () => inspectRevisionReadiness,
@@ -299,6 +301,7 @@ __export(index_exports, {
299
301
  renderSalvageSheet: () => renderSalvageSheet,
300
302
  renderSheet: () => renderSheet,
301
303
  renderSheetDocument: () => renderSheetDocument,
304
+ reportSpecHashes: () => reportSpecHashes,
302
305
  requireApprovedQualitySources: () => requireApprovedQualitySources,
303
306
  requireBalance: () => requireBalance,
304
307
  requireDelete: () => requireDelete,
@@ -338,6 +341,7 @@ __export(index_exports, {
338
341
  sliceVfxSheet: () => sliceVfxSheet,
339
342
  slugify: () => slugify,
340
343
  snapshotQualityBaseline: () => snapshotQualityBaseline,
344
+ snapshotQualityCases: () => snapshotQualityCases,
341
345
  sourceIsStem: () => sourceIsStem,
342
346
  sourceOutputPath: () => sourceOutputPath,
343
347
  specHash: () => specHash,
@@ -1967,7 +1971,17 @@ var LockEntrySchema = import_zod.z.object({
1967
1971
  /** Generations this entry replaced, newest first; see LockHistoryEntrySchema. */
1968
1972
  history: import_zod.z.array(LockHistoryEntrySchema).optional(),
1969
1973
  /** Post-processing applied to the recorded outputs; absent when the bytes are the provider's. */
1970
- postprocess: PostprocessSchema.optional()
1974
+ postprocess: PostprocessSchema.optional(),
1975
+ /**
1976
+ * Set when the entry records art made outside pixelkiln (the PixelLab MCP, a
1977
+ * hand edit, another tool) and brought in with `adopt --local`: nothing was
1978
+ * submitted, so jobId and cost are empty. Absent on generated entries.
1979
+ */
1980
+ imported: import_zod.z.object({
1981
+ source: import_zod.z.string().min(1),
1982
+ note: import_zod.z.string().optional(),
1983
+ importedAt: import_zod.z.string()
1984
+ }).strict().optional()
1971
1985
  });
1972
1986
  var LockSchema = import_zod.z.object({
1973
1987
  version: import_zod.z.literal(2),
@@ -7377,13 +7391,13 @@ var PixelLabProvider = class _PixelLabProvider {
7377
7391
  async pollVfx(jobId, context) {
7378
7392
  const dir = _PixelLabProvider.cacheDir("vfx");
7379
7393
  const sidecar = import_node_path3.default.join(dir, `${jobId}.json`);
7380
- const cached = () => {
7394
+ const cached2 = () => {
7381
7395
  if (!(0, import_node_fs4.existsSync)(sidecar)) return null;
7382
7396
  const facts2 = JSON.parse((0, import_node_fs4.readFileSync)(sidecar, "utf8"));
7383
7397
  const files2 = Array.from({ length: facts2.count }, (_, index) => import_node_path3.default.join(dir, `${jobId}-${index}.png`));
7384
7398
  return files2.every((file) => (0, import_node_fs4.existsSync)(file)) ? { facts: facts2, files: files2 } : null;
7385
7399
  };
7386
- let found = cached();
7400
+ let found = cached2();
7387
7401
  const recorded = context?.metadata?.vfx;
7388
7402
  let artistDone;
7389
7403
  if (!found && recorded?.artist) {
@@ -7403,11 +7417,11 @@ var PixelLabProvider = class _PixelLabProvider {
7403
7417
  }
7404
7418
  artistDone.billed = billedFromUsage(job.usage);
7405
7419
  }
7406
- found = cached();
7420
+ found = cached2();
7407
7421
  } else if (!found && recorded?.downloadBase && Array.isArray(recorded.files)) {
7408
7422
  const exported = recorded;
7409
7423
  await this.cacheVfxFrames(jobId, exported, workbenchVfxUrls(exported));
7410
- found = cached();
7424
+ found = cached2();
7411
7425
  }
7412
7426
  if (!found) {
7413
7427
  return {
@@ -8605,8 +8619,8 @@ var ScenarioClient = class {
8605
8619
  async uploadImage(image, projectId) {
8606
8620
  const bytes = Buffer.from(image.base64, "base64");
8607
8621
  const digest2 = sha256(bytes);
8608
- const cached = readUploadCache()[uploadCacheKey(this.baseUrl, projectId, digest2)];
8609
- if (cached) return cached;
8622
+ const cached2 = readUploadCache()[uploadCacheKey(this.baseUrl, projectId, digest2)];
8623
+ if (cached2) return cached2;
8610
8624
  const response = await this.call(
8611
8625
  "/assets",
8612
8626
  {
@@ -10296,7 +10310,7 @@ registerProvider({
10296
10310
 
10297
10311
  // src/manifest.ts
10298
10312
  var import_promises5 = require("fs/promises");
10299
- var import_node_fs8 = require("fs");
10313
+ var import_node_fs9 = require("fs");
10300
10314
  var import_node_path8 = __toESM(require("path"), 1);
10301
10315
 
10302
10316
  // src/loop-directions.ts
@@ -10711,10 +10725,31 @@ function frameSetLoop(entry) {
10711
10725
  return typeof loop === "boolean" ? loop : null;
10712
10726
  }
10713
10727
 
10728
+ // src/version.ts
10729
+ var import_node_fs8 = require("fs");
10730
+ var cached;
10731
+ function pixelkilnVersion() {
10732
+ if (cached !== void 0) return cached;
10733
+ cached = null;
10734
+ for (const up of ["../package.json", "../../package.json"]) {
10735
+ const url = new URL(up, importMetaUrl);
10736
+ if (!(0, import_node_fs8.existsSync)(url)) continue;
10737
+ try {
10738
+ const pkg = JSON.parse((0, import_node_fs8.readFileSync)(url, "utf8"));
10739
+ if (pkg.name === "pixelkiln" && pkg.version) {
10740
+ cached = pkg.version;
10741
+ break;
10742
+ }
10743
+ } catch {
10744
+ }
10745
+ }
10746
+ return cached;
10747
+ }
10748
+
10714
10749
  // src/manifest.ts
10715
10750
  async function loadManifest(manifestPath) {
10716
10751
  const abs = import_node_path8.default.resolve(manifestPath);
10717
- if (!(0, import_node_fs8.existsSync)(abs)) throw new ProjectError(`No manifest at ${abs}`);
10752
+ if (!(0, import_node_fs9.existsSync)(abs)) throw new ProjectError(`No manifest at ${abs}`);
10718
10753
  const expansion = expandLoopDirections(JSON.parse(await (0, import_promises5.readFile)(abs, "utf8")));
10719
10754
  if (expansion.issues.length) {
10720
10755
  throw new ProjectError(`Manifest at ${abs} is invalid:
@@ -10866,19 +10901,45 @@ function dependencyAssetIds(asset, styleAnchors = []) {
10866
10901
  ].filter((id) => Boolean(id))
10867
10902
  ];
10868
10903
  }
10904
+ var MAX_LISTED_MANIFEST_ISSUES = 20;
10905
+ function flattenManifestIssues(issues) {
10906
+ let unknownShape = false;
10907
+ const visit = (list) => list.flatMap((issue) => {
10908
+ if (issue.code === "invalid_union") return visit(issue.unionErrors.flatMap((error) => error.issues));
10909
+ if (issue.code === "unrecognized_keys" || issue.code === "invalid_enum_value") unknownShape = true;
10910
+ return [` ${issue.path.join(".") || "(manifest)"}: ${issue.message}`];
10911
+ });
10912
+ return { lines: [...new Set(visit(issues))], unknownShape };
10913
+ }
10869
10914
  function formatManifestIssues(issues) {
10870
- return issues.flatMap((issue) => {
10871
- if (issue.code === "invalid_union") {
10872
- return issue.unionErrors.flatMap((error) => formatManifestIssues(error.issues).split("\n"));
10873
- }
10874
- return [` ${issue.path.join(".")}: ${issue.message}`];
10875
- }).join("\n");
10915
+ const { lines, unknownShape } = flattenManifestIssues(issues);
10916
+ const entries = [...new Set(
10917
+ lines.flatMap((line) => {
10918
+ const match = /^ {2}((?:assets|styles)\.[^.:\s]+)/.exec(line);
10919
+ return match ? [match[1]] : [];
10920
+ })
10921
+ )];
10922
+ const out = [];
10923
+ const version = pixelkilnVersion();
10924
+ if (unknownShape) {
10925
+ out.push(
10926
+ ` This manifest uses fields or values pixelkiln ${version ?? "(this version)"} does not know. If it was written by a newer release, run \`npx pixelkiln@latest\` or update the install before editing it.`
10927
+ );
10928
+ }
10929
+ if (entries.length) {
10930
+ out.push(` ${entries.length} invalid entr${entries.length === 1 ? "y" : "ies"}: ${entries.slice(0, 10).join(", ")}${entries.length > 10 ? ", \u2026" : ""}`);
10931
+ }
10932
+ out.push(...lines.slice(0, MAX_LISTED_MANIFEST_ISSUES));
10933
+ if (lines.length > MAX_LISTED_MANIFEST_ISSUES) {
10934
+ out.push(` \u2026 and ${lines.length - MAX_LISTED_MANIFEST_ISSUES} more`);
10935
+ }
10936
+ return out.join("\n");
10876
10937
  }
10877
10938
  function resolveStyleInheritance(styles) {
10878
10939
  const resolved = /* @__PURE__ */ new Map();
10879
10940
  const visit = (styleId, chain) => {
10880
- const cached = resolved.get(styleId);
10881
- if (cached) return cached;
10941
+ const cached2 = resolved.get(styleId);
10942
+ if (cached2) return cached2;
10882
10943
  const cycleStart = chain.indexOf(styleId);
10883
10944
  if (cycleStart >= 0) {
10884
10945
  throw new Error(
@@ -11000,7 +11061,7 @@ async function resolveSpecs(loaded, filter) {
11000
11061
  const abs = import_node_path8.default.resolve(root, rel);
11001
11062
  let hit = styleImageCache.get(abs);
11002
11063
  if (!hit) {
11003
- if (!(0, import_node_fs8.existsSync)(abs)) throw new Error(`${what} not found: ${abs}`);
11064
+ if (!(0, import_node_fs9.existsSync)(abs)) throw new Error(`${what} not found: ${abs}`);
11004
11065
  const buf = await (0, import_promises5.readFile)(abs);
11005
11066
  const metadata = imageMetadata(buf);
11006
11067
  if (!metadata) throw new Error(`${what} is not a readable PNG or JPEG: ${abs}`);
@@ -11351,7 +11412,7 @@ async function resolveSpecs(loaded, filter) {
11351
11412
  const file = memberPath(anchorSpec.outFile, "south", 0, anchorSpec.character.directions, MediaType.PNG);
11352
11413
  resolved.character = {
11353
11414
  ...resolved.character,
11354
- styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: (0, import_node_fs8.existsSync)(file) ? await sha256File(file) : null }
11415
+ styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: (0, import_node_fs9.existsSync)(file) ? await sha256File(file) : null }
11355
11416
  };
11356
11417
  }
11357
11418
  const characterParent = asset.state?.of ?? asset.animation?.of ?? asset.portrait?.of;
@@ -11364,7 +11425,7 @@ async function resolveSpecs(loaded, filter) {
11364
11425
  parentAssetId: characterParent,
11365
11426
  parentSpec,
11366
11427
  parentFile,
11367
- parentSha256: (0, import_node_fs8.existsSync)(parentFile) ? await sha256File(parentFile) : null,
11428
+ parentSha256: (0, import_node_fs9.existsSync)(parentFile) ? await sha256File(parentFile) : null,
11368
11429
  // A state and its animations keep the engine and rotations of the base.
11369
11430
  mode: resolved.character.kind === "base" ? resolved.character.mode : parentSpec.character?.mode ?? resolved.character.mode,
11370
11431
  directions: resolved.character.kind === "base" ? resolved.character.directions : parentSpec.character?.directions ?? resolved.character.directions
@@ -11402,7 +11463,7 @@ async function resolveSpecs(loaded, filter) {
11402
11463
  parentAssetId: characterParent,
11403
11464
  parentSpec,
11404
11465
  parentFile,
11405
- parentSha256: (0, import_node_fs8.existsSync)(parentFile) ? await sha256File(parentFile) : null,
11466
+ parentSha256: (0, import_node_fs9.existsSync)(parentFile) ? await sha256File(parentFile) : null,
11406
11467
  // A state and its animations keep the base's own rotation count.
11407
11468
  directions: resolved.objectPro.kind === "base" ? resolved.objectPro.directions : parentSpec.objectPro.directions
11408
11469
  };
@@ -11606,8 +11667,18 @@ async function resolveSpecs(loaded, filter) {
11606
11667
  providerOptionIdentity,
11607
11668
  providerInputIdentities.get(assetId)
11608
11669
  );
11609
- activeProvider.validate?.(resolved, resolvedImages);
11610
- const estimate = validateCostEstimate(activeProvider.id, activeProvider.estimate(resolved));
11670
+ let estimate;
11671
+ try {
11672
+ activeProvider.validate?.(resolved, resolvedImages);
11673
+ estimate = validateCostEstimate(activeProvider.id, activeProvider.estimate(resolved));
11674
+ } catch (error) {
11675
+ const message6 = error instanceof Error ? error.message : String(error);
11676
+ if (message6.includes(`assets.${assetId}`)) throw error;
11677
+ throw new Error(
11678
+ `assets.${assetId} (style "${styleId}", ${resolved.width}x${resolved.height}): ${message6}`,
11679
+ { cause: error }
11680
+ );
11681
+ }
11611
11682
  resolved.cost = estimate.amount;
11612
11683
  resolved.costUnit = estimate.unit;
11613
11684
  resolved.candidates = estimate.candidates;
@@ -11691,7 +11762,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
11691
11762
  let recordedSprite;
11692
11763
  if (vfx.recipe) {
11693
11764
  const file = import_node_path8.default.resolve(root, vfx.recipe);
11694
- if (!(0, import_node_fs8.existsSync)(file)) throw new Error(`assets.${assetId}.vfx.recipe: VFX recipe not found: ${file}`);
11765
+ if (!(0, import_node_fs9.existsSync)(file)) throw new Error(`assets.${assetId}.vfx.recipe: VFX recipe not found: ${file}`);
11695
11766
  const read = await readVfxRecipe(file).catch((error) => {
11696
11767
  throw new Error(`assets.${assetId}.vfx.recipe: ${error instanceof Error ? error.message : String(error)}`);
11697
11768
  });
@@ -11718,7 +11789,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
11718
11789
  };
11719
11790
  }
11720
11791
  async function optionalRevisionImage(file, label, requiredFormat) {
11721
- if (!(0, import_node_fs8.existsSync)(file)) return null;
11792
+ if (!(0, import_node_fs9.existsSync)(file)) return null;
11722
11793
  const bytes = await (0, import_promises5.readFile)(file);
11723
11794
  const metadata = imageMetadata(bytes);
11724
11795
  if (!metadata) throw new Error(`${label} is not a readable PNG or JPEG: ${file}`);
@@ -11728,7 +11799,7 @@ async function optionalRevisionImage(file, label, requiredFormat) {
11728
11799
  return { hash: sha256(bytes), ...metadata };
11729
11800
  }
11730
11801
  async function optionalSkeletonSet(file) {
11731
- if (!(0, import_node_fs8.existsSync)(file)) return null;
11802
+ if (!(0, import_node_fs9.existsSync)(file)) return null;
11732
11803
  const bytes = await (0, import_promises5.readFile)(file);
11733
11804
  let json;
11734
11805
  try {
@@ -11739,17 +11810,17 @@ async function optionalSkeletonSet(file) {
11739
11810
  return { hash: sha256(bytes), skeleton: parseSkeletonSet(json, file) };
11740
11811
  }
11741
11812
  async function revisionSourceMembers(stem, label) {
11742
- if ((0, import_node_fs8.existsSync)(stem)) return null;
11813
+ if ((0, import_node_fs9.existsSync)(stem)) return null;
11743
11814
  const at = (role) => memberPath(stem, role, 0, 2, MediaType.PNG);
11744
11815
  let roles = [];
11745
11816
  for (const set of [CHARACTER_DIRECTIONS_8, CHARACTER_DIRECTIONS_4]) {
11746
- if (set.every((direction) => (0, import_node_fs8.existsSync)(at(direction)))) {
11817
+ if (set.every((direction) => (0, import_node_fs9.existsSync)(at(direction)))) {
11747
11818
  roles = [...set];
11748
11819
  break;
11749
11820
  }
11750
11821
  }
11751
11822
  if (!roles.length) {
11752
- for (let index = 0; (0, import_node_fs8.existsSync)(at(`frame-${String(index).padStart(2, "0")}`)); index++) {
11823
+ for (let index = 0; (0, import_node_fs9.existsSync)(at(`frame-${String(index).padStart(2, "0")}`)); index++) {
11753
11824
  roles.push(`frame-${String(index).padStart(2, "0")}`);
11754
11825
  }
11755
11826
  }
@@ -11917,7 +11988,7 @@ function characterDirections(directions) {
11917
11988
  var import_node_path16 = __toESM(require("path"), 1);
11918
11989
 
11919
11990
  // src/env.ts
11920
- var import_node_fs9 = require("fs");
11991
+ var import_node_fs10 = require("fs");
11921
11992
  var import_node_path9 = __toESM(require("path"), 1);
11922
11993
  function loadEnvFiles(dir) {
11923
11994
  const loaded = [];
@@ -11933,9 +12004,9 @@ function envFiles(dir) {
11933
12004
  const out = [];
11934
12005
  for (const name of [".env.local", ".env"]) {
11935
12006
  const file = import_node_path9.default.join(dir, name);
11936
- if (!(0, import_node_fs9.existsSync)(file)) continue;
12007
+ if (!(0, import_node_fs10.existsSync)(file)) continue;
11937
12008
  try {
11938
- out.push([file, parseEnv((0, import_node_fs9.readFileSync)(file, "utf8"))]);
12009
+ out.push([file, parseEnv((0, import_node_fs10.readFileSync)(file, "utf8"))]);
11939
12010
  } catch {
11940
12011
  }
11941
12012
  }
@@ -11961,7 +12032,7 @@ function parseEnv(contents) {
11961
12032
  }
11962
12033
 
11963
12034
  // src/pipeline/plan.ts
11964
- var import_node_fs12 = require("fs");
12035
+ var import_node_fs13 = require("fs");
11965
12036
  var import_node_path15 = __toESM(require("path"), 1);
11966
12037
 
11967
12038
  // src/pipeline/mirror.ts
@@ -12167,7 +12238,7 @@ async function deriveMirror(spec, lock, lockPath, opts = {}) {
12167
12238
  }
12168
12239
 
12169
12240
  // src/pipeline/quality-profile.ts
12170
- var import_node_fs10 = require("fs");
12241
+ var import_node_fs11 = require("fs");
12171
12242
  var import_node_path13 = __toESM(require("path"), 1);
12172
12243
 
12173
12244
  // src/pipeline/refine.ts
@@ -13150,7 +13221,7 @@ async function qualitySource(spec, lock) {
13150
13221
  return { items: null, reason: "frame-set quality requires ordered downloaded provider outputs" };
13151
13222
  }
13152
13223
  const source = import_node_path13.default.resolve(spec.root, spec.source);
13153
- return (0, import_node_fs10.existsSync)(source) ? { items: [{ role: "source", path: source }] } : { items: null, reason: `declared source is missing: ${spec.source}` };
13224
+ return (0, import_node_fs11.existsSync)(source) ? { items: [{ role: "source", path: source }] } : { items: null, reason: `declared source is missing: ${spec.source}` };
13154
13225
  }
13155
13226
  const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
13156
13227
  if (!entry) return { items: null, reason: "raw provider output is not in the lockfile" };
@@ -13179,7 +13250,7 @@ async function qualitySource(spec, lock) {
13179
13250
  }
13180
13251
  if (role) roles.add(role);
13181
13252
  const source = currentEntryOutputPath(entry, spec, index);
13182
- if (!(0, import_node_fs10.existsSync)(source)) return { items: null, reason: `raw provider output is missing: ${source}` };
13253
+ if (!(0, import_node_fs11.existsSync)(source)) return { items: null, reason: `raw provider output is missing: ${source}` };
13183
13254
  if (await sha256File(source) !== output.sha256) {
13184
13255
  return { items: null, reason: "raw provider output was modified after download" };
13185
13256
  }
@@ -13198,7 +13269,7 @@ async function inspectQualityProfile(spec, lock) {
13198
13269
  }
13199
13270
  const sourcePaths = source.items.map((item) => item.path);
13200
13271
  const expectedOutputs = spec.generator === "frames" ? source.items.map((item, index) => qualityFrameOutputPath(output, item.role, index)) : [output];
13201
- if (!(0, import_node_fs10.existsSync)(record)) {
13272
+ if (!(0, import_node_fs11.existsSync)(record)) {
13202
13273
  return {
13203
13274
  key,
13204
13275
  state: "needs-refinement",
@@ -13379,7 +13450,7 @@ async function requireApprovedQualitySources(specs, lock, assetIds, outputRoles)
13379
13450
  }
13380
13451
 
13381
13452
  // src/pipeline/revision.ts
13382
- var import_node_fs11 = require("fs");
13453
+ var import_node_fs12 = require("fs");
13383
13454
  var import_node_path14 = __toESM(require("path"), 1);
13384
13455
  async function inspectRevisionReadiness(spec, lock) {
13385
13456
  if (spec.mirror) return inspectMirror(spec, lock, /* @__PURE__ */ new Set());
@@ -13401,7 +13472,7 @@ async function inspectStyleAnchor(spec, lock, seen) {
13401
13472
  const label = `style anchor ${spec.styleId}/${anchor.assetId}`;
13402
13473
  const dependency = await inspectParent(anchor.spec, lock, seen);
13403
13474
  if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
13404
- if (!anchor.sha256 || !(0, import_node_fs11.existsSync)(anchor.file)) return { ready: false, reason: `${label} has no generated south-facing file yet` };
13475
+ if (!anchor.sha256 || !(0, import_node_fs12.existsSync)(anchor.file)) return { ready: false, reason: `${label} has no generated south-facing file yet` };
13405
13476
  if (await sha256File(anchor.file) !== anchor.sha256) {
13406
13477
  return { ready: false, reason: `${label} changed after the manifest was resolved` };
13407
13478
  }
@@ -13438,14 +13509,14 @@ async function inspectScene(spec) {
13438
13509
  const files = [{ label: "scene image", file: scene.file, sha256: scene.sha256 }];
13439
13510
  if (scene.placement.type === "mask") files.push({ label: "scene mask", file: scene.placement.file, sha256: scene.placement.sha256 });
13440
13511
  for (const { label, file, sha256: sha2562 } of files) {
13441
- if (!sha2562 || !(0, import_node_fs11.existsSync)(file)) return { ready: false, reason: `${label} does not exist yet: ${file}` };
13512
+ if (!sha2562 || !(0, import_node_fs12.existsSync)(file)) return { ready: false, reason: `${label} does not exist yet: ${file}` };
13442
13513
  if (await sha256File(file) !== sha2562) return { ready: false, reason: `${label} changed after the manifest was resolved` };
13443
13514
  }
13444
13515
  return { ready: true, reason: "scene is current" };
13445
13516
  }
13446
13517
  async function inspectVfxSprite(spec) {
13447
13518
  const sprite = spec.vfx.sprite;
13448
- if (!sprite.sha256 || !(0, import_node_fs11.existsSync)(sprite.file)) return { ready: false, reason: `vfx sprite does not exist yet: ${sprite.file}` };
13519
+ if (!sprite.sha256 || !(0, import_node_fs12.existsSync)(sprite.file)) return { ready: false, reason: `vfx sprite does not exist yet: ${sprite.file}` };
13449
13520
  if (await sha256File(sprite.file) !== sprite.sha256) return { ready: false, reason: "vfx sprite changed after the manifest was resolved" };
13450
13521
  return { ready: true, reason: "vfx sprite is current" };
13451
13522
  }
@@ -13461,7 +13532,7 @@ async function inspectOutfit(spec, lock, seen) {
13461
13532
  const label = `outfit source ${spec.styleId}/${character.parentAssetId}`;
13462
13533
  const dependency = await inspectParent(character.parentSpec, lock, seen);
13463
13534
  if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
13464
- if (!(0, import_node_fs11.existsSync)(outfit.reference.path)) {
13535
+ if (!(0, import_node_fs12.existsSync)(outfit.reference.path)) {
13465
13536
  return { ready: false, reason: `outfit reference is missing: ${outfit.reference.path}` };
13466
13537
  }
13467
13538
  if (await sha256File(outfit.reference.path) !== outfit.reference.sha256) {
@@ -13475,7 +13546,7 @@ async function inspectCharacterParent(spec, lock, seen) {
13475
13546
  const label = `${character.kind} parent ${spec.styleId}/${character.parentAssetId}`;
13476
13547
  const dependency = await inspectParent(parentSpec, lock, seen);
13477
13548
  if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
13478
- if (!character.parentSha256 || !character.parentFile || !(0, import_node_fs11.existsSync)(character.parentFile)) {
13549
+ if (!character.parentSha256 || !character.parentFile || !(0, import_node_fs12.existsSync)(character.parentFile)) {
13479
13550
  return { ready: false, reason: `${label} has no generated south-facing file yet` };
13480
13551
  }
13481
13552
  if (await sha256File(character.parentFile) !== character.parentSha256) {
@@ -13493,7 +13564,7 @@ async function inspectObjectProParent(spec, lock, seen) {
13493
13564
  const label = `${object.kind} parent ${spec.styleId}/${object.parentAssetId}`;
13494
13565
  const dependency = await inspectParent(parentSpec, lock, seen);
13495
13566
  if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
13496
- if (!object.parentSha256 || !object.parentFile || !(0, import_node_fs11.existsSync)(object.parentFile)) {
13567
+ if (!object.parentSha256 || !object.parentFile || !(0, import_node_fs12.existsSync)(object.parentFile)) {
13497
13568
  return { ready: false, reason: `${label} has no generated south-facing file yet` };
13498
13569
  }
13499
13570
  if (await sha256File(object.parentFile) !== object.parentSha256) {
@@ -13519,7 +13590,7 @@ async function inspectRevision(spec, lock, seen) {
13519
13590
  const members = await inspectSourceMembers(spec, lock);
13520
13591
  if (!members.ready) return members;
13521
13592
  } else {
13522
- if (!revision.sourceSha256 || !(0, import_node_fs11.existsSync)(revision.sourceFile)) {
13593
+ if (!revision.sourceSha256 || !(0, import_node_fs12.existsSync)(revision.sourceFile)) {
13523
13594
  return { ready: false, reason: `revision source is missing: ${revision.sourceFile}` };
13524
13595
  }
13525
13596
  if (await sha256File(revision.sourceFile) !== revision.sourceSha256) {
@@ -13527,7 +13598,7 @@ async function inspectRevision(spec, lock, seen) {
13527
13598
  }
13528
13599
  }
13529
13600
  if (revision.maskFile) {
13530
- if (!revision.maskSha256 || !(0, import_node_fs11.existsSync)(revision.maskFile)) {
13601
+ if (!revision.maskSha256 || !(0, import_node_fs12.existsSync)(revision.maskFile)) {
13531
13602
  return { ready: false, reason: `revision mask is missing: ${revision.maskFile}` };
13532
13603
  }
13533
13604
  if (await sha256File(revision.maskFile) !== revision.maskSha256) {
@@ -13535,7 +13606,7 @@ async function inspectRevision(spec, lock, seen) {
13535
13606
  }
13536
13607
  }
13537
13608
  if (revision.lastFrameFile) {
13538
- if (!revision.lastFrameSha256 || !(0, import_node_fs11.existsSync)(revision.lastFrameFile)) {
13609
+ if (!revision.lastFrameSha256 || !(0, import_node_fs12.existsSync)(revision.lastFrameFile)) {
13539
13610
  return { ready: false, reason: `revision last frame is missing: ${revision.lastFrameFile}` };
13540
13611
  }
13541
13612
  if (await sha256File(revision.lastFrameFile) !== revision.lastFrameSha256) {
@@ -13548,7 +13619,7 @@ async function inspectSourceMembers(spec, lock) {
13548
13619
  const revision = spec.revision;
13549
13620
  const members = revision.sourceMembers;
13550
13621
  for (const member of members) {
13551
- if (!(0, import_node_fs11.existsSync)(member.file)) return { ready: false, reason: `revision source member is missing: ${member.file}` };
13622
+ if (!(0, import_node_fs12.existsSync)(member.file)) return { ready: false, reason: `revision source member is missing: ${member.file}` };
13552
13623
  if (await sha256File(member.file) !== member.sha256) {
13553
13624
  return { ready: false, reason: `revision source member changed after the manifest was resolved: ${member.file}` };
13554
13625
  }
@@ -13616,7 +13687,7 @@ async function inspectParent(spec, lock, seen) {
13616
13687
  }
13617
13688
  if (spec.source) {
13618
13689
  const source = import_node_path14.default.resolve(spec.root, spec.source);
13619
- return (0, import_node_fs11.existsSync)(source) ? { ready: true, reason: "declared source is present" } : { ready: false, reason: `declared source is missing: ${spec.source}` };
13690
+ return (0, import_node_fs12.existsSync)(source) ? { ready: true, reason: "declared source is present" } : { ready: false, reason: `declared source is missing: ${spec.source}` };
13620
13691
  }
13621
13692
  const entry = lock.entries[key];
13622
13693
  if (!entry) return { ready: false, reason: "parent is not in the lockfile" };
@@ -13630,7 +13701,7 @@ async function inspectParent(spec, lock, seen) {
13630
13701
  for (let index = 0; index < entry.outputs.length; index++) {
13631
13702
  const output = entry.outputs[index];
13632
13703
  const file = currentEntryOutputPath(entry, spec, index);
13633
- if (!(0, import_node_fs11.existsSync)(file)) return { ready: false, reason: `parent output is missing: ${file}` };
13704
+ if (!(0, import_node_fs12.existsSync)(file)) return { ready: false, reason: `parent output is missing: ${file}` };
13634
13705
  if (await sha256File(file) !== output.sha256) {
13635
13706
  return { ready: false, reason: `parent output was modified: ${file}` };
13636
13707
  }
@@ -13725,7 +13796,7 @@ async function buildPlan(specs, lock, opts = {}) {
13725
13796
  state = "missing";
13726
13797
  reason = "--force";
13727
13798
  } else if (!entry && spec.source && spec.generator !== "frames" && spec.generator !== "vfx") {
13728
- if ((0, import_node_fs12.existsSync)(import_node_path15.default.resolve(spec.root, spec.source))) {
13799
+ if ((0, import_node_fs13.existsSync)(import_node_path15.default.resolve(spec.root, spec.source))) {
13729
13800
  state = "ok";
13730
13801
  reason = `placed from ${spec.source}; not generated`;
13731
13802
  } else {
@@ -13733,7 +13804,7 @@ async function buildPlan(specs, lock, opts = {}) {
13733
13804
  reason = `declared source is missing: ${spec.source}`;
13734
13805
  }
13735
13806
  } else if (!entry) {
13736
- if ((0, import_node_fs12.existsSync)(spec.outFile)) {
13807
+ if ((0, import_node_fs13.existsSync)(spec.outFile)) {
13737
13808
  state = "untracked";
13738
13809
  reason = "file on disk, no provenance recorded";
13739
13810
  } else {
@@ -13746,7 +13817,7 @@ async function buildPlan(specs, lock, opts = {}) {
13746
13817
  } else if (spec.mirror && !mirrorCurrent(entry, lock.entries[lockKey(spec.styleId, spec.mirror.sourceAssetId)])) {
13747
13818
  state = "stale";
13748
13819
  reason = `mirror source ${spec.mirror.sourceAssetId} changed; flip it again (no generation cost)`;
13749
- } else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !(0, import_node_fs12.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
13820
+ } else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !(0, import_node_fs13.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
13750
13821
  state = "stale";
13751
13822
  reason = "mirror output missing on disk; flip it again (no generation cost)";
13752
13823
  } else if (spec.character?.kind === "outfit" && entry.outfit?.sourceSha256 !== mirrorSourceHash(lock.entries[lockKey(spec.styleId, spec.character.parentAssetId)] ?? { outputs: [] })) {
@@ -13783,9 +13854,9 @@ async function buildPlan(specs, lock, opts = {}) {
13783
13854
  } else if (entry.status !== "downloaded") {
13784
13855
  state = "in-flight";
13785
13856
  reason = `awaiting ${entry.status}`;
13786
- } else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !(0, import_node_fs12.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
13857
+ } else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !(0, import_node_fs13.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
13787
13858
  state = "orphaned";
13788
- reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !(0, import_node_fs12.existsSync)(currentEntryOutputPath(entry, spec, index))).map((o) => o.role ?? "asset").join(", ")}`;
13859
+ reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !(0, import_node_fs13.existsSync)(currentEntryOutputPath(entry, spec, index))).map((o) => o.role ?? "asset").join(", ")}`;
13789
13860
  } else if (await anyOutputModified(entry, spec)) {
13790
13861
  state = "orphaned";
13791
13862
  reason = "output modified since download";
@@ -13921,7 +13992,7 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
13921
13992
 
13922
13993
  // src/recipes.ts
13923
13994
  var import_node_path17 = __toESM(require("path"), 1);
13924
- var import_node_fs13 = require("fs");
13995
+ var import_node_fs14 = require("fs");
13925
13996
  var import_promises9 = require("fs/promises");
13926
13997
  var import_node_url = require("url");
13927
13998
  var import_zod4 = require("zod");
@@ -14124,7 +14195,7 @@ async function readRecipeFile(recipePath, bundled) {
14124
14195
  return { recipe: parsed.data, authored: raw, path: absolute, dir: import_node_path17.default.dirname(absolute), bundled };
14125
14196
  }
14126
14197
  async function walkRecipeFiles(root) {
14127
- if (!(0, import_node_fs13.existsSync)(root)) return [];
14198
+ if (!(0, import_node_fs14.existsSync)(root)) return [];
14128
14199
  const out = [];
14129
14200
  for (const entry of await (0, import_promises9.readdir)(root, { withFileTypes: true })) {
14130
14201
  const resolved = import_node_path17.default.join(root, entry.name);
@@ -14162,7 +14233,7 @@ function parseSelector(selector) {
14162
14233
  }
14163
14234
  async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
14164
14235
  const local = import_node_path17.default.resolve(target);
14165
- if ((0, import_node_fs13.existsSync)(local)) {
14236
+ if ((0, import_node_fs14.existsSync)(local)) {
14166
14237
  const recipePath = import_node_path17.default.basename(local) === RECIPE_FILE ? local : import_node_path17.default.join(local, RECIPE_FILE);
14167
14238
  return readRecipeFile(recipePath, false);
14168
14239
  }
@@ -14178,7 +14249,7 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
14178
14249
  }
14179
14250
  async function verifyFile(root, file) {
14180
14251
  const absolute = import_node_path17.default.resolve(root, ...file.path.split("/"));
14181
- if (!(0, import_node_fs13.existsSync)(absolute)) {
14252
+ if (!(0, import_node_fs14.existsSync)(absolute)) {
14182
14253
  return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
14183
14254
  }
14184
14255
  const actualSha256 = await sha256File(absolute);
@@ -14256,7 +14327,7 @@ async function installRecipe(target, options = {}) {
14256
14327
  })));
14257
14328
  if (!options.force) {
14258
14329
  for (const file of files) {
14259
- if (!(0, import_node_fs13.existsSync)(file.path)) continue;
14330
+ if (!(0, import_node_fs14.existsSync)(file.path)) continue;
14260
14331
  const current = await (0, import_promises9.readFile)(file.path);
14261
14332
  if (!current.equals(file.data)) {
14262
14333
  throw new OverwriteRefusedError(
@@ -14282,7 +14353,7 @@ async function installRecipe(target, options = {}) {
14282
14353
 
14283
14354
  // src/pipeline/audit.ts
14284
14355
  var import_promises10 = require("fs/promises");
14285
- var import_node_fs14 = require("fs");
14356
+ var import_node_fs15 = require("fs");
14286
14357
  var import_node_path18 = __toESM(require("path"), 1);
14287
14358
  function paletteDistance(asset, reference) {
14288
14359
  if (!asset.length || !reference.length) return 0;
@@ -14319,7 +14390,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
14319
14390
  const unreadable = [];
14320
14391
  for (const spec of mine) {
14321
14392
  for (const output of resolveSpecOutputs(spec, lock, loaded.root)) {
14322
- if (!(0, import_node_fs14.existsSync)(output.absolutePath)) {
14393
+ if (!(0, import_node_fs15.existsSync)(output.absolutePath)) {
14323
14394
  missing.push(output.id);
14324
14395
  continue;
14325
14396
  }
@@ -14349,7 +14420,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
14349
14420
  const refPalettes = [];
14350
14421
  for (const img of style.styleImages) {
14351
14422
  const abs = import_node_path18.default.resolve(loaded.root, img.path);
14352
- if (!(0, import_node_fs14.existsSync)(abs)) continue;
14423
+ if (!(0, import_node_fs15.existsSync)(abs)) continue;
14353
14424
  try {
14354
14425
  refPalettes.push(extractPalette(decodePng(await (0, import_promises10.readFile)(abs)), 12));
14355
14426
  } catch {
@@ -14428,7 +14499,7 @@ function hex(c) {
14428
14499
 
14429
14500
  // src/pipeline/quality-regression.ts
14430
14501
  var import_node_path19 = __toESM(require("path"), 1);
14431
- var import_node_fs15 = require("fs");
14502
+ var import_node_fs16 = require("fs");
14432
14503
  var import_promises11 = require("fs/promises");
14433
14504
  var import_zod5 = require("zod");
14434
14505
  var SHA256_RE2 = /^[0-9a-f]{64}$/;
@@ -14671,7 +14742,7 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
14671
14742
  cases
14672
14743
  });
14673
14744
  const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
14674
- if ((0, import_node_fs15.existsSync)(absolute) && !options.force) {
14745
+ if ((0, import_node_fs16.existsSync)(absolute) && !options.force) {
14675
14746
  const current = await (0, import_promises11.readFile)(absolute);
14676
14747
  if (!current.equals(data)) {
14677
14748
  throw new OverwriteRefusedError(
@@ -14683,6 +14754,63 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
14683
14754
  const result = await writeArtifactBundle([{ path: absolute, data }]);
14684
14755
  return { baseline, path: absolute, changed: result.changed.length > 0 };
14685
14756
  }
14757
+ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
14758
+ const absolute = import_node_path19.default.resolve(baselinePath);
14759
+ if (!(0, import_node_fs16.existsSync)(absolute)) {
14760
+ throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
14761
+ }
14762
+ let raw;
14763
+ try {
14764
+ raw = JSON.parse(await (0, import_promises11.readFile)(absolute, "utf8"));
14765
+ } catch (error) {
14766
+ throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
14767
+ }
14768
+ if (!Array.isArray(raw.cases)) throw new Error(`Quality baseline ${absolute} has no cases array.`);
14769
+ const byId = new Map(inputs.map((input) => [input.id, input]));
14770
+ const unknown = only.filter((id) => !byId.has(id));
14771
+ if (unknown.length) {
14772
+ throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
14773
+ }
14774
+ const root = import_node_path19.default.dirname(absolute);
14775
+ const cases = [...raw.cases];
14776
+ const report = [];
14777
+ for (const id of only) {
14778
+ const input = byId.get(id);
14779
+ if (import_node_path19.default.resolve(input.file) === absolute || input.record && import_node_path19.default.resolve(input.record) === absolute) {
14780
+ throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
14781
+ }
14782
+ const expected = await measureImageQuality(input.file);
14783
+ let record;
14784
+ if (input.record) {
14785
+ await verifyRecordForImage(input.record, input.file);
14786
+ record = { path: portableRelative2(root, input.record), sha256: await sha256File(input.record) };
14787
+ }
14788
+ const index = cases.findIndex((entry) => entry.id === id);
14789
+ const before = index >= 0 ? cases[index].expected ?? {} : {};
14790
+ const next = {
14791
+ id,
14792
+ file: portableRelative2(root, input.file),
14793
+ ...record ? { record } : {},
14794
+ expected,
14795
+ tolerances: index >= 0 && cases[index].tolerances ? cases[index].tolerances : input.tolerances
14796
+ };
14797
+ if (index >= 0) cases[index] = next;
14798
+ else cases.push(next);
14799
+ const changes = [];
14800
+ for (const metric of Object.keys(expected)) {
14801
+ if (JSON.stringify(before[metric]) !== JSON.stringify(expected[metric])) {
14802
+ changes.push({ metric, before: before[metric] ?? null, after: expected[metric] });
14803
+ }
14804
+ }
14805
+ report.push({ id, kind: index < 0 ? "added" : changes.length ? "updated" : "unchanged", changes });
14806
+ }
14807
+ const baseline = QualityBaselineSchema.parse({ ...raw, cases });
14808
+ const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
14809
+ const current = await (0, import_promises11.readFile)(absolute);
14810
+ const changed = !current.equals(data);
14811
+ if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
14812
+ return { baseline, path: absolute, changed, cases: report };
14813
+ }
14686
14814
  async function readQualityBaseline(baselinePath) {
14687
14815
  const absolute = import_node_path19.default.resolve(baselinePath);
14688
14816
  let raw;
@@ -14693,9 +14821,23 @@ async function readQualityBaseline(baselinePath) {
14693
14821
  }
14694
14822
  const parsed = QualityBaselineSchema.safeParse(raw);
14695
14823
  if (!parsed.success) {
14824
+ const cases = raw?.cases;
14825
+ const where = (issuePath) => {
14826
+ if (issuePath[0] === "cases" && typeof issuePath[1] === "number") {
14827
+ const id = cases?.[issuePath[1]]?.id;
14828
+ const rest = issuePath.slice(2).join(".");
14829
+ return typeof id === "string" ? `cases[${id}]${rest ? `.${rest}` : ""}` : issuePath.join(".");
14830
+ }
14831
+ return issuePath.join(".") || "$";
14832
+ };
14833
+ const missing = [...new Set(parsed.error.issues.flatMap((issue) => {
14834
+ const id = issue.path[0] === "cases" && typeof issue.path[1] === "number" ? cases?.[issue.path[1]]?.id : void 0;
14835
+ return issue.code === "invalid_type" && issue.received === "undefined" && typeof id === "string" ? [id] : [];
14836
+ }))];
14696
14837
  throw new Error(
14697
14838
  `Invalid quality baseline ${absolute}:
14698
- ` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
14839
+ ` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
14840
+ Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${import_node_path19.default.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
14699
14841
  );
14700
14842
  }
14701
14843
  return parsed.data;
@@ -14811,13 +14953,13 @@ async function checkQualityBaseline(baselinePath) {
14811
14953
  }
14812
14954
 
14813
14955
  // src/pipeline/cache-health.ts
14814
- var import_node_fs19 = require("fs");
14956
+ var import_node_fs20 = require("fs");
14815
14957
  var import_promises14 = require("fs/promises");
14816
14958
  var import_node_path23 = __toESM(require("path"), 1);
14817
14959
 
14818
14960
  // src/cache.ts
14819
14961
  var import_promises12 = require("fs/promises");
14820
- var import_node_fs16 = require("fs");
14962
+ var import_node_fs17 = require("fs");
14821
14963
  var import_node_path20 = __toESM(require("path"), 1);
14822
14964
  var import_zod6 = require("zod");
14823
14965
  var HashCacheSchema = import_zod6.z.object({
@@ -14833,7 +14975,7 @@ function parseCache(value) {
14833
14975
  return HashCacheSchema.parse(value);
14834
14976
  }
14835
14977
  async function loadCache(path39) {
14836
- if (!(0, import_node_fs16.existsSync)(path39)) return { version: 1, hashes: {} };
14978
+ if (!(0, import_node_fs17.existsSync)(path39)) return { version: 1, hashes: {} };
14837
14979
  try {
14838
14980
  const parsed = HashCacheSchema.safeParse(JSON.parse(await (0, import_promises12.readFile)(path39, "utf8")));
14839
14981
  if (!parsed.success) return { version: 1, hashes: {} };
@@ -14882,11 +15024,11 @@ function cachePathFor(lockPath) {
14882
15024
  }
14883
15025
 
14884
15026
  // src/pipeline/history.ts
14885
- var import_node_fs18 = require("fs");
15027
+ var import_node_fs19 = require("fs");
14886
15028
  var import_node_path22 = __toESM(require("path"), 1);
14887
15029
 
14888
15030
  // src/pipeline/fetch.ts
14889
- var import_node_fs17 = require("fs");
15031
+ var import_node_fs18 = require("fs");
14890
15032
  var import_promises13 = require("fs/promises");
14891
15033
  var import_node_path21 = __toESM(require("path"), 1);
14892
15034
  async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
@@ -14906,15 +15048,15 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
14906
15048
  if (spec && e.specHash === spec.specHash && e.outputs.length && !postprocessCurrent(e, spec)) {
14907
15049
  return Boolean(opts.force) || e.outputs.every((output) => {
14908
15050
  const file = resolveOutputPath(output.path, spec.root);
14909
- return (0, import_node_fs17.existsSync)(file) && sha256((0, import_node_fs17.readFileSync)(file)) === output.sha256;
15051
+ return (0, import_node_fs18.existsSync)(file) && sha256((0, import_node_fs18.readFileSync)(file)) === output.sha256;
14910
15052
  });
14911
15053
  }
14912
15054
  if (!opts.repair) return false;
14913
15055
  if (e.outputs.length === 0 || !spec) return true;
14914
15056
  return e.outputs.some((output) => {
14915
15057
  const file = resolveOutputPath(output.path, spec.root);
14916
- if (!(0, import_node_fs17.existsSync)(file)) return true;
14917
- const current = sha256((0, import_node_fs17.readFileSync)(file));
15058
+ if (!(0, import_node_fs18.existsSync)(file)) return true;
15059
+ const current = sha256((0, import_node_fs18.readFileSync)(file));
14918
15060
  if (current === output.sha256) return false;
14919
15061
  return Boolean(opts.force) || (e.supersededOutputs ?? []).some((old) => old.sha256 === current);
14920
15062
  });
@@ -15004,7 +15146,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
15004
15146
  }
15005
15147
  let raw = null;
15006
15148
  let final = null;
15007
- if ((0, import_node_fs17.existsSync)(target)) {
15149
+ if ((0, import_node_fs18.existsSync)(target)) {
15008
15150
  const currentHash = await sha256File(target);
15009
15151
  if (recorded && currentHash === recorded.sha256) {
15010
15152
  if (!fresh && !reapply) {
@@ -15150,7 +15292,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
15150
15292
  }
15151
15293
  async function readCachedMedia(cacheDir, hash, mediaType) {
15152
15294
  const file = import_node_path21.default.join(cacheDir, cacheFileName(hash, mediaType));
15153
- if (!(0, import_node_fs17.existsSync)(file)) return null;
15295
+ if (!(0, import_node_fs18.existsSync)(file)) return null;
15154
15296
  try {
15155
15297
  const buf = await (0, import_promises13.readFile)(file);
15156
15298
  if (sha256(buf) !== hash) return null;
@@ -15171,7 +15313,7 @@ async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
15171
15313
  try {
15172
15314
  await (0, import_promises13.rename)(tmp, file);
15173
15315
  } catch (err) {
15174
- if (!(0, import_node_fs17.existsSync)(file)) throw err;
15316
+ if (!(0, import_node_fs18.existsSync)(file)) throw err;
15175
15317
  } finally {
15176
15318
  await (0, import_promises13.rm)(tmp, { force: true });
15177
15319
  }
@@ -15293,7 +15435,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
15293
15435
  }
15294
15436
  for (let i = 0; i < entry.outputs.length; i++) {
15295
15437
  const file = currentEntryOutputPath(entry, spec, i);
15296
- if (!(0, import_node_fs18.existsSync)(file)) continue;
15438
+ if (!(0, import_node_fs19.existsSync)(file)) continue;
15297
15439
  if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
15298
15440
  throw new OverwriteRefusedError(
15299
15441
  `${import_node_path22.default.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
@@ -15356,7 +15498,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
15356
15498
 
15357
15499
  // src/pipeline/cache-health.ts
15358
15500
  async function inspectCaches(lock, lockPath, options = {}) {
15359
- if (options.prune && !(0, import_node_fs19.existsSync)(lockPath)) {
15501
+ if (options.prune && !(0, import_node_fs20.existsSync)(lockPath)) {
15360
15502
  throw new Error(`Refusing to prune without an existing lockfile at ${import_node_path23.default.resolve(lockPath)}`);
15361
15503
  }
15362
15504
  const contentDir = import_node_path23.default.resolve(import_node_path23.default.dirname(lockPath), ".pixelkiln", "cache");
@@ -15399,7 +15541,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
15399
15541
  async function inspectContentCache(contentDir, referenced) {
15400
15542
  const report = {
15401
15543
  path: contentDir,
15402
- exists: (0, import_node_fs19.existsSync)(contentDir),
15544
+ exists: (0, import_node_fs20.existsSync)(contentDir),
15403
15545
  files: 0,
15404
15546
  bytes: 0,
15405
15547
  valid: 0,
@@ -15463,7 +15605,7 @@ async function inspectContentCache(contentDir, referenced) {
15463
15605
  async function inspectRemoteHashCache(remotePath) {
15464
15606
  const report = {
15465
15607
  path: remotePath,
15466
- exists: (0, import_node_fs19.existsSync)(remotePath),
15608
+ exists: (0, import_node_fs20.existsSync)(remotePath),
15467
15609
  entries: 0,
15468
15610
  valid: 0,
15469
15611
  invalidIds: [],
@@ -15487,7 +15629,7 @@ async function inspectRemoteHashCache(remotePath) {
15487
15629
  }
15488
15630
 
15489
15631
  // src/pipeline/pack.ts
15490
- var import_node_fs20 = require("fs");
15632
+ var import_node_fs21 = require("fs");
15491
15633
  var import_node_path24 = __toESM(require("path"), 1);
15492
15634
  var DEFAULT_FRAME_SET_FPS = 12;
15493
15635
  function resolvePackInputs(raw, inputsFilePath) {
@@ -15521,7 +15663,7 @@ function packSprites(inputs, options = {}) {
15521
15663
  for (const input of ordered) {
15522
15664
  let sourceHash = null;
15523
15665
  try {
15524
- const bytes = (0, import_node_fs20.readFileSync)(input.path);
15666
+ const bytes = (0, import_node_fs21.readFileSync)(input.path);
15525
15667
  sourceHash = sha256(bytes);
15526
15668
  const png = decodePng(bytes);
15527
15669
  sprites.push({ id: input.id, width: png.width, height: png.height, pixels: png.pixels });
@@ -15680,7 +15822,7 @@ function mountSprites(placements, options) {
15680
15822
  for (const p of placements) {
15681
15823
  let sourceHash = null;
15682
15824
  try {
15683
- const bytes = (0, import_node_fs20.readFileSync)(p.path);
15825
+ const bytes = (0, import_node_fs21.readFileSync)(p.path);
15684
15826
  sourceHash = sha256(bytes);
15685
15827
  const png = decodePng(bytes);
15686
15828
  if (png.width > cellWidth || png.height > cellHeight) {
@@ -15784,7 +15926,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
15784
15926
  `Nothing to mount for style "${styleId}": ${ids.length} asset(s) declare a cell, but none has generated output or a \`source\`. Run \`pixelkiln gen --style ${styleId}\`, or point each at a file.${detail}`
15785
15927
  );
15786
15928
  }
15787
- const basePng = mount.base ? (0, import_node_fs20.readFileSync)(import_node_path24.default.resolve(manifestDir, mount.base)) : void 0;
15929
+ const basePng = mount.base ? (0, import_node_fs21.readFileSync)(import_node_path24.default.resolve(manifestDir, mount.base)) : void 0;
15788
15930
  const mounted = mountSprites(placements, {
15789
15931
  cellWidth: mount.cellWidth,
15790
15932
  cellHeight: mount.cellHeight,
@@ -16638,7 +16780,7 @@ async function poll(provider, lock, lockPath, opts = {}) {
16638
16780
  }
16639
16781
 
16640
16782
  // src/pipeline/doctor.ts
16641
- var import_node_fs21 = require("fs");
16783
+ var import_node_fs22 = require("fs");
16642
16784
  var import_promises15 = require("fs/promises");
16643
16785
  var import_node_path25 = __toESM(require("path"), 1);
16644
16786
  async function doctor(loaded, specs, lock, lockPath, opts = {}) {
@@ -16658,7 +16800,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
16658
16800
  for (const dir of dirs) {
16659
16801
  const ancestor = await nearestExistingDirectory(dir);
16660
16802
  try {
16661
- await (0, import_promises15.access)(ancestor, import_node_fs21.constants.W_OK);
16803
+ await (0, import_promises15.access)(ancestor, import_node_fs22.constants.W_OK);
16662
16804
  } catch {
16663
16805
  unwritable.push(dir);
16664
16806
  }
@@ -16706,11 +16848,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
16706
16848
  const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
16707
16849
  let hasCache = false;
16708
16850
  for (const output of entry.outputs) {
16709
- const cached = import_node_path25.default.join(
16851
+ const cached2 = import_node_path25.default.join(
16710
16852
  cacheDir,
16711
16853
  cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
16712
16854
  );
16713
- if ((0, import_node_fs21.existsSync)(cached) && await sha256File(cached) === output.sha256) {
16855
+ if ((0, import_node_fs22.existsSync)(cached2) && await sha256File(cached2) === output.sha256) {
16714
16856
  hasCache = true;
16715
16857
  break;
16716
16858
  }
@@ -16813,7 +16955,7 @@ async function nearestExistingDirectory(start) {
16813
16955
  }
16814
16956
 
16815
16957
  // src/pipeline/adopt.ts
16816
- var import_node_fs22 = require("fs");
16958
+ var import_node_fs23 = require("fs");
16817
16959
  var import_promises16 = require("fs/promises");
16818
16960
  var import_node_path26 = __toESM(require("path"), 1);
16819
16961
  async function adopt(provider, specs, lock, lockPath, opts = {}) {
@@ -16826,7 +16968,7 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
16826
16968
  const localByHash = /* @__PURE__ */ new Map();
16827
16969
  const unmatchedLocal = [];
16828
16970
  for (const spec of specs) {
16829
- if (!(0, import_node_fs22.existsSync)(spec.outFile)) {
16971
+ if (!(0, import_node_fs23.existsSync)(spec.outFile)) {
16830
16972
  unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
16831
16973
  continue;
16832
16974
  }
@@ -16947,13 +17089,124 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
16947
17089
  return count;
16948
17090
  }
16949
17091
 
16950
- // src/pick/server.ts
17092
+ // src/pipeline/import.ts
16951
17093
  var import_node_fs24 = require("fs");
16952
- var import_promises19 = require("fs/promises");
17094
+ var import_promises17 = require("fs/promises");
17095
+ function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
17096
+ const png = decodePng(bytes);
17097
+ const at = now.toISOString();
17098
+ return {
17099
+ styleId: spec.styleId,
17100
+ assetId: spec.assetId,
17101
+ specHash: spec.specHash,
17102
+ generator: spec.generator,
17103
+ prompt: spec.prompt,
17104
+ width: png.width,
17105
+ height: png.height,
17106
+ jobId: opts.objectId ?? null,
17107
+ objectId: opts.objectId ?? null,
17108
+ reviewObjectId: null,
17109
+ candidateIndex: null,
17110
+ status: "downloaded",
17111
+ error: null,
17112
+ sourceUrl: null,
17113
+ sourceUrls: [],
17114
+ outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
17115
+ submittedAt: null,
17116
+ downloadedAt: at,
17117
+ cost: 0,
17118
+ costUnit: spec.costUnit,
17119
+ provider: spec.provider,
17120
+ imported: {
17121
+ source: opts.source ?? "external",
17122
+ ...opts.note ? { note: opts.note } : {},
17123
+ importedAt: at
17124
+ }
17125
+ };
17126
+ }
17127
+ function unimportable(spec) {
17128
+ if (spec.character) return "a character is several files; import it with account adopt";
17129
+ if (spec.vfx) return "an effect is rendered from its recipe, not imported";
17130
+ if (!spec.outFile.toLowerCase().endsWith(".png")) return "only a single PNG output can be imported";
17131
+ return null;
17132
+ }
17133
+ async function importLocal(specs, lock, lockPath, opts = {}) {
17134
+ if (opts.objectId && specs.length !== 1) {
17135
+ throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
17136
+ }
17137
+ const imported = [];
17138
+ const skipped = [];
17139
+ for (const spec of specs) {
17140
+ const key = lockKey(spec.styleId, spec.assetId);
17141
+ const reason = unimportable(spec);
17142
+ if (reason) {
17143
+ skipped.push({ key, reason });
17144
+ continue;
17145
+ }
17146
+ if (!(0, import_node_fs24.existsSync)(spec.outFile)) {
17147
+ skipped.push({ key, reason: `no file at ${spec.outFile}` });
17148
+ continue;
17149
+ }
17150
+ if (lock.entries[key] && !opts.force) {
17151
+ skipped.push({ key, reason: "already in the lockfile (use --force to replace it)" });
17152
+ continue;
17153
+ }
17154
+ let patch;
17155
+ try {
17156
+ patch = buildImportedEntry(spec, await (0, import_promises17.readFile)(spec.outFile), opts);
17157
+ } catch (error) {
17158
+ skipped.push({ key, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
17159
+ continue;
17160
+ }
17161
+ if (opts.dryRun) {
17162
+ imported.push({ key, entry: patch });
17163
+ continue;
17164
+ }
17165
+ imported.push({ key, entry: upsert(lock, key, patch) });
17166
+ }
17167
+ if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
17168
+ return { imported, skipped };
17169
+ }
17170
+ async function reportSpecHashes(specs, lock) {
17171
+ const reports = [];
17172
+ for (const spec of specs) {
17173
+ const key = lockKey(spec.styleId, spec.assetId);
17174
+ let bytes = null;
17175
+ if ((0, import_node_fs24.existsSync)(spec.outFile)) bytes = await (0, import_promises17.readFile)(spec.outFile);
17176
+ let wouldImport = null;
17177
+ if (bytes && !unimportable(spec)) {
17178
+ try {
17179
+ wouldImport = buildImportedEntry(spec, bytes);
17180
+ } catch {
17181
+ wouldImport = null;
17182
+ }
17183
+ }
17184
+ const entry = lock.entries[key];
17185
+ const fileSha256 = bytes ? sha256(bytes) : null;
17186
+ const outputSha256 = entry?.outputs[0]?.sha256 ?? null;
17187
+ reports.push({
17188
+ key,
17189
+ specHash: spec.specHash,
17190
+ file: spec.outFile,
17191
+ fileSha256,
17192
+ lock: entry ? {
17193
+ specHash: entry.specHash,
17194
+ outputSha256,
17195
+ matches: entry.specHash === spec.specHash && outputSha256 !== null && outputSha256 === fileSha256
17196
+ } : null,
17197
+ wouldImport
17198
+ });
17199
+ }
17200
+ return reports;
17201
+ }
17202
+
17203
+ // src/pick/server.ts
17204
+ var import_node_fs26 = require("fs");
17205
+ var import_promises20 = require("fs/promises");
16953
17206
 
16954
17207
  // src/pipeline/init.ts
16955
- var import_promises17 = require("fs/promises");
16956
- var import_node_fs23 = require("fs");
17208
+ var import_promises18 = require("fs/promises");
17209
+ var import_node_fs25 = require("fs");
16957
17210
  var import_node_path27 = __toESM(require("path"), 1);
16958
17211
  function pngSize(buf) {
16959
17212
  if (buf.length < 24) return null;
@@ -16967,7 +17220,7 @@ function slugify(value) {
16967
17220
  }
16968
17221
  async function walk(dir, exclude) {
16969
17222
  const out = [];
16970
- for (const entry of await (0, import_promises17.readdir)(dir, { withFileTypes: true })) {
17223
+ for (const entry of await (0, import_promises18.readdir)(dir, { withFileTypes: true })) {
16971
17224
  const full = import_node_path27.default.join(dir, entry.name);
16972
17225
  if (exclude.some((x) => full.includes(x))) continue;
16973
17226
  if (entry.isDirectory()) out.push(...await walk(full, exclude));
@@ -16982,7 +17235,7 @@ async function scanAssets(root, opts = {}) {
16982
17235
  const skipped = [];
16983
17236
  const seen = /* @__PURE__ */ new Map();
16984
17237
  for (const file of files.sort()) {
16985
- const size = pngSize(await (0, import_promises17.readFile)(file));
17238
+ const size = pngSize(await (0, import_promises18.readFile)(file));
16986
17239
  if (!size) {
16987
17240
  skipped.push(`${file} (not a readable PNG)`);
16988
17241
  continue;
@@ -17463,7 +17716,7 @@ document.getElementById('submit').onclick = async () => {
17463
17716
 
17464
17717
  // src/pick/review-server.ts
17465
17718
  var import_node_http = require("http");
17466
- var import_promises18 = require("fs/promises");
17719
+ var import_promises19 = require("fs/promises");
17467
17720
  function serveReviewPage(opts) {
17468
17721
  const log = opts.onProgress ?? (() => {
17469
17722
  });
@@ -17472,7 +17725,7 @@ function serveReviewPage(opts) {
17472
17725
  if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
17473
17726
  try {
17474
17727
  const asset = opts.assets.get(req.url);
17475
- const bytes = await (0, import_promises18.readFile)(asset.path);
17728
+ const bytes = await (0, import_promises19.readFile)(asset.path);
17476
17729
  res.writeHead(200, {
17477
17730
  "Content-Type": asset.contentType,
17478
17731
  "Cache-Control": "no-store",
@@ -17548,13 +17801,13 @@ async function currentArt(entry, spec) {
17548
17801
  const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
17549
17802
  if (!previous) return null;
17550
17803
  const file = resolveOutputPath(previous.path, spec.root);
17551
- if (!(0, import_node_fs24.existsSync)(file)) return null;
17804
+ if (!(0, import_node_fs26.existsSync)(file)) return null;
17552
17805
  const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
17553
17806
  if (!contentType) return null;
17554
17807
  let width = entry.width;
17555
17808
  let height = entry.height;
17556
17809
  if (contentType === "image/png") {
17557
- const size = pngSize(await (0, import_promises19.readFile)(file));
17810
+ const size = pngSize(await (0, import_promises20.readFile)(file));
17558
17811
  if (size) ({ width, height } = size);
17559
17812
  }
17560
17813
  return { path: file, contentType, width, height };
@@ -17562,7 +17815,7 @@ async function currentArt(entry, spec) {
17562
17815
  async function cachedFrame(url) {
17563
17816
  if (!url.startsWith("file://")) return null;
17564
17817
  const file = url.slice("file://".length);
17565
- const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await (0, import_promises19.readFile)(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
17818
+ const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await (0, import_promises20.readFile)(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
17566
17819
  return { path: file, contentType };
17567
17820
  }
17568
17821
  async function prepareReview(provider, lock, opts = {}) {
@@ -17588,15 +17841,15 @@ async function prepareReview(provider, lock, opts = {}) {
17588
17841
  const frameAssets = [];
17589
17842
  const frameSizes = [];
17590
17843
  for (const [index, url] of urls.entries()) {
17591
- const cached = await cachedFrame(url);
17592
- if (!cached) {
17844
+ const cached2 = await cachedFrame(url);
17845
+ if (!cached2) {
17593
17846
  frameUrls.push(url);
17594
17847
  frameSizes.push(null);
17595
17848
  continue;
17596
17849
  }
17597
- frameSizes.push(cached.contentType === "image/png" ? pngSize(await (0, import_promises19.readFile)(cached.path).catch(() => Buffer.alloc(0))) : null);
17850
+ frameSizes.push(cached2.contentType === "image/png" ? pngSize(await (0, import_promises20.readFile)(cached2.path).catch(() => Buffer.alloc(0))) : null);
17598
17851
  const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
17599
- frameAssets.push([route, cached]);
17852
+ frameAssets.push([route, cached2]);
17600
17853
  frameUrls.push(route);
17601
17854
  }
17602
17855
  const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String(groups.length))}` : null;
@@ -17748,13 +18001,13 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
17748
18001
 
17749
18002
  // src/gallery/snapshot.ts
17750
18003
  var import_node_crypto7 = require("crypto");
17751
- var import_node_fs30 = require("fs");
17752
- var import_promises27 = require("fs/promises");
18004
+ var import_node_fs32 = require("fs");
18005
+ var import_promises28 = require("fs/promises");
17753
18006
  var import_node_path35 = __toESM(require("path"), 1);
17754
18007
 
17755
18008
  // src/workspace.ts
17756
- var import_promises20 = require("fs/promises");
17757
- var import_node_fs25 = require("fs");
18009
+ var import_promises21 = require("fs/promises");
18010
+ var import_node_fs27 = require("fs");
17758
18011
  var import_node_path28 = __toESM(require("path"), 1);
17759
18012
  var import_zod7 = require("zod");
17760
18013
  var WorkspaceProjectSchema = import_zod7.z.object({
@@ -17780,10 +18033,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
17780
18033
  );
17781
18034
  }
17782
18035
  async function loadWorkspace(workspacePath) {
17783
- if (!(0, import_node_fs25.existsSync)(workspacePath)) return { version: 1, projects: [] };
18036
+ if (!(0, import_node_fs27.existsSync)(workspacePath)) return { version: 1, projects: [] };
17784
18037
  let raw;
17785
18038
  try {
17786
- raw = JSON.parse(await (0, import_promises20.readFile)(workspacePath, "utf8"));
18039
+ raw = JSON.parse(await (0, import_promises21.readFile)(workspacePath, "utf8"));
17787
18040
  } catch (err) {
17788
18041
  throw new ProjectError(
17789
18042
  `Workspace catalog at ${workspacePath} is malformed:
@@ -17797,13 +18050,13 @@ async function saveWorkspace(workspacePath, ws) {
17797
18050
  version: 1,
17798
18051
  projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
17799
18052
  };
17800
- await (0, import_promises20.mkdir)(import_node_path28.default.dirname(import_node_path28.default.resolve(workspacePath)), { recursive: true });
18053
+ await (0, import_promises21.mkdir)(import_node_path28.default.dirname(import_node_path28.default.resolve(workspacePath)), { recursive: true });
17801
18054
  const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
17802
18055
  try {
17803
- await (0, import_promises20.writeFile)(tmp, JSON.stringify(sorted, null, 2) + "\n");
17804
- await (0, import_promises20.rename)(tmp, workspacePath);
18056
+ await (0, import_promises21.writeFile)(tmp, JSON.stringify(sorted, null, 2) + "\n");
18057
+ await (0, import_promises21.rename)(tmp, workspacePath);
17805
18058
  } finally {
17806
- await (0, import_promises20.rm)(tmp, { force: true });
18059
+ await (0, import_promises21.rm)(tmp, { force: true });
17807
18060
  }
17808
18061
  }
17809
18062
  function toPortablePath(dir, absolute) {
@@ -17832,14 +18085,14 @@ function validateWorkspace(ws, dir) {
17832
18085
  message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
17833
18086
  });
17834
18087
  }
17835
- if (!(0, import_node_fs25.existsSync)(manifestPath)) {
18088
+ if (!(0, import_node_fs27.existsSync)(manifestPath)) {
17836
18089
  diagnostics.push({
17837
18090
  id: "missing-manifest",
17838
18091
  level: "error",
17839
18092
  message: `project "${project.id}" manifest not found: ${manifestPath}`
17840
18093
  });
17841
18094
  }
17842
- if (!(0, import_node_fs25.existsSync)(lockPath)) {
18095
+ if (!(0, import_node_fs27.existsSync)(lockPath)) {
17843
18096
  diagnostics.push({
17844
18097
  id: "missing-lock",
17845
18098
  level: "error",
@@ -17886,12 +18139,12 @@ function validateWorkspace(ws, dir) {
17886
18139
  }
17887
18140
 
17888
18141
  // src/gallery/edit.ts
17889
- var import_promises26 = require("fs/promises");
18142
+ var import_promises27 = require("fs/promises");
17890
18143
  var import_node_path34 = __toESM(require("path"), 1);
17891
18144
  var import_zod13 = require("zod");
17892
18145
 
17893
18146
  // src/manifest-edit.ts
17894
- var import_promises21 = require("fs/promises");
18147
+ var import_promises22 = require("fs/promises");
17895
18148
  var import_node_path29 = __toESM(require("path"), 1);
17896
18149
  var import_zod8 = require("zod");
17897
18150
  var HexSha = import_zod8.z.string().regex(/^[0-9a-f]{64}$/);
@@ -18316,7 +18569,7 @@ function applyEdit(raw, edit) {
18316
18569
  }
18317
18570
  async function withCandidate(manifestPath, edit, use, unchanged) {
18318
18571
  const absolute = import_node_path29.default.resolve(manifestPath);
18319
- const original = await (0, import_promises21.readFile)(absolute, "utf8");
18572
+ const original = await (0, import_promises22.readFile)(absolute, "utf8");
18320
18573
  if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
18321
18574
  let raw;
18322
18575
  try {
@@ -18334,7 +18587,7 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
18334
18587
  `.${import_node_path29.default.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
18335
18588
  );
18336
18589
  try {
18337
- await (0, import_promises21.writeFile)(tmp, next);
18590
+ await (0, import_promises22.writeFile)(tmp, next);
18338
18591
  let specs;
18339
18592
  try {
18340
18593
  specs = await resolveSpecs(await loadManifest(tmp));
@@ -18344,7 +18597,7 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
18344
18597
  }
18345
18598
  return await use({ absolute, original, next, tmp, specs });
18346
18599
  } finally {
18347
- await (0, import_promises21.rm)(tmp, { force: true });
18600
+ await (0, import_promises22.rm)(tmp, { force: true });
18348
18601
  }
18349
18602
  }
18350
18603
  async function applyManifestEdit(manifestPath, edit) {
@@ -18352,7 +18605,7 @@ async function applyManifestEdit(manifestPath, edit) {
18352
18605
  manifestPath,
18353
18606
  edit,
18354
18607
  async ({ absolute, next, tmp }) => {
18355
- await (0, import_promises21.rename)(tmp, absolute);
18608
+ await (0, import_promises22.rename)(tmp, absolute);
18356
18609
  return { manifestPath: absolute, sha256: sha256(next), changed: true };
18357
18610
  },
18358
18611
  (absolute, original) => ({ manifestPath: absolute, sha256: sha256(original), changed: false })
@@ -18360,8 +18613,8 @@ async function applyManifestEdit(manifestPath, edit) {
18360
18613
  }
18361
18614
 
18362
18615
  // src/pipeline/hand-edit.ts
18363
- var import_node_fs26 = require("fs");
18364
- var import_promises22 = require("fs/promises");
18616
+ var import_node_fs28 = require("fs");
18617
+ var import_promises23 = require("fs/promises");
18365
18618
  var import_node_path30 = __toESM(require("path"), 1);
18366
18619
  var import_zod9 = require("zod");
18367
18620
  var HAND_EDIT_DIR = "edits";
@@ -18384,10 +18637,10 @@ function handEditBases(spec, lock) {
18384
18637
  }));
18385
18638
  if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
18386
18639
  if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
18387
- if (!members.every((member) => (0, import_node_fs26.existsSync)(member.path))) return null;
18640
+ if (!members.every((member) => (0, import_node_fs28.existsSync)(member.path))) return null;
18388
18641
  return members.map(({ role, path: file }) => ({ role, path: file }));
18389
18642
  }
18390
- return (0, import_node_fs26.existsSync)(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
18643
+ return (0, import_node_fs28.existsSync)(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
18391
18644
  }
18392
18645
  function handEditBase(spec, lock) {
18393
18646
  const bases = handEditBases(spec, lock);
@@ -18422,14 +18675,14 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
18422
18675
  const members = handEditMembers(loaded, spec, lock, editPath);
18423
18676
  let created = false;
18424
18677
  for (const member of members) {
18425
- if ((0, import_node_fs26.existsSync)(member.path)) continue;
18678
+ if ((0, import_node_fs28.existsSync)(member.path)) continue;
18426
18679
  if (!member.base) {
18427
18680
  throw new ManifestEditError(
18428
18681
  `${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
18429
18682
  );
18430
18683
  }
18431
- await (0, import_promises22.mkdir)(import_node_path30.default.dirname(member.path), { recursive: true });
18432
- await (0, import_promises22.copyFile)(member.base, member.path);
18684
+ await (0, import_promises23.mkdir)(import_node_path30.default.dirname(member.path), { recursive: true });
18685
+ await (0, import_promises23.copyFile)(member.base, member.path);
18433
18686
  created = true;
18434
18687
  }
18435
18688
  const source = portableOutputPath(editPath, loaded.root);
@@ -18507,7 +18760,7 @@ function handEditProjectPath(editPath) {
18507
18760
  async function readHandEditCompanion(editPath) {
18508
18761
  let text;
18509
18762
  try {
18510
- text = await (0, import_promises22.readFile)(handEditCompanionPath(editPath), "utf8");
18763
+ text = await (0, import_promises23.readFile)(handEditCompanionPath(editPath), "utf8");
18511
18764
  } catch {
18512
18765
  return null;
18513
18766
  }
@@ -18550,7 +18803,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
18550
18803
  }
18551
18804
  });
18552
18805
  const bases = handEditBases(spec, lock);
18553
- const expectedSize = bases?.[0] ? decodePng(await (0, import_promises22.readFile)(bases[0].path)) : { width: spec.width, height: spec.height };
18806
+ const expectedSize = bases?.[0] ? decodePng(await (0, import_promises23.readFile)(bases[0].path)) : { width: spec.width, height: spec.height };
18554
18807
  for (const [index, image] of decoded.entries()) {
18555
18808
  if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
18556
18809
  const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
@@ -18596,10 +18849,10 @@ function basedOnHash(entry, index) {
18596
18849
  async function replaceFile(file, bytes) {
18597
18850
  const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
18598
18851
  try {
18599
- await (0, import_promises22.writeFile)(tmp, bytes);
18600
- await (0, import_promises22.rename)(tmp, file);
18852
+ await (0, import_promises23.writeFile)(tmp, bytes);
18853
+ await (0, import_promises23.rename)(tmp, file);
18601
18854
  } finally {
18602
- await (0, import_promises22.rm)(tmp, { force: true });
18855
+ await (0, import_promises23.rm)(tmp, { force: true });
18603
18856
  }
18604
18857
  }
18605
18858
  function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
@@ -18608,8 +18861,8 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
18608
18861
  }
18609
18862
 
18610
18863
  // src/gallery/upload.ts
18611
- var import_node_fs27 = require("fs");
18612
- var import_promises23 = require("fs/promises");
18864
+ var import_node_fs29 = require("fs");
18865
+ var import_promises24 = require("fs/promises");
18613
18866
  var import_node_path31 = __toESM(require("path"), 1);
18614
18867
  var import_zod10 = require("zod");
18615
18868
  var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
@@ -18640,17 +18893,17 @@ async function saveProjectImage(root, request) {
18640
18893
  if (metadata.format !== expected) {
18641
18894
  throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
18642
18895
  }
18643
- if ((0, import_node_fs27.existsSync)(file) && !request.overwrite) {
18896
+ if ((0, import_node_fs29.existsSync)(file) && !request.overwrite) {
18644
18897
  throw new ManifestEditError(`${relative.split(import_node_path31.default.sep).join("/")} already exists; choose another name, or replace it`);
18645
18898
  }
18646
- await (0, import_promises23.mkdir)(import_node_path31.default.dirname(file), { recursive: true });
18647
- await (0, import_promises23.writeFile)(file, bytes);
18899
+ await (0, import_promises24.mkdir)(import_node_path31.default.dirname(file), { recursive: true });
18900
+ await (0, import_promises24.writeFile)(file, bytes);
18648
18901
  return relative.split(import_node_path31.default.sep).join("/");
18649
18902
  }
18650
18903
 
18651
18904
  // src/gallery/image-revision.ts
18652
- var import_node_fs28 = require("fs");
18653
- var import_promises24 = require("fs/promises");
18905
+ var import_node_fs30 = require("fs");
18906
+ var import_promises25 = require("fs/promises");
18654
18907
  var import_node_path32 = __toESM(require("path"), 1);
18655
18908
  var import_zod11 = require("zod");
18656
18909
  var InpaintRevisionRequestSchema = import_zod11.z.object({
@@ -18678,7 +18931,7 @@ async function createInpaintRevision(manifestPath, request) {
18678
18931
  const metadata = imageMetadata(bytes);
18679
18932
  if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
18680
18933
  const file = import_node_path32.default.resolve(root, request.maskPath);
18681
- const previous = (0, import_node_fs28.existsSync)(file) ? await (0, import_promises24.readFile)(file) : null;
18934
+ const previous = (0, import_node_fs30.existsSync)(file) ? await (0, import_promises25.readFile)(file) : null;
18682
18935
  const mask = await saveProjectImage(root, {
18683
18936
  action: "upload-image",
18684
18937
  path: request.maskPath,
@@ -18697,16 +18950,16 @@ async function createInpaintRevision(manifestPath, request) {
18697
18950
  }
18698
18951
  });
18699
18952
  } catch (error) {
18700
- if (previous) await (0, import_promises24.writeFile)(file, previous);
18701
- else await (0, import_promises24.rm)(file, { force: true });
18953
+ if (previous) await (0, import_promises25.writeFile)(file, previous);
18954
+ else await (0, import_promises25.rm)(file, { force: true });
18702
18955
  throw error;
18703
18956
  }
18704
18957
  return mask;
18705
18958
  }
18706
18959
 
18707
18960
  // src/gallery/skeleton.ts
18708
- var import_node_fs29 = require("fs");
18709
- var import_promises25 = require("fs/promises");
18961
+ var import_node_fs31 = require("fs");
18962
+ var import_promises26 = require("fs/promises");
18710
18963
  var import_node_path33 = __toESM(require("path"), 1);
18711
18964
  var import_zod12 = require("zod");
18712
18965
  var SkeletonEstimateRequestSchema = import_zod12.z.object({
@@ -18752,15 +19005,15 @@ async function createSkeletonAnimation(manifestPath, request) {
18752
19005
  if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || import_node_path33.default.isAbsolute(relative)) {
18753
19006
  throw new ManifestEditError("the keypoints file must be a .json path inside the project");
18754
19007
  }
18755
- const existed = (0, import_node_fs29.existsSync)(file);
19008
+ const existed = (0, import_node_fs31.existsSync)(file);
18756
19009
  let previous = null;
18757
19010
  if (request.set) {
18758
19011
  if (existed && !request.overwrite) {
18759
19012
  throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
18760
19013
  }
18761
- if (existed) previous = await (0, import_promises25.readFile)(file);
18762
- await (0, import_promises25.mkdir)(import_node_path33.default.dirname(file), { recursive: true });
18763
- await (0, import_promises25.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
19014
+ if (existed) previous = await (0, import_promises26.readFile)(file);
19015
+ await (0, import_promises26.mkdir)(import_node_path33.default.dirname(file), { recursive: true });
19016
+ await (0, import_promises26.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
18764
19017
  } else if (!existed) {
18765
19018
  throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
18766
19019
  }
@@ -18784,8 +19037,8 @@ async function createSkeletonAnimation(manifestPath, request) {
18784
19037
  });
18785
19038
  } catch (error) {
18786
19039
  if (request.set) {
18787
- if (previous) await (0, import_promises25.writeFile)(file, previous);
18788
- else await (0, import_promises25.rm)(file, { force: true });
19040
+ if (previous) await (0, import_promises26.writeFile)(file, previous);
19041
+ else await (0, import_promises26.rm)(file, { force: true });
18789
19042
  }
18790
19043
  throw error;
18791
19044
  }
@@ -18800,14 +19053,14 @@ async function updateSkeletonKeypoints(ctx, request) {
18800
19053
  if (relative.startsWith("..") || import_node_path33.default.isAbsolute(relative)) {
18801
19054
  throw new ManifestEditError(`${key}'s keypoints file is outside the project; edit it by hand`);
18802
19055
  }
18803
- const current = (0, import_node_fs29.existsSync)(file) ? sha256(await (0, import_promises25.readFile)(file)) : null;
19056
+ const current = (0, import_node_fs31.existsSync)(file) ? sha256(await (0, import_promises26.readFile)(file)) : null;
18804
19057
  if (current !== request.expectedSha256) {
18805
19058
  throw Object.assign(
18806
19059
  new Error(`${relative.split(import_node_path33.default.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
18807
19060
  { status: 409 }
18808
19061
  );
18809
19062
  }
18810
- await (0, import_promises25.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
19063
+ await (0, import_promises26.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
18811
19064
  return relative.split(import_node_path33.default.sep).join("/");
18812
19065
  }
18813
19066
 
@@ -18872,7 +19125,7 @@ function createGalleryEditHandler(opts) {
18872
19125
  if (undo.success) {
18873
19126
  const manifestPath2 = await manifestOf(undo.data.project);
18874
19127
  if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
18875
- const current = await (0, import_promises26.readFile)(manifestPath2, "utf8");
19128
+ const current = await (0, import_promises27.readFile)(manifestPath2, "utf8");
18876
19129
  if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
18877
19130
  const stack = history.get(manifestPath2) ?? [];
18878
19131
  const last = stack[stack.length - 1];
@@ -18882,17 +19135,17 @@ function createGalleryEditHandler(opts) {
18882
19135
  throw Object.assign(new Error("the manifest changed outside the gallery since its last edit; undo would discard that change"), { status: 409 });
18883
19136
  }
18884
19137
  const tmp = manifestPath2 + ".pixelkiln-undo";
18885
- await (0, import_promises26.writeFile)(tmp, last.before);
18886
- await (0, import_promises26.rename)(tmp, manifestPath2);
19138
+ await (0, import_promises27.writeFile)(tmp, last.before);
19139
+ await (0, import_promises27.rename)(tmp, manifestPath2);
18887
19140
  stack.pop();
18888
19141
  log(` manifest edit undone in ${import_node_path34.default.relative(process.cwd(), manifestPath2) || manifestPath2}`);
18889
19142
  return opts.reload();
18890
19143
  }
18891
19144
  const manifestPath = await manifestOf(body?.project);
18892
- const before = manifestPath ? await (0, import_promises26.readFile)(manifestPath, "utf8").catch(() => null) : null;
19145
+ const before = manifestPath ? await (0, import_promises27.readFile)(manifestPath, "utf8").catch(() => null) : null;
18893
19146
  const build = await apply(body);
18894
19147
  if (manifestPath && before !== null) {
18895
- const after = await (0, import_promises26.readFile)(manifestPath, "utf8").catch(() => null);
19148
+ const after = await (0, import_promises27.readFile)(manifestPath, "utf8").catch(() => null);
18896
19149
  if (after !== null && after !== before) {
18897
19150
  const stack = history.get(manifestPath) ?? [];
18898
19151
  stack.push({ before, afterSha: sha256(after) });
@@ -19068,7 +19321,7 @@ function describeHistory(media, entry, cacheDir) {
19068
19321
  const mediaType = output.mediaType ?? MediaType.PNG;
19069
19322
  const file = import_node_path35.default.join(cacheDir, cacheFileName(output.sha256, mediaType));
19070
19323
  let url = null;
19071
- if ((0, import_node_fs30.existsSync)(file)) {
19324
+ if ((0, import_node_fs32.existsSync)(file)) {
19072
19325
  const id = galleryMediaId(file);
19073
19326
  media.set(id, { path: file, contentType: mediaType });
19074
19327
  url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
@@ -19100,7 +19353,7 @@ function describeHistory(media, entry, cacheDir) {
19100
19353
  var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
19101
19354
  async function samePixels(a, b) {
19102
19355
  try {
19103
- const [left, right] = await Promise.all([(0, import_promises27.readFile)(a), (0, import_promises27.readFile)(b)]);
19356
+ const [left, right] = await Promise.all([(0, import_promises28.readFile)(a), (0, import_promises28.readFile)(b)]);
19104
19357
  if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
19105
19358
  const x = decodePng(left);
19106
19359
  const y = decodePng(right);
@@ -19166,7 +19419,7 @@ function describeCharacter(spec, entry) {
19166
19419
  }
19167
19420
  async function fileInfo(absolutePath) {
19168
19421
  try {
19169
- const info = await (0, import_promises27.stat)(absolutePath);
19422
+ const info = await (0, import_promises28.stat)(absolutePath);
19170
19423
  return info.isFile() ? { bytes: info.size, modifiedAt: info.mtime.toISOString() } : null;
19171
19424
  } catch {
19172
19425
  return null;
@@ -19201,7 +19454,7 @@ async function describeQuality(media, root, inspection) {
19201
19454
  outputPaths.map((file) => describeOutput(media, root, import_node_path35.default.resolve(root, file)))
19202
19455
  );
19203
19456
  const recordPath = import_node_path35.default.resolve(root, inspection.record);
19204
- const recordExists = (0, import_node_fs30.existsSync)(recordPath);
19457
+ const recordExists = (0, import_node_fs32.existsSync)(recordPath);
19205
19458
  let options = null;
19206
19459
  let check = null;
19207
19460
  if (recordExists) {
@@ -19258,7 +19511,7 @@ async function buildGallerySnapshot(opts) {
19258
19511
  const media = /* @__PURE__ */ new Map();
19259
19512
  const plan = await buildPlan(specs, lock);
19260
19513
  const items = [];
19261
- const manifestText = await (0, import_promises27.readFile)(loaded.path, "utf8");
19514
+ const manifestText = await (0, import_promises28.readFile)(loaded.path, "utf8");
19262
19515
  const manifestSha256 = sha256(manifestText);
19263
19516
  const cacheDir = import_node_path35.default.resolve(import_node_path35.default.dirname(opts.lockPath), ".pixelkiln", "cache");
19264
19517
  let rawStyles = {};
@@ -19289,7 +19542,7 @@ async function buildGallerySnapshot(opts) {
19289
19542
  const editShas = await Promise.all(
19290
19543
  Array.from({ length: memberCount }, async (_, index) => {
19291
19544
  const file = sourceOutputPath(spec.source, entry, index, root);
19292
- return { file, sha256: (0, import_node_fs30.existsSync)(file) ? await sha256File(file) : null };
19545
+ return { file, sha256: (0, import_node_fs32.existsSync)(file) ? await sha256File(file) : null };
19293
19546
  })
19294
19547
  );
19295
19548
  edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
@@ -19297,7 +19550,7 @@ async function buildGallerySnapshot(opts) {
19297
19550
  const companion = await readHandEditCompanion(editPath);
19298
19551
  if (companion) {
19299
19552
  const projectPath = handEditProjectPath(editPath);
19300
- const project = companion.project && (0, import_node_fs30.existsSync)(projectPath) ? await fileInfo(projectPath) : null;
19553
+ const project = companion.project && (0, import_node_fs32.existsSync)(projectPath) ? await fileInfo(projectPath) : null;
19301
19554
  let projectUrl = null;
19302
19555
  if (project) {
19303
19556
  const id = galleryMediaId(projectPath);
@@ -19334,7 +19587,7 @@ async function buildGallerySnapshot(opts) {
19334
19587
  }
19335
19588
  } else if (spec.source) {
19336
19589
  outputs = [await describeOutput(media, root, import_node_path35.default.resolve(root, spec.source))];
19337
- } else if (!entry && (0, import_node_fs30.existsSync)(spec.outFile)) {
19590
+ } else if (!entry && (0, import_node_fs32.existsSync)(spec.outFile)) {
19338
19591
  outputs = [await describeOutput(media, root, spec.outFile)];
19339
19592
  } else {
19340
19593
  outputs = [];
@@ -19611,7 +19864,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
19611
19864
  root: loaded.root,
19612
19865
  provider: loaded.manifest.provider,
19613
19866
  account: project.account ?? null,
19614
- manifestSha256: manifestSha256 ?? sha256(await (0, import_promises27.readFile)(manifestPath, "utf8")),
19867
+ manifestSha256: manifestSha256 ?? sha256(await (0, import_promises28.readFile)(manifestPath, "utf8")),
19615
19868
  historyLimit: historyLimit(loaded.manifest),
19616
19869
  entries: Object.keys(lock.entries).length,
19617
19870
  items: projectItems.length,
@@ -19668,7 +19921,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
19668
19921
  }
19669
19922
 
19670
19923
  // src/gallery/page.ts
19671
- var import_node_fs31 = require("fs");
19924
+ var import_node_fs33 = require("fs");
19672
19925
 
19673
19926
  // src/gallery/client-bundle.ts
19674
19927
  var import_node_module = require("module");
@@ -19708,8 +19961,8 @@ var client;
19708
19961
  function clientAssets() {
19709
19962
  const prebuilt = new URL("gallery.js", CLIENT_DIR);
19710
19963
  client ??= {
19711
- css: (0, import_node_fs31.readFileSync)(new URL("gallery.css", CLIENT_DIR), "utf8"),
19712
- js: (0, import_node_fs31.existsSync)(prebuilt) ? (0, import_node_fs31.readFileSync)(prebuilt, "utf8") : bundleGalleryClient()
19964
+ css: (0, import_node_fs33.readFileSync)(new URL("gallery.css", CLIENT_DIR), "utf8"),
19965
+ js: (0, import_node_fs33.existsSync)(prebuilt) ? (0, import_node_fs33.readFileSync)(prebuilt, "utf8") : bundleGalleryClient()
19713
19966
  };
19714
19967
  return client;
19715
19968
  }
@@ -19852,8 +20105,8 @@ var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download
19852
20105
 
19853
20106
  // src/editor/install.ts
19854
20107
  var import_node_crypto8 = require("crypto");
19855
- var import_node_fs32 = require("fs");
19856
- var import_promises28 = require("fs/promises");
20108
+ var import_node_fs34 = require("fs");
20109
+ var import_promises29 = require("fs/promises");
19857
20110
  var import_node_os4 = __toESM(require("os"), 1);
19858
20111
  var import_node_path36 = __toESM(require("path"), 1);
19859
20112
  var EditorInstallError = class extends Error {
@@ -19884,7 +20137,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
19884
20137
  }
19885
20138
  async function sha256Of(file) {
19886
20139
  try {
19887
- return (0, import_node_crypto8.createHash)("sha256").update(await (0, import_promises28.readFile)(file)).digest("hex");
20140
+ return (0, import_node_crypto8.createHash)("sha256").update(await (0, import_promises29.readFile)(file)).digest("hex");
19888
20141
  } catch {
19889
20142
  return null;
19890
20143
  }
@@ -19898,7 +20151,7 @@ async function editorStatus(opts = {}) {
19898
20151
  for (const [name, expected] of Object.entries(pin.files)) {
19899
20152
  totalBytes += expected.bytes;
19900
20153
  const file = import_node_path36.default.join(dir, name);
19901
- const info = (0, import_node_fs32.existsSync)(file) ? await (0, import_promises28.stat)(file).catch(() => null) : null;
20154
+ const info = (0, import_node_fs34.existsSync)(file) ? await (0, import_promises29.stat)(file).catch(() => null) : null;
19902
20155
  if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
19903
20156
  installedBytes += expected.bytes;
19904
20157
  } else {
@@ -19927,7 +20180,7 @@ async function installEditor(opts = {}) {
19927
20180
  );
19928
20181
  }
19929
20182
  if (!baseUrl) throw new EditorInstallError("no download location for the editor build");
19930
- await (0, import_promises28.mkdir)(dir, { recursive: true });
20183
+ await (0, import_promises29.mkdir)(dir, { recursive: true });
19931
20184
  const downloaded = [];
19932
20185
  const skipped = Object.keys(pin.files).filter((name) => !before.missing.includes(name));
19933
20186
  let fetchedBytes = before.installedBytes;
@@ -19958,10 +20211,10 @@ async function installEditor(opts = {}) {
19958
20211
  const final = import_node_path36.default.join(dir, name);
19959
20212
  const tmp = `${final}.${process.pid}.part`;
19960
20213
  try {
19961
- await (0, import_promises28.writeFile)(tmp, bytes);
19962
- await (0, import_promises28.rename)(tmp, final);
20214
+ await (0, import_promises29.writeFile)(tmp, bytes);
20215
+ await (0, import_promises29.rename)(tmp, final);
19963
20216
  } finally {
19964
- await (0, import_promises28.rm)(tmp, { force: true });
20217
+ await (0, import_promises29.rm)(tmp, { force: true });
19965
20218
  }
19966
20219
  fetchedBytes += bytes.length;
19967
20220
  downloaded.push(name);
@@ -20005,7 +20258,7 @@ function editorContentType(name) {
20005
20258
  }
20006
20259
 
20007
20260
  // src/gallery/editor.ts
20008
- var import_promises29 = require("fs/promises");
20261
+ var import_promises30 = require("fs/promises");
20009
20262
  var import_node_path37 = __toESM(require("path"), 1);
20010
20263
  function editorRoute(release, name = "index.html") {
20011
20264
  return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
@@ -20079,7 +20332,7 @@ function createGalleryEditorHandlers(opts = {}) {
20079
20332
  if (!status.installed) return null;
20080
20333
  let bytes;
20081
20334
  try {
20082
- bytes = await (0, import_promises29.readFile)(import_node_path37.default.join(dir, name));
20335
+ bytes = await (0, import_promises30.readFile)(import_node_path37.default.join(dir, name));
20083
20336
  } catch {
20084
20337
  verified = null;
20085
20338
  return null;
@@ -20096,7 +20349,7 @@ function createGalleryEditorHandlers(opts = {}) {
20096
20349
  // src/gallery/server.ts
20097
20350
  var import_node_crypto9 = require("crypto");
20098
20351
  var import_node_http2 = require("http");
20099
- var import_promises30 = require("fs/promises");
20352
+ var import_promises31 = require("fs/promises");
20100
20353
  var MAX_EDIT_BYTES = 48 * 1024 * 1024;
20101
20354
  var EDITOR_CSP = [
20102
20355
  "default-src 'self'",
@@ -20277,7 +20530,7 @@ async function serveGallery(opts) {
20277
20530
  const asset = reviewAssets.get(jobId)?.get(url2.pathname);
20278
20531
  if (!asset) return fail(404, "no such review asset");
20279
20532
  try {
20280
- const bytes = await (0, import_promises30.readFile)(asset.path);
20533
+ const bytes = await (0, import_promises31.readFile)(asset.path);
20281
20534
  res.writeHead(200, {
20282
20535
  "Content-Type": asset.contentType,
20283
20536
  "Cache-Control": "no-store",
@@ -20360,7 +20613,7 @@ async function serveGallery(opts) {
20360
20613
  if (!asset) return fail(404, "no such gallery media");
20361
20614
  let bytes;
20362
20615
  try {
20363
- bytes = await (0, import_promises30.readFile)(asset.path);
20616
+ bytes = await (0, import_promises31.readFile)(asset.path);
20364
20617
  } catch {
20365
20618
  return fail(404, "gallery media is no longer on disk; refresh the page");
20366
20619
  }
@@ -20770,8 +21023,8 @@ function createGenerateHandlers(opts) {
20770
21023
  }
20771
21024
 
20772
21025
  // src/pipeline/salvage.ts
20773
- var import_promises31 = require("fs/promises");
20774
- var import_node_fs33 = require("fs");
21026
+ var import_promises32 = require("fs/promises");
21027
+ var import_node_fs35 = require("fs");
20775
21028
  var import_node_path38 = __toESM(require("path"), 1);
20776
21029
  function providerClaimId(provider, objectId) {
20777
21030
  return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
@@ -20779,10 +21032,10 @@ function providerClaimId(provider, objectId) {
20779
21032
  async function loadClaims(lockPaths, opts = {}) {
20780
21033
  const claimed = /* @__PURE__ */ new Set();
20781
21034
  for (const p of lockPaths) {
20782
- if (!(0, import_node_fs33.existsSync)(p)) throw new Error(`Claim lockfile not found: ${p}`);
21035
+ if (!(0, import_node_fs35.existsSync)(p)) throw new Error(`Claim lockfile not found: ${p}`);
20783
21036
  let parsed;
20784
21037
  try {
20785
- parsed = parseLock(JSON.parse(await (0, import_promises31.readFile)(p, "utf8")));
21038
+ parsed = parseLock(JSON.parse(await (0, import_promises32.readFile)(p, "utf8")));
20786
21039
  } catch {
20787
21040
  throw new Error(`Claim lockfile is malformed: ${p}`);
20788
21041
  }
@@ -20896,7 +21149,7 @@ async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, cla
20896
21149
  const siblings = [];
20897
21150
  for (const siblingManifestPath of siblingManifestPaths) {
20898
21151
  if (import_node_path38.default.resolve(siblingManifestPath) === own) continue;
20899
- if (!(0, import_node_fs33.existsSync)(siblingManifestPath)) continue;
21152
+ if (!(0, import_node_fs35.existsSync)(siblingManifestPath)) continue;
20900
21153
  try {
20901
21154
  const { manifest } = await loadManifest(siblingManifestPath);
20902
21155
  siblings.push({ label: import_node_path38.default.basename(import_node_path38.default.dirname(siblingManifestPath)), manifest });
@@ -21019,7 +21272,7 @@ async function applyTags(provider, decisions, existing, opts = {}) {
21019
21272
  }
21020
21273
 
21021
21274
  // src/pick/salvage-server.ts
21022
- var import_promises32 = require("fs/promises");
21275
+ var import_promises33 = require("fs/promises");
21023
21276
  var import_node_path39 = __toESM(require("path"), 1);
21024
21277
 
21025
21278
  // src/pick/salvage-sheet.ts
@@ -21244,8 +21497,8 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
21244
21497
  const assetId = idFromPrompt(orphan.prompt, taken);
21245
21498
  const rel = import_node_path39.default.join("_salvaged", `${assetId}.png`);
21246
21499
  const outFile = import_node_path39.default.resolve(ctx.importDir, rel);
21247
- await (0, import_promises32.mkdir)(import_node_path39.default.dirname(outFile), { recursive: true });
21248
- await (0, import_promises32.writeFile)(outFile, buf);
21500
+ await (0, import_promises33.mkdir)(import_node_path39.default.dirname(outFile), { recursive: true });
21501
+ await (0, import_promises33.writeFile)(outFile, buf);
21249
21502
  ctx.manifest.assets[assetId] = {
21250
21503
  prompt: orphan.prompt,
21251
21504
  promptByStyle: {},
@@ -21301,9 +21554,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
21301
21554
  }
21302
21555
  }
21303
21556
  await applyTags(provider, decisions, existingTags, { onProgress: log, characters: characterMembers });
21304
- const raw = JSON.parse(await (0, import_promises32.readFile)(ctx.manifestPath, "utf8"));
21557
+ const raw = JSON.parse(await (0, import_promises33.readFile)(ctx.manifestPath, "utf8"));
21305
21558
  for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
21306
- await (0, import_promises32.writeFile)(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
21559
+ await (0, import_promises33.writeFile)(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
21307
21560
  await saveLock(ctx.lockPath, ctx.lock);
21308
21561
  if (characterAssetIds.length) result.characterAssetIds = characterAssetIds;
21309
21562
  return result;
@@ -21527,6 +21780,7 @@ async function workspaceStatus(ws, dir) {
21527
21780
  availableProviders,
21528
21781
  backoffMs,
21529
21782
  buildGallerySnapshot,
21783
+ buildImportedEntry,
21530
21784
  buildManifest,
21531
21785
  buildPlan,
21532
21786
  buildWorkspaceGallerySnapshot,
@@ -21589,6 +21843,7 @@ async function workspaceStatus(ws, dir) {
21589
21843
  historyLimit,
21590
21844
  idFromPrompt,
21591
21845
  imageMetadata,
21846
+ importLocal,
21592
21847
  inspectCaches,
21593
21848
  inspectQualityProfile,
21594
21849
  inspectRevisionReadiness,
@@ -21681,6 +21936,7 @@ async function workspaceStatus(ws, dir) {
21681
21936
  renderSalvageSheet,
21682
21937
  renderSheet,
21683
21938
  renderSheetDocument,
21939
+ reportSpecHashes,
21684
21940
  requireApprovedQualitySources,
21685
21941
  requireBalance,
21686
21942
  requireDelete,
@@ -21720,6 +21976,7 @@ async function workspaceStatus(ws, dir) {
21720
21976
  sliceVfxSheet,
21721
21977
  slugify,
21722
21978
  snapshotQualityBaseline,
21979
+ snapshotQualityCases,
21723
21980
  sourceIsStem,
21724
21981
  sourceOutputPath,
21725
21982
  specHash,