pixelkiln 0.129.0 → 0.131.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 +874 -580
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +942 -655
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +929 -642
- package/dist/index.js.map +1 -1
- package/docs/CHARACTERS_3D.md +15 -0
- package/docs/CLI.md +4 -1
- package/docs/RESEARCH_3D.md +79 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -67,8 +67,8 @@ function exitCodeFor(err) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// src/cli/main.ts
|
|
70
|
-
import { existsSync as
|
|
71
|
-
import { readFile as
|
|
70
|
+
import { existsSync as existsSync59 } from "fs";
|
|
71
|
+
import { readFile as readFile52 } from "fs/promises";
|
|
72
72
|
|
|
73
73
|
// src/cli/args.ts
|
|
74
74
|
import path from "path";
|
|
@@ -917,7 +917,8 @@ Options
|
|
|
917
917
|
--json Machine-readable output where supported, including quality checks
|
|
918
918
|
and the gallery snapshot (no server)
|
|
919
919
|
--check plan/audit/cache: exit nonzero when the selected state is unsafe
|
|
920
|
-
--yes, -y Skip the confirmation prompt
|
|
920
|
+
--yes, -y Skip the confirmation prompt; gen also accepts assets with a single
|
|
921
|
+
candidate or one frame set (2+ candidates still open the pick page)
|
|
921
922
|
--no-open Do not auto-open the browser (pick, salvage, gallery) or editor (edit)
|
|
922
923
|
--edit gallery: allow manifest edits from the page (never spends)
|
|
923
924
|
--no-editor gallery: do not offer or serve the in-browser editor
|
|
@@ -1453,10 +1454,10 @@ function normalizeHex(value) {
|
|
|
1453
1454
|
function sha256(data) {
|
|
1454
1455
|
return createHash("sha256").update(data).digest("hex");
|
|
1455
1456
|
}
|
|
1456
|
-
async function sha256File(
|
|
1457
|
+
async function sha256File(path77) {
|
|
1457
1458
|
return new Promise((resolve, reject) => {
|
|
1458
1459
|
const hash = createHash("sha256");
|
|
1459
|
-
const stream = createReadStream(
|
|
1460
|
+
const stream = createReadStream(path77);
|
|
1460
1461
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
1461
1462
|
stream.on("error", reject);
|
|
1462
1463
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -3190,7 +3191,7 @@ var AssetDeriveSchema = z.object({
|
|
|
3190
3191
|
/** key-skin: how far a pixel may sit from a `skin` colour. despeckle: how near a reference colour must be to vouch for a pixel. */
|
|
3191
3192
|
tolerance: z.number().min(0).max(442).optional()
|
|
3192
3193
|
}).strict().superRefine((derive, context) => {
|
|
3193
|
-
const issue = (message6,
|
|
3194
|
+
const issue = (message6, path77) => context.addIssue({ code: z.ZodIssueCode.custom, message: message6, path: [path77] });
|
|
3194
3195
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
3195
3196
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
3196
3197
|
}
|
|
@@ -7520,7 +7521,7 @@ function changedLayerSource(spec, entry, lock) {
|
|
|
7520
7521
|
|
|
7521
7522
|
// src/cli/io.ts
|
|
7522
7523
|
var log = (msg = "") => console.log(msg);
|
|
7523
|
-
function announceReviewReady(info, stdout = process.stdout, stderr = process.stderr) {
|
|
7524
|
+
function announceReviewReady(info, stdout = process.stdout, stderr = process.stderr, stdinIsTTY = process.stdin.isTTY) {
|
|
7524
7525
|
const stream = stdout.isTTY ? stdout : stderr;
|
|
7525
7526
|
const count = info.keys.length;
|
|
7526
7527
|
stream.write(
|
|
@@ -7530,6 +7531,11 @@ function announceReviewReady(info, stdout = process.stdout, stderr = process.std
|
|
|
7530
7531
|
|
|
7531
7532
|
`
|
|
7532
7533
|
);
|
|
7534
|
+
if (!stdinIsTTY) {
|
|
7535
|
+
stream.write(
|
|
7536
|
+
' hint: stdin is not a terminal; `gen --yes` accepts single-candidate assets without waiting, or POST {"selections":[{"key":"<style>/<asset>","index":0}]} to ' + info.url + "apply\n\n"
|
|
7537
|
+
);
|
|
7538
|
+
}
|
|
7533
7539
|
}
|
|
7534
7540
|
function announceGalleryReady(url, count, stdout = process.stdout, stderr = process.stderr, edit = false, budget = null) {
|
|
7535
7541
|
const stream = stdout.isTTY ? stdout : stderr;
|
|
@@ -9191,9 +9197,9 @@ var PixelLabClient = class {
|
|
|
9191
9197
|
apiKey;
|
|
9192
9198
|
http;
|
|
9193
9199
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
9194
|
-
async request(
|
|
9200
|
+
async request(path77, init) {
|
|
9195
9201
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
9196
|
-
const res = await this.http(`${BASE}${
|
|
9202
|
+
const res = await this.http(`${BASE}${path77}`, {
|
|
9197
9203
|
...init,
|
|
9198
9204
|
headers: {
|
|
9199
9205
|
Authorization: auth,
|
|
@@ -9204,13 +9210,13 @@ var PixelLabClient = class {
|
|
|
9204
9210
|
const text = await res.text();
|
|
9205
9211
|
if (!res.ok) {
|
|
9206
9212
|
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' : "";
|
|
9207
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
9213
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path77} \u2192 ${res.status}${hint}${refusalReason(res.status, text)}`, res.status, text);
|
|
9208
9214
|
}
|
|
9209
9215
|
if (!text) return {};
|
|
9210
9216
|
try {
|
|
9211
9217
|
return JSON.parse(text);
|
|
9212
9218
|
} catch {
|
|
9213
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
9219
|
+
throw new Error(`${init?.method ?? "GET"} ${path77} returned invalid JSON`);
|
|
9214
9220
|
}
|
|
9215
9221
|
}
|
|
9216
9222
|
async balance() {
|
|
@@ -9757,10 +9763,10 @@ var PixelLabClient = class {
|
|
|
9757
9763
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
9758
9764
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
9759
9765
|
const south = args.reference?.south;
|
|
9760
|
-
let
|
|
9766
|
+
let path77;
|
|
9761
9767
|
let body;
|
|
9762
9768
|
if (args.mode === "v3") {
|
|
9763
|
-
|
|
9769
|
+
path77 = "/create-character-v3";
|
|
9764
9770
|
body = {
|
|
9765
9771
|
description: args.description,
|
|
9766
9772
|
image_size: imageSize,
|
|
@@ -9774,7 +9780,7 @@ var PixelLabClient = class {
|
|
|
9774
9780
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
9775
9781
|
};
|
|
9776
9782
|
} else if (args.mode === "pro-flash") {
|
|
9777
|
-
|
|
9783
|
+
path77 = "/create-character-pro-flash";
|
|
9778
9784
|
const traits = args.styleTraits;
|
|
9779
9785
|
body = {
|
|
9780
9786
|
description: args.description,
|
|
@@ -9798,7 +9804,7 @@ var PixelLabClient = class {
|
|
|
9798
9804
|
} : {}
|
|
9799
9805
|
};
|
|
9800
9806
|
} else if (args.mode === "pro") {
|
|
9801
|
-
|
|
9807
|
+
path77 = "/create-character-pro";
|
|
9802
9808
|
body = {
|
|
9803
9809
|
description: args.description,
|
|
9804
9810
|
image_size: imageSize,
|
|
@@ -9812,7 +9818,7 @@ var PixelLabClient = class {
|
|
|
9812
9818
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
9813
9819
|
};
|
|
9814
9820
|
} else {
|
|
9815
|
-
|
|
9821
|
+
path77 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
9816
9822
|
body = {
|
|
9817
9823
|
description: args.description,
|
|
9818
9824
|
image_size: imageSize,
|
|
@@ -9830,8 +9836,8 @@ var PixelLabClient = class {
|
|
|
9830
9836
|
};
|
|
9831
9837
|
}
|
|
9832
9838
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
9833
|
-
const raw = await this.request(
|
|
9834
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
9839
|
+
const raw = await this.request(path77, { method: "POST", body: JSON.stringify(body) });
|
|
9840
|
+
return validateResponse(CharacterSubmitSchema, raw, path77.slice(1));
|
|
9835
9841
|
}
|
|
9836
9842
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
9837
9843
|
async createCharacterState(args) {
|
|
@@ -15227,9 +15233,9 @@ var RetroDiffusionClient = class {
|
|
|
15227
15233
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
15228
15234
|
return Buffer.from(await response.arrayBuffer());
|
|
15229
15235
|
}
|
|
15230
|
-
async call(
|
|
15236
|
+
async call(path77, init = {}) {
|
|
15231
15237
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
15232
|
-
const response = await this.request(`${this.baseUrl}${
|
|
15238
|
+
const response = await this.request(`${this.baseUrl}${path77}`, {
|
|
15233
15239
|
...init,
|
|
15234
15240
|
headers: {
|
|
15235
15241
|
"Content-Type": "application/json",
|
|
@@ -18064,7 +18070,8 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
18064
18070
|
if (!source.url) {
|
|
18065
18071
|
throw new Error(`no source URL or cached bytes remain for ${source.role ?? "asset"}`);
|
|
18066
18072
|
}
|
|
18067
|
-
|
|
18073
|
+
const localFile = source.url.startsWith("file://") ? source.url.slice("file://".length) : null;
|
|
18074
|
+
raw = localFile && existsSync15(localFile) ? await readFile11(localFile) : await provider.download(source.url);
|
|
18068
18075
|
}
|
|
18069
18076
|
let mediaType;
|
|
18070
18077
|
const bytes = final ?? raw;
|
|
@@ -18532,10 +18539,10 @@ function isSha256Hash(value) {
|
|
|
18532
18539
|
function parseCache(value) {
|
|
18533
18540
|
return HashCacheSchema.parse(value);
|
|
18534
18541
|
}
|
|
18535
|
-
async function loadCache(
|
|
18536
|
-
if (!existsSync18(
|
|
18542
|
+
async function loadCache(path77) {
|
|
18543
|
+
if (!existsSync18(path77)) return { version: 1, hashes: {} };
|
|
18537
18544
|
try {
|
|
18538
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(
|
|
18545
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(path77, "utf8")));
|
|
18539
18546
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
18540
18547
|
return {
|
|
18541
18548
|
version: 1,
|
|
@@ -18547,18 +18554,18 @@ async function loadCache(path76) {
|
|
|
18547
18554
|
return { version: 1, hashes: {} };
|
|
18548
18555
|
}
|
|
18549
18556
|
}
|
|
18550
|
-
async function saveCache(
|
|
18557
|
+
async function saveCache(path77, cache) {
|
|
18551
18558
|
const sorted = {};
|
|
18552
18559
|
for (const key3 of Object.keys(cache.hashes).sort()) {
|
|
18553
18560
|
const hash = cache.hashes[key3];
|
|
18554
18561
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key3}`);
|
|
18555
18562
|
sorted[key3] = hash;
|
|
18556
18563
|
}
|
|
18557
|
-
await mkdir9(pathModule.dirname(pathModule.resolve(
|
|
18558
|
-
const tmp = `${
|
|
18564
|
+
await mkdir9(pathModule.dirname(pathModule.resolve(path77)), { recursive: true });
|
|
18565
|
+
const tmp = `${path77}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18559
18566
|
try {
|
|
18560
18567
|
await writeFile9(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
18561
|
-
await rename7(tmp,
|
|
18568
|
+
await rename7(tmp, path77);
|
|
18562
18569
|
} finally {
|
|
18563
18570
|
await rm5(tmp, { force: true });
|
|
18564
18571
|
}
|
|
@@ -21903,10 +21910,10 @@ function uvGuide(document, imageIndex) {
|
|
|
21903
21910
|
function facingOf(normal) {
|
|
21904
21911
|
const length = Math.hypot(...normal);
|
|
21905
21912
|
if (!(length > 0)) return null;
|
|
21906
|
-
const [x, y,
|
|
21907
|
-
const strongest = Math.max(Math.abs(x), Math.abs(y), Math.abs(
|
|
21913
|
+
const [x, y, z19] = normal.map((value) => value / length);
|
|
21914
|
+
const strongest = Math.max(Math.abs(x), Math.abs(y), Math.abs(z19));
|
|
21908
21915
|
if (strongest < 0.6) return null;
|
|
21909
|
-
if (strongest === Math.abs(
|
|
21916
|
+
if (strongest === Math.abs(z19)) return z19 > 0 ? "front" : "back";
|
|
21910
21917
|
if (strongest === Math.abs(y)) return y > 0 ? "top" : "underside";
|
|
21911
21918
|
return x > 0 ? "left" : "right";
|
|
21912
21919
|
}
|
|
@@ -22274,8 +22281,8 @@ function decodeScan(bytes, start, scan, frameComponents, hMax, vMax, width, heig
|
|
|
22274
22281
|
}
|
|
22275
22282
|
k += r;
|
|
22276
22283
|
if (k > 63) break;
|
|
22277
|
-
const
|
|
22278
|
-
coefficients[
|
|
22284
|
+
const z19 = ZIGZAG[k];
|
|
22285
|
+
coefficients[z19] = extend(receive(s), s) * q[z19];
|
|
22279
22286
|
k++;
|
|
22280
22287
|
}
|
|
22281
22288
|
if (blockRow >= c.blocksHigh || blockColumn >= c.blocksWide) return;
|
|
@@ -22751,18 +22758,18 @@ function localMatrix(node) {
|
|
|
22751
22758
|
const [tx, ty, tz] = node.translation ?? [0, 0, 0];
|
|
22752
22759
|
const [qx, qy, qz, qw] = node.rotation ?? [0, 0, 0, 1];
|
|
22753
22760
|
const [sx, sy, sz] = node.scale ?? [1, 1, 1];
|
|
22754
|
-
const x = qx, y = qy,
|
|
22761
|
+
const x = qx, y = qy, z19 = qz, w = qw;
|
|
22755
22762
|
return Float64Array.from([
|
|
22756
|
-
(1 - 2 * (y * y +
|
|
22757
|
-
2 * (x * y +
|
|
22758
|
-
2 * (x *
|
|
22763
|
+
(1 - 2 * (y * y + z19 * z19)) * sx,
|
|
22764
|
+
2 * (x * y + z19 * w) * sx,
|
|
22765
|
+
2 * (x * z19 - y * w) * sx,
|
|
22759
22766
|
0,
|
|
22760
|
-
2 * (x * y -
|
|
22761
|
-
(1 - 2 * (x * x +
|
|
22762
|
-
2 * (y *
|
|
22767
|
+
2 * (x * y - z19 * w) * sy,
|
|
22768
|
+
(1 - 2 * (x * x + z19 * z19)) * sy,
|
|
22769
|
+
2 * (y * z19 + x * w) * sy,
|
|
22763
22770
|
0,
|
|
22764
|
-
2 * (x *
|
|
22765
|
-
2 * (y *
|
|
22771
|
+
2 * (x * z19 + y * w) * sz,
|
|
22772
|
+
2 * (y * z19 - x * w) * sz,
|
|
22766
22773
|
(1 - 2 * (x * x + y * y)) * sz,
|
|
22767
22774
|
0,
|
|
22768
22775
|
tx,
|
|
@@ -22806,13 +22813,13 @@ function poseNodes(document, pose) {
|
|
|
22806
22813
|
const posed = /* @__PURE__ */ new Map();
|
|
22807
22814
|
for (const channel of animation.channels) {
|
|
22808
22815
|
const node = channel.target.node;
|
|
22809
|
-
const
|
|
22810
|
-
if (node === void 0 || !["translation", "rotation", "scale"].includes(
|
|
22816
|
+
const path77 = channel.target.path;
|
|
22817
|
+
if (node === void 0 || !["translation", "rotation", "scale"].includes(path77)) continue;
|
|
22811
22818
|
const sampler = animation.samplers[channel.sampler];
|
|
22812
22819
|
if (!sampler) continue;
|
|
22813
22820
|
const times = readAccessor(document, sampler.input).data;
|
|
22814
22821
|
const values = readAccessor(document, sampler.output);
|
|
22815
|
-
const width =
|
|
22822
|
+
const width = path77 === "rotation" ? 4 : 3;
|
|
22816
22823
|
const cubic = sampler.interpolation === "CUBICSPLINE";
|
|
22817
22824
|
const valueAt = (key4) => Array.from(values.data.subarray((cubic ? key4 * 3 + 1 : key4) * width, (cubic ? key4 * 3 + 1 : key4) * width + width));
|
|
22818
22825
|
const last = times.length - 1;
|
|
@@ -22824,16 +22831,16 @@ function poseNodes(document, pose) {
|
|
|
22824
22831
|
const span = times[key3 + 1] - times[key3];
|
|
22825
22832
|
const f = span > 0 ? (time - times[key3]) / span : 0;
|
|
22826
22833
|
const next = valueAt(key3 + 1);
|
|
22827
|
-
const sign =
|
|
22834
|
+
const sign = path77 === "rotation" && value.reduce((sum, v, k) => sum + v * next[k], 0) < 0 ? -1 : 1;
|
|
22828
22835
|
value = value.map((v, k) => v * (1 - f) + next[k] * sign * f);
|
|
22829
22836
|
}
|
|
22830
|
-
if (
|
|
22837
|
+
if (path77 === "rotation") {
|
|
22831
22838
|
const length = Math.hypot(...value) || 1;
|
|
22832
22839
|
value = value.map((v) => v / length);
|
|
22833
22840
|
}
|
|
22834
22841
|
const base = posed.get(node) ?? { ...document.json.nodes?.[node] ?? {} };
|
|
22835
22842
|
if (base.matrix) delete base.matrix;
|
|
22836
|
-
base[
|
|
22843
|
+
base[path77] = value;
|
|
22837
22844
|
posed.set(node, base);
|
|
22838
22845
|
}
|
|
22839
22846
|
return posed;
|
|
@@ -23047,9 +23054,9 @@ function texelSurface(primitives, document, image, width, height) {
|
|
|
23047
23054
|
return surface;
|
|
23048
23055
|
}
|
|
23049
23056
|
var decodeNormal = (pixels, at2) => {
|
|
23050
|
-
const x = pixels[at2] / 127.5 - 1, y = pixels[at2 + 1] / 127.5 - 1,
|
|
23051
|
-
const length = Math.hypot(x, y,
|
|
23052
|
-
return [x / length, y / length,
|
|
23057
|
+
const x = pixels[at2] / 127.5 - 1, y = pixels[at2 + 1] / 127.5 - 1, z19 = pixels[at2 + 2] / 127.5 - 1;
|
|
23058
|
+
const length = Math.hypot(x, y, z19) || 1;
|
|
23059
|
+
return [x / length, y / length, z19 / length];
|
|
23053
23060
|
};
|
|
23054
23061
|
function textureTiles(base, surface) {
|
|
23055
23062
|
const { width, height } = surface;
|
|
@@ -23115,12 +23122,12 @@ function basisOf(turn, tilt) {
|
|
|
23115
23122
|
toward: [level[0] * Math.cos(e), Math.sin(e), level[2] * Math.cos(e)]
|
|
23116
23123
|
};
|
|
23117
23124
|
}
|
|
23118
|
-
var dot = (v, x, y,
|
|
23119
|
-
function project(camera, basis, x, y,
|
|
23125
|
+
var dot = (v, x, y, z19) => v[0] * x + v[1] * y + v[2] * z19;
|
|
23126
|
+
function project(camera, basis, x, y, z19) {
|
|
23120
23127
|
return [
|
|
23121
|
-
(dot(basis.right, x, y,
|
|
23122
|
-
camera.offsetY - (dot(basis.up, x, y,
|
|
23123
|
-
dot(basis.toward, x, y,
|
|
23128
|
+
(dot(basis.right, x, y, z19) - camera.centreX) * camera.scale + camera.offsetX,
|
|
23129
|
+
camera.offsetY - (dot(basis.up, x, y, z19) - camera.centreY) * camera.scale,
|
|
23130
|
+
dot(basis.toward, x, y, z19)
|
|
23124
23131
|
];
|
|
23125
23132
|
}
|
|
23126
23133
|
function extent(primitives, basis) {
|
|
@@ -23170,10 +23177,10 @@ function drawView(document, primitives, camera, textures) {
|
|
|
23170
23177
|
const l1 = ((c[1] - a[1]) * (px - c[0]) + (a[0] - c[0]) * (py - c[1])) / den;
|
|
23171
23178
|
const l2 = 1 - l0 - l1;
|
|
23172
23179
|
if (l0 < 0 || l1 < 0 || l2 < 0) continue;
|
|
23173
|
-
const
|
|
23180
|
+
const z19 = l0 * a[2] + l1 * b[2] + l2 * c[2];
|
|
23174
23181
|
const at3 = y * width + x;
|
|
23175
|
-
if (
|
|
23176
|
-
depth[at3] =
|
|
23182
|
+
if (z19 <= depth[at3]) continue;
|
|
23183
|
+
depth[at3] = z19;
|
|
23177
23184
|
let rgb = flat;
|
|
23178
23185
|
if (texture && uv) {
|
|
23179
23186
|
const u = l0 * uv[corners[0] * 2] + l1 * uv[corners[1] * 2] + l2 * uv[corners[2] * 2];
|
|
@@ -23303,10 +23310,10 @@ function detailFromViews(surface, views, maps, opts = {}) {
|
|
|
23303
23310
|
const basis = bases[index];
|
|
23304
23311
|
const facing = dot(basis.toward, nx, ny, nz);
|
|
23305
23312
|
if (facing < 0.15) return;
|
|
23306
|
-
const [sx, sy,
|
|
23313
|
+
const [sx, sy, z20] = project(camera, basis, px, py, pz);
|
|
23307
23314
|
const ix = Math.floor(sx), iy = Math.floor(sy);
|
|
23308
23315
|
if (ix < 0 || iy < 0 || ix >= camera.width || iy >= camera.height) return;
|
|
23309
|
-
if (view.depth[iy * camera.width + ix] -
|
|
23316
|
+
if (view.depth[iy * camera.width + ix] - z20 > 1.5 / camera.scale) return;
|
|
23310
23317
|
if (view.use && !view.use[iy * camera.width + ix]) return;
|
|
23311
23318
|
const map = decoded[index];
|
|
23312
23319
|
if (map.pixels[(iy * camera.width + ix) * 4 + 3] < 128) return;
|
|
@@ -23343,9 +23350,9 @@ function detailFromViews(surface, views, maps, opts = {}) {
|
|
|
23343
23350
|
total += weight;
|
|
23344
23351
|
});
|
|
23345
23352
|
if (!(total > 0)) continue;
|
|
23346
|
-
const x = sum[texel * 3] / total, y = sum[texel * 3 + 1] / total,
|
|
23347
|
-
const length = Math.hypot(x, y,
|
|
23348
|
-
field.normal.set([x / length, y / length,
|
|
23353
|
+
const x = sum[texel * 3] / total, y = sum[texel * 3 + 1] / total, z19 = Math.max(0.05, sum[texel * 3 + 2] / total);
|
|
23354
|
+
const length = Math.hypot(x, y, z19);
|
|
23355
|
+
field.normal.set([x / length, y / length, z19 / length], texel * 3);
|
|
23349
23356
|
field.weight[texel] = 1;
|
|
23350
23357
|
}
|
|
23351
23358
|
return field;
|
|
@@ -23398,23 +23405,23 @@ function applyDetail(existing, field, opts = {}) {
|
|
|
23398
23405
|
if (!field.weight[texel]) continue;
|
|
23399
23406
|
let dx = field.normal[texel * 3] * amount, dy = field.normal[texel * 3 + 1] * amount;
|
|
23400
23407
|
const dz = field.normal[texel * 3 + 2];
|
|
23401
|
-
let x, y,
|
|
23408
|
+
let x, y, z19;
|
|
23402
23409
|
if (opts.replace) {
|
|
23403
23410
|
x = dx;
|
|
23404
23411
|
y = dy;
|
|
23405
|
-
|
|
23412
|
+
z19 = dz;
|
|
23406
23413
|
} else {
|
|
23407
23414
|
const [bx, by, bz] = decodeNormal(base.pixels, texel * 4);
|
|
23408
23415
|
x = bx + dx;
|
|
23409
23416
|
y = by + dy;
|
|
23410
|
-
|
|
23417
|
+
z19 = bz * dz;
|
|
23411
23418
|
}
|
|
23412
|
-
const length = Math.hypot(x, y,
|
|
23419
|
+
const length = Math.hypot(x, y, z19) || 1;
|
|
23413
23420
|
dx = x / length;
|
|
23414
23421
|
dy = y / length;
|
|
23415
23422
|
pixels[texel * 4] = Math.round((dx * 0.5 + 0.5) * 255);
|
|
23416
23423
|
pixels[texel * 4 + 1] = Math.round((dy * 0.5 + 0.5) * 255);
|
|
23417
|
-
pixels[texel * 4 + 2] = Math.round((Math.max(0,
|
|
23424
|
+
pixels[texel * 4 + 2] = Math.round((Math.max(0, z19 / length) * 0.5 + 0.5) * 255);
|
|
23418
23425
|
pixels[texel * 4 + 3] = 255;
|
|
23419
23426
|
}
|
|
23420
23427
|
return { width, height, pixels };
|
|
@@ -25316,8 +25323,8 @@ function describeSize(document, image) {
|
|
|
25316
25323
|
}
|
|
25317
25324
|
|
|
25318
25325
|
// src/cli/commands/gallery.ts
|
|
25319
|
-
import
|
|
25320
|
-
import { existsSync as
|
|
25326
|
+
import path47 from "path";
|
|
25327
|
+
import { existsSync as existsSync39 } from "fs";
|
|
25321
25328
|
|
|
25322
25329
|
// src/gallery/server.ts
|
|
25323
25330
|
import { randomBytes } from "crypto";
|
|
@@ -25764,7 +25771,194 @@ async function serveGallery(opts) {
|
|
|
25764
25771
|
|
|
25765
25772
|
// src/gallery/generate.ts
|
|
25766
25773
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
25774
|
+
import { z as z16 } from "zod";
|
|
25775
|
+
|
|
25776
|
+
// src/pick/candidates.ts
|
|
25777
|
+
import { existsSync as existsSync35 } from "fs";
|
|
25778
|
+
import { mkdir as mkdir18, readFile as readFile31, rename as rename13, rm as rm12, writeFile as writeFile22 } from "fs/promises";
|
|
25779
|
+
import path43 from "path";
|
|
25767
25780
|
import { z as z15 } from "zod";
|
|
25781
|
+
var REVIEW_STATE_VERSION = 1;
|
|
25782
|
+
var CandidateSchema = z15.object({
|
|
25783
|
+
index: z15.number().int().nonnegative(),
|
|
25784
|
+
/** Frame role for a frame set (`frame-00`, ...); absent for candidates. */
|
|
25785
|
+
role: z15.string().optional(),
|
|
25786
|
+
/**
|
|
25787
|
+
* Where the provider served the bytes. Null when the URL carried a
|
|
25788
|
+
* credential or signature, which never settles on disk.
|
|
25789
|
+
*/
|
|
25790
|
+
sourceUrl: z15.string().nullable(),
|
|
25791
|
+
/** sha256 of the cached bytes; null until the download succeeds. */
|
|
25792
|
+
sha256: z15.string().nullable(),
|
|
25793
|
+
mediaType: z15.string().nullable(),
|
|
25794
|
+
cachedAt: z15.string().nullable()
|
|
25795
|
+
});
|
|
25796
|
+
var ReviewAssetSchema = z15.object({
|
|
25797
|
+
provider: z15.string(),
|
|
25798
|
+
/** The provider job the candidates came from (the lock's `reviewObjectId`). */
|
|
25799
|
+
jobId: z15.string(),
|
|
25800
|
+
generator: z15.string().optional(),
|
|
25801
|
+
mode: z15.enum(["candidates", "frame-set"]),
|
|
25802
|
+
/** Frame-set playback rate. */
|
|
25803
|
+
fps: z15.number().optional(),
|
|
25804
|
+
/** Frame-set object id the provider reported. */
|
|
25805
|
+
objectId: z15.string().optional(),
|
|
25806
|
+
candidates: z15.array(CandidateSchema),
|
|
25807
|
+
/** "pending" while waiting on a choice, "applied" once one was committed. */
|
|
25808
|
+
status: z15.enum(["pending", "applied"]),
|
|
25809
|
+
/** The chosen candidate index, or null while nothing is chosen. */
|
|
25810
|
+
chosen: z15.number().int().nonnegative().nullable(),
|
|
25811
|
+
updatedAt: z15.string()
|
|
25812
|
+
});
|
|
25813
|
+
var ReviewStateSchema = z15.object({
|
|
25814
|
+
version: z15.literal(REVIEW_STATE_VERSION),
|
|
25815
|
+
/** Keyed by lock key (`<style>/<asset>`). */
|
|
25816
|
+
assets: z15.record(ReviewAssetSchema)
|
|
25817
|
+
});
|
|
25818
|
+
function candidateCacheDirFor(lockPath) {
|
|
25819
|
+
return path43.resolve(path43.dirname(lockPath), ".pixelkiln", "cache");
|
|
25820
|
+
}
|
|
25821
|
+
function reviewStatePathFor(lockPath) {
|
|
25822
|
+
const base = path43.basename(lockPath);
|
|
25823
|
+
const name = base === "pixelkiln.lock.json" ? "review-state.json" : `${base.replace(/\.json$/, "")}.review-state.json`;
|
|
25824
|
+
return path43.resolve(path43.dirname(lockPath), ".pixelkiln", name);
|
|
25825
|
+
}
|
|
25826
|
+
async function loadReviewState(file) {
|
|
25827
|
+
if (!existsSync35(file)) return { version: REVIEW_STATE_VERSION, assets: {} };
|
|
25828
|
+
try {
|
|
25829
|
+
const parsed = ReviewStateSchema.safeParse(JSON.parse(await readFile31(file, "utf8")));
|
|
25830
|
+
if (parsed.success) return parsed.data;
|
|
25831
|
+
} catch {
|
|
25832
|
+
}
|
|
25833
|
+
return { version: REVIEW_STATE_VERSION, assets: {} };
|
|
25834
|
+
}
|
|
25835
|
+
async function saveReviewState(file, state) {
|
|
25836
|
+
await mkdir18(path43.dirname(file), { recursive: true });
|
|
25837
|
+
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
25838
|
+
try {
|
|
25839
|
+
await writeFile22(tmp, JSON.stringify(state, null, 2) + "\n");
|
|
25840
|
+
await rename13(tmp, file);
|
|
25841
|
+
} finally {
|
|
25842
|
+
await rm12(tmp, { force: true });
|
|
25843
|
+
}
|
|
25844
|
+
}
|
|
25845
|
+
async function updateReviewAsset(file, key3, change) {
|
|
25846
|
+
const state = await loadReviewState(file);
|
|
25847
|
+
const asset = state.assets[key3];
|
|
25848
|
+
if (!asset) return null;
|
|
25849
|
+
const next = { ...change(asset), updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
25850
|
+
state.assets[key3] = next;
|
|
25851
|
+
await saveReviewState(file, state);
|
|
25852
|
+
return next;
|
|
25853
|
+
}
|
|
25854
|
+
function cachedCandidatePath(cacheDir, candidate) {
|
|
25855
|
+
if (!candidate.sha256 || !candidate.mediaType) return null;
|
|
25856
|
+
const file = path43.join(cacheDir, cacheFileName(candidate.sha256, candidate.mediaType));
|
|
25857
|
+
return existsSync35(file) ? file : null;
|
|
25858
|
+
}
|
|
25859
|
+
function fullyCached(cacheDir, asset) {
|
|
25860
|
+
return asset.candidates.length > 0 && asset.candidates.every((c) => cachedCandidatePath(cacheDir, c));
|
|
25861
|
+
}
|
|
25862
|
+
function storableUrl(url) {
|
|
25863
|
+
return isSensitiveSourceUrl(url) ? null : url;
|
|
25864
|
+
}
|
|
25865
|
+
async function downloadCandidate(provider, cacheDir, url, label) {
|
|
25866
|
+
let bytes;
|
|
25867
|
+
try {
|
|
25868
|
+
bytes = await provider.download(url);
|
|
25869
|
+
} catch (err) {
|
|
25870
|
+
const message6 = err instanceof Error ? err.message : String(err);
|
|
25871
|
+
throw new Error(`${label} could not be downloaded (${message6}); the provider has likely expired it`);
|
|
25872
|
+
}
|
|
25873
|
+
const mediaType = detectMediaType(bytes) ?? MediaType.PNG;
|
|
25874
|
+
const hash = sha256(bytes);
|
|
25875
|
+
await cacheMedia(cacheDir, bytes, mediaType, hash);
|
|
25876
|
+
return { sha256: hash, mediaType };
|
|
25877
|
+
}
|
|
25878
|
+
async function cacheReviewCandidates(provider, key3, jobId, job, opts) {
|
|
25879
|
+
const state = await loadReviewState(opts.statePath);
|
|
25880
|
+
const previous = state.assets[key3]?.jobId === jobId ? state.assets[key3] : void 0;
|
|
25881
|
+
const sources = job.status === "review" ? job.candidateUrls.map((url) => ({ url, role: void 0 })) : job.sources.map((source) => ({ url: source.url, role: source.role }));
|
|
25882
|
+
const failed = [];
|
|
25883
|
+
const candidates = [];
|
|
25884
|
+
for (const [index, source] of sources.entries()) {
|
|
25885
|
+
const known = [previous, ...Object.values(state.assets).filter((a) => a.jobId === jobId && a.provider === provider.id)].map((asset2) => asset2?.candidates[index]).find((candidate) => candidate && candidate.sourceUrl === storableUrl(source.url) && cachedCandidatePath(opts.cacheDir, candidate));
|
|
25886
|
+
if (known) {
|
|
25887
|
+
candidates.push(known);
|
|
25888
|
+
continue;
|
|
25889
|
+
}
|
|
25890
|
+
try {
|
|
25891
|
+
const cached2 = await downloadCandidate(provider, opts.cacheDir, source.url, `${key3} candidate ${index + 1}`);
|
|
25892
|
+
candidates.push({
|
|
25893
|
+
index,
|
|
25894
|
+
...source.role ? { role: source.role } : {},
|
|
25895
|
+
sourceUrl: storableUrl(source.url),
|
|
25896
|
+
...cached2,
|
|
25897
|
+
cachedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
25898
|
+
});
|
|
25899
|
+
} catch (err) {
|
|
25900
|
+
failed.push(err instanceof Error ? err.message : String(err));
|
|
25901
|
+
candidates.push({
|
|
25902
|
+
index,
|
|
25903
|
+
...source.role ? { role: source.role } : {},
|
|
25904
|
+
sourceUrl: storableUrl(source.url),
|
|
25905
|
+
sha256: null,
|
|
25906
|
+
mediaType: null,
|
|
25907
|
+
cachedAt: null
|
|
25908
|
+
});
|
|
25909
|
+
}
|
|
25910
|
+
}
|
|
25911
|
+
const asset = {
|
|
25912
|
+
provider: provider.id,
|
|
25913
|
+
jobId,
|
|
25914
|
+
...opts.generator ? { generator: opts.generator } : {},
|
|
25915
|
+
mode: job.status === "review" ? "candidates" : "frame-set",
|
|
25916
|
+
...job.status === "review-set" ? { fps: job.fps, objectId: job.objectId } : {},
|
|
25917
|
+
candidates,
|
|
25918
|
+
status: "pending",
|
|
25919
|
+
chosen: previous?.chosen ?? null,
|
|
25920
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
25921
|
+
};
|
|
25922
|
+
const latest = await loadReviewState(opts.statePath);
|
|
25923
|
+
latest.assets[key3] = asset;
|
|
25924
|
+
await saveReviewState(opts.statePath, latest);
|
|
25925
|
+
return { asset, failed };
|
|
25926
|
+
}
|
|
25927
|
+
async function ensureCandidatesCached(provider, key3, opts) {
|
|
25928
|
+
const state = await loadReviewState(opts.statePath);
|
|
25929
|
+
const asset = state.assets[key3];
|
|
25930
|
+
if (!asset) throw new Error(`${key3} has no recorded candidates to recover`);
|
|
25931
|
+
const missing = [];
|
|
25932
|
+
const candidates = [];
|
|
25933
|
+
for (const candidate of asset.candidates) {
|
|
25934
|
+
if (cachedCandidatePath(opts.cacheDir, candidate)) {
|
|
25935
|
+
candidates.push(candidate);
|
|
25936
|
+
continue;
|
|
25937
|
+
}
|
|
25938
|
+
if (!candidate.sourceUrl) {
|
|
25939
|
+
missing.push(`candidate ${candidate.index + 1} has no stored source URL`);
|
|
25940
|
+
candidates.push(candidate);
|
|
25941
|
+
continue;
|
|
25942
|
+
}
|
|
25943
|
+
try {
|
|
25944
|
+
const cached2 = await downloadCandidate(provider, opts.cacheDir, candidate.sourceUrl, `candidate ${candidate.index + 1}`);
|
|
25945
|
+
candidates.push({ ...candidate, ...cached2, cachedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
25946
|
+
} catch (err) {
|
|
25947
|
+
missing.push(err instanceof Error ? err.message : String(err));
|
|
25948
|
+
candidates.push(candidate);
|
|
25949
|
+
}
|
|
25950
|
+
}
|
|
25951
|
+
const next = { ...asset, candidates, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
25952
|
+
const latest = await loadReviewState(opts.statePath);
|
|
25953
|
+
latest.assets[key3] = next;
|
|
25954
|
+
await saveReviewState(opts.statePath, latest);
|
|
25955
|
+
if (missing.length) {
|
|
25956
|
+
throw new Error(
|
|
25957
|
+
`${key3}: job ${asset.jobId} expired on the provider before every candidate was cached (${missing.join("; ")}); re-run gen for this asset`
|
|
25958
|
+
);
|
|
25959
|
+
}
|
|
25960
|
+
return next;
|
|
25961
|
+
}
|
|
25768
25962
|
|
|
25769
25963
|
// src/pipeline/poll.ts
|
|
25770
25964
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -25815,6 +26009,16 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
25815
26009
|
billed: state.billed ?? entry.billed
|
|
25816
26010
|
});
|
|
25817
26011
|
result.review++;
|
|
26012
|
+
try {
|
|
26013
|
+
const { failed } = await cacheReviewCandidates(provider, key3, entry.jobId, state, {
|
|
26014
|
+
cacheDir: candidateCacheDirFor(lockPath),
|
|
26015
|
+
statePath: reviewStatePathFor(lockPath),
|
|
26016
|
+
generator: entry.generator
|
|
26017
|
+
});
|
|
26018
|
+
for (const message6 of failed) log2(` could not cache ${message6}`);
|
|
26019
|
+
} catch (err) {
|
|
26020
|
+
log2(` could not cache candidates for ${key3}: ${err instanceof Error ? err.message : String(err)}`);
|
|
26021
|
+
}
|
|
25818
26022
|
log2(
|
|
25819
26023
|
state.status === "review-set" ? ` review ${key3} (${state.frameUrls.length} ordered frames)` : ` review ${key3} (${state.candidateUrls.length} candidates)`
|
|
25820
26024
|
);
|
|
@@ -26230,13 +26434,13 @@ function ownedReferenceImageId(spec, lock, providerId) {
|
|
|
26230
26434
|
}
|
|
26231
26435
|
|
|
26232
26436
|
// src/pick/server.ts
|
|
26233
|
-
import { existsSync as
|
|
26234
|
-
import { readFile as
|
|
26437
|
+
import { existsSync as existsSync37 } from "fs";
|
|
26438
|
+
import { readFile as readFile33 } from "fs/promises";
|
|
26235
26439
|
|
|
26236
26440
|
// src/pipeline/init.ts
|
|
26237
|
-
import { readdir as readdir3, readFile as
|
|
26238
|
-
import { existsSync as
|
|
26239
|
-
import
|
|
26441
|
+
import { readdir as readdir3, readFile as readFile32, writeFile as writeFile23 } from "fs/promises";
|
|
26442
|
+
import { existsSync as existsSync36 } from "fs";
|
|
26443
|
+
import path44 from "path";
|
|
26240
26444
|
function pngSize(buf) {
|
|
26241
26445
|
if (buf.length < 24) return null;
|
|
26242
26446
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -26250,7 +26454,7 @@ function slugify(value) {
|
|
|
26250
26454
|
async function walk(dir, exclude) {
|
|
26251
26455
|
const out = [];
|
|
26252
26456
|
for (const entry of await readdir3(dir, { withFileTypes: true })) {
|
|
26253
|
-
const full =
|
|
26457
|
+
const full = path44.join(dir, entry.name);
|
|
26254
26458
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
26255
26459
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
26256
26460
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -26264,14 +26468,14 @@ async function scanAssets(root, opts = {}) {
|
|
|
26264
26468
|
const skipped = [];
|
|
26265
26469
|
const seen = /* @__PURE__ */ new Map();
|
|
26266
26470
|
for (const file of files.sort()) {
|
|
26267
|
-
const size = pngSize(await
|
|
26471
|
+
const size = pngSize(await readFile32(file));
|
|
26268
26472
|
if (!size) {
|
|
26269
26473
|
skipped.push(`${file} (not a readable PNG)`);
|
|
26270
26474
|
continue;
|
|
26271
26475
|
}
|
|
26272
|
-
const rel =
|
|
26273
|
-
const category =
|
|
26274
|
-
let id = slugify(
|
|
26476
|
+
const rel = path44.relative(root, file);
|
|
26477
|
+
const category = path44.dirname(rel) === "." ? "" : path44.dirname(rel);
|
|
26478
|
+
let id = slugify(path44.basename(rel));
|
|
26275
26479
|
if (seen.has(id)) {
|
|
26276
26480
|
const n = seen.get(id) + 1;
|
|
26277
26481
|
seen.set(id, n);
|
|
@@ -26329,10 +26533,10 @@ function mode(values) {
|
|
|
26329
26533
|
return [...counts.entries()].sort((a, b) => b[1] - a[1])[0]?.[0] ?? 64;
|
|
26330
26534
|
}
|
|
26331
26535
|
async function writeManifestFile(target, manifest) {
|
|
26332
|
-
if (
|
|
26536
|
+
if (existsSync36(target)) {
|
|
26333
26537
|
throw new Error(`${target} already exists; refusing to overwrite an existing manifest.`);
|
|
26334
26538
|
}
|
|
26335
|
-
await
|
|
26539
|
+
await writeFile23(target, JSON.stringify(manifest, null, 2) + "\n");
|
|
26336
26540
|
}
|
|
26337
26541
|
|
|
26338
26542
|
// src/pick/sheet.ts
|
|
@@ -26755,13 +26959,13 @@ async function currentArt(entry, spec) {
|
|
|
26755
26959
|
const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
|
|
26756
26960
|
if (!previous) return null;
|
|
26757
26961
|
const file = resolveOutputPath(previous.path, spec.root);
|
|
26758
|
-
if (!
|
|
26962
|
+
if (!existsSync37(file)) return null;
|
|
26759
26963
|
const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
|
|
26760
26964
|
if (!contentType) return null;
|
|
26761
26965
|
let width = entry.width;
|
|
26762
26966
|
let height = entry.height;
|
|
26763
26967
|
if (contentType === "image/png") {
|
|
26764
|
-
const size = pngSize(await
|
|
26968
|
+
const size = pngSize(await readFile33(file));
|
|
26765
26969
|
if (size) ({ width, height } = size);
|
|
26766
26970
|
}
|
|
26767
26971
|
return { path: file, contentType, width, height };
|
|
@@ -26769,7 +26973,7 @@ async function currentArt(entry, spec) {
|
|
|
26769
26973
|
async function cachedFrame(url) {
|
|
26770
26974
|
if (!url.startsWith("file://")) return null;
|
|
26771
26975
|
const file = url.slice("file://".length);
|
|
26772
|
-
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await
|
|
26976
|
+
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await readFile33(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
|
|
26773
26977
|
return { path: file, contentType };
|
|
26774
26978
|
}
|
|
26775
26979
|
async function prepareReview(provider, lock, opts = {}) {
|
|
@@ -26782,26 +26986,56 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
26782
26986
|
const reviewAssets = /* @__PURE__ */ new Map();
|
|
26783
26987
|
const prefix = opts.routePrefix ?? "";
|
|
26784
26988
|
const providerUrls = /* @__PURE__ */ new Map();
|
|
26989
|
+
const store = opts.lockPath ? { cacheDir: candidateCacheDirFor(opts.lockPath), statePath: reviewStatePathFor(opts.lockPath) } : null;
|
|
26990
|
+
const records = /* @__PURE__ */ new Map();
|
|
26785
26991
|
const groups = [];
|
|
26786
26992
|
for (const [key3, entry] of Object.entries(lock.entries)) {
|
|
26787
26993
|
if (entry.provider !== provider.id || selectedKeys && !selectedKeys.has(key3)) continue;
|
|
26788
26994
|
if (entry.status !== "review" || !entry.reviewObjectId) continue;
|
|
26789
26995
|
try {
|
|
26790
26996
|
const spec = specByKey.get(key3);
|
|
26791
|
-
const
|
|
26792
|
-
|
|
26793
|
-
|
|
26997
|
+
const jobId = entry.reviewObjectId;
|
|
26998
|
+
let polled = null;
|
|
26999
|
+
let pollError = null;
|
|
27000
|
+
try {
|
|
27001
|
+
polled = await provider.poll(jobId, entry.generator, { spec, metadata: entry.providerMetadata?.[provider.id] });
|
|
27002
|
+
} catch (err) {
|
|
27003
|
+
pollError = err;
|
|
27004
|
+
}
|
|
27005
|
+
const live = polled && (polled.status === "review" && polled.candidateUrls.length || polled.status === "review-set" && polled.frameUrls.length) ? polled : null;
|
|
27006
|
+
let record = null;
|
|
27007
|
+
if (store) {
|
|
27008
|
+
if (live) {
|
|
27009
|
+
const cached2 = await cacheReviewCandidates(provider, key3, jobId, live, { ...store, generator: entry.generator });
|
|
27010
|
+
for (const message6 of cached2.failed) log2(` could not cache ${message6}`);
|
|
27011
|
+
record = cached2.asset;
|
|
27012
|
+
} else {
|
|
27013
|
+
const saved = (await loadReviewState(store.statePath)).assets[key3];
|
|
27014
|
+
if (saved && saved.jobId === jobId && saved.provider === provider.id) {
|
|
27015
|
+
record = fullyCached(store.cacheDir, saved) ? saved : await ensureCandidatesCached(provider, key3, store);
|
|
27016
|
+
const why = pollError instanceof Error ? pollError.message : polled ? `job is ${polled.status}` : String(pollError);
|
|
27017
|
+
log2(` ${key3}: job no longer available upstream (${why}); using the cached candidates`);
|
|
27018
|
+
}
|
|
27019
|
+
}
|
|
27020
|
+
}
|
|
27021
|
+
if (!live && !record) {
|
|
27022
|
+
if (pollError) throw pollError;
|
|
27023
|
+
continue;
|
|
27024
|
+
}
|
|
27025
|
+
if (record) records.set(key3, record);
|
|
27026
|
+
const urls = live ? live.status === "review" ? live.candidateUrls : live.frameUrls : record.candidates.map((c) => c.sourceUrl ?? `file://${cachedCandidatePath(store.cacheDir, c)}`);
|
|
26794
27027
|
const frameUrls = [];
|
|
26795
27028
|
const frameAssets = [];
|
|
26796
27029
|
const frameSizes = [];
|
|
26797
27030
|
for (const [index, url] of urls.entries()) {
|
|
26798
|
-
const
|
|
27031
|
+
const local = record?.candidates[index] && store ? cachedCandidatePath(store.cacheDir, record.candidates[index]) : null;
|
|
27032
|
+
const cached2 = local ? { path: local, contentType: record.candidates[index].mediaType ?? "application/octet-stream" } : await cachedFrame(url);
|
|
26799
27033
|
if (!cached2) {
|
|
26800
27034
|
frameUrls.push(url);
|
|
26801
27035
|
frameSizes.push(null);
|
|
26802
27036
|
continue;
|
|
26803
27037
|
}
|
|
26804
|
-
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await
|
|
27038
|
+
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await readFile33(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
26805
27039
|
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
26806
27040
|
frameAssets.push([route, cached2]);
|
|
26807
27041
|
frameUrls.push(route);
|
|
@@ -26830,10 +27064,14 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
26830
27064
|
...frameSizes.some(Boolean) ? { frameSizes } : {},
|
|
26831
27065
|
width: entry.width,
|
|
26832
27066
|
height: entry.height,
|
|
26833
|
-
...
|
|
27067
|
+
...live?.status === "review-set" ? {
|
|
26834
27068
|
mode: "frame-set",
|
|
26835
|
-
frameLabels:
|
|
26836
|
-
fps:
|
|
27069
|
+
frameLabels: live.sources.map((source, index) => source.role ?? `frame-${index}`),
|
|
27070
|
+
fps: live.fps
|
|
27071
|
+
} : !live && record?.mode === "frame-set" ? {
|
|
27072
|
+
mode: "frame-set",
|
|
27073
|
+
frameLabels: record.candidates.map((c, index) => c.role ?? `frame-${index}`),
|
|
27074
|
+
fps: record.fps ?? 12
|
|
26837
27075
|
} : { mode: "candidates" },
|
|
26838
27076
|
...sourceRoute && spec?.revision && spec.revision.sourceWidth && spec.revision.sourceHeight ? {
|
|
26839
27077
|
revision: {
|
|
@@ -26856,6 +27094,30 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
26856
27094
|
}
|
|
26857
27095
|
if (groups.length === 0) return null;
|
|
26858
27096
|
const byKey = new Map(groups.map((g) => [g.key, g]));
|
|
27097
|
+
const localCandidate = (key3, jobId, index) => {
|
|
27098
|
+
const record = records.get(key3);
|
|
27099
|
+
const candidate = record?.jobId === jobId ? record.candidates[index] : void 0;
|
|
27100
|
+
const file = store && candidate ? cachedCandidatePath(store.cacheDir, candidate) : null;
|
|
27101
|
+
return file ? `file://${file}` : null;
|
|
27102
|
+
};
|
|
27103
|
+
const localFrameSet = (key3, jobId) => {
|
|
27104
|
+
const record = records.get(key3);
|
|
27105
|
+
if (!record || record.jobId !== jobId || record.mode !== "frame-set" || !store || !fullyCached(store.cacheDir, record)) return null;
|
|
27106
|
+
const sources = record.candidates.map((c) => ({
|
|
27107
|
+
url: `file://${cachedCandidatePath(store.cacheDir, c)}`,
|
|
27108
|
+
...c.role ? { role: c.role } : {}
|
|
27109
|
+
}));
|
|
27110
|
+
return {
|
|
27111
|
+
status: "review-set",
|
|
27112
|
+
objectId: record.objectId ?? jobId,
|
|
27113
|
+
sources,
|
|
27114
|
+
metadata: void 0
|
|
27115
|
+
};
|
|
27116
|
+
};
|
|
27117
|
+
const markApplied = async (key3, index) => {
|
|
27118
|
+
if (!store || !records.has(key3)) return;
|
|
27119
|
+
await updateReviewAsset(store.statePath, key3, (asset) => ({ ...asset, status: "applied", chosen: index }));
|
|
27120
|
+
};
|
|
26859
27121
|
return {
|
|
26860
27122
|
groups,
|
|
26861
27123
|
assets: reviewAssets,
|
|
@@ -26870,9 +27132,10 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
26870
27132
|
if (!Number.isInteger(index) || index < 0 || index >= group.frameUrls.length) continue;
|
|
26871
27133
|
if (group.mode === "frame-set") {
|
|
26872
27134
|
const spec = specByKey.get(key3);
|
|
26873
|
-
const
|
|
26874
|
-
|
|
26875
|
-
|
|
27135
|
+
const live = await provider.poll(entry.reviewObjectId, entry.generator, { spec, metadata: entry.providerMetadata?.[provider.id] }).catch(() => null);
|
|
27136
|
+
const state = live?.status === "review-set" ? live : localFrameSet(key3, entry.reviewObjectId);
|
|
27137
|
+
if (!state) {
|
|
27138
|
+
throw new Error(`Frame set ${key3} is no longer ready for review and has no cached frames`);
|
|
26876
27139
|
}
|
|
26877
27140
|
upsert(lock, key3, {
|
|
26878
27141
|
status: "selected",
|
|
@@ -26890,15 +27153,28 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
26890
27153
|
} : entry.providerMetadata
|
|
26891
27154
|
});
|
|
26892
27155
|
selected++;
|
|
26893
|
-
|
|
27156
|
+
await markApplied(key3, index);
|
|
27157
|
+
log2(` accepted ${key3} \u2192 ${state.sources.length} ordered frames${live?.status === "review-set" ? "" : " (from the local cache)"}`);
|
|
26894
27158
|
continue;
|
|
26895
27159
|
}
|
|
26896
|
-
|
|
26897
|
-
|
|
26898
|
-
|
|
26899
|
-
|
|
26900
|
-
|
|
26901
|
-
|
|
27160
|
+
let selection;
|
|
27161
|
+
let fromCache = false;
|
|
27162
|
+
try {
|
|
27163
|
+
selection = await requireSelectCandidate(provider)(
|
|
27164
|
+
entry.reviewObjectId,
|
|
27165
|
+
index,
|
|
27166
|
+
`asset:${entry.assetId}`,
|
|
27167
|
+
entry.generator
|
|
27168
|
+
);
|
|
27169
|
+
} catch (err) {
|
|
27170
|
+
const local = localCandidate(key3, entry.reviewObjectId, index);
|
|
27171
|
+
if (!local) throw err;
|
|
27172
|
+
log2(` ${key3}: promotion failed upstream (${err instanceof Error ? err.message : String(err)}); using the cached candidate`);
|
|
27173
|
+
selection = { objectId: `${entry.reviewObjectId}#${index}`, sourceUrl: local };
|
|
27174
|
+
fromCache = true;
|
|
27175
|
+
}
|
|
27176
|
+
const { objectId, metadata } = selection;
|
|
27177
|
+
const sourceUrl = fromCache ? selection.sourceUrl : selection.sourceUrl ?? localCandidate(key3, entry.reviewObjectId, index);
|
|
26902
27178
|
upsert(lock, key3, {
|
|
26903
27179
|
status: "selected",
|
|
26904
27180
|
objectId,
|
|
@@ -26915,7 +27191,8 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
26915
27191
|
} : entry.providerMetadata
|
|
26916
27192
|
});
|
|
26917
27193
|
selected++;
|
|
26918
|
-
|
|
27194
|
+
await markApplied(key3, index);
|
|
27195
|
+
log2(` picked ${key3} \u2192 candidate ${index + 1}${fromCache ? " (from the local cache)" : ""}`);
|
|
26919
27196
|
}
|
|
26920
27197
|
await saveLock(lockPath, lock);
|
|
26921
27198
|
return { selected, skipped: groups.length - selected };
|
|
@@ -26925,19 +27202,33 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
26925
27202
|
async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
26926
27203
|
const log2 = opts.onProgress ?? (() => {
|
|
26927
27204
|
});
|
|
26928
|
-
|
|
27205
|
+
let session = await prepareReview(provider, lock, {
|
|
26929
27206
|
onProgress: log2,
|
|
26930
27207
|
keys: opts.keys,
|
|
26931
|
-
specs: opts.specs
|
|
27208
|
+
specs: opts.specs,
|
|
27209
|
+
lockPath
|
|
26932
27210
|
});
|
|
26933
27211
|
if (!session) return { selected: 0, skipped: 0 };
|
|
26934
|
-
|
|
26935
|
-
|
|
26936
|
-
|
|
27212
|
+
let autoSelected = 0;
|
|
27213
|
+
if (opts.autoAcceptSingle) {
|
|
27214
|
+
const singles = session.groups.filter((g) => g.mode === "frame-set" || g.frameUrls.length === 1);
|
|
27215
|
+
if (singles.length) {
|
|
27216
|
+
const res = await session.apply({ selections: singles.map((g) => ({ key: g.key, index: 0 })) }, lockPath);
|
|
27217
|
+
autoSelected = res.selected;
|
|
27218
|
+
log2(` --yes: accepted ${res.selected} single-candidate asset(s)`);
|
|
27219
|
+
const rest = session.groups.filter((g) => !singles.includes(g)).map((g) => g.key);
|
|
27220
|
+
session = rest.length ? await prepareReview(provider, lock, { onProgress: log2, keys: rest, specs: opts.specs }) : null;
|
|
27221
|
+
if (!session) return { selected: autoSelected, skipped: 0 };
|
|
27222
|
+
}
|
|
27223
|
+
}
|
|
27224
|
+
const live = session;
|
|
27225
|
+
const groups = live.groups;
|
|
27226
|
+
const served = await serveReviewPage({
|
|
27227
|
+
html: live.html(),
|
|
26937
27228
|
port: opts.port,
|
|
26938
27229
|
open: opts.open,
|
|
26939
27230
|
onProgress: log2,
|
|
26940
|
-
assets:
|
|
27231
|
+
assets: live.assets,
|
|
26941
27232
|
onReady: (url) => {
|
|
26942
27233
|
const info = { url, keys: groups.map((group) => group.key) };
|
|
26943
27234
|
if (opts.onReady) {
|
|
@@ -26949,31 +27240,32 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
26949
27240
|
`);
|
|
26950
27241
|
}
|
|
26951
27242
|
},
|
|
26952
|
-
handleApply: (body) =>
|
|
27243
|
+
handleApply: (body) => live.apply(body, lockPath)
|
|
26953
27244
|
});
|
|
27245
|
+
return { selected: served.selected + autoSelected, skipped: served.skipped };
|
|
26954
27246
|
}
|
|
26955
27247
|
|
|
26956
27248
|
// src/gallery/generate.ts
|
|
26957
|
-
var GenerateRequestSchema =
|
|
26958
|
-
project:
|
|
26959
|
-
keys:
|
|
27249
|
+
var GenerateRequestSchema = z16.object({
|
|
27250
|
+
project: z16.string().min(1).optional(),
|
|
27251
|
+
keys: z16.array(z16.string().min(1)).min(1).max(500),
|
|
26960
27252
|
/**
|
|
26961
27253
|
* Regenerate work that is up to date, as `gen --force` does, and let the
|
|
26962
27254
|
* fetch replace a locally modified or untracked file. With `restore`, put
|
|
26963
27255
|
* the recorded bytes back over a modified file.
|
|
26964
27256
|
*/
|
|
26965
|
-
force:
|
|
27257
|
+
force: z16.boolean().optional(),
|
|
26966
27258
|
/** Advance in-flight, review, or selected work without submitting anything. */
|
|
26967
|
-
resume:
|
|
27259
|
+
resume: z16.boolean().optional(),
|
|
26968
27260
|
/** Re-download downloaded outputs and replace files whose object changed upstream. */
|
|
26969
|
-
refresh:
|
|
27261
|
+
refresh: z16.boolean().optional(),
|
|
26970
27262
|
/** Put recorded outputs back on disk from the cache or the provider, without generating. */
|
|
26971
|
-
restore:
|
|
27263
|
+
restore: z16.boolean().optional(),
|
|
26972
27264
|
/**
|
|
26973
27265
|
* Bring a replaced generation back: 1-based position in the record's
|
|
26974
27266
|
* history (newest first) or an output hash prefix. One key at a time.
|
|
26975
27267
|
*/
|
|
26976
|
-
revert:
|
|
27268
|
+
revert: z16.string().min(1).max(64).optional()
|
|
26977
27269
|
}).strict().refine((request) => [request.resume, request.refresh, request.restore, request.revert !== void 0].filter(Boolean).length <= 1, {
|
|
26978
27270
|
message: "resume, refresh, restore, and revert are exclusive"
|
|
26979
27271
|
}).refine((request) => request.revert === void 0 || request.keys.length === 1, { message: "revert takes one key" });
|
|
@@ -27293,7 +27585,8 @@ function createGenerateHandlers(opts) {
|
|
|
27293
27585
|
keys: job.review,
|
|
27294
27586
|
specs,
|
|
27295
27587
|
onProgress: (line) => say(job, line),
|
|
27296
|
-
routePrefix: options.routePrefix
|
|
27588
|
+
routePrefix: options.routePrefix,
|
|
27589
|
+
lockPath: ctx.lockPath
|
|
27297
27590
|
});
|
|
27298
27591
|
if (session) reviews.set(jobId, session);
|
|
27299
27592
|
return session;
|
|
@@ -27319,15 +27612,15 @@ function createGenerateHandlers(opts) {
|
|
|
27319
27612
|
}
|
|
27320
27613
|
|
|
27321
27614
|
// src/gallery/editor.ts
|
|
27322
|
-
import { readFile as
|
|
27323
|
-
import
|
|
27615
|
+
import { readFile as readFile35 } from "fs/promises";
|
|
27616
|
+
import path46 from "path";
|
|
27324
27617
|
|
|
27325
27618
|
// src/editor/install.ts
|
|
27326
27619
|
import { createHash as createHash6 } from "crypto";
|
|
27327
|
-
import { existsSync as
|
|
27328
|
-
import { mkdir as
|
|
27620
|
+
import { existsSync as existsSync38 } from "fs";
|
|
27621
|
+
import { mkdir as mkdir19, readFile as readFile34, rename as rename14, rm as rm13, stat as stat4, writeFile as writeFile24 } from "fs/promises";
|
|
27329
27622
|
import os3 from "os";
|
|
27330
|
-
import
|
|
27623
|
+
import path45 from "path";
|
|
27331
27624
|
|
|
27332
27625
|
// tools/pixelorama-bridge/pin.json
|
|
27333
27626
|
var pin_default = {
|
|
@@ -27391,15 +27684,15 @@ var EditorInstallError = class extends Error {
|
|
|
27391
27684
|
};
|
|
27392
27685
|
function editorToolsRoot() {
|
|
27393
27686
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
27394
|
-
if (override) return
|
|
27395
|
-
if (process.platform === "darwin") return
|
|
27687
|
+
if (override) return path45.resolve(override);
|
|
27688
|
+
if (process.platform === "darwin") return path45.join(os3.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
27396
27689
|
if (process.platform === "win32") {
|
|
27397
|
-
return
|
|
27690
|
+
return path45.join(process.env.LOCALAPPDATA ?? path45.join(os3.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
27398
27691
|
}
|
|
27399
|
-
return
|
|
27692
|
+
return path45.join(process.env.XDG_CACHE_HOME ?? path45.join(os3.homedir(), ".cache"), "pixelkiln", "tools");
|
|
27400
27693
|
}
|
|
27401
27694
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
27402
|
-
return
|
|
27695
|
+
return path45.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
27403
27696
|
}
|
|
27404
27697
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
27405
27698
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -27409,7 +27702,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
|
|
|
27409
27702
|
}
|
|
27410
27703
|
async function sha256Of(file) {
|
|
27411
27704
|
try {
|
|
27412
|
-
return createHash6("sha256").update(await
|
|
27705
|
+
return createHash6("sha256").update(await readFile34(file)).digest("hex");
|
|
27413
27706
|
} catch {
|
|
27414
27707
|
return null;
|
|
27415
27708
|
}
|
|
@@ -27422,8 +27715,8 @@ async function editorStatus(opts = {}) {
|
|
|
27422
27715
|
let totalBytes = 0;
|
|
27423
27716
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
27424
27717
|
totalBytes += expected.bytes;
|
|
27425
|
-
const file =
|
|
27426
|
-
const info =
|
|
27718
|
+
const file = path45.join(dir, name);
|
|
27719
|
+
const info = existsSync38(file) ? await stat4(file).catch(() => null) : null;
|
|
27427
27720
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
27428
27721
|
installedBytes += expected.bytes;
|
|
27429
27722
|
} else {
|
|
@@ -27452,7 +27745,7 @@ async function installEditor(opts = {}) {
|
|
|
27452
27745
|
);
|
|
27453
27746
|
}
|
|
27454
27747
|
if (!baseUrl) throw new EditorInstallError("no download location for the editor build");
|
|
27455
|
-
await
|
|
27748
|
+
await mkdir19(dir, { recursive: true });
|
|
27456
27749
|
const downloaded = [];
|
|
27457
27750
|
const skipped = Object.keys(pin.files).filter((name) => !before.missing.includes(name));
|
|
27458
27751
|
let fetchedBytes = before.installedBytes;
|
|
@@ -27480,13 +27773,13 @@ async function installEditor(opts = {}) {
|
|
|
27480
27773
|
if (digest2 !== expected.sha256) {
|
|
27481
27774
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
27482
27775
|
}
|
|
27483
|
-
const final =
|
|
27776
|
+
const final = path45.join(dir, name);
|
|
27484
27777
|
const tmp = `${final}.${process.pid}.part`;
|
|
27485
27778
|
try {
|
|
27486
|
-
await
|
|
27487
|
-
await
|
|
27779
|
+
await writeFile24(tmp, bytes);
|
|
27780
|
+
await rename14(tmp, final);
|
|
27488
27781
|
} finally {
|
|
27489
|
-
await
|
|
27782
|
+
await rm13(tmp, { force: true });
|
|
27490
27783
|
}
|
|
27491
27784
|
fetchedBytes += bytes.length;
|
|
27492
27785
|
downloaded.push(name);
|
|
@@ -27526,7 +27819,7 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
27526
27819
|
".json": "application/json; charset=utf-8"
|
|
27527
27820
|
};
|
|
27528
27821
|
function editorContentType(name) {
|
|
27529
|
-
return EDITOR_CONTENT_TYPES[
|
|
27822
|
+
return EDITOR_CONTENT_TYPES[path45.extname(name).toLowerCase()] ?? null;
|
|
27530
27823
|
}
|
|
27531
27824
|
|
|
27532
27825
|
// src/gallery/editor.ts
|
|
@@ -27602,7 +27895,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
27602
27895
|
if (!status.installed) return null;
|
|
27603
27896
|
let bytes;
|
|
27604
27897
|
try {
|
|
27605
|
-
bytes = await
|
|
27898
|
+
bytes = await readFile35(path46.join(dir, name));
|
|
27606
27899
|
} catch {
|
|
27607
27900
|
verified = null;
|
|
27608
27901
|
return null;
|
|
@@ -27642,7 +27935,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
27642
27935
|
};
|
|
27643
27936
|
const loadProject = async (project2) => {
|
|
27644
27937
|
const ctx = await access2.loadProject(project2);
|
|
27645
|
-
loadProjectEnv(
|
|
27938
|
+
loadProjectEnv(path47.dirname(ctx.loaded.path));
|
|
27646
27939
|
return ctx;
|
|
27647
27940
|
};
|
|
27648
27941
|
const loadProjectEnv = (dir) => {
|
|
@@ -27651,7 +27944,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
27651
27944
|
for (const [name, value] of Object.entries(declared)) {
|
|
27652
27945
|
if (credentialNames.has(name) && name in process.env && process.env[name] !== value) {
|
|
27653
27946
|
throw new Error(
|
|
27654
|
-
`${
|
|
27947
|
+
`${path47.relative(process.cwd(), dir) || "."} sets ${name} to a different value than the one this gallery already loaded; run a separate gallery for that project so its work uses its own account.`
|
|
27655
27948
|
);
|
|
27656
27949
|
}
|
|
27657
27950
|
}
|
|
@@ -27659,7 +27952,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
27659
27952
|
};
|
|
27660
27953
|
const quoters = /* @__PURE__ */ new Map();
|
|
27661
27954
|
const quoteFor = async (project2) => {
|
|
27662
|
-
loadProjectEnv(
|
|
27955
|
+
loadProjectEnv(path47.dirname(path47.resolve(await access2.manifestFor(project2))));
|
|
27663
27956
|
const key3 = process.env.PIXELLAB_API_KEY;
|
|
27664
27957
|
if (!key3) return null;
|
|
27665
27958
|
let quoter = quoters.get(key3);
|
|
@@ -27710,8 +28003,8 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
27710
28003
|
}
|
|
27711
28004
|
async function runGallery(args) {
|
|
27712
28005
|
if (args.workspace) {
|
|
27713
|
-
const workspacePath =
|
|
27714
|
-
if (!
|
|
28006
|
+
const workspacePath = path47.resolve(args.workspace);
|
|
28007
|
+
if (!existsSync39(workspacePath)) {
|
|
27715
28008
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
27716
28009
|
}
|
|
27717
28010
|
const filter2 = { styles: args.styles, assets: args.assets };
|
|
@@ -27731,7 +28024,7 @@ async function runGallery(args) {
|
|
|
27731
28024
|
const registered = async (projectId) => {
|
|
27732
28025
|
const project2 = (await loadWorkspace(workspacePath)).projects.find((candidate) => candidate.id === projectId);
|
|
27733
28026
|
if (!projectId || !project2) throw new Error(`unknown workspace project "${projectId ?? ""}"`);
|
|
27734
|
-
return resolveProject(
|
|
28027
|
+
return resolveProject(path47.dirname(workspacePath), project2);
|
|
27735
28028
|
};
|
|
27736
28029
|
await serveUntilStopped(initial, build2, args, {
|
|
27737
28030
|
manifestFor: async (projectId) => (await registered(projectId)).manifestPath,
|
|
@@ -27756,7 +28049,7 @@ async function runGallery(args) {
|
|
|
27756
28049
|
return buildGallerySnapshot({ ...fresh, filter });
|
|
27757
28050
|
};
|
|
27758
28051
|
await serveUntilStopped(await build(), reload, args, {
|
|
27759
|
-
manifestFor: () =>
|
|
28052
|
+
manifestFor: () => path47.resolve(args.manifest),
|
|
27760
28053
|
loadProject: () => openProject(args.manifest, { lockPath: args.lock, env: false })
|
|
27761
28054
|
});
|
|
27762
28055
|
}
|
|
@@ -27937,6 +28230,7 @@ async function runLifecycle(args, wave, spent) {
|
|
|
27937
28230
|
open: !args.noOpen,
|
|
27938
28231
|
onProgress: log,
|
|
27939
28232
|
onReady: announceReviewReady,
|
|
28233
|
+
autoAcceptSingle: args.yes,
|
|
27940
28234
|
keys: providerSpecsForRun.map((spec) => lockKey(spec.styleId, spec.assetId)),
|
|
27941
28235
|
specs: providerSpecsForRun
|
|
27942
28236
|
});
|
|
@@ -28073,18 +28367,18 @@ async function runRestoreGeneration(args) {
|
|
|
28073
28367
|
}
|
|
28074
28368
|
|
|
28075
28369
|
// src/cli/commands/housekeeping.ts
|
|
28076
|
-
import { existsSync as
|
|
28370
|
+
import { existsSync as existsSync41 } from "fs";
|
|
28077
28371
|
|
|
28078
28372
|
// src/pipeline/cache-health.ts
|
|
28079
|
-
import { existsSync as
|
|
28080
|
-
import { readFile as
|
|
28081
|
-
import
|
|
28373
|
+
import { existsSync as existsSync40 } from "fs";
|
|
28374
|
+
import { readFile as readFile36, readdir as readdir4, rm as rm14 } from "fs/promises";
|
|
28375
|
+
import path48 from "path";
|
|
28082
28376
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
28083
|
-
if (options.prune && !
|
|
28084
|
-
throw new Error(`Refusing to prune without an existing lockfile at ${
|
|
28377
|
+
if (options.prune && !existsSync40(lockPath)) {
|
|
28378
|
+
throw new Error(`Refusing to prune without an existing lockfile at ${path48.resolve(lockPath)}`);
|
|
28085
28379
|
}
|
|
28086
|
-
const contentDir =
|
|
28087
|
-
const remotePath =
|
|
28380
|
+
const contentDir = path48.resolve(path48.dirname(lockPath), ".pixelkiln", "cache");
|
|
28381
|
+
const remotePath = path48.resolve(cachePathFor(lockPath));
|
|
28088
28382
|
const referenced = referencedHashes(lock);
|
|
28089
28383
|
let content = await inspectContentCache(contentDir, referenced);
|
|
28090
28384
|
let remoteHashes = await inspectRemoteHashCache(remotePath);
|
|
@@ -28096,7 +28390,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
28096
28390
|
]);
|
|
28097
28391
|
for (const name of names) {
|
|
28098
28392
|
try {
|
|
28099
|
-
await
|
|
28393
|
+
await rm14(path48.join(contentDir, name), { force: true });
|
|
28100
28394
|
removed.contentFiles++;
|
|
28101
28395
|
} catch {
|
|
28102
28396
|
}
|
|
@@ -28105,7 +28399,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
28105
28399
|
await saveCache(remotePath, { version: 1, hashes: {} });
|
|
28106
28400
|
removed.resetRemoteHashCache = true;
|
|
28107
28401
|
} else if (remoteHashes.invalidIds.length) {
|
|
28108
|
-
const cache = parseCache(JSON.parse(await
|
|
28402
|
+
const cache = parseCache(JSON.parse(await readFile36(remotePath, "utf8")));
|
|
28109
28403
|
for (const id of remoteHashes.invalidIds) delete cache.hashes[id];
|
|
28110
28404
|
removed.remoteHashEntries = remoteHashes.invalidIds.length;
|
|
28111
28405
|
await saveCache(remotePath, cache);
|
|
@@ -28123,7 +28417,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
28123
28417
|
async function inspectContentCache(contentDir, referenced) {
|
|
28124
28418
|
const report = {
|
|
28125
28419
|
path: contentDir,
|
|
28126
|
-
exists:
|
|
28420
|
+
exists: existsSync40(contentDir),
|
|
28127
28421
|
files: 0,
|
|
28128
28422
|
bytes: 0,
|
|
28129
28423
|
valid: 0,
|
|
@@ -28144,12 +28438,12 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
28144
28438
|
continue;
|
|
28145
28439
|
}
|
|
28146
28440
|
report.files++;
|
|
28147
|
-
const file =
|
|
28441
|
+
const file = path48.join(contentDir, entry.name);
|
|
28148
28442
|
const mediaType = mediaTypeFromExtension(entry.name);
|
|
28149
28443
|
const expected = mediaType ? entry.name.slice(0, -4) : "";
|
|
28150
28444
|
let bytes;
|
|
28151
28445
|
try {
|
|
28152
|
-
bytes = await
|
|
28446
|
+
bytes = await readFile36(file);
|
|
28153
28447
|
report.bytes += bytes.length;
|
|
28154
28448
|
} catch (err) {
|
|
28155
28449
|
report.invalid.push({
|
|
@@ -28187,7 +28481,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
28187
28481
|
async function inspectRemoteHashCache(remotePath) {
|
|
28188
28482
|
const report = {
|
|
28189
28483
|
path: remotePath,
|
|
28190
|
-
exists:
|
|
28484
|
+
exists: existsSync40(remotePath),
|
|
28191
28485
|
entries: 0,
|
|
28192
28486
|
valid: 0,
|
|
28193
28487
|
invalidIds: [],
|
|
@@ -28196,7 +28490,7 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
28196
28490
|
if (!report.exists) return report;
|
|
28197
28491
|
let cache;
|
|
28198
28492
|
try {
|
|
28199
|
-
cache = parseCache(JSON.parse(await
|
|
28493
|
+
cache = parseCache(JSON.parse(await readFile36(remotePath, "utf8")));
|
|
28200
28494
|
} catch (err) {
|
|
28201
28495
|
report.error = err instanceof Error ? err.message : String(err);
|
|
28202
28496
|
return report;
|
|
@@ -28260,7 +28554,7 @@ async function runAccept(args) {
|
|
|
28260
28554
|
let intact = true;
|
|
28261
28555
|
for (const output of entry.outputs) {
|
|
28262
28556
|
const file = resolveOutputPath(output.path, item.spec.root);
|
|
28263
|
-
if (!
|
|
28557
|
+
if (!existsSync41(file) || await sha256File(file) !== output.sha256) {
|
|
28264
28558
|
intact = false;
|
|
28265
28559
|
break;
|
|
28266
28560
|
}
|
|
@@ -28315,46 +28609,46 @@ This drops their provenance from the lockfile. The art on disk is`);
|
|
|
28315
28609
|
}
|
|
28316
28610
|
|
|
28317
28611
|
// src/cli/commands/init.ts
|
|
28318
|
-
import
|
|
28319
|
-
import { existsSync as
|
|
28612
|
+
import path49 from "path";
|
|
28613
|
+
import { existsSync as existsSync42 } from "fs";
|
|
28320
28614
|
async function runInit(args) {
|
|
28321
28615
|
if (!args.from) throw new Error("init needs --from <dir> pointing at your existing PNGs.");
|
|
28322
|
-
const root =
|
|
28323
|
-
if (!
|
|
28616
|
+
const root = path49.resolve(args.from);
|
|
28617
|
+
if (!existsSync42(root)) throw new Error(`No directory at ${root}`);
|
|
28324
28618
|
const generator = args.generator ?? "map";
|
|
28325
28619
|
if (generator !== "1dir" && generator !== "map") {
|
|
28326
28620
|
throw new Error(`--generator must be "1dir" or "map", got "${args.generator}".`);
|
|
28327
28621
|
}
|
|
28328
|
-
const target =
|
|
28622
|
+
const target = path49.resolve(args.out ?? "pixelkiln.manifest.json");
|
|
28329
28623
|
const { assets, skipped } = await scanAssets(root, { exclude: args.exclude });
|
|
28330
28624
|
if (!assets.length) throw new Error(`No PNGs found under ${root}`);
|
|
28331
28625
|
const manifest = buildManifest(
|
|
28332
|
-
args.name ??
|
|
28626
|
+
args.name ?? path49.basename(path49.dirname(target)),
|
|
28333
28627
|
args.styles[0] ?? "base",
|
|
28334
28628
|
generator,
|
|
28335
|
-
|
|
28629
|
+
path49.relative(path49.dirname(target), root) || ".",
|
|
28336
28630
|
assets
|
|
28337
28631
|
);
|
|
28338
28632
|
await writeManifestFile(target, manifest);
|
|
28339
|
-
log(` scanned ${assets.length} PNG(s) under ${
|
|
28633
|
+
log(` scanned ${assets.length} PNG(s) under ${path49.relative(process.cwd(), root)}`);
|
|
28340
28634
|
if (skipped.length) log(` skipped ${skipped.length} unreadable file(s)`);
|
|
28341
|
-
log(` wrote ${
|
|
28635
|
+
log(` wrote ${path49.relative(process.cwd(), target)}`);
|
|
28342
28636
|
log(`
|
|
28343
28637
|
Prompts are intentionally empty. To recover the real ones from your`);
|
|
28344
28638
|
log(` PixelLab account instead of inventing them:`);
|
|
28345
28639
|
log(`
|
|
28346
|
-
pixelkiln adopt --manifest ${
|
|
28640
|
+
pixelkiln adopt --manifest ${path49.relative(process.cwd(), target)} --write-prompts
|
|
28347
28641
|
`);
|
|
28348
28642
|
}
|
|
28349
28643
|
|
|
28350
28644
|
// src/pipeline/doctor.ts
|
|
28351
|
-
import { constants, existsSync as
|
|
28645
|
+
import { constants, existsSync as existsSync44 } from "fs";
|
|
28352
28646
|
import { access, stat as stat5 } from "fs/promises";
|
|
28353
|
-
import
|
|
28647
|
+
import path51 from "path";
|
|
28354
28648
|
|
|
28355
28649
|
// src/pipeline/install-check.ts
|
|
28356
|
-
import { existsSync as
|
|
28357
|
-
import
|
|
28650
|
+
import { existsSync as existsSync43, readFileSync as readFileSync7 } from "fs";
|
|
28651
|
+
import path50 from "path";
|
|
28358
28652
|
function readJson(file) {
|
|
28359
28653
|
try {
|
|
28360
28654
|
return JSON.parse(readFileSync7(file, "utf8"));
|
|
@@ -28363,19 +28657,19 @@ function readJson(file) {
|
|
|
28363
28657
|
}
|
|
28364
28658
|
}
|
|
28365
28659
|
function readInstallFacts(manifestDir, running) {
|
|
28366
|
-
let dir =
|
|
28660
|
+
let dir = path50.resolve(manifestDir);
|
|
28367
28661
|
for (let depth = 0; depth < 4; depth++) {
|
|
28368
|
-
const pkg = readJson(
|
|
28662
|
+
const pkg = readJson(path50.join(dir, "package.json"));
|
|
28369
28663
|
if (pkg) {
|
|
28370
28664
|
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
28371
28665
|
if (pinned) {
|
|
28372
|
-
const installedPkg = readJson(
|
|
28666
|
+
const installedPkg = readJson(path50.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
28373
28667
|
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
28374
28668
|
return { pinned, installed, running };
|
|
28375
28669
|
}
|
|
28376
28670
|
}
|
|
28377
|
-
const parent =
|
|
28378
|
-
if (parent === dir || !
|
|
28671
|
+
const parent = path50.dirname(dir);
|
|
28672
|
+
if (parent === dir || !existsSync43(parent)) break;
|
|
28379
28673
|
dir = parent;
|
|
28380
28674
|
}
|
|
28381
28675
|
return null;
|
|
@@ -28438,12 +28732,12 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
28438
28732
|
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
28439
28733
|
);
|
|
28440
28734
|
}
|
|
28441
|
-
const facts = readInstallFacts(
|
|
28735
|
+
const facts = readInstallFacts(path51.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
28442
28736
|
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
28443
28737
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
28444
28738
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
28445
|
-
|
|
28446
|
-
...spec.quality ? [
|
|
28739
|
+
path51.dirname(spec.outFile),
|
|
28740
|
+
...spec.quality ? [path51.dirname(spec.quality.outFile)] : []
|
|
28447
28741
|
]))];
|
|
28448
28742
|
const unwritable = [];
|
|
28449
28743
|
for (const dir of dirs) {
|
|
@@ -28466,7 +28760,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
28466
28760
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
28467
28761
|
const output = entry.outputs[index];
|
|
28468
28762
|
const spec = specByKey.get(key3);
|
|
28469
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
28763
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, path51.dirname(lockPath));
|
|
28470
28764
|
const owner = outputOwners.get(absolute);
|
|
28471
28765
|
if (owner && owner !== key3) duplicateOutputs.push(`${output.path} (${owner}, ${key3})`);
|
|
28472
28766
|
outputOwners.set(absolute, key3);
|
|
@@ -28481,7 +28775,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
28481
28775
|
} else {
|
|
28482
28776
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
28483
28777
|
}
|
|
28484
|
-
const cacheDir =
|
|
28778
|
+
const cacheDir = path51.join(path51.dirname(lockPath), ".pixelkiln", "cache");
|
|
28485
28779
|
const stranded = [];
|
|
28486
28780
|
const invalidState = [];
|
|
28487
28781
|
const staleMapUrls = [];
|
|
@@ -28497,11 +28791,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
28497
28791
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
28498
28792
|
let hasCache = false;
|
|
28499
28793
|
for (const output of entry.outputs) {
|
|
28500
|
-
const cached2 =
|
|
28794
|
+
const cached2 = path51.join(
|
|
28501
28795
|
cacheDir,
|
|
28502
28796
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
28503
28797
|
);
|
|
28504
|
-
if (
|
|
28798
|
+
if (existsSync44(cached2) && await sha256File(cached2) === output.sha256) {
|
|
28505
28799
|
hasCache = true;
|
|
28506
28800
|
break;
|
|
28507
28801
|
}
|
|
@@ -28597,16 +28891,16 @@ async function nearestExistingDirectory(start) {
|
|
|
28597
28891
|
if ((await stat5(current)).isDirectory()) return current;
|
|
28598
28892
|
} catch {
|
|
28599
28893
|
}
|
|
28600
|
-
const parent =
|
|
28894
|
+
const parent = path51.dirname(current);
|
|
28601
28895
|
if (parent === current) return current;
|
|
28602
28896
|
current = parent;
|
|
28603
28897
|
}
|
|
28604
28898
|
}
|
|
28605
28899
|
|
|
28606
28900
|
// src/pipeline/audit.ts
|
|
28607
|
-
import { readFile as
|
|
28608
|
-
import { existsSync as
|
|
28609
|
-
import
|
|
28901
|
+
import { readFile as readFile37 } from "fs/promises";
|
|
28902
|
+
import { existsSync as existsSync45 } from "fs";
|
|
28903
|
+
import path52 from "path";
|
|
28610
28904
|
function paletteDistance(asset, reference) {
|
|
28611
28905
|
if (!asset.length || !reference.length) return 0;
|
|
28612
28906
|
let total = 0;
|
|
@@ -28642,12 +28936,12 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
28642
28936
|
const unreadable = [];
|
|
28643
28937
|
for (const spec of mine) {
|
|
28644
28938
|
for (const output of resolveSpecOutputs(spec, lock, loaded.root)) {
|
|
28645
|
-
if (!
|
|
28939
|
+
if (!existsSync45(output.absolutePath)) {
|
|
28646
28940
|
missing.push(output.id);
|
|
28647
28941
|
continue;
|
|
28648
28942
|
}
|
|
28649
28943
|
try {
|
|
28650
|
-
const png = decodePng(await
|
|
28944
|
+
const png = decodePng(await readFile37(output.absolutePath));
|
|
28651
28945
|
const palette = extractPalette(png, 12);
|
|
28652
28946
|
assets.push({
|
|
28653
28947
|
assetId: spec.assetId,
|
|
@@ -28671,10 +28965,10 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
28671
28965
|
let referenceFromStyleImages = false;
|
|
28672
28966
|
const refPalettes = [];
|
|
28673
28967
|
for (const img of style.styleImages) {
|
|
28674
|
-
const abs =
|
|
28675
|
-
if (!
|
|
28968
|
+
const abs = path52.resolve(loaded.root, img.path);
|
|
28969
|
+
if (!existsSync45(abs)) continue;
|
|
28676
28970
|
try {
|
|
28677
|
-
refPalettes.push(extractPalette(decodePng(await
|
|
28971
|
+
refPalettes.push(extractPalette(decodePng(await readFile37(abs)), 12));
|
|
28678
28972
|
} catch {
|
|
28679
28973
|
}
|
|
28680
28974
|
}
|
|
@@ -28929,24 +29223,24 @@ async function runHash(args) {
|
|
|
28929
29223
|
}
|
|
28930
29224
|
|
|
28931
29225
|
// src/cli/commands/pack.ts
|
|
28932
|
-
import
|
|
28933
|
-
import { readFile as
|
|
29226
|
+
import path54 from "path";
|
|
29227
|
+
import { readFile as readFile38 } from "fs/promises";
|
|
28934
29228
|
|
|
28935
29229
|
// src/pipeline/pack.ts
|
|
28936
29230
|
import { readFileSync as readFileSync8 } from "fs";
|
|
28937
|
-
import
|
|
29231
|
+
import path53 from "path";
|
|
28938
29232
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
28939
29233
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
28940
29234
|
if (!Array.isArray(raw) || !raw.length) {
|
|
28941
29235
|
throw new Error("--inputs must be a non-empty JSON array of { id, path }");
|
|
28942
29236
|
}
|
|
28943
|
-
const baseDir =
|
|
29237
|
+
const baseDir = path53.dirname(path53.resolve(inputsFilePath));
|
|
28944
29238
|
return raw.map((entry, i) => {
|
|
28945
29239
|
const e = entry;
|
|
28946
29240
|
if (typeof e.id !== "string" || typeof e.path !== "string") {
|
|
28947
29241
|
throw new Error(`--inputs[${i}] needs string "id" and "path"`);
|
|
28948
29242
|
}
|
|
28949
|
-
return { id: e.id, path:
|
|
29243
|
+
return { id: e.id, path: path53.resolve(baseDir, e.path) };
|
|
28950
29244
|
});
|
|
28951
29245
|
}
|
|
28952
29246
|
function packSprites(inputs, options = {}) {
|
|
@@ -29030,7 +29324,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
29030
29324
|
}
|
|
29031
29325
|
const inputs2 = Object.entries(options.sourceOverrides).map(([id, source]) => ({
|
|
29032
29326
|
id,
|
|
29033
|
-
path:
|
|
29327
|
+
path: path53.resolve(source)
|
|
29034
29328
|
}));
|
|
29035
29329
|
if (!inputs2.length) throw new Error(`No approved quality outputs for style "${styleId}".`);
|
|
29036
29330
|
const packed2 = packSprites(inputs2, options);
|
|
@@ -29062,7 +29356,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
29062
29356
|
let outputs = resolveEntryOutputs(entry, id, manifestDir);
|
|
29063
29357
|
const source = sources[id];
|
|
29064
29358
|
if (source && outputs.length <= 1) {
|
|
29065
|
-
inputs.push({ id, path:
|
|
29359
|
+
inputs.push({ id, path: path53.resolve(manifestDir, source) });
|
|
29066
29360
|
continue;
|
|
29067
29361
|
}
|
|
29068
29362
|
if (source && sourceIsStem(source, entry, manifestDir)) {
|
|
@@ -29099,7 +29393,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
29099
29393
|
}
|
|
29100
29394
|
}
|
|
29101
29395
|
for (const [id, source] of Object.entries(sources)) {
|
|
29102
|
-
if (!locked.has(id)) inputs.push({ id, path:
|
|
29396
|
+
if (!locked.has(id)) inputs.push({ id, path: path53.resolve(manifestDir, source) });
|
|
29103
29397
|
}
|
|
29104
29398
|
if (!inputs.length) {
|
|
29105
29399
|
throw new Error(`No readable sprites for style "${styleId}"; ${noOutput.length} skipped.`);
|
|
@@ -29234,7 +29528,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
29234
29528
|
const source = sources[id];
|
|
29235
29529
|
const entry = lock.entries[`${styleId}/${id}`];
|
|
29236
29530
|
if (source && !(entry && sourceIsStem(source, entry, manifestDir))) {
|
|
29237
|
-
placements.push({ id, path:
|
|
29531
|
+
placements.push({ id, path: path53.resolve(manifestDir, source), cell });
|
|
29238
29532
|
continue;
|
|
29239
29533
|
}
|
|
29240
29534
|
if (source && entry) {
|
|
@@ -29267,7 +29561,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
29267
29561
|
`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}`
|
|
29268
29562
|
);
|
|
29269
29563
|
}
|
|
29270
|
-
const basePng = mount.base ? readFileSync8(
|
|
29564
|
+
const basePng = mount.base ? readFileSync8(path53.resolve(manifestDir, mount.base)) : void 0;
|
|
29271
29565
|
const mounted = mountSprites(placements, {
|
|
29272
29566
|
cellWidth: mount.cellWidth,
|
|
29273
29567
|
cellHeight: mount.cellHeight,
|
|
@@ -29277,7 +29571,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
29277
29571
|
...mounted,
|
|
29278
29572
|
sources: mount.base ? [{
|
|
29279
29573
|
id: "$base",
|
|
29280
|
-
path:
|
|
29574
|
+
path: path53.resolve(manifestDir, mount.base),
|
|
29281
29575
|
sha256: sha256(basePng),
|
|
29282
29576
|
included: true
|
|
29283
29577
|
}, ...mounted.sources] : mounted.sources,
|
|
@@ -30454,12 +30748,12 @@ async function runPack(args) {
|
|
|
30454
30748
|
if (args.primaryOnly || args.outputRoles.length) {
|
|
30455
30749
|
throw new Error("--primary-only and --output-role require manifest-driven pack");
|
|
30456
30750
|
}
|
|
30457
|
-
const raw = JSON.parse(await
|
|
30751
|
+
const raw = JSON.parse(await readFile38(path54.resolve(args.inputs), "utf8"));
|
|
30458
30752
|
const inputs = resolvePackInputs(raw, args.inputs);
|
|
30459
30753
|
const { png, atlas, skipped, sources } = packSprites(inputs, { columns: args.columns });
|
|
30460
30754
|
const format = sheetFormat(args);
|
|
30461
|
-
const base =
|
|
30462
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
30755
|
+
const base = path54.resolve(args.out.replace(/\.(?:png|json|tres)$/i, ""));
|
|
30756
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path54.basename(`${base}.png`) });
|
|
30463
30757
|
const outputs = [
|
|
30464
30758
|
{ path: `${base}.png`, data: png },
|
|
30465
30759
|
{ path: `${base}${extension}`, data: document }
|
|
@@ -30472,7 +30766,7 @@ async function runPack(args) {
|
|
|
30472
30766
|
log(
|
|
30473
30767
|
` ${atlas.frames.length} sprite(s), ${atlas.sheet.width}x${atlas.sheet.height} in ${atlas.columns} column(s), ${(png.length / 1024).toFixed(1)} KB (${format})`
|
|
30474
30768
|
);
|
|
30475
|
-
log(` ${
|
|
30769
|
+
log(` ${path54.relative(process.cwd(), base)}.png + ${extension} + .pixelkiln.json`);
|
|
30476
30770
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
30477
30771
|
return;
|
|
30478
30772
|
}
|
|
@@ -30480,7 +30774,7 @@ async function runPack(args) {
|
|
|
30480
30774
|
if (args.primaryOnly && args.outputRoles.length) {
|
|
30481
30775
|
throw new Error("pack accepts either --primary-only or --output-role, not both");
|
|
30482
30776
|
}
|
|
30483
|
-
const manifestDir =
|
|
30777
|
+
const manifestDir = path54.dirname(path54.resolve(args.manifest));
|
|
30484
30778
|
const styleIds = args.styles.length ? args.styles : Object.keys(loaded.manifest.styles);
|
|
30485
30779
|
for (const styleId of styleIds) {
|
|
30486
30780
|
const style = loaded.manifest.styles[styleId];
|
|
@@ -30495,9 +30789,9 @@ async function runPack(args) {
|
|
|
30495
30789
|
sourceOverrides: qualitySources,
|
|
30496
30790
|
sources: manifestSources(loaded.manifest, styleId)
|
|
30497
30791
|
});
|
|
30498
|
-
const base = args.out ?
|
|
30792
|
+
const base = args.out ? path54.resolve(args.out.replace(/\.(?:png|json|tres)$/i, "")) : path54.resolve(manifestDir, style.outDir, `${styleId}-sheet`);
|
|
30499
30793
|
const format = sheetFormat(args);
|
|
30500
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
30794
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path54.basename(`${base}.png`) });
|
|
30501
30795
|
const outputs = [
|
|
30502
30796
|
{ path: `${base}.png`, data: png },
|
|
30503
30797
|
{ path: `${base}${extension}`, data: document }
|
|
@@ -30529,13 +30823,13 @@ async function runPack(args) {
|
|
|
30529
30823
|
log(
|
|
30530
30824
|
` ${styleId}: ${atlas.frames.length} sprite(s), ${atlas.sheet.width}x${atlas.sheet.height} in ${atlas.columns} column(s)` + (atlas.sets?.length ? `, ${atlas.sets.length} set(s)` : "") + ` (${format})`
|
|
30531
30825
|
);
|
|
30532
|
-
log(` ${
|
|
30826
|
+
log(` ${path54.relative(process.cwd(), base)}.png + ${extension} + .pixelkiln.json`);
|
|
30533
30827
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
30534
30828
|
}
|
|
30535
30829
|
}
|
|
30536
30830
|
async function runMount(args) {
|
|
30537
30831
|
const { loaded, lock } = await openProject2(args);
|
|
30538
|
-
const manifestDir =
|
|
30832
|
+
const manifestDir = path54.dirname(path54.resolve(args.manifest));
|
|
30539
30833
|
const styleIds = args.styles.length ? args.styles : Object.keys(loaded.manifest.styles);
|
|
30540
30834
|
for (const styleId of styleIds) {
|
|
30541
30835
|
const style = loaded.manifest.styles[styleId];
|
|
@@ -30574,9 +30868,9 @@ async function runMount(args) {
|
|
|
30574
30868
|
sources,
|
|
30575
30869
|
outputRoles
|
|
30576
30870
|
);
|
|
30577
|
-
const out =
|
|
30871
|
+
const out = path54.resolve(manifestDir, style.mount.out);
|
|
30578
30872
|
const format = sheetFormat(args);
|
|
30579
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
30873
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path54.basename(out) });
|
|
30580
30874
|
const metadata = out.replace(/\.png$/, "") + extension;
|
|
30581
30875
|
const companion = out.replace(/\.png$/, "") + ".pixelkiln.json";
|
|
30582
30876
|
const outputs = [
|
|
@@ -30596,7 +30890,7 @@ async function runMount(args) {
|
|
|
30596
30890
|
await provenanceFile("$lock", args.lock),
|
|
30597
30891
|
...qualityRecords,
|
|
30598
30892
|
...artifactSources.filter(
|
|
30599
|
-
(source) => source.id !== "$base" ||
|
|
30893
|
+
(source) => source.id !== "$base" || path54.resolve(source.path) !== out
|
|
30600
30894
|
)
|
|
30601
30895
|
],
|
|
30602
30896
|
options: {
|
|
@@ -30610,14 +30904,14 @@ async function runMount(args) {
|
|
|
30610
30904
|
log(
|
|
30611
30905
|
` ${styleId}: ${atlas.frames.length} cell(s) into ${atlas.sheet.width}x${atlas.sheet.height}` + (overBase ? ` over ${style.mount.base}` : " (new sheet)")
|
|
30612
30906
|
);
|
|
30613
|
-
log(` ${
|
|
30907
|
+
log(` ${path54.relative(process.cwd(), out)} + atlas/provenance JSON`);
|
|
30614
30908
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
30615
30909
|
}
|
|
30616
30910
|
}
|
|
30617
30911
|
async function runExport(args) {
|
|
30618
30912
|
const { loaded, specs, lock } = await openProject2(args);
|
|
30619
30913
|
const format = args.format ?? "generic";
|
|
30620
|
-
const manifestDir =
|
|
30914
|
+
const manifestDir = path54.dirname(path54.resolve(args.manifest));
|
|
30621
30915
|
const selected = specs.filter((spec) => {
|
|
30622
30916
|
if (spec.generator !== "tiles" && spec.generator !== "terrain") return false;
|
|
30623
30917
|
if (args.styles.length && !args.styles.includes(spec.styleId)) return false;
|
|
@@ -30657,12 +30951,12 @@ async function runExport(args) {
|
|
|
30657
30951
|
const merged = group.length > 1;
|
|
30658
30952
|
const style = loaded.manifest.styles[spec.styleId];
|
|
30659
30953
|
const assetName = group.map((member) => member.assetId).join("-");
|
|
30660
|
-
const defaultBase =
|
|
30661
|
-
const base = args.out ?
|
|
30954
|
+
const defaultBase = path54.resolve(manifestDir, style.outDir, `${assetName}-tileset`);
|
|
30955
|
+
const base = args.out ? path54.resolve(args.out.replace(/\.(?:png|json|tsj|tres|ldtk)$/i, "")) : defaultBase;
|
|
30662
30956
|
const exportOptions = {
|
|
30663
30957
|
format,
|
|
30664
30958
|
manifestDir,
|
|
30665
|
-
imageName:
|
|
30959
|
+
imageName: path54.basename(`${base}.png`),
|
|
30666
30960
|
columns: args.columns
|
|
30667
30961
|
};
|
|
30668
30962
|
const result = merged ? exportMergedTilesets(
|
|
@@ -30684,7 +30978,7 @@ async function runExport(args) {
|
|
|
30684
30978
|
asset: result.generic.asset,
|
|
30685
30979
|
columns: args.columns ?? null,
|
|
30686
30980
|
format,
|
|
30687
|
-
image:
|
|
30981
|
+
image: path54.basename(`${base}.png`),
|
|
30688
30982
|
providerRules: result.generic.providerRules,
|
|
30689
30983
|
...merged ? { sets: result.generic.sets } : {},
|
|
30690
30984
|
style: spec.styleId,
|
|
@@ -30695,7 +30989,7 @@ async function runExport(args) {
|
|
|
30695
30989
|
` ${spec.styleId}/${merged ? group.map((member) => member.assetId).join(" + ") : spec.assetId}: ${result.generic.tiles.length} tile(s), ` + (merged ? `${result.generic.rules.terrains.length} terrains (${result.generic.rules.terrains.join(", ")}), ` : "") + `${result.generic.sheet.width}x${result.generic.sheet.height} (${format})`
|
|
30696
30990
|
);
|
|
30697
30991
|
log(
|
|
30698
|
-
` ${
|
|
30992
|
+
` ${path54.relative(process.cwd(), base)}.png + ${path54.basename(base)}${result.extension} + .pixelkiln.json`
|
|
30699
30993
|
);
|
|
30700
30994
|
for (const warning of result.warnings) log(` warning: ${warning}`);
|
|
30701
30995
|
}
|
|
@@ -30709,22 +31003,22 @@ function sheetFormat(args) {
|
|
|
30709
31003
|
}
|
|
30710
31004
|
|
|
30711
31005
|
// src/cli/commands/pixellab-utils.ts
|
|
30712
|
-
import { readFile as
|
|
30713
|
-
import
|
|
31006
|
+
import { readFile as readFile41 } from "fs/promises";
|
|
31007
|
+
import path58 from "path";
|
|
30714
31008
|
|
|
30715
31009
|
// src/codex-vfx.ts
|
|
30716
31010
|
import { createHash as createHash8 } from "crypto";
|
|
30717
|
-
import { existsSync as
|
|
30718
|
-
import { readFile as
|
|
31011
|
+
import { existsSync as existsSync47, readFileSync as readFileSync9, readdirSync as readdirSync2 } from "fs";
|
|
31012
|
+
import { readFile as readFile39 } from "fs/promises";
|
|
30719
31013
|
import { createRequire as createRequire2 } from "module";
|
|
30720
|
-
import
|
|
31014
|
+
import path56 from "path";
|
|
30721
31015
|
import { pathToFileURL } from "url";
|
|
30722
31016
|
import vm from "vm";
|
|
30723
31017
|
|
|
30724
31018
|
// src/local-vfx.ts
|
|
30725
|
-
import { existsSync as
|
|
30726
|
-
import { mkdir as
|
|
30727
|
-
import
|
|
31019
|
+
import { existsSync as existsSync46 } from "fs";
|
|
31020
|
+
import { mkdir as mkdir20, writeFile as writeFile25 } from "fs/promises";
|
|
31021
|
+
import path55 from "path";
|
|
30728
31022
|
function localSheet(render) {
|
|
30729
31023
|
const { width, height, frames } = render;
|
|
30730
31024
|
const columns = Math.min(frames.length, Math.max(1, Math.ceil(Math.sqrt(frames.length * height / width))));
|
|
@@ -30744,7 +31038,7 @@ function assertFreshOutputs(out, force) {
|
|
|
30744
31038
|
const paths = vfxOutputPaths(out);
|
|
30745
31039
|
if (!force) {
|
|
30746
31040
|
for (const file of [paths.sheet, paths.atlas, paths.provenance]) {
|
|
30747
|
-
if (
|
|
31041
|
+
if (existsSync46(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
30748
31042
|
}
|
|
30749
31043
|
}
|
|
30750
31044
|
return paths;
|
|
@@ -30752,7 +31046,7 @@ function assertFreshOutputs(out, force) {
|
|
|
30752
31046
|
async function writeLocalVfx(opts) {
|
|
30753
31047
|
const { paths, render } = opts;
|
|
30754
31048
|
const sheet = localSheet(render);
|
|
30755
|
-
const clip =
|
|
31049
|
+
const clip = path55.basename(paths.sheet, ".png");
|
|
30756
31050
|
const anchor = { kind: "origin", ...render.anchor };
|
|
30757
31051
|
const size = { w: render.width, h: render.height };
|
|
30758
31052
|
const atlas = {
|
|
@@ -30768,7 +31062,7 @@ async function writeLocalVfx(opts) {
|
|
|
30768
31062
|
meta: {
|
|
30769
31063
|
app: "pixelkiln",
|
|
30770
31064
|
version: "1",
|
|
30771
|
-
image:
|
|
31065
|
+
image: path55.basename(paths.sheet),
|
|
30772
31066
|
format: "RGBA8888",
|
|
30773
31067
|
size: { w: sheet.columns * render.width, h: sheet.rows * render.height },
|
|
30774
31068
|
scale: "1",
|
|
@@ -30802,16 +31096,16 @@ async function writeLocalVfx(opts) {
|
|
|
30802
31096
|
version: 1,
|
|
30803
31097
|
...opts.record,
|
|
30804
31098
|
...facts,
|
|
30805
|
-
files: { sheet:
|
|
31099
|
+
files: { sheet: path55.basename(paths.sheet), atlas: path55.basename(paths.atlas) },
|
|
30806
31100
|
sheetSha256,
|
|
30807
31101
|
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30808
31102
|
recipe: opts.recipe
|
|
30809
31103
|
};
|
|
30810
|
-
await
|
|
30811
|
-
await
|
|
30812
|
-
await
|
|
31104
|
+
await mkdir20(path55.dirname(paths.sheet), { recursive: true });
|
|
31105
|
+
await writeFile25(paths.sheet, sheet.png);
|
|
31106
|
+
await writeFile25(paths.atlas, `${JSON.stringify(atlas, null, 2)}
|
|
30813
31107
|
`);
|
|
30814
|
-
await
|
|
31108
|
+
await writeFile25(paths.provenance, `${JSON.stringify(record, null, 2)}
|
|
30815
31109
|
`);
|
|
30816
31110
|
return { facts, columns: sheet.columns, sheetSha256, paths: { sheet: paths.sheet, atlas: paths.atlas, provenance: paths.provenance } };
|
|
30817
31111
|
}
|
|
@@ -30832,14 +31126,14 @@ function missingCodex(cause) {
|
|
|
30832
31126
|
);
|
|
30833
31127
|
}
|
|
30834
31128
|
function findCodexRoot(from) {
|
|
30835
|
-
const bases = from?.map((base) => pathToFileURL(
|
|
30836
|
-
pathToFileURL(
|
|
31129
|
+
const bases = from?.map((base) => pathToFileURL(path56.resolve(base, "package.json")).href) ?? [
|
|
31130
|
+
pathToFileURL(path56.join(process.cwd(), "package.json")).href,
|
|
30837
31131
|
import.meta.url
|
|
30838
31132
|
];
|
|
30839
31133
|
let failure;
|
|
30840
31134
|
for (const base of bases) {
|
|
30841
31135
|
try {
|
|
30842
|
-
return
|
|
31136
|
+
return path56.dirname(createRequire2(base).resolve(`${CODEX_PACKAGE}/package.json`));
|
|
30843
31137
|
} catch (error) {
|
|
30844
31138
|
failure = error;
|
|
30845
31139
|
}
|
|
@@ -30848,11 +31142,11 @@ function findCodexRoot(from) {
|
|
|
30848
31142
|
}
|
|
30849
31143
|
function loadCodex(from) {
|
|
30850
31144
|
const root = findCodexRoot(from);
|
|
30851
|
-
const read = (...parts) => readFileSync9(
|
|
31145
|
+
const read = (...parts) => readFileSync9(path56.join(root, ...parts), "utf8");
|
|
30852
31146
|
const pkg = JSON.parse(read("package.json"));
|
|
30853
31147
|
const version = typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
30854
31148
|
for (const required of ["engine/pxfx.js", "engine/kit.js", "fx", "data/meta.json"]) {
|
|
30855
|
-
if (!
|
|
31149
|
+
if (!existsSync47(path56.join(root, required))) {
|
|
30856
31150
|
throw new PixelKilnError(`The installed ${CODEX_PACKAGE} (${version}) has no ${required}; PixelKiln was written against its 1.0.0 layout`, "capability");
|
|
30857
31151
|
}
|
|
30858
31152
|
}
|
|
@@ -30864,7 +31158,7 @@ function loadCodex(from) {
|
|
|
30864
31158
|
throw new PixelKilnError(`The installed ${CODEX_PACKAGE} (${version}) does not define PXFX.View and PXFX.get`, "capability");
|
|
30865
31159
|
}
|
|
30866
31160
|
const loadErrors = [];
|
|
30867
|
-
for (const file of readdirSync2(
|
|
31161
|
+
for (const file of readdirSync2(path56.join(root, "fx")).filter((name) => name.endsWith(".js")).sort()) {
|
|
30868
31162
|
try {
|
|
30869
31163
|
vm.runInContext(read("fx", file), context, { filename: `fx/${file}` });
|
|
30870
31164
|
} catch (error) {
|
|
@@ -31021,7 +31315,7 @@ function renderCodex(lib, recipe) {
|
|
|
31021
31315
|
return { effect: info, fps, loop: true, ...cropped };
|
|
31022
31316
|
}
|
|
31023
31317
|
async function readCodexRecipe(file, opts = {}) {
|
|
31024
|
-
const parsed = JSON.parse(await
|
|
31318
|
+
const parsed = JSON.parse(await readFile39(file, "utf8"));
|
|
31025
31319
|
const record = parsed.tool === CODEX_ID;
|
|
31026
31320
|
if (!record && !(opts.bare && parsed.tool === void 0)) return null;
|
|
31027
31321
|
const raw = record ? parsed.recipe : parsed;
|
|
@@ -31081,10 +31375,10 @@ async function makeCodexVfx(lib, opts) {
|
|
|
31081
31375
|
}
|
|
31082
31376
|
|
|
31083
31377
|
// src/pixelfx-vfx.ts
|
|
31084
|
-
import { existsSync as
|
|
31085
|
-
import { readFile as
|
|
31378
|
+
import { existsSync as existsSync48, readFileSync as readFileSync10 } from "fs";
|
|
31379
|
+
import { readFile as readFile40 } from "fs/promises";
|
|
31086
31380
|
import { createRequire as createRequire3 } from "module";
|
|
31087
|
-
import
|
|
31381
|
+
import path57 from "path";
|
|
31088
31382
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
31089
31383
|
var PIXELFX_TOOL = "pixelfx";
|
|
31090
31384
|
var PIXELFX_REPOSITORY = "https://github.com/patch-gg/pixelfx";
|
|
@@ -31097,17 +31391,17 @@ function missingPixelfx(cause) {
|
|
|
31097
31391
|
);
|
|
31098
31392
|
}
|
|
31099
31393
|
function pixelfxVersion(entry) {
|
|
31100
|
-
for (let dir =
|
|
31101
|
-
const file =
|
|
31102
|
-
if (!
|
|
31394
|
+
for (let dir = path57.dirname(entry); dir !== path57.dirname(dir); dir = path57.dirname(dir)) {
|
|
31395
|
+
const file = path57.join(dir, "package.json");
|
|
31396
|
+
if (!existsSync48(file)) continue;
|
|
31103
31397
|
const pkg = JSON.parse(readFileSync10(file, "utf8"));
|
|
31104
31398
|
if (pkg.name === "pixelfx") return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
31105
31399
|
}
|
|
31106
31400
|
return "unknown";
|
|
31107
31401
|
}
|
|
31108
31402
|
async function loadPixelfx(from) {
|
|
31109
|
-
const bases = from?.map((base) => pathToFileURL2(
|
|
31110
|
-
pathToFileURL2(
|
|
31403
|
+
const bases = from?.map((base) => pathToFileURL2(path57.resolve(base)).href) ?? [
|
|
31404
|
+
pathToFileURL2(path57.join(process.cwd(), "package.json")).href,
|
|
31111
31405
|
import.meta.url
|
|
31112
31406
|
];
|
|
31113
31407
|
let resolved;
|
|
@@ -31274,7 +31568,7 @@ function renderPixelfx(lib, recipe) {
|
|
|
31274
31568
|
};
|
|
31275
31569
|
}
|
|
31276
31570
|
async function readPixelfxRecipe(file) {
|
|
31277
|
-
const parsed = JSON.parse(await
|
|
31571
|
+
const parsed = JSON.parse(await readFile40(file, "utf8"));
|
|
31278
31572
|
const record = parsed.tool === PIXELFX_TOOL;
|
|
31279
31573
|
const raw = record ? parsed.recipe : parsed;
|
|
31280
31574
|
if (!raw || typeof raw !== "object" || typeof raw.effect !== "string" || Array.isArray(raw.layers)) {
|
|
@@ -31332,7 +31626,7 @@ async function makePixelfxVfx(lib, opts) {
|
|
|
31332
31626
|
|
|
31333
31627
|
// src/cli/commands/pixellab-utils.ts
|
|
31334
31628
|
function loadKeys(args) {
|
|
31335
|
-
loadEnvFiles(
|
|
31629
|
+
loadEnvFiles(path58.dirname(path58.resolve(args.manifest)));
|
|
31336
31630
|
loadEnvFiles(process.cwd());
|
|
31337
31631
|
}
|
|
31338
31632
|
async function runUnzoom(args) {
|
|
@@ -31588,7 +31882,7 @@ async function runVfx(args) {
|
|
|
31588
31882
|
const fromRecipe = args.recipe ? await readVfxRecipe(args.recipe) : void 0;
|
|
31589
31883
|
const sprite = args.sprite ?? fromRecipe?.sprite;
|
|
31590
31884
|
const recipeName = typeof fromRecipe?.recipe.name === "string" ? fromRecipe.recipe.name : void 0;
|
|
31591
|
-
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ??
|
|
31885
|
+
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ?? path58.basename(paths.sheet, ".png"));
|
|
31592
31886
|
const from = args.preset ? `preset ${args.preset}` : args.recipe ? `recipe ${args.recipe}` : args.effect ? `saved effect ${args.effect}` : "nothing";
|
|
31593
31887
|
log(
|
|
31594
31888
|
` vfx ${name ? `"${name}"` : "(keeping its saved name)"} from ${from}${args.parts.length ? ` + ${args.parts.join(", ")}` : ""}${sprite ? ` around ${sprite}` : ""} \u2192 ${paths.sheet} (+ .gif, .json, .vfx.json${args.gamePack ? ", -game.zip" : ""})`
|
|
@@ -31770,7 +32064,7 @@ async function runVfxArtist(args, out) {
|
|
|
31770
32064
|
if ((args.spriteFrames !== void 0 || args.spriteFps !== void 0) && !args.sprite) {
|
|
31771
32065
|
throw new UsageError("--sprite-frames and --sprite-fps describe a --sprite; add one");
|
|
31772
32066
|
}
|
|
31773
|
-
const taken = args.sprite ? vfxArtistSprite(await
|
|
32067
|
+
const taken = args.sprite ? vfxArtistSprite(await readFile41(args.sprite), args.sprite, args.spriteFrames ?? 1) : void 0;
|
|
31774
32068
|
if (args.spriteFps !== void 0 && !taken?.animated) {
|
|
31775
32069
|
throw new UsageError("--sprite-fps is the speed of an animated sprite: a GIF, or a PNG strip with --sprite-frames 2 or more");
|
|
31776
32070
|
}
|
|
@@ -31783,7 +32077,7 @@ async function runVfxArtist(args, out) {
|
|
|
31783
32077
|
);
|
|
31784
32078
|
if (args.effect) {
|
|
31785
32079
|
log(
|
|
31786
|
-
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${
|
|
32080
|
+
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${path58.basename(paths.provenance)})` : `; ${path58.basename(paths.provenance)} holds no conversation for it, so PixelLab prices it as a new effect`)
|
|
31787
32081
|
);
|
|
31788
32082
|
}
|
|
31789
32083
|
log(` cost: about ${quote} generations by PixelLab's table, billed on delivery; at most ${ceiling} if the effect runs long`);
|
|
@@ -31833,13 +32127,13 @@ async function runVfxArtist(args, out) {
|
|
|
31833
32127
|
}
|
|
31834
32128
|
|
|
31835
32129
|
// src/cli/commands/audio.ts
|
|
31836
|
-
import { readFile as
|
|
31837
|
-
import
|
|
32130
|
+
import { readFile as readFile42 } from "fs/promises";
|
|
32131
|
+
import path60 from "path";
|
|
31838
32132
|
|
|
31839
32133
|
// src/pixellab-audio.ts
|
|
31840
|
-
import { existsSync as
|
|
31841
|
-
import { mkdir as
|
|
31842
|
-
import
|
|
32134
|
+
import { existsSync as existsSync49 } from "fs";
|
|
32135
|
+
import { mkdir as mkdir21, writeFile as writeFile26 } from "fs/promises";
|
|
32136
|
+
import path59 from "path";
|
|
31843
32137
|
var MUSIC_COST_GENERATIONS = 10;
|
|
31844
32138
|
var MUSIC_LOOP_COST_GENERATIONS = 4;
|
|
31845
32139
|
var MUSIC_LOOP_MIN_BODY_SECONDS = 36;
|
|
@@ -31896,7 +32190,7 @@ async function billedUsage(client2, jobId) {
|
|
|
31896
32190
|
}
|
|
31897
32191
|
}
|
|
31898
32192
|
function musicOutputPaths(out) {
|
|
31899
|
-
const base =
|
|
32193
|
+
const base = path59.resolve(out.replace(/\.(music\.json|mp3)$/i, ""));
|
|
31900
32194
|
return {
|
|
31901
32195
|
takes: [`${base}.mp3`, `${base}.take2.mp3`],
|
|
31902
32196
|
loops: [`${base}.loop.mp3`, `${base}.loop.take2.mp3`],
|
|
@@ -31918,8 +32212,8 @@ async function collectTakes(client2, songs, files, what, opts) {
|
|
|
31918
32212
|
if (!song.audio_url) throw new Error(`PixelLab ${what} ${song.id} completed without an audio URL`);
|
|
31919
32213
|
const bytes = await client2.download(song.audio_url);
|
|
31920
32214
|
validateAudio(bytes, "mp3");
|
|
31921
|
-
await
|
|
31922
|
-
await
|
|
32215
|
+
await mkdir21(path59.dirname(file), { recursive: true });
|
|
32216
|
+
await writeFile26(file, bytes);
|
|
31923
32217
|
finished.push(song);
|
|
31924
32218
|
takes.push({
|
|
31925
32219
|
songId: song.id,
|
|
@@ -31946,7 +32240,7 @@ async function generateMusic(client2, opts) {
|
|
|
31946
32240
|
}
|
|
31947
32241
|
const writes = [paths.record, ...opts.loopOf ? [] : paths.takes, ...wantsLoop ? paths.loops : []];
|
|
31948
32242
|
if (!opts.force) {
|
|
31949
|
-
for (const file of writes) if (
|
|
32243
|
+
for (const file of writes) if (existsSync49(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
31950
32244
|
}
|
|
31951
32245
|
const usage2 = [];
|
|
31952
32246
|
let quoted = null;
|
|
@@ -31984,10 +32278,10 @@ async function generateMusic(client2, opts) {
|
|
|
31984
32278
|
quotedGenerations: quoted,
|
|
31985
32279
|
usage: usage2
|
|
31986
32280
|
});
|
|
31987
|
-
const relative = (take) => ({ ...take, file:
|
|
32281
|
+
const relative = (take) => ({ ...take, file: path59.basename(take.file) });
|
|
31988
32282
|
const writeRecord = async (result2) => {
|
|
31989
|
-
await
|
|
31990
|
-
await
|
|
32283
|
+
await mkdir21(path59.dirname(paths.record), { recursive: true });
|
|
32284
|
+
await writeFile26(
|
|
31991
32285
|
paths.record,
|
|
31992
32286
|
JSON.stringify(
|
|
31993
32287
|
{
|
|
@@ -32027,7 +32321,7 @@ async function generateMusic(client2, opts) {
|
|
|
32027
32321
|
submitted = await client2.loopMusic(loopSource);
|
|
32028
32322
|
} catch (error) {
|
|
32029
32323
|
const detail = refusalDetail(error);
|
|
32030
|
-
const kept = takes.length ? ` The song's takes are saved (${
|
|
32324
|
+
const kept = takes.length ? ` The song's takes are saved (${path59.basename(paths.record)}); nothing was charged for the loop.` : "";
|
|
32031
32325
|
throw new Error(`PixelLab refused to loop ${loopSource}: ${detail ?? (error instanceof Error ? error.message : String(error))}${kept}`, { cause: error });
|
|
32032
32326
|
}
|
|
32033
32327
|
quoted = (quoted ?? 0) + (submitted.quoted_generations ?? 0);
|
|
@@ -32041,13 +32335,13 @@ async function generateMusic(client2, opts) {
|
|
|
32041
32335
|
return result;
|
|
32042
32336
|
}
|
|
32043
32337
|
function soundEffectOutputPaths(out) {
|
|
32044
|
-
const base =
|
|
32338
|
+
const base = path59.resolve(out.replace(/\.(sfx\.json|wav)$/i, ""));
|
|
32045
32339
|
return { wav: `${base}.wav`, record: `${base}.sfx.json` };
|
|
32046
32340
|
}
|
|
32047
32341
|
async function generateSoundEffect(client2, opts) {
|
|
32048
32342
|
const { wav, record } = soundEffectOutputPaths(opts.out);
|
|
32049
32343
|
if (!opts.force) {
|
|
32050
|
-
for (const file of [wav, record]) if (
|
|
32344
|
+
for (const file of [wav, record]) if (existsSync49(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
32051
32345
|
}
|
|
32052
32346
|
const seconds = opts.seconds ?? 2;
|
|
32053
32347
|
const submitted = await client2.createSoundEffect({ prompt: opts.prompt, seconds, name: opts.name });
|
|
@@ -32056,8 +32350,8 @@ async function generateSoundEffect(client2, opts) {
|
|
|
32056
32350
|
if (!clip.audio_url) throw new Error(`PixelLab sound effect ${id} completed without an audio URL`);
|
|
32057
32351
|
const bytes = await client2.download(clip.audio_url);
|
|
32058
32352
|
validateAudio(bytes, "wav");
|
|
32059
|
-
await
|
|
32060
|
-
await
|
|
32353
|
+
await mkdir21(path59.dirname(wav), { recursive: true });
|
|
32354
|
+
await writeFile26(wav, bytes);
|
|
32061
32355
|
const result = {
|
|
32062
32356
|
soundEffectId: id,
|
|
32063
32357
|
file: wav,
|
|
@@ -32068,7 +32362,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
32068
32362
|
quotedGenerations: submitted.quoted_generations ?? null,
|
|
32069
32363
|
usage: await billedUsage(client2, submitted.background_job_id)
|
|
32070
32364
|
};
|
|
32071
|
-
await
|
|
32365
|
+
await writeFile26(
|
|
32072
32366
|
record,
|
|
32073
32367
|
JSON.stringify(
|
|
32074
32368
|
{
|
|
@@ -32079,7 +32373,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
32079
32373
|
prompt: opts.prompt,
|
|
32080
32374
|
seconds,
|
|
32081
32375
|
soundEffectId: id,
|
|
32082
|
-
file:
|
|
32376
|
+
file: path59.basename(wav),
|
|
32083
32377
|
sha256: result.sha256,
|
|
32084
32378
|
durationMs: result.durationMs,
|
|
32085
32379
|
quotedGenerations: result.quotedGenerations,
|
|
@@ -32094,7 +32388,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
32094
32388
|
|
|
32095
32389
|
// src/cli/commands/audio.ts
|
|
32096
32390
|
function loadKeys2(args) {
|
|
32097
|
-
loadEnvFiles(
|
|
32391
|
+
loadEnvFiles(path60.dirname(path60.resolve(args.manifest)));
|
|
32098
32392
|
loadEnvFiles(process.cwd());
|
|
32099
32393
|
}
|
|
32100
32394
|
function progress() {
|
|
@@ -32151,7 +32445,7 @@ async function runMusic(args) {
|
|
|
32151
32445
|
const cost = musicCost({ loop: args.loop, loopOf: args.loopOf });
|
|
32152
32446
|
const paths = musicOutputPaths(args.out);
|
|
32153
32447
|
const what = args.loopOf ? `loop of ${args.loopOf} (two loop takes)` : `"${args.description}"${vocals ? ", with vocals" : ", instrumental"}, two takes${args.loop ? " plus loops of take 1" : ""}`;
|
|
32154
|
-
log(` music: ${what} \u2192 ${
|
|
32448
|
+
log(` music: ${what} \u2192 ${path60.relative(process.cwd(), args.loopOf ? paths.loops[0] : paths.takes[0])} \u2026`);
|
|
32155
32449
|
log(` cost: ${cost} generations (PixelLab's published price)${args.improve ? ", plus about 0.05 for --improve" : ""}`);
|
|
32156
32450
|
if (args.budget !== void 0 && args.budget < cost) {
|
|
32157
32451
|
throw new Error(`--budget ${args.budget} is below this run's ${cost}-generation cost`);
|
|
@@ -32168,7 +32462,7 @@ async function runMusic(args) {
|
|
|
32168
32462
|
style = (await client2.improveMusicStyle({ style, instrumental: !vocals, bpm: args.bpm })).style;
|
|
32169
32463
|
log(` style: ${style}`);
|
|
32170
32464
|
}
|
|
32171
|
-
const lyrics = args.lyrics ? await
|
|
32465
|
+
const lyrics = args.lyrics ? await readFile42(path60.resolve(args.lyrics), "utf8") : void 0;
|
|
32172
32466
|
const res = await generateMusic(client2, {
|
|
32173
32467
|
style,
|
|
32174
32468
|
lyrics,
|
|
@@ -32204,7 +32498,7 @@ async function runSfx(args) {
|
|
|
32204
32498
|
const seconds = args.seconds ?? 2;
|
|
32205
32499
|
const cost = soundEffectCost(seconds);
|
|
32206
32500
|
const { wav } = soundEffectOutputPaths(args.out);
|
|
32207
|
-
log(` sfx: "${args.description}", ${seconds} s \u2192 ${
|
|
32501
|
+
log(` sfx: "${args.description}", ${seconds} s \u2192 ${path60.relative(process.cwd(), wav)}`);
|
|
32208
32502
|
log(` cost: ${cost} generation${cost === 1 ? "" : "s"} (PixelLab's published price, by length)`);
|
|
32209
32503
|
if (args.budget !== void 0 && args.budget < cost) {
|
|
32210
32504
|
throw new Error(`--budget ${args.budget} is below this clip's ${cost}-generation cost`);
|
|
@@ -32232,12 +32526,12 @@ async function runSfx(args) {
|
|
|
32232
32526
|
}
|
|
32233
32527
|
|
|
32234
32528
|
// src/cli/commands/ui.ts
|
|
32235
|
-
import
|
|
32529
|
+
import path62 from "path";
|
|
32236
32530
|
|
|
32237
32531
|
// src/pixellab-ui.ts
|
|
32238
|
-
import { existsSync as
|
|
32239
|
-
import { mkdir as
|
|
32240
|
-
import
|
|
32532
|
+
import { existsSync as existsSync50 } from "fs";
|
|
32533
|
+
import { mkdir as mkdir22, writeFile as writeFile27 } from "fs/promises";
|
|
32534
|
+
import path61 from "path";
|
|
32241
32535
|
var UI_STATES_COSTS = [10, 15, 25];
|
|
32242
32536
|
var UI_STATES_MAX_COST = 25;
|
|
32243
32537
|
var UI_STATES_MAX_ELEMENTS = 64;
|
|
@@ -32330,8 +32624,8 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
32330
32624
|
const asset = await client2.getUiAssetDetail(uiAssetId);
|
|
32331
32625
|
if (asset.status && asset.status !== "completed") throw new Error(`UI asset ${uiAssetId} is ${asset.status}; pull it once it is completed`);
|
|
32332
32626
|
if (!asset.image_url) throw new Error(`UI asset ${uiAssetId} has no image yet`);
|
|
32333
|
-
const dir =
|
|
32334
|
-
const record =
|
|
32627
|
+
const dir = path61.resolve(opts.out);
|
|
32628
|
+
const record = path61.join(dir, "ui.json");
|
|
32335
32629
|
const plan = [];
|
|
32336
32630
|
const insets = (part) => part.nine_slice ? { nineSlice: { left: part.nine_slice.left, right: part.nine_slice.right, top: part.nine_slice.top, bottom: part.nine_slice.bottom } } : {};
|
|
32337
32631
|
const taken = /* @__PURE__ */ new Set();
|
|
@@ -32379,20 +32673,20 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
32379
32673
|
}
|
|
32380
32674
|
if (kind === "element") addStates(asset, rootName, asset.states);
|
|
32381
32675
|
if (!opts.force) {
|
|
32382
|
-
for (const file of [record, ...plan.map((item) =>
|
|
32383
|
-
if (
|
|
32676
|
+
for (const file of [record, ...plan.map((item) => path61.join(dir, item.file))]) {
|
|
32677
|
+
if (existsSync50(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
32384
32678
|
}
|
|
32385
32679
|
}
|
|
32386
32680
|
const files = [];
|
|
32387
32681
|
for (const { url, ...item } of plan) {
|
|
32388
32682
|
const bytes = await client2.download(url);
|
|
32389
32683
|
validateMedia(bytes, MediaType.PNG);
|
|
32390
|
-
const target =
|
|
32391
|
-
await
|
|
32392
|
-
await
|
|
32684
|
+
const target = path61.join(dir, item.file);
|
|
32685
|
+
await mkdir22(path61.dirname(target), { recursive: true });
|
|
32686
|
+
await writeFile27(target, bytes);
|
|
32393
32687
|
files.push({ ...item, sha256: sha256(bytes) });
|
|
32394
32688
|
}
|
|
32395
|
-
await
|
|
32689
|
+
await writeFile27(
|
|
32396
32690
|
record,
|
|
32397
32691
|
JSON.stringify(
|
|
32398
32692
|
{
|
|
@@ -32414,7 +32708,7 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
32414
32708
|
|
|
32415
32709
|
// src/cli/commands/ui.ts
|
|
32416
32710
|
function loadKeys3(args) {
|
|
32417
|
-
loadEnvFiles(
|
|
32711
|
+
loadEnvFiles(path62.dirname(path62.resolve(args.manifest)));
|
|
32418
32712
|
loadEnvFiles(process.cwd());
|
|
32419
32713
|
}
|
|
32420
32714
|
function requireId(args) {
|
|
@@ -32528,18 +32822,18 @@ async function runUi(args) {
|
|
|
32528
32822
|
log(JSON.stringify({ version: 1, ...res }, null, 2));
|
|
32529
32823
|
return;
|
|
32530
32824
|
}
|
|
32531
|
-
for (const file of res.files) log(` wrote ${
|
|
32532
|
-
log(` wrote ${
|
|
32825
|
+
for (const file of res.files) log(` wrote ${path62.join(args.out, file.file)} (${file.kind}, ${file.size.width}x${file.size.height})`);
|
|
32826
|
+
log(` wrote ${path62.join(args.out, "ui.json")}`);
|
|
32533
32827
|
}
|
|
32534
32828
|
|
|
32535
32829
|
// src/cli/commands/asset.ts
|
|
32536
|
-
import { readFile as
|
|
32537
|
-
import
|
|
32830
|
+
import { readFile as readFile44 } from "fs/promises";
|
|
32831
|
+
import path64 from "path";
|
|
32538
32832
|
|
|
32539
32833
|
// src/pixellab-assets.ts
|
|
32540
|
-
import { existsSync as
|
|
32541
|
-
import { mkdir as
|
|
32542
|
-
import
|
|
32834
|
+
import { existsSync as existsSync51 } from "fs";
|
|
32835
|
+
import { mkdir as mkdir23, readdir as readdir5, readFile as readFile43, stat as stat6, writeFile as writeFile28 } from "fs/promises";
|
|
32836
|
+
import path63 from "path";
|
|
32543
32837
|
var ASSET_KINDS = ["object", "character"];
|
|
32544
32838
|
var EXPORT_FORMATS = ["zip", "spritesheet", "aseprite", "gif"];
|
|
32545
32839
|
var MIRROR_DIRECTIONS = ["east", "west", "south-east", "south-west", "north-east", "north-west"];
|
|
@@ -32559,7 +32853,7 @@ function parseCanvasSize(text, kind) {
|
|
|
32559
32853
|
}
|
|
32560
32854
|
function exportOutPath(out, format) {
|
|
32561
32855
|
const extension = format === "aseprite" ? ".aseprite" : format === "gif" ? ".gif" : ".zip";
|
|
32562
|
-
return
|
|
32856
|
+
return path63.extname(out) ? path63.resolve(out) : path63.resolve(`${out}${extension}`);
|
|
32563
32857
|
}
|
|
32564
32858
|
function checkExportBytes(bytes, format) {
|
|
32565
32859
|
const ok = format === "gif" ? bytes.subarray(0, 4).toString("ascii") === "GIF8" : format === "aseprite" ? bytes.length > 6 && bytes.readUInt16LE(4) === 42464 : bytes.subarray(0, 2).toString("ascii") === "PK";
|
|
@@ -32567,15 +32861,15 @@ function checkExportBytes(bytes, format) {
|
|
|
32567
32861
|
}
|
|
32568
32862
|
async function exportAssetFile(client2, kind, id, format, opts) {
|
|
32569
32863
|
const out = exportOutPath(opts.out, format);
|
|
32570
|
-
if (
|
|
32864
|
+
if (existsSync51(out) && !opts.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
32571
32865
|
const bytes = await client2.exportAsset(kind, id, format, { animationGroupId: opts.animationGroupId, direction: opts.direction });
|
|
32572
32866
|
checkExportBytes(bytes, format);
|
|
32573
|
-
await
|
|
32574
|
-
await
|
|
32867
|
+
await mkdir23(path63.dirname(out), { recursive: true });
|
|
32868
|
+
await writeFile28(out, bytes);
|
|
32575
32869
|
return { out, bytes: bytes.length };
|
|
32576
32870
|
}
|
|
32577
32871
|
async function importObjectFile(client2, file, opts = {}) {
|
|
32578
|
-
const bytes = await
|
|
32872
|
+
const bytes = await readFile43(file);
|
|
32579
32873
|
const metadata = imageMetadata(bytes);
|
|
32580
32874
|
if (!metadata || metadata.format !== "png") throw new Error(`${file} is not a PNG; PixelLab imports PNG only (JPEG compression would be stored as pixels)`);
|
|
32581
32875
|
if (metadata.width > IMPORT_MAX_SIDE || metadata.height > IMPORT_MAX_SIDE) {
|
|
@@ -32617,17 +32911,17 @@ async function pullExpansionReview(client2, id, opts) {
|
|
|
32617
32911
|
if (object.status !== "review-expansion" || !review?.rotation_urls) {
|
|
32618
32912
|
throw new Error(`object ${id} is ${object.status ?? "unknown"}; there is no expansion waiting for review`);
|
|
32619
32913
|
}
|
|
32620
|
-
const dir =
|
|
32914
|
+
const dir = path63.resolve(opts.out);
|
|
32621
32915
|
const entries = Object.entries(review.rotation_urls).filter((entry) => typeof entry[1] === "string");
|
|
32622
|
-
const files = entries.map(([direction]) => ({ direction, file:
|
|
32916
|
+
const files = entries.map(([direction]) => ({ direction, file: path63.join(dir, `${direction}.png`) }));
|
|
32623
32917
|
if (!opts.force) {
|
|
32624
|
-
for (const { file } of files) if (
|
|
32918
|
+
for (const { file } of files) if (existsSync51(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
32625
32919
|
}
|
|
32626
|
-
await
|
|
32920
|
+
await mkdir23(dir, { recursive: true });
|
|
32627
32921
|
for (const [index, [, url]] of entries.entries()) {
|
|
32628
32922
|
const bytes = await client2.download(url);
|
|
32629
32923
|
validateMedia(bytes, MediaType.PNG);
|
|
32630
|
-
await
|
|
32924
|
+
await writeFile28(files[index].file, bytes);
|
|
32631
32925
|
}
|
|
32632
32926
|
return { dir, existingDirection: review.existing_direction ?? null, files };
|
|
32633
32927
|
}
|
|
@@ -32668,7 +32962,7 @@ function readPng(bytes, file) {
|
|
|
32668
32962
|
return metadata;
|
|
32669
32963
|
}
|
|
32670
32964
|
async function importTilesetFile(client2, file, opts = {}) {
|
|
32671
|
-
const bytes = await
|
|
32965
|
+
const bytes = await readFile43(file);
|
|
32672
32966
|
const { width, height } = readPng(bytes, file);
|
|
32673
32967
|
const reading = chooseTilesetSheetReading(file, width, height, opts.tileSize);
|
|
32674
32968
|
const mode2 = opts.mode ?? "topdown";
|
|
@@ -32686,11 +32980,11 @@ async function importTilesetFile(client2, file, opts = {}) {
|
|
|
32686
32980
|
return { tilesetId: res.tileset_id, mode: mode2, tileSize: reading.tileSize, layout: reading.layout };
|
|
32687
32981
|
}
|
|
32688
32982
|
async function pngFilesAt(from) {
|
|
32689
|
-
if (!
|
|
32983
|
+
if (!existsSync51(from)) throw new Error(`${from} does not exist`);
|
|
32690
32984
|
if (!(await stat6(from)).isDirectory()) return [from];
|
|
32691
32985
|
const names = (await readdir5(from)).filter((name) => /\.png$/i.test(name)).sort((a, b) => a.localeCompare(b, void 0, { numeric: true }));
|
|
32692
32986
|
if (names.length === 0) throw new Error(`${from} holds no PNG files`);
|
|
32693
|
-
return names.map((name) =>
|
|
32987
|
+
return names.map((name) => path63.join(from, name));
|
|
32694
32988
|
}
|
|
32695
32989
|
function importTileHeights(tileType, tileSize) {
|
|
32696
32990
|
if (tileType === "square_topdown" || tileType === "octagon") return { min: tileSize, max: tileSize };
|
|
@@ -32705,7 +32999,7 @@ async function importTilesFiles(client2, from, opts) {
|
|
|
32705
32999
|
const heights = importTileHeights(opts.tileType, opts.tileSize);
|
|
32706
33000
|
const frames = [];
|
|
32707
33001
|
for (const file of files) {
|
|
32708
|
-
const bytes = await
|
|
33002
|
+
const bytes = await readFile43(file);
|
|
32709
33003
|
const { width, height } = readPng(bytes, file);
|
|
32710
33004
|
if (width !== opts.tileSize || height < heights.min || height > heights.max) {
|
|
32711
33005
|
const tall = heights.min === heights.max ? `${heights.min}` : `${heights.min} to ${heights.max}`;
|
|
@@ -32725,14 +33019,14 @@ function checkSaveTarget(target) {
|
|
|
32725
33019
|
}
|
|
32726
33020
|
function saveUndoDir(target, now = /* @__PURE__ */ new Date()) {
|
|
32727
33021
|
const stamp = now.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
|
|
32728
|
-
return
|
|
33022
|
+
return path63.resolve("pixelkiln-undo", `${target.replace(/[^a-zA-Z0-9-]+/g, "_")}-${stamp}`);
|
|
32729
33023
|
}
|
|
32730
33024
|
async function writeUndo(frames, dir) {
|
|
32731
|
-
await
|
|
33025
|
+
await mkdir23(dir, { recursive: true });
|
|
32732
33026
|
const files = [];
|
|
32733
33027
|
for (const [index, frame] of frames.entries()) {
|
|
32734
|
-
const file =
|
|
32735
|
-
await
|
|
33028
|
+
const file = path63.join(dir, frames.length === 1 ? "previous.png" : `previous-${String(index).padStart(2, "0")}.png`);
|
|
33029
|
+
await writeFile28(file, Buffer.from(frame.base64, "base64"));
|
|
32736
33030
|
files.push(file);
|
|
32737
33031
|
}
|
|
32738
33032
|
return files;
|
|
@@ -32741,13 +33035,13 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
32741
33035
|
checkSaveTarget(target);
|
|
32742
33036
|
if ((opts.name || opts.description) && target !== "gallery:new") throw new Error("a name and a description belong to a new gallery image: --target gallery:new");
|
|
32743
33037
|
const files = await pngFilesAt(from).catch(async (error) => {
|
|
32744
|
-
if (
|
|
33038
|
+
if (existsSync51(from) && /\.gif$/i.test(from)) return [from];
|
|
32745
33039
|
throw error;
|
|
32746
33040
|
});
|
|
32747
33041
|
let image;
|
|
32748
33042
|
let frames;
|
|
32749
33043
|
if (files.length === 1) {
|
|
32750
|
-
const bytes = await
|
|
33044
|
+
const bytes = await readFile43(files[0]);
|
|
32751
33045
|
const gif = bytes.subarray(0, 4).toString("ascii") === "GIF8";
|
|
32752
33046
|
if (!gif) readPng(bytes, files[0]);
|
|
32753
33047
|
image = { base64: bytes.toString("base64"), format: gif ? "gif" : "png" };
|
|
@@ -32756,14 +33050,14 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
32756
33050
|
let size;
|
|
32757
33051
|
frames = [];
|
|
32758
33052
|
for (const file of files) {
|
|
32759
|
-
const bytes = await
|
|
33053
|
+
const bytes = await readFile43(file);
|
|
32760
33054
|
const { width, height } = readPng(bytes, file);
|
|
32761
33055
|
if (size && size !== `${width}x${height}`) throw new Error(`${file} is ${width}x${height}, but the frames before it are ${size}; an animation's frames share one size`);
|
|
32762
33056
|
size = `${width}x${height}`;
|
|
32763
33057
|
frames.push({ base64: bytes.toString("base64"), format: "png" });
|
|
32764
33058
|
}
|
|
32765
33059
|
}
|
|
32766
|
-
const undoDir = opts.undoDir ?
|
|
33060
|
+
const undoDir = opts.undoDir ? path63.resolve(opts.undoDir) : saveUndoDir(target);
|
|
32767
33061
|
let res;
|
|
32768
33062
|
try {
|
|
32769
33063
|
res = await client2.saveToAsset({ target, image, frames, name: opts.name, description: opts.description });
|
|
@@ -32799,7 +33093,7 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
32799
33093
|
|
|
32800
33094
|
// src/cli/commands/asset.ts
|
|
32801
33095
|
function loadKeys4(args) {
|
|
32802
|
-
loadEnvFiles(
|
|
33096
|
+
loadEnvFiles(path64.dirname(path64.resolve(args.manifest)));
|
|
32803
33097
|
loadEnvFiles(process.cwd());
|
|
32804
33098
|
}
|
|
32805
33099
|
function kindOf(args) {
|
|
@@ -32920,7 +33214,7 @@ async function runAsset(args) {
|
|
|
32920
33214
|
const res2 = await pullExpansionReview(clientFromEnv(), id, { out: args.out, force: args.force });
|
|
32921
33215
|
if (args.json) emit(res2);
|
|
32922
33216
|
else {
|
|
32923
|
-
for (const file of res2.files) log(` wrote ${
|
|
33217
|
+
for (const file of res2.files) log(` wrote ${path64.join(args.out, `${file.direction}.png`)}${file.direction === res2.existingDirection ? " (your image, unchanged)" : ""}`);
|
|
32924
33218
|
log(` keep them: pixelkiln asset expand --id ${id} --keep discard: pixelkiln asset expand --id ${id} --discard`);
|
|
32925
33219
|
}
|
|
32926
33220
|
return;
|
|
@@ -32965,7 +33259,7 @@ async function runTileImport(args, emit) {
|
|
|
32965
33259
|
if (args.tileType) throw new UsageError("--tile-type belongs to --kind tiles; a tileset is a Wang sheet");
|
|
32966
33260
|
const opts2 = { mode: mode2, tileSize, lowerDescription: args.lower, upperDescription: args.upper, transitionDescription: args.transition, name: args.name };
|
|
32967
33261
|
if (args.dryRun) {
|
|
32968
|
-
const metadata = imageMetadata(await
|
|
33262
|
+
const metadata = imageMetadata(await readFile44(args.from));
|
|
32969
33263
|
if (!metadata || metadata.format !== "png") throw new UsageError(`${args.from} is not a PNG`);
|
|
32970
33264
|
const reading = await usage(() => chooseTilesetSheetReading(args.from, metadata.width, metadata.height, tileSize));
|
|
32971
33265
|
log(` would import ${args.from} as a ${mode2} tileset of ${reading.tileSize}px tiles (${reading.layout === "compact" ? "4 wide" : "8 wide"}); nothing sent`);
|
|
@@ -33004,7 +33298,7 @@ async function runSave(args, emit) {
|
|
|
33004
33298
|
if (!args.from) throw new UsageError("asset save needs --from: a PNG, an animated GIF, or a directory of PNG frames");
|
|
33005
33299
|
await usage(() => checkSaveTarget(target));
|
|
33006
33300
|
const adding = target === "gallery:new";
|
|
33007
|
-
const undoDir = args.out ?
|
|
33301
|
+
const undoDir = args.out ? path64.resolve(args.out) : saveUndoDir(target);
|
|
33008
33302
|
if (adding) log(` add ${args.from} to your PixelLab gallery as a new image (free)`);
|
|
33009
33303
|
else {
|
|
33010
33304
|
log(` save ${args.from} over ${target} on PixelLab (free)`);
|
|
@@ -33027,21 +33321,21 @@ async function runSave(args, emit) {
|
|
|
33027
33321
|
else {
|
|
33028
33322
|
log(` ${res.target}: ${res.kind} saved, ${res.width}x${res.height}, ${res.frames} frame(s), ${res.changedPixels} pixel(s) changed`);
|
|
33029
33323
|
for (const file of res.undo) log(` kept the old pixels: ${file}`);
|
|
33030
|
-
if (res.undo.length) log(` undo: pixelkiln asset save --target ${res.target} --from ${res.undo.length === 1 ? res.undo[0] :
|
|
33324
|
+
if (res.undo.length) log(` undo: pixelkiln asset save --target ${res.target} --from ${res.undo.length === 1 ? res.undo[0] : path64.dirname(res.undo[0])} --yes`);
|
|
33031
33325
|
}
|
|
33032
33326
|
if (res.note) log(` ${res.note}`);
|
|
33033
33327
|
if (res.maps) log(` ${res.maps}`);
|
|
33034
33328
|
}
|
|
33035
33329
|
|
|
33036
33330
|
// src/cli/commands/talk.ts
|
|
33331
|
+
import { existsSync as existsSync53 } from "fs";
|
|
33332
|
+
import { mkdir as mkdir25, readFile as readFile46, writeFile as writeFile30 } from "fs/promises";
|
|
33333
|
+
import path66 from "path";
|
|
33334
|
+
|
|
33335
|
+
// src/pixellab-talk.ts
|
|
33037
33336
|
import { existsSync as existsSync52 } from "fs";
|
|
33038
33337
|
import { mkdir as mkdir24, readFile as readFile45, writeFile as writeFile29 } from "fs/promises";
|
|
33039
33338
|
import path65 from "path";
|
|
33040
|
-
|
|
33041
|
-
// src/pixellab-talk.ts
|
|
33042
|
-
import { existsSync as existsSync51 } from "fs";
|
|
33043
|
-
import { mkdir as mkdir23, readFile as readFile44, writeFile as writeFile28 } from "fs/promises";
|
|
33044
|
-
import path64 from "path";
|
|
33045
33339
|
var TALK_MOODS = ["neutral", "happy", "angry", "sad", "surprised"];
|
|
33046
33340
|
var VISEME_COUNTS = [3, 5, 7, 12];
|
|
33047
33341
|
var VISEME_ENGINES = ["v3", "pixminimax"];
|
|
@@ -33052,7 +33346,7 @@ function visemeCost(engine, side, count) {
|
|
|
33052
33346
|
return Math.ceil(forSeven * count / 7);
|
|
33053
33347
|
}
|
|
33054
33348
|
function talkOutputPaths(out) {
|
|
33055
|
-
const base =
|
|
33349
|
+
const base = path65.resolve(out.replace(/\.(png|json)$/i, "").replace(/\.(talk|visemes)$/i, ""));
|
|
33056
33350
|
return { strip: `${base}.visemes.png`, record: `${base}.talk.json` };
|
|
33057
33351
|
}
|
|
33058
33352
|
function readPortrait(bytes, label) {
|
|
@@ -33094,14 +33388,14 @@ async function makeVisemes(client2, opts) {
|
|
|
33094
33388
|
if (Boolean(opts.portrait) === Boolean(opts.characterId)) throw new Error("give a portrait file or a character id, not both");
|
|
33095
33389
|
const paths = talkOutputPaths(opts.out);
|
|
33096
33390
|
if (!opts.force) {
|
|
33097
|
-
for (const file of [paths.strip, paths.record]) if (
|
|
33391
|
+
for (const file of [paths.strip, paths.record]) if (existsSync52(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
33098
33392
|
}
|
|
33099
33393
|
const progress2 = opts.onProgress ?? (() => {
|
|
33100
33394
|
});
|
|
33101
33395
|
const sleep3 = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
33102
33396
|
const interval = opts.intervalMs ?? 8e3;
|
|
33103
33397
|
const timeout = opts.timeoutMs ?? 10 * 6e4;
|
|
33104
|
-
const portrait = opts.portrait ? readPortrait(await
|
|
33398
|
+
const portrait = opts.portrait ? readPortrait(await readFile45(opts.portrait), opts.portrait) : void 0;
|
|
33105
33399
|
const engine = opts.engine ?? "v3";
|
|
33106
33400
|
const visemeCount = opts.visemeCount ?? 7;
|
|
33107
33401
|
const submitted = await client2.createVocalAnimation({
|
|
@@ -33146,8 +33440,8 @@ async function makeVisemes(client2, opts) {
|
|
|
33146
33440
|
throw new Error(`PixelLab vocal-animation job ${jobId} finished with no mouth positions and no spritesheet`);
|
|
33147
33441
|
}
|
|
33148
33442
|
const usage2 = (await client2.getBackgroundJob(jobId).catch(() => null))?.usage ?? job.usage ?? null;
|
|
33149
|
-
await
|
|
33150
|
-
await
|
|
33443
|
+
await mkdir24(path65.dirname(paths.strip), { recursive: true });
|
|
33444
|
+
await writeFile29(paths.strip, strip);
|
|
33151
33445
|
const record = {
|
|
33152
33446
|
version: 1,
|
|
33153
33447
|
provider: "pixellab",
|
|
@@ -33157,31 +33451,31 @@ async function makeVisemes(client2, opts) {
|
|
|
33157
33451
|
visemeCount,
|
|
33158
33452
|
visemeOrder,
|
|
33159
33453
|
cell,
|
|
33160
|
-
strip:
|
|
33161
|
-
source: opts.portrait ? { portrait:
|
|
33454
|
+
strip: path65.basename(paths.strip),
|
|
33455
|
+
source: opts.portrait ? { portrait: path65.relative(path65.dirname(paths.record), path65.resolve(opts.portrait)).split(path65.sep).join("/") } : { characterId: opts.characterId },
|
|
33162
33456
|
...job.moods_on_character ? { moodsOnCharacter: job.moods_on_character } : {},
|
|
33163
33457
|
jobId,
|
|
33164
33458
|
usage: usage2,
|
|
33165
33459
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
33166
33460
|
};
|
|
33167
|
-
await
|
|
33461
|
+
await writeFile29(paths.record, `${JSON.stringify(record, null, 2)}
|
|
33168
33462
|
`);
|
|
33169
33463
|
return { ...record, paths };
|
|
33170
33464
|
}
|
|
33171
33465
|
async function readTalkRecord(file) {
|
|
33172
33466
|
let record;
|
|
33173
33467
|
try {
|
|
33174
|
-
record = JSON.parse(await
|
|
33468
|
+
record = JSON.parse(await readFile45(file, "utf8"));
|
|
33175
33469
|
} catch (error) {
|
|
33176
33470
|
throw new Error(`${file} is not a readable .talk.json record: ${error instanceof Error ? error.message : String(error)}`);
|
|
33177
33471
|
}
|
|
33178
33472
|
if (record?.tool !== "vocal-animation" || !Array.isArray(record.visemeOrder) || !record.cell || !record.strip) {
|
|
33179
33473
|
throw new Error(`${file} is not a .talk.json record from pixelkiln talk visemes`);
|
|
33180
33474
|
}
|
|
33181
|
-
const stripFile =
|
|
33182
|
-
if (!
|
|
33475
|
+
const stripFile = path65.resolve(path65.dirname(path65.resolve(file)), record.strip);
|
|
33476
|
+
if (!existsSync52(stripFile)) throw new Error(`${file} names ${record.strip}, which is missing beside it`);
|
|
33183
33477
|
const row = Math.max(0, record.moodsOnCharacter?.indexOf(record.mood) ?? 0);
|
|
33184
|
-
const cells = cutStrip(await
|
|
33478
|
+
const cells = cutStrip(await readFile45(stripFile), record.visemeOrder.length, record.cell, row);
|
|
33185
33479
|
const visemes = Object.fromEntries(record.visemeOrder.map((id, index) => [id, { base64: cells[index].toString("base64"), format: "png" }]));
|
|
33186
33480
|
return { record, visemes };
|
|
33187
33481
|
}
|
|
@@ -33194,15 +33488,15 @@ function checkText(text) {
|
|
|
33194
33488
|
async function makeTalkingGif(client2, text, source, opts) {
|
|
33195
33489
|
if (Boolean(source.record) === Boolean(source.characterId)) throw new Error("give a .talk.json record or a character id, not both");
|
|
33196
33490
|
if (source.record && source.mood) throw new Error("a record holds one expression; --mood picks among a character's stored ones");
|
|
33197
|
-
const out =
|
|
33198
|
-
if (
|
|
33491
|
+
const out = path65.extname(opts.out) ? path65.resolve(opts.out) : path65.resolve(`${opts.out}.gif`);
|
|
33492
|
+
if (existsSync52(out) && !opts.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
33199
33493
|
const line = checkText(text);
|
|
33200
33494
|
const visemes = source.record ? (await readTalkRecord(source.record)).visemes : void 0;
|
|
33201
33495
|
const res = await client2.createTalkingGif({ text: line, visemes, characterId: source.characterId, mood: source.mood, frameMs: opts.frameMs, holdMs: opts.holdMs });
|
|
33202
33496
|
const bytes = Buffer.from(res.gif_base64, "base64");
|
|
33203
33497
|
if (bytes.subarray(0, 4).toString("ascii") !== "GIF8") throw new Error(`PixelLab's talking GIF was not a GIF (${bytes.length} bytes)`);
|
|
33204
|
-
await
|
|
33205
|
-
await
|
|
33498
|
+
await mkdir24(path65.dirname(out), { recursive: true });
|
|
33499
|
+
await writeFile29(out, bytes);
|
|
33206
33500
|
return { out, frames: res.frames, durationMs: res.duration_ms, frameMs: res.frame_ms, holdMs: res.hold_ms, width: res.width, height: res.height, bytes: bytes.length };
|
|
33207
33501
|
}
|
|
33208
33502
|
async function planLipSync(client2, text, source, opts = {}) {
|
|
@@ -33234,7 +33528,7 @@ async function planLipSync(client2, text, source, opts = {}) {
|
|
|
33234
33528
|
|
|
33235
33529
|
// src/cli/commands/talk.ts
|
|
33236
33530
|
function loadKeys5(args) {
|
|
33237
|
-
loadEnvFiles(
|
|
33531
|
+
loadEnvFiles(path66.dirname(path66.resolve(args.manifest)));
|
|
33238
33532
|
loadEnvFiles(process.cwd());
|
|
33239
33533
|
}
|
|
33240
33534
|
function moodOf(args) {
|
|
@@ -33256,7 +33550,7 @@ function textOf(args) {
|
|
|
33256
33550
|
}
|
|
33257
33551
|
function sourceOf(args) {
|
|
33258
33552
|
if (args.from && args.id) throw new UsageError("pass --from <record.talk.json> or --id <character id>, not both");
|
|
33259
|
-
if (args.from && !
|
|
33553
|
+
if (args.from && !existsSync53(args.from)) throw new UsageError(`${args.from} does not exist; --from is the .talk.json record talk visemes wrote`);
|
|
33260
33554
|
return { record: args.from, characterId: args.id };
|
|
33261
33555
|
}
|
|
33262
33556
|
async function runVisemes(args) {
|
|
@@ -33272,9 +33566,9 @@ async function runVisemes(args) {
|
|
|
33272
33566
|
const paths = talkOutputPaths(args.out);
|
|
33273
33567
|
let side = "unknown";
|
|
33274
33568
|
if (args.from) {
|
|
33275
|
-
if (!
|
|
33569
|
+
if (!existsSync53(args.from)) throw new UsageError(`${args.from} does not exist`);
|
|
33276
33570
|
try {
|
|
33277
|
-
side = readPortrait(await
|
|
33571
|
+
side = readPortrait(await readFile46(args.from), args.from).side;
|
|
33278
33572
|
} catch (error) {
|
|
33279
33573
|
throw new UsageError(error instanceof Error ? error.message : String(error));
|
|
33280
33574
|
}
|
|
@@ -33357,10 +33651,10 @@ async function runPlan2(args) {
|
|
|
33357
33651
|
log(json.trimEnd());
|
|
33358
33652
|
return;
|
|
33359
33653
|
}
|
|
33360
|
-
const out =
|
|
33361
|
-
if (
|
|
33362
|
-
await
|
|
33363
|
-
await
|
|
33654
|
+
const out = path66.extname(args.out) ? path66.resolve(args.out) : path66.resolve(`${args.out}.json`);
|
|
33655
|
+
if (existsSync53(out) && !args.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
33656
|
+
await mkdir25(path66.dirname(out), { recursive: true });
|
|
33657
|
+
await writeFile30(out, json);
|
|
33364
33658
|
if (args.json) log(json.trimEnd());
|
|
33365
33659
|
else log(` wrote ${out} (${plan.frames.length} frames, ${(plan.totalMs / 1e3).toFixed(2)} s, free)`);
|
|
33366
33660
|
}
|
|
@@ -33371,19 +33665,19 @@ async function runTalk(args) {
|
|
|
33371
33665
|
}
|
|
33372
33666
|
|
|
33373
33667
|
// src/cli/commands/quality.ts
|
|
33374
|
-
import
|
|
33375
|
-
import { readFile as
|
|
33668
|
+
import path68 from "path";
|
|
33669
|
+
import { readFile as readFile48 } from "fs/promises";
|
|
33376
33670
|
|
|
33377
33671
|
// src/pipeline/quality-regression.ts
|
|
33378
|
-
import
|
|
33379
|
-
import { existsSync as
|
|
33380
|
-
import { readFile as
|
|
33381
|
-
import { z as
|
|
33672
|
+
import path67 from "path";
|
|
33673
|
+
import { existsSync as existsSync54 } from "fs";
|
|
33674
|
+
import { readFile as readFile47 } from "fs/promises";
|
|
33675
|
+
import { z as z17 } from "zod";
|
|
33382
33676
|
var SHA256_RE = /^[0-9a-f]{64}$/;
|
|
33383
33677
|
var HEX_RE = /^#[0-9a-f]{6}$/;
|
|
33384
33678
|
var MAX_REDMEAN_DISTANCE = 765;
|
|
33385
|
-
var QualityPathSchema =
|
|
33386
|
-
(value) => !
|
|
33679
|
+
var QualityPathSchema = z17.string().min(1).refine(
|
|
33680
|
+
(value) => !path67.posix.isAbsolute(value) && !value.includes("\\"),
|
|
33387
33681
|
"expected a portable relative path"
|
|
33388
33682
|
);
|
|
33389
33683
|
var DEFAULT_QUALITY_TOLERANCES = {
|
|
@@ -33396,53 +33690,53 @@ var DEFAULT_QUALITY_TOLERANCES = {
|
|
|
33396
33690
|
maxEdgeContrastDrop: 0.03,
|
|
33397
33691
|
maxIsolatedPixelIncrease: 5e-3
|
|
33398
33692
|
};
|
|
33399
|
-
var QualityToleranceSchema =
|
|
33400
|
-
requireExactHash:
|
|
33401
|
-
maxColorCountIncrease:
|
|
33402
|
-
maxNewColors:
|
|
33403
|
-
maxTransparencyDelta:
|
|
33404
|
-
maxPartialAlphaIncrease:
|
|
33405
|
-
maxEdgeDensityDelta:
|
|
33406
|
-
maxEdgeContrastDrop:
|
|
33407
|
-
maxIsolatedPixelIncrease:
|
|
33693
|
+
var QualityToleranceSchema = z17.object({
|
|
33694
|
+
requireExactHash: z17.boolean(),
|
|
33695
|
+
maxColorCountIncrease: z17.number().int().min(0),
|
|
33696
|
+
maxNewColors: z17.number().int().min(0),
|
|
33697
|
+
maxTransparencyDelta: z17.number().min(0).max(1),
|
|
33698
|
+
maxPartialAlphaIncrease: z17.number().min(0).max(1),
|
|
33699
|
+
maxEdgeDensityDelta: z17.number().min(0).max(1),
|
|
33700
|
+
maxEdgeContrastDrop: z17.number().min(0).max(1),
|
|
33701
|
+
maxIsolatedPixelIncrease: z17.number().min(0).max(1)
|
|
33408
33702
|
}).strict();
|
|
33409
|
-
var ImageQualityMetricsSchema =
|
|
33410
|
-
sha256:
|
|
33411
|
-
width:
|
|
33412
|
-
height:
|
|
33413
|
-
colorCount:
|
|
33414
|
-
colors:
|
|
33415
|
-
transparency:
|
|
33416
|
-
partialAlpha:
|
|
33417
|
-
edgeDensity:
|
|
33418
|
-
meanEdgeContrast:
|
|
33419
|
-
isolatedPixelRatio:
|
|
33703
|
+
var ImageQualityMetricsSchema = z17.object({
|
|
33704
|
+
sha256: z17.string().regex(SHA256_RE),
|
|
33705
|
+
width: z17.number().int().min(1),
|
|
33706
|
+
height: z17.number().int().min(1),
|
|
33707
|
+
colorCount: z17.number().int().min(0),
|
|
33708
|
+
colors: z17.array(z17.string().regex(HEX_RE)),
|
|
33709
|
+
transparency: z17.number().min(0).max(1),
|
|
33710
|
+
partialAlpha: z17.number().min(0).max(1),
|
|
33711
|
+
edgeDensity: z17.number().min(0).max(1),
|
|
33712
|
+
meanEdgeContrast: z17.number().min(0).max(1),
|
|
33713
|
+
isolatedPixelRatio: z17.number().min(0).max(1)
|
|
33420
33714
|
}).strict();
|
|
33421
|
-
var QualityBaselineCaseSchema =
|
|
33422
|
-
id:
|
|
33715
|
+
var QualityBaselineCaseSchema = z17.object({
|
|
33716
|
+
id: z17.string().regex(/^[a-z0-9][a-z0-9/_-]*$/),
|
|
33423
33717
|
file: QualityPathSchema,
|
|
33424
|
-
record:
|
|
33718
|
+
record: z17.object({
|
|
33425
33719
|
path: QualityPathSchema,
|
|
33426
|
-
sha256:
|
|
33720
|
+
sha256: z17.string().regex(SHA256_RE)
|
|
33427
33721
|
}).strict().optional(),
|
|
33428
33722
|
expected: ImageQualityMetricsSchema,
|
|
33429
33723
|
tolerances: QualityToleranceSchema
|
|
33430
33724
|
}).strict();
|
|
33431
|
-
var QualityBaselineSchema =
|
|
33432
|
-
$schema:
|
|
33433
|
-
format:
|
|
33434
|
-
schemaVersion:
|
|
33435
|
-
cases:
|
|
33725
|
+
var QualityBaselineSchema = z17.object({
|
|
33726
|
+
$schema: z17.string().url().optional(),
|
|
33727
|
+
format: z17.literal("pixelkiln-quality-baseline"),
|
|
33728
|
+
schemaVersion: z17.literal(1),
|
|
33729
|
+
cases: z17.array(QualityBaselineCaseSchema).min(1)
|
|
33436
33730
|
}).strict().superRefine((baseline, context) => {
|
|
33437
33731
|
const ids = baseline.cases.map((entry) => entry.id);
|
|
33438
33732
|
if (new Set(ids).size !== ids.length) {
|
|
33439
|
-
context.addIssue({ code:
|
|
33733
|
+
context.addIssue({ code: z17.ZodIssueCode.custom, path: ["cases"], message: "duplicate case id" });
|
|
33440
33734
|
}
|
|
33441
33735
|
});
|
|
33442
|
-
var QualityInputSchema =
|
|
33443
|
-
id:
|
|
33444
|
-
path:
|
|
33445
|
-
record:
|
|
33736
|
+
var QualityInputSchema = z17.object({
|
|
33737
|
+
id: z17.string().regex(/^[a-z0-9][a-z0-9/_-]*$/),
|
|
33738
|
+
path: z17.string().min(1),
|
|
33739
|
+
record: z17.string().min(1).optional(),
|
|
33446
33740
|
tolerances: QualityToleranceSchema.partial().optional()
|
|
33447
33741
|
}).strict();
|
|
33448
33742
|
function message4(error) {
|
|
@@ -33530,10 +33824,10 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
33530
33824
|
};
|
|
33531
33825
|
}
|
|
33532
33826
|
async function measureImageQuality(file) {
|
|
33533
|
-
const absolute =
|
|
33827
|
+
const absolute = path67.resolve(file);
|
|
33534
33828
|
let bytes;
|
|
33535
33829
|
try {
|
|
33536
|
-
bytes = await
|
|
33830
|
+
bytes = await readFile47(absolute);
|
|
33537
33831
|
} catch (error) {
|
|
33538
33832
|
throw new Error(`Cannot read quality image ${absolute}: ${message4(error)}`, { cause: error });
|
|
33539
33833
|
}
|
|
@@ -33544,7 +33838,7 @@ async function measureImageQuality(file) {
|
|
|
33544
33838
|
}
|
|
33545
33839
|
}
|
|
33546
33840
|
function resolveQualityInputs(raw, inputsFilePath) {
|
|
33547
|
-
const parsed =
|
|
33841
|
+
const parsed = z17.array(QualityInputSchema).min(1).safeParse(raw);
|
|
33548
33842
|
if (!parsed.success) {
|
|
33549
33843
|
throw new Error(
|
|
33550
33844
|
"--inputs must be a non-empty JSON array of quality cases:\n" + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
|
|
@@ -33552,11 +33846,11 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
33552
33846
|
}
|
|
33553
33847
|
const ids = parsed.data.map((entry) => entry.id);
|
|
33554
33848
|
if (new Set(ids).size !== ids.length) throw new Error("--inputs contains a duplicate quality case id.");
|
|
33555
|
-
const root =
|
|
33849
|
+
const root = path67.dirname(path67.resolve(inputsFilePath));
|
|
33556
33850
|
return parsed.data.map((entry) => ({
|
|
33557
33851
|
id: entry.id,
|
|
33558
|
-
file:
|
|
33559
|
-
...entry.record ? { record:
|
|
33852
|
+
file: path67.resolve(root, entry.path),
|
|
33853
|
+
...entry.record ? { record: path67.resolve(root, entry.record) } : {},
|
|
33560
33854
|
tolerances: QualityToleranceSchema.parse({
|
|
33561
33855
|
...DEFAULT_QUALITY_TOLERANCES,
|
|
33562
33856
|
...entry.tolerances
|
|
@@ -33564,7 +33858,7 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
33564
33858
|
}));
|
|
33565
33859
|
}
|
|
33566
33860
|
function portableRelative2(from, to) {
|
|
33567
|
-
return
|
|
33861
|
+
return path67.relative(from, path67.resolve(to)).split(path67.sep).join("/") || ".";
|
|
33568
33862
|
}
|
|
33569
33863
|
async function verifyRecordForImage(recordPath, imagePath) {
|
|
33570
33864
|
const verification = await verifyArtifactBundle(recordPath);
|
|
@@ -33579,20 +33873,20 @@ async function verifyRecordForImage(recordPath, imagePath) {
|
|
|
33579
33873
|
if (record.kind !== "refine" || options === null || typeof options !== "object" || options.schema !== "pixelkiln-quality") {
|
|
33580
33874
|
throw new Error(`Quality record ${recordPath} is not a PixelKiln refinement record.`);
|
|
33581
33875
|
}
|
|
33582
|
-
const outputs = record.outputs.map((output) =>
|
|
33583
|
-
if (!outputs.includes(
|
|
33876
|
+
const outputs = record.outputs.map((output) => path67.resolve(path67.dirname(recordPath), output.path));
|
|
33877
|
+
if (!outputs.includes(path67.resolve(imagePath))) {
|
|
33584
33878
|
throw new Error(`Quality record ${recordPath} does not own ${imagePath}.`);
|
|
33585
33879
|
}
|
|
33586
33880
|
}
|
|
33587
33881
|
async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
33588
33882
|
if (!inputs.length) throw new Error("Cannot snapshot an empty quality baseline.");
|
|
33589
|
-
const absolute =
|
|
33883
|
+
const absolute = path67.resolve(baselinePath);
|
|
33590
33884
|
for (const input of inputs) {
|
|
33591
|
-
if (
|
|
33885
|
+
if (path67.resolve(input.file) === absolute || input.record && path67.resolve(input.record) === absolute) {
|
|
33592
33886
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
33593
33887
|
}
|
|
33594
33888
|
}
|
|
33595
|
-
const root =
|
|
33889
|
+
const root = path67.dirname(absolute);
|
|
33596
33890
|
const cases = [];
|
|
33597
33891
|
for (const input of [...inputs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
33598
33892
|
const expected = await measureImageQuality(input.file);
|
|
@@ -33619,8 +33913,8 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
33619
33913
|
cases
|
|
33620
33914
|
});
|
|
33621
33915
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
33622
|
-
if (
|
|
33623
|
-
const current = await
|
|
33916
|
+
if (existsSync54(absolute) && !options.force) {
|
|
33917
|
+
const current = await readFile47(absolute);
|
|
33624
33918
|
if (!current.equals(data)) {
|
|
33625
33919
|
throw new OverwriteRefusedError(
|
|
33626
33920
|
`Quality baseline already exists with different content: ${absolute}. Pass --force to replace it.`,
|
|
@@ -33632,13 +33926,13 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
33632
33926
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
33633
33927
|
}
|
|
33634
33928
|
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
33635
|
-
const absolute =
|
|
33636
|
-
if (!
|
|
33929
|
+
const absolute = path67.resolve(baselinePath);
|
|
33930
|
+
if (!existsSync54(absolute)) {
|
|
33637
33931
|
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
33638
33932
|
}
|
|
33639
33933
|
let raw;
|
|
33640
33934
|
try {
|
|
33641
|
-
raw = JSON.parse(await
|
|
33935
|
+
raw = JSON.parse(await readFile47(absolute, "utf8"));
|
|
33642
33936
|
} catch (error) {
|
|
33643
33937
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
33644
33938
|
}
|
|
@@ -33648,12 +33942,12 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
33648
33942
|
if (unknown.length) {
|
|
33649
33943
|
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
33650
33944
|
}
|
|
33651
|
-
const root =
|
|
33945
|
+
const root = path67.dirname(absolute);
|
|
33652
33946
|
const cases = [...raw.cases];
|
|
33653
33947
|
const report = [];
|
|
33654
33948
|
for (const id of only) {
|
|
33655
33949
|
const input = byId.get(id);
|
|
33656
|
-
if (
|
|
33950
|
+
if (path67.resolve(input.file) === absolute || input.record && path67.resolve(input.record) === absolute) {
|
|
33657
33951
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
33658
33952
|
}
|
|
33659
33953
|
const expected = await measureImageQuality(input.file);
|
|
@@ -33683,16 +33977,16 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
33683
33977
|
}
|
|
33684
33978
|
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
33685
33979
|
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
33686
|
-
const current = await
|
|
33980
|
+
const current = await readFile47(absolute);
|
|
33687
33981
|
const changed = !current.equals(data);
|
|
33688
33982
|
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
33689
33983
|
return { baseline, path: absolute, changed, cases: report };
|
|
33690
33984
|
}
|
|
33691
33985
|
async function readQualityBaseline(baselinePath) {
|
|
33692
|
-
const absolute =
|
|
33986
|
+
const absolute = path67.resolve(baselinePath);
|
|
33693
33987
|
let raw;
|
|
33694
33988
|
try {
|
|
33695
|
-
raw = JSON.parse(await
|
|
33989
|
+
raw = JSON.parse(await readFile47(absolute, "utf8"));
|
|
33696
33990
|
} catch (error) {
|
|
33697
33991
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
33698
33992
|
}
|
|
@@ -33714,7 +34008,7 @@ async function readQualityBaseline(baselinePath) {
|
|
|
33714
34008
|
throw new Error(
|
|
33715
34009
|
`Invalid quality baseline ${absolute}:
|
|
33716
34010
|
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
33717
|
-
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${
|
|
34011
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path67.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
33718
34012
|
);
|
|
33719
34013
|
}
|
|
33720
34014
|
return parsed.data;
|
|
@@ -33776,12 +34070,12 @@ function regressionViolations(expected, actual, tolerances) {
|
|
|
33776
34070
|
return { violations, warnings };
|
|
33777
34071
|
}
|
|
33778
34072
|
async function checkQualityBaseline(baselinePath) {
|
|
33779
|
-
const absolute =
|
|
34073
|
+
const absolute = path67.resolve(baselinePath);
|
|
33780
34074
|
const baseline = await readQualityBaseline(absolute);
|
|
33781
|
-
const root =
|
|
34075
|
+
const root = path67.dirname(absolute);
|
|
33782
34076
|
const cases = [];
|
|
33783
34077
|
for (const entry of baseline.cases) {
|
|
33784
|
-
const file =
|
|
34078
|
+
const file = path67.resolve(root, entry.file);
|
|
33785
34079
|
let actual = null;
|
|
33786
34080
|
const violations = [];
|
|
33787
34081
|
const warnings = [];
|
|
@@ -33794,7 +34088,7 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
33794
34088
|
violations.push(message4(error));
|
|
33795
34089
|
}
|
|
33796
34090
|
if (entry.record) {
|
|
33797
|
-
const recordPath =
|
|
34091
|
+
const recordPath = path67.resolve(root, entry.record.path);
|
|
33798
34092
|
try {
|
|
33799
34093
|
const recordHash = await sha256File(recordPath);
|
|
33800
34094
|
if (recordHash !== entry.record.sha256) violations.push("quality record hash changed");
|
|
@@ -33836,15 +34130,15 @@ async function runQuality(args) {
|
|
|
33836
34130
|
if (!args.out) throw new Error("quality snapshot needs --out <pixelkiln.quality.json>.");
|
|
33837
34131
|
let raw;
|
|
33838
34132
|
try {
|
|
33839
|
-
raw = JSON.parse(await
|
|
34133
|
+
raw = JSON.parse(await readFile48(path68.resolve(args.inputs), "utf8"));
|
|
33840
34134
|
} catch (error) {
|
|
33841
34135
|
throw new Error(
|
|
33842
|
-
`Could not read quality inputs ${
|
|
34136
|
+
`Could not read quality inputs ${path68.resolve(args.inputs)}: ${error instanceof Error ? error.message : String(error)}`,
|
|
33843
34137
|
{ cause: error }
|
|
33844
34138
|
);
|
|
33845
34139
|
}
|
|
33846
34140
|
const inputs = resolveQualityInputs(raw, args.inputs);
|
|
33847
|
-
if (
|
|
34141
|
+
if (path68.resolve(args.inputs) === path68.resolve(args.out)) {
|
|
33848
34142
|
throw new Error("quality snapshot --out must not overwrite its --inputs file.");
|
|
33849
34143
|
}
|
|
33850
34144
|
if (args.assets.length) {
|
|
@@ -33859,7 +34153,7 @@ async function runQuality(args) {
|
|
|
33859
34153
|
}
|
|
33860
34154
|
log(
|
|
33861
34155
|
`
|
|
33862
|
-
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${
|
|
34156
|
+
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${path68.relative(process.cwd(), result2.path)}; other cases left as they were.`
|
|
33863
34157
|
);
|
|
33864
34158
|
return;
|
|
33865
34159
|
}
|
|
@@ -33874,7 +34168,7 @@ async function runQuality(args) {
|
|
|
33874
34168
|
}, null, 2));
|
|
33875
34169
|
} else {
|
|
33876
34170
|
log(
|
|
33877
|
-
` ${result.changed ? "wrote" : "unchanged"} ${
|
|
34171
|
+
` ${result.changed ? "wrote" : "unchanged"} ${path68.relative(process.cwd(), result.path)} (${result.baseline.cases.length} case(s))`
|
|
33878
34172
|
);
|
|
33879
34173
|
log(` Review the tolerances, commit the baseline, then run quality check in CI.`);
|
|
33880
34174
|
}
|
|
@@ -33900,54 +34194,54 @@ async function runQuality(args) {
|
|
|
33900
34194
|
}
|
|
33901
34195
|
|
|
33902
34196
|
// src/cli/commands/recipe.ts
|
|
33903
|
-
import
|
|
34197
|
+
import path70 from "path";
|
|
33904
34198
|
|
|
33905
34199
|
// src/recipes.ts
|
|
33906
|
-
import
|
|
33907
|
-
import { existsSync as
|
|
33908
|
-
import { readdir as readdir6, readFile as
|
|
34200
|
+
import path69 from "path";
|
|
34201
|
+
import { existsSync as existsSync55 } from "fs";
|
|
34202
|
+
import { readdir as readdir6, readFile as readFile49 } from "fs/promises";
|
|
33909
34203
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
33910
|
-
import { z as
|
|
34204
|
+
import { z as z18 } from "zod";
|
|
33911
34205
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
33912
34206
|
var RECIPE_ID_RE = /^[a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*$/;
|
|
33913
34207
|
var VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
33914
34208
|
var RECIPE_FILE = "pixelkiln.recipe.json";
|
|
33915
34209
|
var RECIPE_DIR_TOKEN = "{{recipeDir}}";
|
|
33916
|
-
var PortablePathSchema =
|
|
33917
|
-
if (value.includes("\\") ||
|
|
34210
|
+
var PortablePathSchema = z18.string().min(1).refine((value) => {
|
|
34211
|
+
if (value.includes("\\") || path69.posix.isAbsolute(value)) return false;
|
|
33918
34212
|
const parts = value.split("/");
|
|
33919
34213
|
return !parts.includes("") && !parts.includes(".") && !parts.includes("..");
|
|
33920
34214
|
}, "expected a portable relative path without '.', '..', or backslashes");
|
|
33921
|
-
var RecipeBindingSchema =
|
|
33922
|
-
nodeId:
|
|
33923
|
-
input:
|
|
34215
|
+
var RecipeBindingSchema = z18.object({
|
|
34216
|
+
nodeId: z18.string().min(1),
|
|
34217
|
+
input: z18.string().min(1)
|
|
33924
34218
|
}).strict();
|
|
33925
|
-
var RecipeSchema =
|
|
33926
|
-
$schema:
|
|
33927
|
-
format:
|
|
33928
|
-
schemaVersion:
|
|
33929
|
-
id:
|
|
33930
|
-
version:
|
|
33931
|
-
provider:
|
|
33932
|
-
summary:
|
|
33933
|
-
files:
|
|
34219
|
+
var RecipeSchema = z18.object({
|
|
34220
|
+
$schema: z18.string().url().optional(),
|
|
34221
|
+
format: z18.literal("pixelkiln-recipe"),
|
|
34222
|
+
schemaVersion: z18.literal(1),
|
|
34223
|
+
id: z18.string().regex(RECIPE_ID_RE, "expected provider/name"),
|
|
34224
|
+
version: z18.string().regex(VERSION_RE, "expected x.y.z"),
|
|
34225
|
+
provider: z18.string().regex(/^[a-z0-9][a-z0-9-]*$/),
|
|
34226
|
+
summary: z18.string().min(1).max(240),
|
|
34227
|
+
files: z18.array(z18.object({
|
|
33934
34228
|
path: PortablePathSchema,
|
|
33935
|
-
role:
|
|
33936
|
-
sha256:
|
|
34229
|
+
role: z18.enum(["workflow", "reference"]),
|
|
34230
|
+
sha256: z18.string().regex(SHA256_RE2)
|
|
33937
34231
|
}).strict()).default([]),
|
|
33938
|
-
models:
|
|
34232
|
+
models: z18.array(z18.object({
|
|
33939
34233
|
path: PortablePathSchema,
|
|
33940
|
-
sha256:
|
|
33941
|
-
source:
|
|
33942
|
-
license:
|
|
34234
|
+
sha256: z18.string().regex(SHA256_RE2),
|
|
34235
|
+
source: z18.string().url(),
|
|
34236
|
+
license: z18.string().min(1)
|
|
33943
34237
|
}).strict()).default([]),
|
|
33944
|
-
styleId:
|
|
34238
|
+
styleId: z18.string().regex(/^[a-z0-9][a-z0-9-]*$/),
|
|
33945
34239
|
style: StyleSchema,
|
|
33946
|
-
workflow:
|
|
34240
|
+
workflow: z18.object({
|
|
33947
34241
|
path: PortablePathSchema,
|
|
33948
|
-
outputNodeId:
|
|
33949
|
-
numImages:
|
|
33950
|
-
bindings:
|
|
34242
|
+
outputNodeId: z18.string().min(1),
|
|
34243
|
+
numImages: z18.number().int().min(1).max(16),
|
|
34244
|
+
bindings: z18.object({
|
|
33951
34245
|
prompt: RecipeBindingSchema,
|
|
33952
34246
|
width: RecipeBindingSchema.optional(),
|
|
33953
34247
|
height: RecipeBindingSchema.optional(),
|
|
@@ -33958,67 +34252,67 @@ var RecipeSchema = z17.object({
|
|
|
33958
34252
|
strength: RecipeBindingSchema.optional()
|
|
33959
34253
|
}).strict()
|
|
33960
34254
|
}).strict().optional(),
|
|
33961
|
-
quality:
|
|
33962
|
-
stage:
|
|
33963
|
-
workingCanvas:
|
|
33964
|
-
width:
|
|
33965
|
-
height:
|
|
34255
|
+
quality: z18.object({
|
|
34256
|
+
stage: z18.enum(["composition-source", "production-candidate"]),
|
|
34257
|
+
workingCanvas: z18.object({
|
|
34258
|
+
width: z18.number().int().min(16),
|
|
34259
|
+
height: z18.number().int().min(16)
|
|
33966
34260
|
}).strict(),
|
|
33967
|
-
recommendedNativeSize:
|
|
33968
|
-
min:
|
|
33969
|
-
max:
|
|
34261
|
+
recommendedNativeSize: z18.object({
|
|
34262
|
+
min: z18.number().int().min(1),
|
|
34263
|
+
max: z18.number().int().min(1)
|
|
33970
34264
|
}).strict(),
|
|
33971
|
-
paletteColors:
|
|
33972
|
-
min:
|
|
33973
|
-
max:
|
|
34265
|
+
paletteColors: z18.object({
|
|
34266
|
+
min: z18.number().int().min(1),
|
|
34267
|
+
max: z18.number().int().min(1)
|
|
33974
34268
|
}).strict(),
|
|
33975
|
-
background:
|
|
33976
|
-
checks:
|
|
34269
|
+
background: z18.enum(["opaque", "transparent", "full-bleed"]),
|
|
34270
|
+
checks: z18.array(z18.enum([
|
|
33977
34271
|
"prompt-coverage",
|
|
33978
34272
|
"native-grid",
|
|
33979
34273
|
"final-palette",
|
|
33980
34274
|
"alpha-edge",
|
|
33981
34275
|
"human-1x"
|
|
33982
34276
|
])).min(1),
|
|
33983
|
-
notes:
|
|
34277
|
+
notes: z18.array(z18.string().min(1)).default([])
|
|
33984
34278
|
}).strict(),
|
|
33985
|
-
integrity:
|
|
33986
|
-
algorithm:
|
|
33987
|
-
digest:
|
|
34279
|
+
integrity: z18.object({
|
|
34280
|
+
algorithm: z18.literal("sha256"),
|
|
34281
|
+
digest: z18.string().regex(SHA256_RE2)
|
|
33988
34282
|
}).strict()
|
|
33989
34283
|
}).strict().superRefine((recipe, context) => {
|
|
33990
34284
|
if (recipe.style.provider && recipe.style.provider !== recipe.provider) {
|
|
33991
34285
|
context.addIssue({
|
|
33992
|
-
code:
|
|
34286
|
+
code: z18.ZodIssueCode.custom,
|
|
33993
34287
|
path: ["style", "provider"],
|
|
33994
34288
|
message: "must match the recipe provider"
|
|
33995
34289
|
});
|
|
33996
34290
|
}
|
|
33997
34291
|
const filePaths = recipe.files.map((file) => file.path);
|
|
33998
34292
|
if (new Set(filePaths).size !== filePaths.length) {
|
|
33999
|
-
context.addIssue({ code:
|
|
34293
|
+
context.addIssue({ code: z18.ZodIssueCode.custom, path: ["files"], message: "duplicate file path" });
|
|
34000
34294
|
}
|
|
34001
34295
|
const modelPaths = recipe.models.map((model) => model.path);
|
|
34002
34296
|
if (new Set(modelPaths).size !== modelPaths.length) {
|
|
34003
|
-
context.addIssue({ code:
|
|
34297
|
+
context.addIssue({ code: z18.ZodIssueCode.custom, path: ["models"], message: "duplicate model path" });
|
|
34004
34298
|
}
|
|
34005
34299
|
if (filePaths.includes(RECIPE_FILE)) {
|
|
34006
34300
|
context.addIssue({
|
|
34007
|
-
code:
|
|
34301
|
+
code: z18.ZodIssueCode.custom,
|
|
34008
34302
|
path: ["files"],
|
|
34009
34303
|
message: `${RECIPE_FILE} cannot hash itself`
|
|
34010
34304
|
});
|
|
34011
34305
|
}
|
|
34012
34306
|
if (recipe.quality.recommendedNativeSize.min > recipe.quality.recommendedNativeSize.max) {
|
|
34013
34307
|
context.addIssue({
|
|
34014
|
-
code:
|
|
34308
|
+
code: z18.ZodIssueCode.custom,
|
|
34015
34309
|
path: ["quality", "recommendedNativeSize"],
|
|
34016
34310
|
message: "min cannot exceed max"
|
|
34017
34311
|
});
|
|
34018
34312
|
}
|
|
34019
34313
|
if (recipe.quality.paletteColors.min > recipe.quality.paletteColors.max) {
|
|
34020
34314
|
context.addIssue({
|
|
34021
|
-
code:
|
|
34315
|
+
code: z18.ZodIssueCode.custom,
|
|
34022
34316
|
path: ["quality", "paletteColors"],
|
|
34023
34317
|
message: "min cannot exceed max"
|
|
34024
34318
|
});
|
|
@@ -34027,7 +34321,7 @@ var RecipeSchema = z17.object({
|
|
|
34027
34321
|
(file) => file.path === recipe.workflow.path && file.role === "workflow"
|
|
34028
34322
|
)) {
|
|
34029
34323
|
context.addIssue({
|
|
34030
|
-
code:
|
|
34324
|
+
code: z18.ZodIssueCode.custom,
|
|
34031
34325
|
path: ["workflow", "path"],
|
|
34032
34326
|
message: "must name a file whose role is workflow"
|
|
34033
34327
|
});
|
|
@@ -34035,7 +34329,7 @@ var RecipeSchema = z17.object({
|
|
|
34035
34329
|
if (recipe.provider === "comfyui") {
|
|
34036
34330
|
if (!recipe.workflow) {
|
|
34037
34331
|
context.addIssue({
|
|
34038
|
-
code:
|
|
34332
|
+
code: z18.ZodIssueCode.custom,
|
|
34039
34333
|
path: ["workflow"],
|
|
34040
34334
|
message: "ComfyUI recipes require workflow metadata"
|
|
34041
34335
|
});
|
|
@@ -34044,7 +34338,7 @@ var RecipeSchema = z17.object({
|
|
|
34044
34338
|
const options = recipe.style.providerOptions.comfyui;
|
|
34045
34339
|
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
34046
34340
|
context.addIssue({
|
|
34047
|
-
code:
|
|
34341
|
+
code: z18.ZodIssueCode.custom,
|
|
34048
34342
|
path: ["style", "providerOptions", "comfyui"],
|
|
34049
34343
|
message: "ComfyUI recipes require ComfyUI provider options"
|
|
34050
34344
|
});
|
|
@@ -34058,7 +34352,7 @@ var RecipeSchema = z17.object({
|
|
|
34058
34352
|
};
|
|
34059
34353
|
if (JSON.stringify(canonical3(options)) !== JSON.stringify(canonical3(expected))) {
|
|
34060
34354
|
context.addIssue({
|
|
34061
|
-
code:
|
|
34355
|
+
code: z18.ZodIssueCode.custom,
|
|
34062
34356
|
path: ["style", "providerOptions", "comfyui"],
|
|
34063
34357
|
message: "must match workflow metadata and use {{recipeDir}} for workflowFile"
|
|
34064
34358
|
});
|
|
@@ -34090,10 +34384,10 @@ function message5(error) {
|
|
|
34090
34384
|
return error instanceof Error ? error.message : String(error);
|
|
34091
34385
|
}
|
|
34092
34386
|
async function readRecipeFile(recipePath, bundled) {
|
|
34093
|
-
const absolute =
|
|
34387
|
+
const absolute = path69.resolve(recipePath);
|
|
34094
34388
|
let raw;
|
|
34095
34389
|
try {
|
|
34096
|
-
raw = JSON.parse(await
|
|
34390
|
+
raw = JSON.parse(await readFile49(absolute, "utf8"));
|
|
34097
34391
|
} catch (error) {
|
|
34098
34392
|
throw new Error(`Could not read recipe ${absolute}: ${message5(error)}`, { cause: error });
|
|
34099
34393
|
}
|
|
@@ -34104,13 +34398,13 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
34104
34398
|
` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
|
|
34105
34399
|
);
|
|
34106
34400
|
}
|
|
34107
|
-
return { recipe: parsed.data, authored: raw, path: absolute, dir:
|
|
34401
|
+
return { recipe: parsed.data, authored: raw, path: absolute, dir: path69.dirname(absolute), bundled };
|
|
34108
34402
|
}
|
|
34109
34403
|
async function walkRecipeFiles(root) {
|
|
34110
|
-
if (!
|
|
34404
|
+
if (!existsSync55(root)) return [];
|
|
34111
34405
|
const out = [];
|
|
34112
34406
|
for (const entry of await readdir6(root, { withFileTypes: true })) {
|
|
34113
|
-
const resolved =
|
|
34407
|
+
const resolved = path69.join(root, entry.name);
|
|
34114
34408
|
if (entry.isDirectory()) out.push(...await walkRecipeFiles(resolved));
|
|
34115
34409
|
else if (entry.isFile() && entry.name === RECIPE_FILE) out.push(resolved);
|
|
34116
34410
|
}
|
|
@@ -34121,7 +34415,7 @@ function bundledRecipeRoot() {
|
|
|
34121
34415
|
}
|
|
34122
34416
|
async function listBundledRecipes(root = bundledRecipeRoot()) {
|
|
34123
34417
|
const recipes = await Promise.all(
|
|
34124
|
-
(await walkRecipeFiles(
|
|
34418
|
+
(await walkRecipeFiles(path69.resolve(root))).map((file) => readRecipeFile(file, true))
|
|
34125
34419
|
);
|
|
34126
34420
|
return recipes.sort(
|
|
34127
34421
|
(a, b) => a.recipe.id.localeCompare(b.recipe.id) || compareVersions(b.recipe.version, a.recipe.version)
|
|
@@ -34144,9 +34438,9 @@ function parseSelector(selector) {
|
|
|
34144
34438
|
return { id: match[1], version: match[2] };
|
|
34145
34439
|
}
|
|
34146
34440
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
34147
|
-
const local =
|
|
34148
|
-
if (
|
|
34149
|
-
const recipePath =
|
|
34441
|
+
const local = path69.resolve(target);
|
|
34442
|
+
if (existsSync55(local)) {
|
|
34443
|
+
const recipePath = path69.basename(local) === RECIPE_FILE ? local : path69.join(local, RECIPE_FILE);
|
|
34150
34444
|
return readRecipeFile(recipePath, false);
|
|
34151
34445
|
}
|
|
34152
34446
|
if (target.startsWith(".") || target.startsWith("/") || target.includes("\\")) {
|
|
@@ -34160,8 +34454,8 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
34160
34454
|
return matches[0];
|
|
34161
34455
|
}
|
|
34162
34456
|
async function verifyFile(root, file) {
|
|
34163
|
-
const absolute =
|
|
34164
|
-
if (!
|
|
34457
|
+
const absolute = path69.resolve(root, ...file.path.split("/"));
|
|
34458
|
+
if (!existsSync55(absolute)) {
|
|
34165
34459
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
34166
34460
|
}
|
|
34167
34461
|
const actualSha256 = await sha256File(absolute);
|
|
@@ -34176,7 +34470,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
34176
34470
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
34177
34471
|
const actualIntegrity = recipeDigest(loaded.authored);
|
|
34178
34472
|
const files = await Promise.all(loaded.recipe.files.map((file) => verifyFile(loaded.dir, file)));
|
|
34179
|
-
const modelRoot = options.modelRoot ?
|
|
34473
|
+
const modelRoot = options.modelRoot ? path69.resolve(options.modelRoot) : null;
|
|
34180
34474
|
const models = modelRoot ? await Promise.all(loaded.recipe.models.map(async (model) => ({
|
|
34181
34475
|
...await verifyFile(modelRoot, model),
|
|
34182
34476
|
source: model.source,
|
|
@@ -34210,7 +34504,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
34210
34504
|
};
|
|
34211
34505
|
}
|
|
34212
34506
|
function renderStyle(style, destination, cwd) {
|
|
34213
|
-
const portableDir =
|
|
34507
|
+
const portableDir = path69.relative(cwd, destination).split(path69.sep).join("/") || ".";
|
|
34214
34508
|
const replace = (value) => {
|
|
34215
34509
|
if (typeof value === "string") return value.replaceAll(RECIPE_DIR_TOKEN, portableDir);
|
|
34216
34510
|
if (Array.isArray(value)) return value.map(replace);
|
|
@@ -34222,25 +34516,25 @@ function renderStyle(style, destination, cwd) {
|
|
|
34222
34516
|
return replace(style);
|
|
34223
34517
|
}
|
|
34224
34518
|
async function installRecipe(target, options = {}) {
|
|
34225
|
-
const cwd =
|
|
34519
|
+
const cwd = path69.resolve(options.cwd ?? process.cwd());
|
|
34226
34520
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
34227
34521
|
const verification = await verifyRecipe(loaded.path);
|
|
34228
34522
|
if (!verification.ok) {
|
|
34229
34523
|
throw new Error(`Recipe ${loaded.recipe.id}@${loaded.recipe.version} failed integrity verification.`);
|
|
34230
34524
|
}
|
|
34231
|
-
const destination = options.out ?
|
|
34525
|
+
const destination = options.out ? path69.resolve(cwd, options.out) : path69.join(cwd, "pixelkiln-recipes", ...loaded.recipe.id.split("/"), loaded.recipe.version);
|
|
34232
34526
|
const sources = [
|
|
34233
34527
|
{ path: RECIPE_FILE, source: loaded.path },
|
|
34234
|
-
...loaded.recipe.files.map((file) => ({ path: file.path, source:
|
|
34528
|
+
...loaded.recipe.files.map((file) => ({ path: file.path, source: path69.join(loaded.dir, ...file.path.split("/")) }))
|
|
34235
34529
|
];
|
|
34236
34530
|
const files = await Promise.all(sources.map(async (file) => ({
|
|
34237
|
-
path:
|
|
34238
|
-
data: await
|
|
34531
|
+
path: path69.join(destination, ...file.path.split("/")),
|
|
34532
|
+
data: await readFile49(file.source)
|
|
34239
34533
|
})));
|
|
34240
34534
|
if (!options.force) {
|
|
34241
34535
|
for (const file of files) {
|
|
34242
|
-
if (!
|
|
34243
|
-
const current = await
|
|
34536
|
+
if (!existsSync55(file.path)) continue;
|
|
34537
|
+
const current = await readFile49(file.path);
|
|
34244
34538
|
if (!current.equals(file.data)) {
|
|
34245
34539
|
throw new OverwriteRefusedError(
|
|
34246
34540
|
`Recipe destination has local changes: ${file.path}. Choose another --out or pass --force to replace declared recipe files.`,
|
|
@@ -34334,14 +34628,14 @@ async function runRecipe(args) {
|
|
|
34334
34628
|
}, null, 2));
|
|
34335
34629
|
} else {
|
|
34336
34630
|
log(` installed ${result.recipe.id}@${result.recipe.version}`);
|
|
34337
|
-
log(` ${
|
|
34631
|
+
log(` ${path70.relative(process.cwd(), result.destination) || "."}`);
|
|
34338
34632
|
log(`
|
|
34339
34633
|
Add this entry under your manifest's styles object:`);
|
|
34340
34634
|
log(JSON.stringify({ [result.styleId]: result.style }, null, 2));
|
|
34341
34635
|
if (result.recipe.models.length) {
|
|
34342
34636
|
log(`
|
|
34343
34637
|
Models are not downloaded automatically. Verify them with:`);
|
|
34344
|
-
log(` pixelkiln recipe verify ${
|
|
34638
|
+
log(` pixelkiln recipe verify ${path70.relative(process.cwd(), result.destination)} --model-root <ComfyUI/models>`);
|
|
34345
34639
|
}
|
|
34346
34640
|
}
|
|
34347
34641
|
return;
|
|
@@ -34349,7 +34643,7 @@ async function runRecipe(args) {
|
|
|
34349
34643
|
}
|
|
34350
34644
|
|
|
34351
34645
|
// src/cli/commands/refine.ts
|
|
34352
|
-
import
|
|
34646
|
+
import path71 from "path";
|
|
34353
34647
|
async function runRefine(args) {
|
|
34354
34648
|
if (args.from || args.subcommand === "approve") {
|
|
34355
34649
|
if (!args.from) {
|
|
@@ -34379,12 +34673,12 @@ async function runRefine(args) {
|
|
|
34379
34673
|
` recovered ${result3.detection.columns}x${result3.detection.rows} native grid (${result3.detection.confidence}: ${result3.detection.consensus})`
|
|
34380
34674
|
);
|
|
34381
34675
|
log(` enforced ${result3.palette.length}-color palette without dithering`);
|
|
34382
|
-
log(` wrote ${
|
|
34383
|
-
log(` quality record: ${
|
|
34676
|
+
log(` wrote ${path71.relative(process.cwd(), result3.output)}`);
|
|
34677
|
+
log(` quality record: ${path71.relative(process.cwd(), result3.record)}`);
|
|
34384
34678
|
log(`
|
|
34385
34679
|
Automated checks passed. Human 1\xD7 review is still required:`);
|
|
34386
34680
|
log(
|
|
34387
|
-
` pixelkiln refine approve --from ${
|
|
34681
|
+
` pixelkiln refine approve --from ${path71.relative(process.cwd(), result3.record)} --reviewer "Your Name"`
|
|
34388
34682
|
);
|
|
34389
34683
|
}
|
|
34390
34684
|
return;
|
|
@@ -34412,7 +34706,7 @@ async function runRefine(args) {
|
|
|
34412
34706
|
if (args.json) log(JSON.stringify(result3, null, 2));
|
|
34413
34707
|
else {
|
|
34414
34708
|
log(
|
|
34415
|
-
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${
|
|
34709
|
+
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${path71.relative(process.cwd(), result3.record)} by ${args.reviewer.trim()}` : ` approved ${path71.relative(process.cwd(), result3.output)} by ${args.reviewer.trim()}`
|
|
34416
34710
|
);
|
|
34417
34711
|
}
|
|
34418
34712
|
return;
|
|
@@ -34421,7 +34715,7 @@ async function runRefine(args) {
|
|
|
34421
34715
|
if (args.json) {
|
|
34422
34716
|
log(JSON.stringify(result2, null, 2));
|
|
34423
34717
|
} else {
|
|
34424
|
-
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${
|
|
34718
|
+
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${path71.relative(process.cwd(), result2.output || result2.record)}`);
|
|
34425
34719
|
for (const reason of result2.reasons) log(` ${reason}`);
|
|
34426
34720
|
}
|
|
34427
34721
|
if (!result2.safe) process.exitCode = 1;
|
|
@@ -34467,7 +34761,7 @@ async function runRefine(args) {
|
|
|
34467
34761
|
log(` ${item.state.padEnd(16)} ${item.key} ${item.reason}`);
|
|
34468
34762
|
if (item.state === "needs-approval") {
|
|
34469
34763
|
log(
|
|
34470
|
-
` pixelkiln refine approve --from ${
|
|
34764
|
+
` pixelkiln refine approve --from ${path71.relative(process.cwd(), item.record)} --reviewer "Your Name"`
|
|
34471
34765
|
);
|
|
34472
34766
|
}
|
|
34473
34767
|
}
|
|
@@ -34480,7 +34774,7 @@ async function runRefine(args) {
|
|
|
34480
34774
|
}
|
|
34481
34775
|
|
|
34482
34776
|
// src/cli/commands/anchors.ts
|
|
34483
|
-
import
|
|
34777
|
+
import path72 from "path";
|
|
34484
34778
|
async function runAnchors(args) {
|
|
34485
34779
|
const target = args.target;
|
|
34486
34780
|
const { specs, lock } = await openProject2(args);
|
|
@@ -34501,7 +34795,7 @@ async function runAnchors(args) {
|
|
|
34501
34795
|
dryRun: args.dryRun,
|
|
34502
34796
|
onProgress: log
|
|
34503
34797
|
});
|
|
34504
|
-
const file =
|
|
34798
|
+
const file = path72.relative(spec.root, result.file) || result.file;
|
|
34505
34799
|
if (args.dryRun) {
|
|
34506
34800
|
log(` ${result.estimated} frame${result.estimated === 1 ? "" : "s"} to estimate (about ${cost(result.estimated)}), ${result.current} already current`);
|
|
34507
34801
|
} else if (result.estimated) {
|
|
@@ -34513,12 +34807,12 @@ async function runAnchors(args) {
|
|
|
34513
34807
|
}
|
|
34514
34808
|
|
|
34515
34809
|
// src/cli/commands/redraw.ts
|
|
34516
|
-
import
|
|
34810
|
+
import path74 from "path";
|
|
34517
34811
|
|
|
34518
34812
|
// src/pipeline/redraw.ts
|
|
34519
|
-
import { existsSync as
|
|
34520
|
-
import { mkdir as
|
|
34521
|
-
import
|
|
34813
|
+
import { existsSync as existsSync56 } from "fs";
|
|
34814
|
+
import { mkdir as mkdir26, readFile as readFile50, rename as rename15, writeFile as writeFile31 } from "fs/promises";
|
|
34815
|
+
import path73 from "path";
|
|
34522
34816
|
function redrawRoles(spec, lock) {
|
|
34523
34817
|
return (lock.entries[lockKey(spec.styleId, spec.assetId)]?.outputs ?? []).map((output) => output.role ?? "");
|
|
34524
34818
|
}
|
|
@@ -34560,7 +34854,7 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
34560
34854
|
const still = source.spec.character?.kind !== "animation";
|
|
34561
34855
|
for (const [index, output] of sourceEntry.outputs.entries()) {
|
|
34562
34856
|
if (!still && !owners.includes(source.assetId)) continue;
|
|
34563
|
-
const png = await
|
|
34857
|
+
const png = await readFile50(currentEntryOutputPath(sourceEntry, source.spec, index));
|
|
34564
34858
|
if (still) stills.push(png);
|
|
34565
34859
|
if (!owners.includes(source.assetId)) continue;
|
|
34566
34860
|
const role = output.role ?? String(index).padStart(2, "0");
|
|
@@ -34594,23 +34888,23 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
34594
34888
|
continue;
|
|
34595
34889
|
}
|
|
34596
34890
|
const file = at2 >= 0 ? currentEntryOutputPath(entry, spec, at2) : null;
|
|
34597
|
-
if (!file || !
|
|
34891
|
+
if (!file || !existsSync56(file)) {
|
|
34598
34892
|
layers.push(null);
|
|
34599
34893
|
continue;
|
|
34600
34894
|
}
|
|
34601
34895
|
const pair = offset?.per && offset.per[source.assetId] || offset;
|
|
34602
|
-
const png = await
|
|
34896
|
+
const png = await readFile50(file);
|
|
34603
34897
|
layers.push(pair ? shiftPixels(png, -pair.x, -pair.y).png : png);
|
|
34604
34898
|
}
|
|
34605
34899
|
const prepared = redrawSheet(built, layers, redraw);
|
|
34606
34900
|
const size = decodePng(prepared.keyed);
|
|
34607
34901
|
const cost = proTierCost(size.width, size.height);
|
|
34608
|
-
const workDir =
|
|
34902
|
+
const workDir = path73.join(layerWorkDir(spec), "redraw");
|
|
34609
34903
|
const result = { roles, guides, sheet: { width: size.width, height: size.height }, cost, billed: null, written: [], workDir };
|
|
34610
34904
|
if (opts.dryRun) return result;
|
|
34611
|
-
await
|
|
34612
|
-
await
|
|
34613
|
-
await
|
|
34905
|
+
await mkdir26(workDir, { recursive: true });
|
|
34906
|
+
await writeFile31(path73.join(workDir, "keyed.png"), prepared.keyed);
|
|
34907
|
+
await writeFile31(path73.join(workDir, "mask.png"), prepared.mask);
|
|
34614
34908
|
const count = roles.length;
|
|
34615
34909
|
const description = `${spec.prompt}. Every figure but ${count === 1 ? "one" : count} already wears it. Dress the unfinished figure${count === 1 ? "" : "s"} in exactly the same thing, the same colours and details, seen from the side ${count === 1 ? "that figure faces" : "each of those figures faces"}.`;
|
|
34616
34910
|
const jobId = await painter.paintSheet({ description, keyed: prepared.keyed, mask: prepared.mask, seed: opts.seed ?? spec.seed });
|
|
@@ -34628,13 +34922,13 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
34628
34922
|
if (Date.now() > deadline) throw new Error(`${label}: redraw job ${jobId} did not finish in time; nothing was changed`);
|
|
34629
34923
|
await new Promise((resolve) => setTimeout(resolve, opts.pollMs ?? 3e3));
|
|
34630
34924
|
}
|
|
34631
|
-
await
|
|
34925
|
+
await writeFile31(path73.join(workDir, "result.png"), painted);
|
|
34632
34926
|
const returned = decodePng(painted);
|
|
34633
34927
|
if (returned.width !== size.width || returned.height !== size.height) {
|
|
34634
34928
|
throw new Error(`${label}: redraw job ${jobId} returned a ${returned.width}x${returned.height} image for a ${size.width}x${size.height} sheet`);
|
|
34635
34929
|
}
|
|
34636
34930
|
const cut = cutLayerFrames(painted, { keyed: prepared.keyed, mask: prepared.mask, frames: built.frames }, { key: layer.key, region: layer.region });
|
|
34637
|
-
const cacheDir =
|
|
34931
|
+
const cacheDir = path73.resolve(opts.cacheDir ?? path73.join(path73.dirname(opts.lockPath), ".pixelkiln", "cache"));
|
|
34638
34932
|
const outputs = [...entry.outputs];
|
|
34639
34933
|
const renames = [];
|
|
34640
34934
|
for (const [index, at2] of targets) {
|
|
@@ -34643,12 +34937,12 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
34643
34937
|
const empty = !decodePng(raw).pixels.some((value, i) => i % 4 === 3 && value > 0);
|
|
34644
34938
|
if (empty) throw new Error(`${label}: the redraw of ${role} came back with nothing drawn; nothing was changed. Run it again, or with another --seed`);
|
|
34645
34939
|
const target = currentEntryOutputPath(entry, spec, at2);
|
|
34646
|
-
if (
|
|
34940
|
+
if (existsSync56(target)) await cacheMedia(cacheDir, await readFile50(target), MediaType.PNG);
|
|
34647
34941
|
await cacheMedia(cacheDir, raw, MediaType.PNG);
|
|
34648
34942
|
const processed = applyPostprocess(raw, MediaType.PNG, entry.postprocess, [], role);
|
|
34649
34943
|
await cacheMedia(cacheDir, processed.bytes, MediaType.PNG);
|
|
34650
34944
|
const tmp = `${target}.pixelkiln.tmp`;
|
|
34651
|
-
await
|
|
34945
|
+
await writeFile31(tmp, processed.bytes);
|
|
34652
34946
|
renames.push([tmp, target]);
|
|
34653
34947
|
const { raw: _raw, ...kept } = outputs[at2];
|
|
34654
34948
|
outputs[at2] = { ...kept, sha256: sha256(processed.bytes), ...processed.changed ? { raw: sha256(raw) } : {} };
|
|
@@ -34660,7 +34954,7 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
34660
34954
|
});
|
|
34661
34955
|
await saveLock(opts.lockPath, lock);
|
|
34662
34956
|
for (const [tmp, target] of renames) {
|
|
34663
|
-
await
|
|
34957
|
+
await rename15(tmp, target);
|
|
34664
34958
|
result.written.push(target);
|
|
34665
34959
|
}
|
|
34666
34960
|
return result;
|
|
@@ -34692,7 +34986,7 @@ async function runRedraw(args) {
|
|
|
34692
34986
|
const painter = args.dryRun ? { paintSheet: never, paintedSheet: never } : new PixelLabProvider(clientFromEnv());
|
|
34693
34987
|
const result = await redrawLayerFrames(spec, project2.lock, painter, {
|
|
34694
34988
|
frames: args.redrawFrames,
|
|
34695
|
-
lockPath:
|
|
34989
|
+
lockPath: path74.resolve(args.lock),
|
|
34696
34990
|
seed: args.seed,
|
|
34697
34991
|
dryRun: args.dryRun,
|
|
34698
34992
|
onProgress: log
|
|
@@ -34703,16 +34997,16 @@ async function runRedraw(args) {
|
|
|
34703
34997
|
log(` would redraw ${frames} (${result.roles.join(", ")}) beside ${result.guides} dressed, on a ${sheet} sheet: about ${result.cost} generations`);
|
|
34704
34998
|
return;
|
|
34705
34999
|
}
|
|
34706
|
-
for (const file of result.written) log(` wrote ${
|
|
35000
|
+
for (const file of result.written) log(` wrote ${path74.relative(process.cwd(), file)}`);
|
|
34707
35001
|
const billed = result.billed ? `${result.billed.amount} ${result.billed.unit} billed` : `about ${result.cost} generations`;
|
|
34708
|
-
log(` redrew ${frames} of ${target} (${billed}); the sheet and result are in ${
|
|
35002
|
+
log(` redrew ${frames} of ${target} (${billed}); the sheet and result are in ${path74.relative(process.cwd(), result.workDir)}`);
|
|
34709
35003
|
log(` look at ${result.written.length === 1 ? "it" : "them"}, then run pixelkiln gen to rebuild anything made from this layer`);
|
|
34710
35004
|
}
|
|
34711
35005
|
|
|
34712
35006
|
// src/cli/commands/skeleton.ts
|
|
34713
|
-
import
|
|
34714
|
-
import { existsSync as
|
|
34715
|
-
import { readFile as
|
|
35007
|
+
import path75 from "path";
|
|
35008
|
+
import { existsSync as existsSync57 } from "fs";
|
|
35009
|
+
import { readFile as readFile51, writeFile as writeFile32 } from "fs/promises";
|
|
34716
35010
|
|
|
34717
35011
|
// src/skeleton-preview.ts
|
|
34718
35012
|
var RIGHT = [255, 140, 40, 255];
|
|
@@ -34833,12 +35127,12 @@ var Canvas = class {
|
|
|
34833
35127
|
async function runEstimateSkeleton(args) {
|
|
34834
35128
|
const image = args.target;
|
|
34835
35129
|
if (!image) throw new UsageError("estimate-skeleton needs an image path: pixelkiln estimate-skeleton <image> [--out keypoints.json]");
|
|
34836
|
-
if (args.out &&
|
|
35130
|
+
if (args.out && existsSync57(path75.resolve(args.out)) && !args.force) {
|
|
34837
35131
|
throw new UsageError(`${args.out} already exists; pass --force to replace it`);
|
|
34838
35132
|
}
|
|
34839
|
-
loadEnvFiles(
|
|
35133
|
+
loadEnvFiles(path75.dirname(path75.resolve(args.manifest)));
|
|
34840
35134
|
loadEnvFiles(process.cwd());
|
|
34841
|
-
const bytes = await
|
|
35135
|
+
const bytes = await readFile51(path75.resolve(image));
|
|
34842
35136
|
const metadata = imageMetadata(bytes);
|
|
34843
35137
|
if (!metadata) throw new UsageError(`${image} is not a readable PNG or JPEG`);
|
|
34844
35138
|
if (args.custom) return estimateCustom(args, image, bytes, metadata);
|
|
@@ -34851,7 +35145,7 @@ async function runEstimateSkeleton(args) {
|
|
|
34851
35145
|
const frames = args.frames ?? DEFAULT_SCAFFOLD_FRAMES;
|
|
34852
35146
|
const json = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames), null, 2);
|
|
34853
35147
|
if (args.out) {
|
|
34854
|
-
await
|
|
35148
|
+
await writeFile32(path75.resolve(args.out), json + "\n");
|
|
34855
35149
|
log(` wrote ${args.out}: the estimated pose and ${frames} frames to edit`);
|
|
34856
35150
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
34857
35151
|
} else {
|
|
@@ -34886,7 +35180,7 @@ async function estimateCustom(args, image, bytes, metadata) {
|
|
|
34886
35180
|
const json = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames, { rig: res.rig, kind: res.kind }), null, 2);
|
|
34887
35181
|
const extra = res.rig.filter((joint) => !joint.estimate).map((joint) => joint.name);
|
|
34888
35182
|
if (args.out) {
|
|
34889
|
-
await
|
|
35183
|
+
await writeFile32(path75.resolve(args.out), json + "\n");
|
|
34890
35184
|
log(` wrote ${args.out}: a ${res.kind ?? "custom"} rig of ${res.rig.length} joints and ${frames} frames to edit`);
|
|
34891
35185
|
if (extra.length) log(` joints beyond the 18: ${extra.slice(0, 12).join(", ")}${extra.length > 12 ? ", \u2026" : ""}`);
|
|
34892
35186
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
@@ -34900,8 +35194,8 @@ async function runSkeletonPreview(args) {
|
|
|
34900
35194
|
let sourceFile;
|
|
34901
35195
|
let label;
|
|
34902
35196
|
if (target.endsWith(".json")) {
|
|
34903
|
-
keypointsFile =
|
|
34904
|
-
sourceFile = args.from ?
|
|
35197
|
+
keypointsFile = path75.resolve(target);
|
|
35198
|
+
sourceFile = args.from ? path75.resolve(args.from) : void 0;
|
|
34905
35199
|
label = target;
|
|
34906
35200
|
} else {
|
|
34907
35201
|
const loaded = await loadManifest(args.manifest);
|
|
@@ -34913,31 +35207,31 @@ async function runSkeletonPreview(args) {
|
|
|
34913
35207
|
);
|
|
34914
35208
|
}
|
|
34915
35209
|
keypointsFile = spec.revision.keypointsFile;
|
|
34916
|
-
sourceFile = args.from ?
|
|
35210
|
+
sourceFile = args.from ? path75.resolve(args.from) : spec.revision.sourceFile;
|
|
34917
35211
|
label = `${spec.styleId}/${spec.assetId}`;
|
|
34918
35212
|
}
|
|
34919
|
-
if (!
|
|
35213
|
+
if (!existsSync57(keypointsFile)) throw new UsageError(`Keypoints file does not exist yet: ${keypointsFile}`);
|
|
34920
35214
|
let json;
|
|
34921
35215
|
try {
|
|
34922
|
-
json = JSON.parse(await
|
|
35216
|
+
json = JSON.parse(await readFile51(keypointsFile, "utf8"));
|
|
34923
35217
|
} catch (error) {
|
|
34924
35218
|
throw new UsageError(`${keypointsFile} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
34925
35219
|
}
|
|
34926
35220
|
const set = parseSkeletonSet(json, keypointsFile);
|
|
34927
35221
|
let source;
|
|
34928
35222
|
if (sourceFile) {
|
|
34929
|
-
if (!
|
|
35223
|
+
if (!existsSync57(sourceFile)) {
|
|
34930
35224
|
log(` source image does not exist yet, drawing on a plain ground: ${sourceFile}`);
|
|
34931
35225
|
} else {
|
|
34932
|
-
const bytes = await
|
|
35226
|
+
const bytes = await readFile51(sourceFile);
|
|
34933
35227
|
if (imageMetadata(bytes)?.format !== "png") throw new UsageError(`${sourceFile} must be a PNG to preview over`);
|
|
34934
35228
|
source = decodePng(bytes);
|
|
34935
35229
|
}
|
|
34936
35230
|
}
|
|
34937
|
-
const out =
|
|
34938
|
-
await
|
|
35231
|
+
const out = path75.resolve(args.out ?? keypointsFile.replace(/\.json$/, "") + ".preview.png");
|
|
35232
|
+
await writeFile32(out, renderSkeletonSheet(set, { source }));
|
|
34939
35233
|
log(` ${label}: ${set.frames.length} frames after the starting pose`);
|
|
34940
|
-
const shown2 =
|
|
35234
|
+
const shown2 = path75.relative(process.cwd(), out);
|
|
34941
35235
|
log(` wrote ${shown2.startsWith("..") ? out : shown2}`);
|
|
34942
35236
|
}
|
|
34943
35237
|
|
|
@@ -34983,15 +35277,15 @@ async function runTools(args) {
|
|
|
34983
35277
|
}
|
|
34984
35278
|
|
|
34985
35279
|
// src/cli/commands/workspace.ts
|
|
34986
|
-
import
|
|
34987
|
-
import { existsSync as
|
|
35280
|
+
import path76 from "path";
|
|
35281
|
+
import { existsSync as existsSync58 } from "fs";
|
|
34988
35282
|
async function runWorkspace(args) {
|
|
34989
|
-
const workspacePath =
|
|
34990
|
-
const dir =
|
|
35283
|
+
const workspacePath = path76.resolve(args.workspace ?? "pixelkiln.workspace.json");
|
|
35284
|
+
const dir = path76.dirname(workspacePath);
|
|
34991
35285
|
if (args.subcommand === "add") {
|
|
34992
|
-
const manifestPath =
|
|
35286
|
+
const manifestPath = path76.resolve(args.target);
|
|
34993
35287
|
const loadedTarget = await loadManifest(manifestPath);
|
|
34994
|
-
const lockPath = args.explicitLock ?
|
|
35288
|
+
const lockPath = args.explicitLock ? path76.resolve(args.explicitLock) : path76.join(path76.dirname(manifestPath), "pixelkiln.lock.json");
|
|
34995
35289
|
const ws = await loadWorkspace(workspacePath);
|
|
34996
35290
|
const id = args.name ?? loadedTarget.manifest.name;
|
|
34997
35291
|
if (ws.projects.some((p) => p.id === id)) {
|
|
@@ -35011,10 +35305,10 @@ async function runWorkspace(args) {
|
|
|
35011
35305
|
...args.account ? { account: args.account } : {}
|
|
35012
35306
|
};
|
|
35013
35307
|
await saveWorkspace(workspacePath, { version: 1, projects: [...ws.projects, project2] });
|
|
35014
|
-
log(` registered "${id}" in ${
|
|
35308
|
+
log(` registered "${id}" in ${path76.relative(process.cwd(), workspacePath)}`);
|
|
35015
35309
|
log(` manifest: ${project2.manifest}`);
|
|
35016
35310
|
log(` lock: ${project2.lock}`);
|
|
35017
|
-
if (!
|
|
35311
|
+
if (!existsSync58(lockPath)) {
|
|
35018
35312
|
log(
|
|
35019
35313
|
` warning: no lockfile there yet; this project contributes no claims until one is generated`
|
|
35020
35314
|
);
|
|
@@ -35023,7 +35317,7 @@ async function runWorkspace(args) {
|
|
|
35023
35317
|
}
|
|
35024
35318
|
if (args.subcommand === "remove") {
|
|
35025
35319
|
const ws = await loadWorkspace(workspacePath);
|
|
35026
|
-
const resolvedTarget =
|
|
35320
|
+
const resolvedTarget = path76.resolve(args.target);
|
|
35027
35321
|
const match = ws.projects.find(
|
|
35028
35322
|
(p) => p.id === args.target || resolveProject(dir, p).manifestPath === resolvedTarget
|
|
35029
35323
|
);
|
|
@@ -35034,11 +35328,11 @@ async function runWorkspace(args) {
|
|
|
35034
35328
|
version: 1,
|
|
35035
35329
|
projects: ws.projects.filter((p) => p !== match)
|
|
35036
35330
|
});
|
|
35037
|
-
log(` removed "${match.id}" from ${
|
|
35331
|
+
log(` removed "${match.id}" from ${path76.relative(process.cwd(), workspacePath)}`);
|
|
35038
35332
|
return;
|
|
35039
35333
|
}
|
|
35040
35334
|
if (args.subcommand === "list") {
|
|
35041
|
-
if (!
|
|
35335
|
+
if (!existsSync58(workspacePath)) {
|
|
35042
35336
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
35043
35337
|
}
|
|
35044
35338
|
const ws = await loadWorkspace(workspacePath);
|
|
@@ -35046,9 +35340,9 @@ async function runWorkspace(args) {
|
|
|
35046
35340
|
if (args.json) {
|
|
35047
35341
|
log(JSON.stringify({ version: 1, workspace: workspacePath, projects: ws.projects, diagnostics }, null, 2));
|
|
35048
35342
|
} else if (!ws.projects.length) {
|
|
35049
|
-
log(` no projects registered in ${
|
|
35343
|
+
log(` no projects registered in ${path76.relative(process.cwd(), workspacePath)}`);
|
|
35050
35344
|
} else {
|
|
35051
|
-
log(` ${ws.projects.length} project(s) in ${
|
|
35345
|
+
log(` ${ws.projects.length} project(s) in ${path76.relative(process.cwd(), workspacePath)}:`);
|
|
35052
35346
|
for (const p of ws.projects) {
|
|
35053
35347
|
log(` ${p.id.padEnd(24)} ${p.manifest.padEnd(40)} (${p.provider}${p.account ? `, ${p.account}` : ""})`);
|
|
35054
35348
|
}
|
|
@@ -35058,7 +35352,7 @@ async function runWorkspace(args) {
|
|
|
35058
35352
|
return;
|
|
35059
35353
|
}
|
|
35060
35354
|
if (args.subcommand === "status") {
|
|
35061
|
-
if (!
|
|
35355
|
+
if (!existsSync58(workspacePath)) {
|
|
35062
35356
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
35063
35357
|
}
|
|
35064
35358
|
const ws = await loadWorkspace(workspacePath);
|
|
@@ -35066,7 +35360,7 @@ async function runWorkspace(args) {
|
|
|
35066
35360
|
if (args.json) {
|
|
35067
35361
|
log(JSON.stringify({ ...report, workspace: workspacePath }, null, 2));
|
|
35068
35362
|
} else {
|
|
35069
|
-
log(` workspace: ${
|
|
35363
|
+
log(` workspace: ${path76.relative(process.cwd(), workspacePath)}`);
|
|
35070
35364
|
for (const p of report.projects) {
|
|
35071
35365
|
if (p.error) {
|
|
35072
35366
|
log(`
|
|
@@ -35120,8 +35414,8 @@ async function runHelp() {
|
|
|
35120
35414
|
async function runVersion() {
|
|
35121
35415
|
for (const up of ["../package.json", "../../package.json"]) {
|
|
35122
35416
|
const url = new URL(up, import.meta.url);
|
|
35123
|
-
if (!
|
|
35124
|
-
const pkg = JSON.parse(await
|
|
35417
|
+
if (!existsSync59(url)) continue;
|
|
35418
|
+
const pkg = JSON.parse(await readFile52(url, "utf8"));
|
|
35125
35419
|
if (pkg.name === "pixelkiln") {
|
|
35126
35420
|
log(`${pkg.name} ${pkg.version}`);
|
|
35127
35421
|
return;
|