pixelkiln 0.106.0 → 0.107.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/README.md +1 -1
- package/dist/cli.js +671 -256
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +690 -347
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +205 -1
- package/dist/index.d.ts +205 -1
- package/dist/index.js +655 -323
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +106 -4
- package/docs/ENDPOINTS.md +11 -1
- package/docs/LIBRARY.md +46 -0
- package/docs/README.md +1 -0
- package/docs/THIRD_PARTY.md +48 -0
- package/package.json +2 -1
- package/skills/pixelkiln/SKILL.md +11 -4
- package/skills/pixelkiln/references/pixellab.md +8 -1
- package/skills/pixelkiln/references/vfx.md +223 -0
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 existsSync52 } from "fs";
|
|
71
|
+
import { readFile as readFile46 } from "fs/promises";
|
|
72
72
|
|
|
73
73
|
// src/cli/args.ts
|
|
74
74
|
import path from "path";
|
|
@@ -124,6 +124,8 @@ var VALUE_FLAGS = [
|
|
|
124
124
|
"--part",
|
|
125
125
|
"--sprite",
|
|
126
126
|
"--fps",
|
|
127
|
+
"--lib",
|
|
128
|
+
"--margin",
|
|
127
129
|
"--sprite-frames",
|
|
128
130
|
"--sprite-fps",
|
|
129
131
|
"--artist",
|
|
@@ -250,7 +252,7 @@ var QUALITY_SUBCOMMANDS = ["snapshot", "check"];
|
|
|
250
252
|
var EDIT_SUBCOMMANDS = ["start", "detach"];
|
|
251
253
|
var TOOLS_SUBCOMMANDS = ["status", "install"];
|
|
252
254
|
var TOOLS = ["editor"];
|
|
253
|
-
var VFX_SUBCOMMANDS = ["make", "presets", "parts"];
|
|
255
|
+
var VFX_SUBCOMMANDS = ["make", "presets", "parts", "effects"];
|
|
254
256
|
var MUSIC_SUBCOMMANDS = ["make", "style", "lyrics"];
|
|
255
257
|
var TALK_SUBCOMMANDS = ["visemes", "gif", "plan"];
|
|
256
258
|
var ASSET_SUBCOMMANDS = ["canvas", "mirror", "import", "save", "expand", "review", "export"];
|
|
@@ -579,6 +581,8 @@ function parseArgs(argv) {
|
|
|
579
581
|
parts: list("--part"),
|
|
580
582
|
sprite: get("--sprite"),
|
|
581
583
|
fps: numberOption("--fps", { min: 1, max: 60, integer: true }),
|
|
584
|
+
lib: get("--lib"),
|
|
585
|
+
margin: numberOption("--margin", { min: 0, max: 256, integer: true }),
|
|
582
586
|
spriteFrames: numberOption("--sprite-frames", { min: 1, max: 32, integer: true }),
|
|
583
587
|
spriteFps: numberOption("--sprite-fps", { min: 1, max: 60, integer: true }),
|
|
584
588
|
gamePack: rest.includes("--game-pack"),
|
|
@@ -721,6 +725,10 @@ Commands
|
|
|
721
725
|
.vfx.json recipe record. vfx presets / vfx parts list options.
|
|
722
726
|
With --description, PixelLab's paid VFX artist builds it from
|
|
723
727
|
words instead (lite 1-5, pro 6-28 generations); asks first.
|
|
728
|
+
With --lib pixelfx, renders an --effect <category>/<name> from
|
|
729
|
+
the pixelfx library on this machine instead (free, nothing
|
|
730
|
+
sent; install it with: npm i github:patch-gg/pixelfx); vfx
|
|
731
|
+
effects lists them.
|
|
724
732
|
font PixelLab: generate a pixel font (--description, --out); writes a
|
|
725
733
|
.ttf and a glyph atlas PNG. 15 generations; asks first.
|
|
726
734
|
music PixelLab: a song from a style (--description, --out); writes two
|
|
@@ -827,10 +835,13 @@ Options
|
|
|
827
835
|
--convention <c> normal-map: opengl (green up, default) or directx (green down)
|
|
828
836
|
--preset <name> vfx: start from a whole-effect preset (vfx presets lists them)
|
|
829
837
|
--recipe <file> vfx: render a recipe or an earlier run's .vfx.json record
|
|
830
|
-
--effect <id> vfx: start from a saved My effects id and export over it
|
|
838
|
+
--effect <id> vfx: start from a saved My effects id and export over it;
|
|
839
|
+
with --lib pixelfx, the effect to render (fire/torch)
|
|
831
840
|
--part <name> vfx: add a part (repeatable; vfx parts lists them)
|
|
832
841
|
--sprite <ref> vfx: build around a sprite: a file, a URL, or character:<id>:<dir>
|
|
833
842
|
--fps <n> vfx: frames per second, 1-60
|
|
843
|
+
--lib <name> vfx: pixellab (default) or pixelfx, the local effects library
|
|
844
|
+
--margin <px> vfx --lib pixelfx: transparent pixels around the effect's canvas
|
|
834
845
|
--sprite-frames <n> vfx --description: --sprite is a strip of n equal frames (2-32)
|
|
835
846
|
--sprite-fps <n> vfx --description: how fast the sprite animation plays (default 12)
|
|
836
847
|
--game-pack vfx: also download the game-pack ZIP
|
|
@@ -1382,10 +1393,10 @@ function normalizeHex(value) {
|
|
|
1382
1393
|
function sha256(data) {
|
|
1383
1394
|
return createHash("sha256").update(data).digest("hex");
|
|
1384
1395
|
}
|
|
1385
|
-
async function sha256File(
|
|
1396
|
+
async function sha256File(path70) {
|
|
1386
1397
|
return new Promise((resolve, reject) => {
|
|
1387
1398
|
const hash = createHash("sha256");
|
|
1388
|
-
const stream = createReadStream(
|
|
1399
|
+
const stream = createReadStream(path70);
|
|
1389
1400
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
1390
1401
|
stream.on("error", reject);
|
|
1391
1402
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -3098,7 +3109,7 @@ var AssetDeriveSchema = z.object({
|
|
|
3098
3109
|
/** 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. */
|
|
3099
3110
|
tolerance: z.number().min(0).max(442).optional()
|
|
3100
3111
|
}).strict().superRefine((derive, context) => {
|
|
3101
|
-
const issue = (message6,
|
|
3112
|
+
const issue = (message6, path70) => context.addIssue({ code: z.ZodIssueCode.custom, message: message6, path: [path70] });
|
|
3102
3113
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
3103
3114
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
3104
3115
|
}
|
|
@@ -9011,9 +9022,9 @@ var PixelLabClient = class {
|
|
|
9011
9022
|
apiKey;
|
|
9012
9023
|
http;
|
|
9013
9024
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
9014
|
-
async request(
|
|
9025
|
+
async request(path70, init) {
|
|
9015
9026
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
9016
|
-
const res = await this.http(`${BASE}${
|
|
9027
|
+
const res = await this.http(`${BASE}${path70}`, {
|
|
9017
9028
|
...init,
|
|
9018
9029
|
headers: {
|
|
9019
9030
|
Authorization: auth,
|
|
@@ -9024,13 +9035,13 @@ var PixelLabClient = class {
|
|
|
9024
9035
|
const text = await res.text();
|
|
9025
9036
|
if (!res.ok) {
|
|
9026
9037
|
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' : "";
|
|
9027
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
9038
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path70} \u2192 ${res.status}${hint}${refusalReason(res.status, text)}`, res.status, text);
|
|
9028
9039
|
}
|
|
9029
9040
|
if (!text) return {};
|
|
9030
9041
|
try {
|
|
9031
9042
|
return JSON.parse(text);
|
|
9032
9043
|
} catch {
|
|
9033
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
9044
|
+
throw new Error(`${init?.method ?? "GET"} ${path70} returned invalid JSON`);
|
|
9034
9045
|
}
|
|
9035
9046
|
}
|
|
9036
9047
|
async balance() {
|
|
@@ -9577,10 +9588,10 @@ var PixelLabClient = class {
|
|
|
9577
9588
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
9578
9589
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
9579
9590
|
const south = args.reference?.south;
|
|
9580
|
-
let
|
|
9591
|
+
let path70;
|
|
9581
9592
|
let body;
|
|
9582
9593
|
if (args.mode === "v3") {
|
|
9583
|
-
|
|
9594
|
+
path70 = "/create-character-v3";
|
|
9584
9595
|
body = {
|
|
9585
9596
|
description: args.description,
|
|
9586
9597
|
image_size: imageSize,
|
|
@@ -9594,7 +9605,7 @@ var PixelLabClient = class {
|
|
|
9594
9605
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
9595
9606
|
};
|
|
9596
9607
|
} else if (args.mode === "pro-flash") {
|
|
9597
|
-
|
|
9608
|
+
path70 = "/create-character-pro-flash";
|
|
9598
9609
|
const traits = args.styleTraits;
|
|
9599
9610
|
body = {
|
|
9600
9611
|
description: args.description,
|
|
@@ -9618,7 +9629,7 @@ var PixelLabClient = class {
|
|
|
9618
9629
|
} : {}
|
|
9619
9630
|
};
|
|
9620
9631
|
} else if (args.mode === "pro") {
|
|
9621
|
-
|
|
9632
|
+
path70 = "/create-character-pro";
|
|
9622
9633
|
body = {
|
|
9623
9634
|
description: args.description,
|
|
9624
9635
|
image_size: imageSize,
|
|
@@ -9632,7 +9643,7 @@ var PixelLabClient = class {
|
|
|
9632
9643
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
9633
9644
|
};
|
|
9634
9645
|
} else {
|
|
9635
|
-
|
|
9646
|
+
path70 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
9636
9647
|
body = {
|
|
9637
9648
|
description: args.description,
|
|
9638
9649
|
image_size: imageSize,
|
|
@@ -9650,8 +9661,8 @@ var PixelLabClient = class {
|
|
|
9650
9661
|
};
|
|
9651
9662
|
}
|
|
9652
9663
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
9653
|
-
const raw = await this.request(
|
|
9654
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
9664
|
+
const raw = await this.request(path70, { method: "POST", body: JSON.stringify(body) });
|
|
9665
|
+
return validateResponse(CharacterSubmitSchema, raw, path70.slice(1));
|
|
9655
9666
|
}
|
|
9656
9667
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
9657
9668
|
async createCharacterState(args) {
|
|
@@ -14973,9 +14984,9 @@ var RetroDiffusionClient = class {
|
|
|
14973
14984
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
14974
14985
|
return Buffer.from(await response.arrayBuffer());
|
|
14975
14986
|
}
|
|
14976
|
-
async call(
|
|
14987
|
+
async call(path70, init = {}) {
|
|
14977
14988
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
14978
|
-
const response = await this.request(`${this.baseUrl}${
|
|
14989
|
+
const response = await this.request(`${this.baseUrl}${path70}`, {
|
|
14979
14990
|
...init,
|
|
14980
14991
|
headers: {
|
|
14981
14992
|
"Content-Type": "application/json",
|
|
@@ -18271,10 +18282,10 @@ function isSha256Hash(value) {
|
|
|
18271
18282
|
function parseCache(value) {
|
|
18272
18283
|
return HashCacheSchema.parse(value);
|
|
18273
18284
|
}
|
|
18274
|
-
async function loadCache(
|
|
18275
|
-
if (!existsSync18(
|
|
18285
|
+
async function loadCache(path70) {
|
|
18286
|
+
if (!existsSync18(path70)) return { version: 1, hashes: {} };
|
|
18276
18287
|
try {
|
|
18277
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(
|
|
18288
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(path70, "utf8")));
|
|
18278
18289
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
18279
18290
|
return {
|
|
18280
18291
|
version: 1,
|
|
@@ -18286,18 +18297,18 @@ async function loadCache(path69) {
|
|
|
18286
18297
|
return { version: 1, hashes: {} };
|
|
18287
18298
|
}
|
|
18288
18299
|
}
|
|
18289
|
-
async function saveCache(
|
|
18300
|
+
async function saveCache(path70, cache) {
|
|
18290
18301
|
const sorted = {};
|
|
18291
18302
|
for (const key2 of Object.keys(cache.hashes).sort()) {
|
|
18292
18303
|
const hash = cache.hashes[key2];
|
|
18293
18304
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key2}`);
|
|
18294
18305
|
sorted[key2] = hash;
|
|
18295
18306
|
}
|
|
18296
|
-
await mkdir9(pathModule.dirname(pathModule.resolve(
|
|
18297
|
-
const tmp = `${
|
|
18307
|
+
await mkdir9(pathModule.dirname(pathModule.resolve(path70)), { recursive: true });
|
|
18308
|
+
const tmp = `${path70}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18298
18309
|
try {
|
|
18299
18310
|
await writeFile9(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
18300
|
-
await rename7(tmp,
|
|
18311
|
+
await rename7(tmp, path70);
|
|
18301
18312
|
} finally {
|
|
18302
18313
|
await rm5(tmp, { force: true });
|
|
18303
18314
|
}
|
|
@@ -26839,10 +26850,333 @@ function sheetFormat(args) {
|
|
|
26839
26850
|
}
|
|
26840
26851
|
|
|
26841
26852
|
// src/cli/commands/pixellab-utils.ts
|
|
26842
|
-
import { readFile as
|
|
26853
|
+
import { readFile as readFile35 } from "fs/promises";
|
|
26854
|
+
import path51 from "path";
|
|
26855
|
+
|
|
26856
|
+
// src/pixelfx-vfx.ts
|
|
26857
|
+
import { existsSync as existsSync41, readFileSync as readFileSync9 } from "fs";
|
|
26858
|
+
import { mkdir as mkdir17, readFile as readFile34, writeFile as writeFile22 } from "fs/promises";
|
|
26859
|
+
import { createRequire as createRequire2 } from "module";
|
|
26843
26860
|
import path50 from "path";
|
|
26861
|
+
import { pathToFileURL } from "url";
|
|
26862
|
+
var PIXELFX_TOOL = "pixelfx";
|
|
26863
|
+
var PIXELFX_REPOSITORY = "https://github.com/patch-gg/pixelfx";
|
|
26864
|
+
var PIXELFX_INSTALL = "npm i github:patch-gg/pixelfx";
|
|
26865
|
+
function missingPixelfx(cause) {
|
|
26866
|
+
return new PixelKilnError(
|
|
26867
|
+
"pixelfx is not installed, so there is nothing to render local effects with",
|
|
26868
|
+
"capability",
|
|
26869
|
+
{ hint: `Install it beside your project: ${PIXELFX_INSTALL} (${PIXELFX_REPOSITORY}, MIT; it is not on the npm registry)`, cause }
|
|
26870
|
+
);
|
|
26871
|
+
}
|
|
26872
|
+
function pixelfxVersion(entry) {
|
|
26873
|
+
for (let dir = path50.dirname(entry); dir !== path50.dirname(dir); dir = path50.dirname(dir)) {
|
|
26874
|
+
const file = path50.join(dir, "package.json");
|
|
26875
|
+
if (!existsSync41(file)) continue;
|
|
26876
|
+
const pkg = JSON.parse(readFileSync9(file, "utf8"));
|
|
26877
|
+
if (pkg.name === "pixelfx") return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
26878
|
+
}
|
|
26879
|
+
return "unknown";
|
|
26880
|
+
}
|
|
26881
|
+
async function loadPixelfx(from) {
|
|
26882
|
+
const bases = from?.map((base) => pathToFileURL(path50.resolve(base)).href) ?? [
|
|
26883
|
+
pathToFileURL(path50.join(process.cwd(), "package.json")).href,
|
|
26884
|
+
import.meta.url
|
|
26885
|
+
];
|
|
26886
|
+
let resolved;
|
|
26887
|
+
let failure;
|
|
26888
|
+
for (const base of bases) {
|
|
26889
|
+
try {
|
|
26890
|
+
const require2 = createRequire2(base);
|
|
26891
|
+
resolved = { core: require2.resolve("pixelfx"), index: require2.resolve("pixelfx/fx/index") };
|
|
26892
|
+
break;
|
|
26893
|
+
} catch (error) {
|
|
26894
|
+
failure = error;
|
|
26895
|
+
}
|
|
26896
|
+
}
|
|
26897
|
+
if (!resolved) throw missingPixelfx(failure);
|
|
26898
|
+
const core = await import(pathToFileURL(resolved.core).href);
|
|
26899
|
+
const index = await import(pathToFileURL(resolved.index).href);
|
|
26900
|
+
const version = pixelfxVersion(resolved.core);
|
|
26901
|
+
for (const name of ["createFrame", "clearFrame", "createFx", "composite"]) {
|
|
26902
|
+
if (typeof core[name] !== "function") {
|
|
26903
|
+
throw new PixelKilnError(
|
|
26904
|
+
`The installed pixelfx (${version}) has no ${name}(); PixelKiln was written against pixelfx 0.3`,
|
|
26905
|
+
"capability"
|
|
26906
|
+
);
|
|
26907
|
+
}
|
|
26908
|
+
}
|
|
26909
|
+
if (!index.effects || typeof index.effects !== "object") {
|
|
26910
|
+
throw new PixelKilnError(`The installed pixelfx (${version}) lists no effects in pixelfx/fx/index`, "capability");
|
|
26911
|
+
}
|
|
26912
|
+
return { version, core, effects: index.effects, categories: index.categories ?? [] };
|
|
26913
|
+
}
|
|
26914
|
+
function describeEffect(id, mod) {
|
|
26915
|
+
const meta = mod.meta;
|
|
26916
|
+
if (!meta || !Array.isArray(meta.size) || !Array.isArray(meta.origin)) return null;
|
|
26917
|
+
return {
|
|
26918
|
+
id,
|
|
26919
|
+
category: id.split("/")[0],
|
|
26920
|
+
name: meta.name ?? id,
|
|
26921
|
+
description: meta.desc ?? "",
|
|
26922
|
+
width: meta.size[0],
|
|
26923
|
+
height: meta.size[1],
|
|
26924
|
+
duration: meta.duration ?? 1,
|
|
26925
|
+
loop: meta.loop ?? false,
|
|
26926
|
+
fps: meta.fps ?? 30,
|
|
26927
|
+
needsCharacter: Boolean(meta.actor),
|
|
26928
|
+
options: meta.options ?? {}
|
|
26929
|
+
};
|
|
26930
|
+
}
|
|
26931
|
+
function listPixelfxEffects(lib) {
|
|
26932
|
+
return Object.entries(lib.effects).flatMap(([id, mod]) => describeEffect(id, mod) ?? []);
|
|
26933
|
+
}
|
|
26934
|
+
function formatPixelfxEffects(lib) {
|
|
26935
|
+
const effects = listPixelfxEffects(lib);
|
|
26936
|
+
const known = lib.categories.map((category) => category.id);
|
|
26937
|
+
const ids = [...known, ...new Set(effects.map((effect) => effect.category).filter((id) => !known.includes(id)))];
|
|
26938
|
+
const lines = [`pixelfx ${lib.version}: ${effects.length} effects (${PIXELFX_REPOSITORY}, MIT)`];
|
|
26939
|
+
for (const id of ids) {
|
|
26940
|
+
const inCategory = effects.filter((effect) => effect.category === id);
|
|
26941
|
+
if (!inCategory.length) continue;
|
|
26942
|
+
const category = lib.categories.find((entry) => entry.id === id);
|
|
26943
|
+
lines.push("", `${id}${category?.blurb ? `: ${category.blurb}` : ""}`);
|
|
26944
|
+
for (const effect of inCategory) {
|
|
26945
|
+
const kind = `${effect.loop ? "loop" : "once"} ${Number(effect.duration.toFixed(2))}s`;
|
|
26946
|
+
const note = effect.needsCharacter ? " (needs a character: not supported)" : "";
|
|
26947
|
+
lines.push(` ${effect.id.padEnd(32)} ${`${effect.width}x${effect.height}`.padEnd(8)} ${kind}${note}`);
|
|
26948
|
+
}
|
|
26949
|
+
}
|
|
26950
|
+
const skipped = effects.filter((effect) => effect.needsCharacter).length;
|
|
26951
|
+
if (skipped) lines.push("", `${skipped} effects are drawn around pixelfx's stock character and are not rendered by pixelkiln.`);
|
|
26952
|
+
return lines.join("\n");
|
|
26953
|
+
}
|
|
26954
|
+
var HEX_COLOR = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
26955
|
+
function findEffect(lib, id) {
|
|
26956
|
+
const mod = Object.hasOwn(lib.effects, id) ? lib.effects[id] : void 0;
|
|
26957
|
+
const info = mod ? describeEffect(id, mod) : null;
|
|
26958
|
+
if (!mod || !info) {
|
|
26959
|
+
const all = Object.keys(lib.effects);
|
|
26960
|
+
const category = id.split("/")[0];
|
|
26961
|
+
const near = all.filter((other) => other.startsWith(`${category}/`) || other.endsWith(`/${id.split("/").pop()}`));
|
|
26962
|
+
throw new UsageError(
|
|
26963
|
+
`pixelfx ${lib.version} has no effect "${id}"` + (near.length ? `; close: ${near.slice(0, 12).join(", ")}` : ""),
|
|
26964
|
+
{ hint: "List them with: pixelkiln vfx effects" }
|
|
26965
|
+
);
|
|
26966
|
+
}
|
|
26967
|
+
if (typeof mod.draw !== "function" && typeof mod.create !== "function") {
|
|
26968
|
+
throw new PixelKilnError(`pixelfx effect ${id} exports neither draw nor create`, "capability");
|
|
26969
|
+
}
|
|
26970
|
+
return { mod, info };
|
|
26971
|
+
}
|
|
26972
|
+
function checkPixelfxRecipe(lib, recipe) {
|
|
26973
|
+
const { info } = findEffect(lib, recipe.effect);
|
|
26974
|
+
if (info.needsCharacter) {
|
|
26975
|
+
throw new UsageError(
|
|
26976
|
+
`pixelfx effect ${recipe.effect} is drawn around pixelfx's stock character, which pixelkiln does not render; pick an effect that stands on its own`,
|
|
26977
|
+
{ hint: "pixelkiln vfx effects marks the ones that need a character" }
|
|
26978
|
+
);
|
|
26979
|
+
}
|
|
26980
|
+
const { fps, margin, options = {} } = recipe;
|
|
26981
|
+
if (fps !== void 0 && (!Number.isInteger(fps) || fps < 1 || fps > 60)) {
|
|
26982
|
+
throw new UsageError(`pixelfx fps must be a whole number 1 to 60, got ${fps}`);
|
|
26983
|
+
}
|
|
26984
|
+
if (margin !== void 0 && (!Number.isInteger(margin) || margin < 0 || margin > 256)) {
|
|
26985
|
+
throw new UsageError(`pixelfx margin must be a whole number 0 to 256, got ${margin}`);
|
|
26986
|
+
}
|
|
26987
|
+
if (options.palette !== void 0) {
|
|
26988
|
+
if (!Array.isArray(info.options.palette)) throw new UsageError(`pixelfx effect ${recipe.effect} takes no palette`);
|
|
26989
|
+
const palette = options.palette;
|
|
26990
|
+
if (!Array.isArray(palette) || palette.length < 2 || !palette.every((color) => typeof color === "string" && HEX_COLOR.test(color))) {
|
|
26991
|
+
throw new UsageError("a pixelfx palette is a dark-to-bright ramp of at least two hex colors, e.g. #102,#43a,#8cf,#fff");
|
|
26992
|
+
}
|
|
26993
|
+
}
|
|
26994
|
+
if (options.seed !== void 0 && (typeof options.seed !== "number" || !Number.isFinite(options.seed))) {
|
|
26995
|
+
throw new UsageError(`a pixelfx seed is a number, got ${JSON.stringify(options.seed)}`);
|
|
26996
|
+
}
|
|
26997
|
+
if (options.actor !== void 0) throw new UsageError("pixelkiln does not pass an actor to pixelfx effects");
|
|
26998
|
+
return info;
|
|
26999
|
+
}
|
|
27000
|
+
var isScreen = (width, height) => width >= 320 && Math.abs(width / height - 16 / 9) < 0.05;
|
|
27001
|
+
function fadeLightAtEdges(frame, edge = 8) {
|
|
27002
|
+
const { w, h, light } = frame;
|
|
27003
|
+
for (let y = 0; y < h; y++) {
|
|
27004
|
+
const fromY = Math.min(y, h - 1 - y);
|
|
27005
|
+
for (let x = 0; x < w; x++) {
|
|
27006
|
+
const distance = Math.min(fromY, x, w - 1 - x);
|
|
27007
|
+
if (distance >= edge) continue;
|
|
27008
|
+
const index = y * w + x;
|
|
27009
|
+
const value = light[index];
|
|
27010
|
+
if (!(value & 16777215)) continue;
|
|
27011
|
+
const u = (distance + 0.5) / edge;
|
|
27012
|
+
const k = u * u * (3 - 2 * u);
|
|
27013
|
+
light[index] = (value & 4278190080 | Math.round((value & 255) * k) | Math.round((value >>> 8 & 255) * k) << 8 | Math.round((value >>> 16 & 255) * k) << 16) >>> 0;
|
|
27014
|
+
}
|
|
27015
|
+
}
|
|
27016
|
+
}
|
|
27017
|
+
function renderPixelfx(lib, recipe) {
|
|
27018
|
+
const info = checkPixelfxRecipe(lib, recipe);
|
|
27019
|
+
const mod = lib.effects[recipe.effect];
|
|
27020
|
+
const meta = mod.meta;
|
|
27021
|
+
const margin = recipe.margin ?? 0;
|
|
27022
|
+
const fps = recipe.fps ?? info.fps;
|
|
27023
|
+
const width = info.width + margin * 2;
|
|
27024
|
+
const height = info.height + margin * 2;
|
|
27025
|
+
const count = Math.max(1, Math.round(info.duration * fps) + (info.loop ? 0 : 1));
|
|
27026
|
+
const frame = lib.core.createFrame(width, height, -margin, -margin);
|
|
27027
|
+
const instance = lib.core.createFx(mod, { x: meta.origin[0], y: meta.origin[1], ...recipe.options ?? {} });
|
|
27028
|
+
const fade = margin === 0 && !isScreen(info.width, info.height);
|
|
27029
|
+
const frames = [];
|
|
27030
|
+
for (let i = 0; i < count; i++) {
|
|
27031
|
+
if (i > 0) instance.update(1 / fps);
|
|
27032
|
+
lib.core.clearFrame(frame);
|
|
27033
|
+
instance.draw(frame);
|
|
27034
|
+
if (fade) fadeLightAtEdges(frame);
|
|
27035
|
+
const rgba = new Uint8ClampedArray(width * height * 4);
|
|
27036
|
+
lib.core.composite(frame, rgba, null);
|
|
27037
|
+
frames.push(Buffer.from(rgba.buffer, rgba.byteOffset, rgba.byteLength));
|
|
27038
|
+
}
|
|
27039
|
+
return {
|
|
27040
|
+
effect: info,
|
|
27041
|
+
width,
|
|
27042
|
+
height,
|
|
27043
|
+
fps,
|
|
27044
|
+
loop: info.loop,
|
|
27045
|
+
anchor: { x: meta.origin[0] + margin, y: meta.origin[1] + margin },
|
|
27046
|
+
frames
|
|
27047
|
+
};
|
|
27048
|
+
}
|
|
27049
|
+
function pixelfxSheet(render) {
|
|
27050
|
+
const { width, height, frames } = render;
|
|
27051
|
+
const columns = Math.min(frames.length, Math.max(1, Math.ceil(Math.sqrt(frames.length * height / width))));
|
|
27052
|
+
const rows = Math.ceil(frames.length / columns);
|
|
27053
|
+
const sheet = Buffer.alloc(columns * width * rows * height * 4);
|
|
27054
|
+
const rects = frames.map((rgba, index) => {
|
|
27055
|
+
const x = index % columns * width;
|
|
27056
|
+
const y = Math.floor(index / columns) * height;
|
|
27057
|
+
for (let row = 0; row < height; row++) {
|
|
27058
|
+
rgba.copy(sheet, ((y + row) * columns * width + x) * 4, row * width * 4, (row + 1) * width * 4);
|
|
27059
|
+
}
|
|
27060
|
+
return { x, y, w: width, h: height };
|
|
27061
|
+
});
|
|
27062
|
+
return { png: encodeRgbaPng(columns * width, rows * height, sheet), columns, rows, rects };
|
|
27063
|
+
}
|
|
27064
|
+
async function readPixelfxRecipe(file) {
|
|
27065
|
+
const parsed = JSON.parse(await readFile34(file, "utf8"));
|
|
27066
|
+
const record = parsed.tool === PIXELFX_TOOL;
|
|
27067
|
+
const raw = record ? parsed.recipe : parsed;
|
|
27068
|
+
if (!raw || typeof raw !== "object" || typeof raw.effect !== "string" || Array.isArray(raw.layers)) {
|
|
27069
|
+
if (record) throw new Error(`${file} is a pixelfx record with no recipe naming an effect`);
|
|
27070
|
+
return null;
|
|
27071
|
+
}
|
|
27072
|
+
if (!record && parsed.tool !== void 0) return null;
|
|
27073
|
+
const options = raw.options;
|
|
27074
|
+
if (options !== void 0 && (typeof options !== "object" || options === null || Array.isArray(options))) {
|
|
27075
|
+
throw new Error(`${file}: a pixelfx recipe's options is an object`);
|
|
27076
|
+
}
|
|
27077
|
+
const recipe = {
|
|
27078
|
+
effect: raw.effect,
|
|
27079
|
+
...typeof raw.fps === "number" ? { fps: raw.fps } : {},
|
|
27080
|
+
...typeof raw.margin === "number" ? { margin: raw.margin } : {},
|
|
27081
|
+
...options ? { options } : {}
|
|
27082
|
+
};
|
|
27083
|
+
const version = record ? parsed.library?.version : void 0;
|
|
27084
|
+
return { recipe, ...typeof version === "string" ? { libraryVersion: version } : {} };
|
|
27085
|
+
}
|
|
27086
|
+
async function makePixelfxVfx(lib, opts) {
|
|
27087
|
+
const paths = vfxOutputPaths(opts.out);
|
|
27088
|
+
const recipe = {
|
|
27089
|
+
effect: opts.effect,
|
|
27090
|
+
...opts.fps !== void 0 ? { fps: opts.fps } : {},
|
|
27091
|
+
...opts.margin ? { margin: opts.margin } : {},
|
|
27092
|
+
...opts.options && Object.keys(opts.options).length ? { options: opts.options } : {}
|
|
27093
|
+
};
|
|
27094
|
+
checkPixelfxRecipe(lib, recipe);
|
|
27095
|
+
if (!opts.force) {
|
|
27096
|
+
for (const file of [paths.sheet, paths.atlas, paths.provenance]) {
|
|
27097
|
+
if (existsSync41(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
27098
|
+
}
|
|
27099
|
+
}
|
|
27100
|
+
const render = renderPixelfx(lib, recipe);
|
|
27101
|
+
const sheet = pixelfxSheet(render);
|
|
27102
|
+
const name = opts.name ?? render.effect.name;
|
|
27103
|
+
const clip = path50.basename(paths.sheet, ".png");
|
|
27104
|
+
const anchor = { kind: "origin", ...render.anchor };
|
|
27105
|
+
const size = { w: render.width, h: render.height };
|
|
27106
|
+
const atlas = {
|
|
27107
|
+
frames: sheet.rects.map((frame, index) => ({
|
|
27108
|
+
filename: `${clip} ${index}`,
|
|
27109
|
+
frame,
|
|
27110
|
+
rotated: false,
|
|
27111
|
+
trimmed: false,
|
|
27112
|
+
spriteSourceSize: { x: 0, y: 0, ...size },
|
|
27113
|
+
sourceSize: size,
|
|
27114
|
+
duration: Math.round(1e3 / render.fps)
|
|
27115
|
+
})),
|
|
27116
|
+
meta: {
|
|
27117
|
+
app: "pixelkiln",
|
|
27118
|
+
version: "1",
|
|
27119
|
+
image: path50.basename(paths.sheet),
|
|
27120
|
+
format: "RGBA8888",
|
|
27121
|
+
size: { w: sheet.columns * render.width, h: sheet.rows * render.height },
|
|
27122
|
+
scale: "1",
|
|
27123
|
+
frameTags: [{ name: clip, from: 0, to: render.frames.length - 1, direction: "forward" }],
|
|
27124
|
+
anchor,
|
|
27125
|
+
pixelfx: {
|
|
27126
|
+
id: opts.effect,
|
|
27127
|
+
name,
|
|
27128
|
+
version: lib.version,
|
|
27129
|
+
fps: render.fps,
|
|
27130
|
+
loop: render.loop,
|
|
27131
|
+
frames: render.frames.length,
|
|
27132
|
+
frameSize: [render.width, render.height],
|
|
27133
|
+
pivot: [anchor.x, anchor.y],
|
|
27134
|
+
columns: sheet.columns
|
|
27135
|
+
}
|
|
27136
|
+
}
|
|
27137
|
+
};
|
|
27138
|
+
const sheetSha256 = sha256(sheet.png);
|
|
27139
|
+
const facts = {
|
|
27140
|
+
name,
|
|
27141
|
+
effect: opts.effect,
|
|
27142
|
+
width: render.width,
|
|
27143
|
+
height: render.height,
|
|
27144
|
+
frames: render.frames.length,
|
|
27145
|
+
fps: render.fps,
|
|
27146
|
+
loop: render.loop,
|
|
27147
|
+
anchor
|
|
27148
|
+
};
|
|
27149
|
+
const provenance = {
|
|
27150
|
+
version: 1,
|
|
27151
|
+
provider: "pixelfx",
|
|
27152
|
+
tool: PIXELFX_TOOL,
|
|
27153
|
+
library: { name: "pixelfx", version: lib.version, repository: PIXELFX_REPOSITORY, license: "MIT" },
|
|
27154
|
+
...facts,
|
|
27155
|
+
files: { sheet: path50.basename(paths.sheet), atlas: path50.basename(paths.atlas) },
|
|
27156
|
+
sheetSha256,
|
|
27157
|
+
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27158
|
+
recipe
|
|
27159
|
+
};
|
|
27160
|
+
await mkdir17(path50.dirname(paths.sheet), { recursive: true });
|
|
27161
|
+
await writeFile22(paths.sheet, sheet.png);
|
|
27162
|
+
await writeFile22(paths.atlas, `${JSON.stringify(atlas, null, 2)}
|
|
27163
|
+
`);
|
|
27164
|
+
await writeFile22(paths.provenance, `${JSON.stringify(provenance, null, 2)}
|
|
27165
|
+
`);
|
|
27166
|
+
return {
|
|
27167
|
+
provider: "pixelfx",
|
|
27168
|
+
library: { name: "pixelfx", version: lib.version },
|
|
27169
|
+
...facts,
|
|
27170
|
+
columns: sheet.columns,
|
|
27171
|
+
sheetSha256,
|
|
27172
|
+
paths: { sheet: paths.sheet, atlas: paths.atlas, provenance: paths.provenance },
|
|
27173
|
+
recipe
|
|
27174
|
+
};
|
|
27175
|
+
}
|
|
27176
|
+
|
|
27177
|
+
// src/cli/commands/pixellab-utils.ts
|
|
26844
27178
|
function loadKeys(args) {
|
|
26845
|
-
loadEnvFiles(
|
|
27179
|
+
loadEnvFiles(path51.dirname(path51.resolve(args.manifest)));
|
|
26846
27180
|
loadEnvFiles(process.cwd());
|
|
26847
27181
|
}
|
|
26848
27182
|
async function runUnzoom(args) {
|
|
@@ -27004,7 +27338,32 @@ async function runNormalMap(args) {
|
|
|
27004
27338
|
}
|
|
27005
27339
|
log(` ${res.width}x${res.height}${res.frames > 1 ? `, ${res.frames} frames` : ""}; wrote ${res.out}`);
|
|
27006
27340
|
}
|
|
27341
|
+
var VFX_LIBS = ["pixellab", "pixelfx"];
|
|
27007
27342
|
async function runVfx(args) {
|
|
27343
|
+
if (args.lib !== void 0 && !VFX_LIBS.includes(args.lib)) {
|
|
27344
|
+
throw new UsageError(`--lib must be ${VFX_LIBS.join(" or ")}, got "${args.lib}"`);
|
|
27345
|
+
}
|
|
27346
|
+
const pixelfxOnly = [["--margin", args.margin], ["--seed", args.seed], ["--palette", args.palette.length ? args.palette : void 0]];
|
|
27347
|
+
if (args.subcommand === "effects" || args.lib === "pixelfx" && args.subcommand === "presets") {
|
|
27348
|
+
if (args.lib === "pixellab") throw new UsageError("vfx effects lists the pixelfx library's effects; PixelLab's lists are vfx presets and vfx parts");
|
|
27349
|
+
const lib = await loadPixelfx();
|
|
27350
|
+
if (args.json) {
|
|
27351
|
+
log(JSON.stringify({ version: 1, library: { name: "pixelfx", version: lib.version }, categories: lib.categories, effects: listPixelfxEffects(lib) }, null, 2));
|
|
27352
|
+
return;
|
|
27353
|
+
}
|
|
27354
|
+
log(formatPixelfxEffects(lib));
|
|
27355
|
+
return;
|
|
27356
|
+
}
|
|
27357
|
+
if (args.subcommand === "parts" && args.lib === "pixelfx") {
|
|
27358
|
+
throw new UsageError("pixelfx has no parts: its effects are whole; list them with vfx effects");
|
|
27359
|
+
}
|
|
27360
|
+
if (args.subcommand === "make") {
|
|
27361
|
+
const pixelfxRecipe = args.recipe && args.lib !== "pixellab" ? await readPixelfxRecipe(args.recipe) : null;
|
|
27362
|
+
if (args.lib === "pixelfx" || pixelfxRecipe) return runPixelfxVfx(args, pixelfxRecipe);
|
|
27363
|
+
}
|
|
27364
|
+
for (const [flag, value] of pixelfxOnly) {
|
|
27365
|
+
if (value !== void 0) throw new UsageError(`vfx takes ${flag} only with --lib pixelfx`);
|
|
27366
|
+
}
|
|
27008
27367
|
if (args.subcommand === "presets" || args.subcommand === "parts") {
|
|
27009
27368
|
if (args.dryRun) {
|
|
27010
27369
|
log(` would list PixelLab's VFX ${args.subcommand}; nothing sent`);
|
|
@@ -27029,7 +27388,7 @@ async function runVfx(args) {
|
|
|
27029
27388
|
const fromRecipe = args.recipe ? await readVfxRecipe(args.recipe) : void 0;
|
|
27030
27389
|
const sprite = args.sprite ?? fromRecipe?.sprite;
|
|
27031
27390
|
const recipeName = typeof fromRecipe?.recipe.name === "string" ? fromRecipe.recipe.name : void 0;
|
|
27032
|
-
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ??
|
|
27391
|
+
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ?? path51.basename(paths.sheet, ".png"));
|
|
27033
27392
|
const from = args.preset ? `preset ${args.preset}` : args.recipe ? `recipe ${args.recipe}` : args.effect ? `saved effect ${args.effect}` : "nothing";
|
|
27034
27393
|
log(
|
|
27035
27394
|
` 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" : ""})`
|
|
@@ -27064,6 +27423,62 @@ async function runVfx(args) {
|
|
|
27064
27423
|
}
|
|
27065
27424
|
if (res.editUrl) log(` tweak it with sliders: ${res.editUrl} (then: pixelkiln vfx --effect ${res.effectId} --out ${args.out} --force)`);
|
|
27066
27425
|
}
|
|
27426
|
+
async function runPixelfxVfx(args, fromFile) {
|
|
27427
|
+
if (!args.out) throw new UsageError("vfx needs --out <base>: <base>.png, .json, and .vfx.json are written");
|
|
27428
|
+
const pixellabOnly = [
|
|
27429
|
+
["--preset", args.preset],
|
|
27430
|
+
["--part", args.parts.length ? args.parts : void 0],
|
|
27431
|
+
["--sprite", args.sprite],
|
|
27432
|
+
["--description", args.description],
|
|
27433
|
+
["--artist", args.artist],
|
|
27434
|
+
["--sprite-frames", args.spriteFrames],
|
|
27435
|
+
["--sprite-fps", args.spriteFps],
|
|
27436
|
+
["--game-pack", args.gamePack || void 0]
|
|
27437
|
+
];
|
|
27438
|
+
for (const [flag, value] of pixellabOnly) {
|
|
27439
|
+
if (value !== void 0) throw new UsageError(`${flag} is for PixelLab's VFX tools; a pixelfx effect takes --effect, --palette, --seed, --fps and --margin`);
|
|
27440
|
+
}
|
|
27441
|
+
if (args.recipe && !fromFile) throw new UsageError(`${args.recipe} is not a pixelfx recipe: it names no pixelfx effect`);
|
|
27442
|
+
if (args.recipe && args.effect) throw new UsageError("vfx takes one of --effect or --recipe, not both");
|
|
27443
|
+
const effect = fromFile?.recipe.effect ?? args.effect;
|
|
27444
|
+
if (!effect) throw new UsageError("vfx --lib pixelfx needs --effect <category>/<name> (vfx effects lists them) or --recipe <file>");
|
|
27445
|
+
const options = {
|
|
27446
|
+
...fromFile?.recipe.options ?? {},
|
|
27447
|
+
...args.palette.length ? { palette: args.palette } : {},
|
|
27448
|
+
...args.seed !== void 0 ? { seed: args.seed } : {}
|
|
27449
|
+
};
|
|
27450
|
+
const recipe = {
|
|
27451
|
+
effect,
|
|
27452
|
+
fps: args.fps ?? fromFile?.recipe.fps,
|
|
27453
|
+
margin: args.margin ?? fromFile?.recipe.margin,
|
|
27454
|
+
...Object.keys(options).length ? { options } : {}
|
|
27455
|
+
};
|
|
27456
|
+
const lib = await loadPixelfx();
|
|
27457
|
+
const info = checkPixelfxRecipe(lib, recipe);
|
|
27458
|
+
const paths = vfxOutputPaths(args.out);
|
|
27459
|
+
const fps = recipe.fps ?? info.fps;
|
|
27460
|
+
const margin = recipe.margin ?? 0;
|
|
27461
|
+
const frames = Math.max(1, Math.round(info.duration * fps) + (info.loop ? 0 : 1));
|
|
27462
|
+
log(
|
|
27463
|
+
` vfx "${args.name ?? info.name}" from pixelfx ${lib.version} ${effect}${args.recipe ? ` (recipe ${args.recipe})` : ""} \u2192 ${paths.sheet} (+ .json, .vfx.json)`
|
|
27464
|
+
);
|
|
27465
|
+
log(` ${info.width + margin * 2}x${info.height + margin * 2}, ${frames} frames @ ${fps} fps, ${info.loop ? "loops" : "plays once"}`);
|
|
27466
|
+
log(" cost: free; rendered on this machine, nothing sent");
|
|
27467
|
+
if (fromFile?.libraryVersion && fromFile.libraryVersion !== lib.version) {
|
|
27468
|
+
log(` note: the record was rendered with pixelfx ${fromFile.libraryVersion}; ${lib.version} may draw it differently`);
|
|
27469
|
+
}
|
|
27470
|
+
if (args.dryRun) {
|
|
27471
|
+
log(" dry run: nothing written");
|
|
27472
|
+
return;
|
|
27473
|
+
}
|
|
27474
|
+
const res = await makePixelfxVfx(lib, { ...recipe, out: args.out, name: args.name, force: args.force });
|
|
27475
|
+
if (args.json) {
|
|
27476
|
+
log(JSON.stringify({ version: 1, ...res }, null, 2));
|
|
27477
|
+
return;
|
|
27478
|
+
}
|
|
27479
|
+
for (const file of [res.paths.sheet, res.paths.atlas, res.paths.provenance]) log(` wrote ${file}`);
|
|
27480
|
+
log(` render it again: pixelkiln vfx --recipe ${res.paths.provenance} --out <base>`);
|
|
27481
|
+
}
|
|
27067
27482
|
async function runVfxArtist(args, out) {
|
|
27068
27483
|
const description = args.description.trim();
|
|
27069
27484
|
if (!description) throw new UsageError('vfx --description needs the effect in words, e.g. "a blue lightning strike that leaves sparks"');
|
|
@@ -27090,7 +27505,7 @@ async function runVfxArtist(args, out) {
|
|
|
27090
27505
|
if ((args.spriteFrames !== void 0 || args.spriteFps !== void 0) && !args.sprite) {
|
|
27091
27506
|
throw new UsageError("--sprite-frames and --sprite-fps describe a --sprite; add one");
|
|
27092
27507
|
}
|
|
27093
|
-
const taken = args.sprite ? vfxArtistSprite(await
|
|
27508
|
+
const taken = args.sprite ? vfxArtistSprite(await readFile35(args.sprite), args.sprite, args.spriteFrames ?? 1) : void 0;
|
|
27094
27509
|
if (args.spriteFps !== void 0 && !taken?.animated) {
|
|
27095
27510
|
throw new UsageError("--sprite-fps is the speed of an animated sprite: a GIF, or a PNG strip with --sprite-frames 2 or more");
|
|
27096
27511
|
}
|
|
@@ -27103,7 +27518,7 @@ async function runVfxArtist(args, out) {
|
|
|
27103
27518
|
);
|
|
27104
27519
|
if (args.effect) {
|
|
27105
27520
|
log(
|
|
27106
|
-
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${
|
|
27521
|
+
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${path51.basename(paths.provenance)})` : `; ${path51.basename(paths.provenance)} holds no conversation for it, so PixelLab prices it as a new effect`)
|
|
27107
27522
|
);
|
|
27108
27523
|
}
|
|
27109
27524
|
log(` cost: about ${quote} generations by PixelLab's table, billed on delivery; at most ${ceiling} if the effect runs long`);
|
|
@@ -27153,13 +27568,13 @@ async function runVfxArtist(args, out) {
|
|
|
27153
27568
|
}
|
|
27154
27569
|
|
|
27155
27570
|
// src/cli/commands/audio.ts
|
|
27156
|
-
import { readFile as
|
|
27157
|
-
import
|
|
27571
|
+
import { readFile as readFile36 } from "fs/promises";
|
|
27572
|
+
import path53 from "path";
|
|
27158
27573
|
|
|
27159
27574
|
// src/pixellab-audio.ts
|
|
27160
|
-
import { existsSync as
|
|
27161
|
-
import { mkdir as
|
|
27162
|
-
import
|
|
27575
|
+
import { existsSync as existsSync42 } from "fs";
|
|
27576
|
+
import { mkdir as mkdir18, writeFile as writeFile23 } from "fs/promises";
|
|
27577
|
+
import path52 from "path";
|
|
27163
27578
|
var MUSIC_COST_GENERATIONS = 10;
|
|
27164
27579
|
var MUSIC_LOOP_COST_GENERATIONS = 4;
|
|
27165
27580
|
var MUSIC_LOOP_MIN_BODY_SECONDS = 36;
|
|
@@ -27216,7 +27631,7 @@ async function billedUsage(client2, jobId) {
|
|
|
27216
27631
|
}
|
|
27217
27632
|
}
|
|
27218
27633
|
function musicOutputPaths(out) {
|
|
27219
|
-
const base =
|
|
27634
|
+
const base = path52.resolve(out.replace(/\.(music\.json|mp3)$/i, ""));
|
|
27220
27635
|
return {
|
|
27221
27636
|
takes: [`${base}.mp3`, `${base}.take2.mp3`],
|
|
27222
27637
|
loops: [`${base}.loop.mp3`, `${base}.loop.take2.mp3`],
|
|
@@ -27238,8 +27653,8 @@ async function collectTakes(client2, songs, files, what, opts) {
|
|
|
27238
27653
|
if (!song.audio_url) throw new Error(`PixelLab ${what} ${song.id} completed without an audio URL`);
|
|
27239
27654
|
const bytes = await client2.download(song.audio_url);
|
|
27240
27655
|
validateAudio(bytes, "mp3");
|
|
27241
|
-
await
|
|
27242
|
-
await
|
|
27656
|
+
await mkdir18(path52.dirname(file), { recursive: true });
|
|
27657
|
+
await writeFile23(file, bytes);
|
|
27243
27658
|
finished.push(song);
|
|
27244
27659
|
takes.push({
|
|
27245
27660
|
songId: song.id,
|
|
@@ -27266,7 +27681,7 @@ async function generateMusic(client2, opts) {
|
|
|
27266
27681
|
}
|
|
27267
27682
|
const writes = [paths.record, ...opts.loopOf ? [] : paths.takes, ...wantsLoop ? paths.loops : []];
|
|
27268
27683
|
if (!opts.force) {
|
|
27269
|
-
for (const file of writes) if (
|
|
27684
|
+
for (const file of writes) if (existsSync42(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
27270
27685
|
}
|
|
27271
27686
|
const usage2 = [];
|
|
27272
27687
|
let quoted = null;
|
|
@@ -27304,10 +27719,10 @@ async function generateMusic(client2, opts) {
|
|
|
27304
27719
|
quotedGenerations: quoted,
|
|
27305
27720
|
usage: usage2
|
|
27306
27721
|
});
|
|
27307
|
-
const relative = (take) => ({ ...take, file:
|
|
27722
|
+
const relative = (take) => ({ ...take, file: path52.basename(take.file) });
|
|
27308
27723
|
const writeRecord = async (result2) => {
|
|
27309
|
-
await
|
|
27310
|
-
await
|
|
27724
|
+
await mkdir18(path52.dirname(paths.record), { recursive: true });
|
|
27725
|
+
await writeFile23(
|
|
27311
27726
|
paths.record,
|
|
27312
27727
|
JSON.stringify(
|
|
27313
27728
|
{
|
|
@@ -27347,7 +27762,7 @@ async function generateMusic(client2, opts) {
|
|
|
27347
27762
|
submitted = await client2.loopMusic(loopSource);
|
|
27348
27763
|
} catch (error) {
|
|
27349
27764
|
const detail = refusalDetail(error);
|
|
27350
|
-
const kept = takes.length ? ` The song's takes are saved (${
|
|
27765
|
+
const kept = takes.length ? ` The song's takes are saved (${path52.basename(paths.record)}); nothing was charged for the loop.` : "";
|
|
27351
27766
|
throw new Error(`PixelLab refused to loop ${loopSource}: ${detail ?? (error instanceof Error ? error.message : String(error))}${kept}`, { cause: error });
|
|
27352
27767
|
}
|
|
27353
27768
|
quoted = (quoted ?? 0) + (submitted.quoted_generations ?? 0);
|
|
@@ -27361,13 +27776,13 @@ async function generateMusic(client2, opts) {
|
|
|
27361
27776
|
return result;
|
|
27362
27777
|
}
|
|
27363
27778
|
function soundEffectOutputPaths(out) {
|
|
27364
|
-
const base =
|
|
27779
|
+
const base = path52.resolve(out.replace(/\.(sfx\.json|wav)$/i, ""));
|
|
27365
27780
|
return { wav: `${base}.wav`, record: `${base}.sfx.json` };
|
|
27366
27781
|
}
|
|
27367
27782
|
async function generateSoundEffect(client2, opts) {
|
|
27368
27783
|
const { wav, record } = soundEffectOutputPaths(opts.out);
|
|
27369
27784
|
if (!opts.force) {
|
|
27370
|
-
for (const file of [wav, record]) if (
|
|
27785
|
+
for (const file of [wav, record]) if (existsSync42(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
27371
27786
|
}
|
|
27372
27787
|
const seconds = opts.seconds ?? 2;
|
|
27373
27788
|
const submitted = await client2.createSoundEffect({ prompt: opts.prompt, seconds, name: opts.name });
|
|
@@ -27376,8 +27791,8 @@ async function generateSoundEffect(client2, opts) {
|
|
|
27376
27791
|
if (!clip.audio_url) throw new Error(`PixelLab sound effect ${id} completed without an audio URL`);
|
|
27377
27792
|
const bytes = await client2.download(clip.audio_url);
|
|
27378
27793
|
validateAudio(bytes, "wav");
|
|
27379
|
-
await
|
|
27380
|
-
await
|
|
27794
|
+
await mkdir18(path52.dirname(wav), { recursive: true });
|
|
27795
|
+
await writeFile23(wav, bytes);
|
|
27381
27796
|
const result = {
|
|
27382
27797
|
soundEffectId: id,
|
|
27383
27798
|
file: wav,
|
|
@@ -27388,7 +27803,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
27388
27803
|
quotedGenerations: submitted.quoted_generations ?? null,
|
|
27389
27804
|
usage: await billedUsage(client2, submitted.background_job_id)
|
|
27390
27805
|
};
|
|
27391
|
-
await
|
|
27806
|
+
await writeFile23(
|
|
27392
27807
|
record,
|
|
27393
27808
|
JSON.stringify(
|
|
27394
27809
|
{
|
|
@@ -27399,7 +27814,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
27399
27814
|
prompt: opts.prompt,
|
|
27400
27815
|
seconds,
|
|
27401
27816
|
soundEffectId: id,
|
|
27402
|
-
file:
|
|
27817
|
+
file: path52.basename(wav),
|
|
27403
27818
|
sha256: result.sha256,
|
|
27404
27819
|
durationMs: result.durationMs,
|
|
27405
27820
|
quotedGenerations: result.quotedGenerations,
|
|
@@ -27414,7 +27829,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
27414
27829
|
|
|
27415
27830
|
// src/cli/commands/audio.ts
|
|
27416
27831
|
function loadKeys2(args) {
|
|
27417
|
-
loadEnvFiles(
|
|
27832
|
+
loadEnvFiles(path53.dirname(path53.resolve(args.manifest)));
|
|
27418
27833
|
loadEnvFiles(process.cwd());
|
|
27419
27834
|
}
|
|
27420
27835
|
function progress() {
|
|
@@ -27471,7 +27886,7 @@ async function runMusic(args) {
|
|
|
27471
27886
|
const cost = musicCost({ loop: args.loop, loopOf: args.loopOf });
|
|
27472
27887
|
const paths = musicOutputPaths(args.out);
|
|
27473
27888
|
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" : ""}`;
|
|
27474
|
-
log(` music: ${what} \u2192 ${
|
|
27889
|
+
log(` music: ${what} \u2192 ${path53.relative(process.cwd(), args.loopOf ? paths.loops[0] : paths.takes[0])} \u2026`);
|
|
27475
27890
|
log(` cost: ${cost} generations (PixelLab's published price)${args.improve ? ", plus about 0.05 for --improve" : ""}`);
|
|
27476
27891
|
if (args.budget !== void 0 && args.budget < cost) {
|
|
27477
27892
|
throw new Error(`--budget ${args.budget} is below this run's ${cost}-generation cost`);
|
|
@@ -27488,7 +27903,7 @@ async function runMusic(args) {
|
|
|
27488
27903
|
style = (await client2.improveMusicStyle({ style, instrumental: !vocals, bpm: args.bpm })).style;
|
|
27489
27904
|
log(` style: ${style}`);
|
|
27490
27905
|
}
|
|
27491
|
-
const lyrics = args.lyrics ? await
|
|
27906
|
+
const lyrics = args.lyrics ? await readFile36(path53.resolve(args.lyrics), "utf8") : void 0;
|
|
27492
27907
|
const res = await generateMusic(client2, {
|
|
27493
27908
|
style,
|
|
27494
27909
|
lyrics,
|
|
@@ -27524,7 +27939,7 @@ async function runSfx(args) {
|
|
|
27524
27939
|
const seconds = args.seconds ?? 2;
|
|
27525
27940
|
const cost = soundEffectCost(seconds);
|
|
27526
27941
|
const { wav } = soundEffectOutputPaths(args.out);
|
|
27527
|
-
log(` sfx: "${args.description}", ${seconds} s \u2192 ${
|
|
27942
|
+
log(` sfx: "${args.description}", ${seconds} s \u2192 ${path53.relative(process.cwd(), wav)}`);
|
|
27528
27943
|
log(` cost: ${cost} generation${cost === 1 ? "" : "s"} (PixelLab's published price, by length)`);
|
|
27529
27944
|
if (args.budget !== void 0 && args.budget < cost) {
|
|
27530
27945
|
throw new Error(`--budget ${args.budget} is below this clip's ${cost}-generation cost`);
|
|
@@ -27552,12 +27967,12 @@ async function runSfx(args) {
|
|
|
27552
27967
|
}
|
|
27553
27968
|
|
|
27554
27969
|
// src/cli/commands/ui.ts
|
|
27555
|
-
import
|
|
27970
|
+
import path55 from "path";
|
|
27556
27971
|
|
|
27557
27972
|
// src/pixellab-ui.ts
|
|
27558
|
-
import { existsSync as
|
|
27559
|
-
import { mkdir as
|
|
27560
|
-
import
|
|
27973
|
+
import { existsSync as existsSync43 } from "fs";
|
|
27974
|
+
import { mkdir as mkdir19, writeFile as writeFile24 } from "fs/promises";
|
|
27975
|
+
import path54 from "path";
|
|
27561
27976
|
var UI_STATES_COSTS = [10, 15, 25];
|
|
27562
27977
|
var UI_STATES_MAX_COST = 25;
|
|
27563
27978
|
var UI_STATES_MAX_ELEMENTS = 64;
|
|
@@ -27650,8 +28065,8 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
27650
28065
|
const asset = await client2.getUiAssetDetail(uiAssetId);
|
|
27651
28066
|
if (asset.status && asset.status !== "completed") throw new Error(`UI asset ${uiAssetId} is ${asset.status}; pull it once it is completed`);
|
|
27652
28067
|
if (!asset.image_url) throw new Error(`UI asset ${uiAssetId} has no image yet`);
|
|
27653
|
-
const dir =
|
|
27654
|
-
const record =
|
|
28068
|
+
const dir = path54.resolve(opts.out);
|
|
28069
|
+
const record = path54.join(dir, "ui.json");
|
|
27655
28070
|
const plan = [];
|
|
27656
28071
|
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 } } : {};
|
|
27657
28072
|
const taken = /* @__PURE__ */ new Set();
|
|
@@ -27699,20 +28114,20 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
27699
28114
|
}
|
|
27700
28115
|
if (kind === "element") addStates(asset, rootName, asset.states);
|
|
27701
28116
|
if (!opts.force) {
|
|
27702
|
-
for (const file of [record, ...plan.map((item) =>
|
|
27703
|
-
if (
|
|
28117
|
+
for (const file of [record, ...plan.map((item) => path54.join(dir, item.file))]) {
|
|
28118
|
+
if (existsSync43(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
27704
28119
|
}
|
|
27705
28120
|
}
|
|
27706
28121
|
const files = [];
|
|
27707
28122
|
for (const { url, ...item } of plan) {
|
|
27708
28123
|
const bytes = await client2.download(url);
|
|
27709
28124
|
validateMedia(bytes, MediaType.PNG);
|
|
27710
|
-
const target =
|
|
27711
|
-
await
|
|
27712
|
-
await
|
|
28125
|
+
const target = path54.join(dir, item.file);
|
|
28126
|
+
await mkdir19(path54.dirname(target), { recursive: true });
|
|
28127
|
+
await writeFile24(target, bytes);
|
|
27713
28128
|
files.push({ ...item, sha256: sha256(bytes) });
|
|
27714
28129
|
}
|
|
27715
|
-
await
|
|
28130
|
+
await writeFile24(
|
|
27716
28131
|
record,
|
|
27717
28132
|
JSON.stringify(
|
|
27718
28133
|
{
|
|
@@ -27734,7 +28149,7 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
27734
28149
|
|
|
27735
28150
|
// src/cli/commands/ui.ts
|
|
27736
28151
|
function loadKeys3(args) {
|
|
27737
|
-
loadEnvFiles(
|
|
28152
|
+
loadEnvFiles(path55.dirname(path55.resolve(args.manifest)));
|
|
27738
28153
|
loadEnvFiles(process.cwd());
|
|
27739
28154
|
}
|
|
27740
28155
|
function requireId(args) {
|
|
@@ -27848,18 +28263,18 @@ async function runUi(args) {
|
|
|
27848
28263
|
log(JSON.stringify({ version: 1, ...res }, null, 2));
|
|
27849
28264
|
return;
|
|
27850
28265
|
}
|
|
27851
|
-
for (const file of res.files) log(` wrote ${
|
|
27852
|
-
log(` wrote ${
|
|
28266
|
+
for (const file of res.files) log(` wrote ${path55.join(args.out, file.file)} (${file.kind}, ${file.size.width}x${file.size.height})`);
|
|
28267
|
+
log(` wrote ${path55.join(args.out, "ui.json")}`);
|
|
27853
28268
|
}
|
|
27854
28269
|
|
|
27855
28270
|
// src/cli/commands/asset.ts
|
|
27856
|
-
import { readFile as
|
|
27857
|
-
import
|
|
28271
|
+
import { readFile as readFile38 } from "fs/promises";
|
|
28272
|
+
import path57 from "path";
|
|
27858
28273
|
|
|
27859
28274
|
// src/pixellab-assets.ts
|
|
27860
|
-
import { existsSync as
|
|
27861
|
-
import { mkdir as
|
|
27862
|
-
import
|
|
28275
|
+
import { existsSync as existsSync44 } from "fs";
|
|
28276
|
+
import { mkdir as mkdir20, readdir as readdir3, readFile as readFile37, stat as stat5, writeFile as writeFile25 } from "fs/promises";
|
|
28277
|
+
import path56 from "path";
|
|
27863
28278
|
var ASSET_KINDS = ["object", "character"];
|
|
27864
28279
|
var EXPORT_FORMATS = ["zip", "spritesheet", "aseprite", "gif"];
|
|
27865
28280
|
var MIRROR_DIRECTIONS = ["east", "west", "south-east", "south-west", "north-east", "north-west"];
|
|
@@ -27879,7 +28294,7 @@ function parseCanvasSize(text, kind) {
|
|
|
27879
28294
|
}
|
|
27880
28295
|
function exportOutPath(out, format) {
|
|
27881
28296
|
const extension = format === "aseprite" ? ".aseprite" : format === "gif" ? ".gif" : ".zip";
|
|
27882
|
-
return
|
|
28297
|
+
return path56.extname(out) ? path56.resolve(out) : path56.resolve(`${out}${extension}`);
|
|
27883
28298
|
}
|
|
27884
28299
|
function checkExportBytes(bytes, format) {
|
|
27885
28300
|
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";
|
|
@@ -27887,15 +28302,15 @@ function checkExportBytes(bytes, format) {
|
|
|
27887
28302
|
}
|
|
27888
28303
|
async function exportAssetFile(client2, kind, id, format, opts) {
|
|
27889
28304
|
const out = exportOutPath(opts.out, format);
|
|
27890
|
-
if (
|
|
28305
|
+
if (existsSync44(out) && !opts.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
27891
28306
|
const bytes = await client2.exportAsset(kind, id, format, { animationGroupId: opts.animationGroupId, direction: opts.direction });
|
|
27892
28307
|
checkExportBytes(bytes, format);
|
|
27893
|
-
await
|
|
27894
|
-
await
|
|
28308
|
+
await mkdir20(path56.dirname(out), { recursive: true });
|
|
28309
|
+
await writeFile25(out, bytes);
|
|
27895
28310
|
return { out, bytes: bytes.length };
|
|
27896
28311
|
}
|
|
27897
28312
|
async function importObjectFile(client2, file, opts = {}) {
|
|
27898
|
-
const bytes = await
|
|
28313
|
+
const bytes = await readFile37(file);
|
|
27899
28314
|
const metadata = imageMetadata(bytes);
|
|
27900
28315
|
if (!metadata || metadata.format !== "png") throw new Error(`${file} is not a PNG; PixelLab imports PNG only (JPEG compression would be stored as pixels)`);
|
|
27901
28316
|
if (metadata.width > IMPORT_MAX_SIDE || metadata.height > IMPORT_MAX_SIDE) {
|
|
@@ -27937,17 +28352,17 @@ async function pullExpansionReview(client2, id, opts) {
|
|
|
27937
28352
|
if (object.status !== "review-expansion" || !review?.rotation_urls) {
|
|
27938
28353
|
throw new Error(`object ${id} is ${object.status ?? "unknown"}; there is no expansion waiting for review`);
|
|
27939
28354
|
}
|
|
27940
|
-
const dir =
|
|
28355
|
+
const dir = path56.resolve(opts.out);
|
|
27941
28356
|
const entries = Object.entries(review.rotation_urls).filter((entry) => typeof entry[1] === "string");
|
|
27942
|
-
const files = entries.map(([direction]) => ({ direction, file:
|
|
28357
|
+
const files = entries.map(([direction]) => ({ direction, file: path56.join(dir, `${direction}.png`) }));
|
|
27943
28358
|
if (!opts.force) {
|
|
27944
|
-
for (const { file } of files) if (
|
|
28359
|
+
for (const { file } of files) if (existsSync44(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
27945
28360
|
}
|
|
27946
|
-
await
|
|
28361
|
+
await mkdir20(dir, { recursive: true });
|
|
27947
28362
|
for (const [index, [, url]] of entries.entries()) {
|
|
27948
28363
|
const bytes = await client2.download(url);
|
|
27949
28364
|
validateMedia(bytes, MediaType.PNG);
|
|
27950
|
-
await
|
|
28365
|
+
await writeFile25(files[index].file, bytes);
|
|
27951
28366
|
}
|
|
27952
28367
|
return { dir, existingDirection: review.existing_direction ?? null, files };
|
|
27953
28368
|
}
|
|
@@ -27988,7 +28403,7 @@ function readPng(bytes, file) {
|
|
|
27988
28403
|
return metadata;
|
|
27989
28404
|
}
|
|
27990
28405
|
async function importTilesetFile(client2, file, opts = {}) {
|
|
27991
|
-
const bytes = await
|
|
28406
|
+
const bytes = await readFile37(file);
|
|
27992
28407
|
const { width, height } = readPng(bytes, file);
|
|
27993
28408
|
const reading = chooseTilesetSheetReading(file, width, height, opts.tileSize);
|
|
27994
28409
|
const mode2 = opts.mode ?? "topdown";
|
|
@@ -28006,11 +28421,11 @@ async function importTilesetFile(client2, file, opts = {}) {
|
|
|
28006
28421
|
return { tilesetId: res.tileset_id, mode: mode2, tileSize: reading.tileSize, layout: reading.layout };
|
|
28007
28422
|
}
|
|
28008
28423
|
async function pngFilesAt(from) {
|
|
28009
|
-
if (!
|
|
28424
|
+
if (!existsSync44(from)) throw new Error(`${from} does not exist`);
|
|
28010
28425
|
if (!(await stat5(from)).isDirectory()) return [from];
|
|
28011
28426
|
const names = (await readdir3(from)).filter((name) => /\.png$/i.test(name)).sort((a, b) => a.localeCompare(b, void 0, { numeric: true }));
|
|
28012
28427
|
if (names.length === 0) throw new Error(`${from} holds no PNG files`);
|
|
28013
|
-
return names.map((name) =>
|
|
28428
|
+
return names.map((name) => path56.join(from, name));
|
|
28014
28429
|
}
|
|
28015
28430
|
function importTileHeights(tileType, tileSize) {
|
|
28016
28431
|
if (tileType === "square_topdown" || tileType === "octagon") return { min: tileSize, max: tileSize };
|
|
@@ -28025,7 +28440,7 @@ async function importTilesFiles(client2, from, opts) {
|
|
|
28025
28440
|
const heights = importTileHeights(opts.tileType, opts.tileSize);
|
|
28026
28441
|
const frames = [];
|
|
28027
28442
|
for (const file of files) {
|
|
28028
|
-
const bytes = await
|
|
28443
|
+
const bytes = await readFile37(file);
|
|
28029
28444
|
const { width, height } = readPng(bytes, file);
|
|
28030
28445
|
if (width !== opts.tileSize || height < heights.min || height > heights.max) {
|
|
28031
28446
|
const tall = heights.min === heights.max ? `${heights.min}` : `${heights.min} to ${heights.max}`;
|
|
@@ -28045,14 +28460,14 @@ function checkSaveTarget(target) {
|
|
|
28045
28460
|
}
|
|
28046
28461
|
function saveUndoDir(target, now = /* @__PURE__ */ new Date()) {
|
|
28047
28462
|
const stamp = now.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
|
|
28048
|
-
return
|
|
28463
|
+
return path56.resolve("pixelkiln-undo", `${target.replace(/[^a-zA-Z0-9-]+/g, "_")}-${stamp}`);
|
|
28049
28464
|
}
|
|
28050
28465
|
async function writeUndo(frames, dir) {
|
|
28051
|
-
await
|
|
28466
|
+
await mkdir20(dir, { recursive: true });
|
|
28052
28467
|
const files = [];
|
|
28053
28468
|
for (const [index, frame] of frames.entries()) {
|
|
28054
|
-
const file =
|
|
28055
|
-
await
|
|
28469
|
+
const file = path56.join(dir, frames.length === 1 ? "previous.png" : `previous-${String(index).padStart(2, "0")}.png`);
|
|
28470
|
+
await writeFile25(file, Buffer.from(frame.base64, "base64"));
|
|
28056
28471
|
files.push(file);
|
|
28057
28472
|
}
|
|
28058
28473
|
return files;
|
|
@@ -28061,13 +28476,13 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
28061
28476
|
checkSaveTarget(target);
|
|
28062
28477
|
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");
|
|
28063
28478
|
const files = await pngFilesAt(from).catch(async (error) => {
|
|
28064
|
-
if (
|
|
28479
|
+
if (existsSync44(from) && /\.gif$/i.test(from)) return [from];
|
|
28065
28480
|
throw error;
|
|
28066
28481
|
});
|
|
28067
28482
|
let image;
|
|
28068
28483
|
let frames;
|
|
28069
28484
|
if (files.length === 1) {
|
|
28070
|
-
const bytes = await
|
|
28485
|
+
const bytes = await readFile37(files[0]);
|
|
28071
28486
|
const gif = bytes.subarray(0, 4).toString("ascii") === "GIF8";
|
|
28072
28487
|
if (!gif) readPng(bytes, files[0]);
|
|
28073
28488
|
image = { base64: bytes.toString("base64"), format: gif ? "gif" : "png" };
|
|
@@ -28076,14 +28491,14 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
28076
28491
|
let size;
|
|
28077
28492
|
frames = [];
|
|
28078
28493
|
for (const file of files) {
|
|
28079
|
-
const bytes = await
|
|
28494
|
+
const bytes = await readFile37(file);
|
|
28080
28495
|
const { width, height } = readPng(bytes, file);
|
|
28081
28496
|
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`);
|
|
28082
28497
|
size = `${width}x${height}`;
|
|
28083
28498
|
frames.push({ base64: bytes.toString("base64"), format: "png" });
|
|
28084
28499
|
}
|
|
28085
28500
|
}
|
|
28086
|
-
const undoDir = opts.undoDir ?
|
|
28501
|
+
const undoDir = opts.undoDir ? path56.resolve(opts.undoDir) : saveUndoDir(target);
|
|
28087
28502
|
let res;
|
|
28088
28503
|
try {
|
|
28089
28504
|
res = await client2.saveToAsset({ target, image, frames, name: opts.name, description: opts.description });
|
|
@@ -28119,7 +28534,7 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
28119
28534
|
|
|
28120
28535
|
// src/cli/commands/asset.ts
|
|
28121
28536
|
function loadKeys4(args) {
|
|
28122
|
-
loadEnvFiles(
|
|
28537
|
+
loadEnvFiles(path57.dirname(path57.resolve(args.manifest)));
|
|
28123
28538
|
loadEnvFiles(process.cwd());
|
|
28124
28539
|
}
|
|
28125
28540
|
function kindOf(args) {
|
|
@@ -28240,7 +28655,7 @@ async function runAsset(args) {
|
|
|
28240
28655
|
const res2 = await pullExpansionReview(clientFromEnv(), id, { out: args.out, force: args.force });
|
|
28241
28656
|
if (args.json) emit(res2);
|
|
28242
28657
|
else {
|
|
28243
|
-
for (const file of res2.files) log(` wrote ${
|
|
28658
|
+
for (const file of res2.files) log(` wrote ${path57.join(args.out, `${file.direction}.png`)}${file.direction === res2.existingDirection ? " (your image, unchanged)" : ""}`);
|
|
28244
28659
|
log(` keep them: pixelkiln asset expand --id ${id} --keep discard: pixelkiln asset expand --id ${id} --discard`);
|
|
28245
28660
|
}
|
|
28246
28661
|
return;
|
|
@@ -28285,7 +28700,7 @@ async function runTileImport(args, emit) {
|
|
|
28285
28700
|
if (args.tileType) throw new UsageError("--tile-type belongs to --kind tiles; a tileset is a Wang sheet");
|
|
28286
28701
|
const opts2 = { mode: mode2, tileSize, lowerDescription: args.lower, upperDescription: args.upper, transitionDescription: args.transition, name: args.name };
|
|
28287
28702
|
if (args.dryRun) {
|
|
28288
|
-
const metadata = imageMetadata(await
|
|
28703
|
+
const metadata = imageMetadata(await readFile38(args.from));
|
|
28289
28704
|
if (!metadata || metadata.format !== "png") throw new UsageError(`${args.from} is not a PNG`);
|
|
28290
28705
|
const reading = await usage(() => chooseTilesetSheetReading(args.from, metadata.width, metadata.height, tileSize));
|
|
28291
28706
|
log(` would import ${args.from} as a ${mode2} tileset of ${reading.tileSize}px tiles (${reading.layout === "compact" ? "4 wide" : "8 wide"}); nothing sent`);
|
|
@@ -28324,7 +28739,7 @@ async function runSave(args, emit) {
|
|
|
28324
28739
|
if (!args.from) throw new UsageError("asset save needs --from: a PNG, an animated GIF, or a directory of PNG frames");
|
|
28325
28740
|
await usage(() => checkSaveTarget(target));
|
|
28326
28741
|
const adding = target === "gallery:new";
|
|
28327
|
-
const undoDir = args.out ?
|
|
28742
|
+
const undoDir = args.out ? path57.resolve(args.out) : saveUndoDir(target);
|
|
28328
28743
|
if (adding) log(` add ${args.from} to your PixelLab gallery as a new image (free)`);
|
|
28329
28744
|
else {
|
|
28330
28745
|
log(` save ${args.from} over ${target} on PixelLab (free)`);
|
|
@@ -28347,21 +28762,21 @@ async function runSave(args, emit) {
|
|
|
28347
28762
|
else {
|
|
28348
28763
|
log(` ${res.target}: ${res.kind} saved, ${res.width}x${res.height}, ${res.frames} frame(s), ${res.changedPixels} pixel(s) changed`);
|
|
28349
28764
|
for (const file of res.undo) log(` kept the old pixels: ${file}`);
|
|
28350
|
-
if (res.undo.length) log(` undo: pixelkiln asset save --target ${res.target} --from ${res.undo.length === 1 ? res.undo[0] :
|
|
28765
|
+
if (res.undo.length) log(` undo: pixelkiln asset save --target ${res.target} --from ${res.undo.length === 1 ? res.undo[0] : path57.dirname(res.undo[0])} --yes`);
|
|
28351
28766
|
}
|
|
28352
28767
|
if (res.note) log(` ${res.note}`);
|
|
28353
28768
|
if (res.maps) log(` ${res.maps}`);
|
|
28354
28769
|
}
|
|
28355
28770
|
|
|
28356
28771
|
// src/cli/commands/talk.ts
|
|
28772
|
+
import { existsSync as existsSync46 } from "fs";
|
|
28773
|
+
import { mkdir as mkdir22, readFile as readFile40, writeFile as writeFile27 } from "fs/promises";
|
|
28774
|
+
import path59 from "path";
|
|
28775
|
+
|
|
28776
|
+
// src/pixellab-talk.ts
|
|
28357
28777
|
import { existsSync as existsSync45 } from "fs";
|
|
28358
28778
|
import { mkdir as mkdir21, readFile as readFile39, writeFile as writeFile26 } from "fs/promises";
|
|
28359
28779
|
import path58 from "path";
|
|
28360
|
-
|
|
28361
|
-
// src/pixellab-talk.ts
|
|
28362
|
-
import { existsSync as existsSync44 } from "fs";
|
|
28363
|
-
import { mkdir as mkdir20, readFile as readFile38, writeFile as writeFile25 } from "fs/promises";
|
|
28364
|
-
import path57 from "path";
|
|
28365
28780
|
var TALK_MOODS = ["neutral", "happy", "angry", "sad", "surprised"];
|
|
28366
28781
|
var VISEME_COUNTS = [3, 5, 7, 12];
|
|
28367
28782
|
var VISEME_ENGINES = ["v3", "pixminimax"];
|
|
@@ -28372,7 +28787,7 @@ function visemeCost(engine, side, count) {
|
|
|
28372
28787
|
return Math.ceil(forSeven * count / 7);
|
|
28373
28788
|
}
|
|
28374
28789
|
function talkOutputPaths(out) {
|
|
28375
|
-
const base =
|
|
28790
|
+
const base = path58.resolve(out.replace(/\.(png|json)$/i, "").replace(/\.(talk|visemes)$/i, ""));
|
|
28376
28791
|
return { strip: `${base}.visemes.png`, record: `${base}.talk.json` };
|
|
28377
28792
|
}
|
|
28378
28793
|
function readPortrait(bytes, label) {
|
|
@@ -28414,14 +28829,14 @@ async function makeVisemes(client2, opts) {
|
|
|
28414
28829
|
if (Boolean(opts.portrait) === Boolean(opts.characterId)) throw new Error("give a portrait file or a character id, not both");
|
|
28415
28830
|
const paths = talkOutputPaths(opts.out);
|
|
28416
28831
|
if (!opts.force) {
|
|
28417
|
-
for (const file of [paths.strip, paths.record]) if (
|
|
28832
|
+
for (const file of [paths.strip, paths.record]) if (existsSync45(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
28418
28833
|
}
|
|
28419
28834
|
const progress2 = opts.onProgress ?? (() => {
|
|
28420
28835
|
});
|
|
28421
28836
|
const sleep3 = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
28422
28837
|
const interval = opts.intervalMs ?? 8e3;
|
|
28423
28838
|
const timeout = opts.timeoutMs ?? 10 * 6e4;
|
|
28424
|
-
const portrait = opts.portrait ? readPortrait(await
|
|
28839
|
+
const portrait = opts.portrait ? readPortrait(await readFile39(opts.portrait), opts.portrait) : void 0;
|
|
28425
28840
|
const engine = opts.engine ?? "v3";
|
|
28426
28841
|
const visemeCount = opts.visemeCount ?? 7;
|
|
28427
28842
|
const submitted = await client2.createVocalAnimation({
|
|
@@ -28466,8 +28881,8 @@ async function makeVisemes(client2, opts) {
|
|
|
28466
28881
|
throw new Error(`PixelLab vocal-animation job ${jobId} finished with no mouth positions and no spritesheet`);
|
|
28467
28882
|
}
|
|
28468
28883
|
const usage2 = (await client2.getBackgroundJob(jobId).catch(() => null))?.usage ?? job.usage ?? null;
|
|
28469
|
-
await
|
|
28470
|
-
await
|
|
28884
|
+
await mkdir21(path58.dirname(paths.strip), { recursive: true });
|
|
28885
|
+
await writeFile26(paths.strip, strip);
|
|
28471
28886
|
const record = {
|
|
28472
28887
|
version: 1,
|
|
28473
28888
|
provider: "pixellab",
|
|
@@ -28477,31 +28892,31 @@ async function makeVisemes(client2, opts) {
|
|
|
28477
28892
|
visemeCount,
|
|
28478
28893
|
visemeOrder,
|
|
28479
28894
|
cell,
|
|
28480
|
-
strip:
|
|
28481
|
-
source: opts.portrait ? { portrait:
|
|
28895
|
+
strip: path58.basename(paths.strip),
|
|
28896
|
+
source: opts.portrait ? { portrait: path58.relative(path58.dirname(paths.record), path58.resolve(opts.portrait)).split(path58.sep).join("/") } : { characterId: opts.characterId },
|
|
28482
28897
|
...job.moods_on_character ? { moodsOnCharacter: job.moods_on_character } : {},
|
|
28483
28898
|
jobId,
|
|
28484
28899
|
usage: usage2,
|
|
28485
28900
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
28486
28901
|
};
|
|
28487
|
-
await
|
|
28902
|
+
await writeFile26(paths.record, `${JSON.stringify(record, null, 2)}
|
|
28488
28903
|
`);
|
|
28489
28904
|
return { ...record, paths };
|
|
28490
28905
|
}
|
|
28491
28906
|
async function readTalkRecord(file) {
|
|
28492
28907
|
let record;
|
|
28493
28908
|
try {
|
|
28494
|
-
record = JSON.parse(await
|
|
28909
|
+
record = JSON.parse(await readFile39(file, "utf8"));
|
|
28495
28910
|
} catch (error) {
|
|
28496
28911
|
throw new Error(`${file} is not a readable .talk.json record: ${error instanceof Error ? error.message : String(error)}`);
|
|
28497
28912
|
}
|
|
28498
28913
|
if (record?.tool !== "vocal-animation" || !Array.isArray(record.visemeOrder) || !record.cell || !record.strip) {
|
|
28499
28914
|
throw new Error(`${file} is not a .talk.json record from pixelkiln talk visemes`);
|
|
28500
28915
|
}
|
|
28501
|
-
const stripFile =
|
|
28502
|
-
if (!
|
|
28916
|
+
const stripFile = path58.resolve(path58.dirname(path58.resolve(file)), record.strip);
|
|
28917
|
+
if (!existsSync45(stripFile)) throw new Error(`${file} names ${record.strip}, which is missing beside it`);
|
|
28503
28918
|
const row = Math.max(0, record.moodsOnCharacter?.indexOf(record.mood) ?? 0);
|
|
28504
|
-
const cells = cutStrip(await
|
|
28919
|
+
const cells = cutStrip(await readFile39(stripFile), record.visemeOrder.length, record.cell, row);
|
|
28505
28920
|
const visemes = Object.fromEntries(record.visemeOrder.map((id, index) => [id, { base64: cells[index].toString("base64"), format: "png" }]));
|
|
28506
28921
|
return { record, visemes };
|
|
28507
28922
|
}
|
|
@@ -28514,15 +28929,15 @@ function checkText(text) {
|
|
|
28514
28929
|
async function makeTalkingGif(client2, text, source, opts) {
|
|
28515
28930
|
if (Boolean(source.record) === Boolean(source.characterId)) throw new Error("give a .talk.json record or a character id, not both");
|
|
28516
28931
|
if (source.record && source.mood) throw new Error("a record holds one expression; --mood picks among a character's stored ones");
|
|
28517
|
-
const out =
|
|
28518
|
-
if (
|
|
28932
|
+
const out = path58.extname(opts.out) ? path58.resolve(opts.out) : path58.resolve(`${opts.out}.gif`);
|
|
28933
|
+
if (existsSync45(out) && !opts.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
28519
28934
|
const line = checkText(text);
|
|
28520
28935
|
const visemes = source.record ? (await readTalkRecord(source.record)).visemes : void 0;
|
|
28521
28936
|
const res = await client2.createTalkingGif({ text: line, visemes, characterId: source.characterId, mood: source.mood, frameMs: opts.frameMs, holdMs: opts.holdMs });
|
|
28522
28937
|
const bytes = Buffer.from(res.gif_base64, "base64");
|
|
28523
28938
|
if (bytes.subarray(0, 4).toString("ascii") !== "GIF8") throw new Error(`PixelLab's talking GIF was not a GIF (${bytes.length} bytes)`);
|
|
28524
|
-
await
|
|
28525
|
-
await
|
|
28939
|
+
await mkdir21(path58.dirname(out), { recursive: true });
|
|
28940
|
+
await writeFile26(out, bytes);
|
|
28526
28941
|
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 };
|
|
28527
28942
|
}
|
|
28528
28943
|
async function planLipSync(client2, text, source, opts = {}) {
|
|
@@ -28554,7 +28969,7 @@ async function planLipSync(client2, text, source, opts = {}) {
|
|
|
28554
28969
|
|
|
28555
28970
|
// src/cli/commands/talk.ts
|
|
28556
28971
|
function loadKeys5(args) {
|
|
28557
|
-
loadEnvFiles(
|
|
28972
|
+
loadEnvFiles(path59.dirname(path59.resolve(args.manifest)));
|
|
28558
28973
|
loadEnvFiles(process.cwd());
|
|
28559
28974
|
}
|
|
28560
28975
|
function moodOf(args) {
|
|
@@ -28576,7 +28991,7 @@ function textOf(args) {
|
|
|
28576
28991
|
}
|
|
28577
28992
|
function sourceOf(args) {
|
|
28578
28993
|
if (args.from && args.id) throw new UsageError("pass --from <record.talk.json> or --id <character id>, not both");
|
|
28579
|
-
if (args.from && !
|
|
28994
|
+
if (args.from && !existsSync46(args.from)) throw new UsageError(`${args.from} does not exist; --from is the .talk.json record talk visemes wrote`);
|
|
28580
28995
|
return { record: args.from, characterId: args.id };
|
|
28581
28996
|
}
|
|
28582
28997
|
async function runVisemes(args) {
|
|
@@ -28592,9 +29007,9 @@ async function runVisemes(args) {
|
|
|
28592
29007
|
const paths = talkOutputPaths(args.out);
|
|
28593
29008
|
let side = "unknown";
|
|
28594
29009
|
if (args.from) {
|
|
28595
|
-
if (!
|
|
29010
|
+
if (!existsSync46(args.from)) throw new UsageError(`${args.from} does not exist`);
|
|
28596
29011
|
try {
|
|
28597
|
-
side = readPortrait(await
|
|
29012
|
+
side = readPortrait(await readFile40(args.from), args.from).side;
|
|
28598
29013
|
} catch (error) {
|
|
28599
29014
|
throw new UsageError(error instanceof Error ? error.message : String(error));
|
|
28600
29015
|
}
|
|
@@ -28677,10 +29092,10 @@ async function runPlan2(args) {
|
|
|
28677
29092
|
log(json.trimEnd());
|
|
28678
29093
|
return;
|
|
28679
29094
|
}
|
|
28680
|
-
const out =
|
|
28681
|
-
if (
|
|
28682
|
-
await
|
|
28683
|
-
await
|
|
29095
|
+
const out = path59.extname(args.out) ? path59.resolve(args.out) : path59.resolve(`${args.out}.json`);
|
|
29096
|
+
if (existsSync46(out) && !args.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
29097
|
+
await mkdir22(path59.dirname(out), { recursive: true });
|
|
29098
|
+
await writeFile27(out, json);
|
|
28684
29099
|
if (args.json) log(json.trimEnd());
|
|
28685
29100
|
else log(` wrote ${out} (${plan.frames.length} frames, ${(plan.totalMs / 1e3).toFixed(2)} s, free)`);
|
|
28686
29101
|
}
|
|
@@ -28691,19 +29106,19 @@ async function runTalk(args) {
|
|
|
28691
29106
|
}
|
|
28692
29107
|
|
|
28693
29108
|
// src/cli/commands/quality.ts
|
|
28694
|
-
import
|
|
28695
|
-
import { readFile as
|
|
29109
|
+
import path61 from "path";
|
|
29110
|
+
import { readFile as readFile42 } from "fs/promises";
|
|
28696
29111
|
|
|
28697
29112
|
// src/pipeline/quality-regression.ts
|
|
28698
|
-
import
|
|
28699
|
-
import { existsSync as
|
|
28700
|
-
import { readFile as
|
|
29113
|
+
import path60 from "path";
|
|
29114
|
+
import { existsSync as existsSync47 } from "fs";
|
|
29115
|
+
import { readFile as readFile41 } from "fs/promises";
|
|
28701
29116
|
import { z as z14 } from "zod";
|
|
28702
29117
|
var SHA256_RE = /^[0-9a-f]{64}$/;
|
|
28703
29118
|
var HEX_RE = /^#[0-9a-f]{6}$/;
|
|
28704
29119
|
var MAX_REDMEAN_DISTANCE = 765;
|
|
28705
29120
|
var QualityPathSchema = z14.string().min(1).refine(
|
|
28706
|
-
(value) => !
|
|
29121
|
+
(value) => !path60.posix.isAbsolute(value) && !value.includes("\\"),
|
|
28707
29122
|
"expected a portable relative path"
|
|
28708
29123
|
);
|
|
28709
29124
|
var DEFAULT_QUALITY_TOLERANCES = {
|
|
@@ -28850,10 +29265,10 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
28850
29265
|
};
|
|
28851
29266
|
}
|
|
28852
29267
|
async function measureImageQuality(file) {
|
|
28853
|
-
const absolute =
|
|
29268
|
+
const absolute = path60.resolve(file);
|
|
28854
29269
|
let bytes;
|
|
28855
29270
|
try {
|
|
28856
|
-
bytes = await
|
|
29271
|
+
bytes = await readFile41(absolute);
|
|
28857
29272
|
} catch (error) {
|
|
28858
29273
|
throw new Error(`Cannot read quality image ${absolute}: ${message4(error)}`, { cause: error });
|
|
28859
29274
|
}
|
|
@@ -28872,11 +29287,11 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
28872
29287
|
}
|
|
28873
29288
|
const ids = parsed.data.map((entry) => entry.id);
|
|
28874
29289
|
if (new Set(ids).size !== ids.length) throw new Error("--inputs contains a duplicate quality case id.");
|
|
28875
|
-
const root =
|
|
29290
|
+
const root = path60.dirname(path60.resolve(inputsFilePath));
|
|
28876
29291
|
return parsed.data.map((entry) => ({
|
|
28877
29292
|
id: entry.id,
|
|
28878
|
-
file:
|
|
28879
|
-
...entry.record ? { record:
|
|
29293
|
+
file: path60.resolve(root, entry.path),
|
|
29294
|
+
...entry.record ? { record: path60.resolve(root, entry.record) } : {},
|
|
28880
29295
|
tolerances: QualityToleranceSchema.parse({
|
|
28881
29296
|
...DEFAULT_QUALITY_TOLERANCES,
|
|
28882
29297
|
...entry.tolerances
|
|
@@ -28884,7 +29299,7 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
28884
29299
|
}));
|
|
28885
29300
|
}
|
|
28886
29301
|
function portableRelative2(from, to) {
|
|
28887
|
-
return
|
|
29302
|
+
return path60.relative(from, path60.resolve(to)).split(path60.sep).join("/") || ".";
|
|
28888
29303
|
}
|
|
28889
29304
|
async function verifyRecordForImage(recordPath, imagePath) {
|
|
28890
29305
|
const verification = await verifyArtifactBundle(recordPath);
|
|
@@ -28899,20 +29314,20 @@ async function verifyRecordForImage(recordPath, imagePath) {
|
|
|
28899
29314
|
if (record.kind !== "refine" || options === null || typeof options !== "object" || options.schema !== "pixelkiln-quality") {
|
|
28900
29315
|
throw new Error(`Quality record ${recordPath} is not a PixelKiln refinement record.`);
|
|
28901
29316
|
}
|
|
28902
|
-
const outputs = record.outputs.map((output) =>
|
|
28903
|
-
if (!outputs.includes(
|
|
29317
|
+
const outputs = record.outputs.map((output) => path60.resolve(path60.dirname(recordPath), output.path));
|
|
29318
|
+
if (!outputs.includes(path60.resolve(imagePath))) {
|
|
28904
29319
|
throw new Error(`Quality record ${recordPath} does not own ${imagePath}.`);
|
|
28905
29320
|
}
|
|
28906
29321
|
}
|
|
28907
29322
|
async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
28908
29323
|
if (!inputs.length) throw new Error("Cannot snapshot an empty quality baseline.");
|
|
28909
|
-
const absolute =
|
|
29324
|
+
const absolute = path60.resolve(baselinePath);
|
|
28910
29325
|
for (const input of inputs) {
|
|
28911
|
-
if (
|
|
29326
|
+
if (path60.resolve(input.file) === absolute || input.record && path60.resolve(input.record) === absolute) {
|
|
28912
29327
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
28913
29328
|
}
|
|
28914
29329
|
}
|
|
28915
|
-
const root =
|
|
29330
|
+
const root = path60.dirname(absolute);
|
|
28916
29331
|
const cases = [];
|
|
28917
29332
|
for (const input of [...inputs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
28918
29333
|
const expected = await measureImageQuality(input.file);
|
|
@@ -28939,8 +29354,8 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
28939
29354
|
cases
|
|
28940
29355
|
});
|
|
28941
29356
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
28942
|
-
if (
|
|
28943
|
-
const current = await
|
|
29357
|
+
if (existsSync47(absolute) && !options.force) {
|
|
29358
|
+
const current = await readFile41(absolute);
|
|
28944
29359
|
if (!current.equals(data)) {
|
|
28945
29360
|
throw new OverwriteRefusedError(
|
|
28946
29361
|
`Quality baseline already exists with different content: ${absolute}. Pass --force to replace it.`,
|
|
@@ -28952,13 +29367,13 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
28952
29367
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
28953
29368
|
}
|
|
28954
29369
|
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
28955
|
-
const absolute =
|
|
28956
|
-
if (!
|
|
29370
|
+
const absolute = path60.resolve(baselinePath);
|
|
29371
|
+
if (!existsSync47(absolute)) {
|
|
28957
29372
|
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
28958
29373
|
}
|
|
28959
29374
|
let raw;
|
|
28960
29375
|
try {
|
|
28961
|
-
raw = JSON.parse(await
|
|
29376
|
+
raw = JSON.parse(await readFile41(absolute, "utf8"));
|
|
28962
29377
|
} catch (error) {
|
|
28963
29378
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
28964
29379
|
}
|
|
@@ -28968,12 +29383,12 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
28968
29383
|
if (unknown.length) {
|
|
28969
29384
|
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
28970
29385
|
}
|
|
28971
|
-
const root =
|
|
29386
|
+
const root = path60.dirname(absolute);
|
|
28972
29387
|
const cases = [...raw.cases];
|
|
28973
29388
|
const report = [];
|
|
28974
29389
|
for (const id of only) {
|
|
28975
29390
|
const input = byId.get(id);
|
|
28976
|
-
if (
|
|
29391
|
+
if (path60.resolve(input.file) === absolute || input.record && path60.resolve(input.record) === absolute) {
|
|
28977
29392
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
28978
29393
|
}
|
|
28979
29394
|
const expected = await measureImageQuality(input.file);
|
|
@@ -29003,16 +29418,16 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
29003
29418
|
}
|
|
29004
29419
|
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
29005
29420
|
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
29006
|
-
const current = await
|
|
29421
|
+
const current = await readFile41(absolute);
|
|
29007
29422
|
const changed = !current.equals(data);
|
|
29008
29423
|
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
29009
29424
|
return { baseline, path: absolute, changed, cases: report };
|
|
29010
29425
|
}
|
|
29011
29426
|
async function readQualityBaseline(baselinePath) {
|
|
29012
|
-
const absolute =
|
|
29427
|
+
const absolute = path60.resolve(baselinePath);
|
|
29013
29428
|
let raw;
|
|
29014
29429
|
try {
|
|
29015
|
-
raw = JSON.parse(await
|
|
29430
|
+
raw = JSON.parse(await readFile41(absolute, "utf8"));
|
|
29016
29431
|
} catch (error) {
|
|
29017
29432
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
29018
29433
|
}
|
|
@@ -29034,7 +29449,7 @@ async function readQualityBaseline(baselinePath) {
|
|
|
29034
29449
|
throw new Error(
|
|
29035
29450
|
`Invalid quality baseline ${absolute}:
|
|
29036
29451
|
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
29037
|
-
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${
|
|
29452
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path60.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
29038
29453
|
);
|
|
29039
29454
|
}
|
|
29040
29455
|
return parsed.data;
|
|
@@ -29096,12 +29511,12 @@ function regressionViolations(expected, actual, tolerances) {
|
|
|
29096
29511
|
return { violations, warnings };
|
|
29097
29512
|
}
|
|
29098
29513
|
async function checkQualityBaseline(baselinePath) {
|
|
29099
|
-
const absolute =
|
|
29514
|
+
const absolute = path60.resolve(baselinePath);
|
|
29100
29515
|
const baseline = await readQualityBaseline(absolute);
|
|
29101
|
-
const root =
|
|
29516
|
+
const root = path60.dirname(absolute);
|
|
29102
29517
|
const cases = [];
|
|
29103
29518
|
for (const entry of baseline.cases) {
|
|
29104
|
-
const file =
|
|
29519
|
+
const file = path60.resolve(root, entry.file);
|
|
29105
29520
|
let actual = null;
|
|
29106
29521
|
const violations = [];
|
|
29107
29522
|
const warnings = [];
|
|
@@ -29114,7 +29529,7 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
29114
29529
|
violations.push(message4(error));
|
|
29115
29530
|
}
|
|
29116
29531
|
if (entry.record) {
|
|
29117
|
-
const recordPath =
|
|
29532
|
+
const recordPath = path60.resolve(root, entry.record.path);
|
|
29118
29533
|
try {
|
|
29119
29534
|
const recordHash = await sha256File(recordPath);
|
|
29120
29535
|
if (recordHash !== entry.record.sha256) violations.push("quality record hash changed");
|
|
@@ -29156,15 +29571,15 @@ async function runQuality(args) {
|
|
|
29156
29571
|
if (!args.out) throw new Error("quality snapshot needs --out <pixelkiln.quality.json>.");
|
|
29157
29572
|
let raw;
|
|
29158
29573
|
try {
|
|
29159
|
-
raw = JSON.parse(await
|
|
29574
|
+
raw = JSON.parse(await readFile42(path61.resolve(args.inputs), "utf8"));
|
|
29160
29575
|
} catch (error) {
|
|
29161
29576
|
throw new Error(
|
|
29162
|
-
`Could not read quality inputs ${
|
|
29577
|
+
`Could not read quality inputs ${path61.resolve(args.inputs)}: ${error instanceof Error ? error.message : String(error)}`,
|
|
29163
29578
|
{ cause: error }
|
|
29164
29579
|
);
|
|
29165
29580
|
}
|
|
29166
29581
|
const inputs = resolveQualityInputs(raw, args.inputs);
|
|
29167
|
-
if (
|
|
29582
|
+
if (path61.resolve(args.inputs) === path61.resolve(args.out)) {
|
|
29168
29583
|
throw new Error("quality snapshot --out must not overwrite its --inputs file.");
|
|
29169
29584
|
}
|
|
29170
29585
|
if (args.assets.length) {
|
|
@@ -29179,7 +29594,7 @@ async function runQuality(args) {
|
|
|
29179
29594
|
}
|
|
29180
29595
|
log(
|
|
29181
29596
|
`
|
|
29182
|
-
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${
|
|
29597
|
+
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${path61.relative(process.cwd(), result2.path)}; other cases left as they were.`
|
|
29183
29598
|
);
|
|
29184
29599
|
return;
|
|
29185
29600
|
}
|
|
@@ -29194,7 +29609,7 @@ async function runQuality(args) {
|
|
|
29194
29609
|
}, null, 2));
|
|
29195
29610
|
} else {
|
|
29196
29611
|
log(
|
|
29197
|
-
` ${result.changed ? "wrote" : "unchanged"} ${
|
|
29612
|
+
` ${result.changed ? "wrote" : "unchanged"} ${path61.relative(process.cwd(), result.path)} (${result.baseline.cases.length} case(s))`
|
|
29198
29613
|
);
|
|
29199
29614
|
log(` Review the tolerances, commit the baseline, then run quality check in CI.`);
|
|
29200
29615
|
}
|
|
@@ -29220,12 +29635,12 @@ async function runQuality(args) {
|
|
|
29220
29635
|
}
|
|
29221
29636
|
|
|
29222
29637
|
// src/cli/commands/recipe.ts
|
|
29223
|
-
import
|
|
29638
|
+
import path63 from "path";
|
|
29224
29639
|
|
|
29225
29640
|
// src/recipes.ts
|
|
29226
|
-
import
|
|
29227
|
-
import { existsSync as
|
|
29228
|
-
import { readdir as readdir4, readFile as
|
|
29641
|
+
import path62 from "path";
|
|
29642
|
+
import { existsSync as existsSync48 } from "fs";
|
|
29643
|
+
import { readdir as readdir4, readFile as readFile43 } from "fs/promises";
|
|
29229
29644
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
29230
29645
|
import { z as z15 } from "zod";
|
|
29231
29646
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
@@ -29234,7 +29649,7 @@ var VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
|
29234
29649
|
var RECIPE_FILE = "pixelkiln.recipe.json";
|
|
29235
29650
|
var RECIPE_DIR_TOKEN = "{{recipeDir}}";
|
|
29236
29651
|
var PortablePathSchema = z15.string().min(1).refine((value) => {
|
|
29237
|
-
if (value.includes("\\") ||
|
|
29652
|
+
if (value.includes("\\") || path62.posix.isAbsolute(value)) return false;
|
|
29238
29653
|
const parts = value.split("/");
|
|
29239
29654
|
return !parts.includes("") && !parts.includes(".") && !parts.includes("..");
|
|
29240
29655
|
}, "expected a portable relative path without '.', '..', or backslashes");
|
|
@@ -29410,10 +29825,10 @@ function message5(error) {
|
|
|
29410
29825
|
return error instanceof Error ? error.message : String(error);
|
|
29411
29826
|
}
|
|
29412
29827
|
async function readRecipeFile(recipePath, bundled) {
|
|
29413
|
-
const absolute =
|
|
29828
|
+
const absolute = path62.resolve(recipePath);
|
|
29414
29829
|
let raw;
|
|
29415
29830
|
try {
|
|
29416
|
-
raw = JSON.parse(await
|
|
29831
|
+
raw = JSON.parse(await readFile43(absolute, "utf8"));
|
|
29417
29832
|
} catch (error) {
|
|
29418
29833
|
throw new Error(`Could not read recipe ${absolute}: ${message5(error)}`, { cause: error });
|
|
29419
29834
|
}
|
|
@@ -29424,13 +29839,13 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
29424
29839
|
` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
|
|
29425
29840
|
);
|
|
29426
29841
|
}
|
|
29427
|
-
return { recipe: parsed.data, authored: raw, path: absolute, dir:
|
|
29842
|
+
return { recipe: parsed.data, authored: raw, path: absolute, dir: path62.dirname(absolute), bundled };
|
|
29428
29843
|
}
|
|
29429
29844
|
async function walkRecipeFiles(root) {
|
|
29430
|
-
if (!
|
|
29845
|
+
if (!existsSync48(root)) return [];
|
|
29431
29846
|
const out = [];
|
|
29432
29847
|
for (const entry of await readdir4(root, { withFileTypes: true })) {
|
|
29433
|
-
const resolved =
|
|
29848
|
+
const resolved = path62.join(root, entry.name);
|
|
29434
29849
|
if (entry.isDirectory()) out.push(...await walkRecipeFiles(resolved));
|
|
29435
29850
|
else if (entry.isFile() && entry.name === RECIPE_FILE) out.push(resolved);
|
|
29436
29851
|
}
|
|
@@ -29441,7 +29856,7 @@ function bundledRecipeRoot() {
|
|
|
29441
29856
|
}
|
|
29442
29857
|
async function listBundledRecipes(root = bundledRecipeRoot()) {
|
|
29443
29858
|
const recipes = await Promise.all(
|
|
29444
|
-
(await walkRecipeFiles(
|
|
29859
|
+
(await walkRecipeFiles(path62.resolve(root))).map((file) => readRecipeFile(file, true))
|
|
29445
29860
|
);
|
|
29446
29861
|
return recipes.sort(
|
|
29447
29862
|
(a, b) => a.recipe.id.localeCompare(b.recipe.id) || compareVersions(b.recipe.version, a.recipe.version)
|
|
@@ -29464,9 +29879,9 @@ function parseSelector(selector) {
|
|
|
29464
29879
|
return { id: match[1], version: match[2] };
|
|
29465
29880
|
}
|
|
29466
29881
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
29467
|
-
const local =
|
|
29468
|
-
if (
|
|
29469
|
-
const recipePath =
|
|
29882
|
+
const local = path62.resolve(target);
|
|
29883
|
+
if (existsSync48(local)) {
|
|
29884
|
+
const recipePath = path62.basename(local) === RECIPE_FILE ? local : path62.join(local, RECIPE_FILE);
|
|
29470
29885
|
return readRecipeFile(recipePath, false);
|
|
29471
29886
|
}
|
|
29472
29887
|
if (target.startsWith(".") || target.startsWith("/") || target.includes("\\")) {
|
|
@@ -29480,8 +29895,8 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
29480
29895
|
return matches[0];
|
|
29481
29896
|
}
|
|
29482
29897
|
async function verifyFile(root, file) {
|
|
29483
|
-
const absolute =
|
|
29484
|
-
if (!
|
|
29898
|
+
const absolute = path62.resolve(root, ...file.path.split("/"));
|
|
29899
|
+
if (!existsSync48(absolute)) {
|
|
29485
29900
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
29486
29901
|
}
|
|
29487
29902
|
const actualSha256 = await sha256File(absolute);
|
|
@@ -29496,7 +29911,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
29496
29911
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
29497
29912
|
const actualIntegrity = recipeDigest(loaded.authored);
|
|
29498
29913
|
const files = await Promise.all(loaded.recipe.files.map((file) => verifyFile(loaded.dir, file)));
|
|
29499
|
-
const modelRoot = options.modelRoot ?
|
|
29914
|
+
const modelRoot = options.modelRoot ? path62.resolve(options.modelRoot) : null;
|
|
29500
29915
|
const models = modelRoot ? await Promise.all(loaded.recipe.models.map(async (model) => ({
|
|
29501
29916
|
...await verifyFile(modelRoot, model),
|
|
29502
29917
|
source: model.source,
|
|
@@ -29530,7 +29945,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
29530
29945
|
};
|
|
29531
29946
|
}
|
|
29532
29947
|
function renderStyle(style, destination, cwd) {
|
|
29533
|
-
const portableDir =
|
|
29948
|
+
const portableDir = path62.relative(cwd, destination).split(path62.sep).join("/") || ".";
|
|
29534
29949
|
const replace = (value) => {
|
|
29535
29950
|
if (typeof value === "string") return value.replaceAll(RECIPE_DIR_TOKEN, portableDir);
|
|
29536
29951
|
if (Array.isArray(value)) return value.map(replace);
|
|
@@ -29542,25 +29957,25 @@ function renderStyle(style, destination, cwd) {
|
|
|
29542
29957
|
return replace(style);
|
|
29543
29958
|
}
|
|
29544
29959
|
async function installRecipe(target, options = {}) {
|
|
29545
|
-
const cwd =
|
|
29960
|
+
const cwd = path62.resolve(options.cwd ?? process.cwd());
|
|
29546
29961
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
29547
29962
|
const verification = await verifyRecipe(loaded.path);
|
|
29548
29963
|
if (!verification.ok) {
|
|
29549
29964
|
throw new Error(`Recipe ${loaded.recipe.id}@${loaded.recipe.version} failed integrity verification.`);
|
|
29550
29965
|
}
|
|
29551
|
-
const destination = options.out ?
|
|
29966
|
+
const destination = options.out ? path62.resolve(cwd, options.out) : path62.join(cwd, "pixelkiln-recipes", ...loaded.recipe.id.split("/"), loaded.recipe.version);
|
|
29552
29967
|
const sources = [
|
|
29553
29968
|
{ path: RECIPE_FILE, source: loaded.path },
|
|
29554
|
-
...loaded.recipe.files.map((file) => ({ path: file.path, source:
|
|
29969
|
+
...loaded.recipe.files.map((file) => ({ path: file.path, source: path62.join(loaded.dir, ...file.path.split("/")) }))
|
|
29555
29970
|
];
|
|
29556
29971
|
const files = await Promise.all(sources.map(async (file) => ({
|
|
29557
|
-
path:
|
|
29558
|
-
data: await
|
|
29972
|
+
path: path62.join(destination, ...file.path.split("/")),
|
|
29973
|
+
data: await readFile43(file.source)
|
|
29559
29974
|
})));
|
|
29560
29975
|
if (!options.force) {
|
|
29561
29976
|
for (const file of files) {
|
|
29562
|
-
if (!
|
|
29563
|
-
const current = await
|
|
29977
|
+
if (!existsSync48(file.path)) continue;
|
|
29978
|
+
const current = await readFile43(file.path);
|
|
29564
29979
|
if (!current.equals(file.data)) {
|
|
29565
29980
|
throw new OverwriteRefusedError(
|
|
29566
29981
|
`Recipe destination has local changes: ${file.path}. Choose another --out or pass --force to replace declared recipe files.`,
|
|
@@ -29654,14 +30069,14 @@ async function runRecipe(args) {
|
|
|
29654
30069
|
}, null, 2));
|
|
29655
30070
|
} else {
|
|
29656
30071
|
log(` installed ${result.recipe.id}@${result.recipe.version}`);
|
|
29657
|
-
log(` ${
|
|
30072
|
+
log(` ${path63.relative(process.cwd(), result.destination) || "."}`);
|
|
29658
30073
|
log(`
|
|
29659
30074
|
Add this entry under your manifest's styles object:`);
|
|
29660
30075
|
log(JSON.stringify({ [result.styleId]: result.style }, null, 2));
|
|
29661
30076
|
if (result.recipe.models.length) {
|
|
29662
30077
|
log(`
|
|
29663
30078
|
Models are not downloaded automatically. Verify them with:`);
|
|
29664
|
-
log(` pixelkiln recipe verify ${
|
|
30079
|
+
log(` pixelkiln recipe verify ${path63.relative(process.cwd(), result.destination)} --model-root <ComfyUI/models>`);
|
|
29665
30080
|
}
|
|
29666
30081
|
}
|
|
29667
30082
|
return;
|
|
@@ -29669,7 +30084,7 @@ async function runRecipe(args) {
|
|
|
29669
30084
|
}
|
|
29670
30085
|
|
|
29671
30086
|
// src/cli/commands/refine.ts
|
|
29672
|
-
import
|
|
30087
|
+
import path64 from "path";
|
|
29673
30088
|
async function runRefine(args) {
|
|
29674
30089
|
if (args.from || args.subcommand === "approve") {
|
|
29675
30090
|
if (!args.from) {
|
|
@@ -29699,12 +30114,12 @@ async function runRefine(args) {
|
|
|
29699
30114
|
` recovered ${result3.detection.columns}x${result3.detection.rows} native grid (${result3.detection.confidence}: ${result3.detection.consensus})`
|
|
29700
30115
|
);
|
|
29701
30116
|
log(` enforced ${result3.palette.length}-color palette without dithering`);
|
|
29702
|
-
log(` wrote ${
|
|
29703
|
-
log(` quality record: ${
|
|
30117
|
+
log(` wrote ${path64.relative(process.cwd(), result3.output)}`);
|
|
30118
|
+
log(` quality record: ${path64.relative(process.cwd(), result3.record)}`);
|
|
29704
30119
|
log(`
|
|
29705
30120
|
Automated checks passed. Human 1\xD7 review is still required:`);
|
|
29706
30121
|
log(
|
|
29707
|
-
` pixelkiln refine approve --from ${
|
|
30122
|
+
` pixelkiln refine approve --from ${path64.relative(process.cwd(), result3.record)} --reviewer "Your Name"`
|
|
29708
30123
|
);
|
|
29709
30124
|
}
|
|
29710
30125
|
return;
|
|
@@ -29732,7 +30147,7 @@ async function runRefine(args) {
|
|
|
29732
30147
|
if (args.json) log(JSON.stringify(result3, null, 2));
|
|
29733
30148
|
else {
|
|
29734
30149
|
log(
|
|
29735
|
-
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${
|
|
30150
|
+
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${path64.relative(process.cwd(), result3.record)} by ${args.reviewer.trim()}` : ` approved ${path64.relative(process.cwd(), result3.output)} by ${args.reviewer.trim()}`
|
|
29736
30151
|
);
|
|
29737
30152
|
}
|
|
29738
30153
|
return;
|
|
@@ -29741,7 +30156,7 @@ async function runRefine(args) {
|
|
|
29741
30156
|
if (args.json) {
|
|
29742
30157
|
log(JSON.stringify(result2, null, 2));
|
|
29743
30158
|
} else {
|
|
29744
|
-
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${
|
|
30159
|
+
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${path64.relative(process.cwd(), result2.output || result2.record)}`);
|
|
29745
30160
|
for (const reason of result2.reasons) log(` ${reason}`);
|
|
29746
30161
|
}
|
|
29747
30162
|
if (!result2.safe) process.exitCode = 1;
|
|
@@ -29787,7 +30202,7 @@ async function runRefine(args) {
|
|
|
29787
30202
|
log(` ${item.state.padEnd(16)} ${item.key} ${item.reason}`);
|
|
29788
30203
|
if (item.state === "needs-approval") {
|
|
29789
30204
|
log(
|
|
29790
|
-
` pixelkiln refine approve --from ${
|
|
30205
|
+
` pixelkiln refine approve --from ${path64.relative(process.cwd(), item.record)} --reviewer "Your Name"`
|
|
29791
30206
|
);
|
|
29792
30207
|
}
|
|
29793
30208
|
}
|
|
@@ -29798,7 +30213,7 @@ async function runRefine(args) {
|
|
|
29798
30213
|
}
|
|
29799
30214
|
|
|
29800
30215
|
// src/cli/commands/anchors.ts
|
|
29801
|
-
import
|
|
30216
|
+
import path65 from "path";
|
|
29802
30217
|
async function runAnchors(args) {
|
|
29803
30218
|
const target = args.target;
|
|
29804
30219
|
const { specs, lock } = await openProject2(args);
|
|
@@ -29819,7 +30234,7 @@ async function runAnchors(args) {
|
|
|
29819
30234
|
dryRun: args.dryRun,
|
|
29820
30235
|
onProgress: log
|
|
29821
30236
|
});
|
|
29822
|
-
const file =
|
|
30237
|
+
const file = path65.relative(spec.root, result.file) || result.file;
|
|
29823
30238
|
if (args.dryRun) {
|
|
29824
30239
|
log(` ${result.estimated} frame${result.estimated === 1 ? "" : "s"} to estimate (about ${cost(result.estimated)}), ${result.current} already current`);
|
|
29825
30240
|
} else if (result.estimated) {
|
|
@@ -29831,12 +30246,12 @@ async function runAnchors(args) {
|
|
|
29831
30246
|
}
|
|
29832
30247
|
|
|
29833
30248
|
// src/cli/commands/redraw.ts
|
|
29834
|
-
import
|
|
30249
|
+
import path67 from "path";
|
|
29835
30250
|
|
|
29836
30251
|
// src/pipeline/redraw.ts
|
|
29837
|
-
import { existsSync as
|
|
29838
|
-
import { mkdir as
|
|
29839
|
-
import
|
|
30252
|
+
import { existsSync as existsSync49 } from "fs";
|
|
30253
|
+
import { mkdir as mkdir23, readFile as readFile44, rename as rename13, writeFile as writeFile28 } from "fs/promises";
|
|
30254
|
+
import path66 from "path";
|
|
29840
30255
|
function redrawRoles(spec, lock) {
|
|
29841
30256
|
return (lock.entries[lockKey(spec.styleId, spec.assetId)]?.outputs ?? []).map((output) => output.role ?? "");
|
|
29842
30257
|
}
|
|
@@ -29878,7 +30293,7 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
29878
30293
|
const still = source.spec.character?.kind !== "animation";
|
|
29879
30294
|
for (const [index, output] of sourceEntry.outputs.entries()) {
|
|
29880
30295
|
if (!still && !owners.includes(source.assetId)) continue;
|
|
29881
|
-
const png = await
|
|
30296
|
+
const png = await readFile44(currentEntryOutputPath(sourceEntry, source.spec, index));
|
|
29882
30297
|
if (still) stills.push(png);
|
|
29883
30298
|
if (!owners.includes(source.assetId)) continue;
|
|
29884
30299
|
const role = output.role ?? String(index).padStart(2, "0");
|
|
@@ -29912,23 +30327,23 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
29912
30327
|
continue;
|
|
29913
30328
|
}
|
|
29914
30329
|
const file = at2 >= 0 ? currentEntryOutputPath(entry, spec, at2) : null;
|
|
29915
|
-
if (!file || !
|
|
30330
|
+
if (!file || !existsSync49(file)) {
|
|
29916
30331
|
layers.push(null);
|
|
29917
30332
|
continue;
|
|
29918
30333
|
}
|
|
29919
30334
|
const pair = offset?.per && offset.per[source.assetId] || offset;
|
|
29920
|
-
const png = await
|
|
30335
|
+
const png = await readFile44(file);
|
|
29921
30336
|
layers.push(pair ? shiftPixels(png, -pair.x, -pair.y).png : png);
|
|
29922
30337
|
}
|
|
29923
30338
|
const prepared = redrawSheet(built, layers, redraw);
|
|
29924
30339
|
const size = decodePng(prepared.keyed);
|
|
29925
30340
|
const cost = proTierCost(size.width, size.height);
|
|
29926
|
-
const workDir =
|
|
30341
|
+
const workDir = path66.join(layerWorkDir(spec), "redraw");
|
|
29927
30342
|
const result = { roles, guides, sheet: { width: size.width, height: size.height }, cost, billed: null, written: [], workDir };
|
|
29928
30343
|
if (opts.dryRun) return result;
|
|
29929
|
-
await
|
|
29930
|
-
await
|
|
29931
|
-
await
|
|
30344
|
+
await mkdir23(workDir, { recursive: true });
|
|
30345
|
+
await writeFile28(path66.join(workDir, "keyed.png"), prepared.keyed);
|
|
30346
|
+
await writeFile28(path66.join(workDir, "mask.png"), prepared.mask);
|
|
29932
30347
|
const count = roles.length;
|
|
29933
30348
|
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"}.`;
|
|
29934
30349
|
const jobId = await painter.paintSheet({ description, keyed: prepared.keyed, mask: prepared.mask, seed: opts.seed ?? spec.seed });
|
|
@@ -29946,13 +30361,13 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
29946
30361
|
if (Date.now() > deadline) throw new Error(`${label}: redraw job ${jobId} did not finish in time; nothing was changed`);
|
|
29947
30362
|
await new Promise((resolve) => setTimeout(resolve, opts.pollMs ?? 3e3));
|
|
29948
30363
|
}
|
|
29949
|
-
await
|
|
30364
|
+
await writeFile28(path66.join(workDir, "result.png"), painted);
|
|
29950
30365
|
const returned = decodePng(painted);
|
|
29951
30366
|
if (returned.width !== size.width || returned.height !== size.height) {
|
|
29952
30367
|
throw new Error(`${label}: redraw job ${jobId} returned a ${returned.width}x${returned.height} image for a ${size.width}x${size.height} sheet`);
|
|
29953
30368
|
}
|
|
29954
30369
|
const cut = cutLayerFrames(painted, { keyed: prepared.keyed, mask: prepared.mask, frames: built.frames }, { key: layer.key, region: layer.region });
|
|
29955
|
-
const cacheDir =
|
|
30370
|
+
const cacheDir = path66.resolve(opts.cacheDir ?? path66.join(path66.dirname(opts.lockPath), ".pixelkiln", "cache"));
|
|
29956
30371
|
const outputs = [...entry.outputs];
|
|
29957
30372
|
const renames = [];
|
|
29958
30373
|
for (const [index, at2] of targets) {
|
|
@@ -29961,12 +30376,12 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
29961
30376
|
const empty = !decodePng(raw).pixels.some((value, i) => i % 4 === 3 && value > 0);
|
|
29962
30377
|
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`);
|
|
29963
30378
|
const target = currentEntryOutputPath(entry, spec, at2);
|
|
29964
|
-
if (
|
|
30379
|
+
if (existsSync49(target)) await cacheMedia(cacheDir, await readFile44(target), MediaType.PNG);
|
|
29965
30380
|
await cacheMedia(cacheDir, raw, MediaType.PNG);
|
|
29966
30381
|
const processed = applyPostprocess(raw, MediaType.PNG, entry.postprocess, [], role);
|
|
29967
30382
|
await cacheMedia(cacheDir, processed.bytes, MediaType.PNG);
|
|
29968
30383
|
const tmp = `${target}.pixelkiln.tmp`;
|
|
29969
|
-
await
|
|
30384
|
+
await writeFile28(tmp, processed.bytes);
|
|
29970
30385
|
renames.push([tmp, target]);
|
|
29971
30386
|
const { raw: _raw, ...kept } = outputs[at2];
|
|
29972
30387
|
outputs[at2] = { ...kept, sha256: sha256(processed.bytes), ...processed.changed ? { raw: sha256(raw) } : {} };
|
|
@@ -30010,7 +30425,7 @@ async function runRedraw(args) {
|
|
|
30010
30425
|
const painter = args.dryRun ? { paintSheet: never, paintedSheet: never } : new PixelLabProvider(clientFromEnv());
|
|
30011
30426
|
const result = await redrawLayerFrames(spec, project.lock, painter, {
|
|
30012
30427
|
frames: args.redrawFrames,
|
|
30013
|
-
lockPath:
|
|
30428
|
+
lockPath: path67.resolve(args.lock),
|
|
30014
30429
|
seed: args.seed,
|
|
30015
30430
|
dryRun: args.dryRun,
|
|
30016
30431
|
onProgress: log
|
|
@@ -30021,16 +30436,16 @@ async function runRedraw(args) {
|
|
|
30021
30436
|
log(` would redraw ${frames} (${result.roles.join(", ")}) beside ${result.guides} dressed, on a ${sheet} sheet: about ${result.cost} generations`);
|
|
30022
30437
|
return;
|
|
30023
30438
|
}
|
|
30024
|
-
for (const file of result.written) log(` wrote ${
|
|
30439
|
+
for (const file of result.written) log(` wrote ${path67.relative(process.cwd(), file)}`);
|
|
30025
30440
|
const billed = result.billed ? `${result.billed.amount} ${result.billed.unit} billed` : `about ${result.cost} generations`;
|
|
30026
|
-
log(` redrew ${frames} of ${target} (${billed}); the sheet and result are in ${
|
|
30441
|
+
log(` redrew ${frames} of ${target} (${billed}); the sheet and result are in ${path67.relative(process.cwd(), result.workDir)}`);
|
|
30027
30442
|
log(` look at ${result.written.length === 1 ? "it" : "them"}, then run pixelkiln gen to rebuild anything made from this layer`);
|
|
30028
30443
|
}
|
|
30029
30444
|
|
|
30030
30445
|
// src/cli/commands/skeleton.ts
|
|
30031
|
-
import
|
|
30032
|
-
import { existsSync as
|
|
30033
|
-
import { readFile as
|
|
30446
|
+
import path68 from "path";
|
|
30447
|
+
import { existsSync as existsSync50 } from "fs";
|
|
30448
|
+
import { readFile as readFile45, writeFile as writeFile29 } from "fs/promises";
|
|
30034
30449
|
|
|
30035
30450
|
// src/skeleton-preview.ts
|
|
30036
30451
|
var RIGHT = [255, 140, 40, 255];
|
|
@@ -30141,12 +30556,12 @@ var Canvas = class {
|
|
|
30141
30556
|
async function runEstimateSkeleton(args) {
|
|
30142
30557
|
const image = args.target;
|
|
30143
30558
|
if (!image) throw new UsageError("estimate-skeleton needs an image path: pixelkiln estimate-skeleton <image> [--out keypoints.json]");
|
|
30144
|
-
if (args.out &&
|
|
30559
|
+
if (args.out && existsSync50(path68.resolve(args.out)) && !args.force) {
|
|
30145
30560
|
throw new UsageError(`${args.out} already exists; pass --force to replace it`);
|
|
30146
30561
|
}
|
|
30147
|
-
loadEnvFiles(
|
|
30562
|
+
loadEnvFiles(path68.dirname(path68.resolve(args.manifest)));
|
|
30148
30563
|
loadEnvFiles(process.cwd());
|
|
30149
|
-
const bytes = await
|
|
30564
|
+
const bytes = await readFile45(path68.resolve(image));
|
|
30150
30565
|
const metadata = imageMetadata(bytes);
|
|
30151
30566
|
if (!metadata) throw new UsageError(`${image} is not a readable PNG or JPEG`);
|
|
30152
30567
|
const sizeProblem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
|
|
@@ -30158,7 +30573,7 @@ async function runEstimateSkeleton(args) {
|
|
|
30158
30573
|
const frames = args.frames ?? DEFAULT_SCAFFOLD_FRAMES;
|
|
30159
30574
|
const json = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames), null, 2);
|
|
30160
30575
|
if (args.out) {
|
|
30161
|
-
await
|
|
30576
|
+
await writeFile29(path68.resolve(args.out), json + "\n");
|
|
30162
30577
|
log(` wrote ${args.out}: the estimated pose and ${frames} frames to edit`);
|
|
30163
30578
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
30164
30579
|
} else {
|
|
@@ -30171,8 +30586,8 @@ async function runSkeletonPreview(args) {
|
|
|
30171
30586
|
let sourceFile;
|
|
30172
30587
|
let label;
|
|
30173
30588
|
if (target.endsWith(".json")) {
|
|
30174
|
-
keypointsFile =
|
|
30175
|
-
sourceFile = args.from ?
|
|
30589
|
+
keypointsFile = path68.resolve(target);
|
|
30590
|
+
sourceFile = args.from ? path68.resolve(args.from) : void 0;
|
|
30176
30591
|
label = target;
|
|
30177
30592
|
} else {
|
|
30178
30593
|
const loaded = await loadManifest(args.manifest);
|
|
@@ -30184,31 +30599,31 @@ async function runSkeletonPreview(args) {
|
|
|
30184
30599
|
);
|
|
30185
30600
|
}
|
|
30186
30601
|
keypointsFile = spec.revision.keypointsFile;
|
|
30187
|
-
sourceFile = args.from ?
|
|
30602
|
+
sourceFile = args.from ? path68.resolve(args.from) : spec.revision.sourceFile;
|
|
30188
30603
|
label = `${spec.styleId}/${spec.assetId}`;
|
|
30189
30604
|
}
|
|
30190
|
-
if (!
|
|
30605
|
+
if (!existsSync50(keypointsFile)) throw new UsageError(`Keypoints file does not exist yet: ${keypointsFile}`);
|
|
30191
30606
|
let json;
|
|
30192
30607
|
try {
|
|
30193
|
-
json = JSON.parse(await
|
|
30608
|
+
json = JSON.parse(await readFile45(keypointsFile, "utf8"));
|
|
30194
30609
|
} catch (error) {
|
|
30195
30610
|
throw new UsageError(`${keypointsFile} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
30196
30611
|
}
|
|
30197
30612
|
const set = parseSkeletonSet(json, keypointsFile);
|
|
30198
30613
|
let source;
|
|
30199
30614
|
if (sourceFile) {
|
|
30200
|
-
if (!
|
|
30615
|
+
if (!existsSync50(sourceFile)) {
|
|
30201
30616
|
log(` source image does not exist yet, drawing on a plain ground: ${sourceFile}`);
|
|
30202
30617
|
} else {
|
|
30203
|
-
const bytes = await
|
|
30618
|
+
const bytes = await readFile45(sourceFile);
|
|
30204
30619
|
if (imageMetadata(bytes)?.format !== "png") throw new UsageError(`${sourceFile} must be a PNG to preview over`);
|
|
30205
30620
|
source = decodePng(bytes);
|
|
30206
30621
|
}
|
|
30207
30622
|
}
|
|
30208
|
-
const out =
|
|
30209
|
-
await
|
|
30623
|
+
const out = path68.resolve(args.out ?? keypointsFile.replace(/\.json$/, "") + ".preview.png");
|
|
30624
|
+
await writeFile29(out, renderSkeletonSheet(set, { source }));
|
|
30210
30625
|
log(` ${label}: ${set.frames.length} frames after the starting pose`);
|
|
30211
|
-
const shown =
|
|
30626
|
+
const shown = path68.relative(process.cwd(), out);
|
|
30212
30627
|
log(` wrote ${shown.startsWith("..") ? out : shown}`);
|
|
30213
30628
|
}
|
|
30214
30629
|
|
|
@@ -30254,15 +30669,15 @@ async function runTools(args) {
|
|
|
30254
30669
|
}
|
|
30255
30670
|
|
|
30256
30671
|
// src/cli/commands/workspace.ts
|
|
30257
|
-
import
|
|
30258
|
-
import { existsSync as
|
|
30672
|
+
import path69 from "path";
|
|
30673
|
+
import { existsSync as existsSync51 } from "fs";
|
|
30259
30674
|
async function runWorkspace(args) {
|
|
30260
|
-
const workspacePath =
|
|
30261
|
-
const dir =
|
|
30675
|
+
const workspacePath = path69.resolve(args.workspace ?? "pixelkiln.workspace.json");
|
|
30676
|
+
const dir = path69.dirname(workspacePath);
|
|
30262
30677
|
if (args.subcommand === "add") {
|
|
30263
|
-
const manifestPath =
|
|
30678
|
+
const manifestPath = path69.resolve(args.target);
|
|
30264
30679
|
const loadedTarget = await loadManifest(manifestPath);
|
|
30265
|
-
const lockPath = args.explicitLock ?
|
|
30680
|
+
const lockPath = args.explicitLock ? path69.resolve(args.explicitLock) : path69.join(path69.dirname(manifestPath), "pixelkiln.lock.json");
|
|
30266
30681
|
const ws = await loadWorkspace(workspacePath);
|
|
30267
30682
|
const id = args.name ?? loadedTarget.manifest.name;
|
|
30268
30683
|
if (ws.projects.some((p) => p.id === id)) {
|
|
@@ -30282,10 +30697,10 @@ async function runWorkspace(args) {
|
|
|
30282
30697
|
...args.account ? { account: args.account } : {}
|
|
30283
30698
|
};
|
|
30284
30699
|
await saveWorkspace(workspacePath, { version: 1, projects: [...ws.projects, project] });
|
|
30285
|
-
log(` registered "${id}" in ${
|
|
30700
|
+
log(` registered "${id}" in ${path69.relative(process.cwd(), workspacePath)}`);
|
|
30286
30701
|
log(` manifest: ${project.manifest}`);
|
|
30287
30702
|
log(` lock: ${project.lock}`);
|
|
30288
|
-
if (!
|
|
30703
|
+
if (!existsSync51(lockPath)) {
|
|
30289
30704
|
log(
|
|
30290
30705
|
` warning: no lockfile there yet; this project contributes no claims until one is generated`
|
|
30291
30706
|
);
|
|
@@ -30294,7 +30709,7 @@ async function runWorkspace(args) {
|
|
|
30294
30709
|
}
|
|
30295
30710
|
if (args.subcommand === "remove") {
|
|
30296
30711
|
const ws = await loadWorkspace(workspacePath);
|
|
30297
|
-
const resolvedTarget =
|
|
30712
|
+
const resolvedTarget = path69.resolve(args.target);
|
|
30298
30713
|
const match = ws.projects.find(
|
|
30299
30714
|
(p) => p.id === args.target || resolveProject(dir, p).manifestPath === resolvedTarget
|
|
30300
30715
|
);
|
|
@@ -30305,11 +30720,11 @@ async function runWorkspace(args) {
|
|
|
30305
30720
|
version: 1,
|
|
30306
30721
|
projects: ws.projects.filter((p) => p !== match)
|
|
30307
30722
|
});
|
|
30308
|
-
log(` removed "${match.id}" from ${
|
|
30723
|
+
log(` removed "${match.id}" from ${path69.relative(process.cwd(), workspacePath)}`);
|
|
30309
30724
|
return;
|
|
30310
30725
|
}
|
|
30311
30726
|
if (args.subcommand === "list") {
|
|
30312
|
-
if (!
|
|
30727
|
+
if (!existsSync51(workspacePath)) {
|
|
30313
30728
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
30314
30729
|
}
|
|
30315
30730
|
const ws = await loadWorkspace(workspacePath);
|
|
@@ -30317,9 +30732,9 @@ async function runWorkspace(args) {
|
|
|
30317
30732
|
if (args.json) {
|
|
30318
30733
|
log(JSON.stringify({ version: 1, workspace: workspacePath, projects: ws.projects, diagnostics }, null, 2));
|
|
30319
30734
|
} else if (!ws.projects.length) {
|
|
30320
|
-
log(` no projects registered in ${
|
|
30735
|
+
log(` no projects registered in ${path69.relative(process.cwd(), workspacePath)}`);
|
|
30321
30736
|
} else {
|
|
30322
|
-
log(` ${ws.projects.length} project(s) in ${
|
|
30737
|
+
log(` ${ws.projects.length} project(s) in ${path69.relative(process.cwd(), workspacePath)}:`);
|
|
30323
30738
|
for (const p of ws.projects) {
|
|
30324
30739
|
log(` ${p.id.padEnd(24)} ${p.manifest.padEnd(40)} (${p.provider}${p.account ? `, ${p.account}` : ""})`);
|
|
30325
30740
|
}
|
|
@@ -30329,7 +30744,7 @@ async function runWorkspace(args) {
|
|
|
30329
30744
|
return;
|
|
30330
30745
|
}
|
|
30331
30746
|
if (args.subcommand === "status") {
|
|
30332
|
-
if (!
|
|
30747
|
+
if (!existsSync51(workspacePath)) {
|
|
30333
30748
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
30334
30749
|
}
|
|
30335
30750
|
const ws = await loadWorkspace(workspacePath);
|
|
@@ -30337,7 +30752,7 @@ async function runWorkspace(args) {
|
|
|
30337
30752
|
if (args.json) {
|
|
30338
30753
|
log(JSON.stringify({ ...report, workspace: workspacePath }, null, 2));
|
|
30339
30754
|
} else {
|
|
30340
|
-
log(` workspace: ${
|
|
30755
|
+
log(` workspace: ${path69.relative(process.cwd(), workspacePath)}`);
|
|
30341
30756
|
for (const p of report.projects) {
|
|
30342
30757
|
if (p.error) {
|
|
30343
30758
|
log(`
|
|
@@ -30391,8 +30806,8 @@ async function runHelp() {
|
|
|
30391
30806
|
async function runVersion() {
|
|
30392
30807
|
for (const up of ["../package.json", "../../package.json"]) {
|
|
30393
30808
|
const url = new URL(up, import.meta.url);
|
|
30394
|
-
if (!
|
|
30395
|
-
const pkg = JSON.parse(await
|
|
30809
|
+
if (!existsSync52(url)) continue;
|
|
30810
|
+
const pkg = JSON.parse(await readFile46(url, "utf8"));
|
|
30396
30811
|
if (pkg.name === "pixelkiln") {
|
|
30397
30812
|
log(`${pkg.name} ${pkg.version}`);
|
|
30398
30813
|
return;
|