pixelkiln 0.94.0 → 0.95.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 +3677 -3301
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1160 -785
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +718 -23
- package/dist/index.d.ts +718 -23
- package/dist/index.js +1126 -753
- package/dist/index.js.map +1 -1
- package/docs/MANIFEST.md +51 -1
- package/package.json +1 -1
- package/schema/manifest.schema.json +81 -0
package/dist/index.js
CHANGED
|
@@ -283,12 +283,12 @@ var AssetVfxSchema = z.object({
|
|
|
283
283
|
artist: z.enum(["lite", "pro"]).optional()
|
|
284
284
|
}).strict().superRefine((vfx, context) => {
|
|
285
285
|
if (vfx.description !== void 0) {
|
|
286
|
-
for (const
|
|
287
|
-
if (vfx[
|
|
286
|
+
for (const key2 of ["preset", "recipe", "parts", "fps"]) {
|
|
287
|
+
if (vfx[key2] !== void 0) {
|
|
288
288
|
context.addIssue({
|
|
289
289
|
code: z.ZodIssueCode.custom,
|
|
290
|
-
message: `a vfx description goes to PixelLab's VFX artist, which takes no ${
|
|
291
|
-
path: [
|
|
290
|
+
message: `a vfx description goes to PixelLab's VFX artist, which takes no ${key2}; use a description or the workbench's preset/recipe/parts/fps, not both`,
|
|
291
|
+
path: [key2]
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
@@ -407,18 +407,18 @@ var CharacterAnimationSchema = z.object({
|
|
|
407
407
|
context.addIssue({ code: z.ZodIssueCode.custom, message: "a skeleton-v3 loop from a sentence takes 3 to 15 frames", path: ["frames"] });
|
|
408
408
|
}
|
|
409
409
|
const mode2 = animation.mode ?? (animation.template ? "template" : "v3");
|
|
410
|
-
for (const
|
|
411
|
-
if (animation[
|
|
410
|
+
for (const key2 of ["startFrame", "endFrame", "enhancePrompt"]) {
|
|
411
|
+
if (animation[key2] !== void 0 && mode2 !== "v3") {
|
|
412
412
|
context.addIssue({
|
|
413
413
|
code: z.ZodIssueCode.custom,
|
|
414
|
-
message: `${
|
|
415
|
-
path: [
|
|
414
|
+
message: `${key2} is for v3 loops; a ${mode2} loop ${mode2 === "template" || mode2 === "skeleton-v3" ? `starts from the character's rotation and ${animation.template ? "follows its template" : "animates its sentence"}` : "takes neither"}`,
|
|
415
|
+
path: [key2]
|
|
416
416
|
});
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
|
-
for (const
|
|
420
|
-
if (animation[
|
|
421
|
-
context.addIssue({ code: z.ZodIssueCode.custom, message: `${
|
|
419
|
+
for (const key2 of ["outline", "shading", "detail"]) {
|
|
420
|
+
if (animation[key2] !== void 0 && mode2 !== "template") {
|
|
421
|
+
context.addIssue({ code: z.ZodIssueCode.custom, message: `${key2} overrides apply to template loops only`, path: [key2] });
|
|
422
422
|
}
|
|
423
423
|
}
|
|
424
424
|
if (animation.template && animation.mode && animation.mode !== "template" && animation.mode !== "skeleton-v3") {
|
|
@@ -1107,6 +1107,46 @@ var InheritedStyleSchema = StyleObjectSchema.partial().extend({
|
|
|
1107
1107
|
quality: QualityProfileObjectSchema.partial().optional()
|
|
1108
1108
|
}).strict();
|
|
1109
1109
|
var StyleInputSchema = z.union([StyleSchema, InheritedStyleSchema]);
|
|
1110
|
+
var AssetDeriveSchema = z.object({
|
|
1111
|
+
/** Another asset in the same style whose output is the input. */
|
|
1112
|
+
from: z.string().min(1).optional(),
|
|
1113
|
+
/** A committed PNG, relative to the manifest, as the input. */
|
|
1114
|
+
file: z.string().min(1).optional(),
|
|
1115
|
+
transform: z.enum(["recolor", "palette-snap", "scale"]),
|
|
1116
|
+
/** recolor: exact replacements, `#rrggbb` to `#rrggbb`. Unmapped colors and every alpha value stay. */
|
|
1117
|
+
map: z.record(HexColorSchema, HexColorSchema).optional(),
|
|
1118
|
+
/** palette-snap: the closed palette every visible pixel moves to. */
|
|
1119
|
+
palette: z.array(HexColorSchema).min(2).max(256).optional(),
|
|
1120
|
+
/** scale: the output size. */
|
|
1121
|
+
width: z.number().int().min(1).max(4096).optional(),
|
|
1122
|
+
height: z.number().int().min(1).max(4096).optional(),
|
|
1123
|
+
/** scale: `nearest` (default) keeps hard edges; `box` averages the covered pixels. */
|
|
1124
|
+
mode: z.enum(["nearest", "box"]).optional()
|
|
1125
|
+
}).strict().superRefine((derive, context) => {
|
|
1126
|
+
const issue = (message6, path42) => context.addIssue({ code: z.ZodIssueCode.custom, message: message6, path: [path42] });
|
|
1127
|
+
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
1128
|
+
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
1129
|
+
}
|
|
1130
|
+
const own = {
|
|
1131
|
+
recolor: ["map"],
|
|
1132
|
+
"palette-snap": ["palette"],
|
|
1133
|
+
scale: ["width", "height", "mode"]
|
|
1134
|
+
}[derive.transform];
|
|
1135
|
+
for (const field of ["map", "palette", "width", "height", "mode"]) {
|
|
1136
|
+
if (derive[field] !== void 0 && !own.includes(field)) {
|
|
1137
|
+
issue(`${field} does not apply to ${derive.transform}`, field);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
if (derive.transform === "recolor" && !Object.keys(derive.map ?? {}).length) issue("recolor needs a non-empty map", "map");
|
|
1141
|
+
if (derive.transform === "palette-snap" && !derive.palette) issue("palette-snap needs a palette", "palette");
|
|
1142
|
+
if (derive.transform === "scale" && (!derive.width || !derive.height)) issue("scale needs width and height", "width");
|
|
1143
|
+
});
|
|
1144
|
+
var AssetExternalSchema = z.object({
|
|
1145
|
+
/** The command that rebuilds the file. Documentation and identity; never executed. */
|
|
1146
|
+
builder: z.string().min(1),
|
|
1147
|
+
/** Files the builder reads, relative to the manifest. Their hashes are part of the asset's identity. */
|
|
1148
|
+
inputs: z.array(z.string().min(1)).optional()
|
|
1149
|
+
}).strict();
|
|
1110
1150
|
var AssetSchema = z.object({
|
|
1111
1151
|
/** The subject. Style wrapping comes from the style's prefix/suffix. Only a `mirror` may leave it out. */
|
|
1112
1152
|
prompt: z.string().optional(),
|
|
@@ -1238,6 +1278,10 @@ var AssetSchema = z.object({
|
|
|
1238
1278
|
* (a sword hand, a parted fringe) comes out the other way round.
|
|
1239
1279
|
*/
|
|
1240
1280
|
mirror: z.string().min(1).optional(),
|
|
1281
|
+
/** Made from existing pixels by a local transform; see AssetDeriveSchema. Free; the provider is never called. */
|
|
1282
|
+
derive: AssetDeriveSchema.optional(),
|
|
1283
|
+
/** Built by a tool outside pixelkiln; see AssetExternalSchema. Never generated. */
|
|
1284
|
+
external: AssetExternalSchema.optional(),
|
|
1241
1285
|
/**
|
|
1242
1286
|
* Generated output role to place in `cell` when this asset expands to
|
|
1243
1287
|
* several files. Omit for ordinary single-output assets. A structural set
|
|
@@ -1277,7 +1321,7 @@ var AssetSchema = z.object({
|
|
|
1277
1321
|
path: ["revision"]
|
|
1278
1322
|
});
|
|
1279
1323
|
}
|
|
1280
|
-
const shapes = [asset.revision && "revision", asset.state && "state", asset.animation && "animation", asset.mirror && "mirror", asset.batch && "batch", asset.portrait && "portrait", asset.outfit && "outfit", asset.scene && "scene", asset.vfx && "vfx", asset.connect && "connect"].filter(Boolean);
|
|
1324
|
+
const shapes = [asset.revision && "revision", asset.state && "state", asset.animation && "animation", asset.mirror && "mirror", asset.derive && "derive", asset.external && "external", asset.batch && "batch", asset.portrait && "portrait", asset.outfit && "outfit", asset.scene && "scene", asset.vfx && "vfx", asset.connect && "connect"].filter(Boolean);
|
|
1281
1325
|
if (shapes.length > 1) {
|
|
1282
1326
|
context.addIssue({
|
|
1283
1327
|
code: z.ZodIssueCode.custom,
|
|
@@ -1285,6 +1329,15 @@ var AssetSchema = z.object({
|
|
|
1285
1329
|
path: [shapes[1]]
|
|
1286
1330
|
});
|
|
1287
1331
|
}
|
|
1332
|
+
for (const shape of ["derive", "external"]) {
|
|
1333
|
+
if (asset[shape] && (asset.source || Object.keys(asset.sourceByStyle).length)) {
|
|
1334
|
+
context.addIssue({
|
|
1335
|
+
code: z.ZodIssueCode.custom,
|
|
1336
|
+
message: shape === "derive" ? "a derived asset is made from its derive source; it cannot also declare a source" : "an external asset is built outside pixelkiln; it cannot also declare a source",
|
|
1337
|
+
path: [shape]
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1288
1341
|
if (asset.mirror && (asset.source || Object.keys(asset.sourceByStyle).length)) {
|
|
1289
1342
|
context.addIssue({
|
|
1290
1343
|
code: z.ZodIssueCode.custom,
|
|
@@ -1292,13 +1345,20 @@ var AssetSchema = z.object({
|
|
|
1292
1345
|
path: ["mirror"]
|
|
1293
1346
|
});
|
|
1294
1347
|
}
|
|
1295
|
-
if (asset.prompt === void 0 && !asset.mirror && !asset.portrait && !asset.outfit && !asset.animation?.template && !asset.vfx) {
|
|
1348
|
+
if (asset.prompt === void 0 && !asset.mirror && !asset.derive && !asset.external && !asset.portrait && !asset.outfit && !asset.animation?.template && !asset.vfx) {
|
|
1296
1349
|
context.addIssue({
|
|
1297
1350
|
code: z.ZodIssueCode.custom,
|
|
1298
1351
|
message: "Required",
|
|
1299
1352
|
path: ["prompt"]
|
|
1300
1353
|
});
|
|
1301
1354
|
}
|
|
1355
|
+
if ((asset.derive || asset.external) && (asset.reference || asset.concept)) {
|
|
1356
|
+
context.addIssue({
|
|
1357
|
+
code: z.ZodIssueCode.custom,
|
|
1358
|
+
message: "a derived or external asset is not drawn by a provider, so it takes no reference or concept image",
|
|
1359
|
+
path: [asset.reference ? "reference" : "concept"]
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1302
1362
|
if (asset.reference && (asset.state || asset.animation || asset.mirror || asset.portrait || asset.outfit)) {
|
|
1303
1363
|
context.addIssue({
|
|
1304
1364
|
code: z.ZodIssueCode.custom,
|
|
@@ -1590,6 +1650,24 @@ var LockEntrySchema = z.object({
|
|
|
1590
1650
|
source: z.string().min(1),
|
|
1591
1651
|
note: z.string().optional(),
|
|
1592
1652
|
importedAt: z.string()
|
|
1653
|
+
}).strict().optional(),
|
|
1654
|
+
/**
|
|
1655
|
+
* For a derived asset: what it was made from, and a hash of that input when
|
|
1656
|
+
* this was made. Compared with the input's current bytes by the plan, so a
|
|
1657
|
+
* changed source re-derives it for free. Absent on every other entry.
|
|
1658
|
+
*/
|
|
1659
|
+
derive: z.object({
|
|
1660
|
+
sourceAssetId: z.string().min(1).optional(),
|
|
1661
|
+
sourceFile: z.string().min(1).optional(),
|
|
1662
|
+
sourceSha256: z.string().regex(/^[0-9a-f]{64}$/)
|
|
1663
|
+
}).strict().optional(),
|
|
1664
|
+
/**
|
|
1665
|
+
* For an external asset: the builder command and the hashes of the declared
|
|
1666
|
+
* inputs when the file was recorded. Absent on every other entry.
|
|
1667
|
+
*/
|
|
1668
|
+
external: z.object({
|
|
1669
|
+
builder: z.string().min(1),
|
|
1670
|
+
inputs: z.array(z.object({ path: z.string(), sha256: z.string().nullable() }).strict()).default([])
|
|
1593
1671
|
}).strict().optional()
|
|
1594
1672
|
});
|
|
1595
1673
|
var LockSchema = z.object({
|
|
@@ -2139,9 +2217,9 @@ var PixelLabClient = class {
|
|
|
2139
2217
|
apiKey;
|
|
2140
2218
|
http;
|
|
2141
2219
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
2142
|
-
async request(
|
|
2220
|
+
async request(path42, init) {
|
|
2143
2221
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
2144
|
-
const res = await this.http(`${BASE}${
|
|
2222
|
+
const res = await this.http(`${BASE}${path42}`, {
|
|
2145
2223
|
...init,
|
|
2146
2224
|
headers: {
|
|
2147
2225
|
Authorization: auth,
|
|
@@ -2152,13 +2230,13 @@ var PixelLabClient = class {
|
|
|
2152
2230
|
const text = await res.text();
|
|
2153
2231
|
if (!res.ok) {
|
|
2154
2232
|
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' : "";
|
|
2155
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
2233
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path42} \u2192 ${res.status}${hint}`, res.status, text);
|
|
2156
2234
|
}
|
|
2157
2235
|
if (!text) return {};
|
|
2158
2236
|
try {
|
|
2159
2237
|
return JSON.parse(text);
|
|
2160
2238
|
} catch {
|
|
2161
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
2239
|
+
throw new Error(`${init?.method ?? "GET"} ${path42} returned invalid JSON`);
|
|
2162
2240
|
}
|
|
2163
2241
|
}
|
|
2164
2242
|
async balance() {
|
|
@@ -2611,10 +2689,10 @@ var PixelLabClient = class {
|
|
|
2611
2689
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
2612
2690
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
2613
2691
|
const south = args.reference?.south;
|
|
2614
|
-
let
|
|
2692
|
+
let path42;
|
|
2615
2693
|
let body;
|
|
2616
2694
|
if (args.mode === "v3") {
|
|
2617
|
-
|
|
2695
|
+
path42 = "/create-character-v3";
|
|
2618
2696
|
body = {
|
|
2619
2697
|
description: args.description,
|
|
2620
2698
|
image_size: imageSize,
|
|
@@ -2628,7 +2706,7 @@ var PixelLabClient = class {
|
|
|
2628
2706
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
2629
2707
|
};
|
|
2630
2708
|
} else if (args.mode === "pro-flash") {
|
|
2631
|
-
|
|
2709
|
+
path42 = "/create-character-pro-flash";
|
|
2632
2710
|
const traits = args.styleTraits;
|
|
2633
2711
|
body = {
|
|
2634
2712
|
description: args.description,
|
|
@@ -2652,7 +2730,7 @@ var PixelLabClient = class {
|
|
|
2652
2730
|
} : {}
|
|
2653
2731
|
};
|
|
2654
2732
|
} else if (args.mode === "pro") {
|
|
2655
|
-
|
|
2733
|
+
path42 = "/create-character-pro";
|
|
2656
2734
|
body = {
|
|
2657
2735
|
description: args.description,
|
|
2658
2736
|
image_size: imageSize,
|
|
@@ -2666,7 +2744,7 @@ var PixelLabClient = class {
|
|
|
2666
2744
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
2667
2745
|
};
|
|
2668
2746
|
} else {
|
|
2669
|
-
|
|
2747
|
+
path42 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
2670
2748
|
body = {
|
|
2671
2749
|
description: args.description,
|
|
2672
2750
|
image_size: imageSize,
|
|
@@ -2684,8 +2762,8 @@ var PixelLabClient = class {
|
|
|
2684
2762
|
};
|
|
2685
2763
|
}
|
|
2686
2764
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
2687
|
-
const raw = await this.request(
|
|
2688
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
2765
|
+
const raw = await this.request(path42, { method: "POST", body: JSON.stringify(body) });
|
|
2766
|
+
return validateResponse(CharacterSubmitSchema, raw, path42.slice(1));
|
|
2689
2767
|
}
|
|
2690
2768
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
2691
2769
|
async createCharacterState(args) {
|
|
@@ -3414,13 +3492,13 @@ var PixelLabClient = class {
|
|
|
3414
3492
|
}
|
|
3415
3493
|
};
|
|
3416
3494
|
function clientFromEnv() {
|
|
3417
|
-
const
|
|
3418
|
-
if (!
|
|
3495
|
+
const key2 = process.env.PIXELLAB_API_KEY;
|
|
3496
|
+
if (!key2) {
|
|
3419
3497
|
throw new Error(
|
|
3420
3498
|
"PIXELLAB_API_KEY is not set.\nLooked in the environment, and in .env.local / .env beside the manifest and in the current directory."
|
|
3421
3499
|
);
|
|
3422
3500
|
}
|
|
3423
|
-
return new PixelLabClient(
|
|
3501
|
+
return new PixelLabClient(key2);
|
|
3424
3502
|
}
|
|
3425
3503
|
|
|
3426
3504
|
// src/open.ts
|
|
@@ -3760,14 +3838,14 @@ function extractPalette(png, topN = 8, alphaThreshold = 128) {
|
|
|
3760
3838
|
const alpha = png.pixels[i + 3];
|
|
3761
3839
|
if (alpha < alphaThreshold) continue;
|
|
3762
3840
|
opaque++;
|
|
3763
|
-
const
|
|
3764
|
-
counts.set(
|
|
3841
|
+
const key2 = png.pixels[i] << 16 | png.pixels[i + 1] << 8 | png.pixels[i + 2];
|
|
3842
|
+
counts.set(key2, (counts.get(key2) ?? 0) + 1);
|
|
3765
3843
|
}
|
|
3766
3844
|
if (opaque === 0) return [];
|
|
3767
|
-
return [...counts.entries()].sort((a, b) => b[1] - a[1]).slice(0, topN).map(([
|
|
3768
|
-
r:
|
|
3769
|
-
g:
|
|
3770
|
-
b:
|
|
3845
|
+
return [...counts.entries()].sort((a, b) => b[1] - a[1]).slice(0, topN).map(([key2, n]) => ({
|
|
3846
|
+
r: key2 >> 16 & 255,
|
|
3847
|
+
g: key2 >> 8 & 255,
|
|
3848
|
+
b: key2 & 255,
|
|
3771
3849
|
weight: n / opaque
|
|
3772
3850
|
}));
|
|
3773
3851
|
}
|
|
@@ -4019,13 +4097,17 @@ import path3 from "path";
|
|
|
4019
4097
|
// src/hash.ts
|
|
4020
4098
|
import { createHash } from "crypto";
|
|
4021
4099
|
import { createReadStream } from "fs";
|
|
4100
|
+
function normalizeHex(value) {
|
|
4101
|
+
const { r, g, b } = parseHex(value);
|
|
4102
|
+
return `#${[r, g, b].map((channel) => channel.toString(16).padStart(2, "0")).join("")}`;
|
|
4103
|
+
}
|
|
4022
4104
|
function sha256(data) {
|
|
4023
4105
|
return createHash("sha256").update(data).digest("hex");
|
|
4024
4106
|
}
|
|
4025
|
-
async function sha256File(
|
|
4107
|
+
async function sha256File(path42) {
|
|
4026
4108
|
return new Promise((resolve, reject) => {
|
|
4027
4109
|
const hash = createHash("sha256");
|
|
4028
|
-
const stream = createReadStream(
|
|
4110
|
+
const stream = createReadStream(path42);
|
|
4029
4111
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
4030
4112
|
stream.on("error", reject);
|
|
4031
4113
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -4167,6 +4249,22 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
|
|
|
4167
4249
|
// A mirror's bytes come from its source's recorded outputs; the plan
|
|
4168
4250
|
// compares those directly, so only the choice of source is identity.
|
|
4169
4251
|
mirror: spec.mirror ? { of: spec.mirror.sourceAssetId } : void 0,
|
|
4252
|
+
// A derived asset's identity is its transform and what it reads: the
|
|
4253
|
+
// file source by its bytes' hash, an asset source by id (the plan
|
|
4254
|
+
// compares that asset's current output with the one recorded).
|
|
4255
|
+
derive: spec.derive ? {
|
|
4256
|
+
transform: spec.derive.transform,
|
|
4257
|
+
map: spec.derive.map ? Object.entries(spec.derive.map).map(([from, to]) => [normalizeHex(from), normalizeHex(to)]).sort(([a], [b]) => a.localeCompare(b)) : void 0,
|
|
4258
|
+
palette: spec.derive.palette?.map(normalizeHex),
|
|
4259
|
+
width: spec.derive.width,
|
|
4260
|
+
height: spec.derive.height,
|
|
4261
|
+
mode: spec.derive.transform === "scale" ? spec.derive.mode ?? "nearest" : void 0,
|
|
4262
|
+
from: spec.derive.source.kind === "asset" ? spec.derive.source.assetId : void 0,
|
|
4263
|
+
fileSha256: spec.derive.source.kind === "file" ? spec.derive.source.sha256 : void 0
|
|
4264
|
+
} : void 0,
|
|
4265
|
+
// An external asset: the builder text and each declared input's path
|
|
4266
|
+
// and bytes. The built file itself is checked by the plan.
|
|
4267
|
+
external: spec.external ? { builder: spec.external.builder, inputs: spec.external.inputs.length ? spec.external.inputs : void 0 } : void 0,
|
|
4170
4268
|
// The whole group's ordered descriptions, not just this asset's own —
|
|
4171
4269
|
// any sibling's prompt changing, or a member being added or removed,
|
|
4172
4270
|
// must mark every member stale together, since they all ride on one
|
|
@@ -4294,13 +4392,13 @@ var PixelLabMcpClient = class {
|
|
|
4294
4392
|
}
|
|
4295
4393
|
};
|
|
4296
4394
|
function mcpClientFromEnv() {
|
|
4297
|
-
const
|
|
4298
|
-
if (!
|
|
4395
|
+
const key2 = process.env.PIXELLAB_API_KEY;
|
|
4396
|
+
if (!key2) {
|
|
4299
4397
|
throw new Error(
|
|
4300
4398
|
"PIXELLAB_API_KEY is not set.\nLooked in the environment, and in .env.local / .env beside the manifest and in the current directory."
|
|
4301
4399
|
);
|
|
4302
4400
|
}
|
|
4303
|
-
return new PixelLabMcpClient(
|
|
4401
|
+
return new PixelLabMcpClient(key2);
|
|
4304
4402
|
}
|
|
4305
4403
|
|
|
4306
4404
|
// src/pixellab-vfx.ts
|
|
@@ -4584,27 +4682,27 @@ function vfxArtistFiles(raw) {
|
|
|
4584
4682
|
const urlOf = (value) => {
|
|
4585
4683
|
if (typeof value === "string") return /^https?:\/\//i.test(value) ? value : null;
|
|
4586
4684
|
if (!value || typeof value !== "object") return null;
|
|
4587
|
-
for (const
|
|
4588
|
-
const url = value[
|
|
4685
|
+
for (const key2 of ["url", "download_url", "href"]) {
|
|
4686
|
+
const url = value[key2];
|
|
4589
4687
|
if (typeof url === "string" && /^https?:\/\//i.test(url)) return url;
|
|
4590
4688
|
}
|
|
4591
4689
|
return null;
|
|
4592
4690
|
};
|
|
4593
|
-
const nameOf = (value, url,
|
|
4691
|
+
const nameOf = (value, url, key2) => {
|
|
4594
4692
|
if (value && typeof value === "object") {
|
|
4595
4693
|
for (const field of ["name", "filename", "file"]) {
|
|
4596
4694
|
const name = value[field];
|
|
4597
4695
|
if (typeof name === "string" && name) return name;
|
|
4598
4696
|
}
|
|
4599
4697
|
}
|
|
4600
|
-
if (
|
|
4698
|
+
if (key2 && /\.[a-z0-9]+$/i.test(key2)) return key2;
|
|
4601
4699
|
return decodeURIComponent(new URL(url).pathname.split("/").pop() ?? "");
|
|
4602
4700
|
};
|
|
4603
4701
|
const entries = Array.isArray(raw) ? raw.map((value) => [void 0, value]) : raw && typeof raw === "object" ? Object.entries(raw) : [];
|
|
4604
4702
|
const files = [];
|
|
4605
|
-
for (const [
|
|
4703
|
+
for (const [key2, value] of entries) {
|
|
4606
4704
|
const url = urlOf(value);
|
|
4607
|
-
if (url) files.push({ name: nameOf(value, url,
|
|
4705
|
+
if (url) files.push({ name: nameOf(value, url, key2), url });
|
|
4608
4706
|
}
|
|
4609
4707
|
return files;
|
|
4610
4708
|
}
|
|
@@ -4705,14 +4803,14 @@ async function makeVfxWithArtist(client2, opts) {
|
|
|
4705
4803
|
`);
|
|
4706
4804
|
written.atlas = paths.atlas;
|
|
4707
4805
|
}
|
|
4708
|
-
for (const [file, target,
|
|
4806
|
+
for (const [file, target, key2] of [
|
|
4709
4807
|
[result.gif, paths.gif, "gif"],
|
|
4710
4808
|
[result.gamePack, paths.gamePack, "gamePack"],
|
|
4711
4809
|
[result.normals, paths.normals, "normals"]
|
|
4712
4810
|
]) {
|
|
4713
4811
|
if (!file) continue;
|
|
4714
4812
|
await writeFile(target, await client2.download(file.url));
|
|
4715
|
-
written[
|
|
4813
|
+
written[key2] = target;
|
|
4716
4814
|
}
|
|
4717
4815
|
const facts = vfxArtistFrameFacts(result, atlas);
|
|
4718
4816
|
const usage = job.usage ?? null;
|
|
@@ -4736,7 +4834,7 @@ async function makeVfxWithArtist(client2, opts) {
|
|
|
4736
4834
|
anchor: result.anchor,
|
|
4737
4835
|
parts: result.parts,
|
|
4738
4836
|
files: Object.fromEntries(
|
|
4739
|
-
["sheet", "gif", "atlas", "gamePack", "normals"].filter((
|
|
4837
|
+
["sheet", "gif", "atlas", "gamePack", "normals"].filter((key2) => written[key2]).map((key2) => [key2, path.basename(written[key2])])
|
|
4740
4838
|
),
|
|
4741
4839
|
quotedGenerations: submitted.quoted_generations ?? null,
|
|
4742
4840
|
usage,
|
|
@@ -4761,8 +4859,8 @@ async function makeVfxWithArtist(client2, opts) {
|
|
|
4761
4859
|
};
|
|
4762
4860
|
}
|
|
4763
4861
|
function vfxJobFailure(done) {
|
|
4764
|
-
for (const
|
|
4765
|
-
const value = done?.[
|
|
4862
|
+
for (const key2 of ["error", "detail", "message"]) {
|
|
4863
|
+
const value = done?.[key2];
|
|
4766
4864
|
if (typeof value === "string" && value) return `: ${value}`;
|
|
4767
4865
|
}
|
|
4768
4866
|
return "";
|
|
@@ -4797,8 +4895,8 @@ function isSensitiveSourceUrl(value) {
|
|
|
4797
4895
|
return false;
|
|
4798
4896
|
}
|
|
4799
4897
|
if (parsed.username || parsed.password) return true;
|
|
4800
|
-
for (const
|
|
4801
|
-
const normalized =
|
|
4898
|
+
for (const key2 of parsed.searchParams.keys()) {
|
|
4899
|
+
const normalized = key2.toLowerCase();
|
|
4802
4900
|
if (SENSITIVE_QUERY_KEYS.has(normalized) || normalized.includes("credential") || normalized.includes("signature") || normalized.includes("security-token") || normalized.includes("token")) return true;
|
|
4803
4901
|
}
|
|
4804
4902
|
return false;
|
|
@@ -7193,8 +7291,8 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
7193
7291
|
billed
|
|
7194
7292
|
};
|
|
7195
7293
|
};
|
|
7196
|
-
for (const
|
|
7197
|
-
const list = done[
|
|
7294
|
+
for (const key2 of ["frame_urls", "frames", "images"]) {
|
|
7295
|
+
const list = done[key2];
|
|
7198
7296
|
if (!Array.isArray(list) || !list.length) continue;
|
|
7199
7297
|
const urls = [];
|
|
7200
7298
|
for (const [index, item] of list.entries()) {
|
|
@@ -7249,15 +7347,15 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
7249
7347
|
const billed = billedFromUsage(job.usage);
|
|
7250
7348
|
const done = job.last_response ?? {};
|
|
7251
7349
|
const urlKeys = ["image_url", "download_url", "url", "output_url"];
|
|
7252
|
-
for (const
|
|
7253
|
-
const url = done[
|
|
7350
|
+
for (const key2 of urlKeys) {
|
|
7351
|
+
const url = done[key2];
|
|
7254
7352
|
if (typeof url === "string" && url) {
|
|
7255
7353
|
return { status: "ready", objectId: jobId, sourceUrl: url, sources: [{ url }], billed };
|
|
7256
7354
|
}
|
|
7257
7355
|
}
|
|
7258
7356
|
const imageKeys = ["image", "output_image", "result_image", "edited_image"];
|
|
7259
|
-
for (const
|
|
7260
|
-
const candidate = done[
|
|
7357
|
+
for (const key2 of imageKeys) {
|
|
7358
|
+
const candidate = done[key2];
|
|
7261
7359
|
const base64 = extractBase64(candidate);
|
|
7262
7360
|
if (base64) {
|
|
7263
7361
|
const file = path3.join(_PixelLabProvider.cacheDir(), `${jobId}.png`);
|
|
@@ -7682,7 +7780,7 @@ function requirePixelLabOption(generator, name, value, allowed) {
|
|
|
7682
7780
|
}
|
|
7683
7781
|
}
|
|
7684
7782
|
function tilesInIndexOrder(urls) {
|
|
7685
|
-
return Object.entries(urls).map(([
|
|
7783
|
+
return Object.entries(urls).map(([key2, url]) => ({ index: Number(key2.replace(/^tile_/, "")), url })).filter((tile) => Number.isFinite(tile.index)).sort((a, b) => a.index - b.index);
|
|
7686
7784
|
}
|
|
7687
7785
|
function firstUrl(urls) {
|
|
7688
7786
|
if (!urls) return null;
|
|
@@ -7844,9 +7942,9 @@ var RetroDiffusionClient = class {
|
|
|
7844
7942
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
7845
7943
|
return Buffer.from(await response.arrayBuffer());
|
|
7846
7944
|
}
|
|
7847
|
-
async call(
|
|
7945
|
+
async call(path42, init = {}) {
|
|
7848
7946
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
7849
|
-
const response = await this.request(`${this.baseUrl}${
|
|
7947
|
+
const response = await this.request(`${this.baseUrl}${path42}`, {
|
|
7850
7948
|
...init,
|
|
7851
7949
|
headers: {
|
|
7852
7950
|
"Content-Type": "application/json",
|
|
@@ -8315,8 +8413,8 @@ var ScenarioClient = class {
|
|
|
8315
8413
|
throw new Error(`${missing.join(" and ")} ${missing.length > 1 ? "are" : "is"} not set`);
|
|
8316
8414
|
}
|
|
8317
8415
|
const url = new URL(`${this.baseUrl.replace(/\/$/, "")}${pathname}`);
|
|
8318
|
-
for (const [
|
|
8319
|
-
if (value2 != null) url.searchParams.set(
|
|
8416
|
+
for (const [key2, value2] of Object.entries(query)) {
|
|
8417
|
+
if (value2 != null) url.searchParams.set(key2, value2);
|
|
8320
8418
|
}
|
|
8321
8419
|
const auth = Buffer.from(`${this.apiKey}:${this.apiSecret}`).toString("base64");
|
|
8322
8420
|
const response = await this.request(url, {
|
|
@@ -8556,12 +8654,12 @@ function readUploadCache() {
|
|
|
8556
8654
|
return {};
|
|
8557
8655
|
}
|
|
8558
8656
|
}
|
|
8559
|
-
function writeUploadCache(
|
|
8657
|
+
function writeUploadCache(key2, assetId) {
|
|
8560
8658
|
try {
|
|
8561
8659
|
const file = uploadCachePath();
|
|
8562
8660
|
mkdirSync2(path4.dirname(file), { recursive: true });
|
|
8563
8661
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
8564
|
-
writeFileSync2(tmp, JSON.stringify({ ...readUploadCache(), [
|
|
8662
|
+
writeFileSync2(tmp, JSON.stringify({ ...readUploadCache(), [key2]: assetId }));
|
|
8565
8663
|
renameSync(tmp, file);
|
|
8566
8664
|
} catch {
|
|
8567
8665
|
}
|
|
@@ -8611,9 +8709,9 @@ function validateParameters(parameters) {
|
|
|
8611
8709
|
if (!parameters || typeof parameters !== "object" || Array.isArray(parameters)) {
|
|
8612
8710
|
throw new Error("Scenario parameters must be a JSON object");
|
|
8613
8711
|
}
|
|
8614
|
-
for (const
|
|
8615
|
-
if (PROTECTED_PARAMETERS.has(
|
|
8616
|
-
throw new Error(`Scenario parameters.${
|
|
8712
|
+
for (const key2 of Object.keys(parameters)) {
|
|
8713
|
+
if (PROTECTED_PARAMETERS.has(key2)) {
|
|
8714
|
+
throw new Error(`Scenario parameters.${key2} is managed by PixelKiln and cannot be overridden`);
|
|
8617
8715
|
}
|
|
8618
8716
|
}
|
|
8619
8717
|
assertJsonValue(parameters, "Scenario parameters");
|
|
@@ -8636,8 +8734,8 @@ function assertJsonValue(value, label, seen = /* @__PURE__ */ new Set()) {
|
|
|
8636
8734
|
if (Array.isArray(value)) {
|
|
8637
8735
|
value.forEach((item, index) => assertJsonValue(item, `${label}[${index}]`, seen));
|
|
8638
8736
|
} else {
|
|
8639
|
-
for (const [
|
|
8640
|
-
assertJsonValue(item, `${label}.${
|
|
8737
|
+
for (const [key2, item] of Object.entries(value)) {
|
|
8738
|
+
assertJsonValue(item, `${label}.${key2}`, seen);
|
|
8641
8739
|
}
|
|
8642
8740
|
}
|
|
8643
8741
|
seen.delete(value);
|
|
@@ -8738,8 +8836,8 @@ function numericRecord(value) {
|
|
|
8738
8836
|
throw new Error("Scenario returned invalid cost details");
|
|
8739
8837
|
}
|
|
8740
8838
|
const out = {};
|
|
8741
|
-
for (const [
|
|
8742
|
-
out[
|
|
8839
|
+
for (const [key2, amount] of Object.entries(value)) {
|
|
8840
|
+
out[key2] = finiteNonnegative(amount, `Scenario returned invalid cost detail "${key2}"`);
|
|
8743
8841
|
}
|
|
8744
8842
|
return out;
|
|
8745
8843
|
}
|
|
@@ -9345,7 +9443,7 @@ function parseOptions(value) {
|
|
|
9345
9443
|
"workflow",
|
|
9346
9444
|
"workflowSha256"
|
|
9347
9445
|
]);
|
|
9348
|
-
const extra = Object.keys(value).filter((
|
|
9446
|
+
const extra = Object.keys(value).filter((key2) => !allowed.has(key2));
|
|
9349
9447
|
if (extra.length) throw new Error(`Unknown ComfyUI option(s): ${extra.join(", ")}`);
|
|
9350
9448
|
const workflowFile = requiredString(value.workflowFile, "workflowFile");
|
|
9351
9449
|
const outputNodeId = requiredString(value.outputNodeId, "outputNodeId");
|
|
@@ -9381,7 +9479,7 @@ function parseOptions(value) {
|
|
|
9381
9479
|
}
|
|
9382
9480
|
function parseFrames(value) {
|
|
9383
9481
|
if (!isObject(value)) throw new Error("ComfyUI frames must be an object");
|
|
9384
|
-
const extra = Object.keys(value).filter((
|
|
9482
|
+
const extra = Object.keys(value).filter((key2) => key2 !== "vary" && key2 !== "seedStep");
|
|
9385
9483
|
if (extra.length) throw new Error(`Unknown ComfyUI frames field(s): ${extra.join(", ")}`);
|
|
9386
9484
|
const vary = requiredString(value.vary, "frames.vary");
|
|
9387
9485
|
const seedStep = value.seedStep ?? 0;
|
|
@@ -9399,7 +9497,7 @@ function resolvedOptions(spec) {
|
|
|
9399
9497
|
}
|
|
9400
9498
|
function parseBinding(value, name) {
|
|
9401
9499
|
if (!isObject(value)) throw new Error(`ComfyUI bindings.${name} must be an object`);
|
|
9402
|
-
const extra = Object.keys(value).filter((
|
|
9500
|
+
const extra = Object.keys(value).filter((key2) => key2 !== "nodeId" && key2 !== "input");
|
|
9403
9501
|
if (extra.length) throw new Error(`Unknown ComfyUI bindings.${name} field(s): ${extra.join(", ")}`);
|
|
9404
9502
|
return {
|
|
9405
9503
|
nodeId: requiredString(value.nodeId, `bindings.${name}.nodeId`),
|
|
@@ -9664,7 +9762,7 @@ function canonical(value) {
|
|
|
9664
9762
|
if (Array.isArray(value)) return value.map(canonical);
|
|
9665
9763
|
if (!isObject(value)) return value;
|
|
9666
9764
|
return Object.fromEntries(
|
|
9667
|
-
Object.keys(value).sort().map((
|
|
9765
|
+
Object.keys(value).sort().map((key2) => [key2, canonical(value[key2])])
|
|
9668
9766
|
);
|
|
9669
9767
|
}
|
|
9670
9768
|
|
|
@@ -10073,22 +10171,22 @@ async function writeLockWhileHeld(file, lock) {
|
|
|
10073
10171
|
}
|
|
10074
10172
|
const dirty = dirtyPatches.get(lock) ?? /* @__PURE__ */ new Map();
|
|
10075
10173
|
const snapshot = /* @__PURE__ */ new Map();
|
|
10076
|
-
for (const [
|
|
10174
|
+
for (const [key2, patch] of dirty) snapshot.set(key2, { ...patch });
|
|
10077
10175
|
const merged = { ...disk.entries };
|
|
10078
|
-
for (const [
|
|
10079
|
-
const local = lock.entries[
|
|
10176
|
+
for (const [key2, patch] of snapshot) {
|
|
10177
|
+
const local = lock.entries[key2];
|
|
10080
10178
|
if (!local) continue;
|
|
10081
|
-
merged[
|
|
10179
|
+
merged[key2] = merged[key2] ? { ...merged[key2], ...patch } : local;
|
|
10082
10180
|
}
|
|
10083
|
-
for (const [
|
|
10084
|
-
if (!merged[
|
|
10181
|
+
for (const [key2, entry] of Object.entries(lock.entries)) {
|
|
10182
|
+
if (!merged[key2]) merged[key2] = entry;
|
|
10085
10183
|
}
|
|
10086
10184
|
const deletes = dirtyDeletes.get(lock);
|
|
10087
10185
|
const deleteSnapshot = deletes ? new Set(deletes) : /* @__PURE__ */ new Set();
|
|
10088
|
-
for (const
|
|
10186
|
+
for (const key2 of deleteSnapshot) delete merged[key2];
|
|
10089
10187
|
const sorted = {};
|
|
10090
|
-
for (const
|
|
10091
|
-
sorted[
|
|
10188
|
+
for (const key2 of Object.keys(merged).sort()) {
|
|
10189
|
+
sorted[key2] = merged[key2];
|
|
10092
10190
|
}
|
|
10093
10191
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
10094
10192
|
try {
|
|
@@ -10099,48 +10197,48 @@ async function writeLockWhileHeld(file, lock) {
|
|
|
10099
10197
|
}
|
|
10100
10198
|
const currentDirty = dirtyPatches.get(lock);
|
|
10101
10199
|
if (currentDirty) {
|
|
10102
|
-
for (const [
|
|
10103
|
-
const current = currentDirty.get(
|
|
10200
|
+
for (const [key2, patch] of snapshot) {
|
|
10201
|
+
const current = currentDirty.get(key2);
|
|
10104
10202
|
if (!current) continue;
|
|
10105
10203
|
for (const [field, value] of Object.entries(patch)) {
|
|
10106
10204
|
if (Object.is(current[field], value)) {
|
|
10107
10205
|
delete current[field];
|
|
10108
10206
|
}
|
|
10109
10207
|
}
|
|
10110
|
-
if (Object.keys(current).length === 0) currentDirty.delete(
|
|
10208
|
+
if (Object.keys(current).length === 0) currentDirty.delete(key2);
|
|
10111
10209
|
}
|
|
10112
10210
|
}
|
|
10113
10211
|
const stillDirty = dirtyDeletes.get(lock);
|
|
10114
10212
|
if (stillDirty) {
|
|
10115
|
-
for (const
|
|
10213
|
+
for (const key2 of deleteSnapshot) stillDirty.delete(key2);
|
|
10116
10214
|
if (stillDirty.size === 0) dirtyDeletes.delete(lock);
|
|
10117
10215
|
}
|
|
10118
10216
|
const localAfterWrite = lock.entries;
|
|
10119
10217
|
lock.entries = { ...merged };
|
|
10120
|
-
for (const [
|
|
10121
|
-
const base = lock.entries[
|
|
10122
|
-
if (base) lock.entries[
|
|
10218
|
+
for (const [key2, patch] of currentDirty ?? []) {
|
|
10219
|
+
const base = lock.entries[key2] ?? localAfterWrite[key2];
|
|
10220
|
+
if (base) lock.entries[key2] = { ...base, ...patch };
|
|
10123
10221
|
}
|
|
10124
10222
|
}
|
|
10125
|
-
function upsert(lock,
|
|
10126
|
-
dirtyDeletes.get(lock)?.delete(
|
|
10127
|
-
const existing = lock.entries[
|
|
10223
|
+
function upsert(lock, key2, patch) {
|
|
10224
|
+
dirtyDeletes.get(lock)?.delete(key2);
|
|
10225
|
+
const existing = lock.entries[key2];
|
|
10128
10226
|
const next = { ...existing, ...patch };
|
|
10129
|
-
lock.entries[
|
|
10227
|
+
lock.entries[key2] = next;
|
|
10130
10228
|
let dirty = dirtyPatches.get(lock);
|
|
10131
10229
|
if (!dirty) {
|
|
10132
10230
|
dirty = /* @__PURE__ */ new Map();
|
|
10133
10231
|
dirtyPatches.set(lock, dirty);
|
|
10134
10232
|
}
|
|
10135
|
-
dirty.set(
|
|
10233
|
+
dirty.set(key2, { ...dirty.get(key2) ?? {}, ...patch });
|
|
10136
10234
|
return next;
|
|
10137
10235
|
}
|
|
10138
|
-
function remove(lock,
|
|
10139
|
-
if (!lock.entries[
|
|
10140
|
-
delete lock.entries[
|
|
10236
|
+
function remove(lock, key2) {
|
|
10237
|
+
if (!lock.entries[key2]) return false;
|
|
10238
|
+
delete lock.entries[key2];
|
|
10141
10239
|
const patches = dirtyPatches.get(lock);
|
|
10142
10240
|
if (patches) {
|
|
10143
|
-
patches.delete(
|
|
10241
|
+
patches.delete(key2);
|
|
10144
10242
|
if (patches.size === 0) dirtyPatches.delete(lock);
|
|
10145
10243
|
}
|
|
10146
10244
|
let deletes = dirtyDeletes.get(lock);
|
|
@@ -10148,7 +10246,7 @@ function remove(lock, key) {
|
|
|
10148
10246
|
deletes = /* @__PURE__ */ new Set();
|
|
10149
10247
|
dirtyDeletes.set(lock, deletes);
|
|
10150
10248
|
}
|
|
10151
|
-
deletes.add(
|
|
10249
|
+
deletes.add(key2);
|
|
10152
10250
|
return true;
|
|
10153
10251
|
}
|
|
10154
10252
|
var FILE_LOCK_TIMEOUT_MS = 1e4;
|
|
@@ -10246,8 +10344,8 @@ function currentEntryOutputPath(entry, spec, index) {
|
|
|
10246
10344
|
function normalizeLockOutputPaths(lock, specs) {
|
|
10247
10345
|
const byKey = new Map(specs.map((spec) => [lockKey(spec.styleId, spec.assetId), spec]));
|
|
10248
10346
|
let changed = 0;
|
|
10249
|
-
for (const [
|
|
10250
|
-
const spec = byKey.get(
|
|
10347
|
+
for (const [key2, entry] of Object.entries(lock.entries)) {
|
|
10348
|
+
const spec = byKey.get(key2);
|
|
10251
10349
|
if (!spec) continue;
|
|
10252
10350
|
let entryChanged = false;
|
|
10253
10351
|
const outputs = entry.outputs.map((output, index) => {
|
|
@@ -10258,7 +10356,7 @@ function normalizeLockOutputPaths(lock, specs) {
|
|
|
10258
10356
|
entryChanged = true;
|
|
10259
10357
|
return { ...output, path: portable };
|
|
10260
10358
|
});
|
|
10261
|
-
if (entryChanged) upsert(lock,
|
|
10359
|
+
if (entryChanged) upsert(lock, key2, { outputs });
|
|
10262
10360
|
}
|
|
10263
10361
|
return changed;
|
|
10264
10362
|
}
|
|
@@ -10289,8 +10387,8 @@ function resolveSpecEntryOutputs(entry, spec) {
|
|
|
10289
10387
|
}
|
|
10290
10388
|
function resolveStyleOutputs(lock, styleId, manifestDir) {
|
|
10291
10389
|
const prefix = `${styleId}/`;
|
|
10292
|
-
return Object.entries(lock.entries).filter(([
|
|
10293
|
-
([
|
|
10390
|
+
return Object.entries(lock.entries).filter(([key2]) => key2.startsWith(prefix)).sort(([a], [b]) => a.localeCompare(b)).flatMap(
|
|
10391
|
+
([key2, entry]) => resolveEntryOutputs(entry, key2.slice(prefix.length), manifestDir)
|
|
10294
10392
|
);
|
|
10295
10393
|
}
|
|
10296
10394
|
function selectEntryOutput(entry, role) {
|
|
@@ -10413,10 +10511,10 @@ function culpritEntries(message6) {
|
|
|
10413
10511
|
const match = /^ {2}(assets|styles)\.([^.:\s]+)[.:]/.exec(line);
|
|
10414
10512
|
if (!match) continue;
|
|
10415
10513
|
const kind = match[1] === "styles" ? "style" : "asset";
|
|
10416
|
-
const
|
|
10417
|
-
const entry = found.get(
|
|
10514
|
+
const key2 = `${kind}:${match[2]}`;
|
|
10515
|
+
const entry = found.get(key2) ?? { kind, id: match[2], issues: [] };
|
|
10418
10516
|
entry.issues.push(line.trim());
|
|
10419
|
-
found.set(
|
|
10517
|
+
found.set(key2, entry);
|
|
10420
10518
|
}
|
|
10421
10519
|
return [...found.values()];
|
|
10422
10520
|
}
|
|
@@ -10562,6 +10660,7 @@ function dependencyAssetIds(asset, styleAnchors = []) {
|
|
|
10562
10660
|
asset?.connect?.upper?.of,
|
|
10563
10661
|
asset?.animation?.motionFrom,
|
|
10564
10662
|
asset?.mirror,
|
|
10663
|
+
asset?.derive?.from,
|
|
10565
10664
|
asset?.styleCharacter,
|
|
10566
10665
|
...asset?.styleCharacter ? [] : styleAnchors
|
|
10567
10666
|
].filter((id) => Boolean(id))
|
|
@@ -11020,6 +11119,64 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11020
11119
|
}
|
|
11021
11120
|
if (finalized.has(assetId)) return resolved;
|
|
11022
11121
|
const asset = manifest.assets[assetId];
|
|
11122
|
+
if (asset.derive) {
|
|
11123
|
+
const derive = asset.derive;
|
|
11124
|
+
let source;
|
|
11125
|
+
let sourceSpec;
|
|
11126
|
+
if (derive.from) {
|
|
11127
|
+
if (derive.from === assetId) throw new Error(`assets.${assetId}: an asset cannot derive from itself`);
|
|
11128
|
+
sourceSpec = await finalize(derive.from);
|
|
11129
|
+
if (sourceSpec.generator === "tiles" || sourceSpec.generator === "terrain") {
|
|
11130
|
+
throw new Error(`assets.${assetId}: a tile set is several images; derive takes a single image`);
|
|
11131
|
+
}
|
|
11132
|
+
source = { kind: "asset", assetId: derive.from, spec: sourceSpec };
|
|
11133
|
+
} else {
|
|
11134
|
+
const file = path8.resolve(root, derive.file);
|
|
11135
|
+
source = { kind: "file", file: derive.file, sha256: existsSync7(file) ? await sha256File(file) : null };
|
|
11136
|
+
}
|
|
11137
|
+
if (derive.transform === "scale") {
|
|
11138
|
+
resolved.width = derive.width;
|
|
11139
|
+
resolved.height = derive.height;
|
|
11140
|
+
} else if (sourceSpec) {
|
|
11141
|
+
resolved.width = sourceSpec.width;
|
|
11142
|
+
resolved.height = sourceSpec.height;
|
|
11143
|
+
} else if (source.kind === "file" && source.sha256) {
|
|
11144
|
+
const metadata = imageMetadata(await readFile5(path8.resolve(root, source.file)));
|
|
11145
|
+
if (metadata?.width && metadata.height) {
|
|
11146
|
+
resolved.width = metadata.width;
|
|
11147
|
+
resolved.height = metadata.height;
|
|
11148
|
+
}
|
|
11149
|
+
}
|
|
11150
|
+
resolved.derive = {
|
|
11151
|
+
transform: derive.transform,
|
|
11152
|
+
...derive.map ? { map: derive.map } : {},
|
|
11153
|
+
...derive.palette ? { palette: derive.palette } : {},
|
|
11154
|
+
...derive.width ? { width: derive.width } : {},
|
|
11155
|
+
...derive.height ? { height: derive.height } : {},
|
|
11156
|
+
...derive.mode ? { mode: derive.mode } : {},
|
|
11157
|
+
source
|
|
11158
|
+
};
|
|
11159
|
+
resolved.prompt = "";
|
|
11160
|
+
resolved.specHash = specHash(resolved, styleImageHashes, providerOptionIdentity, providerInputIdentities.get(assetId));
|
|
11161
|
+
resolved.cost = 0;
|
|
11162
|
+
resolved.candidates = 1;
|
|
11163
|
+
finalized.add(assetId);
|
|
11164
|
+
return resolved;
|
|
11165
|
+
}
|
|
11166
|
+
if (asset.external) {
|
|
11167
|
+
const inputs = [];
|
|
11168
|
+
for (const input of asset.external.inputs ?? []) {
|
|
11169
|
+
const file = path8.resolve(root, input);
|
|
11170
|
+
inputs.push({ path: input, sha256: existsSync7(file) ? await sha256File(file) : null });
|
|
11171
|
+
}
|
|
11172
|
+
resolved.external = { builder: asset.external.builder, inputs };
|
|
11173
|
+
resolved.prompt = "";
|
|
11174
|
+
resolved.specHash = specHash(resolved, styleImageHashes, providerOptionIdentity, providerInputIdentities.get(assetId));
|
|
11175
|
+
resolved.cost = 0;
|
|
11176
|
+
resolved.candidates = 1;
|
|
11177
|
+
finalized.add(assetId);
|
|
11178
|
+
return resolved;
|
|
11179
|
+
}
|
|
11023
11180
|
if (asset.mirror) {
|
|
11024
11181
|
if (asset.mirror === assetId) throw new Error(`assets.${assetId}: an asset cannot mirror itself`);
|
|
11025
11182
|
const sourceSpec = await finalize(asset.mirror);
|
|
@@ -11181,8 +11338,8 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11181
11338
|
const sourceSpec = sourceStyleId ? await styleFinalizers.get(sourceStyleId)(asset.revision.from) : await finalize(asset.revision.from);
|
|
11182
11339
|
const sourceStem = sourceSpec.quality?.outFile ?? (sourceSpec.source ? path8.resolve(root, sourceSpec.source) : sourceSpec.outFile);
|
|
11183
11340
|
const sourceMembers = await revisionSourceMembers(sourceStem, `revision source ${asset.revision.from}`);
|
|
11184
|
-
const
|
|
11185
|
-
const sourceImage = sourceMembers ? { ...sourceMembers[0], hash: sha256(JSON.stringify(sourceMembers.map((member) => member.sha256))) } : await optionalRevisionImage(
|
|
11341
|
+
const sourceFile2 = sourceMembers?.[0]?.file ?? sourceStem;
|
|
11342
|
+
const sourceImage = sourceMembers ? { ...sourceMembers[0], hash: sha256(JSON.stringify(sourceMembers.map((member) => member.sha256))) } : await optionalRevisionImage(sourceFile2, "revision source");
|
|
11186
11343
|
const sourceFps = sourceSpec.character?.animation?.fps ?? sourceSpec.objectPro?.animation?.fps ?? sourceSpec.revision?.fps ?? sourceSpec.revision?.sourceFps;
|
|
11187
11344
|
const maskFile = asset.revision.mask ? path8.resolve(root, asset.revision.mask) : void 0;
|
|
11188
11345
|
const maskImage = maskFile ? await optionalRevisionImage(maskFile, "revision mask", "png") : null;
|
|
@@ -11201,7 +11358,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11201
11358
|
mode: asset.revision.mode,
|
|
11202
11359
|
sourceAssetId: asset.revision.from,
|
|
11203
11360
|
...sourceStyleId ? { sourceStyleId } : {},
|
|
11204
|
-
sourceFile,
|
|
11361
|
+
sourceFile: sourceFile2,
|
|
11205
11362
|
sourceSha256: sourceImage?.hash ?? null,
|
|
11206
11363
|
sourceWidth: sourceImage?.width ?? null,
|
|
11207
11364
|
sourceHeight: sourceImage?.height ?? null,
|
|
@@ -11376,8 +11533,8 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11376
11533
|
byOutput.set(file, owner);
|
|
11377
11534
|
};
|
|
11378
11535
|
for (const spec of specs) {
|
|
11379
|
-
const
|
|
11380
|
-
claimOutput(spec.outFile,
|
|
11536
|
+
const key2 = `${spec.styleId}/${spec.assetId}`;
|
|
11537
|
+
claimOutput(spec.outFile, key2);
|
|
11381
11538
|
if (spec.quality) {
|
|
11382
11539
|
if (spec.generator === "frames") {
|
|
11383
11540
|
const frameInputs = Object.values(spec.providerInputs ?? {}).find(Array.isArray);
|
|
@@ -11392,11 +11549,11 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11392
11549
|
count,
|
|
11393
11550
|
MediaType.PNG
|
|
11394
11551
|
),
|
|
11395
|
-
`${
|
|
11552
|
+
`${key2} quality ${role}`
|
|
11396
11553
|
);
|
|
11397
11554
|
}
|
|
11398
11555
|
} else {
|
|
11399
|
-
claimOutput(spec.quality.outFile, `${
|
|
11556
|
+
claimOutput(spec.quality.outFile, `${key2} quality output`);
|
|
11400
11557
|
}
|
|
11401
11558
|
}
|
|
11402
11559
|
}
|
|
@@ -11660,7 +11817,7 @@ function characterDirections(directions) {
|
|
|
11660
11817
|
}
|
|
11661
11818
|
|
|
11662
11819
|
// src/project.ts
|
|
11663
|
-
import
|
|
11820
|
+
import path18 from "path";
|
|
11664
11821
|
|
|
11665
11822
|
// src/env.ts
|
|
11666
11823
|
import { readFileSync as readFileSync4, existsSync as existsSync8 } from "fs";
|
|
@@ -11668,8 +11825,8 @@ import path9 from "path";
|
|
|
11668
11825
|
function loadEnvFiles(dir) {
|
|
11669
11826
|
const loaded = [];
|
|
11670
11827
|
for (const [file, vars] of envFiles(dir)) {
|
|
11671
|
-
for (const [
|
|
11672
|
-
if (!(
|
|
11828
|
+
for (const [key2, value] of Object.entries(vars)) {
|
|
11829
|
+
if (!(key2 in process.env)) process.env[key2] = value;
|
|
11673
11830
|
}
|
|
11674
11831
|
loaded.push(file);
|
|
11675
11832
|
}
|
|
@@ -11694,21 +11851,21 @@ function parseEnv(contents) {
|
|
|
11694
11851
|
if (!line || line.startsWith("#")) continue;
|
|
11695
11852
|
const eq = line.indexOf("=");
|
|
11696
11853
|
if (eq <= 0) continue;
|
|
11697
|
-
const
|
|
11698
|
-
if (!
|
|
11854
|
+
const key2 = line.slice(0, eq).replace(/^export\s+/, "").trim();
|
|
11855
|
+
if (!key2 || key2 in vars) continue;
|
|
11699
11856
|
let value = line.slice(eq + 1).trim();
|
|
11700
11857
|
const quote = value[0];
|
|
11701
11858
|
if ((quote === '"' || quote === "'") && value.endsWith(quote) && value.length >= 2) {
|
|
11702
11859
|
value = value.slice(1, -1);
|
|
11703
11860
|
}
|
|
11704
|
-
vars[
|
|
11861
|
+
vars[key2] = value;
|
|
11705
11862
|
}
|
|
11706
11863
|
return vars;
|
|
11707
11864
|
}
|
|
11708
11865
|
|
|
11709
11866
|
// src/pipeline/plan.ts
|
|
11710
|
-
import { existsSync as
|
|
11711
|
-
import
|
|
11867
|
+
import { existsSync as existsSync13 } from "fs";
|
|
11868
|
+
import path17 from "path";
|
|
11712
11869
|
|
|
11713
11870
|
// src/pipeline/mirror.ts
|
|
11714
11871
|
import { mkdir as mkdir4, readFile as readFile6, rename as rename2, writeFile as writeFile4 } from "fs/promises";
|
|
@@ -11750,8 +11907,8 @@ function quantize(png, palette) {
|
|
|
11750
11907
|
pixels[i + 2] = 0;
|
|
11751
11908
|
continue;
|
|
11752
11909
|
}
|
|
11753
|
-
const
|
|
11754
|
-
let nearest = nearestOf.get(
|
|
11910
|
+
const key2 = pixels[i] << 16 | pixels[i + 1] << 8 | pixels[i + 2];
|
|
11911
|
+
let nearest = nearestOf.get(key2);
|
|
11755
11912
|
if (!nearest) {
|
|
11756
11913
|
const pixel = { r: pixels[i], g: pixels[i + 1], b: pixels[i + 2] };
|
|
11757
11914
|
nearest = colors[0];
|
|
@@ -11764,7 +11921,7 @@ function quantize(png, palette) {
|
|
|
11764
11921
|
distance = candidateDistance;
|
|
11765
11922
|
}
|
|
11766
11923
|
}
|
|
11767
|
-
nearestOf.set(
|
|
11924
|
+
nearestOf.set(key2, nearest);
|
|
11768
11925
|
}
|
|
11769
11926
|
if (pixels[i] !== nearest.r || pixels[i + 1] !== nearest.g || pixels[i + 2] !== nearest.b) changed++;
|
|
11770
11927
|
pixels[i] = nearest.r;
|
|
@@ -11833,7 +11990,7 @@ async function deriveMirror(spec, lock, lockPath, opts = {}) {
|
|
|
11833
11990
|
const log = opts.onProgress ?? (() => {
|
|
11834
11991
|
});
|
|
11835
11992
|
const mirror = spec.mirror;
|
|
11836
|
-
const
|
|
11993
|
+
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
11837
11994
|
const sourceKey = lockKey(spec.styleId, mirror.sourceAssetId);
|
|
11838
11995
|
const source = lock.entries[sourceKey];
|
|
11839
11996
|
if (!source || source.status !== "downloaded" || !source.outputs.length) {
|
|
@@ -11865,7 +12022,7 @@ async function deriveMirror(spec, lock, lockPath, opts = {}) {
|
|
|
11865
12022
|
}
|
|
11866
12023
|
const sourceMetadata = source.providerMetadata?.[source.provider] ?? {};
|
|
11867
12024
|
const character = spec.character;
|
|
11868
|
-
const entry = upsert(lock,
|
|
12025
|
+
const entry = upsert(lock, key2, {
|
|
11869
12026
|
styleId: spec.styleId,
|
|
11870
12027
|
assetId: spec.assetId,
|
|
11871
12028
|
specHash: spec.specHash,
|
|
@@ -11908,25 +12065,206 @@ async function deriveMirror(spec, lock, lockPath, opts = {}) {
|
|
|
11908
12065
|
postprocess: postprocessFor(spec)
|
|
11909
12066
|
});
|
|
11910
12067
|
await saveLock(lockPath, lock);
|
|
11911
|
-
log(` mirror ${
|
|
12068
|
+
log(` mirror ${key2} \u2190 ${sourceKey} (${written.length} file${written.length === 1 ? "" : "s"} flipped, no generation cost)`);
|
|
11912
12069
|
return entry;
|
|
11913
12070
|
}
|
|
11914
12071
|
|
|
11915
|
-
// src/pipeline/
|
|
12072
|
+
// src/pipeline/derive.ts
|
|
11916
12073
|
import { existsSync as existsSync9 } from "fs";
|
|
11917
|
-
import
|
|
12074
|
+
import { mkdir as mkdir5, readFile as readFile7, rename as rename3, writeFile as writeFile5 } from "fs/promises";
|
|
12075
|
+
import path11 from "path";
|
|
12076
|
+
var key = (r, g, b) => r << 16 | g << 8 | b;
|
|
12077
|
+
function recolor(png, map) {
|
|
12078
|
+
const { width, height, pixels } = decodePng(png);
|
|
12079
|
+
const table = /* @__PURE__ */ new Map();
|
|
12080
|
+
for (const [from, to] of Object.entries(map)) {
|
|
12081
|
+
const a = parseHex(from);
|
|
12082
|
+
const b = parseHex(to);
|
|
12083
|
+
table.set(key(a.r, a.g, a.b), [b.r, b.g, b.b]);
|
|
12084
|
+
}
|
|
12085
|
+
const out = Buffer.from(pixels);
|
|
12086
|
+
for (let i = 0; i < out.length; i += 4) {
|
|
12087
|
+
if (out[i + 3] === 0) continue;
|
|
12088
|
+
const hit = table.get(key(out[i], out[i + 1], out[i + 2]));
|
|
12089
|
+
if (hit) {
|
|
12090
|
+
out[i] = hit[0];
|
|
12091
|
+
out[i + 1] = hit[1];
|
|
12092
|
+
out[i + 2] = hit[2];
|
|
12093
|
+
}
|
|
12094
|
+
}
|
|
12095
|
+
return encodeRgbaPng(width, height, out);
|
|
12096
|
+
}
|
|
12097
|
+
function paletteSnap(png, palette) {
|
|
12098
|
+
const snapped = quantize(decodePng(png), normalizePalette(palette).map((color) => color.hex)).png;
|
|
12099
|
+
return encodeRgbaPng(snapped.width, snapped.height, snapped.pixels);
|
|
12100
|
+
}
|
|
12101
|
+
function scale(png, width, height, mode2 = "nearest") {
|
|
12102
|
+
const src = decodePng(png);
|
|
12103
|
+
const out = Buffer.alloc(width * height * 4);
|
|
12104
|
+
for (let y = 0; y < height; y++) {
|
|
12105
|
+
const y0 = Math.floor(y * src.height / height);
|
|
12106
|
+
const y1 = Math.max(y0 + 1, Math.ceil((y + 1) * src.height / height));
|
|
12107
|
+
for (let x = 0; x < width; x++) {
|
|
12108
|
+
const x0 = Math.floor(x * src.width / width);
|
|
12109
|
+
const x1 = Math.max(x0 + 1, Math.ceil((x + 1) * src.width / width));
|
|
12110
|
+
const at = (y * width + x) * 4;
|
|
12111
|
+
if (mode2 === "nearest") {
|
|
12112
|
+
src.pixels.copy(out, at, (y0 * src.width + x0) * 4, (y0 * src.width + x0) * 4 + 4);
|
|
12113
|
+
continue;
|
|
12114
|
+
}
|
|
12115
|
+
let a = 0;
|
|
12116
|
+
let r = 0;
|
|
12117
|
+
let g = 0;
|
|
12118
|
+
let b = 0;
|
|
12119
|
+
let n = 0;
|
|
12120
|
+
for (let sy = y0; sy < Math.min(y1, src.height); sy++) {
|
|
12121
|
+
for (let sx = x0; sx < Math.min(x1, src.width); sx++) {
|
|
12122
|
+
const i = (sy * src.width + sx) * 4;
|
|
12123
|
+
const alpha = src.pixels[i + 3];
|
|
12124
|
+
a += alpha;
|
|
12125
|
+
r += src.pixels[i] * alpha;
|
|
12126
|
+
g += src.pixels[i + 1] * alpha;
|
|
12127
|
+
b += src.pixels[i + 2] * alpha;
|
|
12128
|
+
n++;
|
|
12129
|
+
}
|
|
12130
|
+
}
|
|
12131
|
+
if (a > 0) {
|
|
12132
|
+
out[at] = Math.round(r / a);
|
|
12133
|
+
out[at + 1] = Math.round(g / a);
|
|
12134
|
+
out[at + 2] = Math.round(b / a);
|
|
12135
|
+
}
|
|
12136
|
+
out[at + 3] = Math.round(a / Math.max(1, n));
|
|
12137
|
+
}
|
|
12138
|
+
}
|
|
12139
|
+
return encodeRgbaPng(width, height, out);
|
|
12140
|
+
}
|
|
12141
|
+
function applyDerive(png, derive) {
|
|
12142
|
+
switch (derive.transform) {
|
|
12143
|
+
case "recolor":
|
|
12144
|
+
return recolor(png, derive.map);
|
|
12145
|
+
case "palette-snap":
|
|
12146
|
+
return paletteSnap(png, derive.palette);
|
|
12147
|
+
case "scale":
|
|
12148
|
+
return scale(png, derive.width, derive.height, derive.mode);
|
|
12149
|
+
}
|
|
12150
|
+
}
|
|
12151
|
+
async function sourceFile(spec, lock) {
|
|
12152
|
+
const derive = spec.derive;
|
|
12153
|
+
if (derive.source.kind === "file") {
|
|
12154
|
+
const file2 = path11.resolve(spec.root, derive.source.file);
|
|
12155
|
+
return existsSync9(file2) ? { file: file2, recorded: await sha256File(file2) } : { notReady: `source file ${derive.source.file} does not exist` };
|
|
12156
|
+
}
|
|
12157
|
+
const sourceKey = lockKey(spec.styleId, derive.source.assetId);
|
|
12158
|
+
const entry = lock.entries[sourceKey];
|
|
12159
|
+
if (!entry || entry.status !== "downloaded" || !entry.outputs.length) {
|
|
12160
|
+
return { notReady: `source ${sourceKey} has no downloaded output` };
|
|
12161
|
+
}
|
|
12162
|
+
if (entry.outputs.length !== 1) {
|
|
12163
|
+
return { notReady: `source ${sourceKey} has ${entry.outputs.length} outputs; derive takes a single image` };
|
|
12164
|
+
}
|
|
12165
|
+
const file = currentEntryOutputPath(entry, derive.source.spec, 0);
|
|
12166
|
+
if (!existsSync9(file)) return { notReady: `source ${sourceKey} is missing on disk: ${file}` };
|
|
12167
|
+
return { file, recorded: entry.outputs[0].sha256 };
|
|
12168
|
+
}
|
|
12169
|
+
async function deriveStale(spec, entry, lock) {
|
|
12170
|
+
const derive = spec.derive;
|
|
12171
|
+
if (derive.source.kind === "file") {
|
|
12172
|
+
const file = path11.resolve(spec.root, derive.source.file);
|
|
12173
|
+
if (!existsSync9(file)) return `source file ${derive.source.file} is missing`;
|
|
12174
|
+
return entry.derive?.sourceSha256 === await sha256File(file) ? null : `source file ${derive.source.file} changed`;
|
|
12175
|
+
}
|
|
12176
|
+
const source = lock.entries[lockKey(spec.styleId, derive.source.assetId)];
|
|
12177
|
+
const current = source?.outputs.length === 1 ? source.outputs[0].sha256 : void 0;
|
|
12178
|
+
return entry.derive?.sourceSha256 && entry.derive.sourceSha256 === current ? null : `source ${derive.source.assetId} changed`;
|
|
12179
|
+
}
|
|
12180
|
+
async function deriveAsset(spec, lock, lockPath, opts = {}) {
|
|
12181
|
+
const log = opts.onProgress ?? (() => {
|
|
12182
|
+
});
|
|
12183
|
+
const derive = spec.derive;
|
|
12184
|
+
const entryKey = lockKey(spec.styleId, spec.assetId);
|
|
12185
|
+
const source = await sourceFile(spec, lock);
|
|
12186
|
+
if ("notReady" in source) throw new Error(source.notReady);
|
|
12187
|
+
const bytes = applyDerive(await readFile7(source.file), derive);
|
|
12188
|
+
const target = expectedOutputPath(spec, void 0, 0, 1, MediaType.PNG);
|
|
12189
|
+
await mkdir5(path11.dirname(target), { recursive: true });
|
|
12190
|
+
const tmp = `${target}.pixelkiln.tmp`;
|
|
12191
|
+
await writeFile5(tmp, bytes);
|
|
12192
|
+
await rename3(tmp, target);
|
|
12193
|
+
const out = decodePng(bytes);
|
|
12194
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
12195
|
+
const entry = upsert(lock, entryKey, {
|
|
12196
|
+
styleId: spec.styleId,
|
|
12197
|
+
assetId: spec.assetId,
|
|
12198
|
+
specHash: spec.specHash,
|
|
12199
|
+
generator: spec.generator,
|
|
12200
|
+
tileFeature: null,
|
|
12201
|
+
prompt: "",
|
|
12202
|
+
width: out.width,
|
|
12203
|
+
height: out.height,
|
|
12204
|
+
revision: null,
|
|
12205
|
+
derive: derive.source.kind === "asset" ? { sourceAssetId: derive.source.assetId, sourceSha256: source.recorded } : { sourceFile: derive.source.file, sourceSha256: source.recorded },
|
|
12206
|
+
supersededOutputs: [],
|
|
12207
|
+
jobId: null,
|
|
12208
|
+
submissionComplete: void 0,
|
|
12209
|
+
reviewObjectId: null,
|
|
12210
|
+
objectId: null,
|
|
12211
|
+
candidateIndex: null,
|
|
12212
|
+
status: "downloaded",
|
|
12213
|
+
error: null,
|
|
12214
|
+
outputs: [{ path: portableOutputPath(target, spec.root), sha256: sha256(bytes), mediaType: MediaType.PNG }],
|
|
12215
|
+
sourceUrl: null,
|
|
12216
|
+
sourceUrls: [],
|
|
12217
|
+
submittedAt: now,
|
|
12218
|
+
downloadedAt: now,
|
|
12219
|
+
history: [],
|
|
12220
|
+
cost: 0,
|
|
12221
|
+
costUnit: spec.costUnit,
|
|
12222
|
+
provider: spec.provider,
|
|
12223
|
+
postprocess: void 0
|
|
12224
|
+
});
|
|
12225
|
+
await saveLock(lockPath, lock);
|
|
12226
|
+
log(` derive ${entryKey} \u2190 ${derive.source.kind === "asset" ? derive.source.assetId : derive.source.file} (${derive.transform}, no generation cost)`);
|
|
12227
|
+
return entry;
|
|
12228
|
+
}
|
|
11918
12229
|
|
|
11919
|
-
// src/pipeline/
|
|
12230
|
+
// src/pipeline/external.ts
|
|
12231
|
+
import { existsSync as existsSync10 } from "fs";
|
|
11920
12232
|
import path12 from "path";
|
|
12233
|
+
async function inspectExternal(spec, entry) {
|
|
12234
|
+
const external = spec.external;
|
|
12235
|
+
const file = entry?.outputs.length ? currentEntryOutputPath(entry, spec, 0) : spec.outFile;
|
|
12236
|
+
const rebuild = `run \`${external.builder}\``;
|
|
12237
|
+
if (!existsSync10(file)) {
|
|
12238
|
+
return { state: "orphaned", reason: `built outside pixelkiln and not found at ${path12.relative(spec.root, file)}; ${rebuild}, then adopt --local` };
|
|
12239
|
+
}
|
|
12240
|
+
if (!entry) {
|
|
12241
|
+
return { state: "untracked", reason: `built outside pixelkiln; record it with adopt --local (builder: ${external.builder})` };
|
|
12242
|
+
}
|
|
12243
|
+
if (entry.specHash !== spec.specHash) {
|
|
12244
|
+
return { state: "orphaned", reason: `builder or an input changed since the file was recorded; ${rebuild}, then adopt --local --force` };
|
|
12245
|
+
}
|
|
12246
|
+
const recorded = entry.outputs[0]?.sha256;
|
|
12247
|
+
if (!recorded || await sha256File(file) !== recorded) {
|
|
12248
|
+
return { state: "orphaned", reason: "file changed since it was recorded; adopt --local --force to record it again" };
|
|
12249
|
+
}
|
|
12250
|
+
return { state: "ok", reason: "built outside pixelkiln; matches the recorded file" };
|
|
12251
|
+
}
|
|
12252
|
+
|
|
12253
|
+
// src/pipeline/quality-profile.ts
|
|
12254
|
+
import { existsSync as existsSync11 } from "fs";
|
|
12255
|
+
import path15 from "path";
|
|
12256
|
+
|
|
12257
|
+
// src/pipeline/refine.ts
|
|
12258
|
+
import path14 from "path";
|
|
11921
12259
|
import { execFile } from "child_process";
|
|
11922
|
-
import { mkdtemp, readFile as
|
|
12260
|
+
import { mkdtemp, readFile as readFile9, rm as rm3 } from "fs/promises";
|
|
11923
12261
|
import { tmpdir } from "os";
|
|
11924
12262
|
import { promisify } from "util";
|
|
11925
12263
|
|
|
11926
12264
|
// src/artifacts.ts
|
|
11927
|
-
import
|
|
12265
|
+
import path13 from "path";
|
|
11928
12266
|
import { createHash as createHash4, randomUUID as randomUUID3 } from "crypto";
|
|
11929
|
-
import { mkdir as
|
|
12267
|
+
import { mkdir as mkdir6, readFile as readFile8, rename as rename4, rm as rm2, writeFile as writeFile6 } from "fs/promises";
|
|
11930
12268
|
var activeTransactions = /* @__PURE__ */ new Set();
|
|
11931
12269
|
function message(error) {
|
|
11932
12270
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -11935,7 +12273,7 @@ function digest(data) {
|
|
|
11935
12273
|
return createHash4("sha256").update(data).digest("hex");
|
|
11936
12274
|
}
|
|
11937
12275
|
function portableRelative(from, to) {
|
|
11938
|
-
return
|
|
12276
|
+
return path13.relative(from, path13.resolve(to)).split(path13.sep).join("/") || ".";
|
|
11939
12277
|
}
|
|
11940
12278
|
function canonical2(value) {
|
|
11941
12279
|
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
@@ -11946,9 +12284,9 @@ function canonical2(value) {
|
|
|
11946
12284
|
if (Array.isArray(value)) return value.map(canonical2);
|
|
11947
12285
|
if (typeof value === "object") {
|
|
11948
12286
|
const sorted = {};
|
|
11949
|
-
for (const
|
|
11950
|
-
const item = value[
|
|
11951
|
-
if (item !== void 0) sorted[
|
|
12287
|
+
for (const key2 of Object.keys(value).sort()) {
|
|
12288
|
+
const item = value[key2];
|
|
12289
|
+
if (item !== void 0) sorted[key2] = canonical2(item);
|
|
11952
12290
|
}
|
|
11953
12291
|
return sorted;
|
|
11954
12292
|
}
|
|
@@ -11985,12 +12323,12 @@ function parseArtifactManifest(absolute, data) {
|
|
|
11985
12323
|
return raw;
|
|
11986
12324
|
}
|
|
11987
12325
|
async function readArtifactBundleManifest(manifestPath) {
|
|
11988
|
-
const absolute =
|
|
11989
|
-
return parseArtifactManifest(absolute, await
|
|
12326
|
+
const absolute = path13.resolve(manifestPath);
|
|
12327
|
+
return parseArtifactManifest(absolute, await readFile8(absolute, "utf8"));
|
|
11990
12328
|
}
|
|
11991
12329
|
async function readOptional(file) {
|
|
11992
12330
|
try {
|
|
11993
|
-
return await
|
|
12331
|
+
return await readFile8(file);
|
|
11994
12332
|
} catch (error) {
|
|
11995
12333
|
if (isCode(error, "ENOENT")) return null;
|
|
11996
12334
|
throw error;
|
|
@@ -12009,8 +12347,8 @@ function processIsAlive(pid) {
|
|
|
12009
12347
|
}
|
|
12010
12348
|
}
|
|
12011
12349
|
function validTemporaryPath(candidate, destination, type) {
|
|
12012
|
-
return
|
|
12013
|
-
`.${
|
|
12350
|
+
return path13.dirname(candidate) === path13.dirname(destination) && path13.basename(candidate).startsWith(
|
|
12351
|
+
`.${path13.basename(destination)}.pixelkiln-${type}-`
|
|
12014
12352
|
);
|
|
12015
12353
|
}
|
|
12016
12354
|
function parseTransaction(journal, data) {
|
|
@@ -12030,7 +12368,7 @@ async function removeTransactionFiles(journal) {
|
|
|
12030
12368
|
await rm2(transactionMarker(journal), { force: true });
|
|
12031
12369
|
}
|
|
12032
12370
|
async function recoverArtifactTransaction(recoveryFile, allowedDestinations) {
|
|
12033
|
-
const journal =
|
|
12371
|
+
const journal = path13.resolve(recoveryFile);
|
|
12034
12372
|
const bytes = await readOptional(journal);
|
|
12035
12373
|
if (!bytes) {
|
|
12036
12374
|
await rm2(transactionMarker(journal), { force: true });
|
|
@@ -12046,7 +12384,7 @@ async function recoverArtifactTransaction(recoveryFile, allowedDestinations) {
|
|
|
12046
12384
|
);
|
|
12047
12385
|
}
|
|
12048
12386
|
for (const entry of transaction.entries) {
|
|
12049
|
-
if (typeof entry.destination !== "string" || typeof entry.stage !== "string" || typeof entry.sha256 !== "string" || entry.backup !== void 0 && typeof entry.backup !== "string" || !allowedDestinations.has(
|
|
12387
|
+
if (typeof entry.destination !== "string" || typeof entry.stage !== "string" || typeof entry.sha256 !== "string" || entry.backup !== void 0 && typeof entry.backup !== "string" || !allowedDestinations.has(path13.resolve(entry.destination)) || !validTemporaryPath(entry.stage, entry.destination, "stage") || entry.backup !== void 0 && !validTemporaryPath(entry.backup, entry.destination, "backup")) {
|
|
12050
12388
|
throw new Error(
|
|
12051
12389
|
`Refusing unsafe artifact recovery from ${journal}; its destinations or temporary paths do not match the current bundle.`
|
|
12052
12390
|
);
|
|
@@ -12072,7 +12410,7 @@ async function recoverArtifactTransaction(recoveryFile, allowedDestinations) {
|
|
|
12072
12410
|
}
|
|
12073
12411
|
await remove2(entry.destination, errors);
|
|
12074
12412
|
try {
|
|
12075
|
-
await
|
|
12413
|
+
await rename4(entry.backup, entry.destination);
|
|
12076
12414
|
} catch (error) {
|
|
12077
12415
|
errors.push(
|
|
12078
12416
|
`could not restore ${entry.destination}; previous file remains at ${entry.backup}: ${message(error)}`
|
|
@@ -12092,7 +12430,7 @@ async function recoverArtifactTransaction(recoveryFile, allowedDestinations) {
|
|
|
12092
12430
|
await removeTransactionFiles(journal);
|
|
12093
12431
|
}
|
|
12094
12432
|
function createArtifactBundleManifest(manifestPath, outputs, provenance) {
|
|
12095
|
-
const root =
|
|
12433
|
+
const root = path13.dirname(path13.resolve(manifestPath));
|
|
12096
12434
|
const sources = provenance.sources.map((source) => ({
|
|
12097
12435
|
...source,
|
|
12098
12436
|
path: portableRelative(root, source.path)
|
|
@@ -12122,11 +12460,11 @@ function withArtifactManifest(manifestPath, outputs, provenance) {
|
|
|
12122
12460
|
];
|
|
12123
12461
|
}
|
|
12124
12462
|
async function writeManagedArtifactBundle(manifestPath, outputs, provenance, options = {}) {
|
|
12125
|
-
const absoluteManifest =
|
|
12463
|
+
const absoluteManifest = path13.resolve(manifestPath);
|
|
12126
12464
|
const recoveryFile = `${absoluteManifest}.transaction`;
|
|
12127
12465
|
const allowedDestinations = /* @__PURE__ */ new Set([
|
|
12128
12466
|
absoluteManifest,
|
|
12129
|
-
...outputs.map((output) =>
|
|
12467
|
+
...outputs.map((output) => path13.resolve(output.path))
|
|
12130
12468
|
]);
|
|
12131
12469
|
await recoverArtifactTransaction(recoveryFile, allowedDestinations);
|
|
12132
12470
|
const existingManifestBytes = await readOptional(absoluteManifest);
|
|
@@ -12144,13 +12482,13 @@ async function writeManagedArtifactBundle(manifestPath, outputs, provenance, opt
|
|
|
12144
12482
|
}
|
|
12145
12483
|
}
|
|
12146
12484
|
if (!options.force) {
|
|
12147
|
-
const root =
|
|
12485
|
+
const root = path13.dirname(absoluteManifest);
|
|
12148
12486
|
const recorded = new Map(
|
|
12149
|
-
previous?.outputs.map((output) => [
|
|
12487
|
+
previous?.outputs.map((output) => [path13.resolve(root, output.path), output.sha256]) ?? []
|
|
12150
12488
|
);
|
|
12151
12489
|
const conflicts = [];
|
|
12152
12490
|
for (const output of outputs) {
|
|
12153
|
-
const destination =
|
|
12491
|
+
const destination = path13.resolve(output.path);
|
|
12154
12492
|
const current = await readOptional(destination);
|
|
12155
12493
|
if (!current || digest(current) === digest(output.data)) continue;
|
|
12156
12494
|
const expected = recorded.get(destination);
|
|
@@ -12172,15 +12510,15 @@ Pass { force: true } (CLI: --force) to take ownership and replace the complete b
|
|
|
12172
12510
|
);
|
|
12173
12511
|
}
|
|
12174
12512
|
async function verifyArtifactBundle(manifestPath) {
|
|
12175
|
-
const absolute =
|
|
12513
|
+
const absolute = path13.resolve(manifestPath);
|
|
12176
12514
|
const raw = await readArtifactBundleManifest(absolute);
|
|
12177
|
-
const root =
|
|
12515
|
+
const root = path13.dirname(absolute);
|
|
12178
12516
|
const changedSources = [];
|
|
12179
12517
|
const changedOutputs = [];
|
|
12180
12518
|
for (const source of raw.sources) {
|
|
12181
12519
|
let actual = null;
|
|
12182
12520
|
try {
|
|
12183
|
-
actual = digest(await
|
|
12521
|
+
actual = digest(await readFile8(path13.resolve(root, source.path)));
|
|
12184
12522
|
} catch (error) {
|
|
12185
12523
|
if (!isCode(error, "ENOENT")) throw error;
|
|
12186
12524
|
}
|
|
@@ -12188,7 +12526,7 @@ async function verifyArtifactBundle(manifestPath) {
|
|
|
12188
12526
|
}
|
|
12189
12527
|
for (const output of raw.outputs) {
|
|
12190
12528
|
try {
|
|
12191
|
-
if (digest(await
|
|
12529
|
+
if (digest(await readFile8(path13.resolve(root, output.path))) !== output.sha256) {
|
|
12192
12530
|
changedOutputs.push(output.path);
|
|
12193
12531
|
}
|
|
12194
12532
|
} catch (error) {
|
|
@@ -12227,7 +12565,7 @@ async function rollback(prepared) {
|
|
|
12227
12565
|
for (const artifact of [...prepared].reverse()) {
|
|
12228
12566
|
if (!artifact.backup || !artifact.backedUp) continue;
|
|
12229
12567
|
try {
|
|
12230
|
-
await
|
|
12568
|
+
await rename4(artifact.backup, artifact.destination);
|
|
12231
12569
|
artifact.backedUp = false;
|
|
12232
12570
|
} catch (error) {
|
|
12233
12571
|
errors.push(
|
|
@@ -12244,7 +12582,7 @@ async function writeArtifactBundle(files, options = {}) {
|
|
|
12244
12582
|
if (!files.length) throw new Error("An artifact bundle must contain at least one file.");
|
|
12245
12583
|
const normalized = files.map((file) => {
|
|
12246
12584
|
if (!file.path.trim()) throw new Error("Artifact paths cannot be empty.");
|
|
12247
|
-
return { destination:
|
|
12585
|
+
return { destination: path13.resolve(file.path), data: Buffer.from(file.data) };
|
|
12248
12586
|
});
|
|
12249
12587
|
const destinations = /* @__PURE__ */ new Set();
|
|
12250
12588
|
for (const artifact of normalized) {
|
|
@@ -12260,7 +12598,7 @@ async function writeArtifactBundle(files, options = {}) {
|
|
|
12260
12598
|
const unchanged = [];
|
|
12261
12599
|
for (const artifact of normalized) {
|
|
12262
12600
|
try {
|
|
12263
|
-
const current = await
|
|
12601
|
+
const current = await readFile8(artifact.destination);
|
|
12264
12602
|
if (current.equals(artifact.data)) {
|
|
12265
12603
|
unchanged.push(artifact.destination);
|
|
12266
12604
|
} else {
|
|
@@ -12274,21 +12612,21 @@ async function writeArtifactBundle(files, options = {}) {
|
|
|
12274
12612
|
if (!changed.length) return { changed: [], unchanged };
|
|
12275
12613
|
const token = randomUUID3();
|
|
12276
12614
|
for (const [index, artifact] of changed.entries()) {
|
|
12277
|
-
const basename =
|
|
12278
|
-
artifact.stage =
|
|
12279
|
-
|
|
12615
|
+
const basename = path13.basename(artifact.destination);
|
|
12616
|
+
artifact.stage = path13.join(
|
|
12617
|
+
path13.dirname(artifact.destination),
|
|
12280
12618
|
`.${basename}.pixelkiln-stage-${token}-${index}`
|
|
12281
12619
|
);
|
|
12282
12620
|
if (artifact.existed) {
|
|
12283
|
-
artifact.backup =
|
|
12284
|
-
|
|
12621
|
+
artifact.backup = path13.join(
|
|
12622
|
+
path13.dirname(artifact.destination),
|
|
12285
12623
|
`.${basename}.pixelkiln-backup-${token}-${index}`
|
|
12286
12624
|
);
|
|
12287
12625
|
}
|
|
12288
12626
|
}
|
|
12289
|
-
const journal = options.recoveryFile ?
|
|
12627
|
+
const journal = options.recoveryFile ? path13.resolve(options.recoveryFile) : null;
|
|
12290
12628
|
if (journal) {
|
|
12291
|
-
await
|
|
12629
|
+
await mkdir6(path13.dirname(journal), { recursive: true });
|
|
12292
12630
|
const transaction = {
|
|
12293
12631
|
format: "pixelkiln-artifact-transaction",
|
|
12294
12632
|
version: 1,
|
|
@@ -12302,7 +12640,7 @@ async function writeArtifactBundle(files, options = {}) {
|
|
|
12302
12640
|
}))
|
|
12303
12641
|
};
|
|
12304
12642
|
try {
|
|
12305
|
-
await
|
|
12643
|
+
await writeFile6(journal, JSON.stringify(transaction, null, 2) + "\n", { flag: "wx" });
|
|
12306
12644
|
activeTransactions.add(journal);
|
|
12307
12645
|
} catch (error) {
|
|
12308
12646
|
throw new Error(
|
|
@@ -12313,9 +12651,9 @@ async function writeArtifactBundle(files, options = {}) {
|
|
|
12313
12651
|
}
|
|
12314
12652
|
try {
|
|
12315
12653
|
for (const [index, artifact] of changed.entries()) {
|
|
12316
|
-
await
|
|
12654
|
+
await mkdir6(path13.dirname(artifact.destination), { recursive: true });
|
|
12317
12655
|
await options.beforeStage?.(artifact.destination, index);
|
|
12318
|
-
await
|
|
12656
|
+
await writeFile6(artifact.stage, artifact.data, { flag: "wx" });
|
|
12319
12657
|
}
|
|
12320
12658
|
} catch (error) {
|
|
12321
12659
|
const cleanupErrors2 = await rollback(changed);
|
|
@@ -12328,17 +12666,17 @@ async function writeArtifactBundle(files, options = {}) {
|
|
|
12328
12666
|
try {
|
|
12329
12667
|
for (const artifact of changed) {
|
|
12330
12668
|
if (!artifact.existed) continue;
|
|
12331
|
-
await
|
|
12669
|
+
await rename4(artifact.destination, artifact.backup);
|
|
12332
12670
|
artifact.backedUp = true;
|
|
12333
12671
|
}
|
|
12334
12672
|
for (const [index, artifact] of changed.entries()) {
|
|
12335
12673
|
await options.beforePromote?.(artifact.destination, index);
|
|
12336
|
-
await
|
|
12674
|
+
await rename4(artifact.stage, artifact.destination);
|
|
12337
12675
|
artifact.stage = void 0;
|
|
12338
12676
|
artifact.promoted = true;
|
|
12339
12677
|
}
|
|
12340
12678
|
if (journal) {
|
|
12341
|
-
await
|
|
12679
|
+
await writeFile6(transactionMarker(journal), `${token}
|
|
12342
12680
|
`, { flag: "wx" });
|
|
12343
12681
|
durableCommit = true;
|
|
12344
12682
|
await options.afterCommit?.();
|
|
@@ -12579,16 +12917,16 @@ function sameFrameGrid(first, next) {
|
|
|
12579
12917
|
return next.detection.stepX === first.detection.stepX && next.detection.stepY === first.detection.stepY && next.detection.columns === first.detection.columns && next.detection.rows === first.detection.rows && phaseMatches(next.detection.phaseX, first.detection.phaseX, first.detection.stepX) && phaseMatches(next.detection.phaseY, first.detection.phaseY, first.detection.stepY) && next.audit.width === first.audit.width && next.audit.height === first.audit.height && next.sourceWidth === first.sourceWidth && next.sourceHeight === first.sourceHeight;
|
|
12580
12918
|
}
|
|
12581
12919
|
async function refineAsset(options) {
|
|
12582
|
-
const source =
|
|
12583
|
-
const output =
|
|
12920
|
+
const source = path14.resolve(options.source);
|
|
12921
|
+
const output = path14.resolve(options.output);
|
|
12584
12922
|
if (source === output) throw new Error("Refinement source and output must be different files.");
|
|
12585
|
-
const record =
|
|
12923
|
+
const record = path14.resolve(qualityRecordPath(output));
|
|
12586
12924
|
const palette = normalizePalette(options.palette).map((color) => color.hex);
|
|
12587
12925
|
const minGridConfidence = requireConfidence(options.minGridConfidence ?? "high");
|
|
12588
12926
|
if (options.minTransparency !== void 0 && (!Number.isFinite(options.minTransparency) || options.minTransparency < 0 || options.minTransparency > 1)) throw new Error("minTransparency must be between 0 and 1.");
|
|
12589
12927
|
let sourcePng;
|
|
12590
12928
|
try {
|
|
12591
|
-
sourcePng = decodePng(await
|
|
12929
|
+
sourcePng = decodePng(await readFile9(source));
|
|
12592
12930
|
} catch (error) {
|
|
12593
12931
|
throw new Error(`Cannot read refinement source ${source}: ${message2(error)}`, { cause: error });
|
|
12594
12932
|
}
|
|
@@ -12605,8 +12943,8 @@ async function refineAsset(options) {
|
|
|
12605
12943
|
);
|
|
12606
12944
|
}
|
|
12607
12945
|
}
|
|
12608
|
-
const temp = await mkdtemp(
|
|
12609
|
-
const recovered =
|
|
12946
|
+
const temp = await mkdtemp(path14.join(tmpdir(), "pixelkiln-refine-"));
|
|
12947
|
+
const recovered = path14.join(temp, "native.png");
|
|
12610
12948
|
const fixerCommand = compatibilityCommand ?? options.fixerPython ?? process.env.PIXELKILN_PIXEL_FIXER_PYTHON ?? "python3";
|
|
12611
12949
|
const args = compatibilityCommand ? [...options.fixerArgsPrefix ?? [], source, "--extract", recovered] : ["-c", PYTHON_FIXER_BRIDGE, source, recovered];
|
|
12612
12950
|
try {
|
|
@@ -12627,7 +12965,7 @@ async function refineAsset(options) {
|
|
|
12627
12965
|
);
|
|
12628
12966
|
}
|
|
12629
12967
|
const detection = parseDetection(firstJsonObject(stdout));
|
|
12630
|
-
const native = decodePng(await
|
|
12968
|
+
const native = decodePng(await readFile9(recovered));
|
|
12631
12969
|
const quantized = quantizeToPalette(native, palette);
|
|
12632
12970
|
const png = encodeRgbaPng(quantized.width, quantized.height, quantized.pixels);
|
|
12633
12971
|
const audit = auditRefinement(
|
|
@@ -12691,18 +13029,18 @@ async function refineFrameSet(options) {
|
|
|
12691
13029
|
if (roles.some((role) => !role.trim()) || new Set(roles).size !== roles.length) {
|
|
12692
13030
|
throw new Error("Frame-set roles must be non-empty and unique.");
|
|
12693
13031
|
}
|
|
12694
|
-
const output =
|
|
12695
|
-
const record =
|
|
13032
|
+
const output = path14.resolve(options.output);
|
|
13033
|
+
const record = path14.resolve(qualityRecordPath(output));
|
|
12696
13034
|
const palette = normalizeRefinementPalette(options.palette);
|
|
12697
13035
|
const finalOutputs = options.sources.map((source, index) => qualityFrameOutputPath(output, source.role, index));
|
|
12698
13036
|
if (new Set(finalOutputs).size !== finalOutputs.length) {
|
|
12699
13037
|
throw new Error("Frame-set roles resolve to duplicate output filenames.");
|
|
12700
13038
|
}
|
|
12701
|
-
const sourceSet = new Set(options.sources.map((source) =>
|
|
13039
|
+
const sourceSet = new Set(options.sources.map((source) => path14.resolve(source.path)));
|
|
12702
13040
|
if (finalOutputs.some((file) => sourceSet.has(file))) {
|
|
12703
13041
|
throw new Error("Frame-set refinement sources and outputs must be different files.");
|
|
12704
13042
|
}
|
|
12705
|
-
const temp = await mkdtemp(
|
|
13043
|
+
const temp = await mkdtemp(path14.join(tmpdir(), "pixelkiln-refine-frames-"));
|
|
12706
13044
|
try {
|
|
12707
13045
|
const frames = [];
|
|
12708
13046
|
const outputs = [];
|
|
@@ -12710,8 +13048,8 @@ async function refineFrameSet(options) {
|
|
|
12710
13048
|
const sourcePaths = [];
|
|
12711
13049
|
let firstOptions = null;
|
|
12712
13050
|
for (const [index, sourceEntry] of options.sources.entries()) {
|
|
12713
|
-
const source =
|
|
12714
|
-
const temporaryOutput =
|
|
13051
|
+
const source = path14.resolve(sourceEntry.path);
|
|
13052
|
+
const temporaryOutput = path14.join(temp, `${String(index).padStart(2, "0")}.png`);
|
|
12715
13053
|
const refined = await refineAsset({
|
|
12716
13054
|
source,
|
|
12717
13055
|
output: temporaryOutput,
|
|
@@ -12743,7 +13081,7 @@ async function refineFrameSet(options) {
|
|
|
12743
13081
|
});
|
|
12744
13082
|
outputs.push({
|
|
12745
13083
|
path: finalOutputs[index],
|
|
12746
|
-
data: await
|
|
13084
|
+
data: await readFile9(temporaryOutput)
|
|
12747
13085
|
});
|
|
12748
13086
|
}
|
|
12749
13087
|
const first = frames[0];
|
|
@@ -12786,7 +13124,7 @@ async function refineFrameSet(options) {
|
|
|
12786
13124
|
);
|
|
12787
13125
|
return {
|
|
12788
13126
|
sources: sourcePaths,
|
|
12789
|
-
outputs: outputs.map((item) =>
|
|
13127
|
+
outputs: outputs.map((item) => path14.resolve(item.path)),
|
|
12790
13128
|
record,
|
|
12791
13129
|
frames,
|
|
12792
13130
|
palette,
|
|
@@ -12797,12 +13135,12 @@ async function refineFrameSet(options) {
|
|
|
12797
13135
|
}
|
|
12798
13136
|
}
|
|
12799
13137
|
async function checkQualityRecord(recordPath) {
|
|
12800
|
-
const record =
|
|
13138
|
+
const record = path14.resolve(recordPath);
|
|
12801
13139
|
const manifest = await readArtifactBundleManifest(record);
|
|
12802
13140
|
const options = parseRecordOptions(manifest, record);
|
|
12803
13141
|
const verification = await verifyArtifactBundle(record);
|
|
12804
|
-
const sources = manifest.sources.map((source2) =>
|
|
12805
|
-
const outputs = manifest.outputs.map((output2) =>
|
|
13142
|
+
const sources = manifest.sources.map((source2) => path14.resolve(path14.dirname(record), source2.path));
|
|
13143
|
+
const outputs = manifest.outputs.map((output2) => path14.resolve(path14.dirname(record), output2.path));
|
|
12806
13144
|
const source = sources[0] ?? "";
|
|
12807
13145
|
const output = outputs[0] ?? "";
|
|
12808
13146
|
const expectedCount = options.frameSet?.count ?? 1;
|
|
@@ -12835,7 +13173,7 @@ async function checkQualityRecord(recordPath) {
|
|
|
12835
13173
|
async function approveQualityRecord(recordPath, approval) {
|
|
12836
13174
|
const reviewer = approval.reviewer.trim();
|
|
12837
13175
|
if (!reviewer) throw new Error("A human reviewer name is required.");
|
|
12838
|
-
const record =
|
|
13176
|
+
const record = path14.resolve(recordPath);
|
|
12839
13177
|
const manifest = await readArtifactBundleManifest(record);
|
|
12840
13178
|
const options = parseRecordOptions(manifest, record);
|
|
12841
13179
|
const verification = await verifyArtifactBundle(record);
|
|
@@ -12856,14 +13194,14 @@ async function approveQualityRecord(recordPath, approval) {
|
|
|
12856
13194
|
`A refinement record must contain exactly ${expectedCount} source(s) and output(s).`
|
|
12857
13195
|
);
|
|
12858
13196
|
}
|
|
12859
|
-
const root =
|
|
13197
|
+
const root = path14.dirname(record);
|
|
12860
13198
|
const outputs = await Promise.all(manifest.outputs.map(async (entry) => {
|
|
12861
|
-
const outputPath =
|
|
12862
|
-
return { path: outputPath, data: await
|
|
13199
|
+
const outputPath = path14.resolve(root, entry.path);
|
|
13200
|
+
return { path: outputPath, data: await readFile9(outputPath) };
|
|
12863
13201
|
}));
|
|
12864
13202
|
const sources = manifest.sources.map((source) => ({
|
|
12865
13203
|
...source,
|
|
12866
|
-
path:
|
|
13204
|
+
path: path14.resolve(root, source.path)
|
|
12867
13205
|
}));
|
|
12868
13206
|
const approved = {
|
|
12869
13207
|
...options,
|
|
@@ -12895,8 +13233,8 @@ async function qualitySource(spec, lock) {
|
|
|
12895
13233
|
if (spec.generator === "frames") {
|
|
12896
13234
|
return { items: null, reason: "frame-set quality requires ordered downloaded provider outputs" };
|
|
12897
13235
|
}
|
|
12898
|
-
const source =
|
|
12899
|
-
return
|
|
13236
|
+
const source = path15.resolve(spec.root, spec.source);
|
|
13237
|
+
return existsSync11(source) ? { items: [{ role: "source", path: source }] } : { items: null, reason: `declared source is missing: ${spec.source}` };
|
|
12900
13238
|
}
|
|
12901
13239
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
12902
13240
|
if (!entry) return { items: null, reason: "raw provider output is not in the lockfile" };
|
|
@@ -12925,7 +13263,7 @@ async function qualitySource(spec, lock) {
|
|
|
12925
13263
|
}
|
|
12926
13264
|
if (role) roles.add(role);
|
|
12927
13265
|
const source = currentEntryOutputPath(entry, spec, index);
|
|
12928
|
-
if (!
|
|
13266
|
+
if (!existsSync11(source)) return { items: null, reason: `raw provider output is missing: ${source}` };
|
|
12929
13267
|
if (await sha256File(source) !== output.sha256) {
|
|
12930
13268
|
return { items: null, reason: "raw provider output was modified after download" };
|
|
12931
13269
|
}
|
|
@@ -12935,18 +13273,18 @@ async function qualitySource(spec, lock) {
|
|
|
12935
13273
|
}
|
|
12936
13274
|
async function inspectQualityProfile(spec, lock) {
|
|
12937
13275
|
if (!spec.quality) return null;
|
|
12938
|
-
const
|
|
13276
|
+
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
12939
13277
|
const output = spec.quality.outFile;
|
|
12940
13278
|
const record = qualityRecordPath(output);
|
|
12941
13279
|
const source = await qualitySource(spec, lock);
|
|
12942
13280
|
if (!source.items) {
|
|
12943
|
-
return { key, state: "blocked", reason: source.reason, source: null, output, record };
|
|
13281
|
+
return { key: key2, state: "blocked", reason: source.reason, source: null, output, record };
|
|
12944
13282
|
}
|
|
12945
13283
|
const sourcePaths = source.items.map((item) => item.path);
|
|
12946
13284
|
const expectedOutputs = spec.generator === "frames" ? source.items.map((item, index) => qualityFrameOutputPath(output, item.role, index)) : [output];
|
|
12947
|
-
if (!
|
|
13285
|
+
if (!existsSync11(record)) {
|
|
12948
13286
|
return {
|
|
12949
|
-
key,
|
|
13287
|
+
key: key2,
|
|
12950
13288
|
state: "needs-refinement",
|
|
12951
13289
|
reason: "no refinement record",
|
|
12952
13290
|
source: sourcePaths[0],
|
|
@@ -12962,10 +13300,10 @@ async function inspectQualityProfile(spec, lock) {
|
|
|
12962
13300
|
const expectedRevision = spec.quality.fixerRevision ?? PIXEL_ART_FIXER_REVISION;
|
|
12963
13301
|
const expectedTransparency = spec.quality.minTransparency ?? null;
|
|
12964
13302
|
const expectedFrameSet = spec.generator === "frames" ? { fps: spec.quality.fps ?? 12, count: source.items.length, roles: source.items.map((item) => item.role) } : null;
|
|
12965
|
-
const contractChanged = JSON.stringify(check.sources.map((item) =>
|
|
13303
|
+
const contractChanged = JSON.stringify(check.sources.map((item) => path15.resolve(item))) !== JSON.stringify(sourcePaths.map((item) => path15.resolve(item))) || JSON.stringify(check.outputs.map((item) => path15.resolve(item))) !== JSON.stringify(expectedOutputs.map((item) => path15.resolve(item))) || JSON.stringify(check.options.palette.colors) !== JSON.stringify(expectedPalette) || check.options.nativeGrid.revision !== expectedRevision || check.options.audit.thresholds.minGridConfidence !== spec.quality.minGridConfidence || check.options.audit.thresholds.minTransparency !== expectedTransparency || (expectedFrameSet ? !check.options.frameSet || check.options.frameSet.fps !== expectedFrameSet.fps || check.options.frameSet.count !== expectedFrameSet.count || JSON.stringify(check.options.frameSet.roles) !== JSON.stringify(expectedFrameSet.roles) : check.options.frameSet !== void 0);
|
|
12966
13304
|
if (contractChanged) {
|
|
12967
13305
|
return {
|
|
12968
|
-
key,
|
|
13306
|
+
key: key2,
|
|
12969
13307
|
state: "needs-refinement",
|
|
12970
13308
|
reason: "quality profile changed",
|
|
12971
13309
|
source: sourcePaths[0],
|
|
@@ -12977,7 +13315,7 @@ async function inspectQualityProfile(spec, lock) {
|
|
|
12977
13315
|
}
|
|
12978
13316
|
if (!check.current || !check.auditSafe) {
|
|
12979
13317
|
return {
|
|
12980
|
-
key,
|
|
13318
|
+
key: key2,
|
|
12981
13319
|
state: "needs-refinement",
|
|
12982
13320
|
reason: check.reasons.filter((reason) => reason !== "human 1\xD7 review is pending").join("; ") || "refinement record is stale",
|
|
12983
13321
|
source: sourcePaths[0],
|
|
@@ -12989,7 +13327,7 @@ async function inspectQualityProfile(spec, lock) {
|
|
|
12989
13327
|
}
|
|
12990
13328
|
if (!check.approved) {
|
|
12991
13329
|
return {
|
|
12992
|
-
key,
|
|
13330
|
+
key: key2,
|
|
12993
13331
|
state: "needs-approval",
|
|
12994
13332
|
reason: "automated checks passed; human 1\xD7 review is pending",
|
|
12995
13333
|
source: sourcePaths[0],
|
|
@@ -13000,7 +13338,7 @@ async function inspectQualityProfile(spec, lock) {
|
|
|
13000
13338
|
};
|
|
13001
13339
|
}
|
|
13002
13340
|
return {
|
|
13003
|
-
key,
|
|
13341
|
+
key: key2,
|
|
13004
13342
|
state: "approved",
|
|
13005
13343
|
reason: "refined output and human approval are current",
|
|
13006
13344
|
source: sourcePaths[0],
|
|
@@ -13011,7 +13349,7 @@ async function inspectQualityProfile(spec, lock) {
|
|
|
13011
13349
|
};
|
|
13012
13350
|
} catch (error) {
|
|
13013
13351
|
return {
|
|
13014
|
-
key,
|
|
13352
|
+
key: key2,
|
|
13015
13353
|
state: "needs-refinement",
|
|
13016
13354
|
reason: `invalid refinement record: ${error instanceof Error ? error.message : String(error)}`,
|
|
13017
13355
|
source: sourcePaths[0],
|
|
@@ -13125,10 +13463,11 @@ async function requireApprovedQualitySources(specs, lock, assetIds, outputRoles)
|
|
|
13125
13463
|
}
|
|
13126
13464
|
|
|
13127
13465
|
// src/pipeline/revision.ts
|
|
13128
|
-
import { existsSync as
|
|
13129
|
-
import
|
|
13466
|
+
import { existsSync as existsSync12 } from "fs";
|
|
13467
|
+
import path16 from "path";
|
|
13130
13468
|
async function inspectRevisionReadiness(spec, lock) {
|
|
13131
13469
|
if (spec.mirror) return inspectMirror(spec, lock, /* @__PURE__ */ new Set());
|
|
13470
|
+
if (spec.derive) return inspectDerive(spec, lock, /* @__PURE__ */ new Set());
|
|
13132
13471
|
if (spec.character?.kind === "outfit") return inspectOutfit(spec, lock, /* @__PURE__ */ new Set());
|
|
13133
13472
|
if (spec.character?.parentSpec) {
|
|
13134
13473
|
const parent = await inspectCharacterParent(spec, lock, /* @__PURE__ */ new Set());
|
|
@@ -13147,7 +13486,7 @@ async function inspectStyleAnchor(spec, lock, seen) {
|
|
|
13147
13486
|
const label = `style anchor ${spec.styleId}/${anchor.assetId}`;
|
|
13148
13487
|
const dependency = await inspectParent(anchor.spec, lock, seen);
|
|
13149
13488
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13150
|
-
if (!anchor.sha256 || !
|
|
13489
|
+
if (!anchor.sha256 || !existsSync12(anchor.file)) return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13151
13490
|
if (await sha256File(anchor.file) !== anchor.sha256) {
|
|
13152
13491
|
return { ready: false, reason: `${label} changed after the manifest was resolved` };
|
|
13153
13492
|
}
|
|
@@ -13184,14 +13523,14 @@ async function inspectScene(spec) {
|
|
|
13184
13523
|
const files = [{ label: "scene image", file: scene.file, sha256: scene.sha256 }];
|
|
13185
13524
|
if (scene.placement.type === "mask") files.push({ label: "scene mask", file: scene.placement.file, sha256: scene.placement.sha256 });
|
|
13186
13525
|
for (const { label, file, sha256: sha2562 } of files) {
|
|
13187
|
-
if (!sha2562 || !
|
|
13526
|
+
if (!sha2562 || !existsSync12(file)) return { ready: false, reason: `${label} does not exist yet: ${file}` };
|
|
13188
13527
|
if (await sha256File(file) !== sha2562) return { ready: false, reason: `${label} changed after the manifest was resolved` };
|
|
13189
13528
|
}
|
|
13190
13529
|
return { ready: true, reason: "scene is current" };
|
|
13191
13530
|
}
|
|
13192
13531
|
async function inspectVfxSprite(spec) {
|
|
13193
13532
|
const sprite = spec.vfx.sprite;
|
|
13194
|
-
if (!sprite.sha256 || !
|
|
13533
|
+
if (!sprite.sha256 || !existsSync12(sprite.file)) return { ready: false, reason: `vfx sprite does not exist yet: ${sprite.file}` };
|
|
13195
13534
|
if (await sha256File(sprite.file) !== sprite.sha256) return { ready: false, reason: "vfx sprite changed after the manifest was resolved" };
|
|
13196
13535
|
return { ready: true, reason: "vfx sprite is current" };
|
|
13197
13536
|
}
|
|
@@ -13201,13 +13540,22 @@ async function inspectMirror(spec, lock, seen) {
|
|
|
13201
13540
|
const dependency = await inspectParent(source, lock, seen);
|
|
13202
13541
|
return dependency.ready ? { ready: true, reason: `${label} is current` } : { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13203
13542
|
}
|
|
13543
|
+
async function inspectDerive(spec, lock, seen) {
|
|
13544
|
+
const source = spec.derive.source;
|
|
13545
|
+
if (source.kind === "file") {
|
|
13546
|
+
return existsSync12(path16.resolve(spec.root, source.file)) ? { ready: true, reason: `source file ${source.file} exists` } : { ready: false, reason: `derive source file does not exist: ${source.file}` };
|
|
13547
|
+
}
|
|
13548
|
+
const label = `derive source ${spec.styleId}/${source.assetId}`;
|
|
13549
|
+
const dependency = await inspectParent(source.spec, lock, seen);
|
|
13550
|
+
return dependency.ready ? { ready: true, reason: `${label} is current` } : { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13551
|
+
}
|
|
13204
13552
|
async function inspectOutfit(spec, lock, seen) {
|
|
13205
13553
|
const character = spec.character;
|
|
13206
13554
|
const outfit = character.outfit;
|
|
13207
13555
|
const label = `outfit source ${spec.styleId}/${character.parentAssetId}`;
|
|
13208
13556
|
const dependency = await inspectParent(character.parentSpec, lock, seen);
|
|
13209
13557
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13210
|
-
if (!
|
|
13558
|
+
if (!existsSync12(outfit.reference.path)) {
|
|
13211
13559
|
return { ready: false, reason: `outfit reference is missing: ${outfit.reference.path}` };
|
|
13212
13560
|
}
|
|
13213
13561
|
if (await sha256File(outfit.reference.path) !== outfit.reference.sha256) {
|
|
@@ -13221,7 +13569,7 @@ async function inspectCharacterParent(spec, lock, seen) {
|
|
|
13221
13569
|
const label = `${character.kind} parent ${spec.styleId}/${character.parentAssetId}`;
|
|
13222
13570
|
const dependency = await inspectParent(parentSpec, lock, seen);
|
|
13223
13571
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13224
|
-
if (!character.parentSha256 || !character.parentFile || !
|
|
13572
|
+
if (!character.parentSha256 || !character.parentFile || !existsSync12(character.parentFile)) {
|
|
13225
13573
|
return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13226
13574
|
}
|
|
13227
13575
|
if (await sha256File(character.parentFile) !== character.parentSha256) {
|
|
@@ -13239,7 +13587,7 @@ async function inspectObjectProParent(spec, lock, seen) {
|
|
|
13239
13587
|
const label = `${object.kind} parent ${spec.styleId}/${object.parentAssetId}`;
|
|
13240
13588
|
const dependency = await inspectParent(parentSpec, lock, seen);
|
|
13241
13589
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13242
|
-
if (!object.parentSha256 || !object.parentFile || !
|
|
13590
|
+
if (!object.parentSha256 || !object.parentFile || !existsSync12(object.parentFile)) {
|
|
13243
13591
|
return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13244
13592
|
}
|
|
13245
13593
|
if (await sha256File(object.parentFile) !== object.parentSha256) {
|
|
@@ -13265,7 +13613,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13265
13613
|
const members = await inspectSourceMembers(spec, lock);
|
|
13266
13614
|
if (!members.ready) return members;
|
|
13267
13615
|
} else {
|
|
13268
|
-
if (!revision.sourceSha256 || !
|
|
13616
|
+
if (!revision.sourceSha256 || !existsSync12(revision.sourceFile)) {
|
|
13269
13617
|
return { ready: false, reason: `revision source is missing: ${revision.sourceFile}` };
|
|
13270
13618
|
}
|
|
13271
13619
|
if (await sha256File(revision.sourceFile) !== revision.sourceSha256) {
|
|
@@ -13273,7 +13621,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13273
13621
|
}
|
|
13274
13622
|
}
|
|
13275
13623
|
if (revision.maskFile) {
|
|
13276
|
-
if (!revision.maskSha256 || !
|
|
13624
|
+
if (!revision.maskSha256 || !existsSync12(revision.maskFile)) {
|
|
13277
13625
|
return { ready: false, reason: `revision mask is missing: ${revision.maskFile}` };
|
|
13278
13626
|
}
|
|
13279
13627
|
if (await sha256File(revision.maskFile) !== revision.maskSha256) {
|
|
@@ -13281,7 +13629,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13281
13629
|
}
|
|
13282
13630
|
}
|
|
13283
13631
|
if (revision.lastFrameFile) {
|
|
13284
|
-
if (!revision.lastFrameSha256 || !
|
|
13632
|
+
if (!revision.lastFrameSha256 || !existsSync12(revision.lastFrameFile)) {
|
|
13285
13633
|
return { ready: false, reason: `revision last frame is missing: ${revision.lastFrameFile}` };
|
|
13286
13634
|
}
|
|
13287
13635
|
if (await sha256File(revision.lastFrameFile) !== revision.lastFrameSha256) {
|
|
@@ -13294,7 +13642,7 @@ async function inspectSourceMembers(spec, lock) {
|
|
|
13294
13642
|
const revision = spec.revision;
|
|
13295
13643
|
const members = revision.sourceMembers;
|
|
13296
13644
|
for (const member of members) {
|
|
13297
|
-
if (!
|
|
13645
|
+
if (!existsSync12(member.file)) return { ready: false, reason: `revision source member is missing: ${member.file}` };
|
|
13298
13646
|
if (await sha256File(member.file) !== member.sha256) {
|
|
13299
13647
|
return { ready: false, reason: `revision source member changed after the manifest was resolved: ${member.file}` };
|
|
13300
13648
|
}
|
|
@@ -13303,8 +13651,8 @@ async function inspectSourceMembers(spec, lock) {
|
|
|
13303
13651
|
if (parent.source) return { ready: true, reason: "declared source set is present" };
|
|
13304
13652
|
const entry = lock.entries[lockKey(parent.styleId, parent.assetId)];
|
|
13305
13653
|
if (!entry) return { ready: false, reason: "revision source is not in the lockfile" };
|
|
13306
|
-
const recorded = entry.outputs.map((_, index) =>
|
|
13307
|
-
const found = members.map((member) =>
|
|
13654
|
+
const recorded = entry.outputs.map((_, index) => path16.resolve(currentEntryOutputPath(entry, parent, index))).sort();
|
|
13655
|
+
const found = members.map((member) => path16.resolve(member.file)).sort();
|
|
13308
13656
|
if (recorded.length !== found.length || recorded.some((file, index) => file !== found[index])) {
|
|
13309
13657
|
return {
|
|
13310
13658
|
ready: false,
|
|
@@ -13318,10 +13666,10 @@ async function requireRevisionReady(spec, lock) {
|
|
|
13318
13666
|
if (inspection && !inspection.ready) throw new Error(inspection.reason);
|
|
13319
13667
|
}
|
|
13320
13668
|
async function inspectParent(spec, lock, seen) {
|
|
13321
|
-
const
|
|
13322
|
-
if (seen.has(
|
|
13669
|
+
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
13670
|
+
if (seen.has(key2)) return { ready: false, reason: `revision dependency cycle at ${key2}` };
|
|
13323
13671
|
const nextSeen = new Set(seen);
|
|
13324
|
-
nextSeen.add(
|
|
13672
|
+
nextSeen.add(key2);
|
|
13325
13673
|
if (spec.mirror) {
|
|
13326
13674
|
const inputs = await inspectMirror(spec, lock, nextSeen);
|
|
13327
13675
|
if (!inputs.ready) return inputs;
|
|
@@ -13361,10 +13709,10 @@ async function inspectParent(spec, lock, seen) {
|
|
|
13361
13709
|
};
|
|
13362
13710
|
}
|
|
13363
13711
|
if (spec.source) {
|
|
13364
|
-
const source =
|
|
13365
|
-
return
|
|
13712
|
+
const source = path16.resolve(spec.root, spec.source);
|
|
13713
|
+
return existsSync12(source) ? { ready: true, reason: "declared source is present" } : { ready: false, reason: `declared source is missing: ${spec.source}` };
|
|
13366
13714
|
}
|
|
13367
|
-
const entry = lock.entries[
|
|
13715
|
+
const entry = lock.entries[key2];
|
|
13368
13716
|
if (!entry) return { ready: false, reason: "parent is not in the lockfile" };
|
|
13369
13717
|
if (entry.specHash !== spec.specHash) {
|
|
13370
13718
|
return { ready: false, reason: "parent generation spec is stale" };
|
|
@@ -13376,7 +13724,7 @@ async function inspectParent(spec, lock, seen) {
|
|
|
13376
13724
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
13377
13725
|
const output = entry.outputs[index];
|
|
13378
13726
|
const file = currentEntryOutputPath(entry, spec, index);
|
|
13379
|
-
if (!
|
|
13727
|
+
if (!existsSync12(file)) return { ready: false, reason: `parent output is missing: ${file}` };
|
|
13380
13728
|
if (await sha256File(file) !== output.sha256) {
|
|
13381
13729
|
return { ready: false, reason: `parent output was modified: ${file}` };
|
|
13382
13730
|
}
|
|
@@ -13395,6 +13743,7 @@ async function anyOutputModified(entry, spec) {
|
|
|
13395
13743
|
function dependencies(spec) {
|
|
13396
13744
|
return [
|
|
13397
13745
|
spec.mirror?.sourceSpec,
|
|
13746
|
+
spec.derive?.source.kind === "asset" ? spec.derive.source.spec : void 0,
|
|
13398
13747
|
spec.revision?.sourceSpec,
|
|
13399
13748
|
spec.character?.parentSpec,
|
|
13400
13749
|
spec.character?.motionLeader?.spec,
|
|
@@ -13438,15 +13787,15 @@ function resumeCommandForStatus(status) {
|
|
|
13438
13787
|
function resumeActions(specs, lock) {
|
|
13439
13788
|
const grouped = /* @__PURE__ */ new Map();
|
|
13440
13789
|
for (const spec of specs) {
|
|
13441
|
-
const
|
|
13442
|
-
const entry = lock.entries[
|
|
13790
|
+
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
13791
|
+
const entry = lock.entries[key2];
|
|
13443
13792
|
if (!entry || entry.specHash !== spec.specHash) continue;
|
|
13444
13793
|
if (entry.submissionComplete === false) continue;
|
|
13445
13794
|
const command = resumeCommandForStatus(entry.status) ?? (entry.status === "downloaded" && entry.outputs.length && !postprocessCurrent(entry, spec) ? "fetch" : null);
|
|
13446
13795
|
if (!command) continue;
|
|
13447
13796
|
if (command === "poll" && !entry.jobId) continue;
|
|
13448
13797
|
if (command === "pick" && !entry.reviewObjectId) continue;
|
|
13449
|
-
grouped.set(command, [...grouped.get(command) ?? [],
|
|
13798
|
+
grouped.set(command, [...grouped.get(command) ?? [], key2]);
|
|
13450
13799
|
}
|
|
13451
13800
|
return ["poll", "pick", "fetch"].flatMap((command) => {
|
|
13452
13801
|
const keys = grouped.get(command);
|
|
@@ -13456,22 +13805,26 @@ function resumeActions(specs, lock) {
|
|
|
13456
13805
|
async function buildPlan(specs, lock, opts = {}) {
|
|
13457
13806
|
const items = [];
|
|
13458
13807
|
for (const spec of specs) {
|
|
13459
|
-
const
|
|
13460
|
-
const entry = lock.entries[
|
|
13808
|
+
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
13809
|
+
const entry = lock.entries[key2];
|
|
13461
13810
|
let state;
|
|
13462
13811
|
let reason;
|
|
13463
13812
|
const changedConnection = entry ? changedTerrainConnection(spec, entry, lock) : null;
|
|
13464
13813
|
const changedMotion = entry ? changedMotionLeader(spec, entry, lock) : null;
|
|
13465
13814
|
const changedSettings = entry ? changedTerrainSettings(spec, entry) : null;
|
|
13815
|
+
const derivedStale = spec.derive && entry ? await deriveStale(spec, entry, lock) : null;
|
|
13466
13816
|
const revision = await inspectRevisionReadiness(spec, lock);
|
|
13467
13817
|
if (revision && !revision.ready) {
|
|
13468
13818
|
state = "blocked";
|
|
13469
13819
|
reason = revision.reason;
|
|
13820
|
+
} else if (spec.external) {
|
|
13821
|
+
;
|
|
13822
|
+
({ state, reason } = await inspectExternal(spec, entry));
|
|
13470
13823
|
} else if (opts.force) {
|
|
13471
13824
|
state = "missing";
|
|
13472
13825
|
reason = "--force";
|
|
13473
13826
|
} else if (!entry && spec.source && spec.generator !== "frames" && spec.generator !== "vfx") {
|
|
13474
|
-
if (
|
|
13827
|
+
if (existsSync13(path17.resolve(spec.root, spec.source))) {
|
|
13475
13828
|
state = "ok";
|
|
13476
13829
|
reason = `placed from ${spec.source}; not generated`;
|
|
13477
13830
|
} else {
|
|
@@ -13479,20 +13832,26 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13479
13832
|
reason = `declared source is missing: ${spec.source}`;
|
|
13480
13833
|
}
|
|
13481
13834
|
} else if (!entry) {
|
|
13482
|
-
if (
|
|
13835
|
+
if (existsSync13(spec.outFile)) {
|
|
13483
13836
|
state = "untracked";
|
|
13484
13837
|
reason = "file on disk, no provenance recorded";
|
|
13485
13838
|
} else {
|
|
13486
13839
|
state = "missing";
|
|
13487
|
-
reason = spec.mirror ? `not made yet; flipped from ${spec.mirror.sourceAssetId} (no generation cost)` : "not in lockfile";
|
|
13840
|
+
reason = spec.mirror ? `not made yet; flipped from ${spec.mirror.sourceAssetId} (no generation cost)` : spec.derive ? `not made yet; derived from ${spec.derive.source.kind === "asset" ? spec.derive.source.assetId : spec.derive.source.file} (${spec.derive.transform}, no generation cost)` : "not in lockfile";
|
|
13488
13841
|
}
|
|
13489
13842
|
} else if (entry.specHash !== spec.specHash) {
|
|
13490
13843
|
state = "stale";
|
|
13491
|
-
reason = "prompt, size, or style changed";
|
|
13844
|
+
reason = spec.derive ? "transform, its parameters, or the source file changed; derive it again (no generation cost)" : "prompt, size, or style changed";
|
|
13845
|
+
} else if (derivedStale) {
|
|
13846
|
+
state = "stale";
|
|
13847
|
+
reason = `${derivedStale}; derive it again (no generation cost)`;
|
|
13848
|
+
} else if (spec.derive && entry.status === "downloaded" && entry.outputs.some((_output, index) => !existsSync13(currentEntryOutputPath(entry, spec, index)))) {
|
|
13849
|
+
state = "stale";
|
|
13850
|
+
reason = "derived output missing on disk; derive it again (no generation cost)";
|
|
13492
13851
|
} else if (spec.mirror && !mirrorCurrent(entry, lock.entries[lockKey(spec.styleId, spec.mirror.sourceAssetId)])) {
|
|
13493
13852
|
state = "stale";
|
|
13494
13853
|
reason = `mirror source ${spec.mirror.sourceAssetId} changed; flip it again (no generation cost)`;
|
|
13495
|
-
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !
|
|
13854
|
+
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !existsSync13(currentEntryOutputPath(entry, spec, index)))) {
|
|
13496
13855
|
state = "stale";
|
|
13497
13856
|
reason = "mirror output missing on disk; flip it again (no generation cost)";
|
|
13498
13857
|
} else if (spec.character?.kind === "outfit" && entry.outfit?.sourceSha256 !== mirrorSourceHash(lock.entries[lockKey(spec.styleId, spec.character.parentAssetId)] ?? { outputs: [] })) {
|
|
@@ -13529,12 +13888,15 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13529
13888
|
} else if (entry.status !== "downloaded") {
|
|
13530
13889
|
state = "in-flight";
|
|
13531
13890
|
reason = `awaiting ${entry.status}`;
|
|
13532
|
-
} else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !
|
|
13891
|
+
} else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !existsSync13(currentEntryOutputPath(entry, spec, index)))) {
|
|
13533
13892
|
state = "orphaned";
|
|
13534
|
-
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !
|
|
13893
|
+
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !existsSync13(currentEntryOutputPath(entry, spec, index))).map((o) => o.role ?? "asset").join(", ")}`;
|
|
13535
13894
|
} else if (await anyOutputModified(entry, spec)) {
|
|
13536
13895
|
state = "orphaned";
|
|
13537
13896
|
reason = "output modified since download";
|
|
13897
|
+
} else if (spec.derive) {
|
|
13898
|
+
state = "ok";
|
|
13899
|
+
reason = "up to date";
|
|
13538
13900
|
} else if (spec.mirror && !postprocessCurrent(entry, spec)) {
|
|
13539
13901
|
state = "stale";
|
|
13540
13902
|
reason = "palette enforcement changed; flip the source again once it is refreshed (no generation cost)";
|
|
@@ -13546,7 +13908,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13546
13908
|
reason = "up to date";
|
|
13547
13909
|
}
|
|
13548
13910
|
const quality = await inspectQualityProfile(spec, lock);
|
|
13549
|
-
items.push({ spec, key, state, reason, ...quality ? { quality } : {} });
|
|
13911
|
+
items.push({ spec, key: key2, state, reason, ...quality ? { quality } : {} });
|
|
13550
13912
|
}
|
|
13551
13913
|
const isActionable = (i) => i.state === "missing" || i.state === "stale" || i.state === "failed";
|
|
13552
13914
|
const stateOf = new Map(items.map((i) => [i.key, i.state]));
|
|
@@ -13560,7 +13922,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13560
13922
|
item.reason = `parent ${parentKey} is being generated in this run; this follows in the next wave`;
|
|
13561
13923
|
break;
|
|
13562
13924
|
}
|
|
13563
|
-
if (item.spec.mirror && (parentState === "recoverable" || parentState === "in-flight")) {
|
|
13925
|
+
if ((item.spec.mirror || item.spec.derive) && (parentState === "recoverable" || parentState === "in-flight")) {
|
|
13564
13926
|
item.state = "blocked";
|
|
13565
13927
|
item.reason = `mirror source ${parentKey} is ${parentState}; this follows in the next wave`;
|
|
13566
13928
|
break;
|
|
@@ -13581,6 +13943,12 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13581
13943
|
const provider = item.spec.provider;
|
|
13582
13944
|
const costUnit = item.spec.costUnit ?? "generations";
|
|
13583
13945
|
const group = groupsByProvider.get(provider);
|
|
13946
|
+
if (group && item.spec.derive) {
|
|
13947
|
+
group.actionable.push(item);
|
|
13948
|
+
group.candidates += item.spec.candidates;
|
|
13949
|
+
continue;
|
|
13950
|
+
}
|
|
13951
|
+
if (group && group.cost === 0 && group.actionable.every((other) => other.spec.derive)) group.costUnit = costUnit;
|
|
13584
13952
|
if (group && group.costUnit !== costUnit) {
|
|
13585
13953
|
throw new Error(
|
|
13586
13954
|
`Provider "${provider}" returned mixed cost units (${group.costUnit}, ${costUnit})`
|
|
@@ -13630,13 +13998,13 @@ function summarize(plan) {
|
|
|
13630
13998
|
|
|
13631
13999
|
// src/project.ts
|
|
13632
14000
|
async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {}) {
|
|
13633
|
-
const absolute =
|
|
13634
|
-
const root =
|
|
14001
|
+
const absolute = path18.resolve(manifestPath);
|
|
14002
|
+
const root = path18.dirname(absolute);
|
|
13635
14003
|
if (opts.env !== false) {
|
|
13636
14004
|
loadEnvFiles(root);
|
|
13637
|
-
if (
|
|
14005
|
+
if (path18.resolve(process.cwd()) !== root) loadEnvFiles(process.cwd());
|
|
13638
14006
|
}
|
|
13639
|
-
const lockPath =
|
|
14007
|
+
const lockPath = path18.resolve(opts.lockPath ?? path18.join(root, "pixelkiln.lock.json"));
|
|
13640
14008
|
let loaded = await loadManifest(absolute, { lenient: opts.lenient });
|
|
13641
14009
|
const unresolved = [];
|
|
13642
14010
|
const specs = await resolveSpecs(loaded, {
|
|
@@ -13660,11 +14028,11 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
|
|
|
13660
14028
|
reload: () => openProject(absolute, { ...opts, env: false }),
|
|
13661
14029
|
providers: () => [...new Set(specs.map((spec) => spec.provider))].sort(),
|
|
13662
14030
|
provider: (id, mode2 = "online") => {
|
|
13663
|
-
const
|
|
13664
|
-
let adapter = adapters.get(
|
|
14031
|
+
const key2 = `${mode2}:${id}`;
|
|
14032
|
+
let adapter = adapters.get(key2);
|
|
13665
14033
|
if (!adapter) {
|
|
13666
14034
|
adapter = createProvider(id, mode2);
|
|
13667
|
-
adapters.set(
|
|
14035
|
+
adapters.set(key2, adapter);
|
|
13668
14036
|
}
|
|
13669
14037
|
return adapter;
|
|
13670
14038
|
}
|
|
@@ -13672,9 +14040,9 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
|
|
|
13672
14040
|
}
|
|
13673
14041
|
|
|
13674
14042
|
// src/recipes.ts
|
|
13675
|
-
import
|
|
13676
|
-
import { existsSync as
|
|
13677
|
-
import { readdir, readFile as
|
|
14043
|
+
import path19 from "path";
|
|
14044
|
+
import { existsSync as existsSync14 } from "fs";
|
|
14045
|
+
import { readdir, readFile as readFile10 } from "fs/promises";
|
|
13678
14046
|
import { fileURLToPath } from "url";
|
|
13679
14047
|
import { z as z4 } from "zod";
|
|
13680
14048
|
var SHA256_RE = /^[0-9a-f]{64}$/;
|
|
@@ -13683,7 +14051,7 @@ var VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
|
13683
14051
|
var RECIPE_FILE = "pixelkiln.recipe.json";
|
|
13684
14052
|
var RECIPE_DIR_TOKEN = "{{recipeDir}}";
|
|
13685
14053
|
var PortablePathSchema = z4.string().min(1).refine((value) => {
|
|
13686
|
-
if (value.includes("\\") ||
|
|
14054
|
+
if (value.includes("\\") || path19.posix.isAbsolute(value)) return false;
|
|
13687
14055
|
const parts = value.split("/");
|
|
13688
14056
|
return !parts.includes("") && !parts.includes(".") && !parts.includes("..");
|
|
13689
14057
|
}, "expected a portable relative path without '.', '..', or backslashes");
|
|
@@ -13843,9 +14211,9 @@ function canonical3(value) {
|
|
|
13843
14211
|
if (Array.isArray(value)) return value.map(canonical3);
|
|
13844
14212
|
if (typeof value === "object") {
|
|
13845
14213
|
const sorted = {};
|
|
13846
|
-
for (const
|
|
13847
|
-
const item = value[
|
|
13848
|
-
if (item !== void 0) sorted[
|
|
14214
|
+
for (const key2 of Object.keys(value).sort()) {
|
|
14215
|
+
const item = value[key2];
|
|
14216
|
+
if (item !== void 0) sorted[key2] = canonical3(item);
|
|
13849
14217
|
}
|
|
13850
14218
|
return sorted;
|
|
13851
14219
|
}
|
|
@@ -13859,10 +14227,10 @@ function message3(error) {
|
|
|
13859
14227
|
return error instanceof Error ? error.message : String(error);
|
|
13860
14228
|
}
|
|
13861
14229
|
async function readRecipeFile(recipePath, bundled) {
|
|
13862
|
-
const absolute =
|
|
14230
|
+
const absolute = path19.resolve(recipePath);
|
|
13863
14231
|
let raw;
|
|
13864
14232
|
try {
|
|
13865
|
-
raw = JSON.parse(await
|
|
14233
|
+
raw = JSON.parse(await readFile10(absolute, "utf8"));
|
|
13866
14234
|
} catch (error) {
|
|
13867
14235
|
throw new Error(`Could not read recipe ${absolute}: ${message3(error)}`, { cause: error });
|
|
13868
14236
|
}
|
|
@@ -13873,13 +14241,13 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
13873
14241
|
` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
|
|
13874
14242
|
);
|
|
13875
14243
|
}
|
|
13876
|
-
return { recipe: parsed.data, authored: raw, path: absolute, dir:
|
|
14244
|
+
return { recipe: parsed.data, authored: raw, path: absolute, dir: path19.dirname(absolute), bundled };
|
|
13877
14245
|
}
|
|
13878
14246
|
async function walkRecipeFiles(root) {
|
|
13879
|
-
if (!
|
|
14247
|
+
if (!existsSync14(root)) return [];
|
|
13880
14248
|
const out = [];
|
|
13881
14249
|
for (const entry of await readdir(root, { withFileTypes: true })) {
|
|
13882
|
-
const resolved =
|
|
14250
|
+
const resolved = path19.join(root, entry.name);
|
|
13883
14251
|
if (entry.isDirectory()) out.push(...await walkRecipeFiles(resolved));
|
|
13884
14252
|
else if (entry.isFile() && entry.name === RECIPE_FILE) out.push(resolved);
|
|
13885
14253
|
}
|
|
@@ -13890,7 +14258,7 @@ function bundledRecipeRoot() {
|
|
|
13890
14258
|
}
|
|
13891
14259
|
async function listBundledRecipes(root = bundledRecipeRoot()) {
|
|
13892
14260
|
const recipes = await Promise.all(
|
|
13893
|
-
(await walkRecipeFiles(
|
|
14261
|
+
(await walkRecipeFiles(path19.resolve(root))).map((file) => readRecipeFile(file, true))
|
|
13894
14262
|
);
|
|
13895
14263
|
return recipes.sort(
|
|
13896
14264
|
(a, b) => a.recipe.id.localeCompare(b.recipe.id) || compareVersions(b.recipe.version, a.recipe.version)
|
|
@@ -13913,9 +14281,9 @@ function parseSelector(selector) {
|
|
|
13913
14281
|
return { id: match[1], version: match[2] };
|
|
13914
14282
|
}
|
|
13915
14283
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
13916
|
-
const local =
|
|
13917
|
-
if (
|
|
13918
|
-
const recipePath =
|
|
14284
|
+
const local = path19.resolve(target);
|
|
14285
|
+
if (existsSync14(local)) {
|
|
14286
|
+
const recipePath = path19.basename(local) === RECIPE_FILE ? local : path19.join(local, RECIPE_FILE);
|
|
13919
14287
|
return readRecipeFile(recipePath, false);
|
|
13920
14288
|
}
|
|
13921
14289
|
if (target.startsWith(".") || target.startsWith("/") || target.includes("\\")) {
|
|
@@ -13929,8 +14297,8 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
13929
14297
|
return matches[0];
|
|
13930
14298
|
}
|
|
13931
14299
|
async function verifyFile(root, file) {
|
|
13932
|
-
const absolute =
|
|
13933
|
-
if (!
|
|
14300
|
+
const absolute = path19.resolve(root, ...file.path.split("/"));
|
|
14301
|
+
if (!existsSync14(absolute)) {
|
|
13934
14302
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
13935
14303
|
}
|
|
13936
14304
|
const actualSha256 = await sha256File(absolute);
|
|
@@ -13945,7 +14313,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
13945
14313
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
13946
14314
|
const actualIntegrity = recipeDigest(loaded.authored);
|
|
13947
14315
|
const files = await Promise.all(loaded.recipe.files.map((file) => verifyFile(loaded.dir, file)));
|
|
13948
|
-
const modelRoot = options.modelRoot ?
|
|
14316
|
+
const modelRoot = options.modelRoot ? path19.resolve(options.modelRoot) : null;
|
|
13949
14317
|
const models = modelRoot ? await Promise.all(loaded.recipe.models.map(async (model) => ({
|
|
13950
14318
|
...await verifyFile(modelRoot, model),
|
|
13951
14319
|
source: model.source,
|
|
@@ -13979,37 +14347,37 @@ async function verifyRecipe(target, options = {}) {
|
|
|
13979
14347
|
};
|
|
13980
14348
|
}
|
|
13981
14349
|
function renderStyle(style, destination, cwd) {
|
|
13982
|
-
const portableDir =
|
|
14350
|
+
const portableDir = path19.relative(cwd, destination).split(path19.sep).join("/") || ".";
|
|
13983
14351
|
const replace = (value) => {
|
|
13984
14352
|
if (typeof value === "string") return value.replaceAll(RECIPE_DIR_TOKEN, portableDir);
|
|
13985
14353
|
if (Array.isArray(value)) return value.map(replace);
|
|
13986
14354
|
if (value && typeof value === "object") {
|
|
13987
|
-
return Object.fromEntries(Object.entries(value).map(([
|
|
14355
|
+
return Object.fromEntries(Object.entries(value).map(([key2, item]) => [key2, replace(item)]));
|
|
13988
14356
|
}
|
|
13989
14357
|
return value;
|
|
13990
14358
|
};
|
|
13991
14359
|
return replace(style);
|
|
13992
14360
|
}
|
|
13993
14361
|
async function installRecipe(target, options = {}) {
|
|
13994
|
-
const cwd =
|
|
14362
|
+
const cwd = path19.resolve(options.cwd ?? process.cwd());
|
|
13995
14363
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
13996
14364
|
const verification = await verifyRecipe(loaded.path);
|
|
13997
14365
|
if (!verification.ok) {
|
|
13998
14366
|
throw new Error(`Recipe ${loaded.recipe.id}@${loaded.recipe.version} failed integrity verification.`);
|
|
13999
14367
|
}
|
|
14000
|
-
const destination = options.out ?
|
|
14368
|
+
const destination = options.out ? path19.resolve(cwd, options.out) : path19.join(cwd, "pixelkiln-recipes", ...loaded.recipe.id.split("/"), loaded.recipe.version);
|
|
14001
14369
|
const sources = [
|
|
14002
14370
|
{ path: RECIPE_FILE, source: loaded.path },
|
|
14003
|
-
...loaded.recipe.files.map((file) => ({ path: file.path, source:
|
|
14371
|
+
...loaded.recipe.files.map((file) => ({ path: file.path, source: path19.join(loaded.dir, ...file.path.split("/")) }))
|
|
14004
14372
|
];
|
|
14005
14373
|
const files = await Promise.all(sources.map(async (file) => ({
|
|
14006
|
-
path:
|
|
14007
|
-
data: await
|
|
14374
|
+
path: path19.join(destination, ...file.path.split("/")),
|
|
14375
|
+
data: await readFile10(file.source)
|
|
14008
14376
|
})));
|
|
14009
14377
|
if (!options.force) {
|
|
14010
14378
|
for (const file of files) {
|
|
14011
|
-
if (!
|
|
14012
|
-
const current = await
|
|
14379
|
+
if (!existsSync14(file.path)) continue;
|
|
14380
|
+
const current = await readFile10(file.path);
|
|
14013
14381
|
if (!current.equals(file.data)) {
|
|
14014
14382
|
throw new OverwriteRefusedError(
|
|
14015
14383
|
`Recipe destination has local changes: ${file.path}. Choose another --out or pass --force to replace declared recipe files.`,
|
|
@@ -14033,9 +14401,9 @@ async function installRecipe(target, options = {}) {
|
|
|
14033
14401
|
}
|
|
14034
14402
|
|
|
14035
14403
|
// src/pipeline/audit.ts
|
|
14036
|
-
import { readFile as
|
|
14037
|
-
import { existsSync as
|
|
14038
|
-
import
|
|
14404
|
+
import { readFile as readFile11 } from "fs/promises";
|
|
14405
|
+
import { existsSync as existsSync15 } from "fs";
|
|
14406
|
+
import path20 from "path";
|
|
14039
14407
|
function paletteDistance(asset, reference) {
|
|
14040
14408
|
if (!asset.length || !reference.length) return 0;
|
|
14041
14409
|
let total = 0;
|
|
@@ -14052,10 +14420,10 @@ function mergePalettes(palettes, topN = 24) {
|
|
|
14052
14420
|
const totals = /* @__PURE__ */ new Map();
|
|
14053
14421
|
for (const palette of palettes) {
|
|
14054
14422
|
for (const color of palette) {
|
|
14055
|
-
const
|
|
14056
|
-
const existing = totals.get(
|
|
14423
|
+
const key2 = `${color.r},${color.g},${color.b}`;
|
|
14424
|
+
const existing = totals.get(key2);
|
|
14057
14425
|
if (existing) existing.weight += color.weight;
|
|
14058
|
-
else totals.set(
|
|
14426
|
+
else totals.set(key2, { ...color });
|
|
14059
14427
|
}
|
|
14060
14428
|
}
|
|
14061
14429
|
const merged = [...totals.values()].sort((a, b) => b.weight - a.weight).slice(0, topN);
|
|
@@ -14071,12 +14439,12 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
14071
14439
|
const unreadable = [];
|
|
14072
14440
|
for (const spec of mine) {
|
|
14073
14441
|
for (const output of resolveSpecOutputs(spec, lock, loaded.root)) {
|
|
14074
|
-
if (!
|
|
14442
|
+
if (!existsSync15(output.absolutePath)) {
|
|
14075
14443
|
missing.push(output.id);
|
|
14076
14444
|
continue;
|
|
14077
14445
|
}
|
|
14078
14446
|
try {
|
|
14079
|
-
const png = decodePng(await
|
|
14447
|
+
const png = decodePng(await readFile11(output.absolutePath));
|
|
14080
14448
|
const palette = extractPalette(png, 12);
|
|
14081
14449
|
assets.push({
|
|
14082
14450
|
assetId: spec.assetId,
|
|
@@ -14100,10 +14468,10 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
14100
14468
|
let referenceFromStyleImages = false;
|
|
14101
14469
|
const refPalettes = [];
|
|
14102
14470
|
for (const img of style.styleImages) {
|
|
14103
|
-
const abs =
|
|
14104
|
-
if (!
|
|
14471
|
+
const abs = path20.resolve(loaded.root, img.path);
|
|
14472
|
+
if (!existsSync15(abs)) continue;
|
|
14105
14473
|
try {
|
|
14106
|
-
refPalettes.push(extractPalette(decodePng(await
|
|
14474
|
+
refPalettes.push(extractPalette(decodePng(await readFile11(abs)), 12));
|
|
14107
14475
|
} catch {
|
|
14108
14476
|
}
|
|
14109
14477
|
}
|
|
@@ -14179,15 +14547,15 @@ function hex(c) {
|
|
|
14179
14547
|
}
|
|
14180
14548
|
|
|
14181
14549
|
// src/pipeline/quality-regression.ts
|
|
14182
|
-
import
|
|
14183
|
-
import { existsSync as
|
|
14184
|
-
import { readFile as
|
|
14550
|
+
import path21 from "path";
|
|
14551
|
+
import { existsSync as existsSync16 } from "fs";
|
|
14552
|
+
import { readFile as readFile12 } from "fs/promises";
|
|
14185
14553
|
import { z as z5 } from "zod";
|
|
14186
14554
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
14187
14555
|
var HEX_RE = /^#[0-9a-f]{6}$/;
|
|
14188
14556
|
var MAX_REDMEAN_DISTANCE = 765;
|
|
14189
14557
|
var QualityPathSchema = z5.string().min(1).refine(
|
|
14190
|
-
(value) => !
|
|
14558
|
+
(value) => !path21.posix.isAbsolute(value) && !value.includes("\\"),
|
|
14191
14559
|
"expected a portable relative path"
|
|
14192
14560
|
);
|
|
14193
14561
|
var DEFAULT_QUALITY_TOLERANCES = {
|
|
@@ -14289,8 +14657,8 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
14289
14657
|
const index = offset / 4;
|
|
14290
14658
|
const x = index % png.width;
|
|
14291
14659
|
const y = Math.floor(index / png.width);
|
|
14292
|
-
const
|
|
14293
|
-
const hasSameNeighbor = x > 0 && pixelKey(png.pixels, offset - 4) ===
|
|
14660
|
+
const key2 = pixelKey(png.pixels, offset);
|
|
14661
|
+
const hasSameNeighbor = x > 0 && pixelKey(png.pixels, offset - 4) === key2 || x + 1 < png.width && pixelKey(png.pixels, offset + 4) === key2 || y > 0 && pixelKey(png.pixels, offset - png.width * 4) === key2 || y + 1 < png.height && pixelKey(png.pixels, offset + png.width * 4) === key2;
|
|
14294
14662
|
if (!hasSameNeighbor) {
|
|
14295
14663
|
isolated++;
|
|
14296
14664
|
}
|
|
@@ -14334,10 +14702,10 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
14334
14702
|
};
|
|
14335
14703
|
}
|
|
14336
14704
|
async function measureImageQuality(file) {
|
|
14337
|
-
const absolute =
|
|
14705
|
+
const absolute = path21.resolve(file);
|
|
14338
14706
|
let bytes;
|
|
14339
14707
|
try {
|
|
14340
|
-
bytes = await
|
|
14708
|
+
bytes = await readFile12(absolute);
|
|
14341
14709
|
} catch (error) {
|
|
14342
14710
|
throw new Error(`Cannot read quality image ${absolute}: ${message4(error)}`, { cause: error });
|
|
14343
14711
|
}
|
|
@@ -14356,11 +14724,11 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
14356
14724
|
}
|
|
14357
14725
|
const ids = parsed.data.map((entry) => entry.id);
|
|
14358
14726
|
if (new Set(ids).size !== ids.length) throw new Error("--inputs contains a duplicate quality case id.");
|
|
14359
|
-
const root =
|
|
14727
|
+
const root = path21.dirname(path21.resolve(inputsFilePath));
|
|
14360
14728
|
return parsed.data.map((entry) => ({
|
|
14361
14729
|
id: entry.id,
|
|
14362
|
-
file:
|
|
14363
|
-
...entry.record ? { record:
|
|
14730
|
+
file: path21.resolve(root, entry.path),
|
|
14731
|
+
...entry.record ? { record: path21.resolve(root, entry.record) } : {},
|
|
14364
14732
|
tolerances: QualityToleranceSchema.parse({
|
|
14365
14733
|
...DEFAULT_QUALITY_TOLERANCES,
|
|
14366
14734
|
...entry.tolerances
|
|
@@ -14368,7 +14736,7 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
14368
14736
|
}));
|
|
14369
14737
|
}
|
|
14370
14738
|
function portableRelative2(from, to) {
|
|
14371
|
-
return
|
|
14739
|
+
return path21.relative(from, path21.resolve(to)).split(path21.sep).join("/") || ".";
|
|
14372
14740
|
}
|
|
14373
14741
|
async function verifyRecordForImage(recordPath, imagePath) {
|
|
14374
14742
|
const verification = await verifyArtifactBundle(recordPath);
|
|
@@ -14383,20 +14751,20 @@ async function verifyRecordForImage(recordPath, imagePath) {
|
|
|
14383
14751
|
if (record.kind !== "refine" || options === null || typeof options !== "object" || options.schema !== "pixelkiln-quality") {
|
|
14384
14752
|
throw new Error(`Quality record ${recordPath} is not a PixelKiln refinement record.`);
|
|
14385
14753
|
}
|
|
14386
|
-
const outputs = record.outputs.map((output) =>
|
|
14387
|
-
if (!outputs.includes(
|
|
14754
|
+
const outputs = record.outputs.map((output) => path21.resolve(path21.dirname(recordPath), output.path));
|
|
14755
|
+
if (!outputs.includes(path21.resolve(imagePath))) {
|
|
14388
14756
|
throw new Error(`Quality record ${recordPath} does not own ${imagePath}.`);
|
|
14389
14757
|
}
|
|
14390
14758
|
}
|
|
14391
14759
|
async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
14392
14760
|
if (!inputs.length) throw new Error("Cannot snapshot an empty quality baseline.");
|
|
14393
|
-
const absolute =
|
|
14761
|
+
const absolute = path21.resolve(baselinePath);
|
|
14394
14762
|
for (const input of inputs) {
|
|
14395
|
-
if (
|
|
14763
|
+
if (path21.resolve(input.file) === absolute || input.record && path21.resolve(input.record) === absolute) {
|
|
14396
14764
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
14397
14765
|
}
|
|
14398
14766
|
}
|
|
14399
|
-
const root =
|
|
14767
|
+
const root = path21.dirname(absolute);
|
|
14400
14768
|
const cases = [];
|
|
14401
14769
|
for (const input of [...inputs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
14402
14770
|
const expected = await measureImageQuality(input.file);
|
|
@@ -14423,8 +14791,8 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14423
14791
|
cases
|
|
14424
14792
|
});
|
|
14425
14793
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
14426
|
-
if (
|
|
14427
|
-
const current = await
|
|
14794
|
+
if (existsSync16(absolute) && !options.force) {
|
|
14795
|
+
const current = await readFile12(absolute);
|
|
14428
14796
|
if (!current.equals(data)) {
|
|
14429
14797
|
throw new OverwriteRefusedError(
|
|
14430
14798
|
`Quality baseline already exists with different content: ${absolute}. Pass --force to replace it.`,
|
|
@@ -14436,13 +14804,13 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14436
14804
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
14437
14805
|
}
|
|
14438
14806
|
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
14439
|
-
const absolute =
|
|
14440
|
-
if (!
|
|
14807
|
+
const absolute = path21.resolve(baselinePath);
|
|
14808
|
+
if (!existsSync16(absolute)) {
|
|
14441
14809
|
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
14442
14810
|
}
|
|
14443
14811
|
let raw;
|
|
14444
14812
|
try {
|
|
14445
|
-
raw = JSON.parse(await
|
|
14813
|
+
raw = JSON.parse(await readFile12(absolute, "utf8"));
|
|
14446
14814
|
} catch (error) {
|
|
14447
14815
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
14448
14816
|
}
|
|
@@ -14452,12 +14820,12 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
14452
14820
|
if (unknown.length) {
|
|
14453
14821
|
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
14454
14822
|
}
|
|
14455
|
-
const root =
|
|
14823
|
+
const root = path21.dirname(absolute);
|
|
14456
14824
|
const cases = [...raw.cases];
|
|
14457
14825
|
const report = [];
|
|
14458
14826
|
for (const id of only) {
|
|
14459
14827
|
const input = byId.get(id);
|
|
14460
|
-
if (
|
|
14828
|
+
if (path21.resolve(input.file) === absolute || input.record && path21.resolve(input.record) === absolute) {
|
|
14461
14829
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
14462
14830
|
}
|
|
14463
14831
|
const expected = await measureImageQuality(input.file);
|
|
@@ -14487,16 +14855,16 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
14487
14855
|
}
|
|
14488
14856
|
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
14489
14857
|
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
14490
|
-
const current = await
|
|
14858
|
+
const current = await readFile12(absolute);
|
|
14491
14859
|
const changed = !current.equals(data);
|
|
14492
14860
|
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
14493
14861
|
return { baseline, path: absolute, changed, cases: report };
|
|
14494
14862
|
}
|
|
14495
14863
|
async function readQualityBaseline(baselinePath) {
|
|
14496
|
-
const absolute =
|
|
14864
|
+
const absolute = path21.resolve(baselinePath);
|
|
14497
14865
|
let raw;
|
|
14498
14866
|
try {
|
|
14499
|
-
raw = JSON.parse(await
|
|
14867
|
+
raw = JSON.parse(await readFile12(absolute, "utf8"));
|
|
14500
14868
|
} catch (error) {
|
|
14501
14869
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
14502
14870
|
}
|
|
@@ -14518,7 +14886,7 @@ async function readQualityBaseline(baselinePath) {
|
|
|
14518
14886
|
throw new Error(
|
|
14519
14887
|
`Invalid quality baseline ${absolute}:
|
|
14520
14888
|
` + 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 ${
|
|
14889
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path21.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
14522
14890
|
);
|
|
14523
14891
|
}
|
|
14524
14892
|
return parsed.data;
|
|
@@ -14580,12 +14948,12 @@ function regressionViolations(expected, actual, tolerances) {
|
|
|
14580
14948
|
return { violations, warnings };
|
|
14581
14949
|
}
|
|
14582
14950
|
async function checkQualityBaseline(baselinePath) {
|
|
14583
|
-
const absolute =
|
|
14951
|
+
const absolute = path21.resolve(baselinePath);
|
|
14584
14952
|
const baseline = await readQualityBaseline(absolute);
|
|
14585
|
-
const root =
|
|
14953
|
+
const root = path21.dirname(absolute);
|
|
14586
14954
|
const cases = [];
|
|
14587
14955
|
for (const entry of baseline.cases) {
|
|
14588
|
-
const file =
|
|
14956
|
+
const file = path21.resolve(root, entry.file);
|
|
14589
14957
|
let actual = null;
|
|
14590
14958
|
const violations = [];
|
|
14591
14959
|
const warnings = [];
|
|
@@ -14598,7 +14966,7 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
14598
14966
|
violations.push(message4(error));
|
|
14599
14967
|
}
|
|
14600
14968
|
if (entry.record) {
|
|
14601
|
-
const recordPath =
|
|
14969
|
+
const recordPath = path21.resolve(root, entry.record.path);
|
|
14602
14970
|
try {
|
|
14603
14971
|
const recordHash = await sha256File(recordPath);
|
|
14604
14972
|
if (recordHash !== entry.record.sha256) violations.push("quality record hash changed");
|
|
@@ -14634,13 +15002,13 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
14634
15002
|
}
|
|
14635
15003
|
|
|
14636
15004
|
// src/pipeline/cache-health.ts
|
|
14637
|
-
import { existsSync as
|
|
14638
|
-
import { readFile as
|
|
14639
|
-
import
|
|
15005
|
+
import { existsSync as existsSync20 } from "fs";
|
|
15006
|
+
import { readFile as readFile15, readdir as readdir2, rm as rm6 } from "fs/promises";
|
|
15007
|
+
import path24 from "path";
|
|
14640
15008
|
|
|
14641
15009
|
// src/cache.ts
|
|
14642
|
-
import { mkdir as
|
|
14643
|
-
import { existsSync as
|
|
15010
|
+
import { mkdir as mkdir7, readFile as readFile13, rename as rename5, rm as rm4, writeFile as writeFile7 } from "fs/promises";
|
|
15011
|
+
import { existsSync as existsSync17 } from "fs";
|
|
14644
15012
|
import pathModule from "path";
|
|
14645
15013
|
import { z as z6 } from "zod";
|
|
14646
15014
|
var HashCacheSchema = z6.object({
|
|
@@ -14655,10 +15023,10 @@ function isSha256Hash(value) {
|
|
|
14655
15023
|
function parseCache(value) {
|
|
14656
15024
|
return HashCacheSchema.parse(value);
|
|
14657
15025
|
}
|
|
14658
|
-
async function loadCache(
|
|
14659
|
-
if (!
|
|
15026
|
+
async function loadCache(path42) {
|
|
15027
|
+
if (!existsSync17(path42)) return { version: 1, hashes: {} };
|
|
14660
15028
|
try {
|
|
14661
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await
|
|
15029
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(path42, "utf8")));
|
|
14662
15030
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
14663
15031
|
return {
|
|
14664
15032
|
version: 1,
|
|
@@ -14670,30 +15038,30 @@ async function loadCache(path40) {
|
|
|
14670
15038
|
return { version: 1, hashes: {} };
|
|
14671
15039
|
}
|
|
14672
15040
|
}
|
|
14673
|
-
async function saveCache(
|
|
15041
|
+
async function saveCache(path42, cache) {
|
|
14674
15042
|
const sorted = {};
|
|
14675
|
-
for (const
|
|
14676
|
-
const hash = cache.hashes[
|
|
14677
|
-
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${
|
|
14678
|
-
sorted[
|
|
15043
|
+
for (const key2 of Object.keys(cache.hashes).sort()) {
|
|
15044
|
+
const hash = cache.hashes[key2];
|
|
15045
|
+
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key2}`);
|
|
15046
|
+
sorted[key2] = hash;
|
|
14679
15047
|
}
|
|
14680
|
-
await
|
|
14681
|
-
const tmp = `${
|
|
15048
|
+
await mkdir7(pathModule.dirname(pathModule.resolve(path42)), { recursive: true });
|
|
15049
|
+
const tmp = `${path42}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
14682
15050
|
try {
|
|
14683
|
-
await
|
|
14684
|
-
await
|
|
15051
|
+
await writeFile7(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
15052
|
+
await rename5(tmp, path42);
|
|
14685
15053
|
} finally {
|
|
14686
15054
|
await rm4(tmp, { force: true });
|
|
14687
15055
|
}
|
|
14688
15056
|
}
|
|
14689
15057
|
function pruneCache(cache, liveIds, namespace = "") {
|
|
14690
15058
|
let removed = 0;
|
|
14691
|
-
for (const
|
|
14692
|
-
const owned = namespace ?
|
|
15059
|
+
for (const key2 of Object.keys(cache.hashes)) {
|
|
15060
|
+
const owned = namespace ? key2.startsWith(namespace) : !key2.includes(":");
|
|
14693
15061
|
if (!owned) continue;
|
|
14694
|
-
const id = namespace ?
|
|
15062
|
+
const id = namespace ? key2.slice(namespace.length) : key2;
|
|
14695
15063
|
if (!liveIds.has(id)) {
|
|
14696
|
-
delete cache.hashes[
|
|
15064
|
+
delete cache.hashes[key2];
|
|
14697
15065
|
removed++;
|
|
14698
15066
|
}
|
|
14699
15067
|
}
|
|
@@ -14705,38 +15073,39 @@ function cachePathFor(lockPath) {
|
|
|
14705
15073
|
}
|
|
14706
15074
|
|
|
14707
15075
|
// src/pipeline/history.ts
|
|
14708
|
-
import { existsSync as
|
|
14709
|
-
import
|
|
15076
|
+
import { existsSync as existsSync19 } from "fs";
|
|
15077
|
+
import path23 from "path";
|
|
14710
15078
|
|
|
14711
15079
|
// src/pipeline/fetch.ts
|
|
14712
|
-
import { existsSync as
|
|
14713
|
-
import { mkdir as
|
|
14714
|
-
import
|
|
15080
|
+
import { existsSync as existsSync18, readFileSync as readFileSync5 } from "fs";
|
|
15081
|
+
import { mkdir as mkdir8, readFile as readFile14, rename as rename6, rm as rm5, writeFile as writeFile8 } from "fs/promises";
|
|
15082
|
+
import path22 from "path";
|
|
14715
15083
|
async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
14716
15084
|
const log = opts.onProgress ?? (() => {
|
|
14717
15085
|
});
|
|
14718
15086
|
const result = { downloaded: 0, skipped: 0, failed: 0, ...opts.refresh ? { unchanged: 0 } : {} };
|
|
14719
15087
|
const specByKey = new Map(specs.map((s) => [lockKey(s.styleId, s.assetId), s]));
|
|
14720
15088
|
normalizeLockOutputPaths(lock, specs);
|
|
14721
|
-
const cacheDir = opts.cacheDir === false ? null :
|
|
14722
|
-
const pending = Object.entries(lock.entries).filter(([
|
|
14723
|
-
if (e.provider !== provider.id || !specByKey.has(
|
|
14724
|
-
if (specByKey.get(
|
|
15089
|
+
const cacheDir = opts.cacheDir === false ? null : path22.resolve(opts.cacheDir ?? path22.join(path22.dirname(lockPath), ".pixelkiln", "cache"));
|
|
15090
|
+
const pending = Object.entries(lock.entries).filter(([key2, e]) => {
|
|
15091
|
+
if (e.provider !== provider.id || !specByKey.has(key2)) return false;
|
|
15092
|
+
if (specByKey.get(key2)?.mirror) return false;
|
|
15093
|
+
if (specByKey.get(key2)?.derive || specByKey.get(key2)?.external) return false;
|
|
14725
15094
|
if (e.status === "selected" || e.status === "download-failed") return true;
|
|
14726
15095
|
if (e.status !== "downloaded") return false;
|
|
14727
15096
|
if (opts.refresh) return e.outputs.length > 0 && Boolean(e.sourceUrls?.length || e.sourceUrl);
|
|
14728
|
-
const spec = specByKey.get(
|
|
15097
|
+
const spec = specByKey.get(key2);
|
|
14729
15098
|
if (spec && e.specHash === spec.specHash && e.outputs.length && !postprocessCurrent(e, spec)) {
|
|
14730
15099
|
return Boolean(opts.force) || e.outputs.every((output) => {
|
|
14731
15100
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14732
|
-
return
|
|
15101
|
+
return existsSync18(file) && sha256(readFileSync5(file)) === output.sha256;
|
|
14733
15102
|
});
|
|
14734
15103
|
}
|
|
14735
15104
|
if (!opts.repair) return false;
|
|
14736
15105
|
if (e.outputs.length === 0 || !spec) return true;
|
|
14737
15106
|
return e.outputs.some((output) => {
|
|
14738
15107
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14739
|
-
if (!
|
|
15108
|
+
if (!existsSync18(file)) return true;
|
|
14740
15109
|
const current = sha256(readFileSync5(file));
|
|
14741
15110
|
if (current === output.sha256) return false;
|
|
14742
15111
|
return Boolean(opts.force) || (e.supersededOutputs ?? []).some((old) => old.sha256 === current);
|
|
@@ -14748,15 +15117,15 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14748
15117
|
for (; ; ) {
|
|
14749
15118
|
const next = pending[cursor++];
|
|
14750
15119
|
if (!next) return;
|
|
14751
|
-
const [
|
|
14752
|
-
const spec = specByKey.get(
|
|
15120
|
+
const [key2, entry] = next;
|
|
15121
|
+
const spec = specByKey.get(key2);
|
|
14753
15122
|
if (!spec) {
|
|
14754
|
-
log(` skip ${
|
|
15123
|
+
log(` skip ${key2} (not in current manifest)`);
|
|
14755
15124
|
result.skipped++;
|
|
14756
15125
|
continue;
|
|
14757
15126
|
}
|
|
14758
15127
|
if (entry.specHash !== spec.specHash) {
|
|
14759
|
-
log(` skip ${
|
|
15128
|
+
log(` skip ${key2} (source belongs to a stale spec)`);
|
|
14760
15129
|
result.skipped++;
|
|
14761
15130
|
continue;
|
|
14762
15131
|
}
|
|
@@ -14773,16 +15142,16 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14773
15142
|
});
|
|
14774
15143
|
} catch (err) {
|
|
14775
15144
|
const message6 = err instanceof Error ? err.message : String(err);
|
|
14776
|
-
upsert(lock,
|
|
15145
|
+
upsert(lock, key2, { status: "download-failed", error: `download failed: ${message6}` });
|
|
14777
15146
|
result.failed++;
|
|
14778
|
-
log(` FAILED ${
|
|
15147
|
+
log(` FAILED ${key2}: ${message6}`);
|
|
14779
15148
|
await saveLock(lockPath, lock);
|
|
14780
15149
|
continue;
|
|
14781
15150
|
}
|
|
14782
15151
|
if (current === null) {
|
|
14783
|
-
upsert(lock,
|
|
15152
|
+
upsert(lock, key2, { status: "download-failed", error: `download failed: ${entry.objectId} no longer exists upstream` });
|
|
14784
15153
|
result.failed++;
|
|
14785
|
-
log(` FAILED ${
|
|
15154
|
+
log(` FAILED ${key2}: ${entry.objectId} no longer exists upstream`);
|
|
14786
15155
|
await saveLock(lockPath, lock);
|
|
14787
15156
|
continue;
|
|
14788
15157
|
}
|
|
@@ -14795,7 +15164,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14795
15164
|
}
|
|
14796
15165
|
}
|
|
14797
15166
|
if (!sources.length) {
|
|
14798
|
-
upsert(lock,
|
|
15167
|
+
upsert(lock, key2, {
|
|
14799
15168
|
status: "download-failed",
|
|
14800
15169
|
error: "no persisted source URL to download; poll the job again if it still exists upstream"
|
|
14801
15170
|
});
|
|
@@ -14820,21 +15189,21 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14820
15189
|
if (!source.url) throw new Error(`no durable source URL to refresh ${source.role ?? "asset"} from`);
|
|
14821
15190
|
fresh = await provider.download(source.url);
|
|
14822
15191
|
if (recorded && sha256(fresh) === recordedRaw && !reapply) {
|
|
14823
|
-
log(` current ${
|
|
15192
|
+
log(` current ${path22.relative(process.cwd(), target)}`);
|
|
14824
15193
|
outputs.push({ ...recorded, path: portableOutputPath(target, spec.root) });
|
|
14825
15194
|
continue;
|
|
14826
15195
|
}
|
|
14827
15196
|
}
|
|
14828
15197
|
let raw = null;
|
|
14829
15198
|
let final = null;
|
|
14830
|
-
if (
|
|
15199
|
+
if (existsSync18(target)) {
|
|
14831
15200
|
const currentHash = await sha256File(target);
|
|
14832
15201
|
if (recorded && currentHash === recorded.sha256) {
|
|
14833
15202
|
if (!fresh && !reapply) {
|
|
14834
15203
|
if (cacheDir) {
|
|
14835
15204
|
await cacheMedia(
|
|
14836
15205
|
cacheDir,
|
|
14837
|
-
await
|
|
15206
|
+
await readFile14(target),
|
|
14838
15207
|
recorded.mediaType ?? MediaType.PNG,
|
|
14839
15208
|
recorded.sha256
|
|
14840
15209
|
);
|
|
@@ -14843,10 +15212,10 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14843
15212
|
continue;
|
|
14844
15213
|
}
|
|
14845
15214
|
if (reapply && !fresh) {
|
|
14846
|
-
if (!recorded.raw) raw = await
|
|
14847
|
-
log(` reapply ${
|
|
15215
|
+
if (!recorded.raw) raw = await readFile14(target);
|
|
15216
|
+
log(` reapply ${path22.relative(process.cwd(), target)}`);
|
|
14848
15217
|
} else {
|
|
14849
|
-
log(` changed ${
|
|
15218
|
+
log(` changed ${path22.relative(process.cwd(), target)} (upstream)`);
|
|
14850
15219
|
}
|
|
14851
15220
|
} else {
|
|
14852
15221
|
const superseded = (entry.supersededOutputs ?? []).find(
|
|
@@ -14867,14 +15236,14 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14867
15236
|
}
|
|
14868
15237
|
if (outgoing && cacheDir) {
|
|
14869
15238
|
try {
|
|
14870
|
-
const oldBytes = await
|
|
15239
|
+
const oldBytes = await readFile14(target);
|
|
14871
15240
|
const oldMediaType = detectMediaType(oldBytes);
|
|
14872
15241
|
if (oldMediaType) await cacheMedia(cacheDir, oldBytes, oldMediaType, currentHash);
|
|
14873
15242
|
} catch {
|
|
14874
15243
|
}
|
|
14875
15244
|
}
|
|
14876
15245
|
log(
|
|
14877
|
-
` replace ${
|
|
15246
|
+
` replace ${path22.relative(process.cwd(), target)}` + (opts.force ? " (--force)" : " (previous tracked generation)")
|
|
14878
15247
|
);
|
|
14879
15248
|
}
|
|
14880
15249
|
}
|
|
@@ -14883,7 +15252,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14883
15252
|
} else if (!raw && recorded && cacheDir) {
|
|
14884
15253
|
if (!reapply) final = await readCachedMedia(cacheDir, recorded.sha256, expectedMediaType);
|
|
14885
15254
|
if (!final && recordedRaw) raw = await readCachedMedia(cacheDir, recordedRaw, expectedMediaType);
|
|
14886
|
-
if (final || raw) log(` cached ${
|
|
15255
|
+
if (final || raw) log(` cached ${path22.relative(process.cwd(), target)}`);
|
|
14887
15256
|
}
|
|
14888
15257
|
if (!final && !raw) {
|
|
14889
15258
|
if (!source.url) {
|
|
@@ -14910,13 +15279,13 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14910
15279
|
buf = processed.bytes;
|
|
14911
15280
|
if (processed.changed) {
|
|
14912
15281
|
rawHash = sha256(raw);
|
|
14913
|
-
log(` snapped ${
|
|
15282
|
+
log(` snapped ${path22.relative(process.cwd(), target)} to ${wanted.palette.colors.length} colours`);
|
|
14914
15283
|
}
|
|
14915
15284
|
}
|
|
14916
15285
|
if (cacheDir) await cacheMedia(cacheDir, buf, mediaType);
|
|
14917
|
-
await
|
|
15286
|
+
await mkdir8(path22.dirname(target), { recursive: true });
|
|
14918
15287
|
const tmp = `${target}.pixelkiln.tmp`;
|
|
14919
|
-
await
|
|
15288
|
+
await writeFile8(tmp, buf);
|
|
14920
15289
|
outputs.push({
|
|
14921
15290
|
path: portableOutputPath(target, spec.root),
|
|
14922
15291
|
sha256: sha256(buf),
|
|
@@ -14924,22 +15293,22 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14924
15293
|
mediaType,
|
|
14925
15294
|
...rawHash ? { raw: rawHash } : {}
|
|
14926
15295
|
});
|
|
14927
|
-
upsert(lock,
|
|
15296
|
+
upsert(lock, key2, { outputs: mergeOutputs(entry.outputs, outputs) });
|
|
14928
15297
|
await saveLock(lockPath, lock);
|
|
14929
|
-
await
|
|
15298
|
+
await rename6(tmp, target);
|
|
14930
15299
|
wrote = true;
|
|
14931
|
-
log(` wrote ${
|
|
15300
|
+
log(` wrote ${path22.relative(process.cwd(), target)}`);
|
|
14932
15301
|
}
|
|
14933
15302
|
if (opts.refresh && !wrote) {
|
|
14934
15303
|
if (rotated) {
|
|
14935
15304
|
const persistent = sources.filter((source) => shouldPersistSourceUrl(source.url));
|
|
14936
|
-
upsert(lock,
|
|
15305
|
+
upsert(lock, key2, { sourceUrl: persistent[0]?.url ?? null, sourceUrls: persistent });
|
|
14937
15306
|
}
|
|
14938
15307
|
result.unchanged = (result.unchanged ?? 0) + 1;
|
|
14939
15308
|
continue;
|
|
14940
15309
|
}
|
|
14941
15310
|
const persistentSources = sources.filter((source) => shouldPersistSourceUrl(source.url));
|
|
14942
|
-
upsert(lock,
|
|
15311
|
+
upsert(lock, key2, {
|
|
14943
15312
|
status: "downloaded",
|
|
14944
15313
|
provider: provider.id,
|
|
14945
15314
|
outputs,
|
|
@@ -14956,13 +15325,13 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14956
15325
|
result.downloaded++;
|
|
14957
15326
|
} catch (err) {
|
|
14958
15327
|
const message6 = err instanceof Error ? err.message : String(err);
|
|
14959
|
-
upsert(lock,
|
|
15328
|
+
upsert(lock, key2, {
|
|
14960
15329
|
status: "download-failed",
|
|
14961
15330
|
outputs: mergeOutputs(entry.outputs, outputs),
|
|
14962
15331
|
error: `download failed: ${message6}`
|
|
14963
15332
|
});
|
|
14964
15333
|
result.failed++;
|
|
14965
|
-
log(` FAILED ${
|
|
15334
|
+
log(` FAILED ${key2}: ${message6}`);
|
|
14966
15335
|
}
|
|
14967
15336
|
await saveLock(lockPath, lock);
|
|
14968
15337
|
}
|
|
@@ -14972,10 +15341,10 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14972
15341
|
return result;
|
|
14973
15342
|
}
|
|
14974
15343
|
async function readCachedMedia(cacheDir, hash, mediaType) {
|
|
14975
|
-
const file =
|
|
14976
|
-
if (!
|
|
15344
|
+
const file = path22.join(cacheDir, cacheFileName(hash, mediaType));
|
|
15345
|
+
if (!existsSync18(file)) return null;
|
|
14977
15346
|
try {
|
|
14978
|
-
const buf = await
|
|
15347
|
+
const buf = await readFile14(file);
|
|
14979
15348
|
if (sha256(buf) !== hash) return null;
|
|
14980
15349
|
validateMedia(buf, mediaType);
|
|
14981
15350
|
return buf;
|
|
@@ -14986,15 +15355,15 @@ async function readCachedMedia(cacheDir, hash, mediaType) {
|
|
|
14986
15355
|
async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
|
|
14987
15356
|
const hash = knownHash ?? sha256(buf);
|
|
14988
15357
|
validateMedia(buf, mediaType);
|
|
14989
|
-
const file =
|
|
15358
|
+
const file = path22.join(cacheDir, cacheFileName(hash, mediaType));
|
|
14990
15359
|
if (await readCachedMedia(cacheDir, hash, mediaType)) return;
|
|
14991
|
-
await
|
|
15360
|
+
await mkdir8(cacheDir, { recursive: true });
|
|
14992
15361
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
14993
|
-
await
|
|
15362
|
+
await writeFile8(tmp, buf);
|
|
14994
15363
|
try {
|
|
14995
|
-
await
|
|
15364
|
+
await rename6(tmp, file);
|
|
14996
15365
|
} catch (err) {
|
|
14997
|
-
if (!
|
|
15366
|
+
if (!existsSync18(file)) throw err;
|
|
14998
15367
|
} finally {
|
|
14999
15368
|
await rm5(tmp, { force: true });
|
|
15000
15369
|
}
|
|
@@ -15011,8 +15380,8 @@ async function pushTags(provider, specs, lock, opts = {}) {
|
|
|
15011
15380
|
});
|
|
15012
15381
|
const specByKey = new Map(specs.map((s) => [lockKey(s.styleId, s.assetId), s]));
|
|
15013
15382
|
let tagged = 0;
|
|
15014
|
-
for (const [
|
|
15015
|
-
const spec = specByKey.get(
|
|
15383
|
+
for (const [key2, entry] of Object.entries(lock.entries)) {
|
|
15384
|
+
const spec = specByKey.get(key2);
|
|
15016
15385
|
if (!spec || entry.provider !== provider.id || !entry.objectId) continue;
|
|
15017
15386
|
if (entry.generator === "pixflux" || entry.generator === "vfx") continue;
|
|
15018
15387
|
if (!provider.setTags) return tagged;
|
|
@@ -15020,7 +15389,7 @@ async function pushTags(provider, specs, lock, opts = {}) {
|
|
|
15020
15389
|
await provider.setTags(entry.objectId, spec.tags, entry.generator);
|
|
15021
15390
|
tagged++;
|
|
15022
15391
|
} catch (err) {
|
|
15023
|
-
log(` tag failed ${
|
|
15392
|
+
log(` tag failed ${key2}: ${err instanceof Error ? err.message : String(err)}`);
|
|
15024
15393
|
}
|
|
15025
15394
|
}
|
|
15026
15395
|
return tagged;
|
|
@@ -15104,22 +15473,22 @@ function pickHistory(entry, selector) {
|
|
|
15104
15473
|
return matches[0];
|
|
15105
15474
|
}
|
|
15106
15475
|
async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
15107
|
-
const
|
|
15108
|
-
const entry = lock.entries[
|
|
15109
|
-
if (!entry) throw new Error(`${
|
|
15476
|
+
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
15477
|
+
const entry = lock.entries[key2];
|
|
15478
|
+
if (!entry) throw new Error(`${key2} is not in the lockfile`);
|
|
15110
15479
|
if (entry.status !== "downloaded") {
|
|
15111
|
-
throw new Error(`${
|
|
15480
|
+
throw new Error(`${key2} is ${entry.status}; finish or fetch the current generation before restoring an older one`);
|
|
15112
15481
|
}
|
|
15113
15482
|
const { index, generation } = pickHistory(entry, opts.generation);
|
|
15114
15483
|
if (generation.provider !== provider.id) {
|
|
15115
|
-
throw new Error(`${
|
|
15484
|
+
throw new Error(`${key2}'s previous generation #${index} came from ${generation.provider}, not ${provider.id}`);
|
|
15116
15485
|
}
|
|
15117
15486
|
for (let i = 0; i < entry.outputs.length; i++) {
|
|
15118
15487
|
const file = currentEntryOutputPath(entry, spec, i);
|
|
15119
|
-
if (!
|
|
15488
|
+
if (!existsSync19(file)) continue;
|
|
15120
15489
|
if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
|
|
15121
15490
|
throw new OverwriteRefusedError(
|
|
15122
|
-
`${
|
|
15491
|
+
`${path23.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
|
|
15123
15492
|
[file]
|
|
15124
15493
|
);
|
|
15125
15494
|
}
|
|
@@ -15127,7 +15496,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
15127
15496
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
15128
15497
|
const remaining = (entry.history ?? []).filter((_, i) => i !== index - 1);
|
|
15129
15498
|
const history = [retireGeneration(entry, now), ...remaining];
|
|
15130
|
-
upsert(lock,
|
|
15499
|
+
upsert(lock, key2, {
|
|
15131
15500
|
specHash: generation.specHash,
|
|
15132
15501
|
generator: generation.generator,
|
|
15133
15502
|
tileFeature: generation.tileFeature,
|
|
@@ -15179,11 +15548,11 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
15179
15548
|
|
|
15180
15549
|
// src/pipeline/cache-health.ts
|
|
15181
15550
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
15182
|
-
if (options.prune && !
|
|
15183
|
-
throw new Error(`Refusing to prune without an existing lockfile at ${
|
|
15551
|
+
if (options.prune && !existsSync20(lockPath)) {
|
|
15552
|
+
throw new Error(`Refusing to prune without an existing lockfile at ${path24.resolve(lockPath)}`);
|
|
15184
15553
|
}
|
|
15185
|
-
const contentDir =
|
|
15186
|
-
const remotePath =
|
|
15554
|
+
const contentDir = path24.resolve(path24.dirname(lockPath), ".pixelkiln", "cache");
|
|
15555
|
+
const remotePath = path24.resolve(cachePathFor(lockPath));
|
|
15187
15556
|
const referenced = referencedHashes(lock);
|
|
15188
15557
|
let content = await inspectContentCache(contentDir, referenced);
|
|
15189
15558
|
let remoteHashes = await inspectRemoteHashCache(remotePath);
|
|
@@ -15195,7 +15564,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
15195
15564
|
]);
|
|
15196
15565
|
for (const name of names) {
|
|
15197
15566
|
try {
|
|
15198
|
-
await rm6(
|
|
15567
|
+
await rm6(path24.join(contentDir, name), { force: true });
|
|
15199
15568
|
removed.contentFiles++;
|
|
15200
15569
|
} catch {
|
|
15201
15570
|
}
|
|
@@ -15204,7 +15573,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
15204
15573
|
await saveCache(remotePath, { version: 1, hashes: {} });
|
|
15205
15574
|
removed.resetRemoteHashCache = true;
|
|
15206
15575
|
} else if (remoteHashes.invalidIds.length) {
|
|
15207
|
-
const cache = parseCache(JSON.parse(await
|
|
15576
|
+
const cache = parseCache(JSON.parse(await readFile15(remotePath, "utf8")));
|
|
15208
15577
|
for (const id of remoteHashes.invalidIds) delete cache.hashes[id];
|
|
15209
15578
|
removed.remoteHashEntries = remoteHashes.invalidIds.length;
|
|
15210
15579
|
await saveCache(remotePath, cache);
|
|
@@ -15222,7 +15591,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
15222
15591
|
async function inspectContentCache(contentDir, referenced) {
|
|
15223
15592
|
const report = {
|
|
15224
15593
|
path: contentDir,
|
|
15225
|
-
exists:
|
|
15594
|
+
exists: existsSync20(contentDir),
|
|
15226
15595
|
files: 0,
|
|
15227
15596
|
bytes: 0,
|
|
15228
15597
|
valid: 0,
|
|
@@ -15243,12 +15612,12 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
15243
15612
|
continue;
|
|
15244
15613
|
}
|
|
15245
15614
|
report.files++;
|
|
15246
|
-
const file =
|
|
15615
|
+
const file = path24.join(contentDir, entry.name);
|
|
15247
15616
|
const mediaType = mediaTypeFromExtension(entry.name);
|
|
15248
15617
|
const expected = mediaType ? entry.name.slice(0, -4) : "";
|
|
15249
15618
|
let bytes;
|
|
15250
15619
|
try {
|
|
15251
|
-
bytes = await
|
|
15620
|
+
bytes = await readFile15(file);
|
|
15252
15621
|
report.bytes += bytes.length;
|
|
15253
15622
|
} catch (err) {
|
|
15254
15623
|
report.invalid.push({
|
|
@@ -15286,7 +15655,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
15286
15655
|
async function inspectRemoteHashCache(remotePath) {
|
|
15287
15656
|
const report = {
|
|
15288
15657
|
path: remotePath,
|
|
15289
|
-
exists:
|
|
15658
|
+
exists: existsSync20(remotePath),
|
|
15290
15659
|
entries: 0,
|
|
15291
15660
|
valid: 0,
|
|
15292
15661
|
invalidIds: [],
|
|
@@ -15295,7 +15664,7 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
15295
15664
|
if (!report.exists) return report;
|
|
15296
15665
|
let cache;
|
|
15297
15666
|
try {
|
|
15298
|
-
cache = parseCache(JSON.parse(await
|
|
15667
|
+
cache = parseCache(JSON.parse(await readFile15(remotePath, "utf8")));
|
|
15299
15668
|
} catch (err) {
|
|
15300
15669
|
report.error = err instanceof Error ? err.message : String(err);
|
|
15301
15670
|
return report;
|
|
@@ -15311,19 +15680,19 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
15311
15680
|
|
|
15312
15681
|
// src/pipeline/pack.ts
|
|
15313
15682
|
import { readFileSync as readFileSync6 } from "fs";
|
|
15314
|
-
import
|
|
15683
|
+
import path25 from "path";
|
|
15315
15684
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
15316
15685
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
15317
15686
|
if (!Array.isArray(raw) || !raw.length) {
|
|
15318
15687
|
throw new Error("--inputs must be a non-empty JSON array of { id, path }");
|
|
15319
15688
|
}
|
|
15320
|
-
const baseDir =
|
|
15689
|
+
const baseDir = path25.dirname(path25.resolve(inputsFilePath));
|
|
15321
15690
|
return raw.map((entry, i) => {
|
|
15322
15691
|
const e = entry;
|
|
15323
15692
|
if (typeof e.id !== "string" || typeof e.path !== "string") {
|
|
15324
15693
|
throw new Error(`--inputs[${i}] needs string "id" and "path"`);
|
|
15325
15694
|
}
|
|
15326
|
-
return { id: e.id, path:
|
|
15695
|
+
return { id: e.id, path: path25.resolve(baseDir, e.path) };
|
|
15327
15696
|
});
|
|
15328
15697
|
}
|
|
15329
15698
|
function packSprites(inputs, options = {}) {
|
|
@@ -15407,14 +15776,14 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
15407
15776
|
}
|
|
15408
15777
|
const inputs2 = Object.entries(options.sourceOverrides).map(([id, source]) => ({
|
|
15409
15778
|
id,
|
|
15410
|
-
path:
|
|
15779
|
+
path: path25.resolve(source)
|
|
15411
15780
|
}));
|
|
15412
15781
|
if (!inputs2.length) throw new Error(`No approved quality outputs for style "${styleId}".`);
|
|
15413
15782
|
const packed2 = packSprites(inputs2, options);
|
|
15414
15783
|
return { ...packed2, atlas: { ...packed2.atlas, style: styleId } };
|
|
15415
15784
|
}
|
|
15416
15785
|
const prefix = `${styleId}/`;
|
|
15417
|
-
const entries = Object.entries(lock.entries).filter(([
|
|
15786
|
+
const entries = Object.entries(lock.entries).filter(([key2]) => key2.startsWith(prefix));
|
|
15418
15787
|
const sources = options.sources ?? {};
|
|
15419
15788
|
if (!entries.length && !Object.keys(sources).length) {
|
|
15420
15789
|
throw new Error(
|
|
@@ -15425,13 +15794,13 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
15425
15794
|
const noOutput = [];
|
|
15426
15795
|
const locked = /* @__PURE__ */ new Set();
|
|
15427
15796
|
const sets = [];
|
|
15428
|
-
for (const [
|
|
15429
|
-
const id =
|
|
15797
|
+
for (const [key2, entry] of entries) {
|
|
15798
|
+
const id = key2.slice(prefix.length);
|
|
15430
15799
|
locked.add(id);
|
|
15431
15800
|
let outputs = resolveEntryOutputs(entry, id, manifestDir);
|
|
15432
15801
|
const source = sources[id];
|
|
15433
15802
|
if (source && outputs.length <= 1) {
|
|
15434
|
-
inputs.push({ id, path:
|
|
15803
|
+
inputs.push({ id, path: path25.resolve(manifestDir, source) });
|
|
15435
15804
|
continue;
|
|
15436
15805
|
}
|
|
15437
15806
|
if (source && sourceIsStem(source, entry, manifestDir)) {
|
|
@@ -15466,7 +15835,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
15466
15835
|
}
|
|
15467
15836
|
}
|
|
15468
15837
|
for (const [id, source] of Object.entries(sources)) {
|
|
15469
|
-
if (!locked.has(id)) inputs.push({ id, path:
|
|
15838
|
+
if (!locked.has(id)) inputs.push({ id, path: path25.resolve(manifestDir, source) });
|
|
15470
15839
|
}
|
|
15471
15840
|
if (!inputs.length) {
|
|
15472
15841
|
throw new Error(`No readable sprites for style "${styleId}"; ${noOutput.length} skipped.`);
|
|
@@ -15488,14 +15857,14 @@ function mountSprites(placements, options) {
|
|
|
15488
15857
|
}
|
|
15489
15858
|
const byCell = /* @__PURE__ */ new Map();
|
|
15490
15859
|
for (const p of placements) {
|
|
15491
|
-
const
|
|
15492
|
-
const owner = byCell.get(
|
|
15860
|
+
const key2 = `${p.cell[0]},${p.cell[1]}`;
|
|
15861
|
+
const owner = byCell.get(key2);
|
|
15493
15862
|
if (owner) {
|
|
15494
15863
|
throw new Error(
|
|
15495
|
-
`mountSprites: "${p.id}" and "${owner}" both claim cell ${
|
|
15864
|
+
`mountSprites: "${p.id}" and "${owner}" both claim cell ${key2}; a cell has exactly one owner`
|
|
15496
15865
|
);
|
|
15497
15866
|
}
|
|
15498
|
-
byCell.set(
|
|
15867
|
+
byCell.set(key2, p.id);
|
|
15499
15868
|
}
|
|
15500
15869
|
const loaded = [];
|
|
15501
15870
|
const skipped = [];
|
|
@@ -15574,7 +15943,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
15574
15943
|
const source = sources[id];
|
|
15575
15944
|
const entry = lock.entries[`${styleId}/${id}`];
|
|
15576
15945
|
if (source && !(entry && sourceIsStem(source, entry, manifestDir))) {
|
|
15577
|
-
placements.push({ id, path:
|
|
15946
|
+
placements.push({ id, path: path25.resolve(manifestDir, source), cell });
|
|
15578
15947
|
continue;
|
|
15579
15948
|
}
|
|
15580
15949
|
if (source && entry) {
|
|
@@ -15607,7 +15976,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
15607
15976
|
`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}`
|
|
15608
15977
|
);
|
|
15609
15978
|
}
|
|
15610
|
-
const basePng = mount.base ? readFileSync6(
|
|
15979
|
+
const basePng = mount.base ? readFileSync6(path25.resolve(manifestDir, mount.base)) : void 0;
|
|
15611
15980
|
const mounted = mountSprites(placements, {
|
|
15612
15981
|
cellWidth: mount.cellWidth,
|
|
15613
15982
|
cellHeight: mount.cellHeight,
|
|
@@ -15617,7 +15986,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
15617
15986
|
...mounted,
|
|
15618
15987
|
sources: mount.base ? [{
|
|
15619
15988
|
id: "$base",
|
|
15620
|
-
path:
|
|
15989
|
+
path: path25.resolve(manifestDir, mount.base),
|
|
15621
15990
|
sha256: sha256(basePng),
|
|
15622
15991
|
included: true
|
|
15623
15992
|
}, ...mounted.sources] : mounted.sources,
|
|
@@ -15635,8 +16004,8 @@ function normalizeTileRules(raw) {
|
|
|
15635
16004
|
if (arity !== 4 && arity !== 6) return null;
|
|
15636
16005
|
const masks = {};
|
|
15637
16006
|
if (isRecord2(raw.tiles)) {
|
|
15638
|
-
for (const [
|
|
15639
|
-
const index = tileIndex(
|
|
16007
|
+
for (const [key2, value] of Object.entries(raw.tiles)) {
|
|
16008
|
+
const index = tileIndex(key2);
|
|
15640
16009
|
const mask = typeof value === "number" ? value : isRecord2(value) && typeof value.bitmask === "number" ? value.bitmask : isRecord2(value) && typeof value.mask === "number" ? value.mask : null;
|
|
15641
16010
|
if (index !== null && mask !== null && Number.isInteger(mask) && mask >= 0) masks[index] = mask;
|
|
15642
16011
|
}
|
|
@@ -15911,8 +16280,8 @@ function assertUniformTiles(generic) {
|
|
|
15911
16280
|
);
|
|
15912
16281
|
}
|
|
15913
16282
|
}
|
|
15914
|
-
function tileIndex(
|
|
15915
|
-
const match =
|
|
16283
|
+
function tileIndex(key2) {
|
|
16284
|
+
const match = key2.match(/(?:^|[_-])(\d+)$/);
|
|
15916
16285
|
return match ? Number(match[1]) : null;
|
|
15917
16286
|
}
|
|
15918
16287
|
function isRecord2(value) {
|
|
@@ -16027,9 +16396,9 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
|
|
|
16027
16396
|
});
|
|
16028
16397
|
const estimates = new Map(items.map((item) => [
|
|
16029
16398
|
item.key,
|
|
16030
|
-
item.spec.mirror ? { amount: 0, unit: item.spec.costUnit, candidates: 1 } : validateCostEstimate(provider.id, provider.estimate(item.spec))
|
|
16399
|
+
item.spec.mirror || item.spec.derive ? { amount: 0, unit: item.spec.costUnit, candidates: 1 } : validateCostEstimate(provider.id, provider.estimate(item.spec))
|
|
16031
16400
|
]));
|
|
16032
|
-
const units = new Set(
|
|
16401
|
+
const units = new Set(items.filter((item) => !item.spec.derive).map((item) => estimates.get(item.key).unit));
|
|
16033
16402
|
if (units.size > 1) {
|
|
16034
16403
|
throw new Error(`Provider "${provider.id}" returned mixed cost units for one submission batch`);
|
|
16035
16404
|
}
|
|
@@ -16127,20 +16496,21 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
|
|
|
16127
16496
|
}
|
|
16128
16497
|
}
|
|
16129
16498
|
}
|
|
16130
|
-
for (const { spec, key } of items) {
|
|
16131
|
-
const estimate = estimates.get(
|
|
16499
|
+
for (const { spec, key: key2 } of items) {
|
|
16500
|
+
const estimate = estimates.get(key2);
|
|
16132
16501
|
if (spec.batch?.role === "member") {
|
|
16133
16502
|
continue;
|
|
16134
16503
|
}
|
|
16135
|
-
if (spec.mirror) {
|
|
16504
|
+
if (spec.mirror || spec.derive) {
|
|
16136
16505
|
try {
|
|
16137
16506
|
await requireRevisionReady(spec, lock);
|
|
16138
|
-
await
|
|
16507
|
+
if (spec.derive) await deriveAsset(spec, lock, lockPath, { onProgress: log });
|
|
16508
|
+
else await deriveMirror(spec, lock, lockPath, { onProgress: log });
|
|
16139
16509
|
submitted++;
|
|
16140
16510
|
} catch (err) {
|
|
16141
16511
|
const message6 = err instanceof Error ? err.message : String(err);
|
|
16142
16512
|
failed++;
|
|
16143
|
-
upsert(lock,
|
|
16513
|
+
upsert(lock, key2, {
|
|
16144
16514
|
styleId: spec.styleId,
|
|
16145
16515
|
assetId: spec.assetId,
|
|
16146
16516
|
specHash: spec.specHash,
|
|
@@ -16150,13 +16520,13 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
|
|
|
16150
16520
|
height: spec.height,
|
|
16151
16521
|
status: "failed",
|
|
16152
16522
|
error: message6,
|
|
16153
|
-
outputs: lock.entries[
|
|
16523
|
+
outputs: lock.entries[key2]?.outputs ?? [],
|
|
16154
16524
|
cost: 0,
|
|
16155
16525
|
costUnit: spec.costUnit,
|
|
16156
16526
|
provider: provider.id
|
|
16157
16527
|
});
|
|
16158
16528
|
await saveLock(lockPath, lock);
|
|
16159
|
-
log(` FAILED ${
|
|
16529
|
+
log(` FAILED ${key2}: ${message6}`);
|
|
16160
16530
|
}
|
|
16161
16531
|
continue;
|
|
16162
16532
|
}
|
|
@@ -16168,11 +16538,11 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
|
|
|
16168
16538
|
const missing = (spec.batch.memberAssetIds ?? []).filter((id) => !byKey.has(lockKey(spec.styleId, id)));
|
|
16169
16539
|
if (missing.length) {
|
|
16170
16540
|
throw new Error(
|
|
16171
|
-
`${
|
|
16541
|
+
`${key2}: batch member(s) ${missing.join(", ")} must be submitted in the same run as this leader; run without --only, or include every sibling`
|
|
16172
16542
|
);
|
|
16173
16543
|
}
|
|
16174
16544
|
}
|
|
16175
|
-
const previousEntry = lock.entries[
|
|
16545
|
+
const previousEntry = lock.entries[key2];
|
|
16176
16546
|
const resumesCheckpoint = Boolean(
|
|
16177
16547
|
previousEntry?.specHash === spec.specHash && previousEntry.provider === provider.id && previousEntry.generator === spec.generator && previousEntry.submissionComplete === false && previousEntry.jobId
|
|
16178
16548
|
);
|
|
@@ -16202,9 +16572,9 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
|
|
|
16202
16572
|
const leaderGroup = motionLeader ? recordedAnimationGroup(lock.entries[lockKey(motionLeader.spec.styleId, motionLeader.spec.assetId)]) : void 0;
|
|
16203
16573
|
const motionGroup = leaderGroup?.animationGroupId && leaderGroup.animationName ? { animationGroupId: leaderGroup.animationGroupId, animationName: leaderGroup.animationName } : void 0;
|
|
16204
16574
|
if (motionLeader && !motionGroup) {
|
|
16205
|
-
log(` ${
|
|
16575
|
+
log(` ${key2}: ${motionLeader.assetId} has no animation group recorded; drawing this direction on its own`);
|
|
16206
16576
|
}
|
|
16207
|
-
upsert(lock,
|
|
16577
|
+
upsert(lock, key2, {
|
|
16208
16578
|
styleId: spec.styleId,
|
|
16209
16579
|
assetId: spec.assetId,
|
|
16210
16580
|
specHash: spec.specHash,
|
|
@@ -16302,8 +16672,8 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
|
|
|
16302
16672
|
...previousMetadata ? { previousMetadata } : {},
|
|
16303
16673
|
checkpoint: async (checkpoint) => {
|
|
16304
16674
|
if (!checkpoint.jobId) throw new Error("Provider checkpoint returned an empty job id");
|
|
16305
|
-
const entry = lock.entries[
|
|
16306
|
-
upsert(lock,
|
|
16675
|
+
const entry = lock.entries[key2];
|
|
16676
|
+
upsert(lock, key2, {
|
|
16307
16677
|
jobId: checkpoint.jobId,
|
|
16308
16678
|
submissionComplete: checkpoint.complete,
|
|
16309
16679
|
reviewObjectId: checkpoint.complete && (spec.generator === "frames" || estimate.candidates > 1 && !spec.tileFeature) ? checkpoint.jobId : null,
|
|
@@ -16320,41 +16690,41 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
|
|
|
16320
16690
|
await saveLock(lockPath, lock);
|
|
16321
16691
|
}
|
|
16322
16692
|
});
|
|
16323
|
-
upsert(lock,
|
|
16693
|
+
upsert(lock, key2, {
|
|
16324
16694
|
jobId,
|
|
16325
16695
|
submissionComplete: true,
|
|
16326
16696
|
// A multi-candidate generator routes through review; record the parent
|
|
16327
16697
|
// so `pick` knows where to look.
|
|
16328
16698
|
reviewObjectId: spec.generator === "frames" || estimate.candidates > 1 && !spec.tileFeature ? jobId : null,
|
|
16329
16699
|
status: "processing",
|
|
16330
|
-
providerMetadata: metadata ? { ...lock.entries[
|
|
16700
|
+
providerMetadata: metadata ? { ...lock.entries[key2].providerMetadata, [provider.id]: metadata } : lock.entries[key2].providerMetadata
|
|
16331
16701
|
});
|
|
16332
16702
|
inFlight.set(jobId, spec);
|
|
16333
16703
|
submitted++;
|
|
16334
16704
|
spent += estimate.amount;
|
|
16335
|
-
writeBatchMembers(spec,
|
|
16705
|
+
writeBatchMembers(spec, key2, null);
|
|
16336
16706
|
log(
|
|
16337
|
-
` ${
|
|
16707
|
+
` ${key2} \u2192 ${jobId} (${spec.width}x${spec.height}` + (estimate.candidates > 1 ? `, ${estimate.candidates} ${spec.tileFeature ? "outputs" : "candidates"}` : "") + `, ${estimate.amount})`
|
|
16338
16708
|
);
|
|
16339
16709
|
} catch (err) {
|
|
16340
16710
|
const message6 = err instanceof Error ? err.message : String(err);
|
|
16341
|
-
const entry = lock.entries[
|
|
16711
|
+
const entry = lock.entries[key2];
|
|
16342
16712
|
if (entry.jobId && entry.submissionComplete === true) {
|
|
16343
|
-
upsert(lock,
|
|
16713
|
+
upsert(lock, key2, { status: "processing", error: null });
|
|
16344
16714
|
inFlight.set(entry.jobId, spec);
|
|
16345
16715
|
submitted++;
|
|
16346
16716
|
spent += estimate.amount;
|
|
16347
|
-
writeBatchMembers(spec,
|
|
16348
|
-
log(` ${
|
|
16717
|
+
writeBatchMembers(spec, key2, null);
|
|
16718
|
+
log(` ${key2} \u2192 ${entry.jobId} (recovered from completed checkpoint)`);
|
|
16349
16719
|
} else {
|
|
16350
16720
|
failed++;
|
|
16351
|
-
upsert(lock,
|
|
16721
|
+
upsert(lock, key2, {
|
|
16352
16722
|
status: "failed",
|
|
16353
16723
|
error: message6,
|
|
16354
16724
|
cost: entry.jobId ? estimate.amount : 0
|
|
16355
16725
|
});
|
|
16356
|
-
writeBatchMembers(spec,
|
|
16357
|
-
log(` FAILED ${
|
|
16726
|
+
writeBatchMembers(spec, key2, message6);
|
|
16727
|
+
log(` FAILED ${key2}: ${message6}`);
|
|
16358
16728
|
}
|
|
16359
16729
|
}
|
|
16360
16730
|
await saveLock(lockPath, lock);
|
|
@@ -16385,14 +16755,14 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
16385
16755
|
const selectedKeys = opts.specs ? new Set(specByKey.keys()) : null;
|
|
16386
16756
|
const result = { review: 0, completed: 0, failed: 0, stillRunning: 0 };
|
|
16387
16757
|
const incompleteSubmissions = Object.entries(lock.entries).filter(
|
|
16388
|
-
([
|
|
16758
|
+
([key2, entry]) => entry.provider === provider.id && (!selectedKeys || selectedKeys.has(key2)) && entry.jobId && entry.submissionComplete === false && (entry.status === "pending" || entry.status === "processing")
|
|
16389
16759
|
);
|
|
16390
|
-
for (const [
|
|
16391
|
-
log(` incomplete submission ${
|
|
16760
|
+
for (const [key2] of incompleteSubmissions) {
|
|
16761
|
+
log(` incomplete submission ${key2}; rerun \`pixelkiln submit\` to resume`);
|
|
16392
16762
|
}
|
|
16393
16763
|
result.stillRunning = incompleteSubmissions.length;
|
|
16394
16764
|
const pending = () => Object.entries(lock.entries).filter(
|
|
16395
|
-
([
|
|
16765
|
+
([key2, e]) => e.provider === provider.id && (!selectedKeys || selectedKeys.has(key2)) && e.jobId && e.submissionComplete !== false && (e.status === "pending" || e.status === "processing")
|
|
16396
16766
|
);
|
|
16397
16767
|
while (pending().length > 0) {
|
|
16398
16768
|
if (Date.now() - started > timeout) {
|
|
@@ -16400,16 +16770,16 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
16400
16770
|
log(` timed out with ${result.stillRunning} job(s) still running; re-run \`poll\` to resume`);
|
|
16401
16771
|
break;
|
|
16402
16772
|
}
|
|
16403
|
-
for (const [
|
|
16773
|
+
for (const [key2, entry] of pending()) {
|
|
16404
16774
|
try {
|
|
16405
|
-
const currentSpec = specByKey.get(
|
|
16775
|
+
const currentSpec = specByKey.get(key2);
|
|
16406
16776
|
const state = await provider.poll(entry.jobId, entry.generator, {
|
|
16407
16777
|
tileFeature: entry.tileFeature ?? currentSpec?.tileFeature,
|
|
16408
16778
|
spec: currentSpec,
|
|
16409
16779
|
metadata: entry.providerMetadata?.[provider.id]
|
|
16410
16780
|
});
|
|
16411
16781
|
if (state.status === "review" || state.status === "review-set") {
|
|
16412
|
-
upsert(lock,
|
|
16782
|
+
upsert(lock, key2, {
|
|
16413
16783
|
status: "review",
|
|
16414
16784
|
reviewObjectId: entry.jobId,
|
|
16415
16785
|
providerMetadata: state.metadata ? {
|
|
@@ -16423,11 +16793,11 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
16423
16793
|
});
|
|
16424
16794
|
result.review++;
|
|
16425
16795
|
log(
|
|
16426
|
-
state.status === "review-set" ? ` review ${
|
|
16796
|
+
state.status === "review-set" ? ` review ${key2} (${state.frameUrls.length} ordered frames)` : ` review ${key2} (${state.candidateUrls.length} candidates)`
|
|
16427
16797
|
);
|
|
16428
16798
|
} else if (state.status === "ready") {
|
|
16429
16799
|
const sourceUrls = state.sources?.length ? state.sources : state.sourceUrl ? [{ url: state.sourceUrl }] : [];
|
|
16430
|
-
upsert(lock,
|
|
16800
|
+
upsert(lock, key2, {
|
|
16431
16801
|
status: "selected",
|
|
16432
16802
|
objectId: state.objectId,
|
|
16433
16803
|
sourceUrl: sourceUrls[0]?.url ?? null,
|
|
@@ -16443,14 +16813,14 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
16443
16813
|
billed: state.billed ?? entry.billed
|
|
16444
16814
|
});
|
|
16445
16815
|
result.completed++;
|
|
16446
|
-
log(` ready ${
|
|
16816
|
+
log(` ready ${key2}`);
|
|
16447
16817
|
} else if (state.status === "failed") {
|
|
16448
|
-
upsert(lock,
|
|
16818
|
+
upsert(lock, key2, { status: "failed", error: state.error });
|
|
16449
16819
|
result.failed++;
|
|
16450
|
-
log(` FAILED ${
|
|
16820
|
+
log(` FAILED ${key2}: ${state.error}`);
|
|
16451
16821
|
}
|
|
16452
16822
|
} catch (err) {
|
|
16453
|
-
log(` error polling ${
|
|
16823
|
+
log(` error polling ${key2}: ${err instanceof Error ? err.message : String(err)}`);
|
|
16454
16824
|
}
|
|
16455
16825
|
}
|
|
16456
16826
|
await saveLock(lockPath, lock);
|
|
@@ -16461,13 +16831,13 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
16461
16831
|
}
|
|
16462
16832
|
|
|
16463
16833
|
// src/pipeline/doctor.ts
|
|
16464
|
-
import { constants, existsSync as
|
|
16834
|
+
import { constants, existsSync as existsSync22 } from "fs";
|
|
16465
16835
|
import { access, stat as stat2 } from "fs/promises";
|
|
16466
|
-
import
|
|
16836
|
+
import path27 from "path";
|
|
16467
16837
|
|
|
16468
16838
|
// src/pipeline/install-check.ts
|
|
16469
|
-
import { existsSync as
|
|
16470
|
-
import
|
|
16839
|
+
import { existsSync as existsSync21, readFileSync as readFileSync7 } from "fs";
|
|
16840
|
+
import path26 from "path";
|
|
16471
16841
|
function readJson(file) {
|
|
16472
16842
|
try {
|
|
16473
16843
|
return JSON.parse(readFileSync7(file, "utf8"));
|
|
@@ -16476,19 +16846,19 @@ function readJson(file) {
|
|
|
16476
16846
|
}
|
|
16477
16847
|
}
|
|
16478
16848
|
function readInstallFacts(manifestDir, running) {
|
|
16479
|
-
let dir =
|
|
16849
|
+
let dir = path26.resolve(manifestDir);
|
|
16480
16850
|
for (let depth = 0; depth < 4; depth++) {
|
|
16481
|
-
const pkg = readJson(
|
|
16851
|
+
const pkg = readJson(path26.join(dir, "package.json"));
|
|
16482
16852
|
if (pkg) {
|
|
16483
16853
|
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
16484
16854
|
if (pinned) {
|
|
16485
|
-
const installedPkg = readJson(
|
|
16855
|
+
const installedPkg = readJson(path26.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
16486
16856
|
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
16487
16857
|
return { pinned, installed, running };
|
|
16488
16858
|
}
|
|
16489
16859
|
}
|
|
16490
|
-
const parent =
|
|
16491
|
-
if (parent === dir || !
|
|
16860
|
+
const parent = path26.dirname(dir);
|
|
16861
|
+
if (parent === dir || !existsSync21(parent)) break;
|
|
16492
16862
|
dir = parent;
|
|
16493
16863
|
}
|
|
16494
16864
|
return null;
|
|
@@ -16551,12 +16921,12 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16551
16921
|
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
16552
16922
|
);
|
|
16553
16923
|
}
|
|
16554
|
-
const facts = readInstallFacts(
|
|
16924
|
+
const facts = readInstallFacts(path27.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
16555
16925
|
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
16556
16926
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
16557
16927
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
16558
|
-
|
|
16559
|
-
...spec.quality ? [
|
|
16928
|
+
path27.dirname(spec.outFile),
|
|
16929
|
+
...spec.quality ? [path27.dirname(spec.quality.outFile)] : []
|
|
16560
16930
|
]))];
|
|
16561
16931
|
const unwritable = [];
|
|
16562
16932
|
for (const dir of dirs) {
|
|
@@ -16575,14 +16945,14 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16575
16945
|
const outputOwners = /* @__PURE__ */ new Map();
|
|
16576
16946
|
const duplicateOutputs = [];
|
|
16577
16947
|
const specByKey = new Map(specs.map((spec) => [`${spec.styleId}/${spec.assetId}`, spec]));
|
|
16578
|
-
for (const [
|
|
16948
|
+
for (const [key2, entry] of Object.entries(lock.entries)) {
|
|
16579
16949
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
16580
16950
|
const output = entry.outputs[index];
|
|
16581
|
-
const spec = specByKey.get(
|
|
16582
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
16951
|
+
const spec = specByKey.get(key2);
|
|
16952
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, path27.dirname(lockPath));
|
|
16583
16953
|
const owner = outputOwners.get(absolute);
|
|
16584
|
-
if (owner && owner !==
|
|
16585
|
-
outputOwners.set(absolute,
|
|
16954
|
+
if (owner && owner !== key2) duplicateOutputs.push(`${output.path} (${owner}, ${key2})`);
|
|
16955
|
+
outputOwners.set(absolute, key2);
|
|
16586
16956
|
}
|
|
16587
16957
|
}
|
|
16588
16958
|
if (duplicateOutputs.length) {
|
|
@@ -16594,34 +16964,34 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16594
16964
|
} else {
|
|
16595
16965
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
16596
16966
|
}
|
|
16597
|
-
const cacheDir =
|
|
16967
|
+
const cacheDir = path27.join(path27.dirname(lockPath), ".pixelkiln", "cache");
|
|
16598
16968
|
const stranded = [];
|
|
16599
16969
|
const invalidState = [];
|
|
16600
16970
|
const staleMapUrls = [];
|
|
16601
16971
|
const now = Date.now();
|
|
16602
|
-
for (const [
|
|
16972
|
+
for (const [key2, entry] of Object.entries(lock.entries)) {
|
|
16603
16973
|
if ((entry.status === "pending" || entry.status === "processing") && !entry.jobId) {
|
|
16604
|
-
invalidState.push(`${
|
|
16974
|
+
invalidState.push(`${key2} (${entry.status} without job id)`);
|
|
16605
16975
|
}
|
|
16606
16976
|
if (entry.status === "review" && !entry.reviewObjectId) {
|
|
16607
|
-
invalidState.push(`${
|
|
16977
|
+
invalidState.push(`${key2} (review without review object id)`);
|
|
16608
16978
|
}
|
|
16609
16979
|
if (entry.status !== "selected" && entry.status !== "download-failed") continue;
|
|
16610
16980
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
16611
16981
|
let hasCache = false;
|
|
16612
16982
|
for (const output of entry.outputs) {
|
|
16613
|
-
const cached2 =
|
|
16983
|
+
const cached2 = path27.join(
|
|
16614
16984
|
cacheDir,
|
|
16615
16985
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
16616
16986
|
);
|
|
16617
|
-
if (
|
|
16987
|
+
if (existsSync22(cached2) && await sha256File(cached2) === output.sha256) {
|
|
16618
16988
|
hasCache = true;
|
|
16619
16989
|
break;
|
|
16620
16990
|
}
|
|
16621
16991
|
}
|
|
16622
|
-
if (!hasSource && !hasCache) stranded.push(
|
|
16992
|
+
if (!hasSource && !hasCache) stranded.push(key2);
|
|
16623
16993
|
if (entry.generator === "map" && entry.submittedAt && now - Date.parse(entry.submittedAt) > 8 * 60 * 60 * 1e3) {
|
|
16624
|
-
staleMapUrls.push(
|
|
16994
|
+
staleMapUrls.push(key2);
|
|
16625
16995
|
}
|
|
16626
16996
|
}
|
|
16627
16997
|
add(
|
|
@@ -16710,16 +17080,16 @@ async function nearestExistingDirectory(start) {
|
|
|
16710
17080
|
if ((await stat2(current)).isDirectory()) return current;
|
|
16711
17081
|
} catch {
|
|
16712
17082
|
}
|
|
16713
|
-
const parent =
|
|
17083
|
+
const parent = path27.dirname(current);
|
|
16714
17084
|
if (parent === current) return current;
|
|
16715
17085
|
current = parent;
|
|
16716
17086
|
}
|
|
16717
17087
|
}
|
|
16718
17088
|
|
|
16719
17089
|
// src/pipeline/adopt.ts
|
|
16720
|
-
import { existsSync as
|
|
16721
|
-
import { readFile as
|
|
16722
|
-
import
|
|
17090
|
+
import { existsSync as existsSync23 } from "fs";
|
|
17091
|
+
import { readFile as readFile16, writeFile as writeFile9 } from "fs/promises";
|
|
17092
|
+
import path28 from "path";
|
|
16723
17093
|
async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
16724
17094
|
const log = opts.onProgress ?? (() => {
|
|
16725
17095
|
});
|
|
@@ -16730,11 +17100,11 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
16730
17100
|
const localByHash = /* @__PURE__ */ new Map();
|
|
16731
17101
|
const unmatchedLocal = [];
|
|
16732
17102
|
for (const spec of specs) {
|
|
16733
|
-
if (!
|
|
17103
|
+
if (!existsSync23(spec.outFile)) {
|
|
16734
17104
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
16735
17105
|
continue;
|
|
16736
17106
|
}
|
|
16737
|
-
const bytes = await
|
|
17107
|
+
const bytes = await readFile16(spec.outFile);
|
|
16738
17108
|
try {
|
|
16739
17109
|
decodePng(bytes);
|
|
16740
17110
|
} catch (err) {
|
|
@@ -16779,14 +17149,14 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
16779
17149
|
if (!hits?.length) continue;
|
|
16780
17150
|
matchedRemote.add(obj.id);
|
|
16781
17151
|
for (const spec of hits) {
|
|
16782
|
-
const
|
|
16783
|
-
const existing = lock.entries[
|
|
17152
|
+
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
17153
|
+
const existing = lock.entries[key2];
|
|
16784
17154
|
if (existing?.objectId && existing.objectId !== obj.id) {
|
|
16785
|
-
ambiguous.push(`${
|
|
17155
|
+
ambiguous.push(`${key2}: already mapped to ${existing.objectId}, also matches ${obj.id}`);
|
|
16786
17156
|
continue;
|
|
16787
17157
|
}
|
|
16788
17158
|
const durableSource = shouldPersistSourceUrl(url) ? url : null;
|
|
16789
|
-
upsert(lock,
|
|
17159
|
+
upsert(lock, key2, {
|
|
16790
17160
|
styleId: spec.styleId,
|
|
16791
17161
|
assetId: spec.assetId,
|
|
16792
17162
|
// Deliberately the CURRENT spec hash: adoption declares "the file on
|
|
@@ -16813,7 +17183,7 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
16813
17183
|
provider: provider.id
|
|
16814
17184
|
});
|
|
16815
17185
|
matched++;
|
|
16816
|
-
log(` adopted ${
|
|
17186
|
+
log(` adopted ${key2} \u2190 ${obj.id}`);
|
|
16817
17187
|
}
|
|
16818
17188
|
}
|
|
16819
17189
|
}
|
|
@@ -16837,23 +17207,23 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
16837
17207
|
});
|
|
16838
17208
|
const specByKey = new Map(specs.map((s) => [lockKey(s.styleId, s.assetId), s]));
|
|
16839
17209
|
let count = 0;
|
|
16840
|
-
for (const [
|
|
16841
|
-
const spec = specByKey.get(
|
|
17210
|
+
for (const [key2, entry] of Object.entries(lock.entries)) {
|
|
17211
|
+
const spec = specByKey.get(key2);
|
|
16842
17212
|
if (!spec || !entry.objectId) continue;
|
|
16843
17213
|
if (!provider.setTags) return count;
|
|
16844
17214
|
try {
|
|
16845
17215
|
await provider.setTags(entry.objectId, spec.tags, entry.generator);
|
|
16846
17216
|
count++;
|
|
16847
17217
|
} catch (err) {
|
|
16848
|
-
log(` tag failed ${
|
|
17218
|
+
log(` tag failed ${key2}: ${err instanceof Error ? err.message : String(err)}`);
|
|
16849
17219
|
}
|
|
16850
17220
|
}
|
|
16851
17221
|
return count;
|
|
16852
17222
|
}
|
|
16853
17223
|
|
|
16854
17224
|
// src/pipeline/import.ts
|
|
16855
|
-
import { existsSync as
|
|
16856
|
-
import { readFile as
|
|
17225
|
+
import { existsSync as existsSync24 } from "fs";
|
|
17226
|
+
import { readFile as readFile17 } from "fs/promises";
|
|
16857
17227
|
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
16858
17228
|
const png = decodePng(bytes);
|
|
16859
17229
|
const at = now.toISOString();
|
|
@@ -16879,6 +17249,7 @@ function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Da
|
|
|
16879
17249
|
cost: 0,
|
|
16880
17250
|
costUnit: spec.costUnit,
|
|
16881
17251
|
provider: spec.provider,
|
|
17252
|
+
...spec.external ? { external: { builder: spec.external.builder, inputs: spec.external.inputs } } : {},
|
|
16882
17253
|
imported: {
|
|
16883
17254
|
source: opts.source ?? "external",
|
|
16884
17255
|
...opts.note ? { note: opts.note } : {},
|
|
@@ -16899,32 +17270,32 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
16899
17270
|
const imported = [];
|
|
16900
17271
|
const skipped = [];
|
|
16901
17272
|
for (const spec of specs) {
|
|
16902
|
-
const
|
|
17273
|
+
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
16903
17274
|
const reason = unimportable(spec);
|
|
16904
17275
|
if (reason) {
|
|
16905
|
-
skipped.push({ key, reason });
|
|
17276
|
+
skipped.push({ key: key2, reason });
|
|
16906
17277
|
continue;
|
|
16907
17278
|
}
|
|
16908
|
-
if (!
|
|
16909
|
-
skipped.push({ key, reason: `no file at ${spec.outFile}` });
|
|
17279
|
+
if (!existsSync24(spec.outFile)) {
|
|
17280
|
+
skipped.push({ key: key2, reason: `no file at ${spec.outFile}` });
|
|
16910
17281
|
continue;
|
|
16911
17282
|
}
|
|
16912
|
-
if (lock.entries[
|
|
16913
|
-
skipped.push({ key, reason: "already in the lockfile (use --force to replace it)" });
|
|
17283
|
+
if (lock.entries[key2] && !opts.force) {
|
|
17284
|
+
skipped.push({ key: key2, reason: "already in the lockfile (use --force to replace it)" });
|
|
16914
17285
|
continue;
|
|
16915
17286
|
}
|
|
16916
17287
|
let patch;
|
|
16917
17288
|
try {
|
|
16918
|
-
patch = buildImportedEntry(spec, await
|
|
17289
|
+
patch = buildImportedEntry(spec, await readFile17(spec.outFile), opts);
|
|
16919
17290
|
} catch (error) {
|
|
16920
|
-
skipped.push({ key, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
17291
|
+
skipped.push({ key: key2, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
16921
17292
|
continue;
|
|
16922
17293
|
}
|
|
16923
17294
|
if (opts.dryRun) {
|
|
16924
|
-
imported.push({ key, entry: patch });
|
|
17295
|
+
imported.push({ key: key2, entry: patch });
|
|
16925
17296
|
continue;
|
|
16926
17297
|
}
|
|
16927
|
-
imported.push({ key, entry: upsert(lock,
|
|
17298
|
+
imported.push({ key: key2, entry: upsert(lock, key2, patch) });
|
|
16928
17299
|
}
|
|
16929
17300
|
if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
|
|
16930
17301
|
return { imported, skipped };
|
|
@@ -16932,9 +17303,9 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
16932
17303
|
async function reportSpecHashes(specs, lock) {
|
|
16933
17304
|
const reports = [];
|
|
16934
17305
|
for (const spec of specs) {
|
|
16935
|
-
const
|
|
17306
|
+
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
16936
17307
|
let bytes = null;
|
|
16937
|
-
if (
|
|
17308
|
+
if (existsSync24(spec.outFile)) bytes = await readFile17(spec.outFile);
|
|
16938
17309
|
let wouldImport = null;
|
|
16939
17310
|
if (bytes && !unimportable(spec)) {
|
|
16940
17311
|
try {
|
|
@@ -16943,11 +17314,11 @@ async function reportSpecHashes(specs, lock) {
|
|
|
16943
17314
|
wouldImport = null;
|
|
16944
17315
|
}
|
|
16945
17316
|
}
|
|
16946
|
-
const entry = lock.entries[
|
|
17317
|
+
const entry = lock.entries[key2];
|
|
16947
17318
|
const fileSha256 = bytes ? sha256(bytes) : null;
|
|
16948
17319
|
const outputSha256 = entry?.outputs[0]?.sha256 ?? null;
|
|
16949
17320
|
reports.push({
|
|
16950
|
-
key,
|
|
17321
|
+
key: key2,
|
|
16951
17322
|
specHash: spec.specHash,
|
|
16952
17323
|
file: spec.outFile,
|
|
16953
17324
|
fileSha256,
|
|
@@ -16963,13 +17334,13 @@ async function reportSpecHashes(specs, lock) {
|
|
|
16963
17334
|
}
|
|
16964
17335
|
|
|
16965
17336
|
// src/pick/server.ts
|
|
16966
|
-
import { existsSync as
|
|
16967
|
-
import { readFile as
|
|
17337
|
+
import { existsSync as existsSync26 } from "fs";
|
|
17338
|
+
import { readFile as readFile20 } from "fs/promises";
|
|
16968
17339
|
|
|
16969
17340
|
// src/pipeline/init.ts
|
|
16970
|
-
import { readdir as readdir3, readFile as
|
|
16971
|
-
import { existsSync as
|
|
16972
|
-
import
|
|
17341
|
+
import { readdir as readdir3, readFile as readFile18, writeFile as writeFile10 } from "fs/promises";
|
|
17342
|
+
import { existsSync as existsSync25 } from "fs";
|
|
17343
|
+
import path29 from "path";
|
|
16973
17344
|
function pngSize(buf) {
|
|
16974
17345
|
if (buf.length < 24) return null;
|
|
16975
17346
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -16983,7 +17354,7 @@ function slugify(value) {
|
|
|
16983
17354
|
async function walk(dir, exclude) {
|
|
16984
17355
|
const out = [];
|
|
16985
17356
|
for (const entry of await readdir3(dir, { withFileTypes: true })) {
|
|
16986
|
-
const full =
|
|
17357
|
+
const full = path29.join(dir, entry.name);
|
|
16987
17358
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
16988
17359
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
16989
17360
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -16997,14 +17368,14 @@ async function scanAssets(root, opts = {}) {
|
|
|
16997
17368
|
const skipped = [];
|
|
16998
17369
|
const seen = /* @__PURE__ */ new Map();
|
|
16999
17370
|
for (const file of files.sort()) {
|
|
17000
|
-
const size = pngSize(await
|
|
17371
|
+
const size = pngSize(await readFile18(file));
|
|
17001
17372
|
if (!size) {
|
|
17002
17373
|
skipped.push(`${file} (not a readable PNG)`);
|
|
17003
17374
|
continue;
|
|
17004
17375
|
}
|
|
17005
|
-
const rel =
|
|
17006
|
-
const category =
|
|
17007
|
-
let id = slugify(
|
|
17376
|
+
const rel = path29.relative(root, file);
|
|
17377
|
+
const category = path29.dirname(rel) === "." ? "" : path29.dirname(rel);
|
|
17378
|
+
let id = slugify(path29.basename(rel));
|
|
17008
17379
|
if (seen.has(id)) {
|
|
17009
17380
|
const n = seen.get(id) + 1;
|
|
17010
17381
|
seen.set(id, n);
|
|
@@ -17478,7 +17849,7 @@ document.getElementById('submit').onclick = async () => {
|
|
|
17478
17849
|
|
|
17479
17850
|
// src/pick/review-server.ts
|
|
17480
17851
|
import { createServer } from "http";
|
|
17481
|
-
import { readFile as
|
|
17852
|
+
import { readFile as readFile19 } from "fs/promises";
|
|
17482
17853
|
function serveReviewPage(opts) {
|
|
17483
17854
|
const log = opts.onProgress ?? (() => {
|
|
17484
17855
|
});
|
|
@@ -17487,7 +17858,7 @@ function serveReviewPage(opts) {
|
|
|
17487
17858
|
if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
|
|
17488
17859
|
try {
|
|
17489
17860
|
const asset = opts.assets.get(req.url);
|
|
17490
|
-
const bytes = await
|
|
17861
|
+
const bytes = await readFile19(asset.path);
|
|
17491
17862
|
res.writeHead(200, {
|
|
17492
17863
|
"Content-Type": asset.contentType,
|
|
17493
17864
|
"Cache-Control": "no-store",
|
|
@@ -17563,13 +17934,13 @@ async function currentArt(entry, spec) {
|
|
|
17563
17934
|
const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
|
|
17564
17935
|
if (!previous) return null;
|
|
17565
17936
|
const file = resolveOutputPath(previous.path, spec.root);
|
|
17566
|
-
if (!
|
|
17937
|
+
if (!existsSync26(file)) return null;
|
|
17567
17938
|
const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
|
|
17568
17939
|
if (!contentType) return null;
|
|
17569
17940
|
let width = entry.width;
|
|
17570
17941
|
let height = entry.height;
|
|
17571
17942
|
if (contentType === "image/png") {
|
|
17572
|
-
const size = pngSize(await
|
|
17943
|
+
const size = pngSize(await readFile20(file));
|
|
17573
17944
|
if (size) ({ width, height } = size);
|
|
17574
17945
|
}
|
|
17575
17946
|
return { path: file, contentType, width, height };
|
|
@@ -17577,7 +17948,7 @@ async function currentArt(entry, spec) {
|
|
|
17577
17948
|
async function cachedFrame(url) {
|
|
17578
17949
|
if (!url.startsWith("file://")) return null;
|
|
17579
17950
|
const file = url.slice("file://".length);
|
|
17580
|
-
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await
|
|
17951
|
+
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await readFile20(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
|
|
17581
17952
|
return { path: file, contentType };
|
|
17582
17953
|
}
|
|
17583
17954
|
async function prepareReview(provider, lock, opts = {}) {
|
|
@@ -17591,11 +17962,11 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17591
17962
|
const prefix = opts.routePrefix ?? "";
|
|
17592
17963
|
const providerUrls = /* @__PURE__ */ new Map();
|
|
17593
17964
|
const groups = [];
|
|
17594
|
-
for (const [
|
|
17595
|
-
if (entry.provider !== provider.id || selectedKeys && !selectedKeys.has(
|
|
17965
|
+
for (const [key2, entry] of Object.entries(lock.entries)) {
|
|
17966
|
+
if (entry.provider !== provider.id || selectedKeys && !selectedKeys.has(key2)) continue;
|
|
17596
17967
|
if (entry.status !== "review" || !entry.reviewObjectId) continue;
|
|
17597
17968
|
try {
|
|
17598
|
-
const spec = specByKey.get(
|
|
17969
|
+
const spec = specByKey.get(key2);
|
|
17599
17970
|
const state = await provider.poll(entry.reviewObjectId, entry.generator, { spec, metadata: entry.providerMetadata?.[provider.id] });
|
|
17600
17971
|
if (state.status !== "review" && state.status !== "review-set" || (state.status === "review" ? !state.candidateUrls.length : !state.frameUrls.length)) continue;
|
|
17601
17972
|
const urls = state.status === "review" ? state.candidateUrls : state.frameUrls;
|
|
@@ -17609,7 +17980,7 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17609
17980
|
frameSizes.push(null);
|
|
17610
17981
|
continue;
|
|
17611
17982
|
}
|
|
17612
|
-
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await
|
|
17983
|
+
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await readFile20(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
17613
17984
|
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
17614
17985
|
frameAssets.push([route, cached2]);
|
|
17615
17986
|
frameUrls.push(route);
|
|
@@ -17627,9 +17998,9 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17627
17998
|
reviewAssets.set(currentRoute, { path: current.path, contentType: current.contentType });
|
|
17628
17999
|
}
|
|
17629
18000
|
for (const [route, asset] of frameAssets) reviewAssets.set(route, asset);
|
|
17630
|
-
providerUrls.set(
|
|
18001
|
+
providerUrls.set(key2, urls);
|
|
17631
18002
|
groups.push({
|
|
17632
|
-
key,
|
|
18003
|
+
key: key2,
|
|
17633
18004
|
assetId: entry.assetId,
|
|
17634
18005
|
styleId: entry.styleId,
|
|
17635
18006
|
prompt: entry.prompt,
|
|
@@ -17659,7 +18030,7 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17659
18030
|
...entry.batch?.index != null ? { recommendedIndex: entry.batch.index } : {}
|
|
17660
18031
|
});
|
|
17661
18032
|
} catch (err) {
|
|
17662
|
-
log(` could not load candidates for ${
|
|
18033
|
+
log(` could not load candidates for ${key2}: ${err instanceof Error ? err.message : String(err)}`);
|
|
17663
18034
|
}
|
|
17664
18035
|
}
|
|
17665
18036
|
if (groups.length === 0) return null;
|
|
@@ -17671,18 +18042,18 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17671
18042
|
apply: async (body, lockPath) => {
|
|
17672
18043
|
const { selections } = body;
|
|
17673
18044
|
let selected = 0;
|
|
17674
|
-
for (const { key, index } of selections) {
|
|
17675
|
-
const group = byKey.get(
|
|
17676
|
-
const entry = lock.entries[
|
|
18045
|
+
for (const { key: key2, index } of selections) {
|
|
18046
|
+
const group = byKey.get(key2);
|
|
18047
|
+
const entry = lock.entries[key2];
|
|
17677
18048
|
if (!group || !entry?.reviewObjectId) continue;
|
|
17678
18049
|
if (!Number.isInteger(index) || index < 0 || index >= group.frameUrls.length) continue;
|
|
17679
18050
|
if (group.mode === "frame-set") {
|
|
17680
|
-
const spec = specByKey.get(
|
|
18051
|
+
const spec = specByKey.get(key2);
|
|
17681
18052
|
const state = await provider.poll(entry.reviewObjectId, entry.generator, { spec, metadata: entry.providerMetadata?.[provider.id] });
|
|
17682
18053
|
if (state.status !== "review-set") {
|
|
17683
|
-
throw new Error(`Frame set ${
|
|
18054
|
+
throw new Error(`Frame set ${key2} is no longer ready for review`);
|
|
17684
18055
|
}
|
|
17685
|
-
upsert(lock,
|
|
18056
|
+
upsert(lock, key2, {
|
|
17686
18057
|
status: "selected",
|
|
17687
18058
|
objectId: state.objectId,
|
|
17688
18059
|
candidateIndex: null,
|
|
@@ -17698,7 +18069,7 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17698
18069
|
} : entry.providerMetadata
|
|
17699
18070
|
});
|
|
17700
18071
|
selected++;
|
|
17701
|
-
log(` accepted ${
|
|
18072
|
+
log(` accepted ${key2} \u2192 ${state.sources.length} ordered frames`);
|
|
17702
18073
|
continue;
|
|
17703
18074
|
}
|
|
17704
18075
|
const { objectId, sourceUrl, metadata } = await requireSelectCandidate(provider)(
|
|
@@ -17707,11 +18078,11 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17707
18078
|
`asset:${entry.assetId}`,
|
|
17708
18079
|
entry.generator
|
|
17709
18080
|
);
|
|
17710
|
-
upsert(lock,
|
|
18081
|
+
upsert(lock, key2, {
|
|
17711
18082
|
status: "selected",
|
|
17712
18083
|
objectId,
|
|
17713
18084
|
candidateIndex: index,
|
|
17714
|
-
sourceUrl: sourceUrl ?? providerUrls.get(
|
|
18085
|
+
sourceUrl: sourceUrl ?? providerUrls.get(key2)?.[index] ?? null,
|
|
17715
18086
|
sourceUrls: [],
|
|
17716
18087
|
provider: provider.id,
|
|
17717
18088
|
providerMetadata: metadata ? {
|
|
@@ -17723,7 +18094,7 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17723
18094
|
} : entry.providerMetadata
|
|
17724
18095
|
});
|
|
17725
18096
|
selected++;
|
|
17726
|
-
log(` picked ${
|
|
18097
|
+
log(` picked ${key2} \u2192 candidate ${index + 1}`);
|
|
17727
18098
|
}
|
|
17728
18099
|
await saveLock(lockPath, lock);
|
|
17729
18100
|
return { selected, skipped: groups.length - selected };
|
|
@@ -17763,14 +18134,14 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
17763
18134
|
|
|
17764
18135
|
// src/gallery/snapshot.ts
|
|
17765
18136
|
import { createHash as createHash5 } from "crypto";
|
|
17766
|
-
import { existsSync as
|
|
17767
|
-
import { readFile as
|
|
17768
|
-
import
|
|
18137
|
+
import { existsSync as existsSync32 } from "fs";
|
|
18138
|
+
import { readFile as readFile27, stat as stat3 } from "fs/promises";
|
|
18139
|
+
import path37 from "path";
|
|
17769
18140
|
|
|
17770
18141
|
// src/workspace.ts
|
|
17771
|
-
import { mkdir as
|
|
17772
|
-
import { existsSync as
|
|
17773
|
-
import
|
|
18142
|
+
import { mkdir as mkdir9, readFile as readFile21, rename as rename7, rm as rm7, writeFile as writeFile11 } from "fs/promises";
|
|
18143
|
+
import { existsSync as existsSync27 } from "fs";
|
|
18144
|
+
import path30 from "path";
|
|
17774
18145
|
import { z as z7 } from "zod";
|
|
17775
18146
|
var WorkspaceProjectSchema = z7.object({
|
|
17776
18147
|
id: z7.string().min(1),
|
|
@@ -17795,10 +18166,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
|
|
|
17795
18166
|
);
|
|
17796
18167
|
}
|
|
17797
18168
|
async function loadWorkspace(workspacePath) {
|
|
17798
|
-
if (!
|
|
18169
|
+
if (!existsSync27(workspacePath)) return { version: 1, projects: [] };
|
|
17799
18170
|
let raw;
|
|
17800
18171
|
try {
|
|
17801
|
-
raw = JSON.parse(await
|
|
18172
|
+
raw = JSON.parse(await readFile21(workspacePath, "utf8"));
|
|
17802
18173
|
} catch (err) {
|
|
17803
18174
|
throw new ProjectError(
|
|
17804
18175
|
`Workspace catalog at ${workspacePath} is malformed:
|
|
@@ -17812,22 +18183,22 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
17812
18183
|
version: 1,
|
|
17813
18184
|
projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
|
|
17814
18185
|
};
|
|
17815
|
-
await
|
|
18186
|
+
await mkdir9(path30.dirname(path30.resolve(workspacePath)), { recursive: true });
|
|
17816
18187
|
const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
17817
18188
|
try {
|
|
17818
|
-
await
|
|
17819
|
-
await
|
|
18189
|
+
await writeFile11(tmp, JSON.stringify(sorted, null, 2) + "\n");
|
|
18190
|
+
await rename7(tmp, workspacePath);
|
|
17820
18191
|
} finally {
|
|
17821
18192
|
await rm7(tmp, { force: true });
|
|
17822
18193
|
}
|
|
17823
18194
|
}
|
|
17824
18195
|
function toPortablePath(dir, absolute) {
|
|
17825
|
-
return
|
|
18196
|
+
return path30.relative(dir, absolute).split(path30.sep).join("/");
|
|
17826
18197
|
}
|
|
17827
18198
|
function resolveProject(dir, project) {
|
|
17828
18199
|
return {
|
|
17829
|
-
manifestPath:
|
|
17830
|
-
lockPath:
|
|
18200
|
+
manifestPath: path30.resolve(dir, project.manifest.split("/").join(path30.sep)),
|
|
18201
|
+
lockPath: path30.resolve(dir, project.lock.split("/").join(path30.sep))
|
|
17831
18202
|
};
|
|
17832
18203
|
}
|
|
17833
18204
|
function validateWorkspace(ws, dir) {
|
|
@@ -17840,21 +18211,21 @@ function validateWorkspace(ws, dir) {
|
|
|
17840
18211
|
const { manifestPath, lockPath } = resolveProject(dir, project);
|
|
17841
18212
|
lockOwners.set(lockPath, [...lockOwners.get(lockPath) ?? [], project.id]);
|
|
17842
18213
|
manifestOwners.set(manifestPath, [...manifestOwners.get(manifestPath) ?? [], project.id]);
|
|
17843
|
-
if (
|
|
18214
|
+
if (path30.isAbsolute(project.manifest) || path30.isAbsolute(project.lock)) {
|
|
17844
18215
|
diagnostics.push({
|
|
17845
18216
|
id: "absolute-path",
|
|
17846
18217
|
level: "warning",
|
|
17847
18218
|
message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
|
|
17848
18219
|
});
|
|
17849
18220
|
}
|
|
17850
|
-
if (!
|
|
18221
|
+
if (!existsSync27(manifestPath)) {
|
|
17851
18222
|
diagnostics.push({
|
|
17852
18223
|
id: "missing-manifest",
|
|
17853
18224
|
level: "error",
|
|
17854
18225
|
message: `project "${project.id}" manifest not found: ${manifestPath}`
|
|
17855
18226
|
});
|
|
17856
18227
|
}
|
|
17857
|
-
if (!
|
|
18228
|
+
if (!existsSync27(lockPath)) {
|
|
17858
18229
|
diagnostics.push({
|
|
17859
18230
|
id: "missing-lock",
|
|
17860
18231
|
level: "error",
|
|
@@ -17901,16 +18272,16 @@ function validateWorkspace(ws, dir) {
|
|
|
17901
18272
|
}
|
|
17902
18273
|
|
|
17903
18274
|
// src/gallery/edit.ts
|
|
17904
|
-
import { readFile as
|
|
17905
|
-
import
|
|
18275
|
+
import { readFile as readFile26, rename as rename10, writeFile as writeFile17 } from "fs/promises";
|
|
18276
|
+
import path36 from "path";
|
|
17906
18277
|
import { z as z13 } from "zod";
|
|
17907
18278
|
|
|
17908
18279
|
// src/manifest-edit.ts
|
|
17909
|
-
import { readFile as
|
|
17910
|
-
import
|
|
18280
|
+
import { readFile as readFile22, rename as rename8, rm as rm8, writeFile as writeFile12 } from "fs/promises";
|
|
18281
|
+
import path31 from "path";
|
|
17911
18282
|
import { z as z8 } from "zod";
|
|
17912
18283
|
var HexSha = z8.string().regex(/^[0-9a-f]{64}$/);
|
|
17913
|
-
var ProjectFileSchema = z8.string().min(1).refine((file) => !
|
|
18284
|
+
var ProjectFileSchema = z8.string().min(1).refine((file) => !path31.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
|
|
17914
18285
|
var AssetPatchSchema = z8.object({
|
|
17915
18286
|
prompt: z8.string().optional(),
|
|
17916
18287
|
/** Per-style override for the style being viewed; null removes it. */
|
|
@@ -18177,9 +18548,9 @@ function styleProvider(raw, styleId, seen = /* @__PURE__ */ new Set()) {
|
|
|
18177
18548
|
seen.add(styleId);
|
|
18178
18549
|
return style.extends ? styleProvider(raw, style.extends, seen) : raw.provider ?? "pixellab";
|
|
18179
18550
|
}
|
|
18180
|
-
function setOrDelete(target,
|
|
18181
|
-
if (value === null || value === void 0) delete target[
|
|
18182
|
-
else target[
|
|
18551
|
+
function setOrDelete(target, key2, value) {
|
|
18552
|
+
if (value === null || value === void 0) delete target[key2];
|
|
18553
|
+
else target[key2] = value;
|
|
18183
18554
|
}
|
|
18184
18555
|
function assetStyles(raw, asset) {
|
|
18185
18556
|
const own = Array.isArray(asset.styles) ? asset.styles : [];
|
|
@@ -18330,8 +18701,8 @@ function applyEdit(raw, edit) {
|
|
|
18330
18701
|
}
|
|
18331
18702
|
}
|
|
18332
18703
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
18333
|
-
const absolute =
|
|
18334
|
-
const original = await
|
|
18704
|
+
const absolute = path31.resolve(manifestPath);
|
|
18705
|
+
const original = await readFile22(absolute, "utf8");
|
|
18335
18706
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
18336
18707
|
let raw;
|
|
18337
18708
|
try {
|
|
@@ -18344,12 +18715,12 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
18344
18715
|
applyEdit(raw, edit);
|
|
18345
18716
|
const next = serializeLike(original, raw);
|
|
18346
18717
|
if (next === original) return unchanged(absolute, original);
|
|
18347
|
-
const tmp =
|
|
18348
|
-
|
|
18349
|
-
`.${
|
|
18718
|
+
const tmp = path31.join(
|
|
18719
|
+
path31.dirname(absolute),
|
|
18720
|
+
`.${path31.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
|
|
18350
18721
|
);
|
|
18351
18722
|
try {
|
|
18352
|
-
await
|
|
18723
|
+
await writeFile12(tmp, next);
|
|
18353
18724
|
let specs;
|
|
18354
18725
|
try {
|
|
18355
18726
|
specs = await resolveSpecs(await loadManifest(tmp));
|
|
@@ -18367,7 +18738,7 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
18367
18738
|
manifestPath,
|
|
18368
18739
|
edit,
|
|
18369
18740
|
async ({ absolute, next, tmp }) => {
|
|
18370
|
-
await
|
|
18741
|
+
await rename8(tmp, absolute);
|
|
18371
18742
|
return { manifestPath: absolute, sha256: sha256(next), changed: true };
|
|
18372
18743
|
},
|
|
18373
18744
|
(absolute, original) => ({ manifestPath: absolute, sha256: sha256(original), changed: false })
|
|
@@ -18375,18 +18746,18 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
18375
18746
|
}
|
|
18376
18747
|
|
|
18377
18748
|
// src/pipeline/hand-edit.ts
|
|
18378
|
-
import { existsSync as
|
|
18379
|
-
import { copyFile, mkdir as
|
|
18380
|
-
import
|
|
18749
|
+
import { existsSync as existsSync28 } from "fs";
|
|
18750
|
+
import { copyFile, mkdir as mkdir10, readFile as readFile23, rename as rename9, rm as rm9, writeFile as writeFile13 } from "fs/promises";
|
|
18751
|
+
import path32 from "path";
|
|
18381
18752
|
import { z as z9 } from "zod";
|
|
18382
18753
|
var HAND_EDIT_DIR = "edits";
|
|
18383
18754
|
function handEditPath(loaded, spec) {
|
|
18384
18755
|
const style = loaded.manifest.styles[spec.styleId];
|
|
18385
|
-
const outDir =
|
|
18386
|
-
const relative =
|
|
18387
|
-
const inside = relative && !relative.startsWith("..") && !
|
|
18388
|
-
const file = inside ? relative :
|
|
18389
|
-
return
|
|
18756
|
+
const outDir = path32.resolve(loaded.root, style?.outDir ?? ".");
|
|
18757
|
+
const relative = path32.relative(outDir, spec.outFile);
|
|
18758
|
+
const inside = relative && !relative.startsWith("..") && !path32.isAbsolute(relative);
|
|
18759
|
+
const file = inside ? relative : path32.basename(spec.outFile);
|
|
18760
|
+
return path32.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
|
|
18390
18761
|
}
|
|
18391
18762
|
function handEditBases(spec, lock) {
|
|
18392
18763
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -18399,10 +18770,10 @@ function handEditBases(spec, lock) {
|
|
|
18399
18770
|
}));
|
|
18400
18771
|
if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
|
|
18401
18772
|
if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
|
|
18402
|
-
if (!members.every((member) =>
|
|
18773
|
+
if (!members.every((member) => existsSync28(member.path))) return null;
|
|
18403
18774
|
return members.map(({ role, path: file }) => ({ role, path: file }));
|
|
18404
18775
|
}
|
|
18405
|
-
return
|
|
18776
|
+
return existsSync28(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
|
|
18406
18777
|
}
|
|
18407
18778
|
function handEditBase(spec, lock) {
|
|
18408
18779
|
const bases = handEditBases(spec, lock);
|
|
@@ -18432,18 +18803,18 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
18432
18803
|
`${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`
|
|
18433
18804
|
);
|
|
18434
18805
|
}
|
|
18435
|
-
const existing = spec.source ?
|
|
18806
|
+
const existing = spec.source ? path32.resolve(loaded.root, spec.source) : null;
|
|
18436
18807
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
18437
18808
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
18438
18809
|
let created = false;
|
|
18439
18810
|
for (const member of members) {
|
|
18440
|
-
if (
|
|
18811
|
+
if (existsSync28(member.path)) continue;
|
|
18441
18812
|
if (!member.base) {
|
|
18442
18813
|
throw new ManifestEditError(
|
|
18443
18814
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
18444
18815
|
);
|
|
18445
18816
|
}
|
|
18446
|
-
await
|
|
18817
|
+
await mkdir10(path32.dirname(member.path), { recursive: true });
|
|
18447
18818
|
await copyFile(member.base, member.path);
|
|
18448
18819
|
created = true;
|
|
18449
18820
|
}
|
|
@@ -18522,7 +18893,7 @@ function handEditProjectPath(editPath) {
|
|
|
18522
18893
|
async function readHandEditCompanion(editPath) {
|
|
18523
18894
|
let text;
|
|
18524
18895
|
try {
|
|
18525
|
-
text = await
|
|
18896
|
+
text = await readFile23(handEditCompanionPath(editPath), "utf8");
|
|
18526
18897
|
} catch {
|
|
18527
18898
|
return null;
|
|
18528
18899
|
}
|
|
@@ -18565,7 +18936,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
18565
18936
|
}
|
|
18566
18937
|
});
|
|
18567
18938
|
const bases = handEditBases(spec, lock);
|
|
18568
|
-
const expectedSize = bases?.[0] ? decodePng(await
|
|
18939
|
+
const expectedSize = bases?.[0] ? decodePng(await readFile23(bases[0].path)) : { width: spec.width, height: spec.height };
|
|
18569
18940
|
for (const [index, image] of decoded.entries()) {
|
|
18570
18941
|
if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
|
|
18571
18942
|
const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
|
|
@@ -18581,7 +18952,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
18581
18952
|
editor: input.editor,
|
|
18582
18953
|
protocol: input.protocol,
|
|
18583
18954
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
18584
|
-
project: projectPath ?
|
|
18955
|
+
project: projectPath ? path32.basename(projectPath) : null,
|
|
18585
18956
|
outputs: incoming.map((frame, index) => ({
|
|
18586
18957
|
role: frame.role,
|
|
18587
18958
|
basedOn: basedOnHash(entry, index),
|
|
@@ -18611,8 +18982,8 @@ function basedOnHash(entry, index) {
|
|
|
18611
18982
|
async function replaceFile(file, bytes) {
|
|
18612
18983
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18613
18984
|
try {
|
|
18614
|
-
await
|
|
18615
|
-
await
|
|
18985
|
+
await writeFile13(tmp, bytes);
|
|
18986
|
+
await rename9(tmp, file);
|
|
18616
18987
|
} finally {
|
|
18617
18988
|
await rm9(tmp, { force: true });
|
|
18618
18989
|
}
|
|
@@ -18623,9 +18994,9 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
18623
18994
|
}
|
|
18624
18995
|
|
|
18625
18996
|
// src/gallery/upload.ts
|
|
18626
|
-
import { existsSync as
|
|
18627
|
-
import { mkdir as
|
|
18628
|
-
import
|
|
18997
|
+
import { existsSync as existsSync29 } from "fs";
|
|
18998
|
+
import { mkdir as mkdir11, writeFile as writeFile14 } from "fs/promises";
|
|
18999
|
+
import path33 from "path";
|
|
18629
19000
|
import { z as z10 } from "zod";
|
|
18630
19001
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
18631
19002
|
var UploadImageSchema = z10.object({
|
|
@@ -18638,12 +19009,12 @@ var UploadImageSchema = z10.object({
|
|
|
18638
19009
|
overwrite: z10.boolean().optional()
|
|
18639
19010
|
}).strict();
|
|
18640
19011
|
async function saveProjectImage(root, request) {
|
|
18641
|
-
const file =
|
|
18642
|
-
const relative =
|
|
18643
|
-
if (relative.startsWith("..") ||
|
|
19012
|
+
const file = path33.resolve(root, request.path);
|
|
19013
|
+
const relative = path33.relative(root, file);
|
|
19014
|
+
if (relative.startsWith("..") || path33.isAbsolute(relative)) {
|
|
18644
19015
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
18645
19016
|
}
|
|
18646
|
-
const extension =
|
|
19017
|
+
const extension = path33.extname(file).toLowerCase();
|
|
18647
19018
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
18648
19019
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
18649
19020
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -18655,18 +19026,18 @@ async function saveProjectImage(root, request) {
|
|
|
18655
19026
|
if (metadata.format !== expected) {
|
|
18656
19027
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
18657
19028
|
}
|
|
18658
|
-
if (
|
|
18659
|
-
throw new ManifestEditError(`${relative.split(
|
|
19029
|
+
if (existsSync29(file) && !request.overwrite) {
|
|
19030
|
+
throw new ManifestEditError(`${relative.split(path33.sep).join("/")} already exists; choose another name, or replace it`);
|
|
18660
19031
|
}
|
|
18661
|
-
await
|
|
18662
|
-
await
|
|
18663
|
-
return relative.split(
|
|
19032
|
+
await mkdir11(path33.dirname(file), { recursive: true });
|
|
19033
|
+
await writeFile14(file, bytes);
|
|
19034
|
+
return relative.split(path33.sep).join("/");
|
|
18664
19035
|
}
|
|
18665
19036
|
|
|
18666
19037
|
// src/gallery/image-revision.ts
|
|
18667
|
-
import { existsSync as
|
|
18668
|
-
import { readFile as
|
|
18669
|
-
import
|
|
19038
|
+
import { existsSync as existsSync30 } from "fs";
|
|
19039
|
+
import { readFile as readFile24, rm as rm10, writeFile as writeFile15 } from "fs/promises";
|
|
19040
|
+
import path34 from "path";
|
|
18670
19041
|
import { z as z11 } from "zod";
|
|
18671
19042
|
var InpaintRevisionRequestSchema = z11.object({
|
|
18672
19043
|
action: z11.literal("create-inpaint-revision"),
|
|
@@ -18685,15 +19056,15 @@ var InpaintRevisionRequestSchema = z11.object({
|
|
|
18685
19056
|
overwrite: z11.boolean().optional()
|
|
18686
19057
|
}).strict();
|
|
18687
19058
|
async function createInpaintRevision(manifestPath, request) {
|
|
18688
|
-
const root =
|
|
18689
|
-
if (
|
|
19059
|
+
const root = path34.dirname(path34.resolve(manifestPath));
|
|
19060
|
+
if (path34.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
18690
19061
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
18691
19062
|
}
|
|
18692
19063
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
18693
19064
|
const metadata = imageMetadata(bytes);
|
|
18694
19065
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
18695
|
-
const file =
|
|
18696
|
-
const previous =
|
|
19066
|
+
const file = path34.resolve(root, request.maskPath);
|
|
19067
|
+
const previous = existsSync30(file) ? await readFile24(file) : null;
|
|
18697
19068
|
const mask = await saveProjectImage(root, {
|
|
18698
19069
|
action: "upload-image",
|
|
18699
19070
|
path: request.maskPath,
|
|
@@ -18712,7 +19083,7 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
18712
19083
|
}
|
|
18713
19084
|
});
|
|
18714
19085
|
} catch (error) {
|
|
18715
|
-
if (previous) await
|
|
19086
|
+
if (previous) await writeFile15(file, previous);
|
|
18716
19087
|
else await rm10(file, { force: true });
|
|
18717
19088
|
throw error;
|
|
18718
19089
|
}
|
|
@@ -18720,9 +19091,9 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
18720
19091
|
}
|
|
18721
19092
|
|
|
18722
19093
|
// src/gallery/skeleton.ts
|
|
18723
|
-
import { existsSync as
|
|
18724
|
-
import { mkdir as
|
|
18725
|
-
import
|
|
19094
|
+
import { existsSync as existsSync31 } from "fs";
|
|
19095
|
+
import { mkdir as mkdir12, readFile as readFile25, rm as rm11, writeFile as writeFile16 } from "fs/promises";
|
|
19096
|
+
import path35 from "path";
|
|
18726
19097
|
import { z as z12 } from "zod";
|
|
18727
19098
|
var SkeletonEstimateRequestSchema = z12.object({
|
|
18728
19099
|
project: z12.string().min(1).optional(),
|
|
@@ -18761,21 +19132,21 @@ var SkeletonKeypointsUpdateSchema = z12.object({
|
|
|
18761
19132
|
set: SkeletonSetSchema
|
|
18762
19133
|
}).strict();
|
|
18763
19134
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
18764
|
-
const root =
|
|
18765
|
-
const file =
|
|
18766
|
-
const relative =
|
|
18767
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
19135
|
+
const root = path35.dirname(path35.resolve(manifestPath));
|
|
19136
|
+
const file = path35.resolve(root, request.keypointsFile);
|
|
19137
|
+
const relative = path35.relative(root, file);
|
|
19138
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path35.isAbsolute(relative)) {
|
|
18768
19139
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
18769
19140
|
}
|
|
18770
|
-
const existed =
|
|
19141
|
+
const existed = existsSync31(file);
|
|
18771
19142
|
let previous = null;
|
|
18772
19143
|
if (request.set) {
|
|
18773
19144
|
if (existed && !request.overwrite) {
|
|
18774
19145
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
18775
19146
|
}
|
|
18776
|
-
if (existed) previous = await
|
|
18777
|
-
await
|
|
18778
|
-
await
|
|
19147
|
+
if (existed) previous = await readFile25(file);
|
|
19148
|
+
await mkdir12(path35.dirname(file), { recursive: true });
|
|
19149
|
+
await writeFile16(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18779
19150
|
} else if (!existed) {
|
|
18780
19151
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
18781
19152
|
}
|
|
@@ -18790,7 +19161,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
18790
19161
|
revision: {
|
|
18791
19162
|
mode: "animate-skeleton",
|
|
18792
19163
|
from: request.from,
|
|
18793
|
-
keypointsFile: relative.split(
|
|
19164
|
+
keypointsFile: relative.split(path35.sep).join("/"),
|
|
18794
19165
|
direction: request.direction,
|
|
18795
19166
|
description: request.description,
|
|
18796
19167
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -18799,31 +19170,31 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
18799
19170
|
});
|
|
18800
19171
|
} catch (error) {
|
|
18801
19172
|
if (request.set) {
|
|
18802
|
-
if (previous) await
|
|
19173
|
+
if (previous) await writeFile16(file, previous);
|
|
18803
19174
|
else await rm11(file, { force: true });
|
|
18804
19175
|
}
|
|
18805
19176
|
throw error;
|
|
18806
19177
|
}
|
|
18807
19178
|
}
|
|
18808
19179
|
async function updateSkeletonKeypoints(ctx, request) {
|
|
18809
|
-
const
|
|
18810
|
-
const spec = ctx.specs.find((candidate) => lockKey(candidate.styleId, candidate.assetId) ===
|
|
18811
|
-
if (!spec) throw new ManifestEditError(`"${
|
|
19180
|
+
const key2 = lockKey(request.styleId, request.assetId);
|
|
19181
|
+
const spec = ctx.specs.find((candidate) => lockKey(candidate.styleId, candidate.assetId) === key2);
|
|
19182
|
+
if (!spec) throw new ManifestEditError(`"${key2}" is not declared by the manifest`);
|
|
18812
19183
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
18813
|
-
if (!file) throw new ManifestEditError(`${
|
|
18814
|
-
const relative =
|
|
18815
|
-
if (relative.startsWith("..") ||
|
|
18816
|
-
throw new ManifestEditError(`${
|
|
19184
|
+
if (!file) throw new ManifestEditError(`${key2} is not an animate-skeleton revision`);
|
|
19185
|
+
const relative = path35.relative(ctx.loaded.root, file);
|
|
19186
|
+
if (relative.startsWith("..") || path35.isAbsolute(relative)) {
|
|
19187
|
+
throw new ManifestEditError(`${key2}'s keypoints file is outside the project; edit it by hand`);
|
|
18817
19188
|
}
|
|
18818
|
-
const current =
|
|
19189
|
+
const current = existsSync31(file) ? sha256(await readFile25(file)) : null;
|
|
18819
19190
|
if (current !== request.expectedSha256) {
|
|
18820
19191
|
throw Object.assign(
|
|
18821
|
-
new Error(`${relative.split(
|
|
19192
|
+
new Error(`${relative.split(path35.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
18822
19193
|
{ status: 409 }
|
|
18823
19194
|
);
|
|
18824
19195
|
}
|
|
18825
|
-
await
|
|
18826
|
-
return relative.split(
|
|
19196
|
+
await writeFile16(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
19197
|
+
return relative.split(path35.sep).join("/");
|
|
18827
19198
|
}
|
|
18828
19199
|
|
|
18829
19200
|
// src/gallery/edit.ts
|
|
@@ -18877,7 +19248,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18877
19248
|
const history = /* @__PURE__ */ new Map();
|
|
18878
19249
|
const manifestOf = async (project) => {
|
|
18879
19250
|
try {
|
|
18880
|
-
return
|
|
19251
|
+
return path36.resolve(await opts.manifestFor(typeof project === "string" ? project : void 0));
|
|
18881
19252
|
} catch {
|
|
18882
19253
|
return null;
|
|
18883
19254
|
}
|
|
@@ -18887,7 +19258,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18887
19258
|
if (undo.success) {
|
|
18888
19259
|
const manifestPath2 = await manifestOf(undo.data.project);
|
|
18889
19260
|
if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
|
|
18890
|
-
const current = await
|
|
19261
|
+
const current = await readFile26(manifestPath2, "utf8");
|
|
18891
19262
|
if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
|
|
18892
19263
|
const stack = history.get(manifestPath2) ?? [];
|
|
18893
19264
|
const last = stack[stack.length - 1];
|
|
@@ -18897,17 +19268,17 @@ function createGalleryEditHandler(opts) {
|
|
|
18897
19268
|
throw Object.assign(new Error("the manifest changed outside the gallery since its last edit; undo would discard that change"), { status: 409 });
|
|
18898
19269
|
}
|
|
18899
19270
|
const tmp = manifestPath2 + ".pixelkiln-undo";
|
|
18900
|
-
await
|
|
18901
|
-
await
|
|
19271
|
+
await writeFile17(tmp, last.before);
|
|
19272
|
+
await rename10(tmp, manifestPath2);
|
|
18902
19273
|
stack.pop();
|
|
18903
|
-
log(` manifest edit undone in ${
|
|
19274
|
+
log(` manifest edit undone in ${path36.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
18904
19275
|
return opts.reload();
|
|
18905
19276
|
}
|
|
18906
19277
|
const manifestPath = await manifestOf(body?.project);
|
|
18907
|
-
const before = manifestPath ? await
|
|
19278
|
+
const before = manifestPath ? await readFile26(manifestPath, "utf8").catch(() => null) : null;
|
|
18908
19279
|
const build = await apply(body);
|
|
18909
19280
|
if (manifestPath && before !== null) {
|
|
18910
|
-
const after = await
|
|
19281
|
+
const after = await readFile26(manifestPath, "utf8").catch(() => null);
|
|
18911
19282
|
if (after !== null && after !== before) {
|
|
18912
19283
|
const stack = history.get(manifestPath) ?? [];
|
|
18913
19284
|
stack.push({ before, afterSha: sha256(after) });
|
|
@@ -18962,7 +19333,7 @@ function createEditApplier(opts, log) {
|
|
|
18962
19333
|
} catch (error) {
|
|
18963
19334
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
18964
19335
|
}
|
|
18965
|
-
const written = await saveProjectImage(
|
|
19336
|
+
const written = await saveProjectImage(path36.dirname(path36.resolve(manifestPath2)), upload.data);
|
|
18966
19337
|
log(` image added: ${written}`);
|
|
18967
19338
|
return opts.reload();
|
|
18968
19339
|
}
|
|
@@ -19029,7 +19400,7 @@ function createEditApplier(opts, log) {
|
|
|
19029
19400
|
}
|
|
19030
19401
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
19031
19402
|
if (result.changed) {
|
|
19032
|
-
const relative =
|
|
19403
|
+
const relative = path36.relative(process.cwd(), result.manifestPath);
|
|
19033
19404
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
19034
19405
|
log(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
19035
19406
|
}
|
|
@@ -19057,7 +19428,7 @@ function describeEdit(edit) {
|
|
|
19057
19428
|
// src/gallery/snapshot.ts
|
|
19058
19429
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
19059
19430
|
function galleryMediaId(absolutePath) {
|
|
19060
|
-
return createHash5("sha256").update(
|
|
19431
|
+
return createHash5("sha256").update(path37.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
19061
19432
|
}
|
|
19062
19433
|
function galleryMediaRoute(id) {
|
|
19063
19434
|
return `/media/${id}`;
|
|
@@ -19081,9 +19452,9 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
19081
19452
|
return (entry.history ?? []).map((generation, i) => {
|
|
19082
19453
|
const outputs = generation.outputs.map((output) => {
|
|
19083
19454
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
19084
|
-
const file =
|
|
19455
|
+
const file = path37.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
19085
19456
|
let url = null;
|
|
19086
|
-
if (
|
|
19457
|
+
if (existsSync32(file)) {
|
|
19087
19458
|
const id = galleryMediaId(file);
|
|
19088
19459
|
media.set(id, { path: file, contentType: mediaType });
|
|
19089
19460
|
url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
|
|
@@ -19115,7 +19486,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
19115
19486
|
var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
|
|
19116
19487
|
async function samePixels(a, b) {
|
|
19117
19488
|
try {
|
|
19118
|
-
const [left, right] = await Promise.all([
|
|
19489
|
+
const [left, right] = await Promise.all([readFile27(a), readFile27(b)]);
|
|
19119
19490
|
if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
|
|
19120
19491
|
const x = decodePng(left);
|
|
19121
19492
|
const y = decodePng(right);
|
|
@@ -19213,10 +19584,10 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
19213
19584
|
async function describeQuality(media, root, inspection) {
|
|
19214
19585
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
19215
19586
|
const outputs = await Promise.all(
|
|
19216
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
19587
|
+
outputPaths.map((file) => describeOutput(media, root, path37.resolve(root, file)))
|
|
19217
19588
|
);
|
|
19218
|
-
const recordPath =
|
|
19219
|
-
const recordExists =
|
|
19589
|
+
const recordPath = path37.resolve(root, inspection.record);
|
|
19590
|
+
const recordExists = existsSync32(recordPath);
|
|
19220
19591
|
let options = null;
|
|
19221
19592
|
let check = null;
|
|
19222
19593
|
if (recordExists) {
|
|
@@ -19235,7 +19606,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
19235
19606
|
return {
|
|
19236
19607
|
state: inspection.state,
|
|
19237
19608
|
reason: inspection.reason,
|
|
19238
|
-
output: portableOutputPath(
|
|
19609
|
+
output: portableOutputPath(path37.resolve(root, inspection.output), root),
|
|
19239
19610
|
record: portableOutputPath(recordPath, root),
|
|
19240
19611
|
recordExists,
|
|
19241
19612
|
outputs,
|
|
@@ -19273,9 +19644,9 @@ async function buildGallerySnapshot(opts) {
|
|
|
19273
19644
|
const media = /* @__PURE__ */ new Map();
|
|
19274
19645
|
const plan = await buildPlan(specs, lock);
|
|
19275
19646
|
const items = [];
|
|
19276
|
-
const manifestText = await
|
|
19647
|
+
const manifestText = await readFile27(loaded.path, "utf8");
|
|
19277
19648
|
const manifestSha256 = sha256(manifestText);
|
|
19278
|
-
const cacheDir =
|
|
19649
|
+
const cacheDir = path37.resolve(path37.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
19279
19650
|
let rawStyles = {};
|
|
19280
19651
|
try {
|
|
19281
19652
|
const raw = JSON.parse(manifestText);
|
|
@@ -19283,8 +19654,8 @@ async function buildGallerySnapshot(opts) {
|
|
|
19283
19654
|
} catch {
|
|
19284
19655
|
}
|
|
19285
19656
|
for (const planItem of plan.items) {
|
|
19286
|
-
const { spec, key } = planItem;
|
|
19287
|
-
const entry = lock.entries[
|
|
19657
|
+
const { spec, key: key2 } = planItem;
|
|
19658
|
+
const entry = lock.entries[key2];
|
|
19288
19659
|
const asset = loaded.manifest.assets[spec.assetId] ?? null;
|
|
19289
19660
|
let outputs;
|
|
19290
19661
|
let edit = null;
|
|
@@ -19299,12 +19670,12 @@ async function buildGallerySnapshot(opts) {
|
|
|
19299
19670
|
)
|
|
19300
19671
|
);
|
|
19301
19672
|
if (spec.source) {
|
|
19302
|
-
const editPath =
|
|
19673
|
+
const editPath = path37.resolve(root, spec.source);
|
|
19303
19674
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
19304
19675
|
const editShas = await Promise.all(
|
|
19305
19676
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
19306
19677
|
const file = sourceOutputPath(spec.source, entry, index, root);
|
|
19307
|
-
return { file, sha256:
|
|
19678
|
+
return { file, sha256: existsSync32(file) ? await sha256File(file) : null };
|
|
19308
19679
|
})
|
|
19309
19680
|
);
|
|
19310
19681
|
edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
|
|
@@ -19312,7 +19683,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19312
19683
|
const companion = await readHandEditCompanion(editPath);
|
|
19313
19684
|
if (companion) {
|
|
19314
19685
|
const projectPath = handEditProjectPath(editPath);
|
|
19315
|
-
const project = companion.project &&
|
|
19686
|
+
const project = companion.project && existsSync32(projectPath) ? await fileInfo(projectPath) : null;
|
|
19316
19687
|
let projectUrl = null;
|
|
19317
19688
|
if (project) {
|
|
19318
19689
|
const id = galleryMediaId(projectPath);
|
|
@@ -19348,17 +19719,17 @@ async function buildGallerySnapshot(opts) {
|
|
|
19348
19719
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
19349
19720
|
}
|
|
19350
19721
|
} else if (spec.source) {
|
|
19351
|
-
outputs = [await describeOutput(media, root,
|
|
19352
|
-
} else if (!entry &&
|
|
19722
|
+
outputs = [await describeOutput(media, root, path37.resolve(root, spec.source))];
|
|
19723
|
+
} else if (!entry && existsSync32(spec.outFile)) {
|
|
19353
19724
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
19354
19725
|
} else {
|
|
19355
19726
|
outputs = [];
|
|
19356
19727
|
}
|
|
19357
19728
|
const quality = planItem.quality ? await describeQuality(media, root, planItem.quality) : null;
|
|
19358
19729
|
items.push({
|
|
19359
|
-
id:
|
|
19730
|
+
id: key2,
|
|
19360
19731
|
project: null,
|
|
19361
|
-
key,
|
|
19732
|
+
key: key2,
|
|
19362
19733
|
styleId: spec.styleId,
|
|
19363
19734
|
assetId: spec.assetId,
|
|
19364
19735
|
declared: true,
|
|
@@ -19416,8 +19787,8 @@ async function buildGallerySnapshot(opts) {
|
|
|
19416
19787
|
});
|
|
19417
19788
|
}
|
|
19418
19789
|
const shown = new Set(items.map((item) => item.key));
|
|
19419
|
-
for (const [
|
|
19420
|
-
if (shown.has(
|
|
19790
|
+
for (const [key2, entry] of Object.entries(lock.entries)) {
|
|
19791
|
+
if (shown.has(key2)) continue;
|
|
19421
19792
|
if (isDeclared(loaded, entry.styleId, entry.assetId)) continue;
|
|
19422
19793
|
if (!matchesFilter(filter, entry.styleId, entry.assetId)) continue;
|
|
19423
19794
|
const outputs = await Promise.all(
|
|
@@ -19426,9 +19797,9 @@ async function buildGallerySnapshot(opts) {
|
|
|
19426
19797
|
)
|
|
19427
19798
|
);
|
|
19428
19799
|
items.push({
|
|
19429
|
-
id:
|
|
19800
|
+
id: key2,
|
|
19430
19801
|
project: null,
|
|
19431
|
-
key,
|
|
19802
|
+
key: key2,
|
|
19432
19803
|
styleId: entry.styleId,
|
|
19433
19804
|
assetId: entry.assetId,
|
|
19434
19805
|
declared: false,
|
|
@@ -19529,7 +19900,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19529
19900
|
} : null,
|
|
19530
19901
|
tags: style?.tags ?? [],
|
|
19531
19902
|
extends: typeof rawStyle?.extends === "string" ? rawStyle.extends : null,
|
|
19532
|
-
ownFields: rawStyle ? Object.keys(rawStyle).filter((
|
|
19903
|
+
ownFields: rawStyle ? Object.keys(rawStyle).filter((key2) => key2 !== "extends") : [],
|
|
19533
19904
|
items: styleItems.length,
|
|
19534
19905
|
spendByUnit: spend,
|
|
19535
19906
|
regenerate: {
|
|
@@ -19553,7 +19924,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19553
19924
|
id: loaded.manifest.name,
|
|
19554
19925
|
name: loaded.manifest.name,
|
|
19555
19926
|
manifest: loaded.path,
|
|
19556
|
-
lock:
|
|
19927
|
+
lock: path37.resolve(opts.lockPath),
|
|
19557
19928
|
root,
|
|
19558
19929
|
provider: loaded.manifest.provider,
|
|
19559
19930
|
account: null,
|
|
@@ -19579,7 +19950,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19579
19950
|
return { snapshot, media };
|
|
19580
19951
|
}
|
|
19581
19952
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
19582
|
-
const dir =
|
|
19953
|
+
const dir = path37.dirname(path37.resolve(opts.workspacePath));
|
|
19583
19954
|
const media = /* @__PURE__ */ new Map();
|
|
19584
19955
|
const projects = [];
|
|
19585
19956
|
const items = [];
|
|
@@ -19622,11 +19993,11 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19622
19993
|
id: project.id,
|
|
19623
19994
|
name: loaded.manifest.name,
|
|
19624
19995
|
manifest: manifestPath,
|
|
19625
|
-
lock:
|
|
19996
|
+
lock: path37.resolve(lockPath),
|
|
19626
19997
|
root: loaded.root,
|
|
19627
19998
|
provider: loaded.manifest.provider,
|
|
19628
19999
|
account: project.account ?? null,
|
|
19629
|
-
manifestSha256: manifestSha256 ?? sha256(await
|
|
20000
|
+
manifestSha256: manifestSha256 ?? sha256(await readFile27(manifestPath, "utf8")),
|
|
19630
20001
|
historyLimit: historyLimit(loaded.manifest),
|
|
19631
20002
|
entries: Object.keys(lock.entries).length,
|
|
19632
20003
|
items: projectItems.length,
|
|
@@ -19638,8 +20009,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19638
20009
|
id: project.id,
|
|
19639
20010
|
name: project.id,
|
|
19640
20011
|
manifest: manifestPath,
|
|
19641
|
-
lock:
|
|
19642
|
-
root:
|
|
20012
|
+
lock: path37.resolve(lockPath),
|
|
20013
|
+
root: path37.dirname(manifestPath),
|
|
19643
20014
|
provider: project.provider,
|
|
19644
20015
|
account: project.account ?? null,
|
|
19645
20016
|
manifestSha256: null,
|
|
@@ -19666,7 +20037,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19666
20037
|
version: 1,
|
|
19667
20038
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
19668
20039
|
project: null,
|
|
19669
|
-
workspace: { path:
|
|
20040
|
+
workspace: { path: path37.resolve(opts.workspacePath), dir, projects },
|
|
19670
20041
|
filter,
|
|
19671
20042
|
totals: {
|
|
19672
20043
|
entries: projects.reduce((sum, project) => sum + project.entries, 0),
|
|
@@ -19683,7 +20054,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19683
20054
|
}
|
|
19684
20055
|
|
|
19685
20056
|
// src/gallery/page.ts
|
|
19686
|
-
import { existsSync as
|
|
20057
|
+
import { existsSync as existsSync33, readFileSync as readFileSync8 } from "fs";
|
|
19687
20058
|
|
|
19688
20059
|
// src/gallery/client-bundle.ts
|
|
19689
20060
|
import { createRequire } from "module";
|
|
@@ -19724,7 +20095,7 @@ function clientAssets() {
|
|
|
19724
20095
|
const prebuilt = new URL("gallery.js", CLIENT_DIR);
|
|
19725
20096
|
client ??= {
|
|
19726
20097
|
css: readFileSync8(new URL("gallery.css", CLIENT_DIR), "utf8"),
|
|
19727
|
-
js:
|
|
20098
|
+
js: existsSync33(prebuilt) ? readFileSync8(prebuilt, "utf8") : bundleGalleryClient()
|
|
19728
20099
|
};
|
|
19729
20100
|
return client;
|
|
19730
20101
|
}
|
|
@@ -19867,10 +20238,10 @@ var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download
|
|
|
19867
20238
|
|
|
19868
20239
|
// src/editor/install.ts
|
|
19869
20240
|
import { createHash as createHash6 } from "crypto";
|
|
19870
|
-
import { existsSync as
|
|
19871
|
-
import { mkdir as
|
|
20241
|
+
import { existsSync as existsSync34 } from "fs";
|
|
20242
|
+
import { mkdir as mkdir13, readFile as readFile28, rename as rename11, rm as rm12, stat as stat4, writeFile as writeFile18 } from "fs/promises";
|
|
19872
20243
|
import os3 from "os";
|
|
19873
|
-
import
|
|
20244
|
+
import path38 from "path";
|
|
19874
20245
|
var EditorInstallError = class extends Error {
|
|
19875
20246
|
constructor(message6, file) {
|
|
19876
20247
|
super(message6);
|
|
@@ -19881,15 +20252,15 @@ var EditorInstallError = class extends Error {
|
|
|
19881
20252
|
};
|
|
19882
20253
|
function editorToolsRoot() {
|
|
19883
20254
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
19884
|
-
if (override) return
|
|
19885
|
-
if (process.platform === "darwin") return
|
|
20255
|
+
if (override) return path38.resolve(override);
|
|
20256
|
+
if (process.platform === "darwin") return path38.join(os3.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
19886
20257
|
if (process.platform === "win32") {
|
|
19887
|
-
return
|
|
20258
|
+
return path38.join(process.env.LOCALAPPDATA ?? path38.join(os3.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
19888
20259
|
}
|
|
19889
|
-
return
|
|
20260
|
+
return path38.join(process.env.XDG_CACHE_HOME ?? path38.join(os3.homedir(), ".cache"), "pixelkiln", "tools");
|
|
19890
20261
|
}
|
|
19891
20262
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
19892
|
-
return
|
|
20263
|
+
return path38.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
19893
20264
|
}
|
|
19894
20265
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
19895
20266
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -19899,7 +20270,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
|
|
|
19899
20270
|
}
|
|
19900
20271
|
async function sha256Of(file) {
|
|
19901
20272
|
try {
|
|
19902
|
-
return createHash6("sha256").update(await
|
|
20273
|
+
return createHash6("sha256").update(await readFile28(file)).digest("hex");
|
|
19903
20274
|
} catch {
|
|
19904
20275
|
return null;
|
|
19905
20276
|
}
|
|
@@ -19912,8 +20283,8 @@ async function editorStatus(opts = {}) {
|
|
|
19912
20283
|
let totalBytes = 0;
|
|
19913
20284
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
19914
20285
|
totalBytes += expected.bytes;
|
|
19915
|
-
const file =
|
|
19916
|
-
const info =
|
|
20286
|
+
const file = path38.join(dir, name);
|
|
20287
|
+
const info = existsSync34(file) ? await stat4(file).catch(() => null) : null;
|
|
19917
20288
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
19918
20289
|
installedBytes += expected.bytes;
|
|
19919
20290
|
} else {
|
|
@@ -19942,7 +20313,7 @@ async function installEditor(opts = {}) {
|
|
|
19942
20313
|
);
|
|
19943
20314
|
}
|
|
19944
20315
|
if (!baseUrl) throw new EditorInstallError("no download location for the editor build");
|
|
19945
|
-
await
|
|
20316
|
+
await mkdir13(dir, { recursive: true });
|
|
19946
20317
|
const downloaded = [];
|
|
19947
20318
|
const skipped = Object.keys(pin.files).filter((name) => !before.missing.includes(name));
|
|
19948
20319
|
let fetchedBytes = before.installedBytes;
|
|
@@ -19970,11 +20341,11 @@ async function installEditor(opts = {}) {
|
|
|
19970
20341
|
if (digest2 !== expected.sha256) {
|
|
19971
20342
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
19972
20343
|
}
|
|
19973
|
-
const final =
|
|
20344
|
+
const final = path38.join(dir, name);
|
|
19974
20345
|
const tmp = `${final}.${process.pid}.part`;
|
|
19975
20346
|
try {
|
|
19976
|
-
await
|
|
19977
|
-
await
|
|
20347
|
+
await writeFile18(tmp, bytes);
|
|
20348
|
+
await rename11(tmp, final);
|
|
19978
20349
|
} finally {
|
|
19979
20350
|
await rm12(tmp, { force: true });
|
|
19980
20351
|
}
|
|
@@ -20016,12 +20387,12 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
20016
20387
|
".json": "application/json; charset=utf-8"
|
|
20017
20388
|
};
|
|
20018
20389
|
function editorContentType(name) {
|
|
20019
|
-
return EDITOR_CONTENT_TYPES[
|
|
20390
|
+
return EDITOR_CONTENT_TYPES[path38.extname(name).toLowerCase()] ?? null;
|
|
20020
20391
|
}
|
|
20021
20392
|
|
|
20022
20393
|
// src/gallery/editor.ts
|
|
20023
|
-
import { readFile as
|
|
20024
|
-
import
|
|
20394
|
+
import { readFile as readFile29 } from "fs/promises";
|
|
20395
|
+
import path39 from "path";
|
|
20025
20396
|
function editorRoute(release, name = "index.html") {
|
|
20026
20397
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
20027
20398
|
}
|
|
@@ -20094,7 +20465,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
20094
20465
|
if (!status.installed) return null;
|
|
20095
20466
|
let bytes;
|
|
20096
20467
|
try {
|
|
20097
|
-
bytes = await
|
|
20468
|
+
bytes = await readFile29(path39.join(dir, name));
|
|
20098
20469
|
} catch {
|
|
20099
20470
|
verified = null;
|
|
20100
20471
|
return null;
|
|
@@ -20111,7 +20482,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
20111
20482
|
// src/gallery/server.ts
|
|
20112
20483
|
import { randomBytes } from "crypto";
|
|
20113
20484
|
import { createServer as createServer2 } from "http";
|
|
20114
|
-
import { readFile as
|
|
20485
|
+
import { readFile as readFile30 } from "fs/promises";
|
|
20115
20486
|
var MAX_EDIT_BYTES = 48 * 1024 * 1024;
|
|
20116
20487
|
var EDITOR_CSP = [
|
|
20117
20488
|
"default-src 'self'",
|
|
@@ -20292,7 +20663,7 @@ async function serveGallery(opts) {
|
|
|
20292
20663
|
const asset = reviewAssets.get(jobId)?.get(url2.pathname);
|
|
20293
20664
|
if (!asset) return fail(404, "no such review asset");
|
|
20294
20665
|
try {
|
|
20295
|
-
const bytes = await
|
|
20666
|
+
const bytes = await readFile30(asset.path);
|
|
20296
20667
|
res.writeHead(200, {
|
|
20297
20668
|
"Content-Type": asset.contentType,
|
|
20298
20669
|
"Cache-Control": "no-store",
|
|
@@ -20375,7 +20746,7 @@ async function serveGallery(opts) {
|
|
|
20375
20746
|
if (!asset) return fail(404, "no such gallery media");
|
|
20376
20747
|
let bytes;
|
|
20377
20748
|
try {
|
|
20378
|
-
bytes = await
|
|
20749
|
+
bytes = await readFile30(asset.path);
|
|
20379
20750
|
} catch {
|
|
20380
20751
|
return fail(404, "gallery media is no longer on disk; refresh the page");
|
|
20381
20752
|
}
|
|
@@ -20482,7 +20853,7 @@ function createGenerateHandlers(opts) {
|
|
|
20482
20853
|
const busy = /* @__PURE__ */ new Map();
|
|
20483
20854
|
for (const job of jobs.values()) {
|
|
20484
20855
|
if (job.phase === "done" || job.phase === "failed") continue;
|
|
20485
|
-
for (const
|
|
20856
|
+
for (const key2 of job.keys) busy.set(`${job.project ?? ""}:${key2}`, job.id);
|
|
20486
20857
|
}
|
|
20487
20858
|
return busy;
|
|
20488
20859
|
};
|
|
@@ -20525,7 +20896,7 @@ function createGenerateHandlers(opts) {
|
|
|
20525
20896
|
});
|
|
20526
20897
|
say(job, `${providerId}: ${res.completed} completed, ${res.review} awaiting review, ${res.failed} failed, ${res.stillRunning} still running`);
|
|
20527
20898
|
}
|
|
20528
|
-
job.review = specs.map((spec) => lockKey(spec.styleId, spec.assetId)).filter((
|
|
20899
|
+
job.review = specs.map((spec) => lockKey(spec.styleId, spec.assetId)).filter((key2) => ctx.lock.entries[key2]?.status === "review");
|
|
20529
20900
|
job.phase = "fetching";
|
|
20530
20901
|
for (const [providerId, providerSpecs] of groupByRecordedProvider(specs, ctx.lock)) {
|
|
20531
20902
|
const provider = opts.providerFor(job.project ?? void 0, providerId);
|
|
@@ -20610,7 +20981,7 @@ function createGenerateHandlers(opts) {
|
|
|
20610
20981
|
job.finishedAt = null;
|
|
20611
20982
|
const next = await opts.loadProject(job.project ?? void 0);
|
|
20612
20983
|
const byKey = new Map(next.specs.map((spec) => [lockKey(spec.styleId, spec.assetId), spec]));
|
|
20613
|
-
const nextSpecs = job.keys.map((
|
|
20984
|
+
const nextSpecs = job.keys.map((key2) => byKey.get(key2)).filter((spec) => Boolean(spec));
|
|
20614
20985
|
const plan = await buildPlan(nextSpecs, next.lock);
|
|
20615
20986
|
if (!plan.actionable.length) return finish();
|
|
20616
20987
|
for (const group of plan.groups) {
|
|
@@ -20677,21 +21048,21 @@ function createGenerateHandlers(opts) {
|
|
|
20677
21048
|
const ctx = await opts.loadProject(request.project);
|
|
20678
21049
|
const byKey = new Map(ctx.specs.map((spec) => [lockKey(spec.styleId, spec.assetId), spec]));
|
|
20679
21050
|
const specs = [];
|
|
20680
|
-
for (const
|
|
20681
|
-
const spec = byKey.get(
|
|
20682
|
-
if (!spec) throw new GenerateRequestError(`"${
|
|
21051
|
+
for (const key2 of request.keys) {
|
|
21052
|
+
const spec = byKey.get(key2);
|
|
21053
|
+
if (!spec) throw new GenerateRequestError(`"${key2}" is not declared by the manifest`);
|
|
20683
21054
|
specs.push(spec);
|
|
20684
21055
|
}
|
|
20685
21056
|
const busy = busyKeys();
|
|
20686
|
-
for (const
|
|
20687
|
-
const holder = busy.get(`${request.project ?? ""}:${
|
|
20688
|
-
if (holder) throw new GenerateRequestError(`"${
|
|
21057
|
+
for (const key2 of request.keys) {
|
|
21058
|
+
const holder = busy.get(`${request.project ?? ""}:${key2}`);
|
|
21059
|
+
if (holder) throw new GenerateRequestError(`"${key2}" is already being worked on by job ${holder}`, 409);
|
|
20689
21060
|
}
|
|
20690
21061
|
if (request.restore) {
|
|
20691
|
-
for (const
|
|
20692
|
-
const entry = ctx.lock.entries[
|
|
21062
|
+
for (const key2 of request.keys) {
|
|
21063
|
+
const entry = ctx.lock.entries[key2];
|
|
20693
21064
|
if (!entry || entry.status !== "downloaded" || !entry.outputs.length) {
|
|
20694
|
-
throw new GenerateRequestError(`"${
|
|
21065
|
+
throw new GenerateRequestError(`"${key2}" has no downloaded output recorded to restore`);
|
|
20695
21066
|
}
|
|
20696
21067
|
}
|
|
20697
21068
|
}
|
|
@@ -20785,19 +21156,19 @@ function createGenerateHandlers(opts) {
|
|
|
20785
21156
|
}
|
|
20786
21157
|
|
|
20787
21158
|
// src/pipeline/salvage.ts
|
|
20788
|
-
import { readFile as
|
|
20789
|
-
import { existsSync as
|
|
20790
|
-
import
|
|
21159
|
+
import { readFile as readFile31 } from "fs/promises";
|
|
21160
|
+
import { existsSync as existsSync35 } from "fs";
|
|
21161
|
+
import path40 from "path";
|
|
20791
21162
|
function providerClaimId(provider, objectId) {
|
|
20792
21163
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
20793
21164
|
}
|
|
20794
21165
|
async function loadClaims(lockPaths, opts = {}) {
|
|
20795
21166
|
const claimed = /* @__PURE__ */ new Set();
|
|
20796
21167
|
for (const p of lockPaths) {
|
|
20797
|
-
if (!
|
|
21168
|
+
if (!existsSync35(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
20798
21169
|
let parsed;
|
|
20799
21170
|
try {
|
|
20800
|
-
parsed = parseLock(JSON.parse(await
|
|
21171
|
+
parsed = parseLock(JSON.parse(await readFile31(p, "utf8")));
|
|
20801
21172
|
} catch {
|
|
20802
21173
|
throw new Error(`Claim lockfile is malformed: ${p}`);
|
|
20803
21174
|
}
|
|
@@ -20901,20 +21272,20 @@ function matchOrphanStyle(prompt, manifest) {
|
|
|
20901
21272
|
return matchStyleByPattern(prompt, manifest);
|
|
20902
21273
|
}
|
|
20903
21274
|
async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
|
|
20904
|
-
const own =
|
|
21275
|
+
const own = path40.resolve(ownManifestPath);
|
|
20905
21276
|
const siblingManifestPaths = [
|
|
20906
21277
|
.../* @__PURE__ */ new Set([
|
|
20907
21278
|
...workspaceManifestPaths,
|
|
20908
|
-
...claimPaths.map((c) =>
|
|
21279
|
+
...claimPaths.map((c) => path40.join(path40.dirname(path40.resolve(c)), "pixelkiln.manifest.json"))
|
|
20909
21280
|
])
|
|
20910
21281
|
];
|
|
20911
21282
|
const siblings = [];
|
|
20912
21283
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
20913
|
-
if (
|
|
20914
|
-
if (!
|
|
21284
|
+
if (path40.resolve(siblingManifestPath) === own) continue;
|
|
21285
|
+
if (!existsSync35(siblingManifestPath)) continue;
|
|
20915
21286
|
try {
|
|
20916
21287
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
20917
|
-
siblings.push({ label:
|
|
21288
|
+
siblings.push({ label: path40.basename(path40.dirname(siblingManifestPath)), manifest });
|
|
20918
21289
|
} catch {
|
|
20919
21290
|
}
|
|
20920
21291
|
}
|
|
@@ -20934,10 +21305,10 @@ function groupOrphansByStyle(orphans, manifest, siblings = []) {
|
|
|
20934
21305
|
}
|
|
20935
21306
|
const sibling = siblings.find((s) => matchStyleByPattern(o.prompt, s.manifest));
|
|
20936
21307
|
if (sibling) {
|
|
20937
|
-
const
|
|
20938
|
-
const list = elsewhere.get(
|
|
21308
|
+
const key2 = `${sibling.label}: ${matchStyleByPattern(o.prompt, sibling.manifest)}`;
|
|
21309
|
+
const list = elsewhere.get(key2) ?? [];
|
|
20939
21310
|
list.push(o);
|
|
20940
|
-
elsewhere.set(
|
|
21311
|
+
elsewhere.set(key2, list);
|
|
20941
21312
|
continue;
|
|
20942
21313
|
}
|
|
20943
21314
|
if (ownStyleIds.length <= 1 && ownStyleIds[0]) matched.get(ownStyleIds[0]).push(o);
|
|
@@ -21034,8 +21405,8 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
21034
21405
|
}
|
|
21035
21406
|
|
|
21036
21407
|
// src/pick/salvage-server.ts
|
|
21037
|
-
import { mkdir as
|
|
21038
|
-
import
|
|
21408
|
+
import { mkdir as mkdir14, writeFile as writeFile19, readFile as readFile32 } from "fs/promises";
|
|
21409
|
+
import path41 from "path";
|
|
21039
21410
|
|
|
21040
21411
|
// src/pick/salvage-sheet.ts
|
|
21041
21412
|
var escapeHtml3 = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -21201,7 +21572,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21201
21572
|
});
|
|
21202
21573
|
const html = renderSalvageSheet(orphans, {
|
|
21203
21574
|
styleId: ctx.styleId,
|
|
21204
|
-
importDir:
|
|
21575
|
+
importDir: path41.relative(process.cwd(), ctx.importDir) || "."
|
|
21205
21576
|
});
|
|
21206
21577
|
const byId = new Map(orphans.map((o) => [o.id, o]));
|
|
21207
21578
|
const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
|
|
@@ -21257,10 +21628,10 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21257
21628
|
if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
|
|
21258
21629
|
decodePng(buf);
|
|
21259
21630
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
21260
|
-
const rel =
|
|
21261
|
-
const outFile =
|
|
21262
|
-
await
|
|
21263
|
-
await
|
|
21631
|
+
const rel = path41.join("_salvaged", `${assetId}.png`);
|
|
21632
|
+
const outFile = path41.resolve(ctx.importDir, rel);
|
|
21633
|
+
await mkdir14(path41.dirname(outFile), { recursive: true });
|
|
21634
|
+
await writeFile19(outFile, buf);
|
|
21264
21635
|
ctx.manifest.assets[assetId] = {
|
|
21265
21636
|
prompt: orphan.prompt,
|
|
21266
21637
|
promptByStyle: {},
|
|
@@ -21292,7 +21663,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21292
21663
|
sourceUrl: durableSource,
|
|
21293
21664
|
sourceUrls: durableSource ? [{ url: durableSource }] : [],
|
|
21294
21665
|
outputs: [{
|
|
21295
|
-
path: portableOutputPath(outFile,
|
|
21666
|
+
path: portableOutputPath(outFile, path41.dirname(ctx.manifestPath)),
|
|
21296
21667
|
sha256: sha256(buf)
|
|
21297
21668
|
}],
|
|
21298
21669
|
submittedAt: orphan.createdAt,
|
|
@@ -21316,9 +21687,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21316
21687
|
}
|
|
21317
21688
|
}
|
|
21318
21689
|
await applyTags(provider, decisions, existingTags, { onProgress: log, characters: characterMembers });
|
|
21319
|
-
const raw = JSON.parse(await
|
|
21690
|
+
const raw = JSON.parse(await readFile32(ctx.manifestPath, "utf8"));
|
|
21320
21691
|
for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
|
|
21321
|
-
await
|
|
21692
|
+
await writeFile19(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
|
|
21322
21693
|
await saveLock(ctx.lockPath, ctx.lock);
|
|
21323
21694
|
if (characterAssetIds.length) result.characterAssetIds = characterAssetIds;
|
|
21324
21695
|
return result;
|
|
@@ -21427,6 +21798,8 @@ async function workspaceStatus(ws, dir) {
|
|
|
21427
21798
|
}
|
|
21428
21799
|
export {
|
|
21429
21800
|
AssetBatchSchema,
|
|
21801
|
+
AssetDeriveSchema,
|
|
21802
|
+
AssetExternalSchema,
|
|
21430
21803
|
AssetSchema,
|
|
21431
21804
|
AssetVfxSchema,
|
|
21432
21805
|
BudgetError,
|