pixelkiln 0.92.3 → 0.94.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),
@@ -2516,9 +2530,9 @@ var PixelLabClient = class {
2516
2530
  apiKey;
2517
2531
  http;
2518
2532
  /** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
2519
- async request(path39, init) {
2533
+ async request(path40, init) {
2520
2534
  const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
2521
- const res = await this.http(`${BASE}${path39}`, {
2535
+ const res = await this.http(`${BASE}${path40}`, {
2522
2536
  ...init,
2523
2537
  headers: {
2524
2538
  Authorization: auth,
@@ -2529,13 +2543,13 @@ var PixelLabClient = class {
2529
2543
  const text = await res.text();
2530
2544
  if (!res.ok) {
2531
2545
  const hint = res.status === 500 && text.includes("Failed to start any animation jobs") ? '; a skeleton-v3 loop needs a character with a stored 3D skeleton (a v3 base), use mode: "template" on a standard one' : "";
2532
- throw new PixelLabError(`${init?.method ?? "GET"} ${path39} \u2192 ${res.status}${hint}`, res.status, text);
2546
+ throw new PixelLabError(`${init?.method ?? "GET"} ${path40} \u2192 ${res.status}${hint}`, res.status, text);
2533
2547
  }
2534
2548
  if (!text) return {};
2535
2549
  try {
2536
2550
  return JSON.parse(text);
2537
2551
  } catch {
2538
- throw new Error(`${init?.method ?? "GET"} ${path39} returned invalid JSON`);
2552
+ throw new Error(`${init?.method ?? "GET"} ${path40} returned invalid JSON`);
2539
2553
  }
2540
2554
  }
2541
2555
  async balance() {
@@ -2988,10 +3002,10 @@ var PixelLabClient = class {
2988
3002
  const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
2989
3003
  const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
2990
3004
  const south = args.reference?.south;
2991
- let path39;
3005
+ let path40;
2992
3006
  let body;
2993
3007
  if (args.mode === "v3") {
2994
- path39 = "/create-character-v3";
3008
+ path40 = "/create-character-v3";
2995
3009
  body = {
2996
3010
  description: args.description,
2997
3011
  image_size: imageSize,
@@ -3005,7 +3019,7 @@ var PixelLabClient = class {
3005
3019
  ...args.enhancePrompt ? { enhance_prompt: true } : {}
3006
3020
  };
3007
3021
  } else if (args.mode === "pro-flash") {
3008
- path39 = "/create-character-pro-flash";
3022
+ path40 = "/create-character-pro-flash";
3009
3023
  const traits = args.styleTraits;
3010
3024
  body = {
3011
3025
  description: args.description,
@@ -3029,7 +3043,7 @@ var PixelLabClient = class {
3029
3043
  } : {}
3030
3044
  };
3031
3045
  } else if (args.mode === "pro") {
3032
- path39 = "/create-character-pro";
3046
+ path40 = "/create-character-pro";
3033
3047
  body = {
3034
3048
  description: args.description,
3035
3049
  image_size: imageSize,
@@ -3043,7 +3057,7 @@ var PixelLabClient = class {
3043
3057
  ...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
3044
3058
  };
3045
3059
  } else {
3046
- path39 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
3060
+ path40 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
3047
3061
  body = {
3048
3062
  description: args.description,
3049
3063
  image_size: imageSize,
@@ -3061,8 +3075,8 @@ var PixelLabClient = class {
3061
3075
  };
3062
3076
  }
3063
3077
  if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
3064
- const raw = await this.request(path39, { method: "POST", body: JSON.stringify(body) });
3065
- return validateResponse(CharacterSubmitSchema, raw, path39.slice(1));
3078
+ const raw = await this.request(path40, { method: "POST", body: JSON.stringify(body) });
3079
+ return validateResponse(CharacterSubmitSchema, raw, path40.slice(1));
3066
3080
  }
3067
3081
  /** A text edit of an existing character, applied to every direction and stored as a sibling. */
3068
3082
  async createCharacterState(args) {
@@ -4399,10 +4413,10 @@ var import_node_fs = require("fs");
4399
4413
  function sha256(data) {
4400
4414
  return (0, import_node_crypto.createHash)("sha256").update(data).digest("hex");
4401
4415
  }
4402
- async function sha256File(path39) {
4416
+ async function sha256File(path40) {
4403
4417
  return new Promise((resolve, reject) => {
4404
4418
  const hash = (0, import_node_crypto.createHash)("sha256");
4405
- const stream = (0, import_node_fs.createReadStream)(path39);
4419
+ const stream = (0, import_node_fs.createReadStream)(path40);
4406
4420
  stream.on("data", (chunk2) => hash.update(chunk2));
4407
4421
  stream.on("error", reject);
4408
4422
  stream.on("end", () => resolve(hash.digest("hex")));
@@ -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 {
@@ -8221,9 +8235,9 @@ var RetroDiffusionClient = class {
8221
8235
  if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
8222
8236
  return Buffer.from(await response.arrayBuffer());
8223
8237
  }
8224
- async call(path39, init = {}) {
8238
+ async call(path40, init = {}) {
8225
8239
  if (!this.token) throw new Error("RD_API_KEY is not set");
8226
- const response = await this.request(`${this.baseUrl}${path39}`, {
8240
+ const response = await this.request(`${this.baseUrl}${path40}`, {
8227
8241
  ...init,
8228
8242
  headers: {
8229
8243
  "Content-Type": "application/json",
@@ -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,15 +10725,93 @@ 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
- async function loadManifest(manifestPath) {
10750
+ async function loadManifest(manifestPath, opts = {}) {
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:
10721
10756
  ${expansion.issues.map((i) => ` ${i}`).join("\n")}`);
10722
10757
  }
10758
+ if (!opts.lenient) return loadExpanded(abs, expansion);
10759
+ const invalid = [];
10760
+ const raw = pruneInvalidEntries(expansion.raw, invalid);
10761
+ for (let round2 = 0; ; round2++) {
10762
+ try {
10763
+ const loaded = await loadExpanded(abs, { ...expansion, raw });
10764
+ return invalid.length ? { ...loaded, invalid } : loaded;
10765
+ } catch (error) {
10766
+ const culprits = round2 < 50 && error instanceof ProjectError ? culpritEntries(error.message) : [];
10767
+ const fresh = culprits.filter((entry) => dropEntry(raw, entry));
10768
+ if (!fresh.length) throw error;
10769
+ invalid.push(...fresh);
10770
+ }
10771
+ }
10772
+ }
10773
+ function entryRecord(raw, kind) {
10774
+ const record = raw?.[kind === "style" ? "styles" : "assets"];
10775
+ return record && typeof record === "object" && !Array.isArray(record) ? record : null;
10776
+ }
10777
+ function dropEntry(raw, entry) {
10778
+ const record = entryRecord(raw, entry.kind);
10779
+ if (!record || !(entry.id in record)) return false;
10780
+ delete record[entry.id];
10781
+ return true;
10782
+ }
10783
+ function pruneInvalidEntries(raw, invalid) {
10784
+ for (const [kind, schema] of [["style", StyleInputSchema], ["asset", AssetSchema]]) {
10785
+ const record = entryRecord(raw, kind);
10786
+ if (!record) continue;
10787
+ for (const [id, value] of Object.entries(record)) {
10788
+ const parsed = schema.safeParse(value);
10789
+ if (parsed.success) continue;
10790
+ const prefix = `${kind === "style" ? "styles" : "assets"}.${id}`;
10791
+ const lines = flattenManifestIssues(parsed.error.issues).lines.map((line) => {
10792
+ const [fieldPath, ...rest] = line.trim().split(": ");
10793
+ return `${prefix}${fieldPath === "(manifest)" || !fieldPath ? "" : `.${fieldPath}`}: ${rest.join(": ")}`;
10794
+ });
10795
+ invalid.push({ kind, id, issues: lines.length ? lines : [`${prefix}: invalid`] });
10796
+ delete record[id];
10797
+ }
10798
+ }
10799
+ return raw;
10800
+ }
10801
+ function culpritEntries(message6) {
10802
+ const found = /* @__PURE__ */ new Map();
10803
+ for (const line of message6.split("\n")) {
10804
+ const match = /^ {2}(assets|styles)\.([^.:\s]+)[.:]/.exec(line);
10805
+ if (!match) continue;
10806
+ const kind = match[1] === "styles" ? "style" : "asset";
10807
+ const key = `${kind}:${match[2]}`;
10808
+ const entry = found.get(key) ?? { kind, id: match[2], issues: [] };
10809
+ entry.issues.push(line.trim());
10810
+ found.set(key, entry);
10811
+ }
10812
+ return [...found.values()];
10813
+ }
10814
+ async function loadExpanded(abs, expansion) {
10723
10815
  const input = ManifestInputSchema.safeParse(expansion.raw);
10724
10816
  if (!input.success) {
10725
10817
  const issues = formatManifestIssues(input.error.issues);
@@ -10866,19 +10958,45 @@ function dependencyAssetIds(asset, styleAnchors = []) {
10866
10958
  ].filter((id) => Boolean(id))
10867
10959
  ];
10868
10960
  }
10961
+ var MAX_LISTED_MANIFEST_ISSUES = 20;
10962
+ function flattenManifestIssues(issues) {
10963
+ let unknownShape = false;
10964
+ const visit = (list) => list.flatMap((issue) => {
10965
+ if (issue.code === "invalid_union") return visit(issue.unionErrors.flatMap((error) => error.issues));
10966
+ if (issue.code === "unrecognized_keys" || issue.code === "invalid_enum_value") unknownShape = true;
10967
+ return [` ${issue.path.join(".") || "(manifest)"}: ${issue.message}`];
10968
+ });
10969
+ return { lines: [...new Set(visit(issues))], unknownShape };
10970
+ }
10869
10971
  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");
10972
+ const { lines, unknownShape } = flattenManifestIssues(issues);
10973
+ const entries = [...new Set(
10974
+ lines.flatMap((line) => {
10975
+ const match = /^ {2}((?:assets|styles)\.[^.:\s]+)/.exec(line);
10976
+ return match ? [match[1]] : [];
10977
+ })
10978
+ )];
10979
+ const out = [];
10980
+ const version = pixelkilnVersion();
10981
+ if (unknownShape) {
10982
+ out.push(
10983
+ ` 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.`
10984
+ );
10985
+ }
10986
+ if (entries.length) {
10987
+ out.push(` ${entries.length} invalid entr${entries.length === 1 ? "y" : "ies"}: ${entries.slice(0, 10).join(", ")}${entries.length > 10 ? ", \u2026" : ""}`);
10988
+ }
10989
+ out.push(...lines.slice(0, MAX_LISTED_MANIFEST_ISSUES));
10990
+ if (lines.length > MAX_LISTED_MANIFEST_ISSUES) {
10991
+ out.push(` \u2026 and ${lines.length - MAX_LISTED_MANIFEST_ISSUES} more`);
10992
+ }
10993
+ return out.join("\n");
10876
10994
  }
10877
10995
  function resolveStyleInheritance(styles) {
10878
10996
  const resolved = /* @__PURE__ */ new Map();
10879
10997
  const visit = (styleId, chain) => {
10880
- const cached = resolved.get(styleId);
10881
- if (cached) return cached;
10998
+ const cached2 = resolved.get(styleId);
10999
+ if (cached2) return cached2;
10882
11000
  const cycleStart = chain.indexOf(styleId);
10883
11001
  if (cycleStart >= 0) {
10884
11002
  throw new Error(
@@ -11000,7 +11118,7 @@ async function resolveSpecs(loaded, filter) {
11000
11118
  const abs = import_node_path8.default.resolve(root, rel);
11001
11119
  let hit = styleImageCache.get(abs);
11002
11120
  if (!hit) {
11003
- if (!(0, import_node_fs8.existsSync)(abs)) throw new Error(`${what} not found: ${abs}`);
11121
+ if (!(0, import_node_fs9.existsSync)(abs)) throw new Error(`${what} not found: ${abs}`);
11004
11122
  const buf = await (0, import_promises5.readFile)(abs);
11005
11123
  const metadata = imageMetadata(buf);
11006
11124
  if (!metadata) throw new Error(`${what} is not a readable PNG or JPEG: ${abs}`);
@@ -11351,7 +11469,7 @@ async function resolveSpecs(loaded, filter) {
11351
11469
  const file = memberPath(anchorSpec.outFile, "south", 0, anchorSpec.character.directions, MediaType.PNG);
11352
11470
  resolved.character = {
11353
11471
  ...resolved.character,
11354
- styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: (0, import_node_fs8.existsSync)(file) ? await sha256File(file) : null }
11472
+ styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: (0, import_node_fs9.existsSync)(file) ? await sha256File(file) : null }
11355
11473
  };
11356
11474
  }
11357
11475
  const characterParent = asset.state?.of ?? asset.animation?.of ?? asset.portrait?.of;
@@ -11364,7 +11482,7 @@ async function resolveSpecs(loaded, filter) {
11364
11482
  parentAssetId: characterParent,
11365
11483
  parentSpec,
11366
11484
  parentFile,
11367
- parentSha256: (0, import_node_fs8.existsSync)(parentFile) ? await sha256File(parentFile) : null,
11485
+ parentSha256: (0, import_node_fs9.existsSync)(parentFile) ? await sha256File(parentFile) : null,
11368
11486
  // A state and its animations keep the engine and rotations of the base.
11369
11487
  mode: resolved.character.kind === "base" ? resolved.character.mode : parentSpec.character?.mode ?? resolved.character.mode,
11370
11488
  directions: resolved.character.kind === "base" ? resolved.character.directions : parentSpec.character?.directions ?? resolved.character.directions
@@ -11402,7 +11520,7 @@ async function resolveSpecs(loaded, filter) {
11402
11520
  parentAssetId: characterParent,
11403
11521
  parentSpec,
11404
11522
  parentFile,
11405
- parentSha256: (0, import_node_fs8.existsSync)(parentFile) ? await sha256File(parentFile) : null,
11523
+ parentSha256: (0, import_node_fs9.existsSync)(parentFile) ? await sha256File(parentFile) : null,
11406
11524
  // A state and its animations keep the base's own rotation count.
11407
11525
  directions: resolved.objectPro.kind === "base" ? resolved.objectPro.directions : parentSpec.objectPro.directions
11408
11526
  };
@@ -11606,8 +11724,18 @@ async function resolveSpecs(loaded, filter) {
11606
11724
  providerOptionIdentity,
11607
11725
  providerInputIdentities.get(assetId)
11608
11726
  );
11609
- activeProvider.validate?.(resolved, resolvedImages);
11610
- const estimate = validateCostEstimate(activeProvider.id, activeProvider.estimate(resolved));
11727
+ let estimate;
11728
+ try {
11729
+ activeProvider.validate?.(resolved, resolvedImages);
11730
+ estimate = validateCostEstimate(activeProvider.id, activeProvider.estimate(resolved));
11731
+ } catch (error) {
11732
+ const message6 = error instanceof Error ? error.message : String(error);
11733
+ if (message6.includes(`assets.${assetId}`)) throw error;
11734
+ throw new Error(
11735
+ `assets.${assetId} (style "${styleId}", ${resolved.width}x${resolved.height}): ${message6}`,
11736
+ { cause: error }
11737
+ );
11738
+ }
11611
11739
  resolved.cost = estimate.amount;
11612
11740
  resolved.costUnit = estimate.unit;
11613
11741
  resolved.candidates = estimate.candidates;
@@ -11618,7 +11746,16 @@ async function resolveSpecs(loaded, filter) {
11618
11746
  if (!emitStyles.has(styleId)) continue;
11619
11747
  for (const assetId of Object.keys(manifest.assets)) {
11620
11748
  if (!requestedAssetIds.has(assetId) || !styleSpecs.has(assetId)) continue;
11621
- specs.push(await finalize(assetId));
11749
+ if (!filter?.onInvalid) {
11750
+ specs.push(await finalize(assetId));
11751
+ continue;
11752
+ }
11753
+ try {
11754
+ specs.push(await finalize(assetId));
11755
+ } catch (error) {
11756
+ const message6 = error instanceof Error ? error.message : String(error);
11757
+ filter.onInvalid({ kind: "asset", id: assetId, issues: [message6] });
11758
+ }
11622
11759
  }
11623
11760
  }
11624
11761
  const byOutput = /* @__PURE__ */ new Map();
@@ -11691,7 +11828,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
11691
11828
  let recordedSprite;
11692
11829
  if (vfx.recipe) {
11693
11830
  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}`);
11831
+ if (!(0, import_node_fs9.existsSync)(file)) throw new Error(`assets.${assetId}.vfx.recipe: VFX recipe not found: ${file}`);
11695
11832
  const read = await readVfxRecipe(file).catch((error) => {
11696
11833
  throw new Error(`assets.${assetId}.vfx.recipe: ${error instanceof Error ? error.message : String(error)}`);
11697
11834
  });
@@ -11718,7 +11855,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
11718
11855
  };
11719
11856
  }
11720
11857
  async function optionalRevisionImage(file, label, requiredFormat) {
11721
- if (!(0, import_node_fs8.existsSync)(file)) return null;
11858
+ if (!(0, import_node_fs9.existsSync)(file)) return null;
11722
11859
  const bytes = await (0, import_promises5.readFile)(file);
11723
11860
  const metadata = imageMetadata(bytes);
11724
11861
  if (!metadata) throw new Error(`${label} is not a readable PNG or JPEG: ${file}`);
@@ -11728,7 +11865,7 @@ async function optionalRevisionImage(file, label, requiredFormat) {
11728
11865
  return { hash: sha256(bytes), ...metadata };
11729
11866
  }
11730
11867
  async function optionalSkeletonSet(file) {
11731
- if (!(0, import_node_fs8.existsSync)(file)) return null;
11868
+ if (!(0, import_node_fs9.existsSync)(file)) return null;
11732
11869
  const bytes = await (0, import_promises5.readFile)(file);
11733
11870
  let json;
11734
11871
  try {
@@ -11739,17 +11876,17 @@ async function optionalSkeletonSet(file) {
11739
11876
  return { hash: sha256(bytes), skeleton: parseSkeletonSet(json, file) };
11740
11877
  }
11741
11878
  async function revisionSourceMembers(stem, label) {
11742
- if ((0, import_node_fs8.existsSync)(stem)) return null;
11879
+ if ((0, import_node_fs9.existsSync)(stem)) return null;
11743
11880
  const at = (role) => memberPath(stem, role, 0, 2, MediaType.PNG);
11744
11881
  let roles = [];
11745
11882
  for (const set of [CHARACTER_DIRECTIONS_8, CHARACTER_DIRECTIONS_4]) {
11746
- if (set.every((direction) => (0, import_node_fs8.existsSync)(at(direction)))) {
11883
+ if (set.every((direction) => (0, import_node_fs9.existsSync)(at(direction)))) {
11747
11884
  roles = [...set];
11748
11885
  break;
11749
11886
  }
11750
11887
  }
11751
11888
  if (!roles.length) {
11752
- for (let index = 0; (0, import_node_fs8.existsSync)(at(`frame-${String(index).padStart(2, "0")}`)); index++) {
11889
+ for (let index = 0; (0, import_node_fs9.existsSync)(at(`frame-${String(index).padStart(2, "0")}`)); index++) {
11753
11890
  roles.push(`frame-${String(index).padStart(2, "0")}`);
11754
11891
  }
11755
11892
  }
@@ -11917,7 +12054,7 @@ function characterDirections(directions) {
11917
12054
  var import_node_path16 = __toESM(require("path"), 1);
11918
12055
 
11919
12056
  // src/env.ts
11920
- var import_node_fs9 = require("fs");
12057
+ var import_node_fs10 = require("fs");
11921
12058
  var import_node_path9 = __toESM(require("path"), 1);
11922
12059
  function loadEnvFiles(dir) {
11923
12060
  const loaded = [];
@@ -11933,9 +12070,9 @@ function envFiles(dir) {
11933
12070
  const out = [];
11934
12071
  for (const name of [".env.local", ".env"]) {
11935
12072
  const file = import_node_path9.default.join(dir, name);
11936
- if (!(0, import_node_fs9.existsSync)(file)) continue;
12073
+ if (!(0, import_node_fs10.existsSync)(file)) continue;
11937
12074
  try {
11938
- out.push([file, parseEnv((0, import_node_fs9.readFileSync)(file, "utf8"))]);
12075
+ out.push([file, parseEnv((0, import_node_fs10.readFileSync)(file, "utf8"))]);
11939
12076
  } catch {
11940
12077
  }
11941
12078
  }
@@ -11961,7 +12098,7 @@ function parseEnv(contents) {
11961
12098
  }
11962
12099
 
11963
12100
  // src/pipeline/plan.ts
11964
- var import_node_fs12 = require("fs");
12101
+ var import_node_fs13 = require("fs");
11965
12102
  var import_node_path15 = __toESM(require("path"), 1);
11966
12103
 
11967
12104
  // src/pipeline/mirror.ts
@@ -12167,7 +12304,7 @@ async function deriveMirror(spec, lock, lockPath, opts = {}) {
12167
12304
  }
12168
12305
 
12169
12306
  // src/pipeline/quality-profile.ts
12170
- var import_node_fs10 = require("fs");
12307
+ var import_node_fs11 = require("fs");
12171
12308
  var import_node_path13 = __toESM(require("path"), 1);
12172
12309
 
12173
12310
  // src/pipeline/refine.ts
@@ -13150,7 +13287,7 @@ async function qualitySource(spec, lock) {
13150
13287
  return { items: null, reason: "frame-set quality requires ordered downloaded provider outputs" };
13151
13288
  }
13152
13289
  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}` };
13290
+ return (0, import_node_fs11.existsSync)(source) ? { items: [{ role: "source", path: source }] } : { items: null, reason: `declared source is missing: ${spec.source}` };
13154
13291
  }
13155
13292
  const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
13156
13293
  if (!entry) return { items: null, reason: "raw provider output is not in the lockfile" };
@@ -13179,7 +13316,7 @@ async function qualitySource(spec, lock) {
13179
13316
  }
13180
13317
  if (role) roles.add(role);
13181
13318
  const source = currentEntryOutputPath(entry, spec, index);
13182
- if (!(0, import_node_fs10.existsSync)(source)) return { items: null, reason: `raw provider output is missing: ${source}` };
13319
+ if (!(0, import_node_fs11.existsSync)(source)) return { items: null, reason: `raw provider output is missing: ${source}` };
13183
13320
  if (await sha256File(source) !== output.sha256) {
13184
13321
  return { items: null, reason: "raw provider output was modified after download" };
13185
13322
  }
@@ -13198,7 +13335,7 @@ async function inspectQualityProfile(spec, lock) {
13198
13335
  }
13199
13336
  const sourcePaths = source.items.map((item) => item.path);
13200
13337
  const expectedOutputs = spec.generator === "frames" ? source.items.map((item, index) => qualityFrameOutputPath(output, item.role, index)) : [output];
13201
- if (!(0, import_node_fs10.existsSync)(record)) {
13338
+ if (!(0, import_node_fs11.existsSync)(record)) {
13202
13339
  return {
13203
13340
  key,
13204
13341
  state: "needs-refinement",
@@ -13379,7 +13516,7 @@ async function requireApprovedQualitySources(specs, lock, assetIds, outputRoles)
13379
13516
  }
13380
13517
 
13381
13518
  // src/pipeline/revision.ts
13382
- var import_node_fs11 = require("fs");
13519
+ var import_node_fs12 = require("fs");
13383
13520
  var import_node_path14 = __toESM(require("path"), 1);
13384
13521
  async function inspectRevisionReadiness(spec, lock) {
13385
13522
  if (spec.mirror) return inspectMirror(spec, lock, /* @__PURE__ */ new Set());
@@ -13401,7 +13538,7 @@ async function inspectStyleAnchor(spec, lock, seen) {
13401
13538
  const label = `style anchor ${spec.styleId}/${anchor.assetId}`;
13402
13539
  const dependency = await inspectParent(anchor.spec, lock, seen);
13403
13540
  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` };
13541
+ if (!anchor.sha256 || !(0, import_node_fs12.existsSync)(anchor.file)) return { ready: false, reason: `${label} has no generated south-facing file yet` };
13405
13542
  if (await sha256File(anchor.file) !== anchor.sha256) {
13406
13543
  return { ready: false, reason: `${label} changed after the manifest was resolved` };
13407
13544
  }
@@ -13438,14 +13575,14 @@ async function inspectScene(spec) {
13438
13575
  const files = [{ label: "scene image", file: scene.file, sha256: scene.sha256 }];
13439
13576
  if (scene.placement.type === "mask") files.push({ label: "scene mask", file: scene.placement.file, sha256: scene.placement.sha256 });
13440
13577
  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}` };
13578
+ if (!sha2562 || !(0, import_node_fs12.existsSync)(file)) return { ready: false, reason: `${label} does not exist yet: ${file}` };
13442
13579
  if (await sha256File(file) !== sha2562) return { ready: false, reason: `${label} changed after the manifest was resolved` };
13443
13580
  }
13444
13581
  return { ready: true, reason: "scene is current" };
13445
13582
  }
13446
13583
  async function inspectVfxSprite(spec) {
13447
13584
  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}` };
13585
+ if (!sprite.sha256 || !(0, import_node_fs12.existsSync)(sprite.file)) return { ready: false, reason: `vfx sprite does not exist yet: ${sprite.file}` };
13449
13586
  if (await sha256File(sprite.file) !== sprite.sha256) return { ready: false, reason: "vfx sprite changed after the manifest was resolved" };
13450
13587
  return { ready: true, reason: "vfx sprite is current" };
13451
13588
  }
@@ -13461,7 +13598,7 @@ async function inspectOutfit(spec, lock, seen) {
13461
13598
  const label = `outfit source ${spec.styleId}/${character.parentAssetId}`;
13462
13599
  const dependency = await inspectParent(character.parentSpec, lock, seen);
13463
13600
  if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
13464
- if (!(0, import_node_fs11.existsSync)(outfit.reference.path)) {
13601
+ if (!(0, import_node_fs12.existsSync)(outfit.reference.path)) {
13465
13602
  return { ready: false, reason: `outfit reference is missing: ${outfit.reference.path}` };
13466
13603
  }
13467
13604
  if (await sha256File(outfit.reference.path) !== outfit.reference.sha256) {
@@ -13475,7 +13612,7 @@ async function inspectCharacterParent(spec, lock, seen) {
13475
13612
  const label = `${character.kind} parent ${spec.styleId}/${character.parentAssetId}`;
13476
13613
  const dependency = await inspectParent(parentSpec, lock, seen);
13477
13614
  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)) {
13615
+ if (!character.parentSha256 || !character.parentFile || !(0, import_node_fs12.existsSync)(character.parentFile)) {
13479
13616
  return { ready: false, reason: `${label} has no generated south-facing file yet` };
13480
13617
  }
13481
13618
  if (await sha256File(character.parentFile) !== character.parentSha256) {
@@ -13493,7 +13630,7 @@ async function inspectObjectProParent(spec, lock, seen) {
13493
13630
  const label = `${object.kind} parent ${spec.styleId}/${object.parentAssetId}`;
13494
13631
  const dependency = await inspectParent(parentSpec, lock, seen);
13495
13632
  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)) {
13633
+ if (!object.parentSha256 || !object.parentFile || !(0, import_node_fs12.existsSync)(object.parentFile)) {
13497
13634
  return { ready: false, reason: `${label} has no generated south-facing file yet` };
13498
13635
  }
13499
13636
  if (await sha256File(object.parentFile) !== object.parentSha256) {
@@ -13519,7 +13656,7 @@ async function inspectRevision(spec, lock, seen) {
13519
13656
  const members = await inspectSourceMembers(spec, lock);
13520
13657
  if (!members.ready) return members;
13521
13658
  } else {
13522
- if (!revision.sourceSha256 || !(0, import_node_fs11.existsSync)(revision.sourceFile)) {
13659
+ if (!revision.sourceSha256 || !(0, import_node_fs12.existsSync)(revision.sourceFile)) {
13523
13660
  return { ready: false, reason: `revision source is missing: ${revision.sourceFile}` };
13524
13661
  }
13525
13662
  if (await sha256File(revision.sourceFile) !== revision.sourceSha256) {
@@ -13527,7 +13664,7 @@ async function inspectRevision(spec, lock, seen) {
13527
13664
  }
13528
13665
  }
13529
13666
  if (revision.maskFile) {
13530
- if (!revision.maskSha256 || !(0, import_node_fs11.existsSync)(revision.maskFile)) {
13667
+ if (!revision.maskSha256 || !(0, import_node_fs12.existsSync)(revision.maskFile)) {
13531
13668
  return { ready: false, reason: `revision mask is missing: ${revision.maskFile}` };
13532
13669
  }
13533
13670
  if (await sha256File(revision.maskFile) !== revision.maskSha256) {
@@ -13535,7 +13672,7 @@ async function inspectRevision(spec, lock, seen) {
13535
13672
  }
13536
13673
  }
13537
13674
  if (revision.lastFrameFile) {
13538
- if (!revision.lastFrameSha256 || !(0, import_node_fs11.existsSync)(revision.lastFrameFile)) {
13675
+ if (!revision.lastFrameSha256 || !(0, import_node_fs12.existsSync)(revision.lastFrameFile)) {
13539
13676
  return { ready: false, reason: `revision last frame is missing: ${revision.lastFrameFile}` };
13540
13677
  }
13541
13678
  if (await sha256File(revision.lastFrameFile) !== revision.lastFrameSha256) {
@@ -13548,7 +13685,7 @@ async function inspectSourceMembers(spec, lock) {
13548
13685
  const revision = spec.revision;
13549
13686
  const members = revision.sourceMembers;
13550
13687
  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}` };
13688
+ if (!(0, import_node_fs12.existsSync)(member.file)) return { ready: false, reason: `revision source member is missing: ${member.file}` };
13552
13689
  if (await sha256File(member.file) !== member.sha256) {
13553
13690
  return { ready: false, reason: `revision source member changed after the manifest was resolved: ${member.file}` };
13554
13691
  }
@@ -13616,7 +13753,7 @@ async function inspectParent(spec, lock, seen) {
13616
13753
  }
13617
13754
  if (spec.source) {
13618
13755
  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}` };
13756
+ return (0, import_node_fs12.existsSync)(source) ? { ready: true, reason: "declared source is present" } : { ready: false, reason: `declared source is missing: ${spec.source}` };
13620
13757
  }
13621
13758
  const entry = lock.entries[key];
13622
13759
  if (!entry) return { ready: false, reason: "parent is not in the lockfile" };
@@ -13630,7 +13767,7 @@ async function inspectParent(spec, lock, seen) {
13630
13767
  for (let index = 0; index < entry.outputs.length; index++) {
13631
13768
  const output = entry.outputs[index];
13632
13769
  const file = currentEntryOutputPath(entry, spec, index);
13633
- if (!(0, import_node_fs11.existsSync)(file)) return { ready: false, reason: `parent output is missing: ${file}` };
13770
+ if (!(0, import_node_fs12.existsSync)(file)) return { ready: false, reason: `parent output is missing: ${file}` };
13634
13771
  if (await sha256File(file) !== output.sha256) {
13635
13772
  return { ready: false, reason: `parent output was modified: ${file}` };
13636
13773
  }
@@ -13725,7 +13862,7 @@ async function buildPlan(specs, lock, opts = {}) {
13725
13862
  state = "missing";
13726
13863
  reason = "--force";
13727
13864
  } 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))) {
13865
+ if ((0, import_node_fs13.existsSync)(import_node_path15.default.resolve(spec.root, spec.source))) {
13729
13866
  state = "ok";
13730
13867
  reason = `placed from ${spec.source}; not generated`;
13731
13868
  } else {
@@ -13733,7 +13870,7 @@ async function buildPlan(specs, lock, opts = {}) {
13733
13870
  reason = `declared source is missing: ${spec.source}`;
13734
13871
  }
13735
13872
  } else if (!entry) {
13736
- if ((0, import_node_fs12.existsSync)(spec.outFile)) {
13873
+ if ((0, import_node_fs13.existsSync)(spec.outFile)) {
13737
13874
  state = "untracked";
13738
13875
  reason = "file on disk, no provenance recorded";
13739
13876
  } else {
@@ -13746,7 +13883,7 @@ async function buildPlan(specs, lock, opts = {}) {
13746
13883
  } else if (spec.mirror && !mirrorCurrent(entry, lock.entries[lockKey(spec.styleId, spec.mirror.sourceAssetId)])) {
13747
13884
  state = "stale";
13748
13885
  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)))) {
13886
+ } else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !(0, import_node_fs13.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
13750
13887
  state = "stale";
13751
13888
  reason = "mirror output missing on disk; flip it again (no generation cost)";
13752
13889
  } else if (spec.character?.kind === "outfit" && entry.outfit?.sourceSha256 !== mirrorSourceHash(lock.entries[lockKey(spec.styleId, spec.character.parentAssetId)] ?? { outputs: [] })) {
@@ -13783,9 +13920,9 @@ async function buildPlan(specs, lock, opts = {}) {
13783
13920
  } else if (entry.status !== "downloaded") {
13784
13921
  state = "in-flight";
13785
13922
  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)))) {
13923
+ } else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !(0, import_node_fs13.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
13787
13924
  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(", ")}`;
13925
+ 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
13926
  } else if (await anyOutputModified(entry, spec)) {
13790
13927
  state = "orphaned";
13791
13928
  reason = "output modified since download";
@@ -13891,8 +14028,14 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
13891
14028
  if (import_node_path16.default.resolve(process.cwd()) !== root) loadEnvFiles(process.cwd());
13892
14029
  }
13893
14030
  const lockPath = import_node_path16.default.resolve(opts.lockPath ?? import_node_path16.default.join(root, "pixelkiln.lock.json"));
13894
- const loaded = await loadManifest(absolute);
13895
- const specs = await resolveSpecs(loaded, { styles: opts.styles ?? [], assets: opts.assets ?? [] });
14031
+ let loaded = await loadManifest(absolute, { lenient: opts.lenient });
14032
+ const unresolved = [];
14033
+ const specs = await resolveSpecs(loaded, {
14034
+ styles: opts.styles ?? [],
14035
+ assets: opts.assets ?? [],
14036
+ ...opts.lenient ? { onInvalid: (entry) => unresolved.push(entry) } : {}
14037
+ });
14038
+ if (unresolved.length) loaded = { ...loaded, invalid: [...loaded.invalid ?? [], ...unresolved] };
13896
14039
  const lock = await loadLock(lockPath);
13897
14040
  normalizeLockOutputPaths(lock, specs);
13898
14041
  const adapters = /* @__PURE__ */ new Map();
@@ -13921,7 +14064,7 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
13921
14064
 
13922
14065
  // src/recipes.ts
13923
14066
  var import_node_path17 = __toESM(require("path"), 1);
13924
- var import_node_fs13 = require("fs");
14067
+ var import_node_fs14 = require("fs");
13925
14068
  var import_promises9 = require("fs/promises");
13926
14069
  var import_node_url = require("url");
13927
14070
  var import_zod4 = require("zod");
@@ -14124,7 +14267,7 @@ async function readRecipeFile(recipePath, bundled) {
14124
14267
  return { recipe: parsed.data, authored: raw, path: absolute, dir: import_node_path17.default.dirname(absolute), bundled };
14125
14268
  }
14126
14269
  async function walkRecipeFiles(root) {
14127
- if (!(0, import_node_fs13.existsSync)(root)) return [];
14270
+ if (!(0, import_node_fs14.existsSync)(root)) return [];
14128
14271
  const out = [];
14129
14272
  for (const entry of await (0, import_promises9.readdir)(root, { withFileTypes: true })) {
14130
14273
  const resolved = import_node_path17.default.join(root, entry.name);
@@ -14162,7 +14305,7 @@ function parseSelector(selector) {
14162
14305
  }
14163
14306
  async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
14164
14307
  const local = import_node_path17.default.resolve(target);
14165
- if ((0, import_node_fs13.existsSync)(local)) {
14308
+ if ((0, import_node_fs14.existsSync)(local)) {
14166
14309
  const recipePath = import_node_path17.default.basename(local) === RECIPE_FILE ? local : import_node_path17.default.join(local, RECIPE_FILE);
14167
14310
  return readRecipeFile(recipePath, false);
14168
14311
  }
@@ -14178,7 +14321,7 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
14178
14321
  }
14179
14322
  async function verifyFile(root, file) {
14180
14323
  const absolute = import_node_path17.default.resolve(root, ...file.path.split("/"));
14181
- if (!(0, import_node_fs13.existsSync)(absolute)) {
14324
+ if (!(0, import_node_fs14.existsSync)(absolute)) {
14182
14325
  return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
14183
14326
  }
14184
14327
  const actualSha256 = await sha256File(absolute);
@@ -14256,7 +14399,7 @@ async function installRecipe(target, options = {}) {
14256
14399
  })));
14257
14400
  if (!options.force) {
14258
14401
  for (const file of files) {
14259
- if (!(0, import_node_fs13.existsSync)(file.path)) continue;
14402
+ if (!(0, import_node_fs14.existsSync)(file.path)) continue;
14260
14403
  const current = await (0, import_promises9.readFile)(file.path);
14261
14404
  if (!current.equals(file.data)) {
14262
14405
  throw new OverwriteRefusedError(
@@ -14282,7 +14425,7 @@ async function installRecipe(target, options = {}) {
14282
14425
 
14283
14426
  // src/pipeline/audit.ts
14284
14427
  var import_promises10 = require("fs/promises");
14285
- var import_node_fs14 = require("fs");
14428
+ var import_node_fs15 = require("fs");
14286
14429
  var import_node_path18 = __toESM(require("path"), 1);
14287
14430
  function paletteDistance(asset, reference) {
14288
14431
  if (!asset.length || !reference.length) return 0;
@@ -14319,7 +14462,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
14319
14462
  const unreadable = [];
14320
14463
  for (const spec of mine) {
14321
14464
  for (const output of resolveSpecOutputs(spec, lock, loaded.root)) {
14322
- if (!(0, import_node_fs14.existsSync)(output.absolutePath)) {
14465
+ if (!(0, import_node_fs15.existsSync)(output.absolutePath)) {
14323
14466
  missing.push(output.id);
14324
14467
  continue;
14325
14468
  }
@@ -14349,7 +14492,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
14349
14492
  const refPalettes = [];
14350
14493
  for (const img of style.styleImages) {
14351
14494
  const abs = import_node_path18.default.resolve(loaded.root, img.path);
14352
- if (!(0, import_node_fs14.existsSync)(abs)) continue;
14495
+ if (!(0, import_node_fs15.existsSync)(abs)) continue;
14353
14496
  try {
14354
14497
  refPalettes.push(extractPalette(decodePng(await (0, import_promises10.readFile)(abs)), 12));
14355
14498
  } catch {
@@ -14428,7 +14571,7 @@ function hex(c) {
14428
14571
 
14429
14572
  // src/pipeline/quality-regression.ts
14430
14573
  var import_node_path19 = __toESM(require("path"), 1);
14431
- var import_node_fs15 = require("fs");
14574
+ var import_node_fs16 = require("fs");
14432
14575
  var import_promises11 = require("fs/promises");
14433
14576
  var import_zod5 = require("zod");
14434
14577
  var SHA256_RE2 = /^[0-9a-f]{64}$/;
@@ -14671,7 +14814,7 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
14671
14814
  cases
14672
14815
  });
14673
14816
  const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
14674
- if ((0, import_node_fs15.existsSync)(absolute) && !options.force) {
14817
+ if ((0, import_node_fs16.existsSync)(absolute) && !options.force) {
14675
14818
  const current = await (0, import_promises11.readFile)(absolute);
14676
14819
  if (!current.equals(data)) {
14677
14820
  throw new OverwriteRefusedError(
@@ -14683,6 +14826,63 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
14683
14826
  const result = await writeArtifactBundle([{ path: absolute, data }]);
14684
14827
  return { baseline, path: absolute, changed: result.changed.length > 0 };
14685
14828
  }
14829
+ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
14830
+ const absolute = import_node_path19.default.resolve(baselinePath);
14831
+ if (!(0, import_node_fs16.existsSync)(absolute)) {
14832
+ throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
14833
+ }
14834
+ let raw;
14835
+ try {
14836
+ raw = JSON.parse(await (0, import_promises11.readFile)(absolute, "utf8"));
14837
+ } catch (error) {
14838
+ throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
14839
+ }
14840
+ if (!Array.isArray(raw.cases)) throw new Error(`Quality baseline ${absolute} has no cases array.`);
14841
+ const byId = new Map(inputs.map((input) => [input.id, input]));
14842
+ const unknown = only.filter((id) => !byId.has(id));
14843
+ if (unknown.length) {
14844
+ throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
14845
+ }
14846
+ const root = import_node_path19.default.dirname(absolute);
14847
+ const cases = [...raw.cases];
14848
+ const report = [];
14849
+ for (const id of only) {
14850
+ const input = byId.get(id);
14851
+ if (import_node_path19.default.resolve(input.file) === absolute || input.record && import_node_path19.default.resolve(input.record) === absolute) {
14852
+ throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
14853
+ }
14854
+ const expected = await measureImageQuality(input.file);
14855
+ let record;
14856
+ if (input.record) {
14857
+ await verifyRecordForImage(input.record, input.file);
14858
+ record = { path: portableRelative2(root, input.record), sha256: await sha256File(input.record) };
14859
+ }
14860
+ const index = cases.findIndex((entry) => entry.id === id);
14861
+ const before = index >= 0 ? cases[index].expected ?? {} : {};
14862
+ const next = {
14863
+ id,
14864
+ file: portableRelative2(root, input.file),
14865
+ ...record ? { record } : {},
14866
+ expected,
14867
+ tolerances: index >= 0 && cases[index].tolerances ? cases[index].tolerances : input.tolerances
14868
+ };
14869
+ if (index >= 0) cases[index] = next;
14870
+ else cases.push(next);
14871
+ const changes = [];
14872
+ for (const metric of Object.keys(expected)) {
14873
+ if (JSON.stringify(before[metric]) !== JSON.stringify(expected[metric])) {
14874
+ changes.push({ metric, before: before[metric] ?? null, after: expected[metric] });
14875
+ }
14876
+ }
14877
+ report.push({ id, kind: index < 0 ? "added" : changes.length ? "updated" : "unchanged", changes });
14878
+ }
14879
+ const baseline = QualityBaselineSchema.parse({ ...raw, cases });
14880
+ const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
14881
+ const current = await (0, import_promises11.readFile)(absolute);
14882
+ const changed = !current.equals(data);
14883
+ if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
14884
+ return { baseline, path: absolute, changed, cases: report };
14885
+ }
14686
14886
  async function readQualityBaseline(baselinePath) {
14687
14887
  const absolute = import_node_path19.default.resolve(baselinePath);
14688
14888
  let raw;
@@ -14693,9 +14893,23 @@ async function readQualityBaseline(baselinePath) {
14693
14893
  }
14694
14894
  const parsed = QualityBaselineSchema.safeParse(raw);
14695
14895
  if (!parsed.success) {
14896
+ const cases = raw?.cases;
14897
+ const where = (issuePath) => {
14898
+ if (issuePath[0] === "cases" && typeof issuePath[1] === "number") {
14899
+ const id = cases?.[issuePath[1]]?.id;
14900
+ const rest = issuePath.slice(2).join(".");
14901
+ return typeof id === "string" ? `cases[${id}]${rest ? `.${rest}` : ""}` : issuePath.join(".");
14902
+ }
14903
+ return issuePath.join(".") || "$";
14904
+ };
14905
+ const missing = [...new Set(parsed.error.issues.flatMap((issue) => {
14906
+ const id = issue.path[0] === "cases" && typeof issue.path[1] === "number" ? cases?.[issue.path[1]]?.id : void 0;
14907
+ return issue.code === "invalid_type" && issue.received === "undefined" && typeof id === "string" ? [id] : [];
14908
+ }))];
14696
14909
  throw new Error(
14697
14910
  `Invalid quality baseline ${absolute}:
14698
- ` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
14911
+ ` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
14912
+ 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
14913
  );
14700
14914
  }
14701
14915
  return parsed.data;
@@ -14811,13 +15025,13 @@ async function checkQualityBaseline(baselinePath) {
14811
15025
  }
14812
15026
 
14813
15027
  // src/pipeline/cache-health.ts
14814
- var import_node_fs19 = require("fs");
15028
+ var import_node_fs20 = require("fs");
14815
15029
  var import_promises14 = require("fs/promises");
14816
15030
  var import_node_path23 = __toESM(require("path"), 1);
14817
15031
 
14818
15032
  // src/cache.ts
14819
15033
  var import_promises12 = require("fs/promises");
14820
- var import_node_fs16 = require("fs");
15034
+ var import_node_fs17 = require("fs");
14821
15035
  var import_node_path20 = __toESM(require("path"), 1);
14822
15036
  var import_zod6 = require("zod");
14823
15037
  var HashCacheSchema = import_zod6.z.object({
@@ -14832,10 +15046,10 @@ function isSha256Hash(value) {
14832
15046
  function parseCache(value) {
14833
15047
  return HashCacheSchema.parse(value);
14834
15048
  }
14835
- async function loadCache(path39) {
14836
- if (!(0, import_node_fs16.existsSync)(path39)) return { version: 1, hashes: {} };
15049
+ async function loadCache(path40) {
15050
+ if (!(0, import_node_fs17.existsSync)(path40)) return { version: 1, hashes: {} };
14837
15051
  try {
14838
- const parsed = HashCacheSchema.safeParse(JSON.parse(await (0, import_promises12.readFile)(path39, "utf8")));
15052
+ const parsed = HashCacheSchema.safeParse(JSON.parse(await (0, import_promises12.readFile)(path40, "utf8")));
14839
15053
  if (!parsed.success) return { version: 1, hashes: {} };
14840
15054
  return {
14841
15055
  version: 1,
@@ -14847,18 +15061,18 @@ async function loadCache(path39) {
14847
15061
  return { version: 1, hashes: {} };
14848
15062
  }
14849
15063
  }
14850
- async function saveCache(path39, cache) {
15064
+ async function saveCache(path40, cache) {
14851
15065
  const sorted = {};
14852
15066
  for (const key of Object.keys(cache.hashes).sort()) {
14853
15067
  const hash = cache.hashes[key];
14854
15068
  if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key}`);
14855
15069
  sorted[key] = hash;
14856
15070
  }
14857
- await (0, import_promises12.mkdir)(import_node_path20.default.dirname(import_node_path20.default.resolve(path39)), { recursive: true });
14858
- const tmp = `${path39}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
15071
+ await (0, import_promises12.mkdir)(import_node_path20.default.dirname(import_node_path20.default.resolve(path40)), { recursive: true });
15072
+ const tmp = `${path40}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
14859
15073
  try {
14860
15074
  await (0, import_promises12.writeFile)(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
14861
- await (0, import_promises12.rename)(tmp, path39);
15075
+ await (0, import_promises12.rename)(tmp, path40);
14862
15076
  } finally {
14863
15077
  await (0, import_promises12.rm)(tmp, { force: true });
14864
15078
  }
@@ -14882,11 +15096,11 @@ function cachePathFor(lockPath) {
14882
15096
  }
14883
15097
 
14884
15098
  // src/pipeline/history.ts
14885
- var import_node_fs18 = require("fs");
15099
+ var import_node_fs19 = require("fs");
14886
15100
  var import_node_path22 = __toESM(require("path"), 1);
14887
15101
 
14888
15102
  // src/pipeline/fetch.ts
14889
- var import_node_fs17 = require("fs");
15103
+ var import_node_fs18 = require("fs");
14890
15104
  var import_promises13 = require("fs/promises");
14891
15105
  var import_node_path21 = __toESM(require("path"), 1);
14892
15106
  async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
@@ -14906,15 +15120,15 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
14906
15120
  if (spec && e.specHash === spec.specHash && e.outputs.length && !postprocessCurrent(e, spec)) {
14907
15121
  return Boolean(opts.force) || e.outputs.every((output) => {
14908
15122
  const file = resolveOutputPath(output.path, spec.root);
14909
- return (0, import_node_fs17.existsSync)(file) && sha256((0, import_node_fs17.readFileSync)(file)) === output.sha256;
15123
+ return (0, import_node_fs18.existsSync)(file) && sha256((0, import_node_fs18.readFileSync)(file)) === output.sha256;
14910
15124
  });
14911
15125
  }
14912
15126
  if (!opts.repair) return false;
14913
15127
  if (e.outputs.length === 0 || !spec) return true;
14914
15128
  return e.outputs.some((output) => {
14915
15129
  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));
15130
+ if (!(0, import_node_fs18.existsSync)(file)) return true;
15131
+ const current = sha256((0, import_node_fs18.readFileSync)(file));
14918
15132
  if (current === output.sha256) return false;
14919
15133
  return Boolean(opts.force) || (e.supersededOutputs ?? []).some((old) => old.sha256 === current);
14920
15134
  });
@@ -15004,7 +15218,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
15004
15218
  }
15005
15219
  let raw = null;
15006
15220
  let final = null;
15007
- if ((0, import_node_fs17.existsSync)(target)) {
15221
+ if ((0, import_node_fs18.existsSync)(target)) {
15008
15222
  const currentHash = await sha256File(target);
15009
15223
  if (recorded && currentHash === recorded.sha256) {
15010
15224
  if (!fresh && !reapply) {
@@ -15150,7 +15364,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
15150
15364
  }
15151
15365
  async function readCachedMedia(cacheDir, hash, mediaType) {
15152
15366
  const file = import_node_path21.default.join(cacheDir, cacheFileName(hash, mediaType));
15153
- if (!(0, import_node_fs17.existsSync)(file)) return null;
15367
+ if (!(0, import_node_fs18.existsSync)(file)) return null;
15154
15368
  try {
15155
15369
  const buf = await (0, import_promises13.readFile)(file);
15156
15370
  if (sha256(buf) !== hash) return null;
@@ -15171,7 +15385,7 @@ async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
15171
15385
  try {
15172
15386
  await (0, import_promises13.rename)(tmp, file);
15173
15387
  } catch (err) {
15174
- if (!(0, import_node_fs17.existsSync)(file)) throw err;
15388
+ if (!(0, import_node_fs18.existsSync)(file)) throw err;
15175
15389
  } finally {
15176
15390
  await (0, import_promises13.rm)(tmp, { force: true });
15177
15391
  }
@@ -15293,7 +15507,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
15293
15507
  }
15294
15508
  for (let i = 0; i < entry.outputs.length; i++) {
15295
15509
  const file = currentEntryOutputPath(entry, spec, i);
15296
- if (!(0, import_node_fs18.existsSync)(file)) continue;
15510
+ if (!(0, import_node_fs19.existsSync)(file)) continue;
15297
15511
  if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
15298
15512
  throw new OverwriteRefusedError(
15299
15513
  `${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 +15570,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
15356
15570
 
15357
15571
  // src/pipeline/cache-health.ts
15358
15572
  async function inspectCaches(lock, lockPath, options = {}) {
15359
- if (options.prune && !(0, import_node_fs19.existsSync)(lockPath)) {
15573
+ if (options.prune && !(0, import_node_fs20.existsSync)(lockPath)) {
15360
15574
  throw new Error(`Refusing to prune without an existing lockfile at ${import_node_path23.default.resolve(lockPath)}`);
15361
15575
  }
15362
15576
  const contentDir = import_node_path23.default.resolve(import_node_path23.default.dirname(lockPath), ".pixelkiln", "cache");
@@ -15399,7 +15613,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
15399
15613
  async function inspectContentCache(contentDir, referenced) {
15400
15614
  const report = {
15401
15615
  path: contentDir,
15402
- exists: (0, import_node_fs19.existsSync)(contentDir),
15616
+ exists: (0, import_node_fs20.existsSync)(contentDir),
15403
15617
  files: 0,
15404
15618
  bytes: 0,
15405
15619
  valid: 0,
@@ -15463,7 +15677,7 @@ async function inspectContentCache(contentDir, referenced) {
15463
15677
  async function inspectRemoteHashCache(remotePath) {
15464
15678
  const report = {
15465
15679
  path: remotePath,
15466
- exists: (0, import_node_fs19.existsSync)(remotePath),
15680
+ exists: (0, import_node_fs20.existsSync)(remotePath),
15467
15681
  entries: 0,
15468
15682
  valid: 0,
15469
15683
  invalidIds: [],
@@ -15487,7 +15701,7 @@ async function inspectRemoteHashCache(remotePath) {
15487
15701
  }
15488
15702
 
15489
15703
  // src/pipeline/pack.ts
15490
- var import_node_fs20 = require("fs");
15704
+ var import_node_fs21 = require("fs");
15491
15705
  var import_node_path24 = __toESM(require("path"), 1);
15492
15706
  var DEFAULT_FRAME_SET_FPS = 12;
15493
15707
  function resolvePackInputs(raw, inputsFilePath) {
@@ -15521,7 +15735,7 @@ function packSprites(inputs, options = {}) {
15521
15735
  for (const input of ordered) {
15522
15736
  let sourceHash = null;
15523
15737
  try {
15524
- const bytes = (0, import_node_fs20.readFileSync)(input.path);
15738
+ const bytes = (0, import_node_fs21.readFileSync)(input.path);
15525
15739
  sourceHash = sha256(bytes);
15526
15740
  const png = decodePng(bytes);
15527
15741
  sprites.push({ id: input.id, width: png.width, height: png.height, pixels: png.pixels });
@@ -15680,7 +15894,7 @@ function mountSprites(placements, options) {
15680
15894
  for (const p of placements) {
15681
15895
  let sourceHash = null;
15682
15896
  try {
15683
- const bytes = (0, import_node_fs20.readFileSync)(p.path);
15897
+ const bytes = (0, import_node_fs21.readFileSync)(p.path);
15684
15898
  sourceHash = sha256(bytes);
15685
15899
  const png = decodePng(bytes);
15686
15900
  if (png.width > cellWidth || png.height > cellHeight) {
@@ -15784,7 +15998,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
15784
15998
  `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
15999
  );
15786
16000
  }
15787
- const basePng = mount.base ? (0, import_node_fs20.readFileSync)(import_node_path24.default.resolve(manifestDir, mount.base)) : void 0;
16001
+ const basePng = mount.base ? (0, import_node_fs21.readFileSync)(import_node_path24.default.resolve(manifestDir, mount.base)) : void 0;
15788
16002
  const mounted = mountSprites(placements, {
15789
16003
  cellWidth: mount.cellWidth,
15790
16004
  cellHeight: mount.cellHeight,
@@ -16638,9 +16852,81 @@ async function poll(provider, lock, lockPath, opts = {}) {
16638
16852
  }
16639
16853
 
16640
16854
  // src/pipeline/doctor.ts
16641
- var import_node_fs21 = require("fs");
16855
+ var import_node_fs23 = require("fs");
16642
16856
  var import_promises15 = require("fs/promises");
16857
+ var import_node_path26 = __toESM(require("path"), 1);
16858
+
16859
+ // src/pipeline/install-check.ts
16860
+ var import_node_fs22 = require("fs");
16643
16861
  var import_node_path25 = __toESM(require("path"), 1);
16862
+ function readJson(file) {
16863
+ try {
16864
+ return JSON.parse((0, import_node_fs22.readFileSync)(file, "utf8"));
16865
+ } catch {
16866
+ return null;
16867
+ }
16868
+ }
16869
+ function readInstallFacts(manifestDir, running) {
16870
+ let dir = import_node_path25.default.resolve(manifestDir);
16871
+ for (let depth = 0; depth < 4; depth++) {
16872
+ const pkg = readJson(import_node_path25.default.join(dir, "package.json"));
16873
+ if (pkg) {
16874
+ const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
16875
+ if (pinned) {
16876
+ const installedPkg = readJson(import_node_path25.default.join(dir, "node_modules", "pixelkiln", "package.json"));
16877
+ const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
16878
+ return { pinned, installed, running };
16879
+ }
16880
+ }
16881
+ const parent = import_node_path25.default.dirname(dir);
16882
+ if (parent === dir || !(0, import_node_fs22.existsSync)(parent)) break;
16883
+ dir = parent;
16884
+ }
16885
+ return null;
16886
+ }
16887
+ function parse(version) {
16888
+ const match = /(\d+)\.(\d+)\.(\d+)/.exec(version);
16889
+ return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
16890
+ }
16891
+ function compare(a, b) {
16892
+ return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
16893
+ }
16894
+ function checkInstall(facts) {
16895
+ const findings = [];
16896
+ const pin = parse(facts.pinned ?? "");
16897
+ const installed = facts.installed ? parse(facts.installed) : null;
16898
+ const running = facts.running ? parse(facts.running) : null;
16899
+ const exact = /^[=v]*\d+\.\d+\.\d+$/.test((facts.pinned ?? "").trim());
16900
+ if (pin && facts.installed && installed) {
16901
+ const behind = exact ? compare(installed, pin) !== 0 : compare(installed, pin) < 0;
16902
+ if (behind) {
16903
+ findings.push({
16904
+ level: "warning",
16905
+ message: `package.json asks for pixelkiln ${facts.pinned} but node_modules has ${facts.installed}; run \`npm install\` so the CLI matches the manifest.`
16906
+ });
16907
+ }
16908
+ } else if (pin && !facts.installed) {
16909
+ findings.push({
16910
+ level: "warning",
16911
+ message: `package.json asks for pixelkiln ${facts.pinned} but it is not installed in node_modules; run \`npm install\`.`
16912
+ });
16913
+ }
16914
+ if (running && installed && compare(running, installed) !== 0) {
16915
+ findings.push({
16916
+ level: "warning",
16917
+ message: `running pixelkiln ${facts.running}, but this project's node_modules has ${facts.installed}. Another install is first on your PATH; use \`npx pixelkiln\` or remove the global one.`
16918
+ });
16919
+ }
16920
+ if (!findings.length) {
16921
+ findings.push({
16922
+ level: "ok",
16923
+ message: `pixelkiln ${facts.running ?? facts.installed ?? "?"} matches package.json (${facts.pinned})`
16924
+ });
16925
+ }
16926
+ return findings;
16927
+ }
16928
+
16929
+ // src/pipeline/doctor.ts
16644
16930
  async function doctor(loaded, specs, lock, lockPath, opts = {}) {
16645
16931
  const checks = [];
16646
16932
  const add = (id, level, message6) => checks.push({ id, level, message: message6 });
@@ -16649,16 +16935,25 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
16649
16935
  "ok",
16650
16936
  `${Object.keys(loaded.manifest.styles).length} style(s), ${Object.keys(loaded.manifest.assets).length} asset(s), ${specs.length} resolved spec(s)`
16651
16937
  );
16938
+ for (const entry of loaded.invalid ?? []) {
16939
+ add(
16940
+ "invalid-entry",
16941
+ "error",
16942
+ `${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
16943
+ );
16944
+ }
16945
+ const facts = readInstallFacts(import_node_path26.default.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
16946
+ if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
16652
16947
  add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
16653
16948
  const dirs = [...new Set(specs.flatMap((spec) => [
16654
- import_node_path25.default.dirname(spec.outFile),
16655
- ...spec.quality ? [import_node_path25.default.dirname(spec.quality.outFile)] : []
16949
+ import_node_path26.default.dirname(spec.outFile),
16950
+ ...spec.quality ? [import_node_path26.default.dirname(spec.quality.outFile)] : []
16656
16951
  ]))];
16657
16952
  const unwritable = [];
16658
16953
  for (const dir of dirs) {
16659
16954
  const ancestor = await nearestExistingDirectory(dir);
16660
16955
  try {
16661
- await (0, import_promises15.access)(ancestor, import_node_fs21.constants.W_OK);
16956
+ await (0, import_promises15.access)(ancestor, import_node_fs23.constants.W_OK);
16662
16957
  } catch {
16663
16958
  unwritable.push(dir);
16664
16959
  }
@@ -16675,7 +16970,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
16675
16970
  for (let index = 0; index < entry.outputs.length; index++) {
16676
16971
  const output = entry.outputs[index];
16677
16972
  const spec = specByKey.get(key);
16678
- const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, import_node_path25.default.dirname(lockPath));
16973
+ const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, import_node_path26.default.dirname(lockPath));
16679
16974
  const owner = outputOwners.get(absolute);
16680
16975
  if (owner && owner !== key) duplicateOutputs.push(`${output.path} (${owner}, ${key})`);
16681
16976
  outputOwners.set(absolute, key);
@@ -16690,7 +16985,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
16690
16985
  } else {
16691
16986
  add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
16692
16987
  }
16693
- const cacheDir = import_node_path25.default.join(import_node_path25.default.dirname(lockPath), ".pixelkiln", "cache");
16988
+ const cacheDir = import_node_path26.default.join(import_node_path26.default.dirname(lockPath), ".pixelkiln", "cache");
16694
16989
  const stranded = [];
16695
16990
  const invalidState = [];
16696
16991
  const staleMapUrls = [];
@@ -16706,11 +17001,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
16706
17001
  const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
16707
17002
  let hasCache = false;
16708
17003
  for (const output of entry.outputs) {
16709
- const cached = import_node_path25.default.join(
17004
+ const cached2 = import_node_path26.default.join(
16710
17005
  cacheDir,
16711
17006
  cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
16712
17007
  );
16713
- if ((0, import_node_fs21.existsSync)(cached) && await sha256File(cached) === output.sha256) {
17008
+ if ((0, import_node_fs23.existsSync)(cached2) && await sha256File(cached2) === output.sha256) {
16714
17009
  hasCache = true;
16715
17010
  break;
16716
17011
  }
@@ -16806,16 +17101,16 @@ async function nearestExistingDirectory(start) {
16806
17101
  if ((await (0, import_promises15.stat)(current)).isDirectory()) return current;
16807
17102
  } catch {
16808
17103
  }
16809
- const parent = import_node_path25.default.dirname(current);
17104
+ const parent = import_node_path26.default.dirname(current);
16810
17105
  if (parent === current) return current;
16811
17106
  current = parent;
16812
17107
  }
16813
17108
  }
16814
17109
 
16815
17110
  // src/pipeline/adopt.ts
16816
- var import_node_fs22 = require("fs");
17111
+ var import_node_fs24 = require("fs");
16817
17112
  var import_promises16 = require("fs/promises");
16818
- var import_node_path26 = __toESM(require("path"), 1);
17113
+ var import_node_path27 = __toESM(require("path"), 1);
16819
17114
  async function adopt(provider, specs, lock, lockPath, opts = {}) {
16820
17115
  const log = opts.onProgress ?? (() => {
16821
17116
  });
@@ -16826,7 +17121,7 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
16826
17121
  const localByHash = /* @__PURE__ */ new Map();
16827
17122
  const unmatchedLocal = [];
16828
17123
  for (const spec of specs) {
16829
- if (!(0, import_node_fs22.existsSync)(spec.outFile)) {
17124
+ if (!(0, import_node_fs24.existsSync)(spec.outFile)) {
16830
17125
  unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
16831
17126
  continue;
16832
17127
  }
@@ -16947,14 +17242,125 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
16947
17242
  return count;
16948
17243
  }
16949
17244
 
17245
+ // src/pipeline/import.ts
17246
+ var import_node_fs25 = require("fs");
17247
+ var import_promises17 = require("fs/promises");
17248
+ function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
17249
+ const png = decodePng(bytes);
17250
+ const at = now.toISOString();
17251
+ return {
17252
+ styleId: spec.styleId,
17253
+ assetId: spec.assetId,
17254
+ specHash: spec.specHash,
17255
+ generator: spec.generator,
17256
+ prompt: spec.prompt,
17257
+ width: png.width,
17258
+ height: png.height,
17259
+ jobId: opts.objectId ?? null,
17260
+ objectId: opts.objectId ?? null,
17261
+ reviewObjectId: null,
17262
+ candidateIndex: null,
17263
+ status: "downloaded",
17264
+ error: null,
17265
+ sourceUrl: null,
17266
+ sourceUrls: [],
17267
+ outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
17268
+ submittedAt: null,
17269
+ downloadedAt: at,
17270
+ cost: 0,
17271
+ costUnit: spec.costUnit,
17272
+ provider: spec.provider,
17273
+ imported: {
17274
+ source: opts.source ?? "external",
17275
+ ...opts.note ? { note: opts.note } : {},
17276
+ importedAt: at
17277
+ }
17278
+ };
17279
+ }
17280
+ function unimportable(spec) {
17281
+ if (spec.character) return "a character is several files; import it with account adopt";
17282
+ if (spec.vfx) return "an effect is rendered from its recipe, not imported";
17283
+ if (!spec.outFile.toLowerCase().endsWith(".png")) return "only a single PNG output can be imported";
17284
+ return null;
17285
+ }
17286
+ async function importLocal(specs, lock, lockPath, opts = {}) {
17287
+ if (opts.objectId && specs.length !== 1) {
17288
+ throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
17289
+ }
17290
+ const imported = [];
17291
+ const skipped = [];
17292
+ for (const spec of specs) {
17293
+ const key = lockKey(spec.styleId, spec.assetId);
17294
+ const reason = unimportable(spec);
17295
+ if (reason) {
17296
+ skipped.push({ key, reason });
17297
+ continue;
17298
+ }
17299
+ if (!(0, import_node_fs25.existsSync)(spec.outFile)) {
17300
+ skipped.push({ key, reason: `no file at ${spec.outFile}` });
17301
+ continue;
17302
+ }
17303
+ if (lock.entries[key] && !opts.force) {
17304
+ skipped.push({ key, reason: "already in the lockfile (use --force to replace it)" });
17305
+ continue;
17306
+ }
17307
+ let patch;
17308
+ try {
17309
+ patch = buildImportedEntry(spec, await (0, import_promises17.readFile)(spec.outFile), opts);
17310
+ } catch (error) {
17311
+ skipped.push({ key, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
17312
+ continue;
17313
+ }
17314
+ if (opts.dryRun) {
17315
+ imported.push({ key, entry: patch });
17316
+ continue;
17317
+ }
17318
+ imported.push({ key, entry: upsert(lock, key, patch) });
17319
+ }
17320
+ if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
17321
+ return { imported, skipped };
17322
+ }
17323
+ async function reportSpecHashes(specs, lock) {
17324
+ const reports = [];
17325
+ for (const spec of specs) {
17326
+ const key = lockKey(spec.styleId, spec.assetId);
17327
+ let bytes = null;
17328
+ if ((0, import_node_fs25.existsSync)(spec.outFile)) bytes = await (0, import_promises17.readFile)(spec.outFile);
17329
+ let wouldImport = null;
17330
+ if (bytes && !unimportable(spec)) {
17331
+ try {
17332
+ wouldImport = buildImportedEntry(spec, bytes);
17333
+ } catch {
17334
+ wouldImport = null;
17335
+ }
17336
+ }
17337
+ const entry = lock.entries[key];
17338
+ const fileSha256 = bytes ? sha256(bytes) : null;
17339
+ const outputSha256 = entry?.outputs[0]?.sha256 ?? null;
17340
+ reports.push({
17341
+ key,
17342
+ specHash: spec.specHash,
17343
+ file: spec.outFile,
17344
+ fileSha256,
17345
+ lock: entry ? {
17346
+ specHash: entry.specHash,
17347
+ outputSha256,
17348
+ matches: entry.specHash === spec.specHash && outputSha256 !== null && outputSha256 === fileSha256
17349
+ } : null,
17350
+ wouldImport
17351
+ });
17352
+ }
17353
+ return reports;
17354
+ }
17355
+
16950
17356
  // src/pick/server.ts
16951
- var import_node_fs24 = require("fs");
16952
- var import_promises19 = require("fs/promises");
17357
+ var import_node_fs27 = require("fs");
17358
+ var import_promises20 = require("fs/promises");
16953
17359
 
16954
17360
  // src/pipeline/init.ts
16955
- var import_promises17 = require("fs/promises");
16956
- var import_node_fs23 = require("fs");
16957
- var import_node_path27 = __toESM(require("path"), 1);
17361
+ var import_promises18 = require("fs/promises");
17362
+ var import_node_fs26 = require("fs");
17363
+ var import_node_path28 = __toESM(require("path"), 1);
16958
17364
  function pngSize(buf) {
16959
17365
  if (buf.length < 24) return null;
16960
17366
  const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
@@ -16967,8 +17373,8 @@ function slugify(value) {
16967
17373
  }
16968
17374
  async function walk(dir, exclude) {
16969
17375
  const out = [];
16970
- for (const entry of await (0, import_promises17.readdir)(dir, { withFileTypes: true })) {
16971
- const full = import_node_path27.default.join(dir, entry.name);
17376
+ for (const entry of await (0, import_promises18.readdir)(dir, { withFileTypes: true })) {
17377
+ const full = import_node_path28.default.join(dir, entry.name);
16972
17378
  if (exclude.some((x) => full.includes(x))) continue;
16973
17379
  if (entry.isDirectory()) out.push(...await walk(full, exclude));
16974
17380
  else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
@@ -16982,14 +17388,14 @@ async function scanAssets(root, opts = {}) {
16982
17388
  const skipped = [];
16983
17389
  const seen = /* @__PURE__ */ new Map();
16984
17390
  for (const file of files.sort()) {
16985
- const size = pngSize(await (0, import_promises17.readFile)(file));
17391
+ const size = pngSize(await (0, import_promises18.readFile)(file));
16986
17392
  if (!size) {
16987
17393
  skipped.push(`${file} (not a readable PNG)`);
16988
17394
  continue;
16989
17395
  }
16990
- const rel = import_node_path27.default.relative(root, file);
16991
- const category = import_node_path27.default.dirname(rel) === "." ? "" : import_node_path27.default.dirname(rel);
16992
- let id = slugify(import_node_path27.default.basename(rel));
17396
+ const rel = import_node_path28.default.relative(root, file);
17397
+ const category = import_node_path28.default.dirname(rel) === "." ? "" : import_node_path28.default.dirname(rel);
17398
+ let id = slugify(import_node_path28.default.basename(rel));
16993
17399
  if (seen.has(id)) {
16994
17400
  const n = seen.get(id) + 1;
16995
17401
  seen.set(id, n);
@@ -17463,7 +17869,7 @@ document.getElementById('submit').onclick = async () => {
17463
17869
 
17464
17870
  // src/pick/review-server.ts
17465
17871
  var import_node_http = require("http");
17466
- var import_promises18 = require("fs/promises");
17872
+ var import_promises19 = require("fs/promises");
17467
17873
  function serveReviewPage(opts) {
17468
17874
  const log = opts.onProgress ?? (() => {
17469
17875
  });
@@ -17472,7 +17878,7 @@ function serveReviewPage(opts) {
17472
17878
  if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
17473
17879
  try {
17474
17880
  const asset = opts.assets.get(req.url);
17475
- const bytes = await (0, import_promises18.readFile)(asset.path);
17881
+ const bytes = await (0, import_promises19.readFile)(asset.path);
17476
17882
  res.writeHead(200, {
17477
17883
  "Content-Type": asset.contentType,
17478
17884
  "Cache-Control": "no-store",
@@ -17548,13 +17954,13 @@ async function currentArt(entry, spec) {
17548
17954
  const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
17549
17955
  if (!previous) return null;
17550
17956
  const file = resolveOutputPath(previous.path, spec.root);
17551
- if (!(0, import_node_fs24.existsSync)(file)) return null;
17957
+ if (!(0, import_node_fs27.existsSync)(file)) return null;
17552
17958
  const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
17553
17959
  if (!contentType) return null;
17554
17960
  let width = entry.width;
17555
17961
  let height = entry.height;
17556
17962
  if (contentType === "image/png") {
17557
- const size = pngSize(await (0, import_promises19.readFile)(file));
17963
+ const size = pngSize(await (0, import_promises20.readFile)(file));
17558
17964
  if (size) ({ width, height } = size);
17559
17965
  }
17560
17966
  return { path: file, contentType, width, height };
@@ -17562,7 +17968,7 @@ async function currentArt(entry, spec) {
17562
17968
  async function cachedFrame(url) {
17563
17969
  if (!url.startsWith("file://")) return null;
17564
17970
  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";
17971
+ const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await (0, import_promises20.readFile)(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
17566
17972
  return { path: file, contentType };
17567
17973
  }
17568
17974
  async function prepareReview(provider, lock, opts = {}) {
@@ -17588,15 +17994,15 @@ async function prepareReview(provider, lock, opts = {}) {
17588
17994
  const frameAssets = [];
17589
17995
  const frameSizes = [];
17590
17996
  for (const [index, url] of urls.entries()) {
17591
- const cached = await cachedFrame(url);
17592
- if (!cached) {
17997
+ const cached2 = await cachedFrame(url);
17998
+ if (!cached2) {
17593
17999
  frameUrls.push(url);
17594
18000
  frameSizes.push(null);
17595
18001
  continue;
17596
18002
  }
17597
- frameSizes.push(cached.contentType === "image/png" ? pngSize(await (0, import_promises19.readFile)(cached.path).catch(() => Buffer.alloc(0))) : null);
18003
+ frameSizes.push(cached2.contentType === "image/png" ? pngSize(await (0, import_promises20.readFile)(cached2.path).catch(() => Buffer.alloc(0))) : null);
17598
18004
  const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
17599
- frameAssets.push([route, cached]);
18005
+ frameAssets.push([route, cached2]);
17600
18006
  frameUrls.push(route);
17601
18007
  }
17602
18008
  const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String(groups.length))}` : null;
@@ -17748,14 +18154,14 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
17748
18154
 
17749
18155
  // src/gallery/snapshot.ts
17750
18156
  var import_node_crypto7 = require("crypto");
17751
- var import_node_fs30 = require("fs");
17752
- var import_promises27 = require("fs/promises");
17753
- var import_node_path35 = __toESM(require("path"), 1);
18157
+ var import_node_fs33 = require("fs");
18158
+ var import_promises28 = require("fs/promises");
18159
+ var import_node_path36 = __toESM(require("path"), 1);
17754
18160
 
17755
18161
  // src/workspace.ts
17756
- var import_promises20 = require("fs/promises");
17757
- var import_node_fs25 = require("fs");
17758
- var import_node_path28 = __toESM(require("path"), 1);
18162
+ var import_promises21 = require("fs/promises");
18163
+ var import_node_fs28 = require("fs");
18164
+ var import_node_path29 = __toESM(require("path"), 1);
17759
18165
  var import_zod7 = require("zod");
17760
18166
  var WorkspaceProjectSchema = import_zod7.z.object({
17761
18167
  id: import_zod7.z.string().min(1),
@@ -17780,10 +18186,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
17780
18186
  );
17781
18187
  }
17782
18188
  async function loadWorkspace(workspacePath) {
17783
- if (!(0, import_node_fs25.existsSync)(workspacePath)) return { version: 1, projects: [] };
18189
+ if (!(0, import_node_fs28.existsSync)(workspacePath)) return { version: 1, projects: [] };
17784
18190
  let raw;
17785
18191
  try {
17786
- raw = JSON.parse(await (0, import_promises20.readFile)(workspacePath, "utf8"));
18192
+ raw = JSON.parse(await (0, import_promises21.readFile)(workspacePath, "utf8"));
17787
18193
  } catch (err) {
17788
18194
  throw new ProjectError(
17789
18195
  `Workspace catalog at ${workspacePath} is malformed:
@@ -17797,22 +18203,22 @@ async function saveWorkspace(workspacePath, ws) {
17797
18203
  version: 1,
17798
18204
  projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
17799
18205
  };
17800
- await (0, import_promises20.mkdir)(import_node_path28.default.dirname(import_node_path28.default.resolve(workspacePath)), { recursive: true });
18206
+ await (0, import_promises21.mkdir)(import_node_path29.default.dirname(import_node_path29.default.resolve(workspacePath)), { recursive: true });
17801
18207
  const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
17802
18208
  try {
17803
- await (0, import_promises20.writeFile)(tmp, JSON.stringify(sorted, null, 2) + "\n");
17804
- await (0, import_promises20.rename)(tmp, workspacePath);
18209
+ await (0, import_promises21.writeFile)(tmp, JSON.stringify(sorted, null, 2) + "\n");
18210
+ await (0, import_promises21.rename)(tmp, workspacePath);
17805
18211
  } finally {
17806
- await (0, import_promises20.rm)(tmp, { force: true });
18212
+ await (0, import_promises21.rm)(tmp, { force: true });
17807
18213
  }
17808
18214
  }
17809
18215
  function toPortablePath(dir, absolute) {
17810
- return import_node_path28.default.relative(dir, absolute).split(import_node_path28.default.sep).join("/");
18216
+ return import_node_path29.default.relative(dir, absolute).split(import_node_path29.default.sep).join("/");
17811
18217
  }
17812
18218
  function resolveProject(dir, project) {
17813
18219
  return {
17814
- manifestPath: import_node_path28.default.resolve(dir, project.manifest.split("/").join(import_node_path28.default.sep)),
17815
- lockPath: import_node_path28.default.resolve(dir, project.lock.split("/").join(import_node_path28.default.sep))
18220
+ manifestPath: import_node_path29.default.resolve(dir, project.manifest.split("/").join(import_node_path29.default.sep)),
18221
+ lockPath: import_node_path29.default.resolve(dir, project.lock.split("/").join(import_node_path29.default.sep))
17816
18222
  };
17817
18223
  }
17818
18224
  function validateWorkspace(ws, dir) {
@@ -17825,21 +18231,21 @@ function validateWorkspace(ws, dir) {
17825
18231
  const { manifestPath, lockPath } = resolveProject(dir, project);
17826
18232
  lockOwners.set(lockPath, [...lockOwners.get(lockPath) ?? [], project.id]);
17827
18233
  manifestOwners.set(manifestPath, [...manifestOwners.get(manifestPath) ?? [], project.id]);
17828
- if (import_node_path28.default.isAbsolute(project.manifest) || import_node_path28.default.isAbsolute(project.lock)) {
18234
+ if (import_node_path29.default.isAbsolute(project.manifest) || import_node_path29.default.isAbsolute(project.lock)) {
17829
18235
  diagnostics.push({
17830
18236
  id: "absolute-path",
17831
18237
  level: "warning",
17832
18238
  message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
17833
18239
  });
17834
18240
  }
17835
- if (!(0, import_node_fs25.existsSync)(manifestPath)) {
18241
+ if (!(0, import_node_fs28.existsSync)(manifestPath)) {
17836
18242
  diagnostics.push({
17837
18243
  id: "missing-manifest",
17838
18244
  level: "error",
17839
18245
  message: `project "${project.id}" manifest not found: ${manifestPath}`
17840
18246
  });
17841
18247
  }
17842
- if (!(0, import_node_fs25.existsSync)(lockPath)) {
18248
+ if (!(0, import_node_fs28.existsSync)(lockPath)) {
17843
18249
  diagnostics.push({
17844
18250
  id: "missing-lock",
17845
18251
  level: "error",
@@ -17886,16 +18292,16 @@ function validateWorkspace(ws, dir) {
17886
18292
  }
17887
18293
 
17888
18294
  // src/gallery/edit.ts
17889
- var import_promises26 = require("fs/promises");
17890
- var import_node_path34 = __toESM(require("path"), 1);
18295
+ var import_promises27 = require("fs/promises");
18296
+ var import_node_path35 = __toESM(require("path"), 1);
17891
18297
  var import_zod13 = require("zod");
17892
18298
 
17893
18299
  // src/manifest-edit.ts
17894
- var import_promises21 = require("fs/promises");
17895
- var import_node_path29 = __toESM(require("path"), 1);
18300
+ var import_promises22 = require("fs/promises");
18301
+ var import_node_path30 = __toESM(require("path"), 1);
17896
18302
  var import_zod8 = require("zod");
17897
18303
  var HexSha = import_zod8.z.string().regex(/^[0-9a-f]{64}$/);
17898
- var ProjectFileSchema = import_zod8.z.string().min(1).refine((file) => !import_node_path29.default.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
18304
+ var ProjectFileSchema = import_zod8.z.string().min(1).refine((file) => !import_node_path30.default.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
17899
18305
  var AssetPatchSchema = import_zod8.z.object({
17900
18306
  prompt: import_zod8.z.string().optional(),
17901
18307
  /** Per-style override for the style being viewed; null removes it. */
@@ -18315,8 +18721,8 @@ function applyEdit(raw, edit) {
18315
18721
  }
18316
18722
  }
18317
18723
  async function withCandidate(manifestPath, edit, use, unchanged) {
18318
- const absolute = import_node_path29.default.resolve(manifestPath);
18319
- const original = await (0, import_promises21.readFile)(absolute, "utf8");
18724
+ const absolute = import_node_path30.default.resolve(manifestPath);
18725
+ const original = await (0, import_promises22.readFile)(absolute, "utf8");
18320
18726
  if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
18321
18727
  let raw;
18322
18728
  try {
@@ -18329,12 +18735,12 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
18329
18735
  applyEdit(raw, edit);
18330
18736
  const next = serializeLike(original, raw);
18331
18737
  if (next === original) return unchanged(absolute, original);
18332
- const tmp = import_node_path29.default.join(
18333
- import_node_path29.default.dirname(absolute),
18334
- `.${import_node_path29.default.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
18738
+ const tmp = import_node_path30.default.join(
18739
+ import_node_path30.default.dirname(absolute),
18740
+ `.${import_node_path30.default.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
18335
18741
  );
18336
18742
  try {
18337
- await (0, import_promises21.writeFile)(tmp, next);
18743
+ await (0, import_promises22.writeFile)(tmp, next);
18338
18744
  let specs;
18339
18745
  try {
18340
18746
  specs = await resolveSpecs(await loadManifest(tmp));
@@ -18344,7 +18750,7 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
18344
18750
  }
18345
18751
  return await use({ absolute, original, next, tmp, specs });
18346
18752
  } finally {
18347
- await (0, import_promises21.rm)(tmp, { force: true });
18753
+ await (0, import_promises22.rm)(tmp, { force: true });
18348
18754
  }
18349
18755
  }
18350
18756
  async function applyManifestEdit(manifestPath, edit) {
@@ -18352,7 +18758,7 @@ async function applyManifestEdit(manifestPath, edit) {
18352
18758
  manifestPath,
18353
18759
  edit,
18354
18760
  async ({ absolute, next, tmp }) => {
18355
- await (0, import_promises21.rename)(tmp, absolute);
18761
+ await (0, import_promises22.rename)(tmp, absolute);
18356
18762
  return { manifestPath: absolute, sha256: sha256(next), changed: true };
18357
18763
  },
18358
18764
  (absolute, original) => ({ manifestPath: absolute, sha256: sha256(original), changed: false })
@@ -18360,18 +18766,18 @@ async function applyManifestEdit(manifestPath, edit) {
18360
18766
  }
18361
18767
 
18362
18768
  // src/pipeline/hand-edit.ts
18363
- var import_node_fs26 = require("fs");
18364
- var import_promises22 = require("fs/promises");
18365
- var import_node_path30 = __toESM(require("path"), 1);
18769
+ var import_node_fs29 = require("fs");
18770
+ var import_promises23 = require("fs/promises");
18771
+ var import_node_path31 = __toESM(require("path"), 1);
18366
18772
  var import_zod9 = require("zod");
18367
18773
  var HAND_EDIT_DIR = "edits";
18368
18774
  function handEditPath(loaded, spec) {
18369
18775
  const style = loaded.manifest.styles[spec.styleId];
18370
- const outDir = import_node_path30.default.resolve(loaded.root, style?.outDir ?? ".");
18371
- const relative = import_node_path30.default.relative(outDir, spec.outFile);
18372
- const inside = relative && !relative.startsWith("..") && !import_node_path30.default.isAbsolute(relative);
18373
- const file = inside ? relative : import_node_path30.default.basename(spec.outFile);
18374
- return import_node_path30.default.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
18776
+ const outDir = import_node_path31.default.resolve(loaded.root, style?.outDir ?? ".");
18777
+ const relative = import_node_path31.default.relative(outDir, spec.outFile);
18778
+ const inside = relative && !relative.startsWith("..") && !import_node_path31.default.isAbsolute(relative);
18779
+ const file = inside ? relative : import_node_path31.default.basename(spec.outFile);
18780
+ return import_node_path31.default.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
18375
18781
  }
18376
18782
  function handEditBases(spec, lock) {
18377
18783
  const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
@@ -18384,10 +18790,10 @@ function handEditBases(spec, lock) {
18384
18790
  }));
18385
18791
  if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
18386
18792
  if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
18387
- if (!members.every((member) => (0, import_node_fs26.existsSync)(member.path))) return null;
18793
+ if (!members.every((member) => (0, import_node_fs29.existsSync)(member.path))) return null;
18388
18794
  return members.map(({ role, path: file }) => ({ role, path: file }));
18389
18795
  }
18390
- return (0, import_node_fs26.existsSync)(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
18796
+ return (0, import_node_fs29.existsSync)(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
18391
18797
  }
18392
18798
  function handEditBase(spec, lock) {
18393
18799
  const bases = handEditBases(spec, lock);
@@ -18417,19 +18823,19 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
18417
18823
  `${spec.styleId}/${spec.assetId} declares ${spec.source}, one committed file placed for the whole set; clear that source (pixelkiln edit detach) to hand-edit the members one by one`
18418
18824
  );
18419
18825
  }
18420
- const existing = spec.source ? import_node_path30.default.resolve(loaded.root, spec.source) : null;
18826
+ const existing = spec.source ? import_node_path31.default.resolve(loaded.root, spec.source) : null;
18421
18827
  const editPath = existing ?? handEditPath(loaded, spec);
18422
18828
  const members = handEditMembers(loaded, spec, lock, editPath);
18423
18829
  let created = false;
18424
18830
  for (const member of members) {
18425
- if ((0, import_node_fs26.existsSync)(member.path)) continue;
18831
+ if ((0, import_node_fs29.existsSync)(member.path)) continue;
18426
18832
  if (!member.base) {
18427
18833
  throw new ManifestEditError(
18428
18834
  `${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
18429
18835
  );
18430
18836
  }
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);
18837
+ await (0, import_promises23.mkdir)(import_node_path31.default.dirname(member.path), { recursive: true });
18838
+ await (0, import_promises23.copyFile)(member.base, member.path);
18433
18839
  created = true;
18434
18840
  }
18435
18841
  const source = portableOutputPath(editPath, loaded.root);
@@ -18507,7 +18913,7 @@ function handEditProjectPath(editPath) {
18507
18913
  async function readHandEditCompanion(editPath) {
18508
18914
  let text;
18509
18915
  try {
18510
- text = await (0, import_promises22.readFile)(handEditCompanionPath(editPath), "utf8");
18916
+ text = await (0, import_promises23.readFile)(handEditCompanionPath(editPath), "utf8");
18511
18917
  } catch {
18512
18918
  return null;
18513
18919
  }
@@ -18550,7 +18956,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
18550
18956
  }
18551
18957
  });
18552
18958
  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 };
18959
+ const expectedSize = bases?.[0] ? decodePng(await (0, import_promises23.readFile)(bases[0].path)) : { width: spec.width, height: spec.height };
18554
18960
  for (const [index, image] of decoded.entries()) {
18555
18961
  if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
18556
18962
  const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
@@ -18566,7 +18972,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
18566
18972
  editor: input.editor,
18567
18973
  protocol: input.protocol,
18568
18974
  savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
18569
- project: projectPath ? import_node_path30.default.basename(projectPath) : null,
18975
+ project: projectPath ? import_node_path31.default.basename(projectPath) : null,
18570
18976
  outputs: incoming.map((frame, index) => ({
18571
18977
  role: frame.role,
18572
18978
  basedOn: basedOnHash(entry, index),
@@ -18596,10 +19002,10 @@ function basedOnHash(entry, index) {
18596
19002
  async function replaceFile(file, bytes) {
18597
19003
  const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
18598
19004
  try {
18599
- await (0, import_promises22.writeFile)(tmp, bytes);
18600
- await (0, import_promises22.rename)(tmp, file);
19005
+ await (0, import_promises23.writeFile)(tmp, bytes);
19006
+ await (0, import_promises23.rename)(tmp, file);
18601
19007
  } finally {
18602
- await (0, import_promises22.rm)(tmp, { force: true });
19008
+ await (0, import_promises23.rm)(tmp, { force: true });
18603
19009
  }
18604
19010
  }
18605
19011
  function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
@@ -18608,9 +19014,9 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
18608
19014
  }
18609
19015
 
18610
19016
  // src/gallery/upload.ts
18611
- var import_node_fs27 = require("fs");
18612
- var import_promises23 = require("fs/promises");
18613
- var import_node_path31 = __toESM(require("path"), 1);
19017
+ var import_node_fs30 = require("fs");
19018
+ var import_promises24 = require("fs/promises");
19019
+ var import_node_path32 = __toESM(require("path"), 1);
18614
19020
  var import_zod10 = require("zod");
18615
19021
  var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
18616
19022
  var UploadImageSchema = import_zod10.z.object({
@@ -18623,12 +19029,12 @@ var UploadImageSchema = import_zod10.z.object({
18623
19029
  overwrite: import_zod10.z.boolean().optional()
18624
19030
  }).strict();
18625
19031
  async function saveProjectImage(root, request) {
18626
- const file = import_node_path31.default.resolve(root, request.path);
18627
- const relative = import_node_path31.default.relative(root, file);
18628
- if (relative.startsWith("..") || import_node_path31.default.isAbsolute(relative)) {
19032
+ const file = import_node_path32.default.resolve(root, request.path);
19033
+ const relative = import_node_path32.default.relative(root, file);
19034
+ if (relative.startsWith("..") || import_node_path32.default.isAbsolute(relative)) {
18629
19035
  throw new ManifestEditError("an upload must stay inside the project");
18630
19036
  }
18631
- const extension = import_node_path31.default.extname(file).toLowerCase();
19037
+ const extension = import_node_path32.default.extname(file).toLowerCase();
18632
19038
  const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
18633
19039
  if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
18634
19040
  const bytes = Buffer.from(request.base64, "base64");
@@ -18640,18 +19046,18 @@ async function saveProjectImage(root, request) {
18640
19046
  if (metadata.format !== expected) {
18641
19047
  throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
18642
19048
  }
18643
- if ((0, import_node_fs27.existsSync)(file) && !request.overwrite) {
18644
- throw new ManifestEditError(`${relative.split(import_node_path31.default.sep).join("/")} already exists; choose another name, or replace it`);
19049
+ if ((0, import_node_fs30.existsSync)(file) && !request.overwrite) {
19050
+ throw new ManifestEditError(`${relative.split(import_node_path32.default.sep).join("/")} already exists; choose another name, or replace it`);
18645
19051
  }
18646
- await (0, import_promises23.mkdir)(import_node_path31.default.dirname(file), { recursive: true });
18647
- await (0, import_promises23.writeFile)(file, bytes);
18648
- return relative.split(import_node_path31.default.sep).join("/");
19052
+ await (0, import_promises24.mkdir)(import_node_path32.default.dirname(file), { recursive: true });
19053
+ await (0, import_promises24.writeFile)(file, bytes);
19054
+ return relative.split(import_node_path32.default.sep).join("/");
18649
19055
  }
18650
19056
 
18651
19057
  // src/gallery/image-revision.ts
18652
- var import_node_fs28 = require("fs");
18653
- var import_promises24 = require("fs/promises");
18654
- var import_node_path32 = __toESM(require("path"), 1);
19058
+ var import_node_fs31 = require("fs");
19059
+ var import_promises25 = require("fs/promises");
19060
+ var import_node_path33 = __toESM(require("path"), 1);
18655
19061
  var import_zod11 = require("zod");
18656
19062
  var InpaintRevisionRequestSchema = import_zod11.z.object({
18657
19063
  action: import_zod11.z.literal("create-inpaint-revision"),
@@ -18670,15 +19076,15 @@ var InpaintRevisionRequestSchema = import_zod11.z.object({
18670
19076
  overwrite: import_zod11.z.boolean().optional()
18671
19077
  }).strict();
18672
19078
  async function createInpaintRevision(manifestPath, request) {
18673
- const root = import_node_path32.default.dirname(import_node_path32.default.resolve(manifestPath));
18674
- if (import_node_path32.default.extname(request.maskPath).toLowerCase() !== ".png") {
19079
+ const root = import_node_path33.default.dirname(import_node_path33.default.resolve(manifestPath));
19080
+ if (import_node_path33.default.extname(request.maskPath).toLowerCase() !== ".png") {
18675
19081
  throw new ManifestEditError("the mask must be a .png path inside the project");
18676
19082
  }
18677
19083
  const bytes = Buffer.from(request.maskBase64, "base64");
18678
19084
  const metadata = imageMetadata(bytes);
18679
19085
  if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
18680
- 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;
19086
+ const file = import_node_path33.default.resolve(root, request.maskPath);
19087
+ const previous = (0, import_node_fs31.existsSync)(file) ? await (0, import_promises25.readFile)(file) : null;
18682
19088
  const mask = await saveProjectImage(root, {
18683
19089
  action: "upload-image",
18684
19090
  path: request.maskPath,
@@ -18697,17 +19103,17 @@ async function createInpaintRevision(manifestPath, request) {
18697
19103
  }
18698
19104
  });
18699
19105
  } catch (error) {
18700
- if (previous) await (0, import_promises24.writeFile)(file, previous);
18701
- else await (0, import_promises24.rm)(file, { force: true });
19106
+ if (previous) await (0, import_promises25.writeFile)(file, previous);
19107
+ else await (0, import_promises25.rm)(file, { force: true });
18702
19108
  throw error;
18703
19109
  }
18704
19110
  return mask;
18705
19111
  }
18706
19112
 
18707
19113
  // src/gallery/skeleton.ts
18708
- var import_node_fs29 = require("fs");
18709
- var import_promises25 = require("fs/promises");
18710
- var import_node_path33 = __toESM(require("path"), 1);
19114
+ var import_node_fs32 = require("fs");
19115
+ var import_promises26 = require("fs/promises");
19116
+ var import_node_path34 = __toESM(require("path"), 1);
18711
19117
  var import_zod12 = require("zod");
18712
19118
  var SkeletonEstimateRequestSchema = import_zod12.z.object({
18713
19119
  project: import_zod12.z.string().min(1).optional(),
@@ -18746,21 +19152,21 @@ var SkeletonKeypointsUpdateSchema = import_zod12.z.object({
18746
19152
  set: SkeletonSetSchema
18747
19153
  }).strict();
18748
19154
  async function createSkeletonAnimation(manifestPath, request) {
18749
- const root = import_node_path33.default.dirname(import_node_path33.default.resolve(manifestPath));
18750
- const file = import_node_path33.default.resolve(root, request.keypointsFile);
18751
- const relative = import_node_path33.default.relative(root, file);
18752
- if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || import_node_path33.default.isAbsolute(relative)) {
19155
+ const root = import_node_path34.default.dirname(import_node_path34.default.resolve(manifestPath));
19156
+ const file = import_node_path34.default.resolve(root, request.keypointsFile);
19157
+ const relative = import_node_path34.default.relative(root, file);
19158
+ if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || import_node_path34.default.isAbsolute(relative)) {
18753
19159
  throw new ManifestEditError("the keypoints file must be a .json path inside the project");
18754
19160
  }
18755
- const existed = (0, import_node_fs29.existsSync)(file);
19161
+ const existed = (0, import_node_fs32.existsSync)(file);
18756
19162
  let previous = null;
18757
19163
  if (request.set) {
18758
19164
  if (existed && !request.overwrite) {
18759
19165
  throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
18760
19166
  }
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");
19167
+ if (existed) previous = await (0, import_promises26.readFile)(file);
19168
+ await (0, import_promises26.mkdir)(import_node_path34.default.dirname(file), { recursive: true });
19169
+ await (0, import_promises26.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
18764
19170
  } else if (!existed) {
18765
19171
  throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
18766
19172
  }
@@ -18775,7 +19181,7 @@ async function createSkeletonAnimation(manifestPath, request) {
18775
19181
  revision: {
18776
19182
  mode: "animate-skeleton",
18777
19183
  from: request.from,
18778
- keypointsFile: relative.split(import_node_path33.default.sep).join("/"),
19184
+ keypointsFile: relative.split(import_node_path34.default.sep).join("/"),
18779
19185
  direction: request.direction,
18780
19186
  description: request.description,
18781
19187
  ...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
@@ -18784,8 +19190,8 @@ async function createSkeletonAnimation(manifestPath, request) {
18784
19190
  });
18785
19191
  } catch (error) {
18786
19192
  if (request.set) {
18787
- if (previous) await (0, import_promises25.writeFile)(file, previous);
18788
- else await (0, import_promises25.rm)(file, { force: true });
19193
+ if (previous) await (0, import_promises26.writeFile)(file, previous);
19194
+ else await (0, import_promises26.rm)(file, { force: true });
18789
19195
  }
18790
19196
  throw error;
18791
19197
  }
@@ -18796,19 +19202,19 @@ async function updateSkeletonKeypoints(ctx, request) {
18796
19202
  if (!spec) throw new ManifestEditError(`"${key}" is not declared by the manifest`);
18797
19203
  const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
18798
19204
  if (!file) throw new ManifestEditError(`${key} is not an animate-skeleton revision`);
18799
- const relative = import_node_path33.default.relative(ctx.loaded.root, file);
18800
- if (relative.startsWith("..") || import_node_path33.default.isAbsolute(relative)) {
19205
+ const relative = import_node_path34.default.relative(ctx.loaded.root, file);
19206
+ if (relative.startsWith("..") || import_node_path34.default.isAbsolute(relative)) {
18801
19207
  throw new ManifestEditError(`${key}'s keypoints file is outside the project; edit it by hand`);
18802
19208
  }
18803
- const current = (0, import_node_fs29.existsSync)(file) ? sha256(await (0, import_promises25.readFile)(file)) : null;
19209
+ const current = (0, import_node_fs32.existsSync)(file) ? sha256(await (0, import_promises26.readFile)(file)) : null;
18804
19210
  if (current !== request.expectedSha256) {
18805
19211
  throw Object.assign(
18806
- new Error(`${relative.split(import_node_path33.default.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
19212
+ new Error(`${relative.split(import_node_path34.default.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
18807
19213
  { status: 409 }
18808
19214
  );
18809
19215
  }
18810
- await (0, import_promises25.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
18811
- return relative.split(import_node_path33.default.sep).join("/");
19216
+ await (0, import_promises26.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
19217
+ return relative.split(import_node_path34.default.sep).join("/");
18812
19218
  }
18813
19219
 
18814
19220
  // src/gallery/edit.ts
@@ -18862,7 +19268,7 @@ function createGalleryEditHandler(opts) {
18862
19268
  const history = /* @__PURE__ */ new Map();
18863
19269
  const manifestOf = async (project) => {
18864
19270
  try {
18865
- return import_node_path34.default.resolve(await opts.manifestFor(typeof project === "string" ? project : void 0));
19271
+ return import_node_path35.default.resolve(await opts.manifestFor(typeof project === "string" ? project : void 0));
18866
19272
  } catch {
18867
19273
  return null;
18868
19274
  }
@@ -18872,7 +19278,7 @@ function createGalleryEditHandler(opts) {
18872
19278
  if (undo.success) {
18873
19279
  const manifestPath2 = await manifestOf(undo.data.project);
18874
19280
  if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
18875
- const current = await (0, import_promises26.readFile)(manifestPath2, "utf8");
19281
+ const current = await (0, import_promises27.readFile)(manifestPath2, "utf8");
18876
19282
  if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
18877
19283
  const stack = history.get(manifestPath2) ?? [];
18878
19284
  const last = stack[stack.length - 1];
@@ -18882,17 +19288,17 @@ function createGalleryEditHandler(opts) {
18882
19288
  throw Object.assign(new Error("the manifest changed outside the gallery since its last edit; undo would discard that change"), { status: 409 });
18883
19289
  }
18884
19290
  const tmp = manifestPath2 + ".pixelkiln-undo";
18885
- await (0, import_promises26.writeFile)(tmp, last.before);
18886
- await (0, import_promises26.rename)(tmp, manifestPath2);
19291
+ await (0, import_promises27.writeFile)(tmp, last.before);
19292
+ await (0, import_promises27.rename)(tmp, manifestPath2);
18887
19293
  stack.pop();
18888
- log(` manifest edit undone in ${import_node_path34.default.relative(process.cwd(), manifestPath2) || manifestPath2}`);
19294
+ log(` manifest edit undone in ${import_node_path35.default.relative(process.cwd(), manifestPath2) || manifestPath2}`);
18889
19295
  return opts.reload();
18890
19296
  }
18891
19297
  const manifestPath = await manifestOf(body?.project);
18892
- const before = manifestPath ? await (0, import_promises26.readFile)(manifestPath, "utf8").catch(() => null) : null;
19298
+ const before = manifestPath ? await (0, import_promises27.readFile)(manifestPath, "utf8").catch(() => null) : null;
18893
19299
  const build = await apply(body);
18894
19300
  if (manifestPath && before !== null) {
18895
- const after = await (0, import_promises26.readFile)(manifestPath, "utf8").catch(() => null);
19301
+ const after = await (0, import_promises27.readFile)(manifestPath, "utf8").catch(() => null);
18896
19302
  if (after !== null && after !== before) {
18897
19303
  const stack = history.get(manifestPath) ?? [];
18898
19304
  stack.push({ before, afterSha: sha256(after) });
@@ -18947,7 +19353,7 @@ function createEditApplier(opts, log) {
18947
19353
  } catch (error) {
18948
19354
  throw new ManifestEditError(error instanceof Error ? error.message : String(error));
18949
19355
  }
18950
- const written = await saveProjectImage(import_node_path34.default.dirname(import_node_path34.default.resolve(manifestPath2)), upload.data);
19356
+ const written = await saveProjectImage(import_node_path35.default.dirname(import_node_path35.default.resolve(manifestPath2)), upload.data);
18951
19357
  log(` image added: ${written}`);
18952
19358
  return opts.reload();
18953
19359
  }
@@ -19014,7 +19420,7 @@ function createEditApplier(opts, log) {
19014
19420
  }
19015
19421
  const result = await applyManifestEdit(manifestPath, parsed.data);
19016
19422
  if (result.changed) {
19017
- const relative = import_node_path34.default.relative(process.cwd(), result.manifestPath);
19423
+ const relative = import_node_path35.default.relative(process.cwd(), result.manifestPath);
19018
19424
  const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
19019
19425
  log(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
19020
19426
  }
@@ -19042,7 +19448,7 @@ function describeEdit(edit) {
19042
19448
  // src/gallery/snapshot.ts
19043
19449
  var PROJECT_FILE_TYPE = "application/octet-stream";
19044
19450
  function galleryMediaId(absolutePath) {
19045
- return (0, import_node_crypto7.createHash)("sha256").update(import_node_path35.default.resolve(absolutePath)).digest("hex").slice(0, 24);
19451
+ return (0, import_node_crypto7.createHash)("sha256").update(import_node_path36.default.resolve(absolutePath)).digest("hex").slice(0, 24);
19046
19452
  }
19047
19453
  function galleryMediaRoute(id) {
19048
19454
  return `/media/${id}`;
@@ -19066,9 +19472,9 @@ function describeHistory(media, entry, cacheDir) {
19066
19472
  return (entry.history ?? []).map((generation, i) => {
19067
19473
  const outputs = generation.outputs.map((output) => {
19068
19474
  const mediaType = output.mediaType ?? MediaType.PNG;
19069
- const file = import_node_path35.default.join(cacheDir, cacheFileName(output.sha256, mediaType));
19475
+ const file = import_node_path36.default.join(cacheDir, cacheFileName(output.sha256, mediaType));
19070
19476
  let url = null;
19071
- if ((0, import_node_fs30.existsSync)(file)) {
19477
+ if ((0, import_node_fs33.existsSync)(file)) {
19072
19478
  const id = galleryMediaId(file);
19073
19479
  media.set(id, { path: file, contentType: mediaType });
19074
19480
  url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
@@ -19100,7 +19506,7 @@ function describeHistory(media, entry, cacheDir) {
19100
19506
  var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
19101
19507
  async function samePixels(a, b) {
19102
19508
  try {
19103
- const [left, right] = await Promise.all([(0, import_promises27.readFile)(a), (0, import_promises27.readFile)(b)]);
19509
+ const [left, right] = await Promise.all([(0, import_promises28.readFile)(a), (0, import_promises28.readFile)(b)]);
19104
19510
  if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
19105
19511
  const x = decodePng(left);
19106
19512
  const y = decodePng(right);
@@ -19166,7 +19572,7 @@ function describeCharacter(spec, entry) {
19166
19572
  }
19167
19573
  async function fileInfo(absolutePath) {
19168
19574
  try {
19169
- const info = await (0, import_promises27.stat)(absolutePath);
19575
+ const info = await (0, import_promises28.stat)(absolutePath);
19170
19576
  return info.isFile() ? { bytes: info.size, modifiedAt: info.mtime.toISOString() } : null;
19171
19577
  } catch {
19172
19578
  return null;
@@ -19198,10 +19604,10 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
19198
19604
  async function describeQuality(media, root, inspection) {
19199
19605
  const outputPaths = inspection.outputs ?? [inspection.output];
19200
19606
  const outputs = await Promise.all(
19201
- outputPaths.map((file) => describeOutput(media, root, import_node_path35.default.resolve(root, file)))
19607
+ outputPaths.map((file) => describeOutput(media, root, import_node_path36.default.resolve(root, file)))
19202
19608
  );
19203
- const recordPath = import_node_path35.default.resolve(root, inspection.record);
19204
- const recordExists = (0, import_node_fs30.existsSync)(recordPath);
19609
+ const recordPath = import_node_path36.default.resolve(root, inspection.record);
19610
+ const recordExists = (0, import_node_fs33.existsSync)(recordPath);
19205
19611
  let options = null;
19206
19612
  let check = null;
19207
19613
  if (recordExists) {
@@ -19220,7 +19626,7 @@ async function describeQuality(media, root, inspection) {
19220
19626
  return {
19221
19627
  state: inspection.state,
19222
19628
  reason: inspection.reason,
19223
- output: portableOutputPath(import_node_path35.default.resolve(root, inspection.output), root),
19629
+ output: portableOutputPath(import_node_path36.default.resolve(root, inspection.output), root),
19224
19630
  record: portableOutputPath(recordPath, root),
19225
19631
  recordExists,
19226
19632
  outputs,
@@ -19258,9 +19664,9 @@ async function buildGallerySnapshot(opts) {
19258
19664
  const media = /* @__PURE__ */ new Map();
19259
19665
  const plan = await buildPlan(specs, lock);
19260
19666
  const items = [];
19261
- const manifestText = await (0, import_promises27.readFile)(loaded.path, "utf8");
19667
+ const manifestText = await (0, import_promises28.readFile)(loaded.path, "utf8");
19262
19668
  const manifestSha256 = sha256(manifestText);
19263
- const cacheDir = import_node_path35.default.resolve(import_node_path35.default.dirname(opts.lockPath), ".pixelkiln", "cache");
19669
+ const cacheDir = import_node_path36.default.resolve(import_node_path36.default.dirname(opts.lockPath), ".pixelkiln", "cache");
19264
19670
  let rawStyles = {};
19265
19671
  try {
19266
19672
  const raw = JSON.parse(manifestText);
@@ -19284,12 +19690,12 @@ async function buildGallerySnapshot(opts) {
19284
19690
  )
19285
19691
  );
19286
19692
  if (spec.source) {
19287
- const editPath = import_node_path35.default.resolve(root, spec.source);
19693
+ const editPath = import_node_path36.default.resolve(root, spec.source);
19288
19694
  const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
19289
19695
  const editShas = await Promise.all(
19290
19696
  Array.from({ length: memberCount }, async (_, index) => {
19291
19697
  const file = sourceOutputPath(spec.source, entry, index, root);
19292
- return { file, sha256: (0, import_node_fs30.existsSync)(file) ? await sha256File(file) : null };
19698
+ return { file, sha256: (0, import_node_fs33.existsSync)(file) ? await sha256File(file) : null };
19293
19699
  })
19294
19700
  );
19295
19701
  edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
@@ -19297,7 +19703,7 @@ async function buildGallerySnapshot(opts) {
19297
19703
  const companion = await readHandEditCompanion(editPath);
19298
19704
  if (companion) {
19299
19705
  const projectPath = handEditProjectPath(editPath);
19300
- const project = companion.project && (0, import_node_fs30.existsSync)(projectPath) ? await fileInfo(projectPath) : null;
19706
+ const project = companion.project && (0, import_node_fs33.existsSync)(projectPath) ? await fileInfo(projectPath) : null;
19301
19707
  let projectUrl = null;
19302
19708
  if (project) {
19303
19709
  const id = galleryMediaId(projectPath);
@@ -19333,8 +19739,8 @@ async function buildGallerySnapshot(opts) {
19333
19739
  editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
19334
19740
  }
19335
19741
  } else if (spec.source) {
19336
- outputs = [await describeOutput(media, root, import_node_path35.default.resolve(root, spec.source))];
19337
- } else if (!entry && (0, import_node_fs30.existsSync)(spec.outFile)) {
19742
+ outputs = [await describeOutput(media, root, import_node_path36.default.resolve(root, spec.source))];
19743
+ } else if (!entry && (0, import_node_fs33.existsSync)(spec.outFile)) {
19338
19744
  outputs = [await describeOutput(media, root, spec.outFile)];
19339
19745
  } else {
19340
19746
  outputs = [];
@@ -19538,7 +19944,7 @@ async function buildGallerySnapshot(opts) {
19538
19944
  id: loaded.manifest.name,
19539
19945
  name: loaded.manifest.name,
19540
19946
  manifest: loaded.path,
19541
- lock: import_node_path35.default.resolve(opts.lockPath),
19947
+ lock: import_node_path36.default.resolve(opts.lockPath),
19542
19948
  root,
19543
19949
  provider: loaded.manifest.provider,
19544
19950
  account: null,
@@ -19564,7 +19970,7 @@ async function buildGallerySnapshot(opts) {
19564
19970
  return { snapshot, media };
19565
19971
  }
19566
19972
  async function buildWorkspaceGallerySnapshot(opts) {
19567
- const dir = import_node_path35.default.dirname(import_node_path35.default.resolve(opts.workspacePath));
19973
+ const dir = import_node_path36.default.dirname(import_node_path36.default.resolve(opts.workspacePath));
19568
19974
  const media = /* @__PURE__ */ new Map();
19569
19975
  const projects = [];
19570
19976
  const items = [];
@@ -19607,11 +20013,11 @@ async function buildWorkspaceGallerySnapshot(opts) {
19607
20013
  id: project.id,
19608
20014
  name: loaded.manifest.name,
19609
20015
  manifest: manifestPath,
19610
- lock: import_node_path35.default.resolve(lockPath),
20016
+ lock: import_node_path36.default.resolve(lockPath),
19611
20017
  root: loaded.root,
19612
20018
  provider: loaded.manifest.provider,
19613
20019
  account: project.account ?? null,
19614
- manifestSha256: manifestSha256 ?? sha256(await (0, import_promises27.readFile)(manifestPath, "utf8")),
20020
+ manifestSha256: manifestSha256 ?? sha256(await (0, import_promises28.readFile)(manifestPath, "utf8")),
19615
20021
  historyLimit: historyLimit(loaded.manifest),
19616
20022
  entries: Object.keys(lock.entries).length,
19617
20023
  items: projectItems.length,
@@ -19623,8 +20029,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
19623
20029
  id: project.id,
19624
20030
  name: project.id,
19625
20031
  manifest: manifestPath,
19626
- lock: import_node_path35.default.resolve(lockPath),
19627
- root: import_node_path35.default.dirname(manifestPath),
20032
+ lock: import_node_path36.default.resolve(lockPath),
20033
+ root: import_node_path36.default.dirname(manifestPath),
19628
20034
  provider: project.provider,
19629
20035
  account: project.account ?? null,
19630
20036
  manifestSha256: null,
@@ -19651,7 +20057,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
19651
20057
  version: 1,
19652
20058
  generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
19653
20059
  project: null,
19654
- workspace: { path: import_node_path35.default.resolve(opts.workspacePath), dir, projects },
20060
+ workspace: { path: import_node_path36.default.resolve(opts.workspacePath), dir, projects },
19655
20061
  filter,
19656
20062
  totals: {
19657
20063
  entries: projects.reduce((sum, project) => sum + project.entries, 0),
@@ -19668,7 +20074,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
19668
20074
  }
19669
20075
 
19670
20076
  // src/gallery/page.ts
19671
- var import_node_fs31 = require("fs");
20077
+ var import_node_fs34 = require("fs");
19672
20078
 
19673
20079
  // src/gallery/client-bundle.ts
19674
20080
  var import_node_module = require("module");
@@ -19708,8 +20114,8 @@ var client;
19708
20114
  function clientAssets() {
19709
20115
  const prebuilt = new URL("gallery.js", CLIENT_DIR);
19710
20116
  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()
20117
+ css: (0, import_node_fs34.readFileSync)(new URL("gallery.css", CLIENT_DIR), "utf8"),
20118
+ js: (0, import_node_fs34.existsSync)(prebuilt) ? (0, import_node_fs34.readFileSync)(prebuilt, "utf8") : bundleGalleryClient()
19713
20119
  };
19714
20120
  return client;
19715
20121
  }
@@ -19852,10 +20258,10 @@ var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download
19852
20258
 
19853
20259
  // src/editor/install.ts
19854
20260
  var import_node_crypto8 = require("crypto");
19855
- var import_node_fs32 = require("fs");
19856
- var import_promises28 = require("fs/promises");
20261
+ var import_node_fs35 = require("fs");
20262
+ var import_promises29 = require("fs/promises");
19857
20263
  var import_node_os4 = __toESM(require("os"), 1);
19858
- var import_node_path36 = __toESM(require("path"), 1);
20264
+ var import_node_path37 = __toESM(require("path"), 1);
19859
20265
  var EditorInstallError = class extends Error {
19860
20266
  constructor(message6, file) {
19861
20267
  super(message6);
@@ -19866,15 +20272,15 @@ var EditorInstallError = class extends Error {
19866
20272
  };
19867
20273
  function editorToolsRoot() {
19868
20274
  const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
19869
- if (override) return import_node_path36.default.resolve(override);
19870
- if (process.platform === "darwin") return import_node_path36.default.join(import_node_os4.default.homedir(), "Library", "Caches", "pixelkiln", "tools");
20275
+ if (override) return import_node_path37.default.resolve(override);
20276
+ if (process.platform === "darwin") return import_node_path37.default.join(import_node_os4.default.homedir(), "Library", "Caches", "pixelkiln", "tools");
19871
20277
  if (process.platform === "win32") {
19872
- return import_node_path36.default.join(process.env.LOCALAPPDATA ?? import_node_path36.default.join(import_node_os4.default.homedir(), "AppData", "Local"), "pixelkiln", "tools");
20278
+ return import_node_path37.default.join(process.env.LOCALAPPDATA ?? import_node_path37.default.join(import_node_os4.default.homedir(), "AppData", "Local"), "pixelkiln", "tools");
19873
20279
  }
19874
- return import_node_path36.default.join(process.env.XDG_CACHE_HOME ?? import_node_path36.default.join(import_node_os4.default.homedir(), ".cache"), "pixelkiln", "tools");
20280
+ return import_node_path37.default.join(process.env.XDG_CACHE_HOME ?? import_node_path37.default.join(import_node_os4.default.homedir(), ".cache"), "pixelkiln", "tools");
19875
20281
  }
19876
20282
  function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
19877
- return import_node_path36.default.join(root, "pixelorama", pin.release ?? "unpublished");
20283
+ return import_node_path37.default.join(root, "pixelorama", pin.release ?? "unpublished");
19878
20284
  }
19879
20285
  function editorBaseUrl(pin = EDITOR_PIN) {
19880
20286
  const override = process.env.PIXELKILN_EDITOR_URL?.trim();
@@ -19884,7 +20290,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
19884
20290
  }
19885
20291
  async function sha256Of(file) {
19886
20292
  try {
19887
- return (0, import_node_crypto8.createHash)("sha256").update(await (0, import_promises28.readFile)(file)).digest("hex");
20293
+ return (0, import_node_crypto8.createHash)("sha256").update(await (0, import_promises29.readFile)(file)).digest("hex");
19888
20294
  } catch {
19889
20295
  return null;
19890
20296
  }
@@ -19897,8 +20303,8 @@ async function editorStatus(opts = {}) {
19897
20303
  let totalBytes = 0;
19898
20304
  for (const [name, expected] of Object.entries(pin.files)) {
19899
20305
  totalBytes += expected.bytes;
19900
- 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;
20306
+ const file = import_node_path37.default.join(dir, name);
20307
+ const info = (0, import_node_fs35.existsSync)(file) ? await (0, import_promises29.stat)(file).catch(() => null) : null;
19902
20308
  if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
19903
20309
  installedBytes += expected.bytes;
19904
20310
  } else {
@@ -19927,7 +20333,7 @@ async function installEditor(opts = {}) {
19927
20333
  );
19928
20334
  }
19929
20335
  if (!baseUrl) throw new EditorInstallError("no download location for the editor build");
19930
- await (0, import_promises28.mkdir)(dir, { recursive: true });
20336
+ await (0, import_promises29.mkdir)(dir, { recursive: true });
19931
20337
  const downloaded = [];
19932
20338
  const skipped = Object.keys(pin.files).filter((name) => !before.missing.includes(name));
19933
20339
  let fetchedBytes = before.installedBytes;
@@ -19955,13 +20361,13 @@ async function installEditor(opts = {}) {
19955
20361
  if (digest2 !== expected.sha256) {
19956
20362
  throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
19957
20363
  }
19958
- const final = import_node_path36.default.join(dir, name);
20364
+ const final = import_node_path37.default.join(dir, name);
19959
20365
  const tmp = `${final}.${process.pid}.part`;
19960
20366
  try {
19961
- await (0, import_promises28.writeFile)(tmp, bytes);
19962
- await (0, import_promises28.rename)(tmp, final);
20367
+ await (0, import_promises29.writeFile)(tmp, bytes);
20368
+ await (0, import_promises29.rename)(tmp, final);
19963
20369
  } finally {
19964
- await (0, import_promises28.rm)(tmp, { force: true });
20370
+ await (0, import_promises29.rm)(tmp, { force: true });
19965
20371
  }
19966
20372
  fetchedBytes += bytes.length;
19967
20373
  downloaded.push(name);
@@ -20001,12 +20407,12 @@ var EDITOR_CONTENT_TYPES = {
20001
20407
  ".json": "application/json; charset=utf-8"
20002
20408
  };
20003
20409
  function editorContentType(name) {
20004
- return EDITOR_CONTENT_TYPES[import_node_path36.default.extname(name).toLowerCase()] ?? null;
20410
+ return EDITOR_CONTENT_TYPES[import_node_path37.default.extname(name).toLowerCase()] ?? null;
20005
20411
  }
20006
20412
 
20007
20413
  // src/gallery/editor.ts
20008
- var import_promises29 = require("fs/promises");
20009
- var import_node_path37 = __toESM(require("path"), 1);
20414
+ var import_promises30 = require("fs/promises");
20415
+ var import_node_path38 = __toESM(require("path"), 1);
20010
20416
  function editorRoute(release, name = "index.html") {
20011
20417
  return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
20012
20418
  }
@@ -20079,7 +20485,7 @@ function createGalleryEditorHandlers(opts = {}) {
20079
20485
  if (!status.installed) return null;
20080
20486
  let bytes;
20081
20487
  try {
20082
- bytes = await (0, import_promises29.readFile)(import_node_path37.default.join(dir, name));
20488
+ bytes = await (0, import_promises30.readFile)(import_node_path38.default.join(dir, name));
20083
20489
  } catch {
20084
20490
  verified = null;
20085
20491
  return null;
@@ -20096,7 +20502,7 @@ function createGalleryEditorHandlers(opts = {}) {
20096
20502
  // src/gallery/server.ts
20097
20503
  var import_node_crypto9 = require("crypto");
20098
20504
  var import_node_http2 = require("http");
20099
- var import_promises30 = require("fs/promises");
20505
+ var import_promises31 = require("fs/promises");
20100
20506
  var MAX_EDIT_BYTES = 48 * 1024 * 1024;
20101
20507
  var EDITOR_CSP = [
20102
20508
  "default-src 'self'",
@@ -20277,7 +20683,7 @@ async function serveGallery(opts) {
20277
20683
  const asset = reviewAssets.get(jobId)?.get(url2.pathname);
20278
20684
  if (!asset) return fail(404, "no such review asset");
20279
20685
  try {
20280
- const bytes = await (0, import_promises30.readFile)(asset.path);
20686
+ const bytes = await (0, import_promises31.readFile)(asset.path);
20281
20687
  res.writeHead(200, {
20282
20688
  "Content-Type": asset.contentType,
20283
20689
  "Cache-Control": "no-store",
@@ -20360,7 +20766,7 @@ async function serveGallery(opts) {
20360
20766
  if (!asset) return fail(404, "no such gallery media");
20361
20767
  let bytes;
20362
20768
  try {
20363
- bytes = await (0, import_promises30.readFile)(asset.path);
20769
+ bytes = await (0, import_promises31.readFile)(asset.path);
20364
20770
  } catch {
20365
20771
  return fail(404, "gallery media is no longer on disk; refresh the page");
20366
20772
  }
@@ -20770,19 +21176,19 @@ function createGenerateHandlers(opts) {
20770
21176
  }
20771
21177
 
20772
21178
  // src/pipeline/salvage.ts
20773
- var import_promises31 = require("fs/promises");
20774
- var import_node_fs33 = require("fs");
20775
- var import_node_path38 = __toESM(require("path"), 1);
21179
+ var import_promises32 = require("fs/promises");
21180
+ var import_node_fs36 = require("fs");
21181
+ var import_node_path39 = __toESM(require("path"), 1);
20776
21182
  function providerClaimId(provider, objectId) {
20777
21183
  return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
20778
21184
  }
20779
21185
  async function loadClaims(lockPaths, opts = {}) {
20780
21186
  const claimed = /* @__PURE__ */ new Set();
20781
21187
  for (const p of lockPaths) {
20782
- if (!(0, import_node_fs33.existsSync)(p)) throw new Error(`Claim lockfile not found: ${p}`);
21188
+ if (!(0, import_node_fs36.existsSync)(p)) throw new Error(`Claim lockfile not found: ${p}`);
20783
21189
  let parsed;
20784
21190
  try {
20785
- parsed = parseLock(JSON.parse(await (0, import_promises31.readFile)(p, "utf8")));
21191
+ parsed = parseLock(JSON.parse(await (0, import_promises32.readFile)(p, "utf8")));
20786
21192
  } catch {
20787
21193
  throw new Error(`Claim lockfile is malformed: ${p}`);
20788
21194
  }
@@ -20886,20 +21292,20 @@ function matchOrphanStyle(prompt, manifest) {
20886
21292
  return matchStyleByPattern(prompt, manifest);
20887
21293
  }
20888
21294
  async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
20889
- const own = import_node_path38.default.resolve(ownManifestPath);
21295
+ const own = import_node_path39.default.resolve(ownManifestPath);
20890
21296
  const siblingManifestPaths = [
20891
21297
  .../* @__PURE__ */ new Set([
20892
21298
  ...workspaceManifestPaths,
20893
- ...claimPaths.map((c) => import_node_path38.default.join(import_node_path38.default.dirname(import_node_path38.default.resolve(c)), "pixelkiln.manifest.json"))
21299
+ ...claimPaths.map((c) => import_node_path39.default.join(import_node_path39.default.dirname(import_node_path39.default.resolve(c)), "pixelkiln.manifest.json"))
20894
21300
  ])
20895
21301
  ];
20896
21302
  const siblings = [];
20897
21303
  for (const siblingManifestPath of siblingManifestPaths) {
20898
- if (import_node_path38.default.resolve(siblingManifestPath) === own) continue;
20899
- if (!(0, import_node_fs33.existsSync)(siblingManifestPath)) continue;
21304
+ if (import_node_path39.default.resolve(siblingManifestPath) === own) continue;
21305
+ if (!(0, import_node_fs36.existsSync)(siblingManifestPath)) continue;
20900
21306
  try {
20901
21307
  const { manifest } = await loadManifest(siblingManifestPath);
20902
- siblings.push({ label: import_node_path38.default.basename(import_node_path38.default.dirname(siblingManifestPath)), manifest });
21308
+ siblings.push({ label: import_node_path39.default.basename(import_node_path39.default.dirname(siblingManifestPath)), manifest });
20903
21309
  } catch {
20904
21310
  }
20905
21311
  }
@@ -21019,8 +21425,8 @@ async function applyTags(provider, decisions, existing, opts = {}) {
21019
21425
  }
21020
21426
 
21021
21427
  // src/pick/salvage-server.ts
21022
- var import_promises32 = require("fs/promises");
21023
- var import_node_path39 = __toESM(require("path"), 1);
21428
+ var import_promises33 = require("fs/promises");
21429
+ var import_node_path40 = __toESM(require("path"), 1);
21024
21430
 
21025
21431
  // src/pick/salvage-sheet.ts
21026
21432
  var escapeHtml3 = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
@@ -21186,7 +21592,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
21186
21592
  });
21187
21593
  const html = renderSalvageSheet(orphans, {
21188
21594
  styleId: ctx.styleId,
21189
- importDir: import_node_path39.default.relative(process.cwd(), ctx.importDir) || "."
21595
+ importDir: import_node_path40.default.relative(process.cwd(), ctx.importDir) || "."
21190
21596
  });
21191
21597
  const byId = new Map(orphans.map((o) => [o.id, o]));
21192
21598
  const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
@@ -21242,10 +21648,10 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
21242
21648
  if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
21243
21649
  decodePng(buf);
21244
21650
  const assetId = idFromPrompt(orphan.prompt, taken);
21245
- const rel = import_node_path39.default.join("_salvaged", `${assetId}.png`);
21246
- 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);
21651
+ const rel = import_node_path40.default.join("_salvaged", `${assetId}.png`);
21652
+ const outFile = import_node_path40.default.resolve(ctx.importDir, rel);
21653
+ await (0, import_promises33.mkdir)(import_node_path40.default.dirname(outFile), { recursive: true });
21654
+ await (0, import_promises33.writeFile)(outFile, buf);
21249
21655
  ctx.manifest.assets[assetId] = {
21250
21656
  prompt: orphan.prompt,
21251
21657
  promptByStyle: {},
@@ -21277,7 +21683,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
21277
21683
  sourceUrl: durableSource,
21278
21684
  sourceUrls: durableSource ? [{ url: durableSource }] : [],
21279
21685
  outputs: [{
21280
- path: portableOutputPath(outFile, import_node_path39.default.dirname(ctx.manifestPath)),
21686
+ path: portableOutputPath(outFile, import_node_path40.default.dirname(ctx.manifestPath)),
21281
21687
  sha256: sha256(buf)
21282
21688
  }],
21283
21689
  submittedAt: orphan.createdAt,
@@ -21301,9 +21707,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
21301
21707
  }
21302
21708
  }
21303
21709
  await applyTags(provider, decisions, existingTags, { onProgress: log, characters: characterMembers });
21304
- const raw = JSON.parse(await (0, import_promises32.readFile)(ctx.manifestPath, "utf8"));
21710
+ const raw = JSON.parse(await (0, import_promises33.readFile)(ctx.manifestPath, "utf8"));
21305
21711
  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");
21712
+ await (0, import_promises33.writeFile)(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
21307
21713
  await saveLock(ctx.lockPath, ctx.lock);
21308
21714
  if (characterAssetIds.length) result.characterAssetIds = characterAssetIds;
21309
21715
  return result;
@@ -21527,6 +21933,7 @@ async function workspaceStatus(ws, dir) {
21527
21933
  availableProviders,
21528
21934
  backoffMs,
21529
21935
  buildGallerySnapshot,
21936
+ buildImportedEntry,
21530
21937
  buildManifest,
21531
21938
  buildPlan,
21532
21939
  buildWorkspaceGallerySnapshot,
@@ -21589,6 +21996,7 @@ async function workspaceStatus(ws, dir) {
21589
21996
  historyLimit,
21590
21997
  idFromPrompt,
21591
21998
  imageMetadata,
21999
+ importLocal,
21592
22000
  inspectCaches,
21593
22001
  inspectQualityProfile,
21594
22002
  inspectRevisionReadiness,
@@ -21681,6 +22089,7 @@ async function workspaceStatus(ws, dir) {
21681
22089
  renderSalvageSheet,
21682
22090
  renderSheet,
21683
22091
  renderSheetDocument,
22092
+ reportSpecHashes,
21684
22093
  requireApprovedQualitySources,
21685
22094
  requireBalance,
21686
22095
  requireDelete,
@@ -21720,6 +22129,7 @@ async function workspaceStatus(ws, dir) {
21720
22129
  sliceVfxSheet,
21721
22130
  slugify,
21722
22131
  snapshotQualityBaseline,
22132
+ snapshotQualityCases,
21723
22133
  sourceIsStem,
21724
22134
  sourceOutputPath,
21725
22135
  specHash,