pixelkiln 0.92.3 → 0.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +844 -340
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +722 -312
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +199 -24
- package/dist/index.d.ts +199 -24
- package/dist/index.js +689 -283
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +68 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1580,7 +1580,17 @@ var LockEntrySchema = z.object({
|
|
|
1580
1580
|
/** Generations this entry replaced, newest first; see LockHistoryEntrySchema. */
|
|
1581
1581
|
history: z.array(LockHistoryEntrySchema).optional(),
|
|
1582
1582
|
/** Post-processing applied to the recorded outputs; absent when the bytes are the provider's. */
|
|
1583
|
-
postprocess: PostprocessSchema.optional()
|
|
1583
|
+
postprocess: PostprocessSchema.optional(),
|
|
1584
|
+
/**
|
|
1585
|
+
* Set when the entry records art made outside pixelkiln (the PixelLab MCP, a
|
|
1586
|
+
* hand edit, another tool) and brought in with `adopt --local`: nothing was
|
|
1587
|
+
* submitted, so jobId and cost are empty. Absent on generated entries.
|
|
1588
|
+
*/
|
|
1589
|
+
imported: z.object({
|
|
1590
|
+
source: z.string().min(1),
|
|
1591
|
+
note: z.string().optional(),
|
|
1592
|
+
importedAt: z.string()
|
|
1593
|
+
}).strict().optional()
|
|
1584
1594
|
});
|
|
1585
1595
|
var LockSchema = z.object({
|
|
1586
1596
|
version: z.literal(2),
|
|
@@ -2129,9 +2139,9 @@ var PixelLabClient = class {
|
|
|
2129
2139
|
apiKey;
|
|
2130
2140
|
http;
|
|
2131
2141
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
2132
|
-
async request(
|
|
2142
|
+
async request(path40, init) {
|
|
2133
2143
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
2134
|
-
const res = await this.http(`${BASE}${
|
|
2144
|
+
const res = await this.http(`${BASE}${path40}`, {
|
|
2135
2145
|
...init,
|
|
2136
2146
|
headers: {
|
|
2137
2147
|
Authorization: auth,
|
|
@@ -2142,13 +2152,13 @@ var PixelLabClient = class {
|
|
|
2142
2152
|
const text = await res.text();
|
|
2143
2153
|
if (!res.ok) {
|
|
2144
2154
|
const hint = res.status === 500 && text.includes("Failed to start any animation jobs") ? '; a skeleton-v3 loop needs a character with a stored 3D skeleton (a v3 base), use mode: "template" on a standard one' : "";
|
|
2145
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
2155
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path40} \u2192 ${res.status}${hint}`, res.status, text);
|
|
2146
2156
|
}
|
|
2147
2157
|
if (!text) return {};
|
|
2148
2158
|
try {
|
|
2149
2159
|
return JSON.parse(text);
|
|
2150
2160
|
} catch {
|
|
2151
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
2161
|
+
throw new Error(`${init?.method ?? "GET"} ${path40} returned invalid JSON`);
|
|
2152
2162
|
}
|
|
2153
2163
|
}
|
|
2154
2164
|
async balance() {
|
|
@@ -2601,10 +2611,10 @@ var PixelLabClient = class {
|
|
|
2601
2611
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
2602
2612
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
2603
2613
|
const south = args.reference?.south;
|
|
2604
|
-
let
|
|
2614
|
+
let path40;
|
|
2605
2615
|
let body;
|
|
2606
2616
|
if (args.mode === "v3") {
|
|
2607
|
-
|
|
2617
|
+
path40 = "/create-character-v3";
|
|
2608
2618
|
body = {
|
|
2609
2619
|
description: args.description,
|
|
2610
2620
|
image_size: imageSize,
|
|
@@ -2618,7 +2628,7 @@ var PixelLabClient = class {
|
|
|
2618
2628
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
2619
2629
|
};
|
|
2620
2630
|
} else if (args.mode === "pro-flash") {
|
|
2621
|
-
|
|
2631
|
+
path40 = "/create-character-pro-flash";
|
|
2622
2632
|
const traits = args.styleTraits;
|
|
2623
2633
|
body = {
|
|
2624
2634
|
description: args.description,
|
|
@@ -2642,7 +2652,7 @@ var PixelLabClient = class {
|
|
|
2642
2652
|
} : {}
|
|
2643
2653
|
};
|
|
2644
2654
|
} else if (args.mode === "pro") {
|
|
2645
|
-
|
|
2655
|
+
path40 = "/create-character-pro";
|
|
2646
2656
|
body = {
|
|
2647
2657
|
description: args.description,
|
|
2648
2658
|
image_size: imageSize,
|
|
@@ -2656,7 +2666,7 @@ var PixelLabClient = class {
|
|
|
2656
2666
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
2657
2667
|
};
|
|
2658
2668
|
} else {
|
|
2659
|
-
|
|
2669
|
+
path40 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
2660
2670
|
body = {
|
|
2661
2671
|
description: args.description,
|
|
2662
2672
|
image_size: imageSize,
|
|
@@ -2674,8 +2684,8 @@ var PixelLabClient = class {
|
|
|
2674
2684
|
};
|
|
2675
2685
|
}
|
|
2676
2686
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
2677
|
-
const raw = await this.request(
|
|
2678
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
2687
|
+
const raw = await this.request(path40, { method: "POST", body: JSON.stringify(body) });
|
|
2688
|
+
return validateResponse(CharacterSubmitSchema, raw, path40.slice(1));
|
|
2679
2689
|
}
|
|
2680
2690
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
2681
2691
|
async createCharacterState(args) {
|
|
@@ -4012,10 +4022,10 @@ import { createReadStream } from "fs";
|
|
|
4012
4022
|
function sha256(data) {
|
|
4013
4023
|
return createHash("sha256").update(data).digest("hex");
|
|
4014
4024
|
}
|
|
4015
|
-
async function sha256File(
|
|
4025
|
+
async function sha256File(path40) {
|
|
4016
4026
|
return new Promise((resolve, reject) => {
|
|
4017
4027
|
const hash = createHash("sha256");
|
|
4018
|
-
const stream = createReadStream(
|
|
4028
|
+
const stream = createReadStream(path40);
|
|
4019
4029
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
4020
4030
|
stream.on("error", reject);
|
|
4021
4031
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -6990,13 +7000,13 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
6990
7000
|
async pollVfx(jobId, context) {
|
|
6991
7001
|
const dir = _PixelLabProvider.cacheDir("vfx");
|
|
6992
7002
|
const sidecar = path3.join(dir, `${jobId}.json`);
|
|
6993
|
-
const
|
|
7003
|
+
const cached2 = () => {
|
|
6994
7004
|
if (!existsSync3(sidecar)) return null;
|
|
6995
7005
|
const facts2 = JSON.parse(readFileSync(sidecar, "utf8"));
|
|
6996
7006
|
const files2 = Array.from({ length: facts2.count }, (_, index) => path3.join(dir, `${jobId}-${index}.png`));
|
|
6997
7007
|
return files2.every((file) => existsSync3(file)) ? { facts: facts2, files: files2 } : null;
|
|
6998
7008
|
};
|
|
6999
|
-
let found =
|
|
7009
|
+
let found = cached2();
|
|
7000
7010
|
const recorded = context?.metadata?.vfx;
|
|
7001
7011
|
let artistDone;
|
|
7002
7012
|
if (!found && recorded?.artist) {
|
|
@@ -7016,11 +7026,11 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
7016
7026
|
}
|
|
7017
7027
|
artistDone.billed = billedFromUsage(job.usage);
|
|
7018
7028
|
}
|
|
7019
|
-
found =
|
|
7029
|
+
found = cached2();
|
|
7020
7030
|
} else if (!found && recorded?.downloadBase && Array.isArray(recorded.files)) {
|
|
7021
7031
|
const exported = recorded;
|
|
7022
7032
|
await this.cacheVfxFrames(jobId, exported, workbenchVfxUrls(exported));
|
|
7023
|
-
found =
|
|
7033
|
+
found = cached2();
|
|
7024
7034
|
}
|
|
7025
7035
|
if (!found) {
|
|
7026
7036
|
return {
|
|
@@ -7834,9 +7844,9 @@ var RetroDiffusionClient = class {
|
|
|
7834
7844
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
7835
7845
|
return Buffer.from(await response.arrayBuffer());
|
|
7836
7846
|
}
|
|
7837
|
-
async call(
|
|
7847
|
+
async call(path40, init = {}) {
|
|
7838
7848
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
7839
|
-
const response = await this.request(`${this.baseUrl}${
|
|
7849
|
+
const response = await this.request(`${this.baseUrl}${path40}`, {
|
|
7840
7850
|
...init,
|
|
7841
7851
|
headers: {
|
|
7842
7852
|
"Content-Type": "application/json",
|
|
@@ -8218,8 +8228,8 @@ var ScenarioClient = class {
|
|
|
8218
8228
|
async uploadImage(image, projectId) {
|
|
8219
8229
|
const bytes = Buffer.from(image.base64, "base64");
|
|
8220
8230
|
const digest2 = sha256(bytes);
|
|
8221
|
-
const
|
|
8222
|
-
if (
|
|
8231
|
+
const cached2 = readUploadCache()[uploadCacheKey(this.baseUrl, projectId, digest2)];
|
|
8232
|
+
if (cached2) return cached2;
|
|
8223
8233
|
const response = await this.call(
|
|
8224
8234
|
"/assets",
|
|
8225
8235
|
{
|
|
@@ -9909,7 +9919,7 @@ registerProvider({
|
|
|
9909
9919
|
|
|
9910
9920
|
// src/manifest.ts
|
|
9911
9921
|
import { readFile as readFile5 } from "fs/promises";
|
|
9912
|
-
import { existsSync as
|
|
9922
|
+
import { existsSync as existsSync7 } from "fs";
|
|
9913
9923
|
import path8 from "path";
|
|
9914
9924
|
|
|
9915
9925
|
// src/loop-directions.ts
|
|
@@ -10324,15 +10334,93 @@ function frameSetLoop(entry) {
|
|
|
10324
10334
|
return typeof loop === "boolean" ? loop : null;
|
|
10325
10335
|
}
|
|
10326
10336
|
|
|
10337
|
+
// src/version.ts
|
|
10338
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "fs";
|
|
10339
|
+
var cached;
|
|
10340
|
+
function pixelkilnVersion() {
|
|
10341
|
+
if (cached !== void 0) return cached;
|
|
10342
|
+
cached = null;
|
|
10343
|
+
for (const up of ["../package.json", "../../package.json"]) {
|
|
10344
|
+
const url = new URL(up, import.meta.url);
|
|
10345
|
+
if (!existsSync6(url)) continue;
|
|
10346
|
+
try {
|
|
10347
|
+
const pkg = JSON.parse(readFileSync3(url, "utf8"));
|
|
10348
|
+
if (pkg.name === "pixelkiln" && pkg.version) {
|
|
10349
|
+
cached = pkg.version;
|
|
10350
|
+
break;
|
|
10351
|
+
}
|
|
10352
|
+
} catch {
|
|
10353
|
+
}
|
|
10354
|
+
}
|
|
10355
|
+
return cached;
|
|
10356
|
+
}
|
|
10357
|
+
|
|
10327
10358
|
// src/manifest.ts
|
|
10328
|
-
async function loadManifest(manifestPath) {
|
|
10359
|
+
async function loadManifest(manifestPath, opts = {}) {
|
|
10329
10360
|
const abs = path8.resolve(manifestPath);
|
|
10330
|
-
if (!
|
|
10361
|
+
if (!existsSync7(abs)) throw new ProjectError(`No manifest at ${abs}`);
|
|
10331
10362
|
const expansion = expandLoopDirections(JSON.parse(await readFile5(abs, "utf8")));
|
|
10332
10363
|
if (expansion.issues.length) {
|
|
10333
10364
|
throw new ProjectError(`Manifest at ${abs} is invalid:
|
|
10334
10365
|
${expansion.issues.map((i) => ` ${i}`).join("\n")}`);
|
|
10335
10366
|
}
|
|
10367
|
+
if (!opts.lenient) return loadExpanded(abs, expansion);
|
|
10368
|
+
const invalid = [];
|
|
10369
|
+
const raw = pruneInvalidEntries(expansion.raw, invalid);
|
|
10370
|
+
for (let round2 = 0; ; round2++) {
|
|
10371
|
+
try {
|
|
10372
|
+
const loaded = await loadExpanded(abs, { ...expansion, raw });
|
|
10373
|
+
return invalid.length ? { ...loaded, invalid } : loaded;
|
|
10374
|
+
} catch (error) {
|
|
10375
|
+
const culprits = round2 < 50 && error instanceof ProjectError ? culpritEntries(error.message) : [];
|
|
10376
|
+
const fresh = culprits.filter((entry) => dropEntry(raw, entry));
|
|
10377
|
+
if (!fresh.length) throw error;
|
|
10378
|
+
invalid.push(...fresh);
|
|
10379
|
+
}
|
|
10380
|
+
}
|
|
10381
|
+
}
|
|
10382
|
+
function entryRecord(raw, kind) {
|
|
10383
|
+
const record = raw?.[kind === "style" ? "styles" : "assets"];
|
|
10384
|
+
return record && typeof record === "object" && !Array.isArray(record) ? record : null;
|
|
10385
|
+
}
|
|
10386
|
+
function dropEntry(raw, entry) {
|
|
10387
|
+
const record = entryRecord(raw, entry.kind);
|
|
10388
|
+
if (!record || !(entry.id in record)) return false;
|
|
10389
|
+
delete record[entry.id];
|
|
10390
|
+
return true;
|
|
10391
|
+
}
|
|
10392
|
+
function pruneInvalidEntries(raw, invalid) {
|
|
10393
|
+
for (const [kind, schema] of [["style", StyleInputSchema], ["asset", AssetSchema]]) {
|
|
10394
|
+
const record = entryRecord(raw, kind);
|
|
10395
|
+
if (!record) continue;
|
|
10396
|
+
for (const [id, value] of Object.entries(record)) {
|
|
10397
|
+
const parsed = schema.safeParse(value);
|
|
10398
|
+
if (parsed.success) continue;
|
|
10399
|
+
const prefix = `${kind === "style" ? "styles" : "assets"}.${id}`;
|
|
10400
|
+
const lines = flattenManifestIssues(parsed.error.issues).lines.map((line) => {
|
|
10401
|
+
const [fieldPath, ...rest] = line.trim().split(": ");
|
|
10402
|
+
return `${prefix}${fieldPath === "(manifest)" || !fieldPath ? "" : `.${fieldPath}`}: ${rest.join(": ")}`;
|
|
10403
|
+
});
|
|
10404
|
+
invalid.push({ kind, id, issues: lines.length ? lines : [`${prefix}: invalid`] });
|
|
10405
|
+
delete record[id];
|
|
10406
|
+
}
|
|
10407
|
+
}
|
|
10408
|
+
return raw;
|
|
10409
|
+
}
|
|
10410
|
+
function culpritEntries(message6) {
|
|
10411
|
+
const found = /* @__PURE__ */ new Map();
|
|
10412
|
+
for (const line of message6.split("\n")) {
|
|
10413
|
+
const match = /^ {2}(assets|styles)\.([^.:\s]+)[.:]/.exec(line);
|
|
10414
|
+
if (!match) continue;
|
|
10415
|
+
const kind = match[1] === "styles" ? "style" : "asset";
|
|
10416
|
+
const key = `${kind}:${match[2]}`;
|
|
10417
|
+
const entry = found.get(key) ?? { kind, id: match[2], issues: [] };
|
|
10418
|
+
entry.issues.push(line.trim());
|
|
10419
|
+
found.set(key, entry);
|
|
10420
|
+
}
|
|
10421
|
+
return [...found.values()];
|
|
10422
|
+
}
|
|
10423
|
+
async function loadExpanded(abs, expansion) {
|
|
10336
10424
|
const input = ManifestInputSchema.safeParse(expansion.raw);
|
|
10337
10425
|
if (!input.success) {
|
|
10338
10426
|
const issues = formatManifestIssues(input.error.issues);
|
|
@@ -10479,19 +10567,45 @@ function dependencyAssetIds(asset, styleAnchors = []) {
|
|
|
10479
10567
|
].filter((id) => Boolean(id))
|
|
10480
10568
|
];
|
|
10481
10569
|
}
|
|
10570
|
+
var MAX_LISTED_MANIFEST_ISSUES = 20;
|
|
10571
|
+
function flattenManifestIssues(issues) {
|
|
10572
|
+
let unknownShape = false;
|
|
10573
|
+
const visit = (list) => list.flatMap((issue) => {
|
|
10574
|
+
if (issue.code === "invalid_union") return visit(issue.unionErrors.flatMap((error) => error.issues));
|
|
10575
|
+
if (issue.code === "unrecognized_keys" || issue.code === "invalid_enum_value") unknownShape = true;
|
|
10576
|
+
return [` ${issue.path.join(".") || "(manifest)"}: ${issue.message}`];
|
|
10577
|
+
});
|
|
10578
|
+
return { lines: [...new Set(visit(issues))], unknownShape };
|
|
10579
|
+
}
|
|
10482
10580
|
function formatManifestIssues(issues) {
|
|
10483
|
-
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10581
|
+
const { lines, unknownShape } = flattenManifestIssues(issues);
|
|
10582
|
+
const entries = [...new Set(
|
|
10583
|
+
lines.flatMap((line) => {
|
|
10584
|
+
const match = /^ {2}((?:assets|styles)\.[^.:\s]+)/.exec(line);
|
|
10585
|
+
return match ? [match[1]] : [];
|
|
10586
|
+
})
|
|
10587
|
+
)];
|
|
10588
|
+
const out = [];
|
|
10589
|
+
const version = pixelkilnVersion();
|
|
10590
|
+
if (unknownShape) {
|
|
10591
|
+
out.push(
|
|
10592
|
+
` 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.`
|
|
10593
|
+
);
|
|
10594
|
+
}
|
|
10595
|
+
if (entries.length) {
|
|
10596
|
+
out.push(` ${entries.length} invalid entr${entries.length === 1 ? "y" : "ies"}: ${entries.slice(0, 10).join(", ")}${entries.length > 10 ? ", \u2026" : ""}`);
|
|
10597
|
+
}
|
|
10598
|
+
out.push(...lines.slice(0, MAX_LISTED_MANIFEST_ISSUES));
|
|
10599
|
+
if (lines.length > MAX_LISTED_MANIFEST_ISSUES) {
|
|
10600
|
+
out.push(` \u2026 and ${lines.length - MAX_LISTED_MANIFEST_ISSUES} more`);
|
|
10601
|
+
}
|
|
10602
|
+
return out.join("\n");
|
|
10489
10603
|
}
|
|
10490
10604
|
function resolveStyleInheritance(styles) {
|
|
10491
10605
|
const resolved = /* @__PURE__ */ new Map();
|
|
10492
10606
|
const visit = (styleId, chain) => {
|
|
10493
|
-
const
|
|
10494
|
-
if (
|
|
10607
|
+
const cached2 = resolved.get(styleId);
|
|
10608
|
+
if (cached2) return cached2;
|
|
10495
10609
|
const cycleStart = chain.indexOf(styleId);
|
|
10496
10610
|
if (cycleStart >= 0) {
|
|
10497
10611
|
throw new Error(
|
|
@@ -10613,7 +10727,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
10613
10727
|
const abs = path8.resolve(root, rel);
|
|
10614
10728
|
let hit = styleImageCache.get(abs);
|
|
10615
10729
|
if (!hit) {
|
|
10616
|
-
if (!
|
|
10730
|
+
if (!existsSync7(abs)) throw new Error(`${what} not found: ${abs}`);
|
|
10617
10731
|
const buf = await readFile5(abs);
|
|
10618
10732
|
const metadata = imageMetadata(buf);
|
|
10619
10733
|
if (!metadata) throw new Error(`${what} is not a readable PNG or JPEG: ${abs}`);
|
|
@@ -10964,7 +11078,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
10964
11078
|
const file = memberPath(anchorSpec.outFile, "south", 0, anchorSpec.character.directions, MediaType.PNG);
|
|
10965
11079
|
resolved.character = {
|
|
10966
11080
|
...resolved.character,
|
|
10967
|
-
styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256:
|
|
11081
|
+
styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: existsSync7(file) ? await sha256File(file) : null }
|
|
10968
11082
|
};
|
|
10969
11083
|
}
|
|
10970
11084
|
const characterParent = asset.state?.of ?? asset.animation?.of ?? asset.portrait?.of;
|
|
@@ -10977,7 +11091,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
10977
11091
|
parentAssetId: characterParent,
|
|
10978
11092
|
parentSpec,
|
|
10979
11093
|
parentFile,
|
|
10980
|
-
parentSha256:
|
|
11094
|
+
parentSha256: existsSync7(parentFile) ? await sha256File(parentFile) : null,
|
|
10981
11095
|
// A state and its animations keep the engine and rotations of the base.
|
|
10982
11096
|
mode: resolved.character.kind === "base" ? resolved.character.mode : parentSpec.character?.mode ?? resolved.character.mode,
|
|
10983
11097
|
directions: resolved.character.kind === "base" ? resolved.character.directions : parentSpec.character?.directions ?? resolved.character.directions
|
|
@@ -11015,7 +11129,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11015
11129
|
parentAssetId: characterParent,
|
|
11016
11130
|
parentSpec,
|
|
11017
11131
|
parentFile,
|
|
11018
|
-
parentSha256:
|
|
11132
|
+
parentSha256: existsSync7(parentFile) ? await sha256File(parentFile) : null,
|
|
11019
11133
|
// A state and its animations keep the base's own rotation count.
|
|
11020
11134
|
directions: resolved.objectPro.kind === "base" ? resolved.objectPro.directions : parentSpec.objectPro.directions
|
|
11021
11135
|
};
|
|
@@ -11219,8 +11333,18 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11219
11333
|
providerOptionIdentity,
|
|
11220
11334
|
providerInputIdentities.get(assetId)
|
|
11221
11335
|
);
|
|
11222
|
-
|
|
11223
|
-
|
|
11336
|
+
let estimate;
|
|
11337
|
+
try {
|
|
11338
|
+
activeProvider.validate?.(resolved, resolvedImages);
|
|
11339
|
+
estimate = validateCostEstimate(activeProvider.id, activeProvider.estimate(resolved));
|
|
11340
|
+
} catch (error) {
|
|
11341
|
+
const message6 = error instanceof Error ? error.message : String(error);
|
|
11342
|
+
if (message6.includes(`assets.${assetId}`)) throw error;
|
|
11343
|
+
throw new Error(
|
|
11344
|
+
`assets.${assetId} (style "${styleId}", ${resolved.width}x${resolved.height}): ${message6}`,
|
|
11345
|
+
{ cause: error }
|
|
11346
|
+
);
|
|
11347
|
+
}
|
|
11224
11348
|
resolved.cost = estimate.amount;
|
|
11225
11349
|
resolved.costUnit = estimate.unit;
|
|
11226
11350
|
resolved.candidates = estimate.candidates;
|
|
@@ -11231,7 +11355,16 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11231
11355
|
if (!emitStyles.has(styleId)) continue;
|
|
11232
11356
|
for (const assetId of Object.keys(manifest.assets)) {
|
|
11233
11357
|
if (!requestedAssetIds.has(assetId) || !styleSpecs.has(assetId)) continue;
|
|
11234
|
-
|
|
11358
|
+
if (!filter?.onInvalid) {
|
|
11359
|
+
specs.push(await finalize(assetId));
|
|
11360
|
+
continue;
|
|
11361
|
+
}
|
|
11362
|
+
try {
|
|
11363
|
+
specs.push(await finalize(assetId));
|
|
11364
|
+
} catch (error) {
|
|
11365
|
+
const message6 = error instanceof Error ? error.message : String(error);
|
|
11366
|
+
filter.onInvalid({ kind: "asset", id: assetId, issues: [message6] });
|
|
11367
|
+
}
|
|
11235
11368
|
}
|
|
11236
11369
|
}
|
|
11237
11370
|
const byOutput = /* @__PURE__ */ new Map();
|
|
@@ -11304,7 +11437,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
11304
11437
|
let recordedSprite;
|
|
11305
11438
|
if (vfx.recipe) {
|
|
11306
11439
|
const file = path8.resolve(root, vfx.recipe);
|
|
11307
|
-
if (!
|
|
11440
|
+
if (!existsSync7(file)) throw new Error(`assets.${assetId}.vfx.recipe: VFX recipe not found: ${file}`);
|
|
11308
11441
|
const read = await readVfxRecipe(file).catch((error) => {
|
|
11309
11442
|
throw new Error(`assets.${assetId}.vfx.recipe: ${error instanceof Error ? error.message : String(error)}`);
|
|
11310
11443
|
});
|
|
@@ -11331,7 +11464,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
11331
11464
|
};
|
|
11332
11465
|
}
|
|
11333
11466
|
async function optionalRevisionImage(file, label, requiredFormat) {
|
|
11334
|
-
if (!
|
|
11467
|
+
if (!existsSync7(file)) return null;
|
|
11335
11468
|
const bytes = await readFile5(file);
|
|
11336
11469
|
const metadata = imageMetadata(bytes);
|
|
11337
11470
|
if (!metadata) throw new Error(`${label} is not a readable PNG or JPEG: ${file}`);
|
|
@@ -11341,7 +11474,7 @@ async function optionalRevisionImage(file, label, requiredFormat) {
|
|
|
11341
11474
|
return { hash: sha256(bytes), ...metadata };
|
|
11342
11475
|
}
|
|
11343
11476
|
async function optionalSkeletonSet(file) {
|
|
11344
|
-
if (!
|
|
11477
|
+
if (!existsSync7(file)) return null;
|
|
11345
11478
|
const bytes = await readFile5(file);
|
|
11346
11479
|
let json;
|
|
11347
11480
|
try {
|
|
@@ -11352,17 +11485,17 @@ async function optionalSkeletonSet(file) {
|
|
|
11352
11485
|
return { hash: sha256(bytes), skeleton: parseSkeletonSet(json, file) };
|
|
11353
11486
|
}
|
|
11354
11487
|
async function revisionSourceMembers(stem, label) {
|
|
11355
|
-
if (
|
|
11488
|
+
if (existsSync7(stem)) return null;
|
|
11356
11489
|
const at = (role) => memberPath(stem, role, 0, 2, MediaType.PNG);
|
|
11357
11490
|
let roles = [];
|
|
11358
11491
|
for (const set of [CHARACTER_DIRECTIONS_8, CHARACTER_DIRECTIONS_4]) {
|
|
11359
|
-
if (set.every((direction) =>
|
|
11492
|
+
if (set.every((direction) => existsSync7(at(direction)))) {
|
|
11360
11493
|
roles = [...set];
|
|
11361
11494
|
break;
|
|
11362
11495
|
}
|
|
11363
11496
|
}
|
|
11364
11497
|
if (!roles.length) {
|
|
11365
|
-
for (let index = 0;
|
|
11498
|
+
for (let index = 0; existsSync7(at(`frame-${String(index).padStart(2, "0")}`)); index++) {
|
|
11366
11499
|
roles.push(`frame-${String(index).padStart(2, "0")}`);
|
|
11367
11500
|
}
|
|
11368
11501
|
}
|
|
@@ -11530,7 +11663,7 @@ function characterDirections(directions) {
|
|
|
11530
11663
|
import path16 from "path";
|
|
11531
11664
|
|
|
11532
11665
|
// src/env.ts
|
|
11533
|
-
import { readFileSync as
|
|
11666
|
+
import { readFileSync as readFileSync4, existsSync as existsSync8 } from "fs";
|
|
11534
11667
|
import path9 from "path";
|
|
11535
11668
|
function loadEnvFiles(dir) {
|
|
11536
11669
|
const loaded = [];
|
|
@@ -11546,9 +11679,9 @@ function envFiles(dir) {
|
|
|
11546
11679
|
const out = [];
|
|
11547
11680
|
for (const name of [".env.local", ".env"]) {
|
|
11548
11681
|
const file = path9.join(dir, name);
|
|
11549
|
-
if (!
|
|
11682
|
+
if (!existsSync8(file)) continue;
|
|
11550
11683
|
try {
|
|
11551
|
-
out.push([file, parseEnv(
|
|
11684
|
+
out.push([file, parseEnv(readFileSync4(file, "utf8"))]);
|
|
11552
11685
|
} catch {
|
|
11553
11686
|
}
|
|
11554
11687
|
}
|
|
@@ -11574,7 +11707,7 @@ function parseEnv(contents) {
|
|
|
11574
11707
|
}
|
|
11575
11708
|
|
|
11576
11709
|
// src/pipeline/plan.ts
|
|
11577
|
-
import { existsSync as
|
|
11710
|
+
import { existsSync as existsSync11 } from "fs";
|
|
11578
11711
|
import path15 from "path";
|
|
11579
11712
|
|
|
11580
11713
|
// src/pipeline/mirror.ts
|
|
@@ -11780,7 +11913,7 @@ async function deriveMirror(spec, lock, lockPath, opts = {}) {
|
|
|
11780
11913
|
}
|
|
11781
11914
|
|
|
11782
11915
|
// src/pipeline/quality-profile.ts
|
|
11783
|
-
import { existsSync as
|
|
11916
|
+
import { existsSync as existsSync9 } from "fs";
|
|
11784
11917
|
import path13 from "path";
|
|
11785
11918
|
|
|
11786
11919
|
// src/pipeline/refine.ts
|
|
@@ -12763,7 +12896,7 @@ async function qualitySource(spec, lock) {
|
|
|
12763
12896
|
return { items: null, reason: "frame-set quality requires ordered downloaded provider outputs" };
|
|
12764
12897
|
}
|
|
12765
12898
|
const source = path13.resolve(spec.root, spec.source);
|
|
12766
|
-
return
|
|
12899
|
+
return existsSync9(source) ? { items: [{ role: "source", path: source }] } : { items: null, reason: `declared source is missing: ${spec.source}` };
|
|
12767
12900
|
}
|
|
12768
12901
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
12769
12902
|
if (!entry) return { items: null, reason: "raw provider output is not in the lockfile" };
|
|
@@ -12792,7 +12925,7 @@ async function qualitySource(spec, lock) {
|
|
|
12792
12925
|
}
|
|
12793
12926
|
if (role) roles.add(role);
|
|
12794
12927
|
const source = currentEntryOutputPath(entry, spec, index);
|
|
12795
|
-
if (!
|
|
12928
|
+
if (!existsSync9(source)) return { items: null, reason: `raw provider output is missing: ${source}` };
|
|
12796
12929
|
if (await sha256File(source) !== output.sha256) {
|
|
12797
12930
|
return { items: null, reason: "raw provider output was modified after download" };
|
|
12798
12931
|
}
|
|
@@ -12811,7 +12944,7 @@ async function inspectQualityProfile(spec, lock) {
|
|
|
12811
12944
|
}
|
|
12812
12945
|
const sourcePaths = source.items.map((item) => item.path);
|
|
12813
12946
|
const expectedOutputs = spec.generator === "frames" ? source.items.map((item, index) => qualityFrameOutputPath(output, item.role, index)) : [output];
|
|
12814
|
-
if (!
|
|
12947
|
+
if (!existsSync9(record)) {
|
|
12815
12948
|
return {
|
|
12816
12949
|
key,
|
|
12817
12950
|
state: "needs-refinement",
|
|
@@ -12992,7 +13125,7 @@ async function requireApprovedQualitySources(specs, lock, assetIds, outputRoles)
|
|
|
12992
13125
|
}
|
|
12993
13126
|
|
|
12994
13127
|
// src/pipeline/revision.ts
|
|
12995
|
-
import { existsSync as
|
|
13128
|
+
import { existsSync as existsSync10 } from "fs";
|
|
12996
13129
|
import path14 from "path";
|
|
12997
13130
|
async function inspectRevisionReadiness(spec, lock) {
|
|
12998
13131
|
if (spec.mirror) return inspectMirror(spec, lock, /* @__PURE__ */ new Set());
|
|
@@ -13014,7 +13147,7 @@ async function inspectStyleAnchor(spec, lock, seen) {
|
|
|
13014
13147
|
const label = `style anchor ${spec.styleId}/${anchor.assetId}`;
|
|
13015
13148
|
const dependency = await inspectParent(anchor.spec, lock, seen);
|
|
13016
13149
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13017
|
-
if (!anchor.sha256 || !
|
|
13150
|
+
if (!anchor.sha256 || !existsSync10(anchor.file)) return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13018
13151
|
if (await sha256File(anchor.file) !== anchor.sha256) {
|
|
13019
13152
|
return { ready: false, reason: `${label} changed after the manifest was resolved` };
|
|
13020
13153
|
}
|
|
@@ -13051,14 +13184,14 @@ async function inspectScene(spec) {
|
|
|
13051
13184
|
const files = [{ label: "scene image", file: scene.file, sha256: scene.sha256 }];
|
|
13052
13185
|
if (scene.placement.type === "mask") files.push({ label: "scene mask", file: scene.placement.file, sha256: scene.placement.sha256 });
|
|
13053
13186
|
for (const { label, file, sha256: sha2562 } of files) {
|
|
13054
|
-
if (!sha2562 || !
|
|
13187
|
+
if (!sha2562 || !existsSync10(file)) return { ready: false, reason: `${label} does not exist yet: ${file}` };
|
|
13055
13188
|
if (await sha256File(file) !== sha2562) return { ready: false, reason: `${label} changed after the manifest was resolved` };
|
|
13056
13189
|
}
|
|
13057
13190
|
return { ready: true, reason: "scene is current" };
|
|
13058
13191
|
}
|
|
13059
13192
|
async function inspectVfxSprite(spec) {
|
|
13060
13193
|
const sprite = spec.vfx.sprite;
|
|
13061
|
-
if (!sprite.sha256 || !
|
|
13194
|
+
if (!sprite.sha256 || !existsSync10(sprite.file)) return { ready: false, reason: `vfx sprite does not exist yet: ${sprite.file}` };
|
|
13062
13195
|
if (await sha256File(sprite.file) !== sprite.sha256) return { ready: false, reason: "vfx sprite changed after the manifest was resolved" };
|
|
13063
13196
|
return { ready: true, reason: "vfx sprite is current" };
|
|
13064
13197
|
}
|
|
@@ -13074,7 +13207,7 @@ async function inspectOutfit(spec, lock, seen) {
|
|
|
13074
13207
|
const label = `outfit source ${spec.styleId}/${character.parentAssetId}`;
|
|
13075
13208
|
const dependency = await inspectParent(character.parentSpec, lock, seen);
|
|
13076
13209
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13077
|
-
if (!
|
|
13210
|
+
if (!existsSync10(outfit.reference.path)) {
|
|
13078
13211
|
return { ready: false, reason: `outfit reference is missing: ${outfit.reference.path}` };
|
|
13079
13212
|
}
|
|
13080
13213
|
if (await sha256File(outfit.reference.path) !== outfit.reference.sha256) {
|
|
@@ -13088,7 +13221,7 @@ async function inspectCharacterParent(spec, lock, seen) {
|
|
|
13088
13221
|
const label = `${character.kind} parent ${spec.styleId}/${character.parentAssetId}`;
|
|
13089
13222
|
const dependency = await inspectParent(parentSpec, lock, seen);
|
|
13090
13223
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13091
|
-
if (!character.parentSha256 || !character.parentFile || !
|
|
13224
|
+
if (!character.parentSha256 || !character.parentFile || !existsSync10(character.parentFile)) {
|
|
13092
13225
|
return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13093
13226
|
}
|
|
13094
13227
|
if (await sha256File(character.parentFile) !== character.parentSha256) {
|
|
@@ -13106,7 +13239,7 @@ async function inspectObjectProParent(spec, lock, seen) {
|
|
|
13106
13239
|
const label = `${object.kind} parent ${spec.styleId}/${object.parentAssetId}`;
|
|
13107
13240
|
const dependency = await inspectParent(parentSpec, lock, seen);
|
|
13108
13241
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13109
|
-
if (!object.parentSha256 || !object.parentFile || !
|
|
13242
|
+
if (!object.parentSha256 || !object.parentFile || !existsSync10(object.parentFile)) {
|
|
13110
13243
|
return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13111
13244
|
}
|
|
13112
13245
|
if (await sha256File(object.parentFile) !== object.parentSha256) {
|
|
@@ -13132,7 +13265,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13132
13265
|
const members = await inspectSourceMembers(spec, lock);
|
|
13133
13266
|
if (!members.ready) return members;
|
|
13134
13267
|
} else {
|
|
13135
|
-
if (!revision.sourceSha256 || !
|
|
13268
|
+
if (!revision.sourceSha256 || !existsSync10(revision.sourceFile)) {
|
|
13136
13269
|
return { ready: false, reason: `revision source is missing: ${revision.sourceFile}` };
|
|
13137
13270
|
}
|
|
13138
13271
|
if (await sha256File(revision.sourceFile) !== revision.sourceSha256) {
|
|
@@ -13140,7 +13273,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13140
13273
|
}
|
|
13141
13274
|
}
|
|
13142
13275
|
if (revision.maskFile) {
|
|
13143
|
-
if (!revision.maskSha256 || !
|
|
13276
|
+
if (!revision.maskSha256 || !existsSync10(revision.maskFile)) {
|
|
13144
13277
|
return { ready: false, reason: `revision mask is missing: ${revision.maskFile}` };
|
|
13145
13278
|
}
|
|
13146
13279
|
if (await sha256File(revision.maskFile) !== revision.maskSha256) {
|
|
@@ -13148,7 +13281,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13148
13281
|
}
|
|
13149
13282
|
}
|
|
13150
13283
|
if (revision.lastFrameFile) {
|
|
13151
|
-
if (!revision.lastFrameSha256 || !
|
|
13284
|
+
if (!revision.lastFrameSha256 || !existsSync10(revision.lastFrameFile)) {
|
|
13152
13285
|
return { ready: false, reason: `revision last frame is missing: ${revision.lastFrameFile}` };
|
|
13153
13286
|
}
|
|
13154
13287
|
if (await sha256File(revision.lastFrameFile) !== revision.lastFrameSha256) {
|
|
@@ -13161,7 +13294,7 @@ async function inspectSourceMembers(spec, lock) {
|
|
|
13161
13294
|
const revision = spec.revision;
|
|
13162
13295
|
const members = revision.sourceMembers;
|
|
13163
13296
|
for (const member of members) {
|
|
13164
|
-
if (!
|
|
13297
|
+
if (!existsSync10(member.file)) return { ready: false, reason: `revision source member is missing: ${member.file}` };
|
|
13165
13298
|
if (await sha256File(member.file) !== member.sha256) {
|
|
13166
13299
|
return { ready: false, reason: `revision source member changed after the manifest was resolved: ${member.file}` };
|
|
13167
13300
|
}
|
|
@@ -13229,7 +13362,7 @@ async function inspectParent(spec, lock, seen) {
|
|
|
13229
13362
|
}
|
|
13230
13363
|
if (spec.source) {
|
|
13231
13364
|
const source = path14.resolve(spec.root, spec.source);
|
|
13232
|
-
return
|
|
13365
|
+
return existsSync10(source) ? { ready: true, reason: "declared source is present" } : { ready: false, reason: `declared source is missing: ${spec.source}` };
|
|
13233
13366
|
}
|
|
13234
13367
|
const entry = lock.entries[key];
|
|
13235
13368
|
if (!entry) return { ready: false, reason: "parent is not in the lockfile" };
|
|
@@ -13243,7 +13376,7 @@ async function inspectParent(spec, lock, seen) {
|
|
|
13243
13376
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
13244
13377
|
const output = entry.outputs[index];
|
|
13245
13378
|
const file = currentEntryOutputPath(entry, spec, index);
|
|
13246
|
-
if (!
|
|
13379
|
+
if (!existsSync10(file)) return { ready: false, reason: `parent output is missing: ${file}` };
|
|
13247
13380
|
if (await sha256File(file) !== output.sha256) {
|
|
13248
13381
|
return { ready: false, reason: `parent output was modified: ${file}` };
|
|
13249
13382
|
}
|
|
@@ -13338,7 +13471,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13338
13471
|
state = "missing";
|
|
13339
13472
|
reason = "--force";
|
|
13340
13473
|
} else if (!entry && spec.source && spec.generator !== "frames" && spec.generator !== "vfx") {
|
|
13341
|
-
if (
|
|
13474
|
+
if (existsSync11(path15.resolve(spec.root, spec.source))) {
|
|
13342
13475
|
state = "ok";
|
|
13343
13476
|
reason = `placed from ${spec.source}; not generated`;
|
|
13344
13477
|
} else {
|
|
@@ -13346,7 +13479,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13346
13479
|
reason = `declared source is missing: ${spec.source}`;
|
|
13347
13480
|
}
|
|
13348
13481
|
} else if (!entry) {
|
|
13349
|
-
if (
|
|
13482
|
+
if (existsSync11(spec.outFile)) {
|
|
13350
13483
|
state = "untracked";
|
|
13351
13484
|
reason = "file on disk, no provenance recorded";
|
|
13352
13485
|
} else {
|
|
@@ -13359,7 +13492,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13359
13492
|
} else if (spec.mirror && !mirrorCurrent(entry, lock.entries[lockKey(spec.styleId, spec.mirror.sourceAssetId)])) {
|
|
13360
13493
|
state = "stale";
|
|
13361
13494
|
reason = `mirror source ${spec.mirror.sourceAssetId} changed; flip it again (no generation cost)`;
|
|
13362
|
-
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !
|
|
13495
|
+
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !existsSync11(currentEntryOutputPath(entry, spec, index)))) {
|
|
13363
13496
|
state = "stale";
|
|
13364
13497
|
reason = "mirror output missing on disk; flip it again (no generation cost)";
|
|
13365
13498
|
} else if (spec.character?.kind === "outfit" && entry.outfit?.sourceSha256 !== mirrorSourceHash(lock.entries[lockKey(spec.styleId, spec.character.parentAssetId)] ?? { outputs: [] })) {
|
|
@@ -13396,9 +13529,9 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13396
13529
|
} else if (entry.status !== "downloaded") {
|
|
13397
13530
|
state = "in-flight";
|
|
13398
13531
|
reason = `awaiting ${entry.status}`;
|
|
13399
|
-
} else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !
|
|
13532
|
+
} else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !existsSync11(currentEntryOutputPath(entry, spec, index)))) {
|
|
13400
13533
|
state = "orphaned";
|
|
13401
|
-
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !
|
|
13534
|
+
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !existsSync11(currentEntryOutputPath(entry, spec, index))).map((o) => o.role ?? "asset").join(", ")}`;
|
|
13402
13535
|
} else if (await anyOutputModified(entry, spec)) {
|
|
13403
13536
|
state = "orphaned";
|
|
13404
13537
|
reason = "output modified since download";
|
|
@@ -13504,8 +13637,14 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
|
|
|
13504
13637
|
if (path16.resolve(process.cwd()) !== root) loadEnvFiles(process.cwd());
|
|
13505
13638
|
}
|
|
13506
13639
|
const lockPath = path16.resolve(opts.lockPath ?? path16.join(root, "pixelkiln.lock.json"));
|
|
13507
|
-
|
|
13508
|
-
const
|
|
13640
|
+
let loaded = await loadManifest(absolute, { lenient: opts.lenient });
|
|
13641
|
+
const unresolved = [];
|
|
13642
|
+
const specs = await resolveSpecs(loaded, {
|
|
13643
|
+
styles: opts.styles ?? [],
|
|
13644
|
+
assets: opts.assets ?? [],
|
|
13645
|
+
...opts.lenient ? { onInvalid: (entry) => unresolved.push(entry) } : {}
|
|
13646
|
+
});
|
|
13647
|
+
if (unresolved.length) loaded = { ...loaded, invalid: [...loaded.invalid ?? [], ...unresolved] };
|
|
13509
13648
|
const lock = await loadLock(lockPath);
|
|
13510
13649
|
normalizeLockOutputPaths(lock, specs);
|
|
13511
13650
|
const adapters = /* @__PURE__ */ new Map();
|
|
@@ -13534,7 +13673,7 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
|
|
|
13534
13673
|
|
|
13535
13674
|
// src/recipes.ts
|
|
13536
13675
|
import path17 from "path";
|
|
13537
|
-
import { existsSync as
|
|
13676
|
+
import { existsSync as existsSync12 } from "fs";
|
|
13538
13677
|
import { readdir, readFile as readFile9 } from "fs/promises";
|
|
13539
13678
|
import { fileURLToPath } from "url";
|
|
13540
13679
|
import { z as z4 } from "zod";
|
|
@@ -13737,7 +13876,7 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
13737
13876
|
return { recipe: parsed.data, authored: raw, path: absolute, dir: path17.dirname(absolute), bundled };
|
|
13738
13877
|
}
|
|
13739
13878
|
async function walkRecipeFiles(root) {
|
|
13740
|
-
if (!
|
|
13879
|
+
if (!existsSync12(root)) return [];
|
|
13741
13880
|
const out = [];
|
|
13742
13881
|
for (const entry of await readdir(root, { withFileTypes: true })) {
|
|
13743
13882
|
const resolved = path17.join(root, entry.name);
|
|
@@ -13775,7 +13914,7 @@ function parseSelector(selector) {
|
|
|
13775
13914
|
}
|
|
13776
13915
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
13777
13916
|
const local = path17.resolve(target);
|
|
13778
|
-
if (
|
|
13917
|
+
if (existsSync12(local)) {
|
|
13779
13918
|
const recipePath = path17.basename(local) === RECIPE_FILE ? local : path17.join(local, RECIPE_FILE);
|
|
13780
13919
|
return readRecipeFile(recipePath, false);
|
|
13781
13920
|
}
|
|
@@ -13791,7 +13930,7 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
13791
13930
|
}
|
|
13792
13931
|
async function verifyFile(root, file) {
|
|
13793
13932
|
const absolute = path17.resolve(root, ...file.path.split("/"));
|
|
13794
|
-
if (!
|
|
13933
|
+
if (!existsSync12(absolute)) {
|
|
13795
13934
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
13796
13935
|
}
|
|
13797
13936
|
const actualSha256 = await sha256File(absolute);
|
|
@@ -13869,7 +14008,7 @@ async function installRecipe(target, options = {}) {
|
|
|
13869
14008
|
})));
|
|
13870
14009
|
if (!options.force) {
|
|
13871
14010
|
for (const file of files) {
|
|
13872
|
-
if (!
|
|
14011
|
+
if (!existsSync12(file.path)) continue;
|
|
13873
14012
|
const current = await readFile9(file.path);
|
|
13874
14013
|
if (!current.equals(file.data)) {
|
|
13875
14014
|
throw new OverwriteRefusedError(
|
|
@@ -13895,7 +14034,7 @@ async function installRecipe(target, options = {}) {
|
|
|
13895
14034
|
|
|
13896
14035
|
// src/pipeline/audit.ts
|
|
13897
14036
|
import { readFile as readFile10 } from "fs/promises";
|
|
13898
|
-
import { existsSync as
|
|
14037
|
+
import { existsSync as existsSync13 } from "fs";
|
|
13899
14038
|
import path18 from "path";
|
|
13900
14039
|
function paletteDistance(asset, reference) {
|
|
13901
14040
|
if (!asset.length || !reference.length) return 0;
|
|
@@ -13932,7 +14071,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
13932
14071
|
const unreadable = [];
|
|
13933
14072
|
for (const spec of mine) {
|
|
13934
14073
|
for (const output of resolveSpecOutputs(spec, lock, loaded.root)) {
|
|
13935
|
-
if (!
|
|
14074
|
+
if (!existsSync13(output.absolutePath)) {
|
|
13936
14075
|
missing.push(output.id);
|
|
13937
14076
|
continue;
|
|
13938
14077
|
}
|
|
@@ -13962,7 +14101,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
13962
14101
|
const refPalettes = [];
|
|
13963
14102
|
for (const img of style.styleImages) {
|
|
13964
14103
|
const abs = path18.resolve(loaded.root, img.path);
|
|
13965
|
-
if (!
|
|
14104
|
+
if (!existsSync13(abs)) continue;
|
|
13966
14105
|
try {
|
|
13967
14106
|
refPalettes.push(extractPalette(decodePng(await readFile10(abs)), 12));
|
|
13968
14107
|
} catch {
|
|
@@ -14041,7 +14180,7 @@ function hex(c) {
|
|
|
14041
14180
|
|
|
14042
14181
|
// src/pipeline/quality-regression.ts
|
|
14043
14182
|
import path19 from "path";
|
|
14044
|
-
import { existsSync as
|
|
14183
|
+
import { existsSync as existsSync14 } from "fs";
|
|
14045
14184
|
import { readFile as readFile11 } from "fs/promises";
|
|
14046
14185
|
import { z as z5 } from "zod";
|
|
14047
14186
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
@@ -14284,7 +14423,7 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14284
14423
|
cases
|
|
14285
14424
|
});
|
|
14286
14425
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
14287
|
-
if (
|
|
14426
|
+
if (existsSync14(absolute) && !options.force) {
|
|
14288
14427
|
const current = await readFile11(absolute);
|
|
14289
14428
|
if (!current.equals(data)) {
|
|
14290
14429
|
throw new OverwriteRefusedError(
|
|
@@ -14296,6 +14435,63 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14296
14435
|
const result = await writeArtifactBundle([{ path: absolute, data }]);
|
|
14297
14436
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
14298
14437
|
}
|
|
14438
|
+
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
14439
|
+
const absolute = path19.resolve(baselinePath);
|
|
14440
|
+
if (!existsSync14(absolute)) {
|
|
14441
|
+
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
14442
|
+
}
|
|
14443
|
+
let raw;
|
|
14444
|
+
try {
|
|
14445
|
+
raw = JSON.parse(await readFile11(absolute, "utf8"));
|
|
14446
|
+
} catch (error) {
|
|
14447
|
+
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
14448
|
+
}
|
|
14449
|
+
if (!Array.isArray(raw.cases)) throw new Error(`Quality baseline ${absolute} has no cases array.`);
|
|
14450
|
+
const byId = new Map(inputs.map((input) => [input.id, input]));
|
|
14451
|
+
const unknown = only.filter((id) => !byId.has(id));
|
|
14452
|
+
if (unknown.length) {
|
|
14453
|
+
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
14454
|
+
}
|
|
14455
|
+
const root = path19.dirname(absolute);
|
|
14456
|
+
const cases = [...raw.cases];
|
|
14457
|
+
const report = [];
|
|
14458
|
+
for (const id of only) {
|
|
14459
|
+
const input = byId.get(id);
|
|
14460
|
+
if (path19.resolve(input.file) === absolute || input.record && path19.resolve(input.record) === absolute) {
|
|
14461
|
+
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
14462
|
+
}
|
|
14463
|
+
const expected = await measureImageQuality(input.file);
|
|
14464
|
+
let record;
|
|
14465
|
+
if (input.record) {
|
|
14466
|
+
await verifyRecordForImage(input.record, input.file);
|
|
14467
|
+
record = { path: portableRelative2(root, input.record), sha256: await sha256File(input.record) };
|
|
14468
|
+
}
|
|
14469
|
+
const index = cases.findIndex((entry) => entry.id === id);
|
|
14470
|
+
const before = index >= 0 ? cases[index].expected ?? {} : {};
|
|
14471
|
+
const next = {
|
|
14472
|
+
id,
|
|
14473
|
+
file: portableRelative2(root, input.file),
|
|
14474
|
+
...record ? { record } : {},
|
|
14475
|
+
expected,
|
|
14476
|
+
tolerances: index >= 0 && cases[index].tolerances ? cases[index].tolerances : input.tolerances
|
|
14477
|
+
};
|
|
14478
|
+
if (index >= 0) cases[index] = next;
|
|
14479
|
+
else cases.push(next);
|
|
14480
|
+
const changes = [];
|
|
14481
|
+
for (const metric of Object.keys(expected)) {
|
|
14482
|
+
if (JSON.stringify(before[metric]) !== JSON.stringify(expected[metric])) {
|
|
14483
|
+
changes.push({ metric, before: before[metric] ?? null, after: expected[metric] });
|
|
14484
|
+
}
|
|
14485
|
+
}
|
|
14486
|
+
report.push({ id, kind: index < 0 ? "added" : changes.length ? "updated" : "unchanged", changes });
|
|
14487
|
+
}
|
|
14488
|
+
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
14489
|
+
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
14490
|
+
const current = await readFile11(absolute);
|
|
14491
|
+
const changed = !current.equals(data);
|
|
14492
|
+
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
14493
|
+
return { baseline, path: absolute, changed, cases: report };
|
|
14494
|
+
}
|
|
14299
14495
|
async function readQualityBaseline(baselinePath) {
|
|
14300
14496
|
const absolute = path19.resolve(baselinePath);
|
|
14301
14497
|
let raw;
|
|
@@ -14306,9 +14502,23 @@ async function readQualityBaseline(baselinePath) {
|
|
|
14306
14502
|
}
|
|
14307
14503
|
const parsed = QualityBaselineSchema.safeParse(raw);
|
|
14308
14504
|
if (!parsed.success) {
|
|
14505
|
+
const cases = raw?.cases;
|
|
14506
|
+
const where = (issuePath) => {
|
|
14507
|
+
if (issuePath[0] === "cases" && typeof issuePath[1] === "number") {
|
|
14508
|
+
const id = cases?.[issuePath[1]]?.id;
|
|
14509
|
+
const rest = issuePath.slice(2).join(".");
|
|
14510
|
+
return typeof id === "string" ? `cases[${id}]${rest ? `.${rest}` : ""}` : issuePath.join(".");
|
|
14511
|
+
}
|
|
14512
|
+
return issuePath.join(".") || "$";
|
|
14513
|
+
};
|
|
14514
|
+
const missing = [...new Set(parsed.error.issues.flatMap((issue) => {
|
|
14515
|
+
const id = issue.path[0] === "cases" && typeof issue.path[1] === "number" ? cases?.[issue.path[1]]?.id : void 0;
|
|
14516
|
+
return issue.code === "invalid_type" && issue.received === "undefined" && typeof id === "string" ? [id] : [];
|
|
14517
|
+
}))];
|
|
14309
14518
|
throw new Error(
|
|
14310
14519
|
`Invalid quality baseline ${absolute}:
|
|
14311
|
-
` + parsed.error.issues.map((issue) => ` ${issue.path
|
|
14520
|
+
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
14521
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path19.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
14312
14522
|
);
|
|
14313
14523
|
}
|
|
14314
14524
|
return parsed.data;
|
|
@@ -14424,13 +14634,13 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
14424
14634
|
}
|
|
14425
14635
|
|
|
14426
14636
|
// src/pipeline/cache-health.ts
|
|
14427
|
-
import { existsSync as
|
|
14637
|
+
import { existsSync as existsSync18 } from "fs";
|
|
14428
14638
|
import { readFile as readFile14, readdir as readdir2, rm as rm6 } from "fs/promises";
|
|
14429
14639
|
import path22 from "path";
|
|
14430
14640
|
|
|
14431
14641
|
// src/cache.ts
|
|
14432
14642
|
import { mkdir as mkdir6, readFile as readFile12, rename as rename4, rm as rm4, writeFile as writeFile6 } from "fs/promises";
|
|
14433
|
-
import { existsSync as
|
|
14643
|
+
import { existsSync as existsSync15 } from "fs";
|
|
14434
14644
|
import pathModule from "path";
|
|
14435
14645
|
import { z as z6 } from "zod";
|
|
14436
14646
|
var HashCacheSchema = z6.object({
|
|
@@ -14445,10 +14655,10 @@ function isSha256Hash(value) {
|
|
|
14445
14655
|
function parseCache(value) {
|
|
14446
14656
|
return HashCacheSchema.parse(value);
|
|
14447
14657
|
}
|
|
14448
|
-
async function loadCache(
|
|
14449
|
-
if (!
|
|
14658
|
+
async function loadCache(path40) {
|
|
14659
|
+
if (!existsSync15(path40)) return { version: 1, hashes: {} };
|
|
14450
14660
|
try {
|
|
14451
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile12(
|
|
14661
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile12(path40, "utf8")));
|
|
14452
14662
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
14453
14663
|
return {
|
|
14454
14664
|
version: 1,
|
|
@@ -14460,18 +14670,18 @@ async function loadCache(path39) {
|
|
|
14460
14670
|
return { version: 1, hashes: {} };
|
|
14461
14671
|
}
|
|
14462
14672
|
}
|
|
14463
|
-
async function saveCache(
|
|
14673
|
+
async function saveCache(path40, cache) {
|
|
14464
14674
|
const sorted = {};
|
|
14465
14675
|
for (const key of Object.keys(cache.hashes).sort()) {
|
|
14466
14676
|
const hash = cache.hashes[key];
|
|
14467
14677
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key}`);
|
|
14468
14678
|
sorted[key] = hash;
|
|
14469
14679
|
}
|
|
14470
|
-
await mkdir6(pathModule.dirname(pathModule.resolve(
|
|
14471
|
-
const tmp = `${
|
|
14680
|
+
await mkdir6(pathModule.dirname(pathModule.resolve(path40)), { recursive: true });
|
|
14681
|
+
const tmp = `${path40}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
14472
14682
|
try {
|
|
14473
14683
|
await writeFile6(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
14474
|
-
await rename4(tmp,
|
|
14684
|
+
await rename4(tmp, path40);
|
|
14475
14685
|
} finally {
|
|
14476
14686
|
await rm4(tmp, { force: true });
|
|
14477
14687
|
}
|
|
@@ -14495,11 +14705,11 @@ function cachePathFor(lockPath) {
|
|
|
14495
14705
|
}
|
|
14496
14706
|
|
|
14497
14707
|
// src/pipeline/history.ts
|
|
14498
|
-
import { existsSync as
|
|
14708
|
+
import { existsSync as existsSync17 } from "fs";
|
|
14499
14709
|
import path21 from "path";
|
|
14500
14710
|
|
|
14501
14711
|
// src/pipeline/fetch.ts
|
|
14502
|
-
import { existsSync as
|
|
14712
|
+
import { existsSync as existsSync16, readFileSync as readFileSync5 } from "fs";
|
|
14503
14713
|
import { mkdir as mkdir7, readFile as readFile13, rename as rename5, rm as rm5, writeFile as writeFile7 } from "fs/promises";
|
|
14504
14714
|
import path20 from "path";
|
|
14505
14715
|
async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
@@ -14519,15 +14729,15 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14519
14729
|
if (spec && e.specHash === spec.specHash && e.outputs.length && !postprocessCurrent(e, spec)) {
|
|
14520
14730
|
return Boolean(opts.force) || e.outputs.every((output) => {
|
|
14521
14731
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14522
|
-
return
|
|
14732
|
+
return existsSync16(file) && sha256(readFileSync5(file)) === output.sha256;
|
|
14523
14733
|
});
|
|
14524
14734
|
}
|
|
14525
14735
|
if (!opts.repair) return false;
|
|
14526
14736
|
if (e.outputs.length === 0 || !spec) return true;
|
|
14527
14737
|
return e.outputs.some((output) => {
|
|
14528
14738
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14529
|
-
if (!
|
|
14530
|
-
const current = sha256(
|
|
14739
|
+
if (!existsSync16(file)) return true;
|
|
14740
|
+
const current = sha256(readFileSync5(file));
|
|
14531
14741
|
if (current === output.sha256) return false;
|
|
14532
14742
|
return Boolean(opts.force) || (e.supersededOutputs ?? []).some((old) => old.sha256 === current);
|
|
14533
14743
|
});
|
|
@@ -14617,7 +14827,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14617
14827
|
}
|
|
14618
14828
|
let raw = null;
|
|
14619
14829
|
let final = null;
|
|
14620
|
-
if (
|
|
14830
|
+
if (existsSync16(target)) {
|
|
14621
14831
|
const currentHash = await sha256File(target);
|
|
14622
14832
|
if (recorded && currentHash === recorded.sha256) {
|
|
14623
14833
|
if (!fresh && !reapply) {
|
|
@@ -14763,7 +14973,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14763
14973
|
}
|
|
14764
14974
|
async function readCachedMedia(cacheDir, hash, mediaType) {
|
|
14765
14975
|
const file = path20.join(cacheDir, cacheFileName(hash, mediaType));
|
|
14766
|
-
if (!
|
|
14976
|
+
if (!existsSync16(file)) return null;
|
|
14767
14977
|
try {
|
|
14768
14978
|
const buf = await readFile13(file);
|
|
14769
14979
|
if (sha256(buf) !== hash) return null;
|
|
@@ -14784,7 +14994,7 @@ async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
|
|
|
14784
14994
|
try {
|
|
14785
14995
|
await rename5(tmp, file);
|
|
14786
14996
|
} catch (err) {
|
|
14787
|
-
if (!
|
|
14997
|
+
if (!existsSync16(file)) throw err;
|
|
14788
14998
|
} finally {
|
|
14789
14999
|
await rm5(tmp, { force: true });
|
|
14790
15000
|
}
|
|
@@ -14906,7 +15116,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
14906
15116
|
}
|
|
14907
15117
|
for (let i = 0; i < entry.outputs.length; i++) {
|
|
14908
15118
|
const file = currentEntryOutputPath(entry, spec, i);
|
|
14909
|
-
if (!
|
|
15119
|
+
if (!existsSync17(file)) continue;
|
|
14910
15120
|
if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
|
|
14911
15121
|
throw new OverwriteRefusedError(
|
|
14912
15122
|
`${path21.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
|
|
@@ -14969,7 +15179,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
14969
15179
|
|
|
14970
15180
|
// src/pipeline/cache-health.ts
|
|
14971
15181
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
14972
|
-
if (options.prune && !
|
|
15182
|
+
if (options.prune && !existsSync18(lockPath)) {
|
|
14973
15183
|
throw new Error(`Refusing to prune without an existing lockfile at ${path22.resolve(lockPath)}`);
|
|
14974
15184
|
}
|
|
14975
15185
|
const contentDir = path22.resolve(path22.dirname(lockPath), ".pixelkiln", "cache");
|
|
@@ -15012,7 +15222,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
15012
15222
|
async function inspectContentCache(contentDir, referenced) {
|
|
15013
15223
|
const report = {
|
|
15014
15224
|
path: contentDir,
|
|
15015
|
-
exists:
|
|
15225
|
+
exists: existsSync18(contentDir),
|
|
15016
15226
|
files: 0,
|
|
15017
15227
|
bytes: 0,
|
|
15018
15228
|
valid: 0,
|
|
@@ -15076,7 +15286,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
15076
15286
|
async function inspectRemoteHashCache(remotePath) {
|
|
15077
15287
|
const report = {
|
|
15078
15288
|
path: remotePath,
|
|
15079
|
-
exists:
|
|
15289
|
+
exists: existsSync18(remotePath),
|
|
15080
15290
|
entries: 0,
|
|
15081
15291
|
valid: 0,
|
|
15082
15292
|
invalidIds: [],
|
|
@@ -15100,7 +15310,7 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
15100
15310
|
}
|
|
15101
15311
|
|
|
15102
15312
|
// src/pipeline/pack.ts
|
|
15103
|
-
import { readFileSync as
|
|
15313
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
15104
15314
|
import path23 from "path";
|
|
15105
15315
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
15106
15316
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
@@ -15134,7 +15344,7 @@ function packSprites(inputs, options = {}) {
|
|
|
15134
15344
|
for (const input of ordered) {
|
|
15135
15345
|
let sourceHash = null;
|
|
15136
15346
|
try {
|
|
15137
|
-
const bytes =
|
|
15347
|
+
const bytes = readFileSync6(input.path);
|
|
15138
15348
|
sourceHash = sha256(bytes);
|
|
15139
15349
|
const png = decodePng(bytes);
|
|
15140
15350
|
sprites.push({ id: input.id, width: png.width, height: png.height, pixels: png.pixels });
|
|
@@ -15293,7 +15503,7 @@ function mountSprites(placements, options) {
|
|
|
15293
15503
|
for (const p of placements) {
|
|
15294
15504
|
let sourceHash = null;
|
|
15295
15505
|
try {
|
|
15296
|
-
const bytes =
|
|
15506
|
+
const bytes = readFileSync6(p.path);
|
|
15297
15507
|
sourceHash = sha256(bytes);
|
|
15298
15508
|
const png = decodePng(bytes);
|
|
15299
15509
|
if (png.width > cellWidth || png.height > cellHeight) {
|
|
@@ -15397,7 +15607,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
15397
15607
|
`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}`
|
|
15398
15608
|
);
|
|
15399
15609
|
}
|
|
15400
|
-
const basePng = mount.base ?
|
|
15610
|
+
const basePng = mount.base ? readFileSync6(path23.resolve(manifestDir, mount.base)) : void 0;
|
|
15401
15611
|
const mounted = mountSprites(placements, {
|
|
15402
15612
|
cellWidth: mount.cellWidth,
|
|
15403
15613
|
cellHeight: mount.cellHeight,
|
|
@@ -16251,9 +16461,81 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
16251
16461
|
}
|
|
16252
16462
|
|
|
16253
16463
|
// src/pipeline/doctor.ts
|
|
16254
|
-
import { constants, existsSync as
|
|
16464
|
+
import { constants, existsSync as existsSync20 } from "fs";
|
|
16255
16465
|
import { access, stat as stat2 } from "fs/promises";
|
|
16466
|
+
import path25 from "path";
|
|
16467
|
+
|
|
16468
|
+
// src/pipeline/install-check.ts
|
|
16469
|
+
import { existsSync as existsSync19, readFileSync as readFileSync7 } from "fs";
|
|
16256
16470
|
import path24 from "path";
|
|
16471
|
+
function readJson(file) {
|
|
16472
|
+
try {
|
|
16473
|
+
return JSON.parse(readFileSync7(file, "utf8"));
|
|
16474
|
+
} catch {
|
|
16475
|
+
return null;
|
|
16476
|
+
}
|
|
16477
|
+
}
|
|
16478
|
+
function readInstallFacts(manifestDir, running) {
|
|
16479
|
+
let dir = path24.resolve(manifestDir);
|
|
16480
|
+
for (let depth = 0; depth < 4; depth++) {
|
|
16481
|
+
const pkg = readJson(path24.join(dir, "package.json"));
|
|
16482
|
+
if (pkg) {
|
|
16483
|
+
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
16484
|
+
if (pinned) {
|
|
16485
|
+
const installedPkg = readJson(path24.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
16486
|
+
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
16487
|
+
return { pinned, installed, running };
|
|
16488
|
+
}
|
|
16489
|
+
}
|
|
16490
|
+
const parent = path24.dirname(dir);
|
|
16491
|
+
if (parent === dir || !existsSync19(parent)) break;
|
|
16492
|
+
dir = parent;
|
|
16493
|
+
}
|
|
16494
|
+
return null;
|
|
16495
|
+
}
|
|
16496
|
+
function parse(version) {
|
|
16497
|
+
const match = /(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
16498
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
16499
|
+
}
|
|
16500
|
+
function compare(a, b) {
|
|
16501
|
+
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
16502
|
+
}
|
|
16503
|
+
function checkInstall(facts) {
|
|
16504
|
+
const findings = [];
|
|
16505
|
+
const pin = parse(facts.pinned ?? "");
|
|
16506
|
+
const installed = facts.installed ? parse(facts.installed) : null;
|
|
16507
|
+
const running = facts.running ? parse(facts.running) : null;
|
|
16508
|
+
const exact = /^[=v]*\d+\.\d+\.\d+$/.test((facts.pinned ?? "").trim());
|
|
16509
|
+
if (pin && facts.installed && installed) {
|
|
16510
|
+
const behind = exact ? compare(installed, pin) !== 0 : compare(installed, pin) < 0;
|
|
16511
|
+
if (behind) {
|
|
16512
|
+
findings.push({
|
|
16513
|
+
level: "warning",
|
|
16514
|
+
message: `package.json asks for pixelkiln ${facts.pinned} but node_modules has ${facts.installed}; run \`npm install\` so the CLI matches the manifest.`
|
|
16515
|
+
});
|
|
16516
|
+
}
|
|
16517
|
+
} else if (pin && !facts.installed) {
|
|
16518
|
+
findings.push({
|
|
16519
|
+
level: "warning",
|
|
16520
|
+
message: `package.json asks for pixelkiln ${facts.pinned} but it is not installed in node_modules; run \`npm install\`.`
|
|
16521
|
+
});
|
|
16522
|
+
}
|
|
16523
|
+
if (running && installed && compare(running, installed) !== 0) {
|
|
16524
|
+
findings.push({
|
|
16525
|
+
level: "warning",
|
|
16526
|
+
message: `running pixelkiln ${facts.running}, but this project's node_modules has ${facts.installed}. Another install is first on your PATH; use \`npx pixelkiln\` or remove the global one.`
|
|
16527
|
+
});
|
|
16528
|
+
}
|
|
16529
|
+
if (!findings.length) {
|
|
16530
|
+
findings.push({
|
|
16531
|
+
level: "ok",
|
|
16532
|
+
message: `pixelkiln ${facts.running ?? facts.installed ?? "?"} matches package.json (${facts.pinned})`
|
|
16533
|
+
});
|
|
16534
|
+
}
|
|
16535
|
+
return findings;
|
|
16536
|
+
}
|
|
16537
|
+
|
|
16538
|
+
// src/pipeline/doctor.ts
|
|
16257
16539
|
async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
16258
16540
|
const checks = [];
|
|
16259
16541
|
const add = (id, level, message6) => checks.push({ id, level, message: message6 });
|
|
@@ -16262,10 +16544,19 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16262
16544
|
"ok",
|
|
16263
16545
|
`${Object.keys(loaded.manifest.styles).length} style(s), ${Object.keys(loaded.manifest.assets).length} asset(s), ${specs.length} resolved spec(s)`
|
|
16264
16546
|
);
|
|
16547
|
+
for (const entry of loaded.invalid ?? []) {
|
|
16548
|
+
add(
|
|
16549
|
+
"invalid-entry",
|
|
16550
|
+
"error",
|
|
16551
|
+
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
16552
|
+
);
|
|
16553
|
+
}
|
|
16554
|
+
const facts = readInstallFacts(path25.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
16555
|
+
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
16265
16556
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
16266
16557
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
16267
|
-
|
|
16268
|
-
...spec.quality ? [
|
|
16558
|
+
path25.dirname(spec.outFile),
|
|
16559
|
+
...spec.quality ? [path25.dirname(spec.quality.outFile)] : []
|
|
16269
16560
|
]))];
|
|
16270
16561
|
const unwritable = [];
|
|
16271
16562
|
for (const dir of dirs) {
|
|
@@ -16288,7 +16579,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16288
16579
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
16289
16580
|
const output = entry.outputs[index];
|
|
16290
16581
|
const spec = specByKey.get(key);
|
|
16291
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
16582
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, path25.dirname(lockPath));
|
|
16292
16583
|
const owner = outputOwners.get(absolute);
|
|
16293
16584
|
if (owner && owner !== key) duplicateOutputs.push(`${output.path} (${owner}, ${key})`);
|
|
16294
16585
|
outputOwners.set(absolute, key);
|
|
@@ -16303,7 +16594,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16303
16594
|
} else {
|
|
16304
16595
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
16305
16596
|
}
|
|
16306
|
-
const cacheDir =
|
|
16597
|
+
const cacheDir = path25.join(path25.dirname(lockPath), ".pixelkiln", "cache");
|
|
16307
16598
|
const stranded = [];
|
|
16308
16599
|
const invalidState = [];
|
|
16309
16600
|
const staleMapUrls = [];
|
|
@@ -16319,11 +16610,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16319
16610
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
16320
16611
|
let hasCache = false;
|
|
16321
16612
|
for (const output of entry.outputs) {
|
|
16322
|
-
const
|
|
16613
|
+
const cached2 = path25.join(
|
|
16323
16614
|
cacheDir,
|
|
16324
16615
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
16325
16616
|
);
|
|
16326
|
-
if (
|
|
16617
|
+
if (existsSync20(cached2) && await sha256File(cached2) === output.sha256) {
|
|
16327
16618
|
hasCache = true;
|
|
16328
16619
|
break;
|
|
16329
16620
|
}
|
|
@@ -16419,16 +16710,16 @@ async function nearestExistingDirectory(start) {
|
|
|
16419
16710
|
if ((await stat2(current)).isDirectory()) return current;
|
|
16420
16711
|
} catch {
|
|
16421
16712
|
}
|
|
16422
|
-
const parent =
|
|
16713
|
+
const parent = path25.dirname(current);
|
|
16423
16714
|
if (parent === current) return current;
|
|
16424
16715
|
current = parent;
|
|
16425
16716
|
}
|
|
16426
16717
|
}
|
|
16427
16718
|
|
|
16428
16719
|
// src/pipeline/adopt.ts
|
|
16429
|
-
import { existsSync as
|
|
16720
|
+
import { existsSync as existsSync21 } from "fs";
|
|
16430
16721
|
import { readFile as readFile15, writeFile as writeFile8 } from "fs/promises";
|
|
16431
|
-
import
|
|
16722
|
+
import path26 from "path";
|
|
16432
16723
|
async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
16433
16724
|
const log = opts.onProgress ?? (() => {
|
|
16434
16725
|
});
|
|
@@ -16439,7 +16730,7 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
16439
16730
|
const localByHash = /* @__PURE__ */ new Map();
|
|
16440
16731
|
const unmatchedLocal = [];
|
|
16441
16732
|
for (const spec of specs) {
|
|
16442
|
-
if (!
|
|
16733
|
+
if (!existsSync21(spec.outFile)) {
|
|
16443
16734
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
16444
16735
|
continue;
|
|
16445
16736
|
}
|
|
@@ -16560,14 +16851,125 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
16560
16851
|
return count;
|
|
16561
16852
|
}
|
|
16562
16853
|
|
|
16854
|
+
// src/pipeline/import.ts
|
|
16855
|
+
import { existsSync as existsSync22 } from "fs";
|
|
16856
|
+
import { readFile as readFile16 } from "fs/promises";
|
|
16857
|
+
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
16858
|
+
const png = decodePng(bytes);
|
|
16859
|
+
const at = now.toISOString();
|
|
16860
|
+
return {
|
|
16861
|
+
styleId: spec.styleId,
|
|
16862
|
+
assetId: spec.assetId,
|
|
16863
|
+
specHash: spec.specHash,
|
|
16864
|
+
generator: spec.generator,
|
|
16865
|
+
prompt: spec.prompt,
|
|
16866
|
+
width: png.width,
|
|
16867
|
+
height: png.height,
|
|
16868
|
+
jobId: opts.objectId ?? null,
|
|
16869
|
+
objectId: opts.objectId ?? null,
|
|
16870
|
+
reviewObjectId: null,
|
|
16871
|
+
candidateIndex: null,
|
|
16872
|
+
status: "downloaded",
|
|
16873
|
+
error: null,
|
|
16874
|
+
sourceUrl: null,
|
|
16875
|
+
sourceUrls: [],
|
|
16876
|
+
outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
|
|
16877
|
+
submittedAt: null,
|
|
16878
|
+
downloadedAt: at,
|
|
16879
|
+
cost: 0,
|
|
16880
|
+
costUnit: spec.costUnit,
|
|
16881
|
+
provider: spec.provider,
|
|
16882
|
+
imported: {
|
|
16883
|
+
source: opts.source ?? "external",
|
|
16884
|
+
...opts.note ? { note: opts.note } : {},
|
|
16885
|
+
importedAt: at
|
|
16886
|
+
}
|
|
16887
|
+
};
|
|
16888
|
+
}
|
|
16889
|
+
function unimportable(spec) {
|
|
16890
|
+
if (spec.character) return "a character is several files; import it with account adopt";
|
|
16891
|
+
if (spec.vfx) return "an effect is rendered from its recipe, not imported";
|
|
16892
|
+
if (!spec.outFile.toLowerCase().endsWith(".png")) return "only a single PNG output can be imported";
|
|
16893
|
+
return null;
|
|
16894
|
+
}
|
|
16895
|
+
async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
16896
|
+
if (opts.objectId && specs.length !== 1) {
|
|
16897
|
+
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
16898
|
+
}
|
|
16899
|
+
const imported = [];
|
|
16900
|
+
const skipped = [];
|
|
16901
|
+
for (const spec of specs) {
|
|
16902
|
+
const key = lockKey(spec.styleId, spec.assetId);
|
|
16903
|
+
const reason = unimportable(spec);
|
|
16904
|
+
if (reason) {
|
|
16905
|
+
skipped.push({ key, reason });
|
|
16906
|
+
continue;
|
|
16907
|
+
}
|
|
16908
|
+
if (!existsSync22(spec.outFile)) {
|
|
16909
|
+
skipped.push({ key, reason: `no file at ${spec.outFile}` });
|
|
16910
|
+
continue;
|
|
16911
|
+
}
|
|
16912
|
+
if (lock.entries[key] && !opts.force) {
|
|
16913
|
+
skipped.push({ key, reason: "already in the lockfile (use --force to replace it)" });
|
|
16914
|
+
continue;
|
|
16915
|
+
}
|
|
16916
|
+
let patch;
|
|
16917
|
+
try {
|
|
16918
|
+
patch = buildImportedEntry(spec, await readFile16(spec.outFile), opts);
|
|
16919
|
+
} catch (error) {
|
|
16920
|
+
skipped.push({ key, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
16921
|
+
continue;
|
|
16922
|
+
}
|
|
16923
|
+
if (opts.dryRun) {
|
|
16924
|
+
imported.push({ key, entry: patch });
|
|
16925
|
+
continue;
|
|
16926
|
+
}
|
|
16927
|
+
imported.push({ key, entry: upsert(lock, key, patch) });
|
|
16928
|
+
}
|
|
16929
|
+
if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
|
|
16930
|
+
return { imported, skipped };
|
|
16931
|
+
}
|
|
16932
|
+
async function reportSpecHashes(specs, lock) {
|
|
16933
|
+
const reports = [];
|
|
16934
|
+
for (const spec of specs) {
|
|
16935
|
+
const key = lockKey(spec.styleId, spec.assetId);
|
|
16936
|
+
let bytes = null;
|
|
16937
|
+
if (existsSync22(spec.outFile)) bytes = await readFile16(spec.outFile);
|
|
16938
|
+
let wouldImport = null;
|
|
16939
|
+
if (bytes && !unimportable(spec)) {
|
|
16940
|
+
try {
|
|
16941
|
+
wouldImport = buildImportedEntry(spec, bytes);
|
|
16942
|
+
} catch {
|
|
16943
|
+
wouldImport = null;
|
|
16944
|
+
}
|
|
16945
|
+
}
|
|
16946
|
+
const entry = lock.entries[key];
|
|
16947
|
+
const fileSha256 = bytes ? sha256(bytes) : null;
|
|
16948
|
+
const outputSha256 = entry?.outputs[0]?.sha256 ?? null;
|
|
16949
|
+
reports.push({
|
|
16950
|
+
key,
|
|
16951
|
+
specHash: spec.specHash,
|
|
16952
|
+
file: spec.outFile,
|
|
16953
|
+
fileSha256,
|
|
16954
|
+
lock: entry ? {
|
|
16955
|
+
specHash: entry.specHash,
|
|
16956
|
+
outputSha256,
|
|
16957
|
+
matches: entry.specHash === spec.specHash && outputSha256 !== null && outputSha256 === fileSha256
|
|
16958
|
+
} : null,
|
|
16959
|
+
wouldImport
|
|
16960
|
+
});
|
|
16961
|
+
}
|
|
16962
|
+
return reports;
|
|
16963
|
+
}
|
|
16964
|
+
|
|
16563
16965
|
// src/pick/server.ts
|
|
16564
|
-
import { existsSync as
|
|
16565
|
-
import { readFile as
|
|
16966
|
+
import { existsSync as existsSync24 } from "fs";
|
|
16967
|
+
import { readFile as readFile19 } from "fs/promises";
|
|
16566
16968
|
|
|
16567
16969
|
// src/pipeline/init.ts
|
|
16568
|
-
import { readdir as readdir3, readFile as
|
|
16569
|
-
import { existsSync as
|
|
16570
|
-
import
|
|
16970
|
+
import { readdir as readdir3, readFile as readFile17, writeFile as writeFile9 } from "fs/promises";
|
|
16971
|
+
import { existsSync as existsSync23 } from "fs";
|
|
16972
|
+
import path27 from "path";
|
|
16571
16973
|
function pngSize(buf) {
|
|
16572
16974
|
if (buf.length < 24) return null;
|
|
16573
16975
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -16581,7 +16983,7 @@ function slugify(value) {
|
|
|
16581
16983
|
async function walk(dir, exclude) {
|
|
16582
16984
|
const out = [];
|
|
16583
16985
|
for (const entry of await readdir3(dir, { withFileTypes: true })) {
|
|
16584
|
-
const full =
|
|
16986
|
+
const full = path27.join(dir, entry.name);
|
|
16585
16987
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
16586
16988
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
16587
16989
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -16595,14 +16997,14 @@ async function scanAssets(root, opts = {}) {
|
|
|
16595
16997
|
const skipped = [];
|
|
16596
16998
|
const seen = /* @__PURE__ */ new Map();
|
|
16597
16999
|
for (const file of files.sort()) {
|
|
16598
|
-
const size = pngSize(await
|
|
17000
|
+
const size = pngSize(await readFile17(file));
|
|
16599
17001
|
if (!size) {
|
|
16600
17002
|
skipped.push(`${file} (not a readable PNG)`);
|
|
16601
17003
|
continue;
|
|
16602
17004
|
}
|
|
16603
|
-
const rel =
|
|
16604
|
-
const category =
|
|
16605
|
-
let id = slugify(
|
|
17005
|
+
const rel = path27.relative(root, file);
|
|
17006
|
+
const category = path27.dirname(rel) === "." ? "" : path27.dirname(rel);
|
|
17007
|
+
let id = slugify(path27.basename(rel));
|
|
16606
17008
|
if (seen.has(id)) {
|
|
16607
17009
|
const n = seen.get(id) + 1;
|
|
16608
17010
|
seen.set(id, n);
|
|
@@ -17076,7 +17478,7 @@ document.getElementById('submit').onclick = async () => {
|
|
|
17076
17478
|
|
|
17077
17479
|
// src/pick/review-server.ts
|
|
17078
17480
|
import { createServer } from "http";
|
|
17079
|
-
import { readFile as
|
|
17481
|
+
import { readFile as readFile18 } from "fs/promises";
|
|
17080
17482
|
function serveReviewPage(opts) {
|
|
17081
17483
|
const log = opts.onProgress ?? (() => {
|
|
17082
17484
|
});
|
|
@@ -17085,7 +17487,7 @@ function serveReviewPage(opts) {
|
|
|
17085
17487
|
if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
|
|
17086
17488
|
try {
|
|
17087
17489
|
const asset = opts.assets.get(req.url);
|
|
17088
|
-
const bytes = await
|
|
17490
|
+
const bytes = await readFile18(asset.path);
|
|
17089
17491
|
res.writeHead(200, {
|
|
17090
17492
|
"Content-Type": asset.contentType,
|
|
17091
17493
|
"Cache-Control": "no-store",
|
|
@@ -17161,13 +17563,13 @@ async function currentArt(entry, spec) {
|
|
|
17161
17563
|
const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
|
|
17162
17564
|
if (!previous) return null;
|
|
17163
17565
|
const file = resolveOutputPath(previous.path, spec.root);
|
|
17164
|
-
if (!
|
|
17566
|
+
if (!existsSync24(file)) return null;
|
|
17165
17567
|
const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
|
|
17166
17568
|
if (!contentType) return null;
|
|
17167
17569
|
let width = entry.width;
|
|
17168
17570
|
let height = entry.height;
|
|
17169
17571
|
if (contentType === "image/png") {
|
|
17170
|
-
const size = pngSize(await
|
|
17572
|
+
const size = pngSize(await readFile19(file));
|
|
17171
17573
|
if (size) ({ width, height } = size);
|
|
17172
17574
|
}
|
|
17173
17575
|
return { path: file, contentType, width, height };
|
|
@@ -17175,7 +17577,7 @@ async function currentArt(entry, spec) {
|
|
|
17175
17577
|
async function cachedFrame(url) {
|
|
17176
17578
|
if (!url.startsWith("file://")) return null;
|
|
17177
17579
|
const file = url.slice("file://".length);
|
|
17178
|
-
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await
|
|
17580
|
+
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await readFile19(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
|
|
17179
17581
|
return { path: file, contentType };
|
|
17180
17582
|
}
|
|
17181
17583
|
async function prepareReview(provider, lock, opts = {}) {
|
|
@@ -17201,15 +17603,15 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17201
17603
|
const frameAssets = [];
|
|
17202
17604
|
const frameSizes = [];
|
|
17203
17605
|
for (const [index, url] of urls.entries()) {
|
|
17204
|
-
const
|
|
17205
|
-
if (!
|
|
17606
|
+
const cached2 = await cachedFrame(url);
|
|
17607
|
+
if (!cached2) {
|
|
17206
17608
|
frameUrls.push(url);
|
|
17207
17609
|
frameSizes.push(null);
|
|
17208
17610
|
continue;
|
|
17209
17611
|
}
|
|
17210
|
-
frameSizes.push(
|
|
17612
|
+
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await readFile19(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
17211
17613
|
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
17212
|
-
frameAssets.push([route,
|
|
17614
|
+
frameAssets.push([route, cached2]);
|
|
17213
17615
|
frameUrls.push(route);
|
|
17214
17616
|
}
|
|
17215
17617
|
const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String(groups.length))}` : null;
|
|
@@ -17361,14 +17763,14 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
17361
17763
|
|
|
17362
17764
|
// src/gallery/snapshot.ts
|
|
17363
17765
|
import { createHash as createHash5 } from "crypto";
|
|
17364
|
-
import { existsSync as
|
|
17365
|
-
import { readFile as
|
|
17366
|
-
import
|
|
17766
|
+
import { existsSync as existsSync30 } from "fs";
|
|
17767
|
+
import { readFile as readFile26, stat as stat3 } from "fs/promises";
|
|
17768
|
+
import path35 from "path";
|
|
17367
17769
|
|
|
17368
17770
|
// src/workspace.ts
|
|
17369
|
-
import { mkdir as mkdir8, readFile as
|
|
17370
|
-
import { existsSync as
|
|
17371
|
-
import
|
|
17771
|
+
import { mkdir as mkdir8, readFile as readFile20, rename as rename6, rm as rm7, writeFile as writeFile10 } from "fs/promises";
|
|
17772
|
+
import { existsSync as existsSync25 } from "fs";
|
|
17773
|
+
import path28 from "path";
|
|
17372
17774
|
import { z as z7 } from "zod";
|
|
17373
17775
|
var WorkspaceProjectSchema = z7.object({
|
|
17374
17776
|
id: z7.string().min(1),
|
|
@@ -17393,10 +17795,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
|
|
|
17393
17795
|
);
|
|
17394
17796
|
}
|
|
17395
17797
|
async function loadWorkspace(workspacePath) {
|
|
17396
|
-
if (!
|
|
17798
|
+
if (!existsSync25(workspacePath)) return { version: 1, projects: [] };
|
|
17397
17799
|
let raw;
|
|
17398
17800
|
try {
|
|
17399
|
-
raw = JSON.parse(await
|
|
17801
|
+
raw = JSON.parse(await readFile20(workspacePath, "utf8"));
|
|
17400
17802
|
} catch (err) {
|
|
17401
17803
|
throw new ProjectError(
|
|
17402
17804
|
`Workspace catalog at ${workspacePath} is malformed:
|
|
@@ -17410,7 +17812,7 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
17410
17812
|
version: 1,
|
|
17411
17813
|
projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
|
|
17412
17814
|
};
|
|
17413
|
-
await mkdir8(
|
|
17815
|
+
await mkdir8(path28.dirname(path28.resolve(workspacePath)), { recursive: true });
|
|
17414
17816
|
const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
17415
17817
|
try {
|
|
17416
17818
|
await writeFile10(tmp, JSON.stringify(sorted, null, 2) + "\n");
|
|
@@ -17420,12 +17822,12 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
17420
17822
|
}
|
|
17421
17823
|
}
|
|
17422
17824
|
function toPortablePath(dir, absolute) {
|
|
17423
|
-
return
|
|
17825
|
+
return path28.relative(dir, absolute).split(path28.sep).join("/");
|
|
17424
17826
|
}
|
|
17425
17827
|
function resolveProject(dir, project) {
|
|
17426
17828
|
return {
|
|
17427
|
-
manifestPath:
|
|
17428
|
-
lockPath:
|
|
17829
|
+
manifestPath: path28.resolve(dir, project.manifest.split("/").join(path28.sep)),
|
|
17830
|
+
lockPath: path28.resolve(dir, project.lock.split("/").join(path28.sep))
|
|
17429
17831
|
};
|
|
17430
17832
|
}
|
|
17431
17833
|
function validateWorkspace(ws, dir) {
|
|
@@ -17438,21 +17840,21 @@ function validateWorkspace(ws, dir) {
|
|
|
17438
17840
|
const { manifestPath, lockPath } = resolveProject(dir, project);
|
|
17439
17841
|
lockOwners.set(lockPath, [...lockOwners.get(lockPath) ?? [], project.id]);
|
|
17440
17842
|
manifestOwners.set(manifestPath, [...manifestOwners.get(manifestPath) ?? [], project.id]);
|
|
17441
|
-
if (
|
|
17843
|
+
if (path28.isAbsolute(project.manifest) || path28.isAbsolute(project.lock)) {
|
|
17442
17844
|
diagnostics.push({
|
|
17443
17845
|
id: "absolute-path",
|
|
17444
17846
|
level: "warning",
|
|
17445
17847
|
message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
|
|
17446
17848
|
});
|
|
17447
17849
|
}
|
|
17448
|
-
if (!
|
|
17850
|
+
if (!existsSync25(manifestPath)) {
|
|
17449
17851
|
diagnostics.push({
|
|
17450
17852
|
id: "missing-manifest",
|
|
17451
17853
|
level: "error",
|
|
17452
17854
|
message: `project "${project.id}" manifest not found: ${manifestPath}`
|
|
17453
17855
|
});
|
|
17454
17856
|
}
|
|
17455
|
-
if (!
|
|
17857
|
+
if (!existsSync25(lockPath)) {
|
|
17456
17858
|
diagnostics.push({
|
|
17457
17859
|
id: "missing-lock",
|
|
17458
17860
|
level: "error",
|
|
@@ -17499,16 +17901,16 @@ function validateWorkspace(ws, dir) {
|
|
|
17499
17901
|
}
|
|
17500
17902
|
|
|
17501
17903
|
// src/gallery/edit.ts
|
|
17502
|
-
import { readFile as
|
|
17503
|
-
import
|
|
17904
|
+
import { readFile as readFile25, rename as rename9, writeFile as writeFile16 } from "fs/promises";
|
|
17905
|
+
import path34 from "path";
|
|
17504
17906
|
import { z as z13 } from "zod";
|
|
17505
17907
|
|
|
17506
17908
|
// src/manifest-edit.ts
|
|
17507
|
-
import { readFile as
|
|
17508
|
-
import
|
|
17909
|
+
import { readFile as readFile21, rename as rename7, rm as rm8, writeFile as writeFile11 } from "fs/promises";
|
|
17910
|
+
import path29 from "path";
|
|
17509
17911
|
import { z as z8 } from "zod";
|
|
17510
17912
|
var HexSha = z8.string().regex(/^[0-9a-f]{64}$/);
|
|
17511
|
-
var ProjectFileSchema = z8.string().min(1).refine((file) => !
|
|
17913
|
+
var ProjectFileSchema = z8.string().min(1).refine((file) => !path29.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
|
|
17512
17914
|
var AssetPatchSchema = z8.object({
|
|
17513
17915
|
prompt: z8.string().optional(),
|
|
17514
17916
|
/** Per-style override for the style being viewed; null removes it. */
|
|
@@ -17928,8 +18330,8 @@ function applyEdit(raw, edit) {
|
|
|
17928
18330
|
}
|
|
17929
18331
|
}
|
|
17930
18332
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
17931
|
-
const absolute =
|
|
17932
|
-
const original = await
|
|
18333
|
+
const absolute = path29.resolve(manifestPath);
|
|
18334
|
+
const original = await readFile21(absolute, "utf8");
|
|
17933
18335
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
17934
18336
|
let raw;
|
|
17935
18337
|
try {
|
|
@@ -17942,9 +18344,9 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
17942
18344
|
applyEdit(raw, edit);
|
|
17943
18345
|
const next = serializeLike(original, raw);
|
|
17944
18346
|
if (next === original) return unchanged(absolute, original);
|
|
17945
|
-
const tmp =
|
|
17946
|
-
|
|
17947
|
-
`.${
|
|
18347
|
+
const tmp = path29.join(
|
|
18348
|
+
path29.dirname(absolute),
|
|
18349
|
+
`.${path29.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
|
|
17948
18350
|
);
|
|
17949
18351
|
try {
|
|
17950
18352
|
await writeFile11(tmp, next);
|
|
@@ -17973,18 +18375,18 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
17973
18375
|
}
|
|
17974
18376
|
|
|
17975
18377
|
// src/pipeline/hand-edit.ts
|
|
17976
|
-
import { existsSync as
|
|
17977
|
-
import { copyFile, mkdir as mkdir9, readFile as
|
|
17978
|
-
import
|
|
18378
|
+
import { existsSync as existsSync26 } from "fs";
|
|
18379
|
+
import { copyFile, mkdir as mkdir9, readFile as readFile22, rename as rename8, rm as rm9, writeFile as writeFile12 } from "fs/promises";
|
|
18380
|
+
import path30 from "path";
|
|
17979
18381
|
import { z as z9 } from "zod";
|
|
17980
18382
|
var HAND_EDIT_DIR = "edits";
|
|
17981
18383
|
function handEditPath(loaded, spec) {
|
|
17982
18384
|
const style = loaded.manifest.styles[spec.styleId];
|
|
17983
|
-
const outDir =
|
|
17984
|
-
const relative =
|
|
17985
|
-
const inside = relative && !relative.startsWith("..") && !
|
|
17986
|
-
const file = inside ? relative :
|
|
17987
|
-
return
|
|
18385
|
+
const outDir = path30.resolve(loaded.root, style?.outDir ?? ".");
|
|
18386
|
+
const relative = path30.relative(outDir, spec.outFile);
|
|
18387
|
+
const inside = relative && !relative.startsWith("..") && !path30.isAbsolute(relative);
|
|
18388
|
+
const file = inside ? relative : path30.basename(spec.outFile);
|
|
18389
|
+
return path30.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
|
|
17988
18390
|
}
|
|
17989
18391
|
function handEditBases(spec, lock) {
|
|
17990
18392
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -17997,10 +18399,10 @@ function handEditBases(spec, lock) {
|
|
|
17997
18399
|
}));
|
|
17998
18400
|
if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
|
|
17999
18401
|
if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
|
|
18000
|
-
if (!members.every((member) =>
|
|
18402
|
+
if (!members.every((member) => existsSync26(member.path))) return null;
|
|
18001
18403
|
return members.map(({ role, path: file }) => ({ role, path: file }));
|
|
18002
18404
|
}
|
|
18003
|
-
return
|
|
18405
|
+
return existsSync26(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
|
|
18004
18406
|
}
|
|
18005
18407
|
function handEditBase(spec, lock) {
|
|
18006
18408
|
const bases = handEditBases(spec, lock);
|
|
@@ -18030,18 +18432,18 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
18030
18432
|
`${spec.styleId}/${spec.assetId} declares ${spec.source}, one committed file placed for the whole set; clear that source (pixelkiln edit detach) to hand-edit the members one by one`
|
|
18031
18433
|
);
|
|
18032
18434
|
}
|
|
18033
|
-
const existing = spec.source ?
|
|
18435
|
+
const existing = spec.source ? path30.resolve(loaded.root, spec.source) : null;
|
|
18034
18436
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
18035
18437
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
18036
18438
|
let created = false;
|
|
18037
18439
|
for (const member of members) {
|
|
18038
|
-
if (
|
|
18440
|
+
if (existsSync26(member.path)) continue;
|
|
18039
18441
|
if (!member.base) {
|
|
18040
18442
|
throw new ManifestEditError(
|
|
18041
18443
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
18042
18444
|
);
|
|
18043
18445
|
}
|
|
18044
|
-
await mkdir9(
|
|
18446
|
+
await mkdir9(path30.dirname(member.path), { recursive: true });
|
|
18045
18447
|
await copyFile(member.base, member.path);
|
|
18046
18448
|
created = true;
|
|
18047
18449
|
}
|
|
@@ -18120,7 +18522,7 @@ function handEditProjectPath(editPath) {
|
|
|
18120
18522
|
async function readHandEditCompanion(editPath) {
|
|
18121
18523
|
let text;
|
|
18122
18524
|
try {
|
|
18123
|
-
text = await
|
|
18525
|
+
text = await readFile22(handEditCompanionPath(editPath), "utf8");
|
|
18124
18526
|
} catch {
|
|
18125
18527
|
return null;
|
|
18126
18528
|
}
|
|
@@ -18163,7 +18565,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
18163
18565
|
}
|
|
18164
18566
|
});
|
|
18165
18567
|
const bases = handEditBases(spec, lock);
|
|
18166
|
-
const expectedSize = bases?.[0] ? decodePng(await
|
|
18568
|
+
const expectedSize = bases?.[0] ? decodePng(await readFile22(bases[0].path)) : { width: spec.width, height: spec.height };
|
|
18167
18569
|
for (const [index, image] of decoded.entries()) {
|
|
18168
18570
|
if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
|
|
18169
18571
|
const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
|
|
@@ -18179,7 +18581,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
18179
18581
|
editor: input.editor,
|
|
18180
18582
|
protocol: input.protocol,
|
|
18181
18583
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
18182
|
-
project: projectPath ?
|
|
18584
|
+
project: projectPath ? path30.basename(projectPath) : null,
|
|
18183
18585
|
outputs: incoming.map((frame, index) => ({
|
|
18184
18586
|
role: frame.role,
|
|
18185
18587
|
basedOn: basedOnHash(entry, index),
|
|
@@ -18221,9 +18623,9 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
18221
18623
|
}
|
|
18222
18624
|
|
|
18223
18625
|
// src/gallery/upload.ts
|
|
18224
|
-
import { existsSync as
|
|
18626
|
+
import { existsSync as existsSync27 } from "fs";
|
|
18225
18627
|
import { mkdir as mkdir10, writeFile as writeFile13 } from "fs/promises";
|
|
18226
|
-
import
|
|
18628
|
+
import path31 from "path";
|
|
18227
18629
|
import { z as z10 } from "zod";
|
|
18228
18630
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
18229
18631
|
var UploadImageSchema = z10.object({
|
|
@@ -18236,12 +18638,12 @@ var UploadImageSchema = z10.object({
|
|
|
18236
18638
|
overwrite: z10.boolean().optional()
|
|
18237
18639
|
}).strict();
|
|
18238
18640
|
async function saveProjectImage(root, request) {
|
|
18239
|
-
const file =
|
|
18240
|
-
const relative =
|
|
18241
|
-
if (relative.startsWith("..") ||
|
|
18641
|
+
const file = path31.resolve(root, request.path);
|
|
18642
|
+
const relative = path31.relative(root, file);
|
|
18643
|
+
if (relative.startsWith("..") || path31.isAbsolute(relative)) {
|
|
18242
18644
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
18243
18645
|
}
|
|
18244
|
-
const extension =
|
|
18646
|
+
const extension = path31.extname(file).toLowerCase();
|
|
18245
18647
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
18246
18648
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
18247
18649
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -18253,18 +18655,18 @@ async function saveProjectImage(root, request) {
|
|
|
18253
18655
|
if (metadata.format !== expected) {
|
|
18254
18656
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
18255
18657
|
}
|
|
18256
|
-
if (
|
|
18257
|
-
throw new ManifestEditError(`${relative.split(
|
|
18658
|
+
if (existsSync27(file) && !request.overwrite) {
|
|
18659
|
+
throw new ManifestEditError(`${relative.split(path31.sep).join("/")} already exists; choose another name, or replace it`);
|
|
18258
18660
|
}
|
|
18259
|
-
await mkdir10(
|
|
18661
|
+
await mkdir10(path31.dirname(file), { recursive: true });
|
|
18260
18662
|
await writeFile13(file, bytes);
|
|
18261
|
-
return relative.split(
|
|
18663
|
+
return relative.split(path31.sep).join("/");
|
|
18262
18664
|
}
|
|
18263
18665
|
|
|
18264
18666
|
// src/gallery/image-revision.ts
|
|
18265
|
-
import { existsSync as
|
|
18266
|
-
import { readFile as
|
|
18267
|
-
import
|
|
18667
|
+
import { existsSync as existsSync28 } from "fs";
|
|
18668
|
+
import { readFile as readFile23, rm as rm10, writeFile as writeFile14 } from "fs/promises";
|
|
18669
|
+
import path32 from "path";
|
|
18268
18670
|
import { z as z11 } from "zod";
|
|
18269
18671
|
var InpaintRevisionRequestSchema = z11.object({
|
|
18270
18672
|
action: z11.literal("create-inpaint-revision"),
|
|
@@ -18283,15 +18685,15 @@ var InpaintRevisionRequestSchema = z11.object({
|
|
|
18283
18685
|
overwrite: z11.boolean().optional()
|
|
18284
18686
|
}).strict();
|
|
18285
18687
|
async function createInpaintRevision(manifestPath, request) {
|
|
18286
|
-
const root =
|
|
18287
|
-
if (
|
|
18688
|
+
const root = path32.dirname(path32.resolve(manifestPath));
|
|
18689
|
+
if (path32.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
18288
18690
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
18289
18691
|
}
|
|
18290
18692
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
18291
18693
|
const metadata = imageMetadata(bytes);
|
|
18292
18694
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
18293
|
-
const file =
|
|
18294
|
-
const previous =
|
|
18695
|
+
const file = path32.resolve(root, request.maskPath);
|
|
18696
|
+
const previous = existsSync28(file) ? await readFile23(file) : null;
|
|
18295
18697
|
const mask = await saveProjectImage(root, {
|
|
18296
18698
|
action: "upload-image",
|
|
18297
18699
|
path: request.maskPath,
|
|
@@ -18318,9 +18720,9 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
18318
18720
|
}
|
|
18319
18721
|
|
|
18320
18722
|
// src/gallery/skeleton.ts
|
|
18321
|
-
import { existsSync as
|
|
18322
|
-
import { mkdir as mkdir11, readFile as
|
|
18323
|
-
import
|
|
18723
|
+
import { existsSync as existsSync29 } from "fs";
|
|
18724
|
+
import { mkdir as mkdir11, readFile as readFile24, rm as rm11, writeFile as writeFile15 } from "fs/promises";
|
|
18725
|
+
import path33 from "path";
|
|
18324
18726
|
import { z as z12 } from "zod";
|
|
18325
18727
|
var SkeletonEstimateRequestSchema = z12.object({
|
|
18326
18728
|
project: z12.string().min(1).optional(),
|
|
@@ -18359,20 +18761,20 @@ var SkeletonKeypointsUpdateSchema = z12.object({
|
|
|
18359
18761
|
set: SkeletonSetSchema
|
|
18360
18762
|
}).strict();
|
|
18361
18763
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
18362
|
-
const root =
|
|
18363
|
-
const file =
|
|
18364
|
-
const relative =
|
|
18365
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
18764
|
+
const root = path33.dirname(path33.resolve(manifestPath));
|
|
18765
|
+
const file = path33.resolve(root, request.keypointsFile);
|
|
18766
|
+
const relative = path33.relative(root, file);
|
|
18767
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path33.isAbsolute(relative)) {
|
|
18366
18768
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
18367
18769
|
}
|
|
18368
|
-
const existed =
|
|
18770
|
+
const existed = existsSync29(file);
|
|
18369
18771
|
let previous = null;
|
|
18370
18772
|
if (request.set) {
|
|
18371
18773
|
if (existed && !request.overwrite) {
|
|
18372
18774
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
18373
18775
|
}
|
|
18374
|
-
if (existed) previous = await
|
|
18375
|
-
await mkdir11(
|
|
18776
|
+
if (existed) previous = await readFile24(file);
|
|
18777
|
+
await mkdir11(path33.dirname(file), { recursive: true });
|
|
18376
18778
|
await writeFile15(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18377
18779
|
} else if (!existed) {
|
|
18378
18780
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
@@ -18388,7 +18790,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
18388
18790
|
revision: {
|
|
18389
18791
|
mode: "animate-skeleton",
|
|
18390
18792
|
from: request.from,
|
|
18391
|
-
keypointsFile: relative.split(
|
|
18793
|
+
keypointsFile: relative.split(path33.sep).join("/"),
|
|
18392
18794
|
direction: request.direction,
|
|
18393
18795
|
description: request.description,
|
|
18394
18796
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -18409,19 +18811,19 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
18409
18811
|
if (!spec) throw new ManifestEditError(`"${key}" is not declared by the manifest`);
|
|
18410
18812
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
18411
18813
|
if (!file) throw new ManifestEditError(`${key} is not an animate-skeleton revision`);
|
|
18412
|
-
const relative =
|
|
18413
|
-
if (relative.startsWith("..") ||
|
|
18814
|
+
const relative = path33.relative(ctx.loaded.root, file);
|
|
18815
|
+
if (relative.startsWith("..") || path33.isAbsolute(relative)) {
|
|
18414
18816
|
throw new ManifestEditError(`${key}'s keypoints file is outside the project; edit it by hand`);
|
|
18415
18817
|
}
|
|
18416
|
-
const current =
|
|
18818
|
+
const current = existsSync29(file) ? sha256(await readFile24(file)) : null;
|
|
18417
18819
|
if (current !== request.expectedSha256) {
|
|
18418
18820
|
throw Object.assign(
|
|
18419
|
-
new Error(`${relative.split(
|
|
18821
|
+
new Error(`${relative.split(path33.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
18420
18822
|
{ status: 409 }
|
|
18421
18823
|
);
|
|
18422
18824
|
}
|
|
18423
18825
|
await writeFile15(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18424
|
-
return relative.split(
|
|
18826
|
+
return relative.split(path33.sep).join("/");
|
|
18425
18827
|
}
|
|
18426
18828
|
|
|
18427
18829
|
// src/gallery/edit.ts
|
|
@@ -18475,7 +18877,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18475
18877
|
const history = /* @__PURE__ */ new Map();
|
|
18476
18878
|
const manifestOf = async (project) => {
|
|
18477
18879
|
try {
|
|
18478
|
-
return
|
|
18880
|
+
return path34.resolve(await opts.manifestFor(typeof project === "string" ? project : void 0));
|
|
18479
18881
|
} catch {
|
|
18480
18882
|
return null;
|
|
18481
18883
|
}
|
|
@@ -18485,7 +18887,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18485
18887
|
if (undo.success) {
|
|
18486
18888
|
const manifestPath2 = await manifestOf(undo.data.project);
|
|
18487
18889
|
if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
|
|
18488
|
-
const current = await
|
|
18890
|
+
const current = await readFile25(manifestPath2, "utf8");
|
|
18489
18891
|
if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
|
|
18490
18892
|
const stack = history.get(manifestPath2) ?? [];
|
|
18491
18893
|
const last = stack[stack.length - 1];
|
|
@@ -18498,14 +18900,14 @@ function createGalleryEditHandler(opts) {
|
|
|
18498
18900
|
await writeFile16(tmp, last.before);
|
|
18499
18901
|
await rename9(tmp, manifestPath2);
|
|
18500
18902
|
stack.pop();
|
|
18501
|
-
log(` manifest edit undone in ${
|
|
18903
|
+
log(` manifest edit undone in ${path34.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
18502
18904
|
return opts.reload();
|
|
18503
18905
|
}
|
|
18504
18906
|
const manifestPath = await manifestOf(body?.project);
|
|
18505
|
-
const before = manifestPath ? await
|
|
18907
|
+
const before = manifestPath ? await readFile25(manifestPath, "utf8").catch(() => null) : null;
|
|
18506
18908
|
const build = await apply(body);
|
|
18507
18909
|
if (manifestPath && before !== null) {
|
|
18508
|
-
const after = await
|
|
18910
|
+
const after = await readFile25(manifestPath, "utf8").catch(() => null);
|
|
18509
18911
|
if (after !== null && after !== before) {
|
|
18510
18912
|
const stack = history.get(manifestPath) ?? [];
|
|
18511
18913
|
stack.push({ before, afterSha: sha256(after) });
|
|
@@ -18560,7 +18962,7 @@ function createEditApplier(opts, log) {
|
|
|
18560
18962
|
} catch (error) {
|
|
18561
18963
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
18562
18964
|
}
|
|
18563
|
-
const written = await saveProjectImage(
|
|
18965
|
+
const written = await saveProjectImage(path34.dirname(path34.resolve(manifestPath2)), upload.data);
|
|
18564
18966
|
log(` image added: ${written}`);
|
|
18565
18967
|
return opts.reload();
|
|
18566
18968
|
}
|
|
@@ -18627,7 +19029,7 @@ function createEditApplier(opts, log) {
|
|
|
18627
19029
|
}
|
|
18628
19030
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
18629
19031
|
if (result.changed) {
|
|
18630
|
-
const relative =
|
|
19032
|
+
const relative = path34.relative(process.cwd(), result.manifestPath);
|
|
18631
19033
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
18632
19034
|
log(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
18633
19035
|
}
|
|
@@ -18655,7 +19057,7 @@ function describeEdit(edit) {
|
|
|
18655
19057
|
// src/gallery/snapshot.ts
|
|
18656
19058
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
18657
19059
|
function galleryMediaId(absolutePath) {
|
|
18658
|
-
return createHash5("sha256").update(
|
|
19060
|
+
return createHash5("sha256").update(path35.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
18659
19061
|
}
|
|
18660
19062
|
function galleryMediaRoute(id) {
|
|
18661
19063
|
return `/media/${id}`;
|
|
@@ -18679,9 +19081,9 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
18679
19081
|
return (entry.history ?? []).map((generation, i) => {
|
|
18680
19082
|
const outputs = generation.outputs.map((output) => {
|
|
18681
19083
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
18682
|
-
const file =
|
|
19084
|
+
const file = path35.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
18683
19085
|
let url = null;
|
|
18684
|
-
if (
|
|
19086
|
+
if (existsSync30(file)) {
|
|
18685
19087
|
const id = galleryMediaId(file);
|
|
18686
19088
|
media.set(id, { path: file, contentType: mediaType });
|
|
18687
19089
|
url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
|
|
@@ -18713,7 +19115,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
18713
19115
|
var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
|
|
18714
19116
|
async function samePixels(a, b) {
|
|
18715
19117
|
try {
|
|
18716
|
-
const [left, right] = await Promise.all([
|
|
19118
|
+
const [left, right] = await Promise.all([readFile26(a), readFile26(b)]);
|
|
18717
19119
|
if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
|
|
18718
19120
|
const x = decodePng(left);
|
|
18719
19121
|
const y = decodePng(right);
|
|
@@ -18811,10 +19213,10 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
18811
19213
|
async function describeQuality(media, root, inspection) {
|
|
18812
19214
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
18813
19215
|
const outputs = await Promise.all(
|
|
18814
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
19216
|
+
outputPaths.map((file) => describeOutput(media, root, path35.resolve(root, file)))
|
|
18815
19217
|
);
|
|
18816
|
-
const recordPath =
|
|
18817
|
-
const recordExists =
|
|
19218
|
+
const recordPath = path35.resolve(root, inspection.record);
|
|
19219
|
+
const recordExists = existsSync30(recordPath);
|
|
18818
19220
|
let options = null;
|
|
18819
19221
|
let check = null;
|
|
18820
19222
|
if (recordExists) {
|
|
@@ -18833,7 +19235,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
18833
19235
|
return {
|
|
18834
19236
|
state: inspection.state,
|
|
18835
19237
|
reason: inspection.reason,
|
|
18836
|
-
output: portableOutputPath(
|
|
19238
|
+
output: portableOutputPath(path35.resolve(root, inspection.output), root),
|
|
18837
19239
|
record: portableOutputPath(recordPath, root),
|
|
18838
19240
|
recordExists,
|
|
18839
19241
|
outputs,
|
|
@@ -18871,9 +19273,9 @@ async function buildGallerySnapshot(opts) {
|
|
|
18871
19273
|
const media = /* @__PURE__ */ new Map();
|
|
18872
19274
|
const plan = await buildPlan(specs, lock);
|
|
18873
19275
|
const items = [];
|
|
18874
|
-
const manifestText = await
|
|
19276
|
+
const manifestText = await readFile26(loaded.path, "utf8");
|
|
18875
19277
|
const manifestSha256 = sha256(manifestText);
|
|
18876
|
-
const cacheDir =
|
|
19278
|
+
const cacheDir = path35.resolve(path35.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
18877
19279
|
let rawStyles = {};
|
|
18878
19280
|
try {
|
|
18879
19281
|
const raw = JSON.parse(manifestText);
|
|
@@ -18897,12 +19299,12 @@ async function buildGallerySnapshot(opts) {
|
|
|
18897
19299
|
)
|
|
18898
19300
|
);
|
|
18899
19301
|
if (spec.source) {
|
|
18900
|
-
const editPath =
|
|
19302
|
+
const editPath = path35.resolve(root, spec.source);
|
|
18901
19303
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
18902
19304
|
const editShas = await Promise.all(
|
|
18903
19305
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
18904
19306
|
const file = sourceOutputPath(spec.source, entry, index, root);
|
|
18905
|
-
return { file, sha256:
|
|
19307
|
+
return { file, sha256: existsSync30(file) ? await sha256File(file) : null };
|
|
18906
19308
|
})
|
|
18907
19309
|
);
|
|
18908
19310
|
edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
|
|
@@ -18910,7 +19312,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18910
19312
|
const companion = await readHandEditCompanion(editPath);
|
|
18911
19313
|
if (companion) {
|
|
18912
19314
|
const projectPath = handEditProjectPath(editPath);
|
|
18913
|
-
const project = companion.project &&
|
|
19315
|
+
const project = companion.project && existsSync30(projectPath) ? await fileInfo(projectPath) : null;
|
|
18914
19316
|
let projectUrl = null;
|
|
18915
19317
|
if (project) {
|
|
18916
19318
|
const id = galleryMediaId(projectPath);
|
|
@@ -18946,8 +19348,8 @@ async function buildGallerySnapshot(opts) {
|
|
|
18946
19348
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
18947
19349
|
}
|
|
18948
19350
|
} else if (spec.source) {
|
|
18949
|
-
outputs = [await describeOutput(media, root,
|
|
18950
|
-
} else if (!entry &&
|
|
19351
|
+
outputs = [await describeOutput(media, root, path35.resolve(root, spec.source))];
|
|
19352
|
+
} else if (!entry && existsSync30(spec.outFile)) {
|
|
18951
19353
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
18952
19354
|
} else {
|
|
18953
19355
|
outputs = [];
|
|
@@ -19151,7 +19553,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19151
19553
|
id: loaded.manifest.name,
|
|
19152
19554
|
name: loaded.manifest.name,
|
|
19153
19555
|
manifest: loaded.path,
|
|
19154
|
-
lock:
|
|
19556
|
+
lock: path35.resolve(opts.lockPath),
|
|
19155
19557
|
root,
|
|
19156
19558
|
provider: loaded.manifest.provider,
|
|
19157
19559
|
account: null,
|
|
@@ -19177,7 +19579,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19177
19579
|
return { snapshot, media };
|
|
19178
19580
|
}
|
|
19179
19581
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
19180
|
-
const dir =
|
|
19582
|
+
const dir = path35.dirname(path35.resolve(opts.workspacePath));
|
|
19181
19583
|
const media = /* @__PURE__ */ new Map();
|
|
19182
19584
|
const projects = [];
|
|
19183
19585
|
const items = [];
|
|
@@ -19220,11 +19622,11 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19220
19622
|
id: project.id,
|
|
19221
19623
|
name: loaded.manifest.name,
|
|
19222
19624
|
manifest: manifestPath,
|
|
19223
|
-
lock:
|
|
19625
|
+
lock: path35.resolve(lockPath),
|
|
19224
19626
|
root: loaded.root,
|
|
19225
19627
|
provider: loaded.manifest.provider,
|
|
19226
19628
|
account: project.account ?? null,
|
|
19227
|
-
manifestSha256: manifestSha256 ?? sha256(await
|
|
19629
|
+
manifestSha256: manifestSha256 ?? sha256(await readFile26(manifestPath, "utf8")),
|
|
19228
19630
|
historyLimit: historyLimit(loaded.manifest),
|
|
19229
19631
|
entries: Object.keys(lock.entries).length,
|
|
19230
19632
|
items: projectItems.length,
|
|
@@ -19236,8 +19638,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19236
19638
|
id: project.id,
|
|
19237
19639
|
name: project.id,
|
|
19238
19640
|
manifest: manifestPath,
|
|
19239
|
-
lock:
|
|
19240
|
-
root:
|
|
19641
|
+
lock: path35.resolve(lockPath),
|
|
19642
|
+
root: path35.dirname(manifestPath),
|
|
19241
19643
|
provider: project.provider,
|
|
19242
19644
|
account: project.account ?? null,
|
|
19243
19645
|
manifestSha256: null,
|
|
@@ -19264,7 +19666,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19264
19666
|
version: 1,
|
|
19265
19667
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
19266
19668
|
project: null,
|
|
19267
|
-
workspace: { path:
|
|
19669
|
+
workspace: { path: path35.resolve(opts.workspacePath), dir, projects },
|
|
19268
19670
|
filter,
|
|
19269
19671
|
totals: {
|
|
19270
19672
|
entries: projects.reduce((sum, project) => sum + project.entries, 0),
|
|
@@ -19281,7 +19683,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19281
19683
|
}
|
|
19282
19684
|
|
|
19283
19685
|
// src/gallery/page.ts
|
|
19284
|
-
import { existsSync as
|
|
19686
|
+
import { existsSync as existsSync31, readFileSync as readFileSync8 } from "fs";
|
|
19285
19687
|
|
|
19286
19688
|
// src/gallery/client-bundle.ts
|
|
19287
19689
|
import { createRequire } from "module";
|
|
@@ -19321,8 +19723,8 @@ var client;
|
|
|
19321
19723
|
function clientAssets() {
|
|
19322
19724
|
const prebuilt = new URL("gallery.js", CLIENT_DIR);
|
|
19323
19725
|
client ??= {
|
|
19324
|
-
css:
|
|
19325
|
-
js:
|
|
19726
|
+
css: readFileSync8(new URL("gallery.css", CLIENT_DIR), "utf8"),
|
|
19727
|
+
js: existsSync31(prebuilt) ? readFileSync8(prebuilt, "utf8") : bundleGalleryClient()
|
|
19326
19728
|
};
|
|
19327
19729
|
return client;
|
|
19328
19730
|
}
|
|
@@ -19465,10 +19867,10 @@ var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download
|
|
|
19465
19867
|
|
|
19466
19868
|
// src/editor/install.ts
|
|
19467
19869
|
import { createHash as createHash6 } from "crypto";
|
|
19468
|
-
import { existsSync as
|
|
19469
|
-
import { mkdir as mkdir12, readFile as
|
|
19870
|
+
import { existsSync as existsSync32 } from "fs";
|
|
19871
|
+
import { mkdir as mkdir12, readFile as readFile27, rename as rename10, rm as rm12, stat as stat4, writeFile as writeFile17 } from "fs/promises";
|
|
19470
19872
|
import os3 from "os";
|
|
19471
|
-
import
|
|
19873
|
+
import path36 from "path";
|
|
19472
19874
|
var EditorInstallError = class extends Error {
|
|
19473
19875
|
constructor(message6, file) {
|
|
19474
19876
|
super(message6);
|
|
@@ -19479,15 +19881,15 @@ var EditorInstallError = class extends Error {
|
|
|
19479
19881
|
};
|
|
19480
19882
|
function editorToolsRoot() {
|
|
19481
19883
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
19482
|
-
if (override) return
|
|
19483
|
-
if (process.platform === "darwin") return
|
|
19884
|
+
if (override) return path36.resolve(override);
|
|
19885
|
+
if (process.platform === "darwin") return path36.join(os3.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
19484
19886
|
if (process.platform === "win32") {
|
|
19485
|
-
return
|
|
19887
|
+
return path36.join(process.env.LOCALAPPDATA ?? path36.join(os3.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
19486
19888
|
}
|
|
19487
|
-
return
|
|
19889
|
+
return path36.join(process.env.XDG_CACHE_HOME ?? path36.join(os3.homedir(), ".cache"), "pixelkiln", "tools");
|
|
19488
19890
|
}
|
|
19489
19891
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
19490
|
-
return
|
|
19892
|
+
return path36.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
19491
19893
|
}
|
|
19492
19894
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
19493
19895
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -19497,7 +19899,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
|
|
|
19497
19899
|
}
|
|
19498
19900
|
async function sha256Of(file) {
|
|
19499
19901
|
try {
|
|
19500
|
-
return createHash6("sha256").update(await
|
|
19902
|
+
return createHash6("sha256").update(await readFile27(file)).digest("hex");
|
|
19501
19903
|
} catch {
|
|
19502
19904
|
return null;
|
|
19503
19905
|
}
|
|
@@ -19510,8 +19912,8 @@ async function editorStatus(opts = {}) {
|
|
|
19510
19912
|
let totalBytes = 0;
|
|
19511
19913
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
19512
19914
|
totalBytes += expected.bytes;
|
|
19513
|
-
const file =
|
|
19514
|
-
const info =
|
|
19915
|
+
const file = path36.join(dir, name);
|
|
19916
|
+
const info = existsSync32(file) ? await stat4(file).catch(() => null) : null;
|
|
19515
19917
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
19516
19918
|
installedBytes += expected.bytes;
|
|
19517
19919
|
} else {
|
|
@@ -19568,7 +19970,7 @@ async function installEditor(opts = {}) {
|
|
|
19568
19970
|
if (digest2 !== expected.sha256) {
|
|
19569
19971
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
19570
19972
|
}
|
|
19571
|
-
const final =
|
|
19973
|
+
const final = path36.join(dir, name);
|
|
19572
19974
|
const tmp = `${final}.${process.pid}.part`;
|
|
19573
19975
|
try {
|
|
19574
19976
|
await writeFile17(tmp, bytes);
|
|
@@ -19614,12 +20016,12 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
19614
20016
|
".json": "application/json; charset=utf-8"
|
|
19615
20017
|
};
|
|
19616
20018
|
function editorContentType(name) {
|
|
19617
|
-
return EDITOR_CONTENT_TYPES[
|
|
20019
|
+
return EDITOR_CONTENT_TYPES[path36.extname(name).toLowerCase()] ?? null;
|
|
19618
20020
|
}
|
|
19619
20021
|
|
|
19620
20022
|
// src/gallery/editor.ts
|
|
19621
|
-
import { readFile as
|
|
19622
|
-
import
|
|
20023
|
+
import { readFile as readFile28 } from "fs/promises";
|
|
20024
|
+
import path37 from "path";
|
|
19623
20025
|
function editorRoute(release, name = "index.html") {
|
|
19624
20026
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
19625
20027
|
}
|
|
@@ -19692,7 +20094,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
19692
20094
|
if (!status.installed) return null;
|
|
19693
20095
|
let bytes;
|
|
19694
20096
|
try {
|
|
19695
|
-
bytes = await
|
|
20097
|
+
bytes = await readFile28(path37.join(dir, name));
|
|
19696
20098
|
} catch {
|
|
19697
20099
|
verified = null;
|
|
19698
20100
|
return null;
|
|
@@ -19709,7 +20111,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
19709
20111
|
// src/gallery/server.ts
|
|
19710
20112
|
import { randomBytes } from "crypto";
|
|
19711
20113
|
import { createServer as createServer2 } from "http";
|
|
19712
|
-
import { readFile as
|
|
20114
|
+
import { readFile as readFile29 } from "fs/promises";
|
|
19713
20115
|
var MAX_EDIT_BYTES = 48 * 1024 * 1024;
|
|
19714
20116
|
var EDITOR_CSP = [
|
|
19715
20117
|
"default-src 'self'",
|
|
@@ -19890,7 +20292,7 @@ async function serveGallery(opts) {
|
|
|
19890
20292
|
const asset = reviewAssets.get(jobId)?.get(url2.pathname);
|
|
19891
20293
|
if (!asset) return fail(404, "no such review asset");
|
|
19892
20294
|
try {
|
|
19893
|
-
const bytes = await
|
|
20295
|
+
const bytes = await readFile29(asset.path);
|
|
19894
20296
|
res.writeHead(200, {
|
|
19895
20297
|
"Content-Type": asset.contentType,
|
|
19896
20298
|
"Cache-Control": "no-store",
|
|
@@ -19973,7 +20375,7 @@ async function serveGallery(opts) {
|
|
|
19973
20375
|
if (!asset) return fail(404, "no such gallery media");
|
|
19974
20376
|
let bytes;
|
|
19975
20377
|
try {
|
|
19976
|
-
bytes = await
|
|
20378
|
+
bytes = await readFile29(asset.path);
|
|
19977
20379
|
} catch {
|
|
19978
20380
|
return fail(404, "gallery media is no longer on disk; refresh the page");
|
|
19979
20381
|
}
|
|
@@ -20383,19 +20785,19 @@ function createGenerateHandlers(opts) {
|
|
|
20383
20785
|
}
|
|
20384
20786
|
|
|
20385
20787
|
// src/pipeline/salvage.ts
|
|
20386
|
-
import { readFile as
|
|
20387
|
-
import { existsSync as
|
|
20388
|
-
import
|
|
20788
|
+
import { readFile as readFile30 } from "fs/promises";
|
|
20789
|
+
import { existsSync as existsSync33 } from "fs";
|
|
20790
|
+
import path38 from "path";
|
|
20389
20791
|
function providerClaimId(provider, objectId) {
|
|
20390
20792
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
20391
20793
|
}
|
|
20392
20794
|
async function loadClaims(lockPaths, opts = {}) {
|
|
20393
20795
|
const claimed = /* @__PURE__ */ new Set();
|
|
20394
20796
|
for (const p of lockPaths) {
|
|
20395
|
-
if (!
|
|
20797
|
+
if (!existsSync33(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
20396
20798
|
let parsed;
|
|
20397
20799
|
try {
|
|
20398
|
-
parsed = parseLock(JSON.parse(await
|
|
20800
|
+
parsed = parseLock(JSON.parse(await readFile30(p, "utf8")));
|
|
20399
20801
|
} catch {
|
|
20400
20802
|
throw new Error(`Claim lockfile is malformed: ${p}`);
|
|
20401
20803
|
}
|
|
@@ -20499,20 +20901,20 @@ function matchOrphanStyle(prompt, manifest) {
|
|
|
20499
20901
|
return matchStyleByPattern(prompt, manifest);
|
|
20500
20902
|
}
|
|
20501
20903
|
async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
|
|
20502
|
-
const own =
|
|
20904
|
+
const own = path38.resolve(ownManifestPath);
|
|
20503
20905
|
const siblingManifestPaths = [
|
|
20504
20906
|
.../* @__PURE__ */ new Set([
|
|
20505
20907
|
...workspaceManifestPaths,
|
|
20506
|
-
...claimPaths.map((c) =>
|
|
20908
|
+
...claimPaths.map((c) => path38.join(path38.dirname(path38.resolve(c)), "pixelkiln.manifest.json"))
|
|
20507
20909
|
])
|
|
20508
20910
|
];
|
|
20509
20911
|
const siblings = [];
|
|
20510
20912
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
20511
|
-
if (
|
|
20512
|
-
if (!
|
|
20913
|
+
if (path38.resolve(siblingManifestPath) === own) continue;
|
|
20914
|
+
if (!existsSync33(siblingManifestPath)) continue;
|
|
20513
20915
|
try {
|
|
20514
20916
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
20515
|
-
siblings.push({ label:
|
|
20917
|
+
siblings.push({ label: path38.basename(path38.dirname(siblingManifestPath)), manifest });
|
|
20516
20918
|
} catch {
|
|
20517
20919
|
}
|
|
20518
20920
|
}
|
|
@@ -20632,8 +21034,8 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
20632
21034
|
}
|
|
20633
21035
|
|
|
20634
21036
|
// src/pick/salvage-server.ts
|
|
20635
|
-
import { mkdir as mkdir13, writeFile as writeFile18, readFile as
|
|
20636
|
-
import
|
|
21037
|
+
import { mkdir as mkdir13, writeFile as writeFile18, readFile as readFile31 } from "fs/promises";
|
|
21038
|
+
import path39 from "path";
|
|
20637
21039
|
|
|
20638
21040
|
// src/pick/salvage-sheet.ts
|
|
20639
21041
|
var escapeHtml3 = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -20799,7 +21201,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
20799
21201
|
});
|
|
20800
21202
|
const html = renderSalvageSheet(orphans, {
|
|
20801
21203
|
styleId: ctx.styleId,
|
|
20802
|
-
importDir:
|
|
21204
|
+
importDir: path39.relative(process.cwd(), ctx.importDir) || "."
|
|
20803
21205
|
});
|
|
20804
21206
|
const byId = new Map(orphans.map((o) => [o.id, o]));
|
|
20805
21207
|
const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
|
|
@@ -20855,9 +21257,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
20855
21257
|
if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
|
|
20856
21258
|
decodePng(buf);
|
|
20857
21259
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
20858
|
-
const rel =
|
|
20859
|
-
const outFile =
|
|
20860
|
-
await mkdir13(
|
|
21260
|
+
const rel = path39.join("_salvaged", `${assetId}.png`);
|
|
21261
|
+
const outFile = path39.resolve(ctx.importDir, rel);
|
|
21262
|
+
await mkdir13(path39.dirname(outFile), { recursive: true });
|
|
20861
21263
|
await writeFile18(outFile, buf);
|
|
20862
21264
|
ctx.manifest.assets[assetId] = {
|
|
20863
21265
|
prompt: orphan.prompt,
|
|
@@ -20890,7 +21292,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
20890
21292
|
sourceUrl: durableSource,
|
|
20891
21293
|
sourceUrls: durableSource ? [{ url: durableSource }] : [],
|
|
20892
21294
|
outputs: [{
|
|
20893
|
-
path: portableOutputPath(outFile,
|
|
21295
|
+
path: portableOutputPath(outFile, path39.dirname(ctx.manifestPath)),
|
|
20894
21296
|
sha256: sha256(buf)
|
|
20895
21297
|
}],
|
|
20896
21298
|
submittedAt: orphan.createdAt,
|
|
@@ -20914,7 +21316,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
20914
21316
|
}
|
|
20915
21317
|
}
|
|
20916
21318
|
await applyTags(provider, decisions, existingTags, { onProgress: log, characters: characterMembers });
|
|
20917
|
-
const raw = JSON.parse(await
|
|
21319
|
+
const raw = JSON.parse(await readFile31(ctx.manifestPath, "utf8"));
|
|
20918
21320
|
for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
|
|
20919
21321
|
await writeFile18(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
|
|
20920
21322
|
await saveLock(ctx.lockPath, ctx.lock);
|
|
@@ -21139,6 +21541,7 @@ export {
|
|
|
21139
21541
|
availableProviders,
|
|
21140
21542
|
backoffMs,
|
|
21141
21543
|
buildGallerySnapshot,
|
|
21544
|
+
buildImportedEntry,
|
|
21142
21545
|
buildManifest,
|
|
21143
21546
|
buildPlan,
|
|
21144
21547
|
buildWorkspaceGallerySnapshot,
|
|
@@ -21201,6 +21604,7 @@ export {
|
|
|
21201
21604
|
historyLimit,
|
|
21202
21605
|
idFromPrompt,
|
|
21203
21606
|
imageMetadata,
|
|
21607
|
+
importLocal,
|
|
21204
21608
|
inspectCaches,
|
|
21205
21609
|
inspectQualityProfile,
|
|
21206
21610
|
inspectRevisionReadiness,
|
|
@@ -21293,6 +21697,7 @@ export {
|
|
|
21293
21697
|
renderSalvageSheet,
|
|
21294
21698
|
renderSheet,
|
|
21295
21699
|
renderSheetDocument,
|
|
21700
|
+
reportSpecHashes,
|
|
21296
21701
|
requireApprovedQualitySources,
|
|
21297
21702
|
requireBalance,
|
|
21298
21703
|
requireDelete,
|
|
@@ -21332,6 +21737,7 @@ export {
|
|
|
21332
21737
|
sliceVfxSheet,
|
|
21333
21738
|
slugify,
|
|
21334
21739
|
snapshotQualityBaseline,
|
|
21740
|
+
snapshotQualityCases,
|
|
21335
21741
|
sourceIsStem,
|
|
21336
21742
|
sourceOutputPath,
|
|
21337
21743
|
specHash,
|