pixelkiln 0.92.3 → 0.93.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -67,8 +67,8 @@ function exitCodeFor(err) {
67
67
  }
68
68
 
69
69
  // src/cli/main.ts
70
- import { existsSync as existsSync39 } from "fs";
71
- import { readFile as readFile36 } from "fs/promises";
70
+ import { existsSync as existsSync41 } from "fs";
71
+ import { readFile as readFile37 } from "fs/promises";
72
72
 
73
73
  // src/cli/args.ts
74
74
  import path from "path";
@@ -102,6 +102,8 @@ var VALUE_FLAGS = [
102
102
  "--min-grid-confidence",
103
103
  "--reviewer",
104
104
  "--note",
105
+ "--source",
106
+ "--object-id",
105
107
  "--model-root",
106
108
  "--generation",
107
109
  "--quantize",
@@ -135,11 +137,13 @@ var BOOL_FLAGS = [
135
137
  "--edit",
136
138
  "--refresh",
137
139
  "--no-editor",
138
- "--game-pack"
140
+ "--game-pack",
141
+ "--local"
139
142
  ];
140
143
  var COMMANDS = [
141
144
  "init",
142
145
  "plan",
146
+ "hash",
143
147
  "doctor",
144
148
  "gen",
145
149
  "submit",
@@ -415,6 +419,9 @@ function parseArgs(argv) {
415
419
  edit: rest.includes("--edit"),
416
420
  noEditor: rest.includes("--no-editor"),
417
421
  refresh: rest.includes("--refresh"),
422
+ local: rest.includes("--local"),
423
+ source: get("--source"),
424
+ objectId: get("--object-id"),
418
425
  from: get("--from"),
419
426
  out: get("--out"),
420
427
  generator: get("--generator"),
@@ -482,6 +489,8 @@ Commands
482
489
  --generation <n|hash> brings a previous generation back instead.
483
490
  history List the generations each asset has replaced and can restore.
484
491
  adopt Match existing account objects to files already in the repo.
492
+ --local records them offline (no key): --source, --note, --object-id, --dry-run.
493
+ hash Print each asset's spec hash, file hash and would-be lock entry (offline).
485
494
  accept Keep existing art after a style reword. Re-baseline, do not regenerate.
486
495
  salvage Triage account objects no lockfile claims. Recovers usable art.
487
496
  One session per matching style unless --style forces a single one.
@@ -2512,7 +2521,17 @@ var LockEntrySchema = z.object({
2512
2521
  /** Generations this entry replaced, newest first; see LockHistoryEntrySchema. */
2513
2522
  history: z.array(LockHistoryEntrySchema).optional(),
2514
2523
  /** Post-processing applied to the recorded outputs; absent when the bytes are the provider's. */
2515
- postprocess: PostprocessSchema.optional()
2524
+ postprocess: PostprocessSchema.optional(),
2525
+ /**
2526
+ * Set when the entry records art made outside pixelkiln (the PixelLab MCP, a
2527
+ * hand edit, another tool) and brought in with `adopt --local`: nothing was
2528
+ * submitted, so jobId and cost are empty. Absent on generated entries.
2529
+ */
2530
+ imported: z.object({
2531
+ source: z.string().min(1),
2532
+ note: z.string().optional(),
2533
+ importedAt: z.string()
2534
+ }).strict().optional()
2516
2535
  });
2517
2536
  var LockSchema = z.object({
2518
2537
  version: z.literal(2),
@@ -5354,7 +5373,7 @@ async function confirm(question, auto) {
5354
5373
 
5355
5374
  // src/cli/commands/account.ts
5356
5375
  import path25 from "path";
5357
- import { existsSync as existsSync18 } from "fs";
5376
+ import { existsSync as existsSync20 } from "fs";
5358
5377
 
5359
5378
  // src/env.ts
5360
5379
  import { readFileSync, existsSync as existsSync6 } from "fs";
@@ -10943,13 +10962,13 @@ var PixelLabProvider = class _PixelLabProvider {
10943
10962
  async pollVfx(jobId, context) {
10944
10963
  const dir = _PixelLabProvider.cacheDir("vfx");
10945
10964
  const sidecar = path14.join(dir, `${jobId}.json`);
10946
- const cached = () => {
10965
+ const cached2 = () => {
10947
10966
  if (!existsSync9(sidecar)) return null;
10948
10967
  const facts2 = JSON.parse(readFileSync2(sidecar, "utf8"));
10949
10968
  const files2 = Array.from({ length: facts2.count }, (_, index) => path14.join(dir, `${jobId}-${index}.png`));
10950
10969
  return files2.every((file) => existsSync9(file)) ? { facts: facts2, files: files2 } : null;
10951
10970
  };
10952
- let found = cached();
10971
+ let found = cached2();
10953
10972
  const recorded = context?.metadata?.vfx;
10954
10973
  let artistDone;
10955
10974
  if (!found && recorded?.artist) {
@@ -10969,11 +10988,11 @@ var PixelLabProvider = class _PixelLabProvider {
10969
10988
  }
10970
10989
  artistDone.billed = billedFromUsage(job.usage);
10971
10990
  }
10972
- found = cached();
10991
+ found = cached2();
10973
10992
  } else if (!found && recorded?.downloadBase && Array.isArray(recorded.files)) {
10974
10993
  const exported = recorded;
10975
10994
  await this.cacheVfxFrames(jobId, exported, workbenchVfxUrls(exported));
10976
- found = cached();
10995
+ found = cached2();
10977
10996
  }
10978
10997
  if (!found) {
10979
10998
  return {
@@ -12171,8 +12190,8 @@ var ScenarioClient = class {
12171
12190
  async uploadImage(image, projectId) {
12172
12191
  const bytes = Buffer.from(image.base64, "base64");
12173
12192
  const digest2 = sha256(bytes);
12174
- const cached = readUploadCache()[uploadCacheKey(this.baseUrl, projectId, digest2)];
12175
- if (cached) return cached;
12193
+ const cached2 = readUploadCache()[uploadCacheKey(this.baseUrl, projectId, digest2)];
12194
+ if (cached2) return cached2;
12176
12195
  const response = await this.call(
12177
12196
  "/assets",
12178
12197
  {
@@ -12763,7 +12782,7 @@ registerProvider({
12763
12782
 
12764
12783
  // src/manifest.ts
12765
12784
  import { readFile as readFile8 } from "fs/promises";
12766
- import { existsSync as existsSync10 } from "fs";
12785
+ import { existsSync as existsSync11 } from "fs";
12767
12786
  import path16 from "path";
12768
12787
 
12769
12788
  // src/loop-directions.ts
@@ -12859,10 +12878,31 @@ function isObject2(value) {
12859
12878
  return typeof value === "object" && value !== null && !Array.isArray(value);
12860
12879
  }
12861
12880
 
12881
+ // src/version.ts
12882
+ import { existsSync as existsSync10, readFileSync as readFileSync4 } from "fs";
12883
+ var cached;
12884
+ function pixelkilnVersion() {
12885
+ if (cached !== void 0) return cached;
12886
+ cached = null;
12887
+ for (const up of ["../package.json", "../../package.json"]) {
12888
+ const url = new URL(up, import.meta.url);
12889
+ if (!existsSync10(url)) continue;
12890
+ try {
12891
+ const pkg = JSON.parse(readFileSync4(url, "utf8"));
12892
+ if (pkg.name === "pixelkiln" && pkg.version) {
12893
+ cached = pkg.version;
12894
+ break;
12895
+ }
12896
+ } catch {
12897
+ }
12898
+ }
12899
+ return cached;
12900
+ }
12901
+
12862
12902
  // src/manifest.ts
12863
12903
  async function loadManifest(manifestPath) {
12864
12904
  const abs = path16.resolve(manifestPath);
12865
- if (!existsSync10(abs)) throw new ProjectError(`No manifest at ${abs}`);
12905
+ if (!existsSync11(abs)) throw new ProjectError(`No manifest at ${abs}`);
12866
12906
  const expansion = expandLoopDirections(JSON.parse(await readFile8(abs, "utf8")));
12867
12907
  if (expansion.issues.length) {
12868
12908
  throw new ProjectError(`Manifest at ${abs} is invalid:
@@ -13014,19 +13054,45 @@ function dependencyAssetIds(asset, styleAnchors = []) {
13014
13054
  ].filter((id) => Boolean(id))
13015
13055
  ];
13016
13056
  }
13057
+ var MAX_LISTED_MANIFEST_ISSUES = 20;
13058
+ function flattenManifestIssues(issues) {
13059
+ let unknownShape = false;
13060
+ const visit = (list) => list.flatMap((issue) => {
13061
+ if (issue.code === "invalid_union") return visit(issue.unionErrors.flatMap((error) => error.issues));
13062
+ if (issue.code === "unrecognized_keys" || issue.code === "invalid_enum_value") unknownShape = true;
13063
+ return [` ${issue.path.join(".") || "(manifest)"}: ${issue.message}`];
13064
+ });
13065
+ return { lines: [...new Set(visit(issues))], unknownShape };
13066
+ }
13017
13067
  function formatManifestIssues(issues) {
13018
- return issues.flatMap((issue) => {
13019
- if (issue.code === "invalid_union") {
13020
- return issue.unionErrors.flatMap((error) => formatManifestIssues(error.issues).split("\n"));
13021
- }
13022
- return [` ${issue.path.join(".")}: ${issue.message}`];
13023
- }).join("\n");
13068
+ const { lines, unknownShape } = flattenManifestIssues(issues);
13069
+ const entries = [...new Set(
13070
+ lines.flatMap((line) => {
13071
+ const match = /^ {2}((?:assets|styles)\.[^.:\s]+)/.exec(line);
13072
+ return match ? [match[1]] : [];
13073
+ })
13074
+ )];
13075
+ const out = [];
13076
+ const version = pixelkilnVersion();
13077
+ if (unknownShape) {
13078
+ out.push(
13079
+ ` 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.`
13080
+ );
13081
+ }
13082
+ if (entries.length) {
13083
+ out.push(` ${entries.length} invalid entr${entries.length === 1 ? "y" : "ies"}: ${entries.slice(0, 10).join(", ")}${entries.length > 10 ? ", \u2026" : ""}`);
13084
+ }
13085
+ out.push(...lines.slice(0, MAX_LISTED_MANIFEST_ISSUES));
13086
+ if (lines.length > MAX_LISTED_MANIFEST_ISSUES) {
13087
+ out.push(` \u2026 and ${lines.length - MAX_LISTED_MANIFEST_ISSUES} more`);
13088
+ }
13089
+ return out.join("\n");
13024
13090
  }
13025
13091
  function resolveStyleInheritance(styles) {
13026
13092
  const resolved = /* @__PURE__ */ new Map();
13027
13093
  const visit = (styleId, chain) => {
13028
- const cached = resolved.get(styleId);
13029
- if (cached) return cached;
13094
+ const cached2 = resolved.get(styleId);
13095
+ if (cached2) return cached2;
13030
13096
  const cycleStart = chain.indexOf(styleId);
13031
13097
  if (cycleStart >= 0) {
13032
13098
  throw new Error(
@@ -13148,7 +13214,7 @@ async function resolveSpecs(loaded, filter) {
13148
13214
  const abs = path16.resolve(root, rel);
13149
13215
  let hit = styleImageCache.get(abs);
13150
13216
  if (!hit) {
13151
- if (!existsSync10(abs)) throw new Error(`${what} not found: ${abs}`);
13217
+ if (!existsSync11(abs)) throw new Error(`${what} not found: ${abs}`);
13152
13218
  const buf = await readFile8(abs);
13153
13219
  const metadata = imageMetadata(buf);
13154
13220
  if (!metadata) throw new Error(`${what} is not a readable PNG or JPEG: ${abs}`);
@@ -13499,7 +13565,7 @@ async function resolveSpecs(loaded, filter) {
13499
13565
  const file = memberPath(anchorSpec.outFile, "south", 0, anchorSpec.character.directions, MediaType.PNG);
13500
13566
  resolved.character = {
13501
13567
  ...resolved.character,
13502
- styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: existsSync10(file) ? await sha256File(file) : null }
13568
+ styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: existsSync11(file) ? await sha256File(file) : null }
13503
13569
  };
13504
13570
  }
13505
13571
  const characterParent = asset.state?.of ?? asset.animation?.of ?? asset.portrait?.of;
@@ -13512,7 +13578,7 @@ async function resolveSpecs(loaded, filter) {
13512
13578
  parentAssetId: characterParent,
13513
13579
  parentSpec,
13514
13580
  parentFile,
13515
- parentSha256: existsSync10(parentFile) ? await sha256File(parentFile) : null,
13581
+ parentSha256: existsSync11(parentFile) ? await sha256File(parentFile) : null,
13516
13582
  // A state and its animations keep the engine and rotations of the base.
13517
13583
  mode: resolved.character.kind === "base" ? resolved.character.mode : parentSpec.character?.mode ?? resolved.character.mode,
13518
13584
  directions: resolved.character.kind === "base" ? resolved.character.directions : parentSpec.character?.directions ?? resolved.character.directions
@@ -13550,7 +13616,7 @@ async function resolveSpecs(loaded, filter) {
13550
13616
  parentAssetId: characterParent,
13551
13617
  parentSpec,
13552
13618
  parentFile,
13553
- parentSha256: existsSync10(parentFile) ? await sha256File(parentFile) : null,
13619
+ parentSha256: existsSync11(parentFile) ? await sha256File(parentFile) : null,
13554
13620
  // A state and its animations keep the base's own rotation count.
13555
13621
  directions: resolved.objectPro.kind === "base" ? resolved.objectPro.directions : parentSpec.objectPro.directions
13556
13622
  };
@@ -13754,8 +13820,18 @@ async function resolveSpecs(loaded, filter) {
13754
13820
  providerOptionIdentity,
13755
13821
  providerInputIdentities.get(assetId)
13756
13822
  );
13757
- activeProvider.validate?.(resolved, resolvedImages);
13758
- const estimate = validateCostEstimate(activeProvider.id, activeProvider.estimate(resolved));
13823
+ let estimate;
13824
+ try {
13825
+ activeProvider.validate?.(resolved, resolvedImages);
13826
+ estimate = validateCostEstimate(activeProvider.id, activeProvider.estimate(resolved));
13827
+ } catch (error) {
13828
+ const message6 = error instanceof Error ? error.message : String(error);
13829
+ if (message6.includes(`assets.${assetId}`)) throw error;
13830
+ throw new Error(
13831
+ `assets.${assetId} (style "${styleId}", ${resolved.width}x${resolved.height}): ${message6}`,
13832
+ { cause: error }
13833
+ );
13834
+ }
13759
13835
  resolved.cost = estimate.amount;
13760
13836
  resolved.costUnit = estimate.unit;
13761
13837
  resolved.candidates = estimate.candidates;
@@ -13839,7 +13915,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
13839
13915
  let recordedSprite;
13840
13916
  if (vfx.recipe) {
13841
13917
  const file = path16.resolve(root, vfx.recipe);
13842
- if (!existsSync10(file)) throw new Error(`assets.${assetId}.vfx.recipe: VFX recipe not found: ${file}`);
13918
+ if (!existsSync11(file)) throw new Error(`assets.${assetId}.vfx.recipe: VFX recipe not found: ${file}`);
13843
13919
  const read = await readVfxRecipe(file).catch((error) => {
13844
13920
  throw new Error(`assets.${assetId}.vfx.recipe: ${error instanceof Error ? error.message : String(error)}`);
13845
13921
  });
@@ -13866,7 +13942,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
13866
13942
  };
13867
13943
  }
13868
13944
  async function optionalRevisionImage(file, label, requiredFormat) {
13869
- if (!existsSync10(file)) return null;
13945
+ if (!existsSync11(file)) return null;
13870
13946
  const bytes = await readFile8(file);
13871
13947
  const metadata = imageMetadata(bytes);
13872
13948
  if (!metadata) throw new Error(`${label} is not a readable PNG or JPEG: ${file}`);
@@ -13876,7 +13952,7 @@ async function optionalRevisionImage(file, label, requiredFormat) {
13876
13952
  return { hash: sha256(bytes), ...metadata };
13877
13953
  }
13878
13954
  async function optionalSkeletonSet(file) {
13879
- if (!existsSync10(file)) return null;
13955
+ if (!existsSync11(file)) return null;
13880
13956
  const bytes = await readFile8(file);
13881
13957
  let json;
13882
13958
  try {
@@ -13887,17 +13963,17 @@ async function optionalSkeletonSet(file) {
13887
13963
  return { hash: sha256(bytes), skeleton: parseSkeletonSet(json, file) };
13888
13964
  }
13889
13965
  async function revisionSourceMembers(stem, label) {
13890
- if (existsSync10(stem)) return null;
13966
+ if (existsSync11(stem)) return null;
13891
13967
  const at = (role) => memberPath(stem, role, 0, 2, MediaType.PNG);
13892
13968
  let roles = [];
13893
13969
  for (const set of [CHARACTER_DIRECTIONS_8, CHARACTER_DIRECTIONS_4]) {
13894
- if (set.every((direction) => existsSync10(at(direction)))) {
13970
+ if (set.every((direction) => existsSync11(at(direction)))) {
13895
13971
  roles = [...set];
13896
13972
  break;
13897
13973
  }
13898
13974
  }
13899
13975
  if (!roles.length) {
13900
- for (let index = 0; existsSync10(at(`frame-${String(index).padStart(2, "0")}`)); index++) {
13976
+ for (let index = 0; existsSync11(at(`frame-${String(index).padStart(2, "0")}`)); index++) {
13901
13977
  roles.push(`frame-${String(index).padStart(2, "0")}`);
13902
13978
  }
13903
13979
  }
@@ -14056,7 +14132,7 @@ async function resolveObjectProShape(assetId, asset, style, kind, files) {
14056
14132
  }
14057
14133
 
14058
14134
  // src/pipeline/fetch.ts
14059
- import { existsSync as existsSync11, readFileSync as readFileSync4 } from "fs";
14135
+ import { existsSync as existsSync12, readFileSync as readFileSync5 } from "fs";
14060
14136
  import { mkdir as mkdir6, readFile as readFile9, rename as rename4, rm as rm4, writeFile as writeFile6 } from "fs/promises";
14061
14137
  import path17 from "path";
14062
14138
  async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
@@ -14076,15 +14152,15 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
14076
14152
  if (spec && e.specHash === spec.specHash && e.outputs.length && !postprocessCurrent(e, spec)) {
14077
14153
  return Boolean(opts.force) || e.outputs.every((output) => {
14078
14154
  const file = resolveOutputPath(output.path, spec.root);
14079
- return existsSync11(file) && sha256(readFileSync4(file)) === output.sha256;
14155
+ return existsSync12(file) && sha256(readFileSync5(file)) === output.sha256;
14080
14156
  });
14081
14157
  }
14082
14158
  if (!opts.repair) return false;
14083
14159
  if (e.outputs.length === 0 || !spec) return true;
14084
14160
  return e.outputs.some((output) => {
14085
14161
  const file = resolveOutputPath(output.path, spec.root);
14086
- if (!existsSync11(file)) return true;
14087
- const current = sha256(readFileSync4(file));
14162
+ if (!existsSync12(file)) return true;
14163
+ const current = sha256(readFileSync5(file));
14088
14164
  if (current === output.sha256) return false;
14089
14165
  return Boolean(opts.force) || (e.supersededOutputs ?? []).some((old) => old.sha256 === current);
14090
14166
  });
@@ -14174,7 +14250,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
14174
14250
  }
14175
14251
  let raw = null;
14176
14252
  let final = null;
14177
- if (existsSync11(target)) {
14253
+ if (existsSync12(target)) {
14178
14254
  const currentHash = await sha256File(target);
14179
14255
  if (recorded && currentHash === recorded.sha256) {
14180
14256
  if (!fresh && !reapply) {
@@ -14320,7 +14396,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
14320
14396
  }
14321
14397
  async function readCachedMedia(cacheDir, hash, mediaType) {
14322
14398
  const file = path17.join(cacheDir, cacheFileName(hash, mediaType));
14323
- if (!existsSync11(file)) return null;
14399
+ if (!existsSync12(file)) return null;
14324
14400
  try {
14325
14401
  const buf = await readFile9(file);
14326
14402
  if (sha256(buf) !== hash) return null;
@@ -14341,7 +14417,7 @@ async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
14341
14417
  try {
14342
14418
  await rename4(tmp, file);
14343
14419
  } catch (err) {
14344
- if (!existsSync11(file)) throw err;
14420
+ if (!existsSync12(file)) throw err;
14345
14421
  } finally {
14346
14422
  await rm4(tmp, { force: true });
14347
14423
  }
@@ -14373,14 +14449,125 @@ async function pushTags(provider, specs, lock, opts = {}) {
14373
14449
  return tagged;
14374
14450
  }
14375
14451
 
14376
- // src/pipeline/adopt.ts
14452
+ // src/pipeline/import.ts
14377
14453
  import { existsSync as existsSync13 } from "fs";
14378
- import { readFile as readFile11, writeFile as writeFile8 } from "fs/promises";
14454
+ import { readFile as readFile10 } from "fs/promises";
14455
+ function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
14456
+ const png = decodePng(bytes);
14457
+ const at = now.toISOString();
14458
+ return {
14459
+ styleId: spec.styleId,
14460
+ assetId: spec.assetId,
14461
+ specHash: spec.specHash,
14462
+ generator: spec.generator,
14463
+ prompt: spec.prompt,
14464
+ width: png.width,
14465
+ height: png.height,
14466
+ jobId: opts.objectId ?? null,
14467
+ objectId: opts.objectId ?? null,
14468
+ reviewObjectId: null,
14469
+ candidateIndex: null,
14470
+ status: "downloaded",
14471
+ error: null,
14472
+ sourceUrl: null,
14473
+ sourceUrls: [],
14474
+ outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
14475
+ submittedAt: null,
14476
+ downloadedAt: at,
14477
+ cost: 0,
14478
+ costUnit: spec.costUnit,
14479
+ provider: spec.provider,
14480
+ imported: {
14481
+ source: opts.source ?? "external",
14482
+ ...opts.note ? { note: opts.note } : {},
14483
+ importedAt: at
14484
+ }
14485
+ };
14486
+ }
14487
+ function unimportable(spec) {
14488
+ if (spec.character) return "a character is several files; import it with account adopt";
14489
+ if (spec.vfx) return "an effect is rendered from its recipe, not imported";
14490
+ if (!spec.outFile.toLowerCase().endsWith(".png")) return "only a single PNG output can be imported";
14491
+ return null;
14492
+ }
14493
+ async function importLocal(specs, lock, lockPath, opts = {}) {
14494
+ if (opts.objectId && specs.length !== 1) {
14495
+ throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
14496
+ }
14497
+ const imported = [];
14498
+ const skipped = [];
14499
+ for (const spec of specs) {
14500
+ const key = lockKey(spec.styleId, spec.assetId);
14501
+ const reason = unimportable(spec);
14502
+ if (reason) {
14503
+ skipped.push({ key, reason });
14504
+ continue;
14505
+ }
14506
+ if (!existsSync13(spec.outFile)) {
14507
+ skipped.push({ key, reason: `no file at ${spec.outFile}` });
14508
+ continue;
14509
+ }
14510
+ if (lock.entries[key] && !opts.force) {
14511
+ skipped.push({ key, reason: "already in the lockfile (use --force to replace it)" });
14512
+ continue;
14513
+ }
14514
+ let patch;
14515
+ try {
14516
+ patch = buildImportedEntry(spec, await readFile10(spec.outFile), opts);
14517
+ } catch (error) {
14518
+ skipped.push({ key, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
14519
+ continue;
14520
+ }
14521
+ if (opts.dryRun) {
14522
+ imported.push({ key, entry: patch });
14523
+ continue;
14524
+ }
14525
+ imported.push({ key, entry: upsert(lock, key, patch) });
14526
+ }
14527
+ if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
14528
+ return { imported, skipped };
14529
+ }
14530
+ async function reportSpecHashes(specs, lock) {
14531
+ const reports = [];
14532
+ for (const spec of specs) {
14533
+ const key = lockKey(spec.styleId, spec.assetId);
14534
+ let bytes = null;
14535
+ if (existsSync13(spec.outFile)) bytes = await readFile10(spec.outFile);
14536
+ let wouldImport = null;
14537
+ if (bytes && !unimportable(spec)) {
14538
+ try {
14539
+ wouldImport = buildImportedEntry(spec, bytes);
14540
+ } catch {
14541
+ wouldImport = null;
14542
+ }
14543
+ }
14544
+ const entry = lock.entries[key];
14545
+ const fileSha256 = bytes ? sha256(bytes) : null;
14546
+ const outputSha256 = entry?.outputs[0]?.sha256 ?? null;
14547
+ reports.push({
14548
+ key,
14549
+ specHash: spec.specHash,
14550
+ file: spec.outFile,
14551
+ fileSha256,
14552
+ lock: entry ? {
14553
+ specHash: entry.specHash,
14554
+ outputSha256,
14555
+ matches: entry.specHash === spec.specHash && outputSha256 !== null && outputSha256 === fileSha256
14556
+ } : null,
14557
+ wouldImport
14558
+ });
14559
+ }
14560
+ return reports;
14561
+ }
14562
+
14563
+ // src/pipeline/adopt.ts
14564
+ import { existsSync as existsSync15 } from "fs";
14565
+ import { readFile as readFile12, writeFile as writeFile8 } from "fs/promises";
14379
14566
  import path18 from "path";
14380
14567
 
14381
14568
  // src/cache.ts
14382
- import { mkdir as mkdir7, readFile as readFile10, rename as rename5, rm as rm5, writeFile as writeFile7 } from "fs/promises";
14383
- import { existsSync as existsSync12 } from "fs";
14569
+ import { mkdir as mkdir7, readFile as readFile11, rename as rename5, rm as rm5, writeFile as writeFile7 } from "fs/promises";
14570
+ import { existsSync as existsSync14 } from "fs";
14384
14571
  import pathModule from "path";
14385
14572
  import { z as z4 } from "zod";
14386
14573
  var HashCacheSchema = z4.object({
@@ -14396,9 +14583,9 @@ function parseCache(value) {
14396
14583
  return HashCacheSchema.parse(value);
14397
14584
  }
14398
14585
  async function loadCache(path53) {
14399
- if (!existsSync12(path53)) return { version: 1, hashes: {} };
14586
+ if (!existsSync14(path53)) return { version: 1, hashes: {} };
14400
14587
  try {
14401
- const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile10(path53, "utf8")));
14588
+ const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile11(path53, "utf8")));
14402
14589
  if (!parsed.success) return { version: 1, hashes: {} };
14403
14590
  return {
14404
14591
  version: 1,
@@ -14455,11 +14642,11 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
14455
14642
  const localByHash = /* @__PURE__ */ new Map();
14456
14643
  const unmatchedLocal = [];
14457
14644
  for (const spec of specs) {
14458
- if (!existsSync13(spec.outFile)) {
14645
+ if (!existsSync15(spec.outFile)) {
14459
14646
  unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
14460
14647
  continue;
14461
14648
  }
14462
- const bytes = await readFile11(spec.outFile);
14649
+ const bytes = await readFile12(spec.outFile);
14463
14650
  try {
14464
14651
  decodePng(bytes);
14465
14652
  } catch (err) {
@@ -14579,7 +14766,7 @@ async function writePromptsBack(manifestPath, lock, opts = {}) {
14579
14766
  const log2 = opts.onProgress ?? (() => {
14580
14767
  });
14581
14768
  const selectedAssets = opts.assetIds ? new Set(opts.assetIds) : null;
14582
- const raw = JSON.parse(await readFile11(manifestPath, "utf8"));
14769
+ const raw = JSON.parse(await readFile12(manifestPath, "utf8"));
14583
14770
  const best = /* @__PURE__ */ new Map();
14584
14771
  for (const entry of Object.values(lock.entries)) {
14585
14772
  if (opts.provider && entry.provider !== opts.provider) continue;
@@ -14612,8 +14799,8 @@ function formatUnmatchedRemote(objects, limit = 15) {
14612
14799
  }
14613
14800
 
14614
14801
  // src/pipeline/adopt-characters.ts
14615
- import { existsSync as existsSync14 } from "fs";
14616
- import { mkdir as mkdir8, readFile as readFile12, writeFile as writeFile9 } from "fs/promises";
14802
+ import { existsSync as existsSync16 } from "fs";
14803
+ import { mkdir as mkdir8, readFile as readFile13, writeFile as writeFile9 } from "fs/promises";
14617
14804
  import path19 from "path";
14618
14805
  async function adoptCharacters(provider, specs, lock, lockPath, opts) {
14619
14806
  const log2 = opts.onProgress ?? (() => {
@@ -14648,8 +14835,8 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
14648
14835
  return bytes;
14649
14836
  };
14650
14837
  const southHash = async (character) => {
14651
- const cached = cache.hashes[`character:${character.id}`];
14652
- if (cached) return cached;
14838
+ const cached2 = cache.hashes[`character:${character.id}`];
14839
+ if (cached2) return cached2;
14653
14840
  if (!character.previewUrl || character.status !== "completed") return null;
14654
14841
  try {
14655
14842
  const hash = sha256(await download(character.previewUrl));
@@ -14665,8 +14852,8 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
14665
14852
  const bytes = await download(source.url);
14666
14853
  const hash = sha256(bytes);
14667
14854
  const file = expectedOutputPath(spec, source.role, index, sources.length);
14668
- if (existsSync14(file)) {
14669
- if (sha256(await readFile12(file)) !== hash) result.differing.push(path19.relative(process.cwd(), file));
14855
+ if (existsSync16(file)) {
14856
+ if (sha256(await readFile13(file)) !== hash) result.differing.push(path19.relative(process.cwd(), file));
14670
14857
  } else {
14671
14858
  await mkdir8(path19.dirname(file), { recursive: true });
14672
14859
  await writeFile9(file, bytes);
@@ -14708,11 +14895,11 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
14708
14895
  if (!match) throw new Error(`remoteId ${spec.remoteId} is not a character on this account`);
14709
14896
  } else {
14710
14897
  const south = expectedOutputPath(spec, "south", 0, spec.character.directions);
14711
- if (!existsSync14(south)) {
14898
+ if (!existsSync16(south)) {
14712
14899
  result.unmatched.push(`${key}: no remoteId and no ${path19.relative(process.cwd(), south)} to match by`);
14713
14900
  return false;
14714
14901
  }
14715
- const localHash = sha256(await readFile12(south));
14902
+ const localHash = sha256(await readFile13(south));
14716
14903
  for (const candidate of remote) {
14717
14904
  if (claimed.has(candidate.id)) continue;
14718
14905
  if (await southHash(candidate) === localHash) {
@@ -14788,7 +14975,7 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
14788
14975
  if (!match) throw new Error(`remoteId ${spec.remoteId} names no ${animation.direction} animation of character ${parentId}`);
14789
14976
  } else {
14790
14977
  const first = expectedOutputPath(spec, "frame-00", 0, 2);
14791
- if (!existsSync14(first)) {
14978
+ if (!existsSync16(first)) {
14792
14979
  const byName = candidates.find((a) => a.name === characterAnimationName(spec));
14793
14980
  if (!byName) {
14794
14981
  result.unmatched.push(`${key}: no remoteId and no ${path19.relative(process.cwd(), first)} to match by`);
@@ -14796,7 +14983,7 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
14796
14983
  }
14797
14984
  match = byName;
14798
14985
  } else {
14799
- const localHash = sha256(await readFile12(first));
14986
+ const localHash = sha256(await readFile13(first));
14800
14987
  for (const candidate of candidates) {
14801
14988
  if (sha256(await download(candidate.frames[0])) === localHash) {
14802
14989
  match = candidate;
@@ -14864,8 +15051,8 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
14864
15051
  }
14865
15052
 
14866
15053
  // src/pipeline/salvage.ts
14867
- import { readFile as readFile13 } from "fs/promises";
14868
- import { existsSync as existsSync15 } from "fs";
15054
+ import { readFile as readFile14 } from "fs/promises";
15055
+ import { existsSync as existsSync17 } from "fs";
14869
15056
  import path20 from "path";
14870
15057
  function providerClaimId(provider, objectId) {
14871
15058
  return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
@@ -14873,10 +15060,10 @@ function providerClaimId(provider, objectId) {
14873
15060
  async function loadClaims(lockPaths, opts = {}) {
14874
15061
  const claimed = /* @__PURE__ */ new Set();
14875
15062
  for (const p of lockPaths) {
14876
- if (!existsSync15(p)) throw new Error(`Claim lockfile not found: ${p}`);
15063
+ if (!existsSync17(p)) throw new Error(`Claim lockfile not found: ${p}`);
14877
15064
  let parsed;
14878
15065
  try {
14879
- parsed = parseLock(JSON.parse(await readFile13(p, "utf8")));
15066
+ parsed = parseLock(JSON.parse(await readFile14(p, "utf8")));
14880
15067
  } catch {
14881
15068
  throw new Error(`Claim lockfile is malformed: ${p}`);
14882
15069
  }
@@ -15053,7 +15240,7 @@ async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, cla
15053
15240
  const siblings = [];
15054
15241
  for (const siblingManifestPath of siblingManifestPaths) {
15055
15242
  if (path20.resolve(siblingManifestPath) === own) continue;
15056
- if (!existsSync15(siblingManifestPath)) continue;
15243
+ if (!existsSync17(siblingManifestPath)) continue;
15057
15244
  try {
15058
15245
  const { manifest } = await loadManifest(siblingManifestPath);
15059
15246
  siblings.push({ label: path20.basename(path20.dirname(siblingManifestPath)), manifest });
@@ -15176,8 +15363,8 @@ async function applyTags(provider, decisions, existing, opts = {}) {
15176
15363
  }
15177
15364
 
15178
15365
  // src/workspace.ts
15179
- import { mkdir as mkdir9, readFile as readFile14, rename as rename6, rm as rm6, writeFile as writeFile10 } from "fs/promises";
15180
- import { existsSync as existsSync16 } from "fs";
15366
+ import { mkdir as mkdir9, readFile as readFile15, rename as rename6, rm as rm6, writeFile as writeFile10 } from "fs/promises";
15367
+ import { existsSync as existsSync18 } from "fs";
15181
15368
  import path21 from "path";
15182
15369
  import { z as z5 } from "zod";
15183
15370
  var WorkspaceProjectSchema = z5.object({
@@ -15203,10 +15390,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
15203
15390
  );
15204
15391
  }
15205
15392
  async function loadWorkspace(workspacePath) {
15206
- if (!existsSync16(workspacePath)) return { version: 1, projects: [] };
15393
+ if (!existsSync18(workspacePath)) return { version: 1, projects: [] };
15207
15394
  let raw;
15208
15395
  try {
15209
- raw = JSON.parse(await readFile14(workspacePath, "utf8"));
15396
+ raw = JSON.parse(await readFile15(workspacePath, "utf8"));
15210
15397
  } catch (err) {
15211
15398
  throw new ProjectError(
15212
15399
  `Workspace catalog at ${workspacePath} is malformed:
@@ -15255,14 +15442,14 @@ function validateWorkspace(ws, dir) {
15255
15442
  message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
15256
15443
  });
15257
15444
  }
15258
- if (!existsSync16(manifestPath)) {
15445
+ if (!existsSync18(manifestPath)) {
15259
15446
  diagnostics.push({
15260
15447
  id: "missing-manifest",
15261
15448
  level: "error",
15262
15449
  message: `project "${project.id}" manifest not found: ${manifestPath}`
15263
15450
  });
15264
15451
  }
15265
- if (!existsSync16(lockPath)) {
15452
+ if (!existsSync18(lockPath)) {
15266
15453
  diagnostics.push({
15267
15454
  id: "missing-lock",
15268
15455
  level: "error",
@@ -15309,7 +15496,7 @@ function validateWorkspace(ws, dir) {
15309
15496
  }
15310
15497
 
15311
15498
  // src/pick/salvage-server.ts
15312
- import { mkdir as mkdir10, writeFile as writeFile11, readFile as readFile16 } from "fs/promises";
15499
+ import { mkdir as mkdir10, writeFile as writeFile11, readFile as readFile17 } from "fs/promises";
15313
15500
  import path22 from "path";
15314
15501
 
15315
15502
  // src/pick/salvage-sheet.ts
@@ -15471,7 +15658,7 @@ refresh();
15471
15658
 
15472
15659
  // src/pick/review-server.ts
15473
15660
  import { createServer } from "http";
15474
- import { readFile as readFile15 } from "fs/promises";
15661
+ import { readFile as readFile16 } from "fs/promises";
15475
15662
 
15476
15663
  // src/open.ts
15477
15664
  import { spawn } from "child_process";
@@ -15498,7 +15685,7 @@ function serveReviewPage(opts) {
15498
15685
  if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
15499
15686
  try {
15500
15687
  const asset = opts.assets.get(req.url);
15501
- const bytes = await readFile15(asset.path);
15688
+ const bytes = await readFile16(asset.path);
15502
15689
  res.writeHead(200, {
15503
15690
  "Content-Type": asset.contentType,
15504
15691
  "Cache-Control": "no-store",
@@ -15690,7 +15877,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
15690
15877
  }
15691
15878
  }
15692
15879
  await applyTags(provider, decisions, existingTags, { onProgress: log2, characters: characterMembers });
15693
- const raw = JSON.parse(await readFile16(ctx.manifestPath, "utf8"));
15880
+ const raw = JSON.parse(await readFile17(ctx.manifestPath, "utf8"));
15694
15881
  for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
15695
15882
  await writeFile11(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
15696
15883
  await saveLock(ctx.lockPath, ctx.lock);
@@ -15702,7 +15889,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
15702
15889
 
15703
15890
  // src/cli/project.ts
15704
15891
  import path24 from "path";
15705
- import { existsSync as existsSync17 } from "fs";
15892
+ import { existsSync as existsSync19 } from "fs";
15706
15893
 
15707
15894
  // src/project.ts
15708
15895
  import path23 from "path";
@@ -15848,7 +16035,7 @@ async function provenanceFile(id, file) {
15848
16035
  return {
15849
16036
  id,
15850
16037
  path: absolute,
15851
- sha256: existsSync17(absolute) ? await sha256File(absolute) : null,
16038
+ sha256: existsSync19(absolute) ? await sha256File(absolute) : null,
15852
16039
  included: true
15853
16040
  };
15854
16041
  }
@@ -15920,7 +16107,7 @@ function budgetsForPlan(plan, args) {
15920
16107
  return out;
15921
16108
  }
15922
16109
  async function requireCompleteWorkspaceClaims(workspacePath) {
15923
- if (!existsSync17(workspacePath)) {
16110
+ if (!existsSync19(workspacePath)) {
15924
16111
  throw new ProjectError(`Workspace catalog not found: ${workspacePath}`);
15925
16112
  }
15926
16113
  const dir = path24.dirname(path24.resolve(workspacePath));
@@ -15946,7 +16133,7 @@ async function openAccountProject(args) {
15946
16133
  return project;
15947
16134
  }
15948
16135
  async function open(args) {
15949
- if (!existsSync17(path24.resolve(args.manifest))) {
16136
+ if (!existsSync19(path24.resolve(args.manifest))) {
15950
16137
  throw new ProjectError(
15951
16138
  `No manifest at ${path24.resolve(args.manifest)}. Pass --manifest, or run \`pixelkiln init --from <dir>\`.`
15952
16139
  );
@@ -15954,7 +16141,7 @@ async function open(args) {
15954
16141
  const project = await openProject(args.manifest, { lockPath: args.lock, styles: args.styles, assets: args.assets });
15955
16142
  const { loaded, lock } = project;
15956
16143
  let specs = project.specs;
15957
- const accountProvider = ACCOUNT_COMMANDS.has(args.command) ? accountProviderId(loaded.manifest, args.provider, args.command) : void 0;
16144
+ const accountProvider = ACCOUNT_COMMANDS.has(args.command) && !args.local ? accountProviderId(loaded.manifest, args.provider, args.command) : void 0;
15958
16145
  if (args.provider && !accountProvider) {
15959
16146
  throw new UsageError("--provider is only used by balance, adopt, salvage, purge, or workspace add.");
15960
16147
  }
@@ -16000,7 +16187,35 @@ async function runBalance(args) {
16000
16187
  log(` plan: ${b.plan ?? "n/a"}`);
16001
16188
  log(` remaining: ${formatCost(b.unit, b.remaining)}${b.total ? ` of ${b.total}` : ""}`);
16002
16189
  }
16190
+ async function runAdoptLocal(args) {
16191
+ if (args.tag || args.writePrompts) {
16192
+ throw new UsageError("--tag and --write-prompts talk to the account; they cannot be combined with --local.");
16193
+ }
16194
+ const { specs, lock } = await openProject2(args);
16195
+ const result = await importLocal(specs, lock, args.lock, {
16196
+ source: args.source,
16197
+ note: args.note,
16198
+ objectId: args.objectId,
16199
+ force: args.force,
16200
+ dryRun: args.dryRun
16201
+ });
16202
+ if (args.json) {
16203
+ log(JSON.stringify({
16204
+ dryRun: args.dryRun,
16205
+ imported: result.imported.map(({ key, entry }) => ({ key, entry })),
16206
+ skipped: result.skipped
16207
+ }, null, 2));
16208
+ return;
16209
+ }
16210
+ for (const { key, entry } of result.imported) {
16211
+ log(` ${args.dryRun ? "would import" : "imported"} ${key} ${entry.outputs?.[0]?.sha256.slice(0, 12)}`);
16212
+ }
16213
+ for (const { key, reason } of result.skipped) log(` skipped ${key}: ${reason}`);
16214
+ log(`
16215
+ ${result.imported.length} ${args.dryRun ? "to import" : "imported"}, ${result.skipped.length} skipped (offline; no provider contacted)`);
16216
+ }
16003
16217
  async function runAdopt(args) {
16218
+ if (args.local) return runAdoptLocal(args);
16004
16219
  const { loaded, specs, lock, accountProvider } = await openAccountProject(args);
16005
16220
  const providerFor = providerCache("online");
16006
16221
  const provider = providerFor(accountProvider);
@@ -16112,7 +16327,7 @@ async function runSalvage2(args) {
16112
16327
  const lockPaths = [
16113
16328
  .../* @__PURE__ */ new Set([
16114
16329
  ...workspaceLockPaths,
16115
- ...existsSync18(ownLock) ? [ownLock] : [],
16330
+ ...existsSync20(ownLock) ? [ownLock] : [],
16116
16331
  ...args.claims.map((c) => path25.resolve(c))
16117
16332
  ])
16118
16333
  ];
@@ -16374,13 +16589,13 @@ async function runTag(args) {
16374
16589
  import path28 from "path";
16375
16590
 
16376
16591
  // src/pipeline/hand-edit.ts
16377
- import { existsSync as existsSync19 } from "fs";
16378
- import { copyFile, mkdir as mkdir11, readFile as readFile18, rename as rename8, rm as rm8, writeFile as writeFile13 } from "fs/promises";
16592
+ import { existsSync as existsSync21 } from "fs";
16593
+ import { copyFile, mkdir as mkdir11, readFile as readFile19, rename as rename8, rm as rm8, writeFile as writeFile13 } from "fs/promises";
16379
16594
  import path27 from "path";
16380
16595
  import { z as z7 } from "zod";
16381
16596
 
16382
16597
  // src/manifest-edit.ts
16383
- import { readFile as readFile17, rename as rename7, rm as rm7, writeFile as writeFile12 } from "fs/promises";
16598
+ import { readFile as readFile18, rename as rename7, rm as rm7, writeFile as writeFile12 } from "fs/promises";
16384
16599
  import path26 from "path";
16385
16600
  import { z as z6 } from "zod";
16386
16601
  var HexSha = z6.string().regex(/^[0-9a-f]{64}$/);
@@ -16805,7 +17020,7 @@ function applyEdit(raw, edit) {
16805
17020
  }
16806
17021
  async function withCandidate(manifestPath, edit, use, unchanged) {
16807
17022
  const absolute = path26.resolve(manifestPath);
16808
- const original = await readFile17(absolute, "utf8");
17023
+ const original = await readFile18(absolute, "utf8");
16809
17024
  if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
16810
17025
  let raw;
16811
17026
  try {
@@ -16910,10 +17125,10 @@ function handEditBases(spec, lock) {
16910
17125
  }));
16911
17126
  if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
16912
17127
  if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
16913
- if (!members.every((member) => existsSync19(member.path))) return null;
17128
+ if (!members.every((member) => existsSync21(member.path))) return null;
16914
17129
  return members.map(({ role, path: file }) => ({ role, path: file }));
16915
17130
  }
16916
- return existsSync19(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
17131
+ return existsSync21(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
16917
17132
  }
16918
17133
  function handEditMembers(loaded, spec, lock, editPath) {
16919
17134
  const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
@@ -16944,7 +17159,7 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
16944
17159
  const members = handEditMembers(loaded, spec, lock, editPath);
16945
17160
  let created = false;
16946
17161
  for (const member of members) {
16947
- if (existsSync19(member.path)) continue;
17162
+ if (existsSync21(member.path)) continue;
16948
17163
  if (!member.base) {
16949
17164
  throw new ManifestEditError(
16950
17165
  `${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
@@ -17029,7 +17244,7 @@ function handEditProjectPath(editPath) {
17029
17244
  async function readHandEditCompanion(editPath) {
17030
17245
  let text;
17031
17246
  try {
17032
- text = await readFile18(handEditCompanionPath(editPath), "utf8");
17247
+ text = await readFile19(handEditCompanionPath(editPath), "utf8");
17033
17248
  } catch {
17034
17249
  return null;
17035
17250
  }
@@ -17072,7 +17287,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
17072
17287
  }
17073
17288
  });
17074
17289
  const bases = handEditBases(spec, lock);
17075
- const expectedSize = bases?.[0] ? decodePng(await readFile18(bases[0].path)) : { width: spec.width, height: spec.height };
17290
+ const expectedSize = bases?.[0] ? decodePng(await readFile19(bases[0].path)) : { width: spec.width, height: spec.height };
17076
17291
  for (const [index, image] of decoded.entries()) {
17077
17292
  if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
17078
17293
  const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
@@ -17159,21 +17374,21 @@ async function runEdit(args) {
17159
17374
 
17160
17375
  // src/cli/commands/gallery.ts
17161
17376
  import path38 from "path";
17162
- import { existsSync as existsSync29 } from "fs";
17377
+ import { existsSync as existsSync31 } from "fs";
17163
17378
 
17164
17379
  // src/gallery/snapshot.ts
17165
17380
  import { createHash as createHash4 } from "crypto";
17166
- import { existsSync as existsSync24 } from "fs";
17167
- import { readFile as readFile22, stat as stat2 } from "fs/promises";
17381
+ import { existsSync as existsSync26 } from "fs";
17382
+ import { readFile as readFile23, stat as stat2 } from "fs/promises";
17168
17383
  import path34 from "path";
17169
17384
 
17170
17385
  // src/gallery/edit.ts
17171
- import { readFile as readFile21, rename as rename9, writeFile as writeFile17 } from "fs/promises";
17386
+ import { readFile as readFile22, rename as rename9, writeFile as writeFile17 } from "fs/promises";
17172
17387
  import path32 from "path";
17173
17388
  import { z as z11 } from "zod";
17174
17389
 
17175
17390
  // src/gallery/upload.ts
17176
- import { existsSync as existsSync20 } from "fs";
17391
+ import { existsSync as existsSync22 } from "fs";
17177
17392
  import { mkdir as mkdir12, writeFile as writeFile14 } from "fs/promises";
17178
17393
  import path29 from "path";
17179
17394
  import { z as z8 } from "zod";
@@ -17205,7 +17420,7 @@ async function saveProjectImage(root, request) {
17205
17420
  if (metadata.format !== expected) {
17206
17421
  throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
17207
17422
  }
17208
- if (existsSync20(file) && !request.overwrite) {
17423
+ if (existsSync22(file) && !request.overwrite) {
17209
17424
  throw new ManifestEditError(`${relative.split(path29.sep).join("/")} already exists; choose another name, or replace it`);
17210
17425
  }
17211
17426
  await mkdir12(path29.dirname(file), { recursive: true });
@@ -17214,8 +17429,8 @@ async function saveProjectImage(root, request) {
17214
17429
  }
17215
17430
 
17216
17431
  // src/gallery/image-revision.ts
17217
- import { existsSync as existsSync21 } from "fs";
17218
- import { readFile as readFile19, rm as rm9, writeFile as writeFile15 } from "fs/promises";
17432
+ import { existsSync as existsSync23 } from "fs";
17433
+ import { readFile as readFile20, rm as rm9, writeFile as writeFile15 } from "fs/promises";
17219
17434
  import path30 from "path";
17220
17435
  import { z as z9 } from "zod";
17221
17436
  var InpaintRevisionRequestSchema = z9.object({
@@ -17243,7 +17458,7 @@ async function createInpaintRevision(manifestPath, request) {
17243
17458
  const metadata = imageMetadata(bytes);
17244
17459
  if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
17245
17460
  const file = path30.resolve(root, request.maskPath);
17246
- const previous = existsSync21(file) ? await readFile19(file) : null;
17461
+ const previous = existsSync23(file) ? await readFile20(file) : null;
17247
17462
  const mask = await saveProjectImage(root, {
17248
17463
  action: "upload-image",
17249
17464
  path: request.maskPath,
@@ -17270,8 +17485,8 @@ async function createInpaintRevision(manifestPath, request) {
17270
17485
  }
17271
17486
 
17272
17487
  // src/gallery/skeleton.ts
17273
- import { existsSync as existsSync22 } from "fs";
17274
- import { mkdir as mkdir13, readFile as readFile20, rm as rm10, writeFile as writeFile16 } from "fs/promises";
17488
+ import { existsSync as existsSync24 } from "fs";
17489
+ import { mkdir as mkdir13, readFile as readFile21, rm as rm10, writeFile as writeFile16 } from "fs/promises";
17275
17490
  import path31 from "path";
17276
17491
  import { z as z10 } from "zod";
17277
17492
  var SkeletonEstimateRequestSchema = z10.object({
@@ -17313,7 +17528,7 @@ var SkeletonKeypointsUpdateSchema = z10.object({
17313
17528
  var DEFAULT_ESTIMATE_LIMIT = 10;
17314
17529
  function skeletonSourceFile(spec) {
17315
17530
  if (spec.source) return path31.resolve(spec.root, spec.source);
17316
- if (spec.quality && existsSync22(spec.quality.outFile)) return spec.quality.outFile;
17531
+ if (spec.quality && existsSync24(spec.quality.outFile)) return spec.quality.outFile;
17317
17532
  return spec.outFile;
17318
17533
  }
17319
17534
  function createGallerySkeletonHandlers(opts) {
@@ -17334,8 +17549,8 @@ function createGallerySkeletonHandlers(opts) {
17334
17549
  const spec = ctx.specs.find((candidate) => lockKey(candidate.styleId, candidate.assetId) === key);
17335
17550
  if (!spec) throw new ManifestEditError(`"${key}" is not declared by the manifest`);
17336
17551
  const file = skeletonSourceFile(spec);
17337
- if (!existsSync22(file)) throw new ManifestEditError(`${key} has no image on disk to estimate from`);
17338
- const bytes = await readFile20(file);
17552
+ if (!existsSync24(file)) throw new ManifestEditError(`${key} has no image on disk to estimate from`);
17553
+ const bytes = await readFile21(file);
17339
17554
  const metadata = imageMetadata(bytes);
17340
17555
  if (!metadata) throw new ManifestEditError(`${path31.basename(file)} is not a readable PNG or JPEG`);
17341
17556
  const problem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
@@ -17374,13 +17589,13 @@ async function createSkeletonAnimation(manifestPath, request) {
17374
17589
  if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path31.isAbsolute(relative)) {
17375
17590
  throw new ManifestEditError("the keypoints file must be a .json path inside the project");
17376
17591
  }
17377
- const existed = existsSync22(file);
17592
+ const existed = existsSync24(file);
17378
17593
  let previous = null;
17379
17594
  if (request.set) {
17380
17595
  if (existed && !request.overwrite) {
17381
17596
  throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
17382
17597
  }
17383
- if (existed) previous = await readFile20(file);
17598
+ if (existed) previous = await readFile21(file);
17384
17599
  await mkdir13(path31.dirname(file), { recursive: true });
17385
17600
  await writeFile16(file, JSON.stringify(request.set, null, 2) + "\n");
17386
17601
  } else if (!existed) {
@@ -17422,7 +17637,7 @@ async function updateSkeletonKeypoints(ctx, request) {
17422
17637
  if (relative.startsWith("..") || path31.isAbsolute(relative)) {
17423
17638
  throw new ManifestEditError(`${key}'s keypoints file is outside the project; edit it by hand`);
17424
17639
  }
17425
- const current = existsSync22(file) ? sha256(await readFile20(file)) : null;
17640
+ const current = existsSync24(file) ? sha256(await readFile21(file)) : null;
17426
17641
  if (current !== request.expectedSha256) {
17427
17642
  throw Object.assign(
17428
17643
  new Error(`${relative.split(path31.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
@@ -17494,7 +17709,7 @@ function createGalleryEditHandler(opts) {
17494
17709
  if (undo.success) {
17495
17710
  const manifestPath2 = await manifestOf(undo.data.project);
17496
17711
  if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
17497
- const current = await readFile21(manifestPath2, "utf8");
17712
+ const current = await readFile22(manifestPath2, "utf8");
17498
17713
  if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
17499
17714
  const stack = history.get(manifestPath2) ?? [];
17500
17715
  const last = stack[stack.length - 1];
@@ -17511,10 +17726,10 @@ function createGalleryEditHandler(opts) {
17511
17726
  return opts.reload();
17512
17727
  }
17513
17728
  const manifestPath = await manifestOf(body?.project);
17514
- const before = manifestPath ? await readFile21(manifestPath, "utf8").catch(() => null) : null;
17729
+ const before = manifestPath ? await readFile22(manifestPath, "utf8").catch(() => null) : null;
17515
17730
  const build = await apply(body);
17516
17731
  if (manifestPath && before !== null) {
17517
- const after = await readFile21(manifestPath, "utf8").catch(() => null);
17732
+ const after = await readFile22(manifestPath, "utf8").catch(() => null);
17518
17733
  if (after !== null && after !== before) {
17519
17734
  const stack = history.get(manifestPath) ?? [];
17520
17735
  stack.push({ before, afterSha: sha256(after) });
@@ -17687,7 +17902,7 @@ function createGalleryPriceHandler(opts) {
17687
17902
  }
17688
17903
 
17689
17904
  // src/pipeline/history.ts
17690
- import { existsSync as existsSync23 } from "fs";
17905
+ import { existsSync as existsSync25 } from "fs";
17691
17906
  import path33 from "path";
17692
17907
  var HISTORY_ENV = "PIXELKILN_HISTORY";
17693
17908
  function historyLimit(manifest, env = process.env) {
@@ -17778,7 +17993,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
17778
17993
  }
17779
17994
  for (let i = 0; i < entry.outputs.length; i++) {
17780
17995
  const file = currentEntryOutputPath(entry, spec, i);
17781
- if (!existsSync23(file)) continue;
17996
+ if (!existsSync25(file)) continue;
17782
17997
  if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
17783
17998
  throw new OverwriteRefusedError(
17784
17999
  `${path33.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
@@ -17868,7 +18083,7 @@ function describeHistory(media, entry, cacheDir) {
17868
18083
  const mediaType = output.mediaType ?? MediaType.PNG;
17869
18084
  const file = path34.join(cacheDir, cacheFileName(output.sha256, mediaType));
17870
18085
  let url = null;
17871
- if (existsSync24(file)) {
18086
+ if (existsSync26(file)) {
17872
18087
  const id = galleryMediaId(file);
17873
18088
  media.set(id, { path: file, contentType: mediaType });
17874
18089
  url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
@@ -17900,7 +18115,7 @@ function describeHistory(media, entry, cacheDir) {
17900
18115
  var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
17901
18116
  async function samePixels(a, b) {
17902
18117
  try {
17903
- const [left, right] = await Promise.all([readFile22(a), readFile22(b)]);
18118
+ const [left, right] = await Promise.all([readFile23(a), readFile23(b)]);
17904
18119
  if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
17905
18120
  const x = decodePng(left);
17906
18121
  const y = decodePng(right);
@@ -18001,7 +18216,7 @@ async function describeQuality(media, root, inspection) {
18001
18216
  outputPaths.map((file) => describeOutput(media, root, path34.resolve(root, file)))
18002
18217
  );
18003
18218
  const recordPath = path34.resolve(root, inspection.record);
18004
- const recordExists = existsSync24(recordPath);
18219
+ const recordExists = existsSync26(recordPath);
18005
18220
  let options = null;
18006
18221
  let check = null;
18007
18222
  if (recordExists) {
@@ -18058,7 +18273,7 @@ async function buildGallerySnapshot(opts) {
18058
18273
  const media = /* @__PURE__ */ new Map();
18059
18274
  const plan = await buildPlan(specs, lock);
18060
18275
  const items = [];
18061
- const manifestText = await readFile22(loaded.path, "utf8");
18276
+ const manifestText = await readFile23(loaded.path, "utf8");
18062
18277
  const manifestSha256 = sha256(manifestText);
18063
18278
  const cacheDir = path34.resolve(path34.dirname(opts.lockPath), ".pixelkiln", "cache");
18064
18279
  let rawStyles = {};
@@ -18089,7 +18304,7 @@ async function buildGallerySnapshot(opts) {
18089
18304
  const editShas = await Promise.all(
18090
18305
  Array.from({ length: memberCount }, async (_, index) => {
18091
18306
  const file = sourceOutputPath(spec.source, entry, index, root);
18092
- return { file, sha256: existsSync24(file) ? await sha256File(file) : null };
18307
+ return { file, sha256: existsSync26(file) ? await sha256File(file) : null };
18093
18308
  })
18094
18309
  );
18095
18310
  edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
@@ -18097,7 +18312,7 @@ async function buildGallerySnapshot(opts) {
18097
18312
  const companion = await readHandEditCompanion(editPath);
18098
18313
  if (companion) {
18099
18314
  const projectPath = handEditProjectPath(editPath);
18100
- const project = companion.project && existsSync24(projectPath) ? await fileInfo(projectPath) : null;
18315
+ const project = companion.project && existsSync26(projectPath) ? await fileInfo(projectPath) : null;
18101
18316
  let projectUrl = null;
18102
18317
  if (project) {
18103
18318
  const id = galleryMediaId(projectPath);
@@ -18134,7 +18349,7 @@ async function buildGallerySnapshot(opts) {
18134
18349
  }
18135
18350
  } else if (spec.source) {
18136
18351
  outputs = [await describeOutput(media, root, path34.resolve(root, spec.source))];
18137
- } else if (!entry && existsSync24(spec.outFile)) {
18352
+ } else if (!entry && existsSync26(spec.outFile)) {
18138
18353
  outputs = [await describeOutput(media, root, spec.outFile)];
18139
18354
  } else {
18140
18355
  outputs = [];
@@ -18411,7 +18626,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
18411
18626
  root: loaded.root,
18412
18627
  provider: loaded.manifest.provider,
18413
18628
  account: project.account ?? null,
18414
- manifestSha256: manifestSha256 ?? sha256(await readFile22(manifestPath, "utf8")),
18629
+ manifestSha256: manifestSha256 ?? sha256(await readFile23(manifestPath, "utf8")),
18415
18630
  historyLimit: historyLimit(loaded.manifest),
18416
18631
  entries: Object.keys(lock.entries).length,
18417
18632
  items: projectItems.length,
@@ -18470,10 +18685,10 @@ async function buildWorkspaceGallerySnapshot(opts) {
18470
18685
  // src/gallery/server.ts
18471
18686
  import { randomBytes } from "crypto";
18472
18687
  import { createServer as createServer2 } from "http";
18473
- import { readFile as readFile23 } from "fs/promises";
18688
+ import { readFile as readFile24 } from "fs/promises";
18474
18689
 
18475
18690
  // src/gallery/page.ts
18476
- import { existsSync as existsSync25, readFileSync as readFileSync5 } from "fs";
18691
+ import { existsSync as existsSync27, readFileSync as readFileSync6 } from "fs";
18477
18692
 
18478
18693
  // src/gallery/client-bundle.ts
18479
18694
  import { createRequire } from "module";
@@ -18513,8 +18728,8 @@ var client;
18513
18728
  function clientAssets() {
18514
18729
  const prebuilt = new URL("gallery.js", CLIENT_DIR);
18515
18730
  client ??= {
18516
- css: readFileSync5(new URL("gallery.css", CLIENT_DIR), "utf8"),
18517
- js: existsSync25(prebuilt) ? readFileSync5(prebuilt, "utf8") : bundleGalleryClient()
18731
+ css: readFileSync6(new URL("gallery.css", CLIENT_DIR), "utf8"),
18732
+ js: existsSync27(prebuilt) ? readFileSync6(prebuilt, "utf8") : bundleGalleryClient()
18518
18733
  };
18519
18734
  return client;
18520
18735
  }
@@ -18785,7 +19000,7 @@ async function serveGallery(opts) {
18785
19000
  const asset = reviewAssets.get(jobId)?.get(url2.pathname);
18786
19001
  if (!asset) return fail(404, "no such review asset");
18787
19002
  try {
18788
- const bytes = await readFile23(asset.path);
19003
+ const bytes = await readFile24(asset.path);
18789
19004
  res.writeHead(200, {
18790
19005
  "Content-Type": asset.contentType,
18791
19006
  "Cache-Control": "no-store",
@@ -18868,7 +19083,7 @@ async function serveGallery(opts) {
18868
19083
  if (!asset) return fail(404, "no such gallery media");
18869
19084
  let bytes;
18870
19085
  try {
18871
- bytes = await readFile23(asset.path);
19086
+ bytes = await readFile24(asset.path);
18872
19087
  } catch {
18873
19088
  return fail(404, "gallery media is no longer on disk; refresh the page");
18874
19089
  }
@@ -19361,12 +19576,12 @@ function ownedReferenceImageId(spec, lock, providerId) {
19361
19576
  }
19362
19577
 
19363
19578
  // src/pick/server.ts
19364
- import { existsSync as existsSync27 } from "fs";
19365
- import { readFile as readFile25 } from "fs/promises";
19579
+ import { existsSync as existsSync29 } from "fs";
19580
+ import { readFile as readFile26 } from "fs/promises";
19366
19581
 
19367
19582
  // src/pipeline/init.ts
19368
- import { readdir, readFile as readFile24, writeFile as writeFile18 } from "fs/promises";
19369
- import { existsSync as existsSync26 } from "fs";
19583
+ import { readdir, readFile as readFile25, writeFile as writeFile18 } from "fs/promises";
19584
+ import { existsSync as existsSync28 } from "fs";
19370
19585
  import path35 from "path";
19371
19586
  function pngSize(buf) {
19372
19587
  if (buf.length < 24) return null;
@@ -19395,7 +19610,7 @@ async function scanAssets(root, opts = {}) {
19395
19610
  const skipped = [];
19396
19611
  const seen = /* @__PURE__ */ new Map();
19397
19612
  for (const file of files.sort()) {
19398
- const size = pngSize(await readFile24(file));
19613
+ const size = pngSize(await readFile25(file));
19399
19614
  if (!size) {
19400
19615
  skipped.push(`${file} (not a readable PNG)`);
19401
19616
  continue;
@@ -19460,7 +19675,7 @@ function mode(values) {
19460
19675
  return [...counts.entries()].sort((a, b) => b[1] - a[1])[0]?.[0] ?? 64;
19461
19676
  }
19462
19677
  async function writeManifestFile(target, manifest) {
19463
- if (existsSync26(target)) {
19678
+ if (existsSync28(target)) {
19464
19679
  throw new Error(`${target} already exists; refusing to overwrite an existing manifest.`);
19465
19680
  }
19466
19681
  await writeFile18(target, JSON.stringify(manifest, null, 2) + "\n");
@@ -19886,13 +20101,13 @@ async function currentArt(entry, spec) {
19886
20101
  const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
19887
20102
  if (!previous) return null;
19888
20103
  const file = resolveOutputPath(previous.path, spec.root);
19889
- if (!existsSync27(file)) return null;
20104
+ if (!existsSync29(file)) return null;
19890
20105
  const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
19891
20106
  if (!contentType) return null;
19892
20107
  let width = entry.width;
19893
20108
  let height = entry.height;
19894
20109
  if (contentType === "image/png") {
19895
- const size = pngSize(await readFile25(file));
20110
+ const size = pngSize(await readFile26(file));
19896
20111
  if (size) ({ width, height } = size);
19897
20112
  }
19898
20113
  return { path: file, contentType, width, height };
@@ -19900,7 +20115,7 @@ async function currentArt(entry, spec) {
19900
20115
  async function cachedFrame(url) {
19901
20116
  if (!url.startsWith("file://")) return null;
19902
20117
  const file = url.slice("file://".length);
19903
- const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await readFile25(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
20118
+ const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await readFile26(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
19904
20119
  return { path: file, contentType };
19905
20120
  }
19906
20121
  async function prepareReview(provider, lock, opts = {}) {
@@ -19926,15 +20141,15 @@ async function prepareReview(provider, lock, opts = {}) {
19926
20141
  const frameAssets = [];
19927
20142
  const frameSizes = [];
19928
20143
  for (const [index, url] of urls.entries()) {
19929
- const cached = await cachedFrame(url);
19930
- if (!cached) {
20144
+ const cached2 = await cachedFrame(url);
20145
+ if (!cached2) {
19931
20146
  frameUrls.push(url);
19932
20147
  frameSizes.push(null);
19933
20148
  continue;
19934
20149
  }
19935
- frameSizes.push(cached.contentType === "image/png" ? pngSize(await readFile25(cached.path).catch(() => Buffer.alloc(0))) : null);
20150
+ frameSizes.push(cached2.contentType === "image/png" ? pngSize(await readFile26(cached2.path).catch(() => Buffer.alloc(0))) : null);
19936
20151
  const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
19937
- frameAssets.push([route, cached]);
20152
+ frameAssets.push([route, cached2]);
19938
20153
  frameUrls.push(route);
19939
20154
  }
19940
20155
  const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String(groups.length))}` : null;
@@ -20450,13 +20665,13 @@ function createGenerateHandlers(opts) {
20450
20665
  }
20451
20666
 
20452
20667
  // src/gallery/editor.ts
20453
- import { readFile as readFile27 } from "fs/promises";
20668
+ import { readFile as readFile28 } from "fs/promises";
20454
20669
  import path37 from "path";
20455
20670
 
20456
20671
  // src/editor/install.ts
20457
20672
  import { createHash as createHash5 } from "crypto";
20458
- import { existsSync as existsSync28 } from "fs";
20459
- import { mkdir as mkdir14, readFile as readFile26, rename as rename10, rm as rm11, stat as stat3, writeFile as writeFile19 } from "fs/promises";
20673
+ import { existsSync as existsSync30 } from "fs";
20674
+ import { mkdir as mkdir14, readFile as readFile27, rename as rename10, rm as rm11, stat as stat3, writeFile as writeFile19 } from "fs/promises";
20460
20675
  import os3 from "os";
20461
20676
  import path36 from "path";
20462
20677
 
@@ -20540,7 +20755,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
20540
20755
  }
20541
20756
  async function sha256Of(file) {
20542
20757
  try {
20543
- return createHash5("sha256").update(await readFile26(file)).digest("hex");
20758
+ return createHash5("sha256").update(await readFile27(file)).digest("hex");
20544
20759
  } catch {
20545
20760
  return null;
20546
20761
  }
@@ -20554,7 +20769,7 @@ async function editorStatus(opts = {}) {
20554
20769
  for (const [name, expected] of Object.entries(pin.files)) {
20555
20770
  totalBytes += expected.bytes;
20556
20771
  const file = path36.join(dir, name);
20557
- const info = existsSync28(file) ? await stat3(file).catch(() => null) : null;
20772
+ const info = existsSync30(file) ? await stat3(file).catch(() => null) : null;
20558
20773
  if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
20559
20774
  installedBytes += expected.bytes;
20560
20775
  } else {
@@ -20733,7 +20948,7 @@ function createGalleryEditorHandlers(opts = {}) {
20733
20948
  if (!status.installed) return null;
20734
20949
  let bytes;
20735
20950
  try {
20736
- bytes = await readFile27(path37.join(dir, name));
20951
+ bytes = await readFile28(path37.join(dir, name));
20737
20952
  } catch {
20738
20953
  verified = null;
20739
20954
  return null;
@@ -20842,7 +21057,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
20842
21057
  async function runGallery(args) {
20843
21058
  if (args.workspace) {
20844
21059
  const workspacePath = path38.resolve(args.workspace);
20845
- if (!existsSync29(workspacePath)) {
21060
+ if (!existsSync31(workspacePath)) {
20846
21061
  throw new Error(`Workspace catalog not found: ${workspacePath}`);
20847
21062
  }
20848
21063
  const filter2 = { styles: args.styles, assets: args.assets };
@@ -21196,14 +21411,14 @@ async function runRestoreGeneration(args) {
21196
21411
  }
21197
21412
 
21198
21413
  // src/cli/commands/housekeeping.ts
21199
- import { existsSync as existsSync31 } from "fs";
21414
+ import { existsSync as existsSync33 } from "fs";
21200
21415
 
21201
21416
  // src/pipeline/cache-health.ts
21202
- import { existsSync as existsSync30 } from "fs";
21203
- import { readFile as readFile28, readdir as readdir2, rm as rm12 } from "fs/promises";
21417
+ import { existsSync as existsSync32 } from "fs";
21418
+ import { readFile as readFile29, readdir as readdir2, rm as rm12 } from "fs/promises";
21204
21419
  import path39 from "path";
21205
21420
  async function inspectCaches(lock, lockPath, options = {}) {
21206
- if (options.prune && !existsSync30(lockPath)) {
21421
+ if (options.prune && !existsSync32(lockPath)) {
21207
21422
  throw new Error(`Refusing to prune without an existing lockfile at ${path39.resolve(lockPath)}`);
21208
21423
  }
21209
21424
  const contentDir = path39.resolve(path39.dirname(lockPath), ".pixelkiln", "cache");
@@ -21228,7 +21443,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
21228
21443
  await saveCache(remotePath, { version: 1, hashes: {} });
21229
21444
  removed.resetRemoteHashCache = true;
21230
21445
  } else if (remoteHashes.invalidIds.length) {
21231
- const cache = parseCache(JSON.parse(await readFile28(remotePath, "utf8")));
21446
+ const cache = parseCache(JSON.parse(await readFile29(remotePath, "utf8")));
21232
21447
  for (const id of remoteHashes.invalidIds) delete cache.hashes[id];
21233
21448
  removed.remoteHashEntries = remoteHashes.invalidIds.length;
21234
21449
  await saveCache(remotePath, cache);
@@ -21246,7 +21461,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
21246
21461
  async function inspectContentCache(contentDir, referenced) {
21247
21462
  const report = {
21248
21463
  path: contentDir,
21249
- exists: existsSync30(contentDir),
21464
+ exists: existsSync32(contentDir),
21250
21465
  files: 0,
21251
21466
  bytes: 0,
21252
21467
  valid: 0,
@@ -21272,7 +21487,7 @@ async function inspectContentCache(contentDir, referenced) {
21272
21487
  const expected = mediaType ? entry.name.slice(0, -4) : "";
21273
21488
  let bytes;
21274
21489
  try {
21275
- bytes = await readFile28(file);
21490
+ bytes = await readFile29(file);
21276
21491
  report.bytes += bytes.length;
21277
21492
  } catch (err) {
21278
21493
  report.invalid.push({
@@ -21310,7 +21525,7 @@ async function inspectContentCache(contentDir, referenced) {
21310
21525
  async function inspectRemoteHashCache(remotePath) {
21311
21526
  const report = {
21312
21527
  path: remotePath,
21313
- exists: existsSync30(remotePath),
21528
+ exists: existsSync32(remotePath),
21314
21529
  entries: 0,
21315
21530
  valid: 0,
21316
21531
  invalidIds: [],
@@ -21319,7 +21534,7 @@ async function inspectRemoteHashCache(remotePath) {
21319
21534
  if (!report.exists) return report;
21320
21535
  let cache;
21321
21536
  try {
21322
- cache = parseCache(JSON.parse(await readFile28(remotePath, "utf8")));
21537
+ cache = parseCache(JSON.parse(await readFile29(remotePath, "utf8")));
21323
21538
  } catch (err) {
21324
21539
  report.error = err instanceof Error ? err.message : String(err);
21325
21540
  return report;
@@ -21383,7 +21598,7 @@ async function runAccept(args) {
21383
21598
  let intact = true;
21384
21599
  for (const output of entry.outputs) {
21385
21600
  const file = resolveOutputPath(output.path, item.spec.root);
21386
- if (!existsSync31(file) || await sha256File(file) !== output.sha256) {
21601
+ if (!existsSync33(file) || await sha256File(file) !== output.sha256) {
21387
21602
  intact = false;
21388
21603
  break;
21389
21604
  }
@@ -21439,11 +21654,11 @@ This drops their provenance from the lockfile. The art on disk is`);
21439
21654
 
21440
21655
  // src/cli/commands/init.ts
21441
21656
  import path40 from "path";
21442
- import { existsSync as existsSync32 } from "fs";
21657
+ import { existsSync as existsSync34 } from "fs";
21443
21658
  async function runInit(args) {
21444
21659
  if (!args.from) throw new Error("init needs --from <dir> pointing at your existing PNGs.");
21445
21660
  const root = path40.resolve(args.from);
21446
- if (!existsSync32(root)) throw new Error(`No directory at ${root}`);
21661
+ if (!existsSync34(root)) throw new Error(`No directory at ${root}`);
21447
21662
  const generator = args.generator ?? "map";
21448
21663
  if (generator !== "1dir" && generator !== "map") {
21449
21664
  throw new Error(`--generator must be "1dir" or "map", got "${args.generator}".`);
@@ -21471,7 +21686,7 @@ async function runInit(args) {
21471
21686
  }
21472
21687
 
21473
21688
  // src/pipeline/doctor.ts
21474
- import { constants, existsSync as existsSync33 } from "fs";
21689
+ import { constants, existsSync as existsSync35 } from "fs";
21475
21690
  import { access, stat as stat4 } from "fs/promises";
21476
21691
  import path41 from "path";
21477
21692
  async function doctor(loaded, specs, lock, lockPath, opts = {}) {
@@ -21539,11 +21754,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
21539
21754
  const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
21540
21755
  let hasCache = false;
21541
21756
  for (const output of entry.outputs) {
21542
- const cached = path41.join(
21757
+ const cached2 = path41.join(
21543
21758
  cacheDir,
21544
21759
  cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
21545
21760
  );
21546
- if (existsSync33(cached) && await sha256File(cached) === output.sha256) {
21761
+ if (existsSync35(cached2) && await sha256File(cached2) === output.sha256) {
21547
21762
  hasCache = true;
21548
21763
  break;
21549
21764
  }
@@ -21646,8 +21861,8 @@ async function nearestExistingDirectory(start) {
21646
21861
  }
21647
21862
 
21648
21863
  // src/pipeline/audit.ts
21649
- import { readFile as readFile29 } from "fs/promises";
21650
- import { existsSync as existsSync34 } from "fs";
21864
+ import { readFile as readFile30 } from "fs/promises";
21865
+ import { existsSync as existsSync36 } from "fs";
21651
21866
  import path42 from "path";
21652
21867
  function paletteDistance(asset, reference) {
21653
21868
  if (!asset.length || !reference.length) return 0;
@@ -21684,12 +21899,12 @@ async function auditStyle(loaded, specs, styleId, lock) {
21684
21899
  const unreadable = [];
21685
21900
  for (const spec of mine) {
21686
21901
  for (const output of resolveSpecOutputs(spec, lock, loaded.root)) {
21687
- if (!existsSync34(output.absolutePath)) {
21902
+ if (!existsSync36(output.absolutePath)) {
21688
21903
  missing.push(output.id);
21689
21904
  continue;
21690
21905
  }
21691
21906
  try {
21692
- const png = decodePng(await readFile29(output.absolutePath));
21907
+ const png = decodePng(await readFile30(output.absolutePath));
21693
21908
  const palette = extractPalette(png, 12);
21694
21909
  assets.push({
21695
21910
  assetId: spec.assetId,
@@ -21714,9 +21929,9 @@ async function auditStyle(loaded, specs, styleId, lock) {
21714
21929
  const refPalettes = [];
21715
21930
  for (const img of style.styleImages) {
21716
21931
  const abs = path42.resolve(loaded.root, img.path);
21717
- if (!existsSync34(abs)) continue;
21932
+ if (!existsSync36(abs)) continue;
21718
21933
  try {
21719
- refPalettes.push(extractPalette(decodePng(await readFile29(abs)), 12));
21934
+ refPalettes.push(extractPalette(decodePng(await readFile30(abs)), 12));
21720
21935
  } catch {
21721
21936
  }
21722
21937
  }
@@ -21942,13 +22157,33 @@ async function runAudit(args) {
21942
22157
  }
21943
22158
  if (args.check && reports.some((report) => !report.evaluation.safe)) process.exitCode = 1;
21944
22159
  }
22160
+ async function runHash(args) {
22161
+ const { specs, lock } = await openProject2(args);
22162
+ if (!args.assets.length && !args.styles.length && !args.all) {
22163
+ throw new UsageError("hash needs --only <asset>, --style <style>, or --all.");
22164
+ }
22165
+ const reports = await reportSpecHashes(specs, lock);
22166
+ if (args.json) {
22167
+ log(JSON.stringify({ items: reports }, null, 2));
22168
+ return;
22169
+ }
22170
+ for (const report of reports) {
22171
+ const state = !report.lock ? "no lock entry" : report.lock.matches ? "lock matches" : "lock differs";
22172
+ log(` ${report.key}`);
22173
+ log(` spec hash ${report.specHash}`);
22174
+ log(` file hash ${report.fileSha256 ?? "(no file)"}`);
22175
+ log(` ${state}`);
22176
+ }
22177
+ log(`
22178
+ \`pixelkiln adopt --local\` writes the entry above for files with no lock entry.`);
22179
+ }
21945
22180
 
21946
22181
  // src/cli/commands/pack.ts
21947
22182
  import path44 from "path";
21948
- import { readFile as readFile30 } from "fs/promises";
22183
+ import { readFile as readFile31 } from "fs/promises";
21949
22184
 
21950
22185
  // src/pipeline/pack.ts
21951
- import { readFileSync as readFileSync6 } from "fs";
22186
+ import { readFileSync as readFileSync7 } from "fs";
21952
22187
  import path43 from "path";
21953
22188
  var DEFAULT_FRAME_SET_FPS = 12;
21954
22189
  function resolvePackInputs(raw, inputsFilePath) {
@@ -21982,7 +22217,7 @@ function packSprites(inputs, options = {}) {
21982
22217
  for (const input of ordered) {
21983
22218
  let sourceHash = null;
21984
22219
  try {
21985
- const bytes = readFileSync6(input.path);
22220
+ const bytes = readFileSync7(input.path);
21986
22221
  sourceHash = sha256(bytes);
21987
22222
  const png = decodePng(bytes);
21988
22223
  sprites.push({ id: input.id, width: png.width, height: png.height, pixels: png.pixels });
@@ -22141,7 +22376,7 @@ function mountSprites(placements, options) {
22141
22376
  for (const p of placements) {
22142
22377
  let sourceHash = null;
22143
22378
  try {
22144
- const bytes = readFileSync6(p.path);
22379
+ const bytes = readFileSync7(p.path);
22145
22380
  sourceHash = sha256(bytes);
22146
22381
  const png = decodePng(bytes);
22147
22382
  if (png.width > cellWidth || png.height > cellHeight) {
@@ -22245,7 +22480,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
22245
22480
  `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}`
22246
22481
  );
22247
22482
  }
22248
- const basePng = mount.base ? readFileSync6(path43.resolve(manifestDir, mount.base)) : void 0;
22483
+ const basePng = mount.base ? readFileSync7(path43.resolve(manifestDir, mount.base)) : void 0;
22249
22484
  const mounted = mountSprites(placements, {
22250
22485
  cellWidth: mount.cellWidth,
22251
22486
  cellHeight: mount.cellHeight,
@@ -22659,7 +22894,7 @@ async function runPack(args) {
22659
22894
  if (args.primaryOnly || args.outputRoles.length) {
22660
22895
  throw new Error("--primary-only and --output-role require manifest-driven pack");
22661
22896
  }
22662
- const raw = JSON.parse(await readFile30(path44.resolve(args.inputs), "utf8"));
22897
+ const raw = JSON.parse(await readFile31(path44.resolve(args.inputs), "utf8"));
22663
22898
  const inputs = resolvePackInputs(raw, args.inputs);
22664
22899
  const { png, atlas, skipped, sources } = packSprites(inputs, { columns: args.columns });
22665
22900
  const format = sheetFormat(args);
@@ -22884,7 +23119,7 @@ function sheetFormat(args) {
22884
23119
  }
22885
23120
 
22886
23121
  // src/cli/commands/pixellab-utils.ts
22887
- import { readFile as readFile31 } from "fs/promises";
23122
+ import { readFile as readFile32 } from "fs/promises";
22888
23123
  import path45 from "path";
22889
23124
  function loadKeys(args) {
22890
23125
  loadEnvFiles(path45.dirname(path45.resolve(args.manifest)));
@@ -23102,7 +23337,7 @@ async function runVfxArtist(args, out) {
23102
23337
  }
23103
23338
  if (args.name && args.name.length > 80) throw new UsageError("vfx --description takes a --name of at most 80 characters");
23104
23339
  const paths = vfxOutputPaths(out);
23105
- const side = args.sprite ? vfxArtistSprite(await readFile31(args.sprite), args.sprite).side : "none";
23340
+ const side = args.sprite ? vfxArtistSprite(await readFile32(args.sprite), args.sprite).side : "none";
23106
23341
  const conversation = args.effect ? await readVfxConversation(paths.provenance, args.effect) : void 0;
23107
23342
  const quote = vfxArtistQuote(artist, args.effect && !args.sprite ? "unknown" : side, Boolean(conversation));
23108
23343
  const ceiling = vfxArtistCeiling(quote);
@@ -23160,12 +23395,12 @@ async function runVfxArtist(args, out) {
23160
23395
 
23161
23396
  // src/cli/commands/quality.ts
23162
23397
  import path47 from "path";
23163
- import { readFile as readFile33 } from "fs/promises";
23398
+ import { readFile as readFile34 } from "fs/promises";
23164
23399
 
23165
23400
  // src/pipeline/quality-regression.ts
23166
23401
  import path46 from "path";
23167
- import { existsSync as existsSync35 } from "fs";
23168
- import { readFile as readFile32 } from "fs/promises";
23402
+ import { existsSync as existsSync37 } from "fs";
23403
+ import { readFile as readFile33 } from "fs/promises";
23169
23404
  import { z as z13 } from "zod";
23170
23405
  var SHA256_RE = /^[0-9a-f]{64}$/;
23171
23406
  var HEX_RE = /^#[0-9a-f]{6}$/;
@@ -23321,7 +23556,7 @@ async function measureImageQuality(file) {
23321
23556
  const absolute = path46.resolve(file);
23322
23557
  let bytes;
23323
23558
  try {
23324
- bytes = await readFile32(absolute);
23559
+ bytes = await readFile33(absolute);
23325
23560
  } catch (error) {
23326
23561
  throw new Error(`Cannot read quality image ${absolute}: ${message4(error)}`, { cause: error });
23327
23562
  }
@@ -23407,8 +23642,8 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
23407
23642
  cases
23408
23643
  });
23409
23644
  const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
23410
- if (existsSync35(absolute) && !options.force) {
23411
- const current = await readFile32(absolute);
23645
+ if (existsSync37(absolute) && !options.force) {
23646
+ const current = await readFile33(absolute);
23412
23647
  if (!current.equals(data)) {
23413
23648
  throw new OverwriteRefusedError(
23414
23649
  `Quality baseline already exists with different content: ${absolute}. Pass --force to replace it.`,
@@ -23419,19 +23654,90 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
23419
23654
  const result = await writeArtifactBundle([{ path: absolute, data }]);
23420
23655
  return { baseline, path: absolute, changed: result.changed.length > 0 };
23421
23656
  }
23657
+ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
23658
+ const absolute = path46.resolve(baselinePath);
23659
+ if (!existsSync37(absolute)) {
23660
+ throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
23661
+ }
23662
+ let raw;
23663
+ try {
23664
+ raw = JSON.parse(await readFile33(absolute, "utf8"));
23665
+ } catch (error) {
23666
+ throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
23667
+ }
23668
+ if (!Array.isArray(raw.cases)) throw new Error(`Quality baseline ${absolute} has no cases array.`);
23669
+ const byId = new Map(inputs.map((input) => [input.id, input]));
23670
+ const unknown = only.filter((id) => !byId.has(id));
23671
+ if (unknown.length) {
23672
+ throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
23673
+ }
23674
+ const root = path46.dirname(absolute);
23675
+ const cases = [...raw.cases];
23676
+ const report = [];
23677
+ for (const id of only) {
23678
+ const input = byId.get(id);
23679
+ if (path46.resolve(input.file) === absolute || input.record && path46.resolve(input.record) === absolute) {
23680
+ throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
23681
+ }
23682
+ const expected = await measureImageQuality(input.file);
23683
+ let record;
23684
+ if (input.record) {
23685
+ await verifyRecordForImage(input.record, input.file);
23686
+ record = { path: portableRelative2(root, input.record), sha256: await sha256File(input.record) };
23687
+ }
23688
+ const index = cases.findIndex((entry) => entry.id === id);
23689
+ const before = index >= 0 ? cases[index].expected ?? {} : {};
23690
+ const next = {
23691
+ id,
23692
+ file: portableRelative2(root, input.file),
23693
+ ...record ? { record } : {},
23694
+ expected,
23695
+ tolerances: index >= 0 && cases[index].tolerances ? cases[index].tolerances : input.tolerances
23696
+ };
23697
+ if (index >= 0) cases[index] = next;
23698
+ else cases.push(next);
23699
+ const changes = [];
23700
+ for (const metric of Object.keys(expected)) {
23701
+ if (JSON.stringify(before[metric]) !== JSON.stringify(expected[metric])) {
23702
+ changes.push({ metric, before: before[metric] ?? null, after: expected[metric] });
23703
+ }
23704
+ }
23705
+ report.push({ id, kind: index < 0 ? "added" : changes.length ? "updated" : "unchanged", changes });
23706
+ }
23707
+ const baseline = QualityBaselineSchema.parse({ ...raw, cases });
23708
+ const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
23709
+ const current = await readFile33(absolute);
23710
+ const changed = !current.equals(data);
23711
+ if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
23712
+ return { baseline, path: absolute, changed, cases: report };
23713
+ }
23422
23714
  async function readQualityBaseline(baselinePath) {
23423
23715
  const absolute = path46.resolve(baselinePath);
23424
23716
  let raw;
23425
23717
  try {
23426
- raw = JSON.parse(await readFile32(absolute, "utf8"));
23718
+ raw = JSON.parse(await readFile33(absolute, "utf8"));
23427
23719
  } catch (error) {
23428
23720
  throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
23429
23721
  }
23430
23722
  const parsed = QualityBaselineSchema.safeParse(raw);
23431
23723
  if (!parsed.success) {
23724
+ const cases = raw?.cases;
23725
+ const where = (issuePath) => {
23726
+ if (issuePath[0] === "cases" && typeof issuePath[1] === "number") {
23727
+ const id = cases?.[issuePath[1]]?.id;
23728
+ const rest = issuePath.slice(2).join(".");
23729
+ return typeof id === "string" ? `cases[${id}]${rest ? `.${rest}` : ""}` : issuePath.join(".");
23730
+ }
23731
+ return issuePath.join(".") || "$";
23732
+ };
23733
+ const missing = [...new Set(parsed.error.issues.flatMap((issue) => {
23734
+ const id = issue.path[0] === "cases" && typeof issue.path[1] === "number" ? cases?.[issue.path[1]]?.id : void 0;
23735
+ return issue.code === "invalid_type" && issue.received === "undefined" && typeof id === "string" ? [id] : [];
23736
+ }))];
23432
23737
  throw new Error(
23433
23738
  `Invalid quality baseline ${absolute}:
23434
- ` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
23739
+ ` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
23740
+ Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path46.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
23435
23741
  );
23436
23742
  }
23437
23743
  return parsed.data;
@@ -23553,7 +23859,7 @@ async function runQuality(args) {
23553
23859
  if (!args.out) throw new Error("quality snapshot needs --out <pixelkiln.quality.json>.");
23554
23860
  let raw;
23555
23861
  try {
23556
- raw = JSON.parse(await readFile33(path47.resolve(args.inputs), "utf8"));
23862
+ raw = JSON.parse(await readFile34(path47.resolve(args.inputs), "utf8"));
23557
23863
  } catch (error) {
23558
23864
  throw new Error(
23559
23865
  `Could not read quality inputs ${path47.resolve(args.inputs)}: ${error instanceof Error ? error.message : String(error)}`,
@@ -23564,6 +23870,23 @@ async function runQuality(args) {
23564
23870
  if (path47.resolve(args.inputs) === path47.resolve(args.out)) {
23565
23871
  throw new Error("quality snapshot --out must not overwrite its --inputs file.");
23566
23872
  }
23873
+ if (args.assets.length) {
23874
+ const result2 = await snapshotQualityCases(inputs, args.out, args.assets, { dryRun: args.dryRun });
23875
+ if (args.json) {
23876
+ log(JSON.stringify({ version: 1, path: result2.path, changed: result2.changed, dryRun: args.dryRun, cases: result2.cases }, null, 2));
23877
+ return;
23878
+ }
23879
+ for (const entry of result2.cases ?? []) {
23880
+ log(` ${entry.kind === "unchanged" ? "unchanged" : args.dryRun ? `would ${entry.kind === "added" ? "add" : "update"}` : entry.kind} ${entry.id}`);
23881
+ for (const c of entry.changes) log(` ${c.metric}: ${JSON.stringify(c.before)} -> ${JSON.stringify(c.after)}`);
23882
+ }
23883
+ log(
23884
+ `
23885
+ ${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${path47.relative(process.cwd(), result2.path)}; other cases left as they were.`
23886
+ );
23887
+ return;
23888
+ }
23889
+ if (args.dryRun) throw new Error("quality snapshot --dry-run applies to a partial re-snapshot; add --only <id,...>.");
23567
23890
  const result = await snapshotQualityBaseline(inputs, args.out, { force: args.force });
23568
23891
  if (args.json) {
23569
23892
  log(JSON.stringify({
@@ -23604,8 +23927,8 @@ import path49 from "path";
23604
23927
 
23605
23928
  // src/recipes.ts
23606
23929
  import path48 from "path";
23607
- import { existsSync as existsSync36 } from "fs";
23608
- import { readdir as readdir3, readFile as readFile34 } from "fs/promises";
23930
+ import { existsSync as existsSync38 } from "fs";
23931
+ import { readdir as readdir3, readFile as readFile35 } from "fs/promises";
23609
23932
  import { fileURLToPath as fileURLToPath2 } from "url";
23610
23933
  import { z as z14 } from "zod";
23611
23934
  var SHA256_RE2 = /^[0-9a-f]{64}$/;
@@ -23793,7 +24116,7 @@ async function readRecipeFile(recipePath, bundled) {
23793
24116
  const absolute = path48.resolve(recipePath);
23794
24117
  let raw;
23795
24118
  try {
23796
- raw = JSON.parse(await readFile34(absolute, "utf8"));
24119
+ raw = JSON.parse(await readFile35(absolute, "utf8"));
23797
24120
  } catch (error) {
23798
24121
  throw new Error(`Could not read recipe ${absolute}: ${message5(error)}`, { cause: error });
23799
24122
  }
@@ -23807,7 +24130,7 @@ async function readRecipeFile(recipePath, bundled) {
23807
24130
  return { recipe: parsed.data, authored: raw, path: absolute, dir: path48.dirname(absolute), bundled };
23808
24131
  }
23809
24132
  async function walkRecipeFiles(root) {
23810
- if (!existsSync36(root)) return [];
24133
+ if (!existsSync38(root)) return [];
23811
24134
  const out = [];
23812
24135
  for (const entry of await readdir3(root, { withFileTypes: true })) {
23813
24136
  const resolved = path48.join(root, entry.name);
@@ -23845,7 +24168,7 @@ function parseSelector(selector) {
23845
24168
  }
23846
24169
  async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
23847
24170
  const local = path48.resolve(target);
23848
- if (existsSync36(local)) {
24171
+ if (existsSync38(local)) {
23849
24172
  const recipePath = path48.basename(local) === RECIPE_FILE ? local : path48.join(local, RECIPE_FILE);
23850
24173
  return readRecipeFile(recipePath, false);
23851
24174
  }
@@ -23861,7 +24184,7 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
23861
24184
  }
23862
24185
  async function verifyFile(root, file) {
23863
24186
  const absolute = path48.resolve(root, ...file.path.split("/"));
23864
- if (!existsSync36(absolute)) {
24187
+ if (!existsSync38(absolute)) {
23865
24188
  return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
23866
24189
  }
23867
24190
  const actualSha256 = await sha256File(absolute);
@@ -23935,12 +24258,12 @@ async function installRecipe(target, options = {}) {
23935
24258
  ];
23936
24259
  const files = await Promise.all(sources.map(async (file) => ({
23937
24260
  path: path48.join(destination, ...file.path.split("/")),
23938
- data: await readFile34(file.source)
24261
+ data: await readFile35(file.source)
23939
24262
  })));
23940
24263
  if (!options.force) {
23941
24264
  for (const file of files) {
23942
- if (!existsSync36(file.path)) continue;
23943
- const current = await readFile34(file.path);
24265
+ if (!existsSync38(file.path)) continue;
24266
+ const current = await readFile35(file.path);
23944
24267
  if (!current.equals(file.data)) {
23945
24268
  throw new OverwriteRefusedError(
23946
24269
  `Recipe destination has local changes: ${file.path}. Choose another --out or pass --force to replace declared recipe files.`,
@@ -24179,8 +24502,8 @@ async function runRefine(args) {
24179
24502
 
24180
24503
  // src/cli/commands/skeleton.ts
24181
24504
  import path51 from "path";
24182
- import { existsSync as existsSync37 } from "fs";
24183
- import { readFile as readFile35, writeFile as writeFile20 } from "fs/promises";
24505
+ import { existsSync as existsSync39 } from "fs";
24506
+ import { readFile as readFile36, writeFile as writeFile20 } from "fs/promises";
24184
24507
 
24185
24508
  // src/skeleton-preview.ts
24186
24509
  var RIGHT = [255, 140, 40, 255];
@@ -24291,12 +24614,12 @@ var Canvas = class {
24291
24614
  async function runEstimateSkeleton(args) {
24292
24615
  const image = args.target;
24293
24616
  if (!image) throw new UsageError("estimate-skeleton needs an image path: pixelkiln estimate-skeleton <image> [--out keypoints.json]");
24294
- if (args.out && existsSync37(path51.resolve(args.out)) && !args.force) {
24617
+ if (args.out && existsSync39(path51.resolve(args.out)) && !args.force) {
24295
24618
  throw new UsageError(`${args.out} already exists; pass --force to replace it`);
24296
24619
  }
24297
24620
  loadEnvFiles(path51.dirname(path51.resolve(args.manifest)));
24298
24621
  loadEnvFiles(process.cwd());
24299
- const bytes = await readFile35(path51.resolve(image));
24622
+ const bytes = await readFile36(path51.resolve(image));
24300
24623
  const metadata = imageMetadata(bytes);
24301
24624
  if (!metadata) throw new UsageError(`${image} is not a readable PNG or JPEG`);
24302
24625
  const sizeProblem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
@@ -24337,20 +24660,20 @@ async function runSkeletonPreview(args) {
24337
24660
  sourceFile = args.from ? path51.resolve(args.from) : spec.revision.sourceFile;
24338
24661
  label = `${spec.styleId}/${spec.assetId}`;
24339
24662
  }
24340
- if (!existsSync37(keypointsFile)) throw new UsageError(`Keypoints file does not exist yet: ${keypointsFile}`);
24663
+ if (!existsSync39(keypointsFile)) throw new UsageError(`Keypoints file does not exist yet: ${keypointsFile}`);
24341
24664
  let json;
24342
24665
  try {
24343
- json = JSON.parse(await readFile35(keypointsFile, "utf8"));
24666
+ json = JSON.parse(await readFile36(keypointsFile, "utf8"));
24344
24667
  } catch (error) {
24345
24668
  throw new UsageError(`${keypointsFile} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
24346
24669
  }
24347
24670
  const set = parseSkeletonSet(json, keypointsFile);
24348
24671
  let source;
24349
24672
  if (sourceFile) {
24350
- if (!existsSync37(sourceFile)) {
24673
+ if (!existsSync39(sourceFile)) {
24351
24674
  log(` source image does not exist yet, drawing on a plain ground: ${sourceFile}`);
24352
24675
  } else {
24353
- const bytes = await readFile35(sourceFile);
24676
+ const bytes = await readFile36(sourceFile);
24354
24677
  if (imageMetadata(bytes)?.format !== "png") throw new UsageError(`${sourceFile} must be a PNG to preview over`);
24355
24678
  source = decodePng(bytes);
24356
24679
  }
@@ -24405,7 +24728,7 @@ async function runTools(args) {
24405
24728
 
24406
24729
  // src/cli/commands/workspace.ts
24407
24730
  import path52 from "path";
24408
- import { existsSync as existsSync38 } from "fs";
24731
+ import { existsSync as existsSync40 } from "fs";
24409
24732
  async function runWorkspace(args) {
24410
24733
  const workspacePath = path52.resolve(args.workspace ?? "pixelkiln.workspace.json");
24411
24734
  const dir = path52.dirname(workspacePath);
@@ -24435,7 +24758,7 @@ async function runWorkspace(args) {
24435
24758
  log(` registered "${id}" in ${path52.relative(process.cwd(), workspacePath)}`);
24436
24759
  log(` manifest: ${project.manifest}`);
24437
24760
  log(` lock: ${project.lock}`);
24438
- if (!existsSync38(lockPath)) {
24761
+ if (!existsSync40(lockPath)) {
24439
24762
  log(
24440
24763
  ` warning: no lockfile there yet; this project contributes no claims until one is generated`
24441
24764
  );
@@ -24459,7 +24782,7 @@ async function runWorkspace(args) {
24459
24782
  return;
24460
24783
  }
24461
24784
  if (args.subcommand === "list") {
24462
- if (!existsSync38(workspacePath)) {
24785
+ if (!existsSync40(workspacePath)) {
24463
24786
  throw new Error(`Workspace catalog not found: ${workspacePath}`);
24464
24787
  }
24465
24788
  const ws = await loadWorkspace(workspacePath);
@@ -24479,7 +24802,7 @@ async function runWorkspace(args) {
24479
24802
  return;
24480
24803
  }
24481
24804
  if (args.subcommand === "status") {
24482
- if (!existsSync38(workspacePath)) {
24805
+ if (!existsSync40(workspacePath)) {
24483
24806
  throw new Error(`Workspace catalog not found: ${workspacePath}`);
24484
24807
  }
24485
24808
  const ws = await loadWorkspace(workspacePath);
@@ -24541,8 +24864,8 @@ async function runHelp() {
24541
24864
  async function runVersion() {
24542
24865
  for (const up of ["../package.json", "../../package.json"]) {
24543
24866
  const url = new URL(up, import.meta.url);
24544
- if (!existsSync39(url)) continue;
24545
- const pkg = JSON.parse(await readFile36(url, "utf8"));
24867
+ if (!existsSync41(url)) continue;
24868
+ const pkg = JSON.parse(await readFile37(url, "utf8"));
24546
24869
  if (pkg.name === "pixelkiln") {
24547
24870
  log(`${pkg.name} ${pkg.version}`);
24548
24871
  return;
@@ -24558,6 +24881,7 @@ var RUNNERS = {
24558
24881
  "-v": runVersion,
24559
24882
  init: runInit,
24560
24883
  plan: runPlan,
24884
+ hash: runHash,
24561
24885
  doctor: runDoctor,
24562
24886
  gen: runGenerate,
24563
24887
  submit: runGenerate,