pixelkiln 0.92.3 → 0.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +844 -340
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +722 -312
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +199 -24
- package/dist/index.d.ts +199 -24
- package/dist/index.js +689 -283
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +68 -2
- package/package.json +1 -1
package/dist/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 existsSync42 } from "fs";
|
|
71
|
+
import { readFile as readFile37 } from "fs/promises";
|
|
72
72
|
|
|
73
73
|
// src/cli/args.ts
|
|
74
74
|
import path from "path";
|
|
@@ -102,6 +102,8 @@ var VALUE_FLAGS = [
|
|
|
102
102
|
"--min-grid-confidence",
|
|
103
103
|
"--reviewer",
|
|
104
104
|
"--note",
|
|
105
|
+
"--source",
|
|
106
|
+
"--object-id",
|
|
105
107
|
"--model-root",
|
|
106
108
|
"--generation",
|
|
107
109
|
"--quantize",
|
|
@@ -135,11 +137,14 @@ var BOOL_FLAGS = [
|
|
|
135
137
|
"--edit",
|
|
136
138
|
"--refresh",
|
|
137
139
|
"--no-editor",
|
|
138
|
-
"--game-pack"
|
|
140
|
+
"--game-pack",
|
|
141
|
+
"--local",
|
|
142
|
+
"--strict"
|
|
139
143
|
];
|
|
140
144
|
var COMMANDS = [
|
|
141
145
|
"init",
|
|
142
146
|
"plan",
|
|
147
|
+
"hash",
|
|
143
148
|
"doctor",
|
|
144
149
|
"gen",
|
|
145
150
|
"submit",
|
|
@@ -415,6 +420,10 @@ function parseArgs(argv) {
|
|
|
415
420
|
edit: rest.includes("--edit"),
|
|
416
421
|
noEditor: rest.includes("--no-editor"),
|
|
417
422
|
refresh: rest.includes("--refresh"),
|
|
423
|
+
local: rest.includes("--local"),
|
|
424
|
+
strict: rest.includes("--strict"),
|
|
425
|
+
source: get("--source"),
|
|
426
|
+
objectId: get("--object-id"),
|
|
418
427
|
from: get("--from"),
|
|
419
428
|
out: get("--out"),
|
|
420
429
|
generator: get("--generator"),
|
|
@@ -482,6 +491,8 @@ Commands
|
|
|
482
491
|
--generation <n|hash> brings a previous generation back instead.
|
|
483
492
|
history List the generations each asset has replaced and can restore.
|
|
484
493
|
adopt Match existing account objects to files already in the repo.
|
|
494
|
+
--local records them offline (no key): --source, --note, --object-id, --dry-run.
|
|
495
|
+
hash Print each asset's spec hash, file hash and would-be lock entry (offline).
|
|
485
496
|
accept Keep existing art after a style reword. Re-baseline, do not regenerate.
|
|
486
497
|
salvage Triage account objects no lockfile claims. Recovers usable art.
|
|
487
498
|
One session per matching style unless --style forces a single one.
|
|
@@ -611,6 +622,7 @@ Options
|
|
|
611
622
|
and switches gallery to every registered project.
|
|
612
623
|
--from <path> Source for init/path-mode refine, or baseline for quality check
|
|
613
624
|
--write-prompts adopt: recover prompts into the manifest
|
|
625
|
+
--strict plan/hash/doctor: fail on any invalid manifest entry instead of listing it and continuing
|
|
614
626
|
|
|
615
627
|
Examples
|
|
616
628
|
pixelkiln plan
|
|
@@ -725,10 +737,10 @@ import { createReadStream } from "fs";
|
|
|
725
737
|
function sha256(data) {
|
|
726
738
|
return createHash("sha256").update(data).digest("hex");
|
|
727
739
|
}
|
|
728
|
-
async function sha256File(
|
|
740
|
+
async function sha256File(path54) {
|
|
729
741
|
return new Promise((resolve, reject) => {
|
|
730
742
|
const hash = createHash("sha256");
|
|
731
|
-
const stream = createReadStream(
|
|
743
|
+
const stream = createReadStream(path54);
|
|
732
744
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
733
745
|
stream.on("error", reject);
|
|
734
746
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -2512,7 +2524,17 @@ var LockEntrySchema = z.object({
|
|
|
2512
2524
|
/** Generations this entry replaced, newest first; see LockHistoryEntrySchema. */
|
|
2513
2525
|
history: z.array(LockHistoryEntrySchema).optional(),
|
|
2514
2526
|
/** Post-processing applied to the recorded outputs; absent when the bytes are the provider's. */
|
|
2515
|
-
postprocess: PostprocessSchema.optional()
|
|
2527
|
+
postprocess: PostprocessSchema.optional(),
|
|
2528
|
+
/**
|
|
2529
|
+
* Set when the entry records art made outside pixelkiln (the PixelLab MCP, a
|
|
2530
|
+
* hand edit, another tool) and brought in with `adopt --local`: nothing was
|
|
2531
|
+
* submitted, so jobId and cost are empty. Absent on generated entries.
|
|
2532
|
+
*/
|
|
2533
|
+
imported: z.object({
|
|
2534
|
+
source: z.string().min(1),
|
|
2535
|
+
note: z.string().optional(),
|
|
2536
|
+
importedAt: z.string()
|
|
2537
|
+
}).strict().optional()
|
|
2516
2538
|
});
|
|
2517
2539
|
var LockSchema = z.object({
|
|
2518
2540
|
version: z.literal(2),
|
|
@@ -5280,7 +5302,12 @@ function announceGalleryReady(url, count, stdout = process.stdout, stderr = proc
|
|
|
5280
5302
|
` : " (read-only; add --edit to change prompts or edit sprites, --budget <n> to generate; Ctrl+C to stop)\n\n")
|
|
5281
5303
|
);
|
|
5282
5304
|
}
|
|
5283
|
-
function
|
|
5305
|
+
function selectInvalid(invalid, selection) {
|
|
5306
|
+
if (!selection.assets.length && !selection.styles.length) return { shown: invalid, hidden: 0 };
|
|
5307
|
+
const shown = invalid.filter((entry) => entry.kind === "asset" ? selection.assets.includes(entry.id) : selection.styles.includes(entry.id));
|
|
5308
|
+
return { shown, hidden: invalid.length - shown.length };
|
|
5309
|
+
}
|
|
5310
|
+
function printPlan(plan, invalid = [], hiddenInvalid = 0) {
|
|
5284
5311
|
const counts = summarize(plan);
|
|
5285
5312
|
const order = [
|
|
5286
5313
|
"blocked",
|
|
@@ -5303,9 +5330,21 @@ function printPlan(plan) {
|
|
|
5303
5330
|
}
|
|
5304
5331
|
if (items.length > 40) log(` \u2026 and ${items.length - 40} more`);
|
|
5305
5332
|
}
|
|
5333
|
+
if (invalid.length) {
|
|
5334
|
+
log(`
|
|
5335
|
+
invalid (${invalid.length}) not planned; fix the entry or pass --strict to stop here`);
|
|
5336
|
+
for (const entry of invalid.slice(0, 40)) {
|
|
5337
|
+
const clip = (text) => text.length > 160 ? `${text.slice(0, 157)}\u2026` : text;
|
|
5338
|
+
log(` ${`${entry.kind === "style" ? "styles" : "assets"}.${entry.id}`.padEnd(42)} ${clip(entry.issues[0] ?? "")}`);
|
|
5339
|
+
for (const extra of entry.issues.slice(1, 3)) log(` ${"".padEnd(42)} ${clip(extra)}`);
|
|
5340
|
+
}
|
|
5341
|
+
if (invalid.length > 40) log(` \u2026 and ${invalid.length - 40} more`);
|
|
5342
|
+
}
|
|
5343
|
+
if (hiddenInvalid) log(`
|
|
5344
|
+
${hiddenInvalid} other invalid entr${hiddenInvalid === 1 ? "y" : "ies"} outside this selection; run without --only/--style to see them`);
|
|
5306
5345
|
log(
|
|
5307
5346
|
`
|
|
5308
|
-
totals: ${counts.ok} ok \xB7 ${counts.blocked} blocked \xB7 ${counts.missing} missing \xB7 ${counts.untracked} untracked \xB7 ${counts.stale} stale \xB7 ${counts["in-flight"]} in-flight \xB7 ${counts.orphaned} orphaned \xB7 ${counts.recoverable} recoverable \xB7 ${counts.failed} failed`
|
|
5347
|
+
totals: ${counts.ok} ok \xB7 ${counts.blocked} blocked \xB7 ${counts.missing} missing \xB7 ${counts.untracked} untracked \xB7 ${counts.stale} stale \xB7 ${counts["in-flight"]} in-flight \xB7 ${counts.orphaned} orphaned \xB7 ${counts.recoverable} recoverable \xB7 ${counts.failed} failed` + (invalid.length ? ` \xB7 ${invalid.length} invalid` : "")
|
|
5309
5348
|
);
|
|
5310
5349
|
if (plan.actionable.length) {
|
|
5311
5350
|
for (const group of plan.groups) {
|
|
@@ -5354,7 +5393,7 @@ async function confirm(question, auto) {
|
|
|
5354
5393
|
|
|
5355
5394
|
// src/cli/commands/account.ts
|
|
5356
5395
|
import path25 from "path";
|
|
5357
|
-
import { existsSync as
|
|
5396
|
+
import { existsSync as existsSync20 } from "fs";
|
|
5358
5397
|
|
|
5359
5398
|
// src/env.ts
|
|
5360
5399
|
import { readFileSync, existsSync as existsSync6 } from "fs";
|
|
@@ -6818,9 +6857,9 @@ var PixelLabClient = class {
|
|
|
6818
6857
|
apiKey;
|
|
6819
6858
|
http;
|
|
6820
6859
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
6821
|
-
async request(
|
|
6860
|
+
async request(path54, init) {
|
|
6822
6861
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
6823
|
-
const res = await this.http(`${BASE}${
|
|
6862
|
+
const res = await this.http(`${BASE}${path54}`, {
|
|
6824
6863
|
...init,
|
|
6825
6864
|
headers: {
|
|
6826
6865
|
Authorization: auth,
|
|
@@ -6831,13 +6870,13 @@ var PixelLabClient = class {
|
|
|
6831
6870
|
const text = await res.text();
|
|
6832
6871
|
if (!res.ok) {
|
|
6833
6872
|
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' : "";
|
|
6834
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
6873
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path54} \u2192 ${res.status}${hint}`, res.status, text);
|
|
6835
6874
|
}
|
|
6836
6875
|
if (!text) return {};
|
|
6837
6876
|
try {
|
|
6838
6877
|
return JSON.parse(text);
|
|
6839
6878
|
} catch {
|
|
6840
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
6879
|
+
throw new Error(`${init?.method ?? "GET"} ${path54} returned invalid JSON`);
|
|
6841
6880
|
}
|
|
6842
6881
|
}
|
|
6843
6882
|
async balance() {
|
|
@@ -7290,10 +7329,10 @@ var PixelLabClient = class {
|
|
|
7290
7329
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
7291
7330
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
7292
7331
|
const south = args.reference?.south;
|
|
7293
|
-
let
|
|
7332
|
+
let path54;
|
|
7294
7333
|
let body;
|
|
7295
7334
|
if (args.mode === "v3") {
|
|
7296
|
-
|
|
7335
|
+
path54 = "/create-character-v3";
|
|
7297
7336
|
body = {
|
|
7298
7337
|
description: args.description,
|
|
7299
7338
|
image_size: imageSize,
|
|
@@ -7307,7 +7346,7 @@ var PixelLabClient = class {
|
|
|
7307
7346
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
7308
7347
|
};
|
|
7309
7348
|
} else if (args.mode === "pro-flash") {
|
|
7310
|
-
|
|
7349
|
+
path54 = "/create-character-pro-flash";
|
|
7311
7350
|
const traits = args.styleTraits;
|
|
7312
7351
|
body = {
|
|
7313
7352
|
description: args.description,
|
|
@@ -7331,7 +7370,7 @@ var PixelLabClient = class {
|
|
|
7331
7370
|
} : {}
|
|
7332
7371
|
};
|
|
7333
7372
|
} else if (args.mode === "pro") {
|
|
7334
|
-
|
|
7373
|
+
path54 = "/create-character-pro";
|
|
7335
7374
|
body = {
|
|
7336
7375
|
description: args.description,
|
|
7337
7376
|
image_size: imageSize,
|
|
@@ -7345,7 +7384,7 @@ var PixelLabClient = class {
|
|
|
7345
7384
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
7346
7385
|
};
|
|
7347
7386
|
} else {
|
|
7348
|
-
|
|
7387
|
+
path54 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
7349
7388
|
body = {
|
|
7350
7389
|
description: args.description,
|
|
7351
7390
|
image_size: imageSize,
|
|
@@ -7363,8 +7402,8 @@ var PixelLabClient = class {
|
|
|
7363
7402
|
};
|
|
7364
7403
|
}
|
|
7365
7404
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
7366
|
-
const raw = await this.request(
|
|
7367
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
7405
|
+
const raw = await this.request(path54, { method: "POST", body: JSON.stringify(body) });
|
|
7406
|
+
return validateResponse(CharacterSubmitSchema, raw, path54.slice(1));
|
|
7368
7407
|
}
|
|
7369
7408
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
7370
7409
|
async createCharacterState(args) {
|
|
@@ -10943,13 +10982,13 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
10943
10982
|
async pollVfx(jobId, context) {
|
|
10944
10983
|
const dir = _PixelLabProvider.cacheDir("vfx");
|
|
10945
10984
|
const sidecar = path14.join(dir, `${jobId}.json`);
|
|
10946
|
-
const
|
|
10985
|
+
const cached2 = () => {
|
|
10947
10986
|
if (!existsSync9(sidecar)) return null;
|
|
10948
10987
|
const facts2 = JSON.parse(readFileSync2(sidecar, "utf8"));
|
|
10949
10988
|
const files2 = Array.from({ length: facts2.count }, (_, index) => path14.join(dir, `${jobId}-${index}.png`));
|
|
10950
10989
|
return files2.every((file) => existsSync9(file)) ? { facts: facts2, files: files2 } : null;
|
|
10951
10990
|
};
|
|
10952
|
-
let found =
|
|
10991
|
+
let found = cached2();
|
|
10953
10992
|
const recorded = context?.metadata?.vfx;
|
|
10954
10993
|
let artistDone;
|
|
10955
10994
|
if (!found && recorded?.artist) {
|
|
@@ -10969,11 +11008,11 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
10969
11008
|
}
|
|
10970
11009
|
artistDone.billed = billedFromUsage(job.usage);
|
|
10971
11010
|
}
|
|
10972
|
-
found =
|
|
11011
|
+
found = cached2();
|
|
10973
11012
|
} else if (!found && recorded?.downloadBase && Array.isArray(recorded.files)) {
|
|
10974
11013
|
const exported = recorded;
|
|
10975
11014
|
await this.cacheVfxFrames(jobId, exported, workbenchVfxUrls(exported));
|
|
10976
|
-
found =
|
|
11015
|
+
found = cached2();
|
|
10977
11016
|
}
|
|
10978
11017
|
if (!found) {
|
|
10979
11018
|
return {
|
|
@@ -11787,9 +11826,9 @@ var RetroDiffusionClient = class {
|
|
|
11787
11826
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
11788
11827
|
return Buffer.from(await response.arrayBuffer());
|
|
11789
11828
|
}
|
|
11790
|
-
async call(
|
|
11829
|
+
async call(path54, init = {}) {
|
|
11791
11830
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
11792
|
-
const response = await this.request(`${this.baseUrl}${
|
|
11831
|
+
const response = await this.request(`${this.baseUrl}${path54}`, {
|
|
11793
11832
|
...init,
|
|
11794
11833
|
headers: {
|
|
11795
11834
|
"Content-Type": "application/json",
|
|
@@ -12171,8 +12210,8 @@ var ScenarioClient = class {
|
|
|
12171
12210
|
async uploadImage(image, projectId) {
|
|
12172
12211
|
const bytes = Buffer.from(image.base64, "base64");
|
|
12173
12212
|
const digest2 = sha256(bytes);
|
|
12174
|
-
const
|
|
12175
|
-
if (
|
|
12213
|
+
const cached2 = readUploadCache()[uploadCacheKey(this.baseUrl, projectId, digest2)];
|
|
12214
|
+
if (cached2) return cached2;
|
|
12176
12215
|
const response = await this.call(
|
|
12177
12216
|
"/assets",
|
|
12178
12217
|
{
|
|
@@ -12763,7 +12802,7 @@ registerProvider({
|
|
|
12763
12802
|
|
|
12764
12803
|
// src/manifest.ts
|
|
12765
12804
|
import { readFile as readFile8 } from "fs/promises";
|
|
12766
|
-
import { existsSync as
|
|
12805
|
+
import { existsSync as existsSync11 } from "fs";
|
|
12767
12806
|
import path16 from "path";
|
|
12768
12807
|
|
|
12769
12808
|
// src/loop-directions.ts
|
|
@@ -12859,15 +12898,93 @@ function isObject2(value) {
|
|
|
12859
12898
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12860
12899
|
}
|
|
12861
12900
|
|
|
12901
|
+
// src/version.ts
|
|
12902
|
+
import { existsSync as existsSync10, readFileSync as readFileSync4 } from "fs";
|
|
12903
|
+
var cached;
|
|
12904
|
+
function pixelkilnVersion() {
|
|
12905
|
+
if (cached !== void 0) return cached;
|
|
12906
|
+
cached = null;
|
|
12907
|
+
for (const up of ["../package.json", "../../package.json"]) {
|
|
12908
|
+
const url = new URL(up, import.meta.url);
|
|
12909
|
+
if (!existsSync10(url)) continue;
|
|
12910
|
+
try {
|
|
12911
|
+
const pkg = JSON.parse(readFileSync4(url, "utf8"));
|
|
12912
|
+
if (pkg.name === "pixelkiln" && pkg.version) {
|
|
12913
|
+
cached = pkg.version;
|
|
12914
|
+
break;
|
|
12915
|
+
}
|
|
12916
|
+
} catch {
|
|
12917
|
+
}
|
|
12918
|
+
}
|
|
12919
|
+
return cached;
|
|
12920
|
+
}
|
|
12921
|
+
|
|
12862
12922
|
// src/manifest.ts
|
|
12863
|
-
async function loadManifest(manifestPath) {
|
|
12923
|
+
async function loadManifest(manifestPath, opts = {}) {
|
|
12864
12924
|
const abs = path16.resolve(manifestPath);
|
|
12865
|
-
if (!
|
|
12925
|
+
if (!existsSync11(abs)) throw new ProjectError(`No manifest at ${abs}`);
|
|
12866
12926
|
const expansion = expandLoopDirections(JSON.parse(await readFile8(abs, "utf8")));
|
|
12867
12927
|
if (expansion.issues.length) {
|
|
12868
12928
|
throw new ProjectError(`Manifest at ${abs} is invalid:
|
|
12869
12929
|
${expansion.issues.map((i) => ` ${i}`).join("\n")}`);
|
|
12870
12930
|
}
|
|
12931
|
+
if (!opts.lenient) return loadExpanded(abs, expansion);
|
|
12932
|
+
const invalid = [];
|
|
12933
|
+
const raw = pruneInvalidEntries(expansion.raw, invalid);
|
|
12934
|
+
for (let round2 = 0; ; round2++) {
|
|
12935
|
+
try {
|
|
12936
|
+
const loaded = await loadExpanded(abs, { ...expansion, raw });
|
|
12937
|
+
return invalid.length ? { ...loaded, invalid } : loaded;
|
|
12938
|
+
} catch (error) {
|
|
12939
|
+
const culprits = round2 < 50 && error instanceof ProjectError ? culpritEntries(error.message) : [];
|
|
12940
|
+
const fresh = culprits.filter((entry) => dropEntry(raw, entry));
|
|
12941
|
+
if (!fresh.length) throw error;
|
|
12942
|
+
invalid.push(...fresh);
|
|
12943
|
+
}
|
|
12944
|
+
}
|
|
12945
|
+
}
|
|
12946
|
+
function entryRecord(raw, kind) {
|
|
12947
|
+
const record = raw?.[kind === "style" ? "styles" : "assets"];
|
|
12948
|
+
return record && typeof record === "object" && !Array.isArray(record) ? record : null;
|
|
12949
|
+
}
|
|
12950
|
+
function dropEntry(raw, entry) {
|
|
12951
|
+
const record = entryRecord(raw, entry.kind);
|
|
12952
|
+
if (!record || !(entry.id in record)) return false;
|
|
12953
|
+
delete record[entry.id];
|
|
12954
|
+
return true;
|
|
12955
|
+
}
|
|
12956
|
+
function pruneInvalidEntries(raw, invalid) {
|
|
12957
|
+
for (const [kind, schema] of [["style", StyleInputSchema], ["asset", AssetSchema]]) {
|
|
12958
|
+
const record = entryRecord(raw, kind);
|
|
12959
|
+
if (!record) continue;
|
|
12960
|
+
for (const [id, value] of Object.entries(record)) {
|
|
12961
|
+
const parsed = schema.safeParse(value);
|
|
12962
|
+
if (parsed.success) continue;
|
|
12963
|
+
const prefix = `${kind === "style" ? "styles" : "assets"}.${id}`;
|
|
12964
|
+
const lines = flattenManifestIssues(parsed.error.issues).lines.map((line) => {
|
|
12965
|
+
const [fieldPath, ...rest] = line.trim().split(": ");
|
|
12966
|
+
return `${prefix}${fieldPath === "(manifest)" || !fieldPath ? "" : `.${fieldPath}`}: ${rest.join(": ")}`;
|
|
12967
|
+
});
|
|
12968
|
+
invalid.push({ kind, id, issues: lines.length ? lines : [`${prefix}: invalid`] });
|
|
12969
|
+
delete record[id];
|
|
12970
|
+
}
|
|
12971
|
+
}
|
|
12972
|
+
return raw;
|
|
12973
|
+
}
|
|
12974
|
+
function culpritEntries(message6) {
|
|
12975
|
+
const found = /* @__PURE__ */ new Map();
|
|
12976
|
+
for (const line of message6.split("\n")) {
|
|
12977
|
+
const match = /^ {2}(assets|styles)\.([^.:\s]+)[.:]/.exec(line);
|
|
12978
|
+
if (!match) continue;
|
|
12979
|
+
const kind = match[1] === "styles" ? "style" : "asset";
|
|
12980
|
+
const key = `${kind}:${match[2]}`;
|
|
12981
|
+
const entry = found.get(key) ?? { kind, id: match[2], issues: [] };
|
|
12982
|
+
entry.issues.push(line.trim());
|
|
12983
|
+
found.set(key, entry);
|
|
12984
|
+
}
|
|
12985
|
+
return [...found.values()];
|
|
12986
|
+
}
|
|
12987
|
+
async function loadExpanded(abs, expansion) {
|
|
12871
12988
|
const input = ManifestInputSchema.safeParse(expansion.raw);
|
|
12872
12989
|
if (!input.success) {
|
|
12873
12990
|
const issues = formatManifestIssues(input.error.issues);
|
|
@@ -13014,19 +13131,45 @@ function dependencyAssetIds(asset, styleAnchors = []) {
|
|
|
13014
13131
|
].filter((id) => Boolean(id))
|
|
13015
13132
|
];
|
|
13016
13133
|
}
|
|
13134
|
+
var MAX_LISTED_MANIFEST_ISSUES = 20;
|
|
13135
|
+
function flattenManifestIssues(issues) {
|
|
13136
|
+
let unknownShape = false;
|
|
13137
|
+
const visit = (list) => list.flatMap((issue) => {
|
|
13138
|
+
if (issue.code === "invalid_union") return visit(issue.unionErrors.flatMap((error) => error.issues));
|
|
13139
|
+
if (issue.code === "unrecognized_keys" || issue.code === "invalid_enum_value") unknownShape = true;
|
|
13140
|
+
return [` ${issue.path.join(".") || "(manifest)"}: ${issue.message}`];
|
|
13141
|
+
});
|
|
13142
|
+
return { lines: [...new Set(visit(issues))], unknownShape };
|
|
13143
|
+
}
|
|
13017
13144
|
function formatManifestIssues(issues) {
|
|
13018
|
-
|
|
13019
|
-
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13023
|
-
|
|
13145
|
+
const { lines, unknownShape } = flattenManifestIssues(issues);
|
|
13146
|
+
const entries = [...new Set(
|
|
13147
|
+
lines.flatMap((line) => {
|
|
13148
|
+
const match = /^ {2}((?:assets|styles)\.[^.:\s]+)/.exec(line);
|
|
13149
|
+
return match ? [match[1]] : [];
|
|
13150
|
+
})
|
|
13151
|
+
)];
|
|
13152
|
+
const out = [];
|
|
13153
|
+
const version = pixelkilnVersion();
|
|
13154
|
+
if (unknownShape) {
|
|
13155
|
+
out.push(
|
|
13156
|
+
` This manifest uses fields or values pixelkiln ${version ?? "(this version)"} does not know. If it was written by a newer release, run \`npx pixelkiln@latest\` or update the install before editing it.`
|
|
13157
|
+
);
|
|
13158
|
+
}
|
|
13159
|
+
if (entries.length) {
|
|
13160
|
+
out.push(` ${entries.length} invalid entr${entries.length === 1 ? "y" : "ies"}: ${entries.slice(0, 10).join(", ")}${entries.length > 10 ? ", \u2026" : ""}`);
|
|
13161
|
+
}
|
|
13162
|
+
out.push(...lines.slice(0, MAX_LISTED_MANIFEST_ISSUES));
|
|
13163
|
+
if (lines.length > MAX_LISTED_MANIFEST_ISSUES) {
|
|
13164
|
+
out.push(` \u2026 and ${lines.length - MAX_LISTED_MANIFEST_ISSUES} more`);
|
|
13165
|
+
}
|
|
13166
|
+
return out.join("\n");
|
|
13024
13167
|
}
|
|
13025
13168
|
function resolveStyleInheritance(styles) {
|
|
13026
13169
|
const resolved = /* @__PURE__ */ new Map();
|
|
13027
13170
|
const visit = (styleId, chain) => {
|
|
13028
|
-
const
|
|
13029
|
-
if (
|
|
13171
|
+
const cached2 = resolved.get(styleId);
|
|
13172
|
+
if (cached2) return cached2;
|
|
13030
13173
|
const cycleStart = chain.indexOf(styleId);
|
|
13031
13174
|
if (cycleStart >= 0) {
|
|
13032
13175
|
throw new Error(
|
|
@@ -13148,7 +13291,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
13148
13291
|
const abs = path16.resolve(root, rel);
|
|
13149
13292
|
let hit = styleImageCache.get(abs);
|
|
13150
13293
|
if (!hit) {
|
|
13151
|
-
if (!
|
|
13294
|
+
if (!existsSync11(abs)) throw new Error(`${what} not found: ${abs}`);
|
|
13152
13295
|
const buf = await readFile8(abs);
|
|
13153
13296
|
const metadata = imageMetadata(buf);
|
|
13154
13297
|
if (!metadata) throw new Error(`${what} is not a readable PNG or JPEG: ${abs}`);
|
|
@@ -13499,7 +13642,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
13499
13642
|
const file = memberPath(anchorSpec.outFile, "south", 0, anchorSpec.character.directions, MediaType.PNG);
|
|
13500
13643
|
resolved.character = {
|
|
13501
13644
|
...resolved.character,
|
|
13502
|
-
styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256:
|
|
13645
|
+
styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: existsSync11(file) ? await sha256File(file) : null }
|
|
13503
13646
|
};
|
|
13504
13647
|
}
|
|
13505
13648
|
const characterParent = asset.state?.of ?? asset.animation?.of ?? asset.portrait?.of;
|
|
@@ -13512,7 +13655,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
13512
13655
|
parentAssetId: characterParent,
|
|
13513
13656
|
parentSpec,
|
|
13514
13657
|
parentFile,
|
|
13515
|
-
parentSha256:
|
|
13658
|
+
parentSha256: existsSync11(parentFile) ? await sha256File(parentFile) : null,
|
|
13516
13659
|
// A state and its animations keep the engine and rotations of the base.
|
|
13517
13660
|
mode: resolved.character.kind === "base" ? resolved.character.mode : parentSpec.character?.mode ?? resolved.character.mode,
|
|
13518
13661
|
directions: resolved.character.kind === "base" ? resolved.character.directions : parentSpec.character?.directions ?? resolved.character.directions
|
|
@@ -13550,7 +13693,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
13550
13693
|
parentAssetId: characterParent,
|
|
13551
13694
|
parentSpec,
|
|
13552
13695
|
parentFile,
|
|
13553
|
-
parentSha256:
|
|
13696
|
+
parentSha256: existsSync11(parentFile) ? await sha256File(parentFile) : null,
|
|
13554
13697
|
// A state and its animations keep the base's own rotation count.
|
|
13555
13698
|
directions: resolved.objectPro.kind === "base" ? resolved.objectPro.directions : parentSpec.objectPro.directions
|
|
13556
13699
|
};
|
|
@@ -13754,8 +13897,18 @@ async function resolveSpecs(loaded, filter) {
|
|
|
13754
13897
|
providerOptionIdentity,
|
|
13755
13898
|
providerInputIdentities.get(assetId)
|
|
13756
13899
|
);
|
|
13757
|
-
|
|
13758
|
-
|
|
13900
|
+
let estimate;
|
|
13901
|
+
try {
|
|
13902
|
+
activeProvider.validate?.(resolved, resolvedImages);
|
|
13903
|
+
estimate = validateCostEstimate(activeProvider.id, activeProvider.estimate(resolved));
|
|
13904
|
+
} catch (error) {
|
|
13905
|
+
const message6 = error instanceof Error ? error.message : String(error);
|
|
13906
|
+
if (message6.includes(`assets.${assetId}`)) throw error;
|
|
13907
|
+
throw new Error(
|
|
13908
|
+
`assets.${assetId} (style "${styleId}", ${resolved.width}x${resolved.height}): ${message6}`,
|
|
13909
|
+
{ cause: error }
|
|
13910
|
+
);
|
|
13911
|
+
}
|
|
13759
13912
|
resolved.cost = estimate.amount;
|
|
13760
13913
|
resolved.costUnit = estimate.unit;
|
|
13761
13914
|
resolved.candidates = estimate.candidates;
|
|
@@ -13766,7 +13919,16 @@ async function resolveSpecs(loaded, filter) {
|
|
|
13766
13919
|
if (!emitStyles.has(styleId)) continue;
|
|
13767
13920
|
for (const assetId of Object.keys(manifest.assets)) {
|
|
13768
13921
|
if (!requestedAssetIds.has(assetId) || !styleSpecs.has(assetId)) continue;
|
|
13769
|
-
|
|
13922
|
+
if (!filter?.onInvalid) {
|
|
13923
|
+
specs.push(await finalize(assetId));
|
|
13924
|
+
continue;
|
|
13925
|
+
}
|
|
13926
|
+
try {
|
|
13927
|
+
specs.push(await finalize(assetId));
|
|
13928
|
+
} catch (error) {
|
|
13929
|
+
const message6 = error instanceof Error ? error.message : String(error);
|
|
13930
|
+
filter.onInvalid({ kind: "asset", id: assetId, issues: [message6] });
|
|
13931
|
+
}
|
|
13770
13932
|
}
|
|
13771
13933
|
}
|
|
13772
13934
|
const byOutput = /* @__PURE__ */ new Map();
|
|
@@ -13839,7 +14001,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
13839
14001
|
let recordedSprite;
|
|
13840
14002
|
if (vfx.recipe) {
|
|
13841
14003
|
const file = path16.resolve(root, vfx.recipe);
|
|
13842
|
-
if (!
|
|
14004
|
+
if (!existsSync11(file)) throw new Error(`assets.${assetId}.vfx.recipe: VFX recipe not found: ${file}`);
|
|
13843
14005
|
const read = await readVfxRecipe(file).catch((error) => {
|
|
13844
14006
|
throw new Error(`assets.${assetId}.vfx.recipe: ${error instanceof Error ? error.message : String(error)}`);
|
|
13845
14007
|
});
|
|
@@ -13866,7 +14028,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
13866
14028
|
};
|
|
13867
14029
|
}
|
|
13868
14030
|
async function optionalRevisionImage(file, label, requiredFormat) {
|
|
13869
|
-
if (!
|
|
14031
|
+
if (!existsSync11(file)) return null;
|
|
13870
14032
|
const bytes = await readFile8(file);
|
|
13871
14033
|
const metadata = imageMetadata(bytes);
|
|
13872
14034
|
if (!metadata) throw new Error(`${label} is not a readable PNG or JPEG: ${file}`);
|
|
@@ -13876,7 +14038,7 @@ async function optionalRevisionImage(file, label, requiredFormat) {
|
|
|
13876
14038
|
return { hash: sha256(bytes), ...metadata };
|
|
13877
14039
|
}
|
|
13878
14040
|
async function optionalSkeletonSet(file) {
|
|
13879
|
-
if (!
|
|
14041
|
+
if (!existsSync11(file)) return null;
|
|
13880
14042
|
const bytes = await readFile8(file);
|
|
13881
14043
|
let json;
|
|
13882
14044
|
try {
|
|
@@ -13887,17 +14049,17 @@ async function optionalSkeletonSet(file) {
|
|
|
13887
14049
|
return { hash: sha256(bytes), skeleton: parseSkeletonSet(json, file) };
|
|
13888
14050
|
}
|
|
13889
14051
|
async function revisionSourceMembers(stem, label) {
|
|
13890
|
-
if (
|
|
14052
|
+
if (existsSync11(stem)) return null;
|
|
13891
14053
|
const at = (role) => memberPath(stem, role, 0, 2, MediaType.PNG);
|
|
13892
14054
|
let roles = [];
|
|
13893
14055
|
for (const set of [CHARACTER_DIRECTIONS_8, CHARACTER_DIRECTIONS_4]) {
|
|
13894
|
-
if (set.every((direction) =>
|
|
14056
|
+
if (set.every((direction) => existsSync11(at(direction)))) {
|
|
13895
14057
|
roles = [...set];
|
|
13896
14058
|
break;
|
|
13897
14059
|
}
|
|
13898
14060
|
}
|
|
13899
14061
|
if (!roles.length) {
|
|
13900
|
-
for (let index = 0;
|
|
14062
|
+
for (let index = 0; existsSync11(at(`frame-${String(index).padStart(2, "0")}`)); index++) {
|
|
13901
14063
|
roles.push(`frame-${String(index).padStart(2, "0")}`);
|
|
13902
14064
|
}
|
|
13903
14065
|
}
|
|
@@ -14056,7 +14218,7 @@ async function resolveObjectProShape(assetId, asset, style, kind, files) {
|
|
|
14056
14218
|
}
|
|
14057
14219
|
|
|
14058
14220
|
// src/pipeline/fetch.ts
|
|
14059
|
-
import { existsSync as
|
|
14221
|
+
import { existsSync as existsSync12, readFileSync as readFileSync5 } from "fs";
|
|
14060
14222
|
import { mkdir as mkdir6, readFile as readFile9, rename as rename4, rm as rm4, writeFile as writeFile6 } from "fs/promises";
|
|
14061
14223
|
import path17 from "path";
|
|
14062
14224
|
async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
@@ -14076,15 +14238,15 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14076
14238
|
if (spec && e.specHash === spec.specHash && e.outputs.length && !postprocessCurrent(e, spec)) {
|
|
14077
14239
|
return Boolean(opts.force) || e.outputs.every((output) => {
|
|
14078
14240
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14079
|
-
return
|
|
14241
|
+
return existsSync12(file) && sha256(readFileSync5(file)) === output.sha256;
|
|
14080
14242
|
});
|
|
14081
14243
|
}
|
|
14082
14244
|
if (!opts.repair) return false;
|
|
14083
14245
|
if (e.outputs.length === 0 || !spec) return true;
|
|
14084
14246
|
return e.outputs.some((output) => {
|
|
14085
14247
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14086
|
-
if (!
|
|
14087
|
-
const current = sha256(
|
|
14248
|
+
if (!existsSync12(file)) return true;
|
|
14249
|
+
const current = sha256(readFileSync5(file));
|
|
14088
14250
|
if (current === output.sha256) return false;
|
|
14089
14251
|
return Boolean(opts.force) || (e.supersededOutputs ?? []).some((old) => old.sha256 === current);
|
|
14090
14252
|
});
|
|
@@ -14174,7 +14336,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14174
14336
|
}
|
|
14175
14337
|
let raw = null;
|
|
14176
14338
|
let final = null;
|
|
14177
|
-
if (
|
|
14339
|
+
if (existsSync12(target)) {
|
|
14178
14340
|
const currentHash = await sha256File(target);
|
|
14179
14341
|
if (recorded && currentHash === recorded.sha256) {
|
|
14180
14342
|
if (!fresh && !reapply) {
|
|
@@ -14320,7 +14482,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14320
14482
|
}
|
|
14321
14483
|
async function readCachedMedia(cacheDir, hash, mediaType) {
|
|
14322
14484
|
const file = path17.join(cacheDir, cacheFileName(hash, mediaType));
|
|
14323
|
-
if (!
|
|
14485
|
+
if (!existsSync12(file)) return null;
|
|
14324
14486
|
try {
|
|
14325
14487
|
const buf = await readFile9(file);
|
|
14326
14488
|
if (sha256(buf) !== hash) return null;
|
|
@@ -14341,7 +14503,7 @@ async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
|
|
|
14341
14503
|
try {
|
|
14342
14504
|
await rename4(tmp, file);
|
|
14343
14505
|
} catch (err) {
|
|
14344
|
-
if (!
|
|
14506
|
+
if (!existsSync12(file)) throw err;
|
|
14345
14507
|
} finally {
|
|
14346
14508
|
await rm4(tmp, { force: true });
|
|
14347
14509
|
}
|
|
@@ -14373,14 +14535,125 @@ async function pushTags(provider, specs, lock, opts = {}) {
|
|
|
14373
14535
|
return tagged;
|
|
14374
14536
|
}
|
|
14375
14537
|
|
|
14376
|
-
// src/pipeline/
|
|
14538
|
+
// src/pipeline/import.ts
|
|
14377
14539
|
import { existsSync as existsSync13 } from "fs";
|
|
14378
|
-
import { readFile as
|
|
14540
|
+
import { readFile as readFile10 } from "fs/promises";
|
|
14541
|
+
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
14542
|
+
const png = decodePng(bytes);
|
|
14543
|
+
const at = now.toISOString();
|
|
14544
|
+
return {
|
|
14545
|
+
styleId: spec.styleId,
|
|
14546
|
+
assetId: spec.assetId,
|
|
14547
|
+
specHash: spec.specHash,
|
|
14548
|
+
generator: spec.generator,
|
|
14549
|
+
prompt: spec.prompt,
|
|
14550
|
+
width: png.width,
|
|
14551
|
+
height: png.height,
|
|
14552
|
+
jobId: opts.objectId ?? null,
|
|
14553
|
+
objectId: opts.objectId ?? null,
|
|
14554
|
+
reviewObjectId: null,
|
|
14555
|
+
candidateIndex: null,
|
|
14556
|
+
status: "downloaded",
|
|
14557
|
+
error: null,
|
|
14558
|
+
sourceUrl: null,
|
|
14559
|
+
sourceUrls: [],
|
|
14560
|
+
outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
|
|
14561
|
+
submittedAt: null,
|
|
14562
|
+
downloadedAt: at,
|
|
14563
|
+
cost: 0,
|
|
14564
|
+
costUnit: spec.costUnit,
|
|
14565
|
+
provider: spec.provider,
|
|
14566
|
+
imported: {
|
|
14567
|
+
source: opts.source ?? "external",
|
|
14568
|
+
...opts.note ? { note: opts.note } : {},
|
|
14569
|
+
importedAt: at
|
|
14570
|
+
}
|
|
14571
|
+
};
|
|
14572
|
+
}
|
|
14573
|
+
function unimportable(spec) {
|
|
14574
|
+
if (spec.character) return "a character is several files; import it with account adopt";
|
|
14575
|
+
if (spec.vfx) return "an effect is rendered from its recipe, not imported";
|
|
14576
|
+
if (!spec.outFile.toLowerCase().endsWith(".png")) return "only a single PNG output can be imported";
|
|
14577
|
+
return null;
|
|
14578
|
+
}
|
|
14579
|
+
async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
14580
|
+
if (opts.objectId && specs.length !== 1) {
|
|
14581
|
+
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
14582
|
+
}
|
|
14583
|
+
const imported = [];
|
|
14584
|
+
const skipped = [];
|
|
14585
|
+
for (const spec of specs) {
|
|
14586
|
+
const key = lockKey(spec.styleId, spec.assetId);
|
|
14587
|
+
const reason = unimportable(spec);
|
|
14588
|
+
if (reason) {
|
|
14589
|
+
skipped.push({ key, reason });
|
|
14590
|
+
continue;
|
|
14591
|
+
}
|
|
14592
|
+
if (!existsSync13(spec.outFile)) {
|
|
14593
|
+
skipped.push({ key, reason: `no file at ${spec.outFile}` });
|
|
14594
|
+
continue;
|
|
14595
|
+
}
|
|
14596
|
+
if (lock.entries[key] && !opts.force) {
|
|
14597
|
+
skipped.push({ key, reason: "already in the lockfile (use --force to replace it)" });
|
|
14598
|
+
continue;
|
|
14599
|
+
}
|
|
14600
|
+
let patch;
|
|
14601
|
+
try {
|
|
14602
|
+
patch = buildImportedEntry(spec, await readFile10(spec.outFile), opts);
|
|
14603
|
+
} catch (error) {
|
|
14604
|
+
skipped.push({ key, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
14605
|
+
continue;
|
|
14606
|
+
}
|
|
14607
|
+
if (opts.dryRun) {
|
|
14608
|
+
imported.push({ key, entry: patch });
|
|
14609
|
+
continue;
|
|
14610
|
+
}
|
|
14611
|
+
imported.push({ key, entry: upsert(lock, key, patch) });
|
|
14612
|
+
}
|
|
14613
|
+
if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
|
|
14614
|
+
return { imported, skipped };
|
|
14615
|
+
}
|
|
14616
|
+
async function reportSpecHashes(specs, lock) {
|
|
14617
|
+
const reports = [];
|
|
14618
|
+
for (const spec of specs) {
|
|
14619
|
+
const key = lockKey(spec.styleId, spec.assetId);
|
|
14620
|
+
let bytes = null;
|
|
14621
|
+
if (existsSync13(spec.outFile)) bytes = await readFile10(spec.outFile);
|
|
14622
|
+
let wouldImport = null;
|
|
14623
|
+
if (bytes && !unimportable(spec)) {
|
|
14624
|
+
try {
|
|
14625
|
+
wouldImport = buildImportedEntry(spec, bytes);
|
|
14626
|
+
} catch {
|
|
14627
|
+
wouldImport = null;
|
|
14628
|
+
}
|
|
14629
|
+
}
|
|
14630
|
+
const entry = lock.entries[key];
|
|
14631
|
+
const fileSha256 = bytes ? sha256(bytes) : null;
|
|
14632
|
+
const outputSha256 = entry?.outputs[0]?.sha256 ?? null;
|
|
14633
|
+
reports.push({
|
|
14634
|
+
key,
|
|
14635
|
+
specHash: spec.specHash,
|
|
14636
|
+
file: spec.outFile,
|
|
14637
|
+
fileSha256,
|
|
14638
|
+
lock: entry ? {
|
|
14639
|
+
specHash: entry.specHash,
|
|
14640
|
+
outputSha256,
|
|
14641
|
+
matches: entry.specHash === spec.specHash && outputSha256 !== null && outputSha256 === fileSha256
|
|
14642
|
+
} : null,
|
|
14643
|
+
wouldImport
|
|
14644
|
+
});
|
|
14645
|
+
}
|
|
14646
|
+
return reports;
|
|
14647
|
+
}
|
|
14648
|
+
|
|
14649
|
+
// src/pipeline/adopt.ts
|
|
14650
|
+
import { existsSync as existsSync15 } from "fs";
|
|
14651
|
+
import { readFile as readFile12, writeFile as writeFile8 } from "fs/promises";
|
|
14379
14652
|
import path18 from "path";
|
|
14380
14653
|
|
|
14381
14654
|
// src/cache.ts
|
|
14382
|
-
import { mkdir as mkdir7, readFile as
|
|
14383
|
-
import { existsSync as
|
|
14655
|
+
import { mkdir as mkdir7, readFile as readFile11, rename as rename5, rm as rm5, writeFile as writeFile7 } from "fs/promises";
|
|
14656
|
+
import { existsSync as existsSync14 } from "fs";
|
|
14384
14657
|
import pathModule from "path";
|
|
14385
14658
|
import { z as z4 } from "zod";
|
|
14386
14659
|
var HashCacheSchema = z4.object({
|
|
@@ -14395,10 +14668,10 @@ function isSha256Hash(value) {
|
|
|
14395
14668
|
function parseCache(value) {
|
|
14396
14669
|
return HashCacheSchema.parse(value);
|
|
14397
14670
|
}
|
|
14398
|
-
async function loadCache(
|
|
14399
|
-
if (!
|
|
14671
|
+
async function loadCache(path54) {
|
|
14672
|
+
if (!existsSync14(path54)) return { version: 1, hashes: {} };
|
|
14400
14673
|
try {
|
|
14401
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await
|
|
14674
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile11(path54, "utf8")));
|
|
14402
14675
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
14403
14676
|
return {
|
|
14404
14677
|
version: 1,
|
|
@@ -14410,18 +14683,18 @@ async function loadCache(path53) {
|
|
|
14410
14683
|
return { version: 1, hashes: {} };
|
|
14411
14684
|
}
|
|
14412
14685
|
}
|
|
14413
|
-
async function saveCache(
|
|
14686
|
+
async function saveCache(path54, cache) {
|
|
14414
14687
|
const sorted = {};
|
|
14415
14688
|
for (const key of Object.keys(cache.hashes).sort()) {
|
|
14416
14689
|
const hash = cache.hashes[key];
|
|
14417
14690
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key}`);
|
|
14418
14691
|
sorted[key] = hash;
|
|
14419
14692
|
}
|
|
14420
|
-
await mkdir7(pathModule.dirname(pathModule.resolve(
|
|
14421
|
-
const tmp = `${
|
|
14693
|
+
await mkdir7(pathModule.dirname(pathModule.resolve(path54)), { recursive: true });
|
|
14694
|
+
const tmp = `${path54}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
14422
14695
|
try {
|
|
14423
14696
|
await writeFile7(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
14424
|
-
await rename5(tmp,
|
|
14697
|
+
await rename5(tmp, path54);
|
|
14425
14698
|
} finally {
|
|
14426
14699
|
await rm5(tmp, { force: true });
|
|
14427
14700
|
}
|
|
@@ -14455,11 +14728,11 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14455
14728
|
const localByHash = /* @__PURE__ */ new Map();
|
|
14456
14729
|
const unmatchedLocal = [];
|
|
14457
14730
|
for (const spec of specs) {
|
|
14458
|
-
if (!
|
|
14731
|
+
if (!existsSync15(spec.outFile)) {
|
|
14459
14732
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
14460
14733
|
continue;
|
|
14461
14734
|
}
|
|
14462
|
-
const bytes = await
|
|
14735
|
+
const bytes = await readFile12(spec.outFile);
|
|
14463
14736
|
try {
|
|
14464
14737
|
decodePng(bytes);
|
|
14465
14738
|
} catch (err) {
|
|
@@ -14579,7 +14852,7 @@ async function writePromptsBack(manifestPath, lock, opts = {}) {
|
|
|
14579
14852
|
const log2 = opts.onProgress ?? (() => {
|
|
14580
14853
|
});
|
|
14581
14854
|
const selectedAssets = opts.assetIds ? new Set(opts.assetIds) : null;
|
|
14582
|
-
const raw = JSON.parse(await
|
|
14855
|
+
const raw = JSON.parse(await readFile12(manifestPath, "utf8"));
|
|
14583
14856
|
const best = /* @__PURE__ */ new Map();
|
|
14584
14857
|
for (const entry of Object.values(lock.entries)) {
|
|
14585
14858
|
if (opts.provider && entry.provider !== opts.provider) continue;
|
|
@@ -14612,8 +14885,8 @@ function formatUnmatchedRemote(objects, limit = 15) {
|
|
|
14612
14885
|
}
|
|
14613
14886
|
|
|
14614
14887
|
// src/pipeline/adopt-characters.ts
|
|
14615
|
-
import { existsSync as
|
|
14616
|
-
import { mkdir as mkdir8, readFile as
|
|
14888
|
+
import { existsSync as existsSync16 } from "fs";
|
|
14889
|
+
import { mkdir as mkdir8, readFile as readFile13, writeFile as writeFile9 } from "fs/promises";
|
|
14617
14890
|
import path19 from "path";
|
|
14618
14891
|
async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
14619
14892
|
const log2 = opts.onProgress ?? (() => {
|
|
@@ -14648,8 +14921,8 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
14648
14921
|
return bytes;
|
|
14649
14922
|
};
|
|
14650
14923
|
const southHash = async (character) => {
|
|
14651
|
-
const
|
|
14652
|
-
if (
|
|
14924
|
+
const cached2 = cache.hashes[`character:${character.id}`];
|
|
14925
|
+
if (cached2) return cached2;
|
|
14653
14926
|
if (!character.previewUrl || character.status !== "completed") return null;
|
|
14654
14927
|
try {
|
|
14655
14928
|
const hash = sha256(await download(character.previewUrl));
|
|
@@ -14665,8 +14938,8 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
14665
14938
|
const bytes = await download(source.url);
|
|
14666
14939
|
const hash = sha256(bytes);
|
|
14667
14940
|
const file = expectedOutputPath(spec, source.role, index, sources.length);
|
|
14668
|
-
if (
|
|
14669
|
-
if (sha256(await
|
|
14941
|
+
if (existsSync16(file)) {
|
|
14942
|
+
if (sha256(await readFile13(file)) !== hash) result.differing.push(path19.relative(process.cwd(), file));
|
|
14670
14943
|
} else {
|
|
14671
14944
|
await mkdir8(path19.dirname(file), { recursive: true });
|
|
14672
14945
|
await writeFile9(file, bytes);
|
|
@@ -14708,11 +14981,11 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
14708
14981
|
if (!match) throw new Error(`remoteId ${spec.remoteId} is not a character on this account`);
|
|
14709
14982
|
} else {
|
|
14710
14983
|
const south = expectedOutputPath(spec, "south", 0, spec.character.directions);
|
|
14711
|
-
if (!
|
|
14984
|
+
if (!existsSync16(south)) {
|
|
14712
14985
|
result.unmatched.push(`${key}: no remoteId and no ${path19.relative(process.cwd(), south)} to match by`);
|
|
14713
14986
|
return false;
|
|
14714
14987
|
}
|
|
14715
|
-
const localHash = sha256(await
|
|
14988
|
+
const localHash = sha256(await readFile13(south));
|
|
14716
14989
|
for (const candidate of remote) {
|
|
14717
14990
|
if (claimed.has(candidate.id)) continue;
|
|
14718
14991
|
if (await southHash(candidate) === localHash) {
|
|
@@ -14788,7 +15061,7 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
14788
15061
|
if (!match) throw new Error(`remoteId ${spec.remoteId} names no ${animation.direction} animation of character ${parentId}`);
|
|
14789
15062
|
} else {
|
|
14790
15063
|
const first = expectedOutputPath(spec, "frame-00", 0, 2);
|
|
14791
|
-
if (!
|
|
15064
|
+
if (!existsSync16(first)) {
|
|
14792
15065
|
const byName = candidates.find((a) => a.name === characterAnimationName(spec));
|
|
14793
15066
|
if (!byName) {
|
|
14794
15067
|
result.unmatched.push(`${key}: no remoteId and no ${path19.relative(process.cwd(), first)} to match by`);
|
|
@@ -14796,7 +15069,7 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
14796
15069
|
}
|
|
14797
15070
|
match = byName;
|
|
14798
15071
|
} else {
|
|
14799
|
-
const localHash = sha256(await
|
|
15072
|
+
const localHash = sha256(await readFile13(first));
|
|
14800
15073
|
for (const candidate of candidates) {
|
|
14801
15074
|
if (sha256(await download(candidate.frames[0])) === localHash) {
|
|
14802
15075
|
match = candidate;
|
|
@@ -14864,8 +15137,8 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
14864
15137
|
}
|
|
14865
15138
|
|
|
14866
15139
|
// src/pipeline/salvage.ts
|
|
14867
|
-
import { readFile as
|
|
14868
|
-
import { existsSync as
|
|
15140
|
+
import { readFile as readFile14 } from "fs/promises";
|
|
15141
|
+
import { existsSync as existsSync17 } from "fs";
|
|
14869
15142
|
import path20 from "path";
|
|
14870
15143
|
function providerClaimId(provider, objectId) {
|
|
14871
15144
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
@@ -14873,10 +15146,10 @@ function providerClaimId(provider, objectId) {
|
|
|
14873
15146
|
async function loadClaims(lockPaths, opts = {}) {
|
|
14874
15147
|
const claimed = /* @__PURE__ */ new Set();
|
|
14875
15148
|
for (const p of lockPaths) {
|
|
14876
|
-
if (!
|
|
15149
|
+
if (!existsSync17(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
14877
15150
|
let parsed;
|
|
14878
15151
|
try {
|
|
14879
|
-
parsed = parseLock(JSON.parse(await
|
|
15152
|
+
parsed = parseLock(JSON.parse(await readFile14(p, "utf8")));
|
|
14880
15153
|
} catch {
|
|
14881
15154
|
throw new Error(`Claim lockfile is malformed: ${p}`);
|
|
14882
15155
|
}
|
|
@@ -15053,7 +15326,7 @@ async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, cla
|
|
|
15053
15326
|
const siblings = [];
|
|
15054
15327
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
15055
15328
|
if (path20.resolve(siblingManifestPath) === own) continue;
|
|
15056
|
-
if (!
|
|
15329
|
+
if (!existsSync17(siblingManifestPath)) continue;
|
|
15057
15330
|
try {
|
|
15058
15331
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
15059
15332
|
siblings.push({ label: path20.basename(path20.dirname(siblingManifestPath)), manifest });
|
|
@@ -15176,8 +15449,8 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
15176
15449
|
}
|
|
15177
15450
|
|
|
15178
15451
|
// src/workspace.ts
|
|
15179
|
-
import { mkdir as mkdir9, readFile as
|
|
15180
|
-
import { existsSync as
|
|
15452
|
+
import { mkdir as mkdir9, readFile as readFile15, rename as rename6, rm as rm6, writeFile as writeFile10 } from "fs/promises";
|
|
15453
|
+
import { existsSync as existsSync18 } from "fs";
|
|
15181
15454
|
import path21 from "path";
|
|
15182
15455
|
import { z as z5 } from "zod";
|
|
15183
15456
|
var WorkspaceProjectSchema = z5.object({
|
|
@@ -15203,10 +15476,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
|
|
|
15203
15476
|
);
|
|
15204
15477
|
}
|
|
15205
15478
|
async function loadWorkspace(workspacePath) {
|
|
15206
|
-
if (!
|
|
15479
|
+
if (!existsSync18(workspacePath)) return { version: 1, projects: [] };
|
|
15207
15480
|
let raw;
|
|
15208
15481
|
try {
|
|
15209
|
-
raw = JSON.parse(await
|
|
15482
|
+
raw = JSON.parse(await readFile15(workspacePath, "utf8"));
|
|
15210
15483
|
} catch (err) {
|
|
15211
15484
|
throw new ProjectError(
|
|
15212
15485
|
`Workspace catalog at ${workspacePath} is malformed:
|
|
@@ -15255,14 +15528,14 @@ function validateWorkspace(ws, dir) {
|
|
|
15255
15528
|
message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
|
|
15256
15529
|
});
|
|
15257
15530
|
}
|
|
15258
|
-
if (!
|
|
15531
|
+
if (!existsSync18(manifestPath)) {
|
|
15259
15532
|
diagnostics.push({
|
|
15260
15533
|
id: "missing-manifest",
|
|
15261
15534
|
level: "error",
|
|
15262
15535
|
message: `project "${project.id}" manifest not found: ${manifestPath}`
|
|
15263
15536
|
});
|
|
15264
15537
|
}
|
|
15265
|
-
if (!
|
|
15538
|
+
if (!existsSync18(lockPath)) {
|
|
15266
15539
|
diagnostics.push({
|
|
15267
15540
|
id: "missing-lock",
|
|
15268
15541
|
level: "error",
|
|
@@ -15309,7 +15582,7 @@ function validateWorkspace(ws, dir) {
|
|
|
15309
15582
|
}
|
|
15310
15583
|
|
|
15311
15584
|
// src/pick/salvage-server.ts
|
|
15312
|
-
import { mkdir as mkdir10, writeFile as writeFile11, readFile as
|
|
15585
|
+
import { mkdir as mkdir10, writeFile as writeFile11, readFile as readFile17 } from "fs/promises";
|
|
15313
15586
|
import path22 from "path";
|
|
15314
15587
|
|
|
15315
15588
|
// src/pick/salvage-sheet.ts
|
|
@@ -15471,7 +15744,7 @@ refresh();
|
|
|
15471
15744
|
|
|
15472
15745
|
// src/pick/review-server.ts
|
|
15473
15746
|
import { createServer } from "http";
|
|
15474
|
-
import { readFile as
|
|
15747
|
+
import { readFile as readFile16 } from "fs/promises";
|
|
15475
15748
|
|
|
15476
15749
|
// src/open.ts
|
|
15477
15750
|
import { spawn } from "child_process";
|
|
@@ -15498,7 +15771,7 @@ function serveReviewPage(opts) {
|
|
|
15498
15771
|
if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
|
|
15499
15772
|
try {
|
|
15500
15773
|
const asset = opts.assets.get(req.url);
|
|
15501
|
-
const bytes = await
|
|
15774
|
+
const bytes = await readFile16(asset.path);
|
|
15502
15775
|
res.writeHead(200, {
|
|
15503
15776
|
"Content-Type": asset.contentType,
|
|
15504
15777
|
"Cache-Control": "no-store",
|
|
@@ -15690,7 +15963,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
15690
15963
|
}
|
|
15691
15964
|
}
|
|
15692
15965
|
await applyTags(provider, decisions, existingTags, { onProgress: log2, characters: characterMembers });
|
|
15693
|
-
const raw = JSON.parse(await
|
|
15966
|
+
const raw = JSON.parse(await readFile17(ctx.manifestPath, "utf8"));
|
|
15694
15967
|
for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
|
|
15695
15968
|
await writeFile11(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
|
|
15696
15969
|
await saveLock(ctx.lockPath, ctx.lock);
|
|
@@ -15702,7 +15975,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
15702
15975
|
|
|
15703
15976
|
// src/cli/project.ts
|
|
15704
15977
|
import path24 from "path";
|
|
15705
|
-
import { existsSync as
|
|
15978
|
+
import { existsSync as existsSync19 } from "fs";
|
|
15706
15979
|
|
|
15707
15980
|
// src/project.ts
|
|
15708
15981
|
import path23 from "path";
|
|
@@ -15714,8 +15987,14 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
|
|
|
15714
15987
|
if (path23.resolve(process.cwd()) !== root) loadEnvFiles(process.cwd());
|
|
15715
15988
|
}
|
|
15716
15989
|
const lockPath = path23.resolve(opts.lockPath ?? path23.join(root, "pixelkiln.lock.json"));
|
|
15717
|
-
|
|
15718
|
-
const
|
|
15990
|
+
let loaded = await loadManifest(absolute, { lenient: opts.lenient });
|
|
15991
|
+
const unresolved = [];
|
|
15992
|
+
const specs = await resolveSpecs(loaded, {
|
|
15993
|
+
styles: opts.styles ?? [],
|
|
15994
|
+
assets: opts.assets ?? [],
|
|
15995
|
+
...opts.lenient ? { onInvalid: (entry) => unresolved.push(entry) } : {}
|
|
15996
|
+
});
|
|
15997
|
+
if (unresolved.length) loaded = { ...loaded, invalid: [...loaded.invalid ?? [], ...unresolved] };
|
|
15719
15998
|
const lock = await loadLock(lockPath);
|
|
15720
15999
|
normalizeLockOutputPaths(lock, specs);
|
|
15721
16000
|
const adapters = /* @__PURE__ */ new Map();
|
|
@@ -15848,7 +16127,7 @@ async function provenanceFile(id, file) {
|
|
|
15848
16127
|
return {
|
|
15849
16128
|
id,
|
|
15850
16129
|
path: absolute,
|
|
15851
|
-
sha256:
|
|
16130
|
+
sha256: existsSync19(absolute) ? await sha256File(absolute) : null,
|
|
15852
16131
|
included: true
|
|
15853
16132
|
};
|
|
15854
16133
|
}
|
|
@@ -15920,7 +16199,7 @@ function budgetsForPlan(plan, args) {
|
|
|
15920
16199
|
return out;
|
|
15921
16200
|
}
|
|
15922
16201
|
async function requireCompleteWorkspaceClaims(workspacePath) {
|
|
15923
|
-
if (!
|
|
16202
|
+
if (!existsSync19(workspacePath)) {
|
|
15924
16203
|
throw new ProjectError(`Workspace catalog not found: ${workspacePath}`);
|
|
15925
16204
|
}
|
|
15926
16205
|
const dir = path24.dirname(path24.resolve(workspacePath));
|
|
@@ -15946,15 +16225,16 @@ async function openAccountProject(args) {
|
|
|
15946
16225
|
return project;
|
|
15947
16226
|
}
|
|
15948
16227
|
async function open(args) {
|
|
15949
|
-
if (!
|
|
16228
|
+
if (!existsSync19(path24.resolve(args.manifest))) {
|
|
15950
16229
|
throw new ProjectError(
|
|
15951
16230
|
`No manifest at ${path24.resolve(args.manifest)}. Pass --manifest, or run \`pixelkiln init --from <dir>\`.`
|
|
15952
16231
|
);
|
|
15953
16232
|
}
|
|
15954
|
-
const
|
|
16233
|
+
const lenient = (args.command === "plan" || args.command === "hash" || args.command === "doctor") && !args.strict;
|
|
16234
|
+
const project = await openProject(args.manifest, { lockPath: args.lock, styles: args.styles, assets: args.assets, lenient });
|
|
15955
16235
|
const { loaded, lock } = project;
|
|
15956
16236
|
let specs = project.specs;
|
|
15957
|
-
const accountProvider = ACCOUNT_COMMANDS.has(args.command) ? accountProviderId(loaded.manifest, args.provider, args.command) : void 0;
|
|
16237
|
+
const accountProvider = ACCOUNT_COMMANDS.has(args.command) && !args.local ? accountProviderId(loaded.manifest, args.provider, args.command) : void 0;
|
|
15958
16238
|
if (args.provider && !accountProvider) {
|
|
15959
16239
|
throw new UsageError("--provider is only used by balance, adopt, salvage, purge, or workspace add.");
|
|
15960
16240
|
}
|
|
@@ -16000,7 +16280,35 @@ async function runBalance(args) {
|
|
|
16000
16280
|
log(` plan: ${b.plan ?? "n/a"}`);
|
|
16001
16281
|
log(` remaining: ${formatCost(b.unit, b.remaining)}${b.total ? ` of ${b.total}` : ""}`);
|
|
16002
16282
|
}
|
|
16283
|
+
async function runAdoptLocal(args) {
|
|
16284
|
+
if (args.tag || args.writePrompts) {
|
|
16285
|
+
throw new UsageError("--tag and --write-prompts talk to the account; they cannot be combined with --local.");
|
|
16286
|
+
}
|
|
16287
|
+
const { specs, lock } = await openProject2(args);
|
|
16288
|
+
const result = await importLocal(specs, lock, args.lock, {
|
|
16289
|
+
source: args.source,
|
|
16290
|
+
note: args.note,
|
|
16291
|
+
objectId: args.objectId,
|
|
16292
|
+
force: args.force,
|
|
16293
|
+
dryRun: args.dryRun
|
|
16294
|
+
});
|
|
16295
|
+
if (args.json) {
|
|
16296
|
+
log(JSON.stringify({
|
|
16297
|
+
dryRun: args.dryRun,
|
|
16298
|
+
imported: result.imported.map(({ key, entry }) => ({ key, entry })),
|
|
16299
|
+
skipped: result.skipped
|
|
16300
|
+
}, null, 2));
|
|
16301
|
+
return;
|
|
16302
|
+
}
|
|
16303
|
+
for (const { key, entry } of result.imported) {
|
|
16304
|
+
log(` ${args.dryRun ? "would import" : "imported"} ${key} ${entry.outputs?.[0]?.sha256.slice(0, 12)}`);
|
|
16305
|
+
}
|
|
16306
|
+
for (const { key, reason } of result.skipped) log(` skipped ${key}: ${reason}`);
|
|
16307
|
+
log(`
|
|
16308
|
+
${result.imported.length} ${args.dryRun ? "to import" : "imported"}, ${result.skipped.length} skipped (offline; no provider contacted)`);
|
|
16309
|
+
}
|
|
16003
16310
|
async function runAdopt(args) {
|
|
16311
|
+
if (args.local) return runAdoptLocal(args);
|
|
16004
16312
|
const { loaded, specs, lock, accountProvider } = await openAccountProject(args);
|
|
16005
16313
|
const providerFor = providerCache("online");
|
|
16006
16314
|
const provider = providerFor(accountProvider);
|
|
@@ -16112,7 +16420,7 @@ async function runSalvage2(args) {
|
|
|
16112
16420
|
const lockPaths = [
|
|
16113
16421
|
.../* @__PURE__ */ new Set([
|
|
16114
16422
|
...workspaceLockPaths,
|
|
16115
|
-
...
|
|
16423
|
+
...existsSync20(ownLock) ? [ownLock] : [],
|
|
16116
16424
|
...args.claims.map((c) => path25.resolve(c))
|
|
16117
16425
|
])
|
|
16118
16426
|
];
|
|
@@ -16374,13 +16682,13 @@ async function runTag(args) {
|
|
|
16374
16682
|
import path28 from "path";
|
|
16375
16683
|
|
|
16376
16684
|
// src/pipeline/hand-edit.ts
|
|
16377
|
-
import { existsSync as
|
|
16378
|
-
import { copyFile, mkdir as mkdir11, readFile as
|
|
16685
|
+
import { existsSync as existsSync21 } from "fs";
|
|
16686
|
+
import { copyFile, mkdir as mkdir11, readFile as readFile19, rename as rename8, rm as rm8, writeFile as writeFile13 } from "fs/promises";
|
|
16379
16687
|
import path27 from "path";
|
|
16380
16688
|
import { z as z7 } from "zod";
|
|
16381
16689
|
|
|
16382
16690
|
// src/manifest-edit.ts
|
|
16383
|
-
import { readFile as
|
|
16691
|
+
import { readFile as readFile18, rename as rename7, rm as rm7, writeFile as writeFile12 } from "fs/promises";
|
|
16384
16692
|
import path26 from "path";
|
|
16385
16693
|
import { z as z6 } from "zod";
|
|
16386
16694
|
var HexSha = z6.string().regex(/^[0-9a-f]{64}$/);
|
|
@@ -16805,7 +17113,7 @@ function applyEdit(raw, edit) {
|
|
|
16805
17113
|
}
|
|
16806
17114
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
16807
17115
|
const absolute = path26.resolve(manifestPath);
|
|
16808
|
-
const original = await
|
|
17116
|
+
const original = await readFile18(absolute, "utf8");
|
|
16809
17117
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
16810
17118
|
let raw;
|
|
16811
17119
|
try {
|
|
@@ -16910,10 +17218,10 @@ function handEditBases(spec, lock) {
|
|
|
16910
17218
|
}));
|
|
16911
17219
|
if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
|
|
16912
17220
|
if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
|
|
16913
|
-
if (!members.every((member) =>
|
|
17221
|
+
if (!members.every((member) => existsSync21(member.path))) return null;
|
|
16914
17222
|
return members.map(({ role, path: file }) => ({ role, path: file }));
|
|
16915
17223
|
}
|
|
16916
|
-
return
|
|
17224
|
+
return existsSync21(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
|
|
16917
17225
|
}
|
|
16918
17226
|
function handEditMembers(loaded, spec, lock, editPath) {
|
|
16919
17227
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -16944,7 +17252,7 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
16944
17252
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
16945
17253
|
let created = false;
|
|
16946
17254
|
for (const member of members) {
|
|
16947
|
-
if (
|
|
17255
|
+
if (existsSync21(member.path)) continue;
|
|
16948
17256
|
if (!member.base) {
|
|
16949
17257
|
throw new ManifestEditError(
|
|
16950
17258
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
@@ -17029,7 +17337,7 @@ function handEditProjectPath(editPath) {
|
|
|
17029
17337
|
async function readHandEditCompanion(editPath) {
|
|
17030
17338
|
let text;
|
|
17031
17339
|
try {
|
|
17032
|
-
text = await
|
|
17340
|
+
text = await readFile19(handEditCompanionPath(editPath), "utf8");
|
|
17033
17341
|
} catch {
|
|
17034
17342
|
return null;
|
|
17035
17343
|
}
|
|
@@ -17072,7 +17380,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
17072
17380
|
}
|
|
17073
17381
|
});
|
|
17074
17382
|
const bases = handEditBases(spec, lock);
|
|
17075
|
-
const expectedSize = bases?.[0] ? decodePng(await
|
|
17383
|
+
const expectedSize = bases?.[0] ? decodePng(await readFile19(bases[0].path)) : { width: spec.width, height: spec.height };
|
|
17076
17384
|
for (const [index, image] of decoded.entries()) {
|
|
17077
17385
|
if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
|
|
17078
17386
|
const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
|
|
@@ -17159,21 +17467,21 @@ async function runEdit(args) {
|
|
|
17159
17467
|
|
|
17160
17468
|
// src/cli/commands/gallery.ts
|
|
17161
17469
|
import path38 from "path";
|
|
17162
|
-
import { existsSync as
|
|
17470
|
+
import { existsSync as existsSync31 } from "fs";
|
|
17163
17471
|
|
|
17164
17472
|
// src/gallery/snapshot.ts
|
|
17165
17473
|
import { createHash as createHash4 } from "crypto";
|
|
17166
|
-
import { existsSync as
|
|
17167
|
-
import { readFile as
|
|
17474
|
+
import { existsSync as existsSync26 } from "fs";
|
|
17475
|
+
import { readFile as readFile23, stat as stat2 } from "fs/promises";
|
|
17168
17476
|
import path34 from "path";
|
|
17169
17477
|
|
|
17170
17478
|
// src/gallery/edit.ts
|
|
17171
|
-
import { readFile as
|
|
17479
|
+
import { readFile as readFile22, rename as rename9, writeFile as writeFile17 } from "fs/promises";
|
|
17172
17480
|
import path32 from "path";
|
|
17173
17481
|
import { z as z11 } from "zod";
|
|
17174
17482
|
|
|
17175
17483
|
// src/gallery/upload.ts
|
|
17176
|
-
import { existsSync as
|
|
17484
|
+
import { existsSync as existsSync22 } from "fs";
|
|
17177
17485
|
import { mkdir as mkdir12, writeFile as writeFile14 } from "fs/promises";
|
|
17178
17486
|
import path29 from "path";
|
|
17179
17487
|
import { z as z8 } from "zod";
|
|
@@ -17205,7 +17513,7 @@ async function saveProjectImage(root, request) {
|
|
|
17205
17513
|
if (metadata.format !== expected) {
|
|
17206
17514
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
17207
17515
|
}
|
|
17208
|
-
if (
|
|
17516
|
+
if (existsSync22(file) && !request.overwrite) {
|
|
17209
17517
|
throw new ManifestEditError(`${relative.split(path29.sep).join("/")} already exists; choose another name, or replace it`);
|
|
17210
17518
|
}
|
|
17211
17519
|
await mkdir12(path29.dirname(file), { recursive: true });
|
|
@@ -17214,8 +17522,8 @@ async function saveProjectImage(root, request) {
|
|
|
17214
17522
|
}
|
|
17215
17523
|
|
|
17216
17524
|
// src/gallery/image-revision.ts
|
|
17217
|
-
import { existsSync as
|
|
17218
|
-
import { readFile as
|
|
17525
|
+
import { existsSync as existsSync23 } from "fs";
|
|
17526
|
+
import { readFile as readFile20, rm as rm9, writeFile as writeFile15 } from "fs/promises";
|
|
17219
17527
|
import path30 from "path";
|
|
17220
17528
|
import { z as z9 } from "zod";
|
|
17221
17529
|
var InpaintRevisionRequestSchema = z9.object({
|
|
@@ -17243,7 +17551,7 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
17243
17551
|
const metadata = imageMetadata(bytes);
|
|
17244
17552
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
17245
17553
|
const file = path30.resolve(root, request.maskPath);
|
|
17246
|
-
const previous =
|
|
17554
|
+
const previous = existsSync23(file) ? await readFile20(file) : null;
|
|
17247
17555
|
const mask = await saveProjectImage(root, {
|
|
17248
17556
|
action: "upload-image",
|
|
17249
17557
|
path: request.maskPath,
|
|
@@ -17270,8 +17578,8 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
17270
17578
|
}
|
|
17271
17579
|
|
|
17272
17580
|
// src/gallery/skeleton.ts
|
|
17273
|
-
import { existsSync as
|
|
17274
|
-
import { mkdir as mkdir13, readFile as
|
|
17581
|
+
import { existsSync as existsSync24 } from "fs";
|
|
17582
|
+
import { mkdir as mkdir13, readFile as readFile21, rm as rm10, writeFile as writeFile16 } from "fs/promises";
|
|
17275
17583
|
import path31 from "path";
|
|
17276
17584
|
import { z as z10 } from "zod";
|
|
17277
17585
|
var SkeletonEstimateRequestSchema = z10.object({
|
|
@@ -17313,7 +17621,7 @@ var SkeletonKeypointsUpdateSchema = z10.object({
|
|
|
17313
17621
|
var DEFAULT_ESTIMATE_LIMIT = 10;
|
|
17314
17622
|
function skeletonSourceFile(spec) {
|
|
17315
17623
|
if (spec.source) return path31.resolve(spec.root, spec.source);
|
|
17316
|
-
if (spec.quality &&
|
|
17624
|
+
if (spec.quality && existsSync24(spec.quality.outFile)) return spec.quality.outFile;
|
|
17317
17625
|
return spec.outFile;
|
|
17318
17626
|
}
|
|
17319
17627
|
function createGallerySkeletonHandlers(opts) {
|
|
@@ -17334,8 +17642,8 @@ function createGallerySkeletonHandlers(opts) {
|
|
|
17334
17642
|
const spec = ctx.specs.find((candidate) => lockKey(candidate.styleId, candidate.assetId) === key);
|
|
17335
17643
|
if (!spec) throw new ManifestEditError(`"${key}" is not declared by the manifest`);
|
|
17336
17644
|
const file = skeletonSourceFile(spec);
|
|
17337
|
-
if (!
|
|
17338
|
-
const bytes = await
|
|
17645
|
+
if (!existsSync24(file)) throw new ManifestEditError(`${key} has no image on disk to estimate from`);
|
|
17646
|
+
const bytes = await readFile21(file);
|
|
17339
17647
|
const metadata = imageMetadata(bytes);
|
|
17340
17648
|
if (!metadata) throw new ManifestEditError(`${path31.basename(file)} is not a readable PNG or JPEG`);
|
|
17341
17649
|
const problem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
|
|
@@ -17374,13 +17682,13 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
17374
17682
|
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path31.isAbsolute(relative)) {
|
|
17375
17683
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
17376
17684
|
}
|
|
17377
|
-
const existed =
|
|
17685
|
+
const existed = existsSync24(file);
|
|
17378
17686
|
let previous = null;
|
|
17379
17687
|
if (request.set) {
|
|
17380
17688
|
if (existed && !request.overwrite) {
|
|
17381
17689
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
17382
17690
|
}
|
|
17383
|
-
if (existed) previous = await
|
|
17691
|
+
if (existed) previous = await readFile21(file);
|
|
17384
17692
|
await mkdir13(path31.dirname(file), { recursive: true });
|
|
17385
17693
|
await writeFile16(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
17386
17694
|
} else if (!existed) {
|
|
@@ -17422,7 +17730,7 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
17422
17730
|
if (relative.startsWith("..") || path31.isAbsolute(relative)) {
|
|
17423
17731
|
throw new ManifestEditError(`${key}'s keypoints file is outside the project; edit it by hand`);
|
|
17424
17732
|
}
|
|
17425
|
-
const current =
|
|
17733
|
+
const current = existsSync24(file) ? sha256(await readFile21(file)) : null;
|
|
17426
17734
|
if (current !== request.expectedSha256) {
|
|
17427
17735
|
throw Object.assign(
|
|
17428
17736
|
new Error(`${relative.split(path31.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
@@ -17494,7 +17802,7 @@ function createGalleryEditHandler(opts) {
|
|
|
17494
17802
|
if (undo.success) {
|
|
17495
17803
|
const manifestPath2 = await manifestOf(undo.data.project);
|
|
17496
17804
|
if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
|
|
17497
|
-
const current = await
|
|
17805
|
+
const current = await readFile22(manifestPath2, "utf8");
|
|
17498
17806
|
if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
|
|
17499
17807
|
const stack = history.get(manifestPath2) ?? [];
|
|
17500
17808
|
const last = stack[stack.length - 1];
|
|
@@ -17511,10 +17819,10 @@ function createGalleryEditHandler(opts) {
|
|
|
17511
17819
|
return opts.reload();
|
|
17512
17820
|
}
|
|
17513
17821
|
const manifestPath = await manifestOf(body?.project);
|
|
17514
|
-
const before = manifestPath ? await
|
|
17822
|
+
const before = manifestPath ? await readFile22(manifestPath, "utf8").catch(() => null) : null;
|
|
17515
17823
|
const build = await apply(body);
|
|
17516
17824
|
if (manifestPath && before !== null) {
|
|
17517
|
-
const after = await
|
|
17825
|
+
const after = await readFile22(manifestPath, "utf8").catch(() => null);
|
|
17518
17826
|
if (after !== null && after !== before) {
|
|
17519
17827
|
const stack = history.get(manifestPath) ?? [];
|
|
17520
17828
|
stack.push({ before, afterSha: sha256(after) });
|
|
@@ -17687,7 +17995,7 @@ function createGalleryPriceHandler(opts) {
|
|
|
17687
17995
|
}
|
|
17688
17996
|
|
|
17689
17997
|
// src/pipeline/history.ts
|
|
17690
|
-
import { existsSync as
|
|
17998
|
+
import { existsSync as existsSync25 } from "fs";
|
|
17691
17999
|
import path33 from "path";
|
|
17692
18000
|
var HISTORY_ENV = "PIXELKILN_HISTORY";
|
|
17693
18001
|
function historyLimit(manifest, env = process.env) {
|
|
@@ -17778,7 +18086,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
17778
18086
|
}
|
|
17779
18087
|
for (let i = 0; i < entry.outputs.length; i++) {
|
|
17780
18088
|
const file = currentEntryOutputPath(entry, spec, i);
|
|
17781
|
-
if (!
|
|
18089
|
+
if (!existsSync25(file)) continue;
|
|
17782
18090
|
if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
|
|
17783
18091
|
throw new OverwriteRefusedError(
|
|
17784
18092
|
`${path33.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
|
|
@@ -17868,7 +18176,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
17868
18176
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
17869
18177
|
const file = path34.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
17870
18178
|
let url = null;
|
|
17871
|
-
if (
|
|
18179
|
+
if (existsSync26(file)) {
|
|
17872
18180
|
const id = galleryMediaId(file);
|
|
17873
18181
|
media.set(id, { path: file, contentType: mediaType });
|
|
17874
18182
|
url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
|
|
@@ -17900,7 +18208,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
17900
18208
|
var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
|
|
17901
18209
|
async function samePixels(a, b) {
|
|
17902
18210
|
try {
|
|
17903
|
-
const [left, right] = await Promise.all([
|
|
18211
|
+
const [left, right] = await Promise.all([readFile23(a), readFile23(b)]);
|
|
17904
18212
|
if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
|
|
17905
18213
|
const x = decodePng(left);
|
|
17906
18214
|
const y = decodePng(right);
|
|
@@ -18001,7 +18309,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
18001
18309
|
outputPaths.map((file) => describeOutput(media, root, path34.resolve(root, file)))
|
|
18002
18310
|
);
|
|
18003
18311
|
const recordPath = path34.resolve(root, inspection.record);
|
|
18004
|
-
const recordExists =
|
|
18312
|
+
const recordExists = existsSync26(recordPath);
|
|
18005
18313
|
let options = null;
|
|
18006
18314
|
let check = null;
|
|
18007
18315
|
if (recordExists) {
|
|
@@ -18058,7 +18366,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18058
18366
|
const media = /* @__PURE__ */ new Map();
|
|
18059
18367
|
const plan = await buildPlan(specs, lock);
|
|
18060
18368
|
const items = [];
|
|
18061
|
-
const manifestText = await
|
|
18369
|
+
const manifestText = await readFile23(loaded.path, "utf8");
|
|
18062
18370
|
const manifestSha256 = sha256(manifestText);
|
|
18063
18371
|
const cacheDir = path34.resolve(path34.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
18064
18372
|
let rawStyles = {};
|
|
@@ -18089,7 +18397,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18089
18397
|
const editShas = await Promise.all(
|
|
18090
18398
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
18091
18399
|
const file = sourceOutputPath(spec.source, entry, index, root);
|
|
18092
|
-
return { file, sha256:
|
|
18400
|
+
return { file, sha256: existsSync26(file) ? await sha256File(file) : null };
|
|
18093
18401
|
})
|
|
18094
18402
|
);
|
|
18095
18403
|
edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
|
|
@@ -18097,7 +18405,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18097
18405
|
const companion = await readHandEditCompanion(editPath);
|
|
18098
18406
|
if (companion) {
|
|
18099
18407
|
const projectPath = handEditProjectPath(editPath);
|
|
18100
|
-
const project = companion.project &&
|
|
18408
|
+
const project = companion.project && existsSync26(projectPath) ? await fileInfo(projectPath) : null;
|
|
18101
18409
|
let projectUrl = null;
|
|
18102
18410
|
if (project) {
|
|
18103
18411
|
const id = galleryMediaId(projectPath);
|
|
@@ -18134,7 +18442,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18134
18442
|
}
|
|
18135
18443
|
} else if (spec.source) {
|
|
18136
18444
|
outputs = [await describeOutput(media, root, path34.resolve(root, spec.source))];
|
|
18137
|
-
} else if (!entry &&
|
|
18445
|
+
} else if (!entry && existsSync26(spec.outFile)) {
|
|
18138
18446
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
18139
18447
|
} else {
|
|
18140
18448
|
outputs = [];
|
|
@@ -18411,7 +18719,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
18411
18719
|
root: loaded.root,
|
|
18412
18720
|
provider: loaded.manifest.provider,
|
|
18413
18721
|
account: project.account ?? null,
|
|
18414
|
-
manifestSha256: manifestSha256 ?? sha256(await
|
|
18722
|
+
manifestSha256: manifestSha256 ?? sha256(await readFile23(manifestPath, "utf8")),
|
|
18415
18723
|
historyLimit: historyLimit(loaded.manifest),
|
|
18416
18724
|
entries: Object.keys(lock.entries).length,
|
|
18417
18725
|
items: projectItems.length,
|
|
@@ -18470,10 +18778,10 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
18470
18778
|
// src/gallery/server.ts
|
|
18471
18779
|
import { randomBytes } from "crypto";
|
|
18472
18780
|
import { createServer as createServer2 } from "http";
|
|
18473
|
-
import { readFile as
|
|
18781
|
+
import { readFile as readFile24 } from "fs/promises";
|
|
18474
18782
|
|
|
18475
18783
|
// src/gallery/page.ts
|
|
18476
|
-
import { existsSync as
|
|
18784
|
+
import { existsSync as existsSync27, readFileSync as readFileSync6 } from "fs";
|
|
18477
18785
|
|
|
18478
18786
|
// src/gallery/client-bundle.ts
|
|
18479
18787
|
import { createRequire } from "module";
|
|
@@ -18513,8 +18821,8 @@ var client;
|
|
|
18513
18821
|
function clientAssets() {
|
|
18514
18822
|
const prebuilt = new URL("gallery.js", CLIENT_DIR);
|
|
18515
18823
|
client ??= {
|
|
18516
|
-
css:
|
|
18517
|
-
js:
|
|
18824
|
+
css: readFileSync6(new URL("gallery.css", CLIENT_DIR), "utf8"),
|
|
18825
|
+
js: existsSync27(prebuilt) ? readFileSync6(prebuilt, "utf8") : bundleGalleryClient()
|
|
18518
18826
|
};
|
|
18519
18827
|
return client;
|
|
18520
18828
|
}
|
|
@@ -18785,7 +19093,7 @@ async function serveGallery(opts) {
|
|
|
18785
19093
|
const asset = reviewAssets.get(jobId)?.get(url2.pathname);
|
|
18786
19094
|
if (!asset) return fail(404, "no such review asset");
|
|
18787
19095
|
try {
|
|
18788
|
-
const bytes = await
|
|
19096
|
+
const bytes = await readFile24(asset.path);
|
|
18789
19097
|
res.writeHead(200, {
|
|
18790
19098
|
"Content-Type": asset.contentType,
|
|
18791
19099
|
"Cache-Control": "no-store",
|
|
@@ -18868,7 +19176,7 @@ async function serveGallery(opts) {
|
|
|
18868
19176
|
if (!asset) return fail(404, "no such gallery media");
|
|
18869
19177
|
let bytes;
|
|
18870
19178
|
try {
|
|
18871
|
-
bytes = await
|
|
19179
|
+
bytes = await readFile24(asset.path);
|
|
18872
19180
|
} catch {
|
|
18873
19181
|
return fail(404, "gallery media is no longer on disk; refresh the page");
|
|
18874
19182
|
}
|
|
@@ -19361,12 +19669,12 @@ function ownedReferenceImageId(spec, lock, providerId) {
|
|
|
19361
19669
|
}
|
|
19362
19670
|
|
|
19363
19671
|
// src/pick/server.ts
|
|
19364
|
-
import { existsSync as
|
|
19365
|
-
import { readFile as
|
|
19672
|
+
import { existsSync as existsSync29 } from "fs";
|
|
19673
|
+
import { readFile as readFile26 } from "fs/promises";
|
|
19366
19674
|
|
|
19367
19675
|
// src/pipeline/init.ts
|
|
19368
|
-
import { readdir, readFile as
|
|
19369
|
-
import { existsSync as
|
|
19676
|
+
import { readdir, readFile as readFile25, writeFile as writeFile18 } from "fs/promises";
|
|
19677
|
+
import { existsSync as existsSync28 } from "fs";
|
|
19370
19678
|
import path35 from "path";
|
|
19371
19679
|
function pngSize(buf) {
|
|
19372
19680
|
if (buf.length < 24) return null;
|
|
@@ -19395,7 +19703,7 @@ async function scanAssets(root, opts = {}) {
|
|
|
19395
19703
|
const skipped = [];
|
|
19396
19704
|
const seen = /* @__PURE__ */ new Map();
|
|
19397
19705
|
for (const file of files.sort()) {
|
|
19398
|
-
const size = pngSize(await
|
|
19706
|
+
const size = pngSize(await readFile25(file));
|
|
19399
19707
|
if (!size) {
|
|
19400
19708
|
skipped.push(`${file} (not a readable PNG)`);
|
|
19401
19709
|
continue;
|
|
@@ -19460,7 +19768,7 @@ function mode(values) {
|
|
|
19460
19768
|
return [...counts.entries()].sort((a, b) => b[1] - a[1])[0]?.[0] ?? 64;
|
|
19461
19769
|
}
|
|
19462
19770
|
async function writeManifestFile(target, manifest) {
|
|
19463
|
-
if (
|
|
19771
|
+
if (existsSync28(target)) {
|
|
19464
19772
|
throw new Error(`${target} already exists; refusing to overwrite an existing manifest.`);
|
|
19465
19773
|
}
|
|
19466
19774
|
await writeFile18(target, JSON.stringify(manifest, null, 2) + "\n");
|
|
@@ -19886,13 +20194,13 @@ async function currentArt(entry, spec) {
|
|
|
19886
20194
|
const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
|
|
19887
20195
|
if (!previous) return null;
|
|
19888
20196
|
const file = resolveOutputPath(previous.path, spec.root);
|
|
19889
|
-
if (!
|
|
20197
|
+
if (!existsSync29(file)) return null;
|
|
19890
20198
|
const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
|
|
19891
20199
|
if (!contentType) return null;
|
|
19892
20200
|
let width = entry.width;
|
|
19893
20201
|
let height = entry.height;
|
|
19894
20202
|
if (contentType === "image/png") {
|
|
19895
|
-
const size = pngSize(await
|
|
20203
|
+
const size = pngSize(await readFile26(file));
|
|
19896
20204
|
if (size) ({ width, height } = size);
|
|
19897
20205
|
}
|
|
19898
20206
|
return { path: file, contentType, width, height };
|
|
@@ -19900,7 +20208,7 @@ async function currentArt(entry, spec) {
|
|
|
19900
20208
|
async function cachedFrame(url) {
|
|
19901
20209
|
if (!url.startsWith("file://")) return null;
|
|
19902
20210
|
const file = url.slice("file://".length);
|
|
19903
|
-
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await
|
|
20211
|
+
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await readFile26(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
|
|
19904
20212
|
return { path: file, contentType };
|
|
19905
20213
|
}
|
|
19906
20214
|
async function prepareReview(provider, lock, opts = {}) {
|
|
@@ -19926,15 +20234,15 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
19926
20234
|
const frameAssets = [];
|
|
19927
20235
|
const frameSizes = [];
|
|
19928
20236
|
for (const [index, url] of urls.entries()) {
|
|
19929
|
-
const
|
|
19930
|
-
if (!
|
|
20237
|
+
const cached2 = await cachedFrame(url);
|
|
20238
|
+
if (!cached2) {
|
|
19931
20239
|
frameUrls.push(url);
|
|
19932
20240
|
frameSizes.push(null);
|
|
19933
20241
|
continue;
|
|
19934
20242
|
}
|
|
19935
|
-
frameSizes.push(
|
|
20243
|
+
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await readFile26(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
19936
20244
|
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
19937
|
-
frameAssets.push([route,
|
|
20245
|
+
frameAssets.push([route, cached2]);
|
|
19938
20246
|
frameUrls.push(route);
|
|
19939
20247
|
}
|
|
19940
20248
|
const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String(groups.length))}` : null;
|
|
@@ -20450,13 +20758,13 @@ function createGenerateHandlers(opts) {
|
|
|
20450
20758
|
}
|
|
20451
20759
|
|
|
20452
20760
|
// src/gallery/editor.ts
|
|
20453
|
-
import { readFile as
|
|
20761
|
+
import { readFile as readFile28 } from "fs/promises";
|
|
20454
20762
|
import path37 from "path";
|
|
20455
20763
|
|
|
20456
20764
|
// src/editor/install.ts
|
|
20457
20765
|
import { createHash as createHash5 } from "crypto";
|
|
20458
|
-
import { existsSync as
|
|
20459
|
-
import { mkdir as mkdir14, readFile as
|
|
20766
|
+
import { existsSync as existsSync30 } from "fs";
|
|
20767
|
+
import { mkdir as mkdir14, readFile as readFile27, rename as rename10, rm as rm11, stat as stat3, writeFile as writeFile19 } from "fs/promises";
|
|
20460
20768
|
import os3 from "os";
|
|
20461
20769
|
import path36 from "path";
|
|
20462
20770
|
|
|
@@ -20540,7 +20848,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
|
|
|
20540
20848
|
}
|
|
20541
20849
|
async function sha256Of(file) {
|
|
20542
20850
|
try {
|
|
20543
|
-
return createHash5("sha256").update(await
|
|
20851
|
+
return createHash5("sha256").update(await readFile27(file)).digest("hex");
|
|
20544
20852
|
} catch {
|
|
20545
20853
|
return null;
|
|
20546
20854
|
}
|
|
@@ -20554,7 +20862,7 @@ async function editorStatus(opts = {}) {
|
|
|
20554
20862
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
20555
20863
|
totalBytes += expected.bytes;
|
|
20556
20864
|
const file = path36.join(dir, name);
|
|
20557
|
-
const info =
|
|
20865
|
+
const info = existsSync30(file) ? await stat3(file).catch(() => null) : null;
|
|
20558
20866
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
20559
20867
|
installedBytes += expected.bytes;
|
|
20560
20868
|
} else {
|
|
@@ -20733,7 +21041,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
20733
21041
|
if (!status.installed) return null;
|
|
20734
21042
|
let bytes;
|
|
20735
21043
|
try {
|
|
20736
|
-
bytes = await
|
|
21044
|
+
bytes = await readFile28(path37.join(dir, name));
|
|
20737
21045
|
} catch {
|
|
20738
21046
|
verified = null;
|
|
20739
21047
|
return null;
|
|
@@ -20842,7 +21150,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
20842
21150
|
async function runGallery(args) {
|
|
20843
21151
|
if (args.workspace) {
|
|
20844
21152
|
const workspacePath = path38.resolve(args.workspace);
|
|
20845
|
-
if (!
|
|
21153
|
+
if (!existsSync31(workspacePath)) {
|
|
20846
21154
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
20847
21155
|
}
|
|
20848
21156
|
const filter2 = { styles: args.styles, assets: args.assets };
|
|
@@ -21196,14 +21504,14 @@ async function runRestoreGeneration(args) {
|
|
|
21196
21504
|
}
|
|
21197
21505
|
|
|
21198
21506
|
// src/cli/commands/housekeeping.ts
|
|
21199
|
-
import { existsSync as
|
|
21507
|
+
import { existsSync as existsSync33 } from "fs";
|
|
21200
21508
|
|
|
21201
21509
|
// src/pipeline/cache-health.ts
|
|
21202
|
-
import { existsSync as
|
|
21203
|
-
import { readFile as
|
|
21510
|
+
import { existsSync as existsSync32 } from "fs";
|
|
21511
|
+
import { readFile as readFile29, readdir as readdir2, rm as rm12 } from "fs/promises";
|
|
21204
21512
|
import path39 from "path";
|
|
21205
21513
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
21206
|
-
if (options.prune && !
|
|
21514
|
+
if (options.prune && !existsSync32(lockPath)) {
|
|
21207
21515
|
throw new Error(`Refusing to prune without an existing lockfile at ${path39.resolve(lockPath)}`);
|
|
21208
21516
|
}
|
|
21209
21517
|
const contentDir = path39.resolve(path39.dirname(lockPath), ".pixelkiln", "cache");
|
|
@@ -21228,7 +21536,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
21228
21536
|
await saveCache(remotePath, { version: 1, hashes: {} });
|
|
21229
21537
|
removed.resetRemoteHashCache = true;
|
|
21230
21538
|
} else if (remoteHashes.invalidIds.length) {
|
|
21231
|
-
const cache = parseCache(JSON.parse(await
|
|
21539
|
+
const cache = parseCache(JSON.parse(await readFile29(remotePath, "utf8")));
|
|
21232
21540
|
for (const id of remoteHashes.invalidIds) delete cache.hashes[id];
|
|
21233
21541
|
removed.remoteHashEntries = remoteHashes.invalidIds.length;
|
|
21234
21542
|
await saveCache(remotePath, cache);
|
|
@@ -21246,7 +21554,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
21246
21554
|
async function inspectContentCache(contentDir, referenced) {
|
|
21247
21555
|
const report = {
|
|
21248
21556
|
path: contentDir,
|
|
21249
|
-
exists:
|
|
21557
|
+
exists: existsSync32(contentDir),
|
|
21250
21558
|
files: 0,
|
|
21251
21559
|
bytes: 0,
|
|
21252
21560
|
valid: 0,
|
|
@@ -21272,7 +21580,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
21272
21580
|
const expected = mediaType ? entry.name.slice(0, -4) : "";
|
|
21273
21581
|
let bytes;
|
|
21274
21582
|
try {
|
|
21275
|
-
bytes = await
|
|
21583
|
+
bytes = await readFile29(file);
|
|
21276
21584
|
report.bytes += bytes.length;
|
|
21277
21585
|
} catch (err) {
|
|
21278
21586
|
report.invalid.push({
|
|
@@ -21310,7 +21618,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
21310
21618
|
async function inspectRemoteHashCache(remotePath) {
|
|
21311
21619
|
const report = {
|
|
21312
21620
|
path: remotePath,
|
|
21313
|
-
exists:
|
|
21621
|
+
exists: existsSync32(remotePath),
|
|
21314
21622
|
entries: 0,
|
|
21315
21623
|
valid: 0,
|
|
21316
21624
|
invalidIds: [],
|
|
@@ -21319,7 +21627,7 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
21319
21627
|
if (!report.exists) return report;
|
|
21320
21628
|
let cache;
|
|
21321
21629
|
try {
|
|
21322
|
-
cache = parseCache(JSON.parse(await
|
|
21630
|
+
cache = parseCache(JSON.parse(await readFile29(remotePath, "utf8")));
|
|
21323
21631
|
} catch (err) {
|
|
21324
21632
|
report.error = err instanceof Error ? err.message : String(err);
|
|
21325
21633
|
return report;
|
|
@@ -21383,7 +21691,7 @@ async function runAccept(args) {
|
|
|
21383
21691
|
let intact = true;
|
|
21384
21692
|
for (const output of entry.outputs) {
|
|
21385
21693
|
const file = resolveOutputPath(output.path, item.spec.root);
|
|
21386
|
-
if (!
|
|
21694
|
+
if (!existsSync33(file) || await sha256File(file) !== output.sha256) {
|
|
21387
21695
|
intact = false;
|
|
21388
21696
|
break;
|
|
21389
21697
|
}
|
|
@@ -21439,11 +21747,11 @@ This drops their provenance from the lockfile. The art on disk is`);
|
|
|
21439
21747
|
|
|
21440
21748
|
// src/cli/commands/init.ts
|
|
21441
21749
|
import path40 from "path";
|
|
21442
|
-
import { existsSync as
|
|
21750
|
+
import { existsSync as existsSync34 } from "fs";
|
|
21443
21751
|
async function runInit(args) {
|
|
21444
21752
|
if (!args.from) throw new Error("init needs --from <dir> pointing at your existing PNGs.");
|
|
21445
21753
|
const root = path40.resolve(args.from);
|
|
21446
|
-
if (!
|
|
21754
|
+
if (!existsSync34(root)) throw new Error(`No directory at ${root}`);
|
|
21447
21755
|
const generator = args.generator ?? "map";
|
|
21448
21756
|
if (generator !== "1dir" && generator !== "map") {
|
|
21449
21757
|
throw new Error(`--generator must be "1dir" or "map", got "${args.generator}".`);
|
|
@@ -21471,9 +21779,81 @@ async function runInit(args) {
|
|
|
21471
21779
|
}
|
|
21472
21780
|
|
|
21473
21781
|
// src/pipeline/doctor.ts
|
|
21474
|
-
import { constants, existsSync as
|
|
21782
|
+
import { constants, existsSync as existsSync36 } from "fs";
|
|
21475
21783
|
import { access, stat as stat4 } from "fs/promises";
|
|
21784
|
+
import path42 from "path";
|
|
21785
|
+
|
|
21786
|
+
// src/pipeline/install-check.ts
|
|
21787
|
+
import { existsSync as existsSync35, readFileSync as readFileSync7 } from "fs";
|
|
21476
21788
|
import path41 from "path";
|
|
21789
|
+
function readJson(file) {
|
|
21790
|
+
try {
|
|
21791
|
+
return JSON.parse(readFileSync7(file, "utf8"));
|
|
21792
|
+
} catch {
|
|
21793
|
+
return null;
|
|
21794
|
+
}
|
|
21795
|
+
}
|
|
21796
|
+
function readInstallFacts(manifestDir, running) {
|
|
21797
|
+
let dir = path41.resolve(manifestDir);
|
|
21798
|
+
for (let depth = 0; depth < 4; depth++) {
|
|
21799
|
+
const pkg = readJson(path41.join(dir, "package.json"));
|
|
21800
|
+
if (pkg) {
|
|
21801
|
+
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
21802
|
+
if (pinned) {
|
|
21803
|
+
const installedPkg = readJson(path41.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
21804
|
+
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
21805
|
+
return { pinned, installed, running };
|
|
21806
|
+
}
|
|
21807
|
+
}
|
|
21808
|
+
const parent = path41.dirname(dir);
|
|
21809
|
+
if (parent === dir || !existsSync35(parent)) break;
|
|
21810
|
+
dir = parent;
|
|
21811
|
+
}
|
|
21812
|
+
return null;
|
|
21813
|
+
}
|
|
21814
|
+
function parse(version) {
|
|
21815
|
+
const match = /(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
21816
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
21817
|
+
}
|
|
21818
|
+
function compare(a, b) {
|
|
21819
|
+
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
21820
|
+
}
|
|
21821
|
+
function checkInstall(facts) {
|
|
21822
|
+
const findings = [];
|
|
21823
|
+
const pin = parse(facts.pinned ?? "");
|
|
21824
|
+
const installed = facts.installed ? parse(facts.installed) : null;
|
|
21825
|
+
const running = facts.running ? parse(facts.running) : null;
|
|
21826
|
+
const exact = /^[=v]*\d+\.\d+\.\d+$/.test((facts.pinned ?? "").trim());
|
|
21827
|
+
if (pin && facts.installed && installed) {
|
|
21828
|
+
const behind = exact ? compare(installed, pin) !== 0 : compare(installed, pin) < 0;
|
|
21829
|
+
if (behind) {
|
|
21830
|
+
findings.push({
|
|
21831
|
+
level: "warning",
|
|
21832
|
+
message: `package.json asks for pixelkiln ${facts.pinned} but node_modules has ${facts.installed}; run \`npm install\` so the CLI matches the manifest.`
|
|
21833
|
+
});
|
|
21834
|
+
}
|
|
21835
|
+
} else if (pin && !facts.installed) {
|
|
21836
|
+
findings.push({
|
|
21837
|
+
level: "warning",
|
|
21838
|
+
message: `package.json asks for pixelkiln ${facts.pinned} but it is not installed in node_modules; run \`npm install\`.`
|
|
21839
|
+
});
|
|
21840
|
+
}
|
|
21841
|
+
if (running && installed && compare(running, installed) !== 0) {
|
|
21842
|
+
findings.push({
|
|
21843
|
+
level: "warning",
|
|
21844
|
+
message: `running pixelkiln ${facts.running}, but this project's node_modules has ${facts.installed}. Another install is first on your PATH; use \`npx pixelkiln\` or remove the global one.`
|
|
21845
|
+
});
|
|
21846
|
+
}
|
|
21847
|
+
if (!findings.length) {
|
|
21848
|
+
findings.push({
|
|
21849
|
+
level: "ok",
|
|
21850
|
+
message: `pixelkiln ${facts.running ?? facts.installed ?? "?"} matches package.json (${facts.pinned})`
|
|
21851
|
+
});
|
|
21852
|
+
}
|
|
21853
|
+
return findings;
|
|
21854
|
+
}
|
|
21855
|
+
|
|
21856
|
+
// src/pipeline/doctor.ts
|
|
21477
21857
|
async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
21478
21858
|
const checks = [];
|
|
21479
21859
|
const add = (id, level, message6) => checks.push({ id, level, message: message6 });
|
|
@@ -21482,10 +21862,19 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
21482
21862
|
"ok",
|
|
21483
21863
|
`${Object.keys(loaded.manifest.styles).length} style(s), ${Object.keys(loaded.manifest.assets).length} asset(s), ${specs.length} resolved spec(s)`
|
|
21484
21864
|
);
|
|
21865
|
+
for (const entry of loaded.invalid ?? []) {
|
|
21866
|
+
add(
|
|
21867
|
+
"invalid-entry",
|
|
21868
|
+
"error",
|
|
21869
|
+
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
21870
|
+
);
|
|
21871
|
+
}
|
|
21872
|
+
const facts = readInstallFacts(path42.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
21873
|
+
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
21485
21874
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
21486
21875
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
21487
|
-
|
|
21488
|
-
...spec.quality ? [
|
|
21876
|
+
path42.dirname(spec.outFile),
|
|
21877
|
+
...spec.quality ? [path42.dirname(spec.quality.outFile)] : []
|
|
21489
21878
|
]))];
|
|
21490
21879
|
const unwritable = [];
|
|
21491
21880
|
for (const dir of dirs) {
|
|
@@ -21508,7 +21897,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
21508
21897
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
21509
21898
|
const output = entry.outputs[index];
|
|
21510
21899
|
const spec = specByKey.get(key);
|
|
21511
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
21900
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, path42.dirname(lockPath));
|
|
21512
21901
|
const owner = outputOwners.get(absolute);
|
|
21513
21902
|
if (owner && owner !== key) duplicateOutputs.push(`${output.path} (${owner}, ${key})`);
|
|
21514
21903
|
outputOwners.set(absolute, key);
|
|
@@ -21523,7 +21912,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
21523
21912
|
} else {
|
|
21524
21913
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
21525
21914
|
}
|
|
21526
|
-
const cacheDir =
|
|
21915
|
+
const cacheDir = path42.join(path42.dirname(lockPath), ".pixelkiln", "cache");
|
|
21527
21916
|
const stranded = [];
|
|
21528
21917
|
const invalidState = [];
|
|
21529
21918
|
const staleMapUrls = [];
|
|
@@ -21539,11 +21928,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
21539
21928
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
21540
21929
|
let hasCache = false;
|
|
21541
21930
|
for (const output of entry.outputs) {
|
|
21542
|
-
const
|
|
21931
|
+
const cached2 = path42.join(
|
|
21543
21932
|
cacheDir,
|
|
21544
21933
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
21545
21934
|
);
|
|
21546
|
-
if (
|
|
21935
|
+
if (existsSync36(cached2) && await sha256File(cached2) === output.sha256) {
|
|
21547
21936
|
hasCache = true;
|
|
21548
21937
|
break;
|
|
21549
21938
|
}
|
|
@@ -21639,16 +22028,16 @@ async function nearestExistingDirectory(start) {
|
|
|
21639
22028
|
if ((await stat4(current)).isDirectory()) return current;
|
|
21640
22029
|
} catch {
|
|
21641
22030
|
}
|
|
21642
|
-
const parent =
|
|
22031
|
+
const parent = path42.dirname(current);
|
|
21643
22032
|
if (parent === current) return current;
|
|
21644
22033
|
current = parent;
|
|
21645
22034
|
}
|
|
21646
22035
|
}
|
|
21647
22036
|
|
|
21648
22037
|
// src/pipeline/audit.ts
|
|
21649
|
-
import { readFile as
|
|
21650
|
-
import { existsSync as
|
|
21651
|
-
import
|
|
22038
|
+
import { readFile as readFile30 } from "fs/promises";
|
|
22039
|
+
import { existsSync as existsSync37 } from "fs";
|
|
22040
|
+
import path43 from "path";
|
|
21652
22041
|
function paletteDistance(asset, reference) {
|
|
21653
22042
|
if (!asset.length || !reference.length) return 0;
|
|
21654
22043
|
let total = 0;
|
|
@@ -21684,12 +22073,12 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
21684
22073
|
const unreadable = [];
|
|
21685
22074
|
for (const spec of mine) {
|
|
21686
22075
|
for (const output of resolveSpecOutputs(spec, lock, loaded.root)) {
|
|
21687
|
-
if (!
|
|
22076
|
+
if (!existsSync37(output.absolutePath)) {
|
|
21688
22077
|
missing.push(output.id);
|
|
21689
22078
|
continue;
|
|
21690
22079
|
}
|
|
21691
22080
|
try {
|
|
21692
|
-
const png = decodePng(await
|
|
22081
|
+
const png = decodePng(await readFile30(output.absolutePath));
|
|
21693
22082
|
const palette = extractPalette(png, 12);
|
|
21694
22083
|
assets.push({
|
|
21695
22084
|
assetId: spec.assetId,
|
|
@@ -21713,10 +22102,10 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
21713
22102
|
let referenceFromStyleImages = false;
|
|
21714
22103
|
const refPalettes = [];
|
|
21715
22104
|
for (const img of style.styleImages) {
|
|
21716
|
-
const abs =
|
|
21717
|
-
if (!
|
|
22105
|
+
const abs = path43.resolve(loaded.root, img.path);
|
|
22106
|
+
if (!existsSync37(abs)) continue;
|
|
21718
22107
|
try {
|
|
21719
|
-
refPalettes.push(extractPalette(decodePng(await
|
|
22108
|
+
refPalettes.push(extractPalette(decodePng(await readFile30(abs)), 12));
|
|
21720
22109
|
} catch {
|
|
21721
22110
|
}
|
|
21722
22111
|
}
|
|
@@ -21846,11 +22235,14 @@ async function runDoctor(args) {
|
|
|
21846
22235
|
if (!report.ok) process.exitCode = 1;
|
|
21847
22236
|
}
|
|
21848
22237
|
async function runPlan(args) {
|
|
21849
|
-
const { specs, lock } = await openProject2(args);
|
|
22238
|
+
const { loaded, specs, lock } = await openProject2(args);
|
|
22239
|
+
const { shown: invalid, hidden: hiddenInvalid } = selectInvalid(loaded.invalid ?? [], args);
|
|
21850
22240
|
const plan = await buildPlan(specs, lock, { force: args.force });
|
|
21851
22241
|
if (args.json) {
|
|
21852
22242
|
log(JSON.stringify({
|
|
21853
22243
|
totals: summarize(plan),
|
|
22244
|
+
invalid,
|
|
22245
|
+
hiddenInvalid,
|
|
21854
22246
|
cost: plan.cost,
|
|
21855
22247
|
costUnit: plan.costUnit,
|
|
21856
22248
|
candidates: plan.candidates,
|
|
@@ -21887,11 +22279,11 @@ async function runPlan(args) {
|
|
|
21887
22279
|
})
|
|
21888
22280
|
}, null, 2));
|
|
21889
22281
|
} else {
|
|
21890
|
-
printPlan(plan);
|
|
22282
|
+
printPlan(plan, invalid, hiddenInvalid);
|
|
21891
22283
|
}
|
|
21892
|
-
if (args.check && plan.items.some(
|
|
22284
|
+
if (args.check && (invalid.length > 0 || plan.items.some(
|
|
21893
22285
|
(item) => item.state !== "ok" || item.quality && item.quality.state !== "approved"
|
|
21894
|
-
)) process.exitCode = 1;
|
|
22286
|
+
))) process.exitCode = 1;
|
|
21895
22287
|
}
|
|
21896
22288
|
async function runAudit(args) {
|
|
21897
22289
|
const { loaded, specs, lock } = await openProject2(args);
|
|
@@ -21942,26 +22334,49 @@ async function runAudit(args) {
|
|
|
21942
22334
|
}
|
|
21943
22335
|
if (args.check && reports.some((report) => !report.evaluation.safe)) process.exitCode = 1;
|
|
21944
22336
|
}
|
|
22337
|
+
async function runHash(args) {
|
|
22338
|
+
const { loaded, specs, lock } = await openProject2(args);
|
|
22339
|
+
if (!args.assets.length && !args.styles.length && !args.all) {
|
|
22340
|
+
throw new UsageError("hash needs --only <asset>, --style <style>, or --all.");
|
|
22341
|
+
}
|
|
22342
|
+
const reports = await reportSpecHashes(specs, lock);
|
|
22343
|
+
if (args.json) {
|
|
22344
|
+
log(JSON.stringify({ items: reports, invalid: selectInvalid(loaded.invalid ?? [], args).shown }, null, 2));
|
|
22345
|
+
return;
|
|
22346
|
+
}
|
|
22347
|
+
for (const entry of selectInvalid(loaded.invalid ?? [], args).shown) {
|
|
22348
|
+
log(` invalid ${entry.kind === "style" ? "styles" : "assets"}.${entry.id}: ${entry.issues[0] ?? ""}`);
|
|
22349
|
+
}
|
|
22350
|
+
for (const report of reports) {
|
|
22351
|
+
const state = !report.lock ? "no lock entry" : report.lock.matches ? "lock matches" : "lock differs";
|
|
22352
|
+
log(` ${report.key}`);
|
|
22353
|
+
log(` spec hash ${report.specHash}`);
|
|
22354
|
+
log(` file hash ${report.fileSha256 ?? "(no file)"}`);
|
|
22355
|
+
log(` ${state}`);
|
|
22356
|
+
}
|
|
22357
|
+
log(`
|
|
22358
|
+
\`pixelkiln adopt --local\` writes the entry above for files with no lock entry.`);
|
|
22359
|
+
}
|
|
21945
22360
|
|
|
21946
22361
|
// src/cli/commands/pack.ts
|
|
21947
|
-
import
|
|
21948
|
-
import { readFile as
|
|
22362
|
+
import path45 from "path";
|
|
22363
|
+
import { readFile as readFile31 } from "fs/promises";
|
|
21949
22364
|
|
|
21950
22365
|
// src/pipeline/pack.ts
|
|
21951
|
-
import { readFileSync as
|
|
21952
|
-
import
|
|
22366
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
22367
|
+
import path44 from "path";
|
|
21953
22368
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
21954
22369
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
21955
22370
|
if (!Array.isArray(raw) || !raw.length) {
|
|
21956
22371
|
throw new Error("--inputs must be a non-empty JSON array of { id, path }");
|
|
21957
22372
|
}
|
|
21958
|
-
const baseDir =
|
|
22373
|
+
const baseDir = path44.dirname(path44.resolve(inputsFilePath));
|
|
21959
22374
|
return raw.map((entry, i) => {
|
|
21960
22375
|
const e = entry;
|
|
21961
22376
|
if (typeof e.id !== "string" || typeof e.path !== "string") {
|
|
21962
22377
|
throw new Error(`--inputs[${i}] needs string "id" and "path"`);
|
|
21963
22378
|
}
|
|
21964
|
-
return { id: e.id, path:
|
|
22379
|
+
return { id: e.id, path: path44.resolve(baseDir, e.path) };
|
|
21965
22380
|
});
|
|
21966
22381
|
}
|
|
21967
22382
|
function packSprites(inputs, options = {}) {
|
|
@@ -21982,7 +22397,7 @@ function packSprites(inputs, options = {}) {
|
|
|
21982
22397
|
for (const input of ordered) {
|
|
21983
22398
|
let sourceHash = null;
|
|
21984
22399
|
try {
|
|
21985
|
-
const bytes =
|
|
22400
|
+
const bytes = readFileSync8(input.path);
|
|
21986
22401
|
sourceHash = sha256(bytes);
|
|
21987
22402
|
const png = decodePng(bytes);
|
|
21988
22403
|
sprites.push({ id: input.id, width: png.width, height: png.height, pixels: png.pixels });
|
|
@@ -22045,7 +22460,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
22045
22460
|
}
|
|
22046
22461
|
const inputs2 = Object.entries(options.sourceOverrides).map(([id, source]) => ({
|
|
22047
22462
|
id,
|
|
22048
|
-
path:
|
|
22463
|
+
path: path44.resolve(source)
|
|
22049
22464
|
}));
|
|
22050
22465
|
if (!inputs2.length) throw new Error(`No approved quality outputs for style "${styleId}".`);
|
|
22051
22466
|
const packed2 = packSprites(inputs2, options);
|
|
@@ -22069,7 +22484,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
22069
22484
|
let outputs = resolveEntryOutputs(entry, id, manifestDir);
|
|
22070
22485
|
const source = sources[id];
|
|
22071
22486
|
if (source && outputs.length <= 1) {
|
|
22072
|
-
inputs.push({ id, path:
|
|
22487
|
+
inputs.push({ id, path: path44.resolve(manifestDir, source) });
|
|
22073
22488
|
continue;
|
|
22074
22489
|
}
|
|
22075
22490
|
if (source && sourceIsStem(source, entry, manifestDir)) {
|
|
@@ -22104,7 +22519,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
22104
22519
|
}
|
|
22105
22520
|
}
|
|
22106
22521
|
for (const [id, source] of Object.entries(sources)) {
|
|
22107
|
-
if (!locked.has(id)) inputs.push({ id, path:
|
|
22522
|
+
if (!locked.has(id)) inputs.push({ id, path: path44.resolve(manifestDir, source) });
|
|
22108
22523
|
}
|
|
22109
22524
|
if (!inputs.length) {
|
|
22110
22525
|
throw new Error(`No readable sprites for style "${styleId}"; ${noOutput.length} skipped.`);
|
|
@@ -22141,7 +22556,7 @@ function mountSprites(placements, options) {
|
|
|
22141
22556
|
for (const p of placements) {
|
|
22142
22557
|
let sourceHash = null;
|
|
22143
22558
|
try {
|
|
22144
|
-
const bytes =
|
|
22559
|
+
const bytes = readFileSync8(p.path);
|
|
22145
22560
|
sourceHash = sha256(bytes);
|
|
22146
22561
|
const png = decodePng(bytes);
|
|
22147
22562
|
if (png.width > cellWidth || png.height > cellHeight) {
|
|
@@ -22212,7 +22627,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
22212
22627
|
const source = sources[id];
|
|
22213
22628
|
const entry = lock.entries[`${styleId}/${id}`];
|
|
22214
22629
|
if (source && !(entry && sourceIsStem(source, entry, manifestDir))) {
|
|
22215
|
-
placements.push({ id, path:
|
|
22630
|
+
placements.push({ id, path: path44.resolve(manifestDir, source), cell });
|
|
22216
22631
|
continue;
|
|
22217
22632
|
}
|
|
22218
22633
|
if (source && entry) {
|
|
@@ -22245,7 +22660,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
22245
22660
|
`Nothing to mount for style "${styleId}": ${ids.length} asset(s) declare a cell, but none has generated output or a \`source\`. Run \`pixelkiln gen --style ${styleId}\`, or point each at a file.${detail}`
|
|
22246
22661
|
);
|
|
22247
22662
|
}
|
|
22248
|
-
const basePng = mount.base ?
|
|
22663
|
+
const basePng = mount.base ? readFileSync8(path44.resolve(manifestDir, mount.base)) : void 0;
|
|
22249
22664
|
const mounted = mountSprites(placements, {
|
|
22250
22665
|
cellWidth: mount.cellWidth,
|
|
22251
22666
|
cellHeight: mount.cellHeight,
|
|
@@ -22255,7 +22670,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
22255
22670
|
...mounted,
|
|
22256
22671
|
sources: mount.base ? [{
|
|
22257
22672
|
id: "$base",
|
|
22258
|
-
path:
|
|
22673
|
+
path: path44.resolve(manifestDir, mount.base),
|
|
22259
22674
|
sha256: sha256(basePng),
|
|
22260
22675
|
included: true
|
|
22261
22676
|
}, ...mounted.sources] : mounted.sources,
|
|
@@ -22659,12 +23074,12 @@ async function runPack(args) {
|
|
|
22659
23074
|
if (args.primaryOnly || args.outputRoles.length) {
|
|
22660
23075
|
throw new Error("--primary-only and --output-role require manifest-driven pack");
|
|
22661
23076
|
}
|
|
22662
|
-
const raw = JSON.parse(await
|
|
23077
|
+
const raw = JSON.parse(await readFile31(path45.resolve(args.inputs), "utf8"));
|
|
22663
23078
|
const inputs = resolvePackInputs(raw, args.inputs);
|
|
22664
23079
|
const { png, atlas, skipped, sources } = packSprites(inputs, { columns: args.columns });
|
|
22665
23080
|
const format = sheetFormat(args);
|
|
22666
|
-
const base =
|
|
22667
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
23081
|
+
const base = path45.resolve(args.out.replace(/\.(?:png|json|tres)$/i, ""));
|
|
23082
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path45.basename(`${base}.png`) });
|
|
22668
23083
|
const outputs = [
|
|
22669
23084
|
{ path: `${base}.png`, data: png },
|
|
22670
23085
|
{ path: `${base}${extension}`, data: document }
|
|
@@ -22677,7 +23092,7 @@ async function runPack(args) {
|
|
|
22677
23092
|
log(
|
|
22678
23093
|
` ${atlas.frames.length} sprite(s), ${atlas.sheet.width}x${atlas.sheet.height} in ${atlas.columns} column(s), ${(png.length / 1024).toFixed(1)} KB (${format})`
|
|
22679
23094
|
);
|
|
22680
|
-
log(` ${
|
|
23095
|
+
log(` ${path45.relative(process.cwd(), base)}.png + ${extension} + .pixelkiln.json`);
|
|
22681
23096
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
22682
23097
|
return;
|
|
22683
23098
|
}
|
|
@@ -22685,7 +23100,7 @@ async function runPack(args) {
|
|
|
22685
23100
|
if (args.primaryOnly && args.outputRoles.length) {
|
|
22686
23101
|
throw new Error("pack accepts either --primary-only or --output-role, not both");
|
|
22687
23102
|
}
|
|
22688
|
-
const manifestDir =
|
|
23103
|
+
const manifestDir = path45.dirname(path45.resolve(args.manifest));
|
|
22689
23104
|
const styleIds = args.styles.length ? args.styles : Object.keys(loaded.manifest.styles);
|
|
22690
23105
|
for (const styleId of styleIds) {
|
|
22691
23106
|
const style = loaded.manifest.styles[styleId];
|
|
@@ -22700,9 +23115,9 @@ async function runPack(args) {
|
|
|
22700
23115
|
sourceOverrides: qualitySources,
|
|
22701
23116
|
sources: manifestSources(loaded.manifest, styleId)
|
|
22702
23117
|
});
|
|
22703
|
-
const base = args.out ?
|
|
23118
|
+
const base = args.out ? path45.resolve(args.out.replace(/\.(?:png|json|tres)$/i, "")) : path45.resolve(manifestDir, style.outDir, `${styleId}-sheet`);
|
|
22704
23119
|
const format = sheetFormat(args);
|
|
22705
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
23120
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path45.basename(`${base}.png`) });
|
|
22706
23121
|
const outputs = [
|
|
22707
23122
|
{ path: `${base}.png`, data: png },
|
|
22708
23123
|
{ path: `${base}${extension}`, data: document }
|
|
@@ -22734,13 +23149,13 @@ async function runPack(args) {
|
|
|
22734
23149
|
log(
|
|
22735
23150
|
` ${styleId}: ${atlas.frames.length} sprite(s), ${atlas.sheet.width}x${atlas.sheet.height} in ${atlas.columns} column(s)` + (atlas.sets?.length ? `, ${atlas.sets.length} set(s)` : "") + ` (${format})`
|
|
22736
23151
|
);
|
|
22737
|
-
log(` ${
|
|
23152
|
+
log(` ${path45.relative(process.cwd(), base)}.png + ${extension} + .pixelkiln.json`);
|
|
22738
23153
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
22739
23154
|
}
|
|
22740
23155
|
}
|
|
22741
23156
|
async function runMount(args) {
|
|
22742
23157
|
const { loaded, lock } = await openProject2(args);
|
|
22743
|
-
const manifestDir =
|
|
23158
|
+
const manifestDir = path45.dirname(path45.resolve(args.manifest));
|
|
22744
23159
|
const styleIds = args.styles.length ? args.styles : Object.keys(loaded.manifest.styles);
|
|
22745
23160
|
for (const styleId of styleIds) {
|
|
22746
23161
|
const style = loaded.manifest.styles[styleId];
|
|
@@ -22779,9 +23194,9 @@ async function runMount(args) {
|
|
|
22779
23194
|
sources,
|
|
22780
23195
|
outputRoles
|
|
22781
23196
|
);
|
|
22782
|
-
const out =
|
|
23197
|
+
const out = path45.resolve(manifestDir, style.mount.out);
|
|
22783
23198
|
const format = sheetFormat(args);
|
|
22784
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
23199
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path45.basename(out) });
|
|
22785
23200
|
const metadata = out.replace(/\.png$/, "") + extension;
|
|
22786
23201
|
const companion = out.replace(/\.png$/, "") + ".pixelkiln.json";
|
|
22787
23202
|
const outputs = [
|
|
@@ -22801,7 +23216,7 @@ async function runMount(args) {
|
|
|
22801
23216
|
await provenanceFile("$lock", args.lock),
|
|
22802
23217
|
...qualityRecords,
|
|
22803
23218
|
...artifactSources.filter(
|
|
22804
|
-
(source) => source.id !== "$base" ||
|
|
23219
|
+
(source) => source.id !== "$base" || path45.resolve(source.path) !== out
|
|
22805
23220
|
)
|
|
22806
23221
|
],
|
|
22807
23222
|
options: {
|
|
@@ -22815,14 +23230,14 @@ async function runMount(args) {
|
|
|
22815
23230
|
log(
|
|
22816
23231
|
` ${styleId}: ${atlas.frames.length} cell(s) into ${atlas.sheet.width}x${atlas.sheet.height}` + (overBase ? ` over ${style.mount.base}` : " (new sheet)")
|
|
22817
23232
|
);
|
|
22818
|
-
log(` ${
|
|
23233
|
+
log(` ${path45.relative(process.cwd(), out)} + atlas/provenance JSON`);
|
|
22819
23234
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
22820
23235
|
}
|
|
22821
23236
|
}
|
|
22822
23237
|
async function runExport(args) {
|
|
22823
23238
|
const { loaded, specs, lock } = await openProject2(args);
|
|
22824
23239
|
const format = args.format ?? "generic";
|
|
22825
|
-
const manifestDir =
|
|
23240
|
+
const manifestDir = path45.dirname(path45.resolve(args.manifest));
|
|
22826
23241
|
const selected = specs.filter((spec) => {
|
|
22827
23242
|
if (spec.generator !== "tiles" && spec.generator !== "terrain") return false;
|
|
22828
23243
|
if (args.styles.length && !args.styles.includes(spec.styleId)) return false;
|
|
@@ -22838,12 +23253,12 @@ async function runExport(args) {
|
|
|
22838
23253
|
for (const spec of selected) {
|
|
22839
23254
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
22840
23255
|
const style = loaded.manifest.styles[spec.styleId];
|
|
22841
|
-
const defaultBase =
|
|
22842
|
-
const base = args.out ?
|
|
23256
|
+
const defaultBase = path45.resolve(manifestDir, style.outDir, `${spec.assetId}-tileset`);
|
|
23257
|
+
const base = args.out ? path45.resolve(args.out.replace(/\.(?:png|json|tsj|tres)$/i, "")) : defaultBase;
|
|
22843
23258
|
const result = exportTileset(entry, spec, {
|
|
22844
23259
|
format,
|
|
22845
23260
|
manifestDir,
|
|
22846
|
-
imageName:
|
|
23261
|
+
imageName: path45.basename(`${base}.png`),
|
|
22847
23262
|
columns: args.columns
|
|
22848
23263
|
});
|
|
22849
23264
|
const outputs = [
|
|
@@ -22861,7 +23276,7 @@ async function runExport(args) {
|
|
|
22861
23276
|
asset: spec.assetId,
|
|
22862
23277
|
columns: args.columns ?? null,
|
|
22863
23278
|
format,
|
|
22864
|
-
image:
|
|
23279
|
+
image: path45.basename(`${base}.png`),
|
|
22865
23280
|
providerRules: result.generic.providerRules,
|
|
22866
23281
|
style: spec.styleId,
|
|
22867
23282
|
tileType: spec.tileType ?? null
|
|
@@ -22871,7 +23286,7 @@ async function runExport(args) {
|
|
|
22871
23286
|
` ${spec.styleId}/${spec.assetId}: ${result.generic.tiles.length} tile(s), ${result.generic.sheet.width}x${result.generic.sheet.height} (${format})`
|
|
22872
23287
|
);
|
|
22873
23288
|
log(
|
|
22874
|
-
` ${
|
|
23289
|
+
` ${path45.relative(process.cwd(), base)}.png + ${path45.basename(base)}${result.extension} + .pixelkiln.json`
|
|
22875
23290
|
);
|
|
22876
23291
|
}
|
|
22877
23292
|
}
|
|
@@ -22884,10 +23299,10 @@ function sheetFormat(args) {
|
|
|
22884
23299
|
}
|
|
22885
23300
|
|
|
22886
23301
|
// src/cli/commands/pixellab-utils.ts
|
|
22887
|
-
import { readFile as
|
|
22888
|
-
import
|
|
23302
|
+
import { readFile as readFile32 } from "fs/promises";
|
|
23303
|
+
import path46 from "path";
|
|
22889
23304
|
function loadKeys(args) {
|
|
22890
|
-
loadEnvFiles(
|
|
23305
|
+
loadEnvFiles(path46.dirname(path46.resolve(args.manifest)));
|
|
22891
23306
|
loadEnvFiles(process.cwd());
|
|
22892
23307
|
}
|
|
22893
23308
|
async function runUnzoom(args) {
|
|
@@ -23044,7 +23459,7 @@ async function runVfx(args) {
|
|
|
23044
23459
|
const fromRecipe = args.recipe ? await readVfxRecipe(args.recipe) : void 0;
|
|
23045
23460
|
const sprite = args.sprite ?? fromRecipe?.sprite;
|
|
23046
23461
|
const recipeName = typeof fromRecipe?.recipe.name === "string" ? fromRecipe.recipe.name : void 0;
|
|
23047
|
-
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ??
|
|
23462
|
+
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ?? path46.basename(paths.sheet, ".png"));
|
|
23048
23463
|
const from = args.preset ? `preset ${args.preset}` : args.recipe ? `recipe ${args.recipe}` : args.effect ? `saved effect ${args.effect}` : "nothing";
|
|
23049
23464
|
log(
|
|
23050
23465
|
` 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" : ""})`
|
|
@@ -23102,7 +23517,7 @@ async function runVfxArtist(args, out) {
|
|
|
23102
23517
|
}
|
|
23103
23518
|
if (args.name && args.name.length > 80) throw new UsageError("vfx --description takes a --name of at most 80 characters");
|
|
23104
23519
|
const paths = vfxOutputPaths(out);
|
|
23105
|
-
const side = args.sprite ? vfxArtistSprite(await
|
|
23520
|
+
const side = args.sprite ? vfxArtistSprite(await readFile32(args.sprite), args.sprite).side : "none";
|
|
23106
23521
|
const conversation = args.effect ? await readVfxConversation(paths.provenance, args.effect) : void 0;
|
|
23107
23522
|
const quote = vfxArtistQuote(artist, args.effect && !args.sprite ? "unknown" : side, Boolean(conversation));
|
|
23108
23523
|
const ceiling = vfxArtistCeiling(quote);
|
|
@@ -23111,7 +23526,7 @@ async function runVfxArtist(args, out) {
|
|
|
23111
23526
|
);
|
|
23112
23527
|
if (args.effect) {
|
|
23113
23528
|
log(
|
|
23114
|
-
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${
|
|
23529
|
+
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${path46.basename(paths.provenance)})` : `; ${path46.basename(paths.provenance)} holds no conversation for it, so PixelLab prices it as a new effect`)
|
|
23115
23530
|
);
|
|
23116
23531
|
}
|
|
23117
23532
|
log(` cost: about ${quote} generations by PixelLab's table, billed on delivery; at most ${ceiling} if the effect runs long`);
|
|
@@ -23159,19 +23574,19 @@ async function runVfxArtist(args, out) {
|
|
|
23159
23574
|
}
|
|
23160
23575
|
|
|
23161
23576
|
// src/cli/commands/quality.ts
|
|
23162
|
-
import
|
|
23163
|
-
import { readFile as
|
|
23577
|
+
import path48 from "path";
|
|
23578
|
+
import { readFile as readFile34 } from "fs/promises";
|
|
23164
23579
|
|
|
23165
23580
|
// src/pipeline/quality-regression.ts
|
|
23166
|
-
import
|
|
23167
|
-
import { existsSync as
|
|
23168
|
-
import { readFile as
|
|
23581
|
+
import path47 from "path";
|
|
23582
|
+
import { existsSync as existsSync38 } from "fs";
|
|
23583
|
+
import { readFile as readFile33 } from "fs/promises";
|
|
23169
23584
|
import { z as z13 } from "zod";
|
|
23170
23585
|
var SHA256_RE = /^[0-9a-f]{64}$/;
|
|
23171
23586
|
var HEX_RE = /^#[0-9a-f]{6}$/;
|
|
23172
23587
|
var MAX_REDMEAN_DISTANCE = 765;
|
|
23173
23588
|
var QualityPathSchema = z13.string().min(1).refine(
|
|
23174
|
-
(value) => !
|
|
23589
|
+
(value) => !path47.posix.isAbsolute(value) && !value.includes("\\"),
|
|
23175
23590
|
"expected a portable relative path"
|
|
23176
23591
|
);
|
|
23177
23592
|
var DEFAULT_QUALITY_TOLERANCES = {
|
|
@@ -23318,10 +23733,10 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
23318
23733
|
};
|
|
23319
23734
|
}
|
|
23320
23735
|
async function measureImageQuality(file) {
|
|
23321
|
-
const absolute =
|
|
23736
|
+
const absolute = path47.resolve(file);
|
|
23322
23737
|
let bytes;
|
|
23323
23738
|
try {
|
|
23324
|
-
bytes = await
|
|
23739
|
+
bytes = await readFile33(absolute);
|
|
23325
23740
|
} catch (error) {
|
|
23326
23741
|
throw new Error(`Cannot read quality image ${absolute}: ${message4(error)}`, { cause: error });
|
|
23327
23742
|
}
|
|
@@ -23340,11 +23755,11 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
23340
23755
|
}
|
|
23341
23756
|
const ids = parsed.data.map((entry) => entry.id);
|
|
23342
23757
|
if (new Set(ids).size !== ids.length) throw new Error("--inputs contains a duplicate quality case id.");
|
|
23343
|
-
const root =
|
|
23758
|
+
const root = path47.dirname(path47.resolve(inputsFilePath));
|
|
23344
23759
|
return parsed.data.map((entry) => ({
|
|
23345
23760
|
id: entry.id,
|
|
23346
|
-
file:
|
|
23347
|
-
...entry.record ? { record:
|
|
23761
|
+
file: path47.resolve(root, entry.path),
|
|
23762
|
+
...entry.record ? { record: path47.resolve(root, entry.record) } : {},
|
|
23348
23763
|
tolerances: QualityToleranceSchema.parse({
|
|
23349
23764
|
...DEFAULT_QUALITY_TOLERANCES,
|
|
23350
23765
|
...entry.tolerances
|
|
@@ -23352,7 +23767,7 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
23352
23767
|
}));
|
|
23353
23768
|
}
|
|
23354
23769
|
function portableRelative2(from, to) {
|
|
23355
|
-
return
|
|
23770
|
+
return path47.relative(from, path47.resolve(to)).split(path47.sep).join("/") || ".";
|
|
23356
23771
|
}
|
|
23357
23772
|
async function verifyRecordForImage(recordPath, imagePath) {
|
|
23358
23773
|
const verification = await verifyArtifactBundle(recordPath);
|
|
@@ -23367,20 +23782,20 @@ async function verifyRecordForImage(recordPath, imagePath) {
|
|
|
23367
23782
|
if (record.kind !== "refine" || options === null || typeof options !== "object" || options.schema !== "pixelkiln-quality") {
|
|
23368
23783
|
throw new Error(`Quality record ${recordPath} is not a PixelKiln refinement record.`);
|
|
23369
23784
|
}
|
|
23370
|
-
const outputs = record.outputs.map((output) =>
|
|
23371
|
-
if (!outputs.includes(
|
|
23785
|
+
const outputs = record.outputs.map((output) => path47.resolve(path47.dirname(recordPath), output.path));
|
|
23786
|
+
if (!outputs.includes(path47.resolve(imagePath))) {
|
|
23372
23787
|
throw new Error(`Quality record ${recordPath} does not own ${imagePath}.`);
|
|
23373
23788
|
}
|
|
23374
23789
|
}
|
|
23375
23790
|
async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
23376
23791
|
if (!inputs.length) throw new Error("Cannot snapshot an empty quality baseline.");
|
|
23377
|
-
const absolute =
|
|
23792
|
+
const absolute = path47.resolve(baselinePath);
|
|
23378
23793
|
for (const input of inputs) {
|
|
23379
|
-
if (
|
|
23794
|
+
if (path47.resolve(input.file) === absolute || input.record && path47.resolve(input.record) === absolute) {
|
|
23380
23795
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
23381
23796
|
}
|
|
23382
23797
|
}
|
|
23383
|
-
const root =
|
|
23798
|
+
const root = path47.dirname(absolute);
|
|
23384
23799
|
const cases = [];
|
|
23385
23800
|
for (const input of [...inputs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
23386
23801
|
const expected = await measureImageQuality(input.file);
|
|
@@ -23407,8 +23822,8 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
23407
23822
|
cases
|
|
23408
23823
|
});
|
|
23409
23824
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
23410
|
-
if (
|
|
23411
|
-
const current = await
|
|
23825
|
+
if (existsSync38(absolute) && !options.force) {
|
|
23826
|
+
const current = await readFile33(absolute);
|
|
23412
23827
|
if (!current.equals(data)) {
|
|
23413
23828
|
throw new OverwriteRefusedError(
|
|
23414
23829
|
`Quality baseline already exists with different content: ${absolute}. Pass --force to replace it.`,
|
|
@@ -23419,19 +23834,90 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
23419
23834
|
const result = await writeArtifactBundle([{ path: absolute, data }]);
|
|
23420
23835
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
23421
23836
|
}
|
|
23837
|
+
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
23838
|
+
const absolute = path47.resolve(baselinePath);
|
|
23839
|
+
if (!existsSync38(absolute)) {
|
|
23840
|
+
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
23841
|
+
}
|
|
23842
|
+
let raw;
|
|
23843
|
+
try {
|
|
23844
|
+
raw = JSON.parse(await readFile33(absolute, "utf8"));
|
|
23845
|
+
} catch (error) {
|
|
23846
|
+
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
23847
|
+
}
|
|
23848
|
+
if (!Array.isArray(raw.cases)) throw new Error(`Quality baseline ${absolute} has no cases array.`);
|
|
23849
|
+
const byId = new Map(inputs.map((input) => [input.id, input]));
|
|
23850
|
+
const unknown = only.filter((id) => !byId.has(id));
|
|
23851
|
+
if (unknown.length) {
|
|
23852
|
+
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
23853
|
+
}
|
|
23854
|
+
const root = path47.dirname(absolute);
|
|
23855
|
+
const cases = [...raw.cases];
|
|
23856
|
+
const report = [];
|
|
23857
|
+
for (const id of only) {
|
|
23858
|
+
const input = byId.get(id);
|
|
23859
|
+
if (path47.resolve(input.file) === absolute || input.record && path47.resolve(input.record) === absolute) {
|
|
23860
|
+
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
23861
|
+
}
|
|
23862
|
+
const expected = await measureImageQuality(input.file);
|
|
23863
|
+
let record;
|
|
23864
|
+
if (input.record) {
|
|
23865
|
+
await verifyRecordForImage(input.record, input.file);
|
|
23866
|
+
record = { path: portableRelative2(root, input.record), sha256: await sha256File(input.record) };
|
|
23867
|
+
}
|
|
23868
|
+
const index = cases.findIndex((entry) => entry.id === id);
|
|
23869
|
+
const before = index >= 0 ? cases[index].expected ?? {} : {};
|
|
23870
|
+
const next = {
|
|
23871
|
+
id,
|
|
23872
|
+
file: portableRelative2(root, input.file),
|
|
23873
|
+
...record ? { record } : {},
|
|
23874
|
+
expected,
|
|
23875
|
+
tolerances: index >= 0 && cases[index].tolerances ? cases[index].tolerances : input.tolerances
|
|
23876
|
+
};
|
|
23877
|
+
if (index >= 0) cases[index] = next;
|
|
23878
|
+
else cases.push(next);
|
|
23879
|
+
const changes = [];
|
|
23880
|
+
for (const metric of Object.keys(expected)) {
|
|
23881
|
+
if (JSON.stringify(before[metric]) !== JSON.stringify(expected[metric])) {
|
|
23882
|
+
changes.push({ metric, before: before[metric] ?? null, after: expected[metric] });
|
|
23883
|
+
}
|
|
23884
|
+
}
|
|
23885
|
+
report.push({ id, kind: index < 0 ? "added" : changes.length ? "updated" : "unchanged", changes });
|
|
23886
|
+
}
|
|
23887
|
+
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
23888
|
+
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
23889
|
+
const current = await readFile33(absolute);
|
|
23890
|
+
const changed = !current.equals(data);
|
|
23891
|
+
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
23892
|
+
return { baseline, path: absolute, changed, cases: report };
|
|
23893
|
+
}
|
|
23422
23894
|
async function readQualityBaseline(baselinePath) {
|
|
23423
|
-
const absolute =
|
|
23895
|
+
const absolute = path47.resolve(baselinePath);
|
|
23424
23896
|
let raw;
|
|
23425
23897
|
try {
|
|
23426
|
-
raw = JSON.parse(await
|
|
23898
|
+
raw = JSON.parse(await readFile33(absolute, "utf8"));
|
|
23427
23899
|
} catch (error) {
|
|
23428
23900
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
23429
23901
|
}
|
|
23430
23902
|
const parsed = QualityBaselineSchema.safeParse(raw);
|
|
23431
23903
|
if (!parsed.success) {
|
|
23904
|
+
const cases = raw?.cases;
|
|
23905
|
+
const where = (issuePath) => {
|
|
23906
|
+
if (issuePath[0] === "cases" && typeof issuePath[1] === "number") {
|
|
23907
|
+
const id = cases?.[issuePath[1]]?.id;
|
|
23908
|
+
const rest = issuePath.slice(2).join(".");
|
|
23909
|
+
return typeof id === "string" ? `cases[${id}]${rest ? `.${rest}` : ""}` : issuePath.join(".");
|
|
23910
|
+
}
|
|
23911
|
+
return issuePath.join(".") || "$";
|
|
23912
|
+
};
|
|
23913
|
+
const missing = [...new Set(parsed.error.issues.flatMap((issue) => {
|
|
23914
|
+
const id = issue.path[0] === "cases" && typeof issue.path[1] === "number" ? cases?.[issue.path[1]]?.id : void 0;
|
|
23915
|
+
return issue.code === "invalid_type" && issue.received === "undefined" && typeof id === "string" ? [id] : [];
|
|
23916
|
+
}))];
|
|
23432
23917
|
throw new Error(
|
|
23433
23918
|
`Invalid quality baseline ${absolute}:
|
|
23434
|
-
` + parsed.error.issues.map((issue) => ` ${issue.path
|
|
23919
|
+
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
23920
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path47.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
23435
23921
|
);
|
|
23436
23922
|
}
|
|
23437
23923
|
return parsed.data;
|
|
@@ -23493,12 +23979,12 @@ function regressionViolations(expected, actual, tolerances) {
|
|
|
23493
23979
|
return { violations, warnings };
|
|
23494
23980
|
}
|
|
23495
23981
|
async function checkQualityBaseline(baselinePath) {
|
|
23496
|
-
const absolute =
|
|
23982
|
+
const absolute = path47.resolve(baselinePath);
|
|
23497
23983
|
const baseline = await readQualityBaseline(absolute);
|
|
23498
|
-
const root =
|
|
23984
|
+
const root = path47.dirname(absolute);
|
|
23499
23985
|
const cases = [];
|
|
23500
23986
|
for (const entry of baseline.cases) {
|
|
23501
|
-
const file =
|
|
23987
|
+
const file = path47.resolve(root, entry.file);
|
|
23502
23988
|
let actual = null;
|
|
23503
23989
|
const violations = [];
|
|
23504
23990
|
const warnings = [];
|
|
@@ -23511,7 +23997,7 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
23511
23997
|
violations.push(message4(error));
|
|
23512
23998
|
}
|
|
23513
23999
|
if (entry.record) {
|
|
23514
|
-
const recordPath =
|
|
24000
|
+
const recordPath = path47.resolve(root, entry.record.path);
|
|
23515
24001
|
try {
|
|
23516
24002
|
const recordHash = await sha256File(recordPath);
|
|
23517
24003
|
if (recordHash !== entry.record.sha256) violations.push("quality record hash changed");
|
|
@@ -23553,17 +24039,34 @@ async function runQuality(args) {
|
|
|
23553
24039
|
if (!args.out) throw new Error("quality snapshot needs --out <pixelkiln.quality.json>.");
|
|
23554
24040
|
let raw;
|
|
23555
24041
|
try {
|
|
23556
|
-
raw = JSON.parse(await
|
|
24042
|
+
raw = JSON.parse(await readFile34(path48.resolve(args.inputs), "utf8"));
|
|
23557
24043
|
} catch (error) {
|
|
23558
24044
|
throw new Error(
|
|
23559
|
-
`Could not read quality inputs ${
|
|
24045
|
+
`Could not read quality inputs ${path48.resolve(args.inputs)}: ${error instanceof Error ? error.message : String(error)}`,
|
|
23560
24046
|
{ cause: error }
|
|
23561
24047
|
);
|
|
23562
24048
|
}
|
|
23563
24049
|
const inputs = resolveQualityInputs(raw, args.inputs);
|
|
23564
|
-
if (
|
|
24050
|
+
if (path48.resolve(args.inputs) === path48.resolve(args.out)) {
|
|
23565
24051
|
throw new Error("quality snapshot --out must not overwrite its --inputs file.");
|
|
23566
24052
|
}
|
|
24053
|
+
if (args.assets.length) {
|
|
24054
|
+
const result2 = await snapshotQualityCases(inputs, args.out, args.assets, { dryRun: args.dryRun });
|
|
24055
|
+
if (args.json) {
|
|
24056
|
+
log(JSON.stringify({ version: 1, path: result2.path, changed: result2.changed, dryRun: args.dryRun, cases: result2.cases }, null, 2));
|
|
24057
|
+
return;
|
|
24058
|
+
}
|
|
24059
|
+
for (const entry of result2.cases ?? []) {
|
|
24060
|
+
log(` ${entry.kind === "unchanged" ? "unchanged" : args.dryRun ? `would ${entry.kind === "added" ? "add" : "update"}` : entry.kind} ${entry.id}`);
|
|
24061
|
+
for (const c of entry.changes) log(` ${c.metric}: ${JSON.stringify(c.before)} -> ${JSON.stringify(c.after)}`);
|
|
24062
|
+
}
|
|
24063
|
+
log(
|
|
24064
|
+
`
|
|
24065
|
+
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${path48.relative(process.cwd(), result2.path)}; other cases left as they were.`
|
|
24066
|
+
);
|
|
24067
|
+
return;
|
|
24068
|
+
}
|
|
24069
|
+
if (args.dryRun) throw new Error("quality snapshot --dry-run applies to a partial re-snapshot; add --only <id,...>.");
|
|
23567
24070
|
const result = await snapshotQualityBaseline(inputs, args.out, { force: args.force });
|
|
23568
24071
|
if (args.json) {
|
|
23569
24072
|
log(JSON.stringify({
|
|
@@ -23574,7 +24077,7 @@ async function runQuality(args) {
|
|
|
23574
24077
|
}, null, 2));
|
|
23575
24078
|
} else {
|
|
23576
24079
|
log(
|
|
23577
|
-
` ${result.changed ? "wrote" : "unchanged"} ${
|
|
24080
|
+
` ${result.changed ? "wrote" : "unchanged"} ${path48.relative(process.cwd(), result.path)} (${result.baseline.cases.length} case(s))`
|
|
23578
24081
|
);
|
|
23579
24082
|
log(` Review the tolerances, commit the baseline, then run quality check in CI.`);
|
|
23580
24083
|
}
|
|
@@ -23600,12 +24103,12 @@ async function runQuality(args) {
|
|
|
23600
24103
|
}
|
|
23601
24104
|
|
|
23602
24105
|
// src/cli/commands/recipe.ts
|
|
23603
|
-
import
|
|
24106
|
+
import path50 from "path";
|
|
23604
24107
|
|
|
23605
24108
|
// src/recipes.ts
|
|
23606
|
-
import
|
|
23607
|
-
import { existsSync as
|
|
23608
|
-
import { readdir as readdir3, readFile as
|
|
24109
|
+
import path49 from "path";
|
|
24110
|
+
import { existsSync as existsSync39 } from "fs";
|
|
24111
|
+
import { readdir as readdir3, readFile as readFile35 } from "fs/promises";
|
|
23609
24112
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
23610
24113
|
import { z as z14 } from "zod";
|
|
23611
24114
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
@@ -23614,7 +24117,7 @@ var VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
|
23614
24117
|
var RECIPE_FILE = "pixelkiln.recipe.json";
|
|
23615
24118
|
var RECIPE_DIR_TOKEN = "{{recipeDir}}";
|
|
23616
24119
|
var PortablePathSchema = z14.string().min(1).refine((value) => {
|
|
23617
|
-
if (value.includes("\\") ||
|
|
24120
|
+
if (value.includes("\\") || path49.posix.isAbsolute(value)) return false;
|
|
23618
24121
|
const parts = value.split("/");
|
|
23619
24122
|
return !parts.includes("") && !parts.includes(".") && !parts.includes("..");
|
|
23620
24123
|
}, "expected a portable relative path without '.', '..', or backslashes");
|
|
@@ -23790,10 +24293,10 @@ function message5(error) {
|
|
|
23790
24293
|
return error instanceof Error ? error.message : String(error);
|
|
23791
24294
|
}
|
|
23792
24295
|
async function readRecipeFile(recipePath, bundled) {
|
|
23793
|
-
const absolute =
|
|
24296
|
+
const absolute = path49.resolve(recipePath);
|
|
23794
24297
|
let raw;
|
|
23795
24298
|
try {
|
|
23796
|
-
raw = JSON.parse(await
|
|
24299
|
+
raw = JSON.parse(await readFile35(absolute, "utf8"));
|
|
23797
24300
|
} catch (error) {
|
|
23798
24301
|
throw new Error(`Could not read recipe ${absolute}: ${message5(error)}`, { cause: error });
|
|
23799
24302
|
}
|
|
@@ -23804,13 +24307,13 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
23804
24307
|
` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
|
|
23805
24308
|
);
|
|
23806
24309
|
}
|
|
23807
|
-
return { recipe: parsed.data, authored: raw, path: absolute, dir:
|
|
24310
|
+
return { recipe: parsed.data, authored: raw, path: absolute, dir: path49.dirname(absolute), bundled };
|
|
23808
24311
|
}
|
|
23809
24312
|
async function walkRecipeFiles(root) {
|
|
23810
|
-
if (!
|
|
24313
|
+
if (!existsSync39(root)) return [];
|
|
23811
24314
|
const out = [];
|
|
23812
24315
|
for (const entry of await readdir3(root, { withFileTypes: true })) {
|
|
23813
|
-
const resolved =
|
|
24316
|
+
const resolved = path49.join(root, entry.name);
|
|
23814
24317
|
if (entry.isDirectory()) out.push(...await walkRecipeFiles(resolved));
|
|
23815
24318
|
else if (entry.isFile() && entry.name === RECIPE_FILE) out.push(resolved);
|
|
23816
24319
|
}
|
|
@@ -23821,7 +24324,7 @@ function bundledRecipeRoot() {
|
|
|
23821
24324
|
}
|
|
23822
24325
|
async function listBundledRecipes(root = bundledRecipeRoot()) {
|
|
23823
24326
|
const recipes = await Promise.all(
|
|
23824
|
-
(await walkRecipeFiles(
|
|
24327
|
+
(await walkRecipeFiles(path49.resolve(root))).map((file) => readRecipeFile(file, true))
|
|
23825
24328
|
);
|
|
23826
24329
|
return recipes.sort(
|
|
23827
24330
|
(a, b) => a.recipe.id.localeCompare(b.recipe.id) || compareVersions(b.recipe.version, a.recipe.version)
|
|
@@ -23844,9 +24347,9 @@ function parseSelector(selector) {
|
|
|
23844
24347
|
return { id: match[1], version: match[2] };
|
|
23845
24348
|
}
|
|
23846
24349
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
23847
|
-
const local =
|
|
23848
|
-
if (
|
|
23849
|
-
const recipePath =
|
|
24350
|
+
const local = path49.resolve(target);
|
|
24351
|
+
if (existsSync39(local)) {
|
|
24352
|
+
const recipePath = path49.basename(local) === RECIPE_FILE ? local : path49.join(local, RECIPE_FILE);
|
|
23850
24353
|
return readRecipeFile(recipePath, false);
|
|
23851
24354
|
}
|
|
23852
24355
|
if (target.startsWith(".") || target.startsWith("/") || target.includes("\\")) {
|
|
@@ -23860,8 +24363,8 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
23860
24363
|
return matches[0];
|
|
23861
24364
|
}
|
|
23862
24365
|
async function verifyFile(root, file) {
|
|
23863
|
-
const absolute =
|
|
23864
|
-
if (!
|
|
24366
|
+
const absolute = path49.resolve(root, ...file.path.split("/"));
|
|
24367
|
+
if (!existsSync39(absolute)) {
|
|
23865
24368
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
23866
24369
|
}
|
|
23867
24370
|
const actualSha256 = await sha256File(absolute);
|
|
@@ -23876,7 +24379,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
23876
24379
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
23877
24380
|
const actualIntegrity = recipeDigest(loaded.authored);
|
|
23878
24381
|
const files = await Promise.all(loaded.recipe.files.map((file) => verifyFile(loaded.dir, file)));
|
|
23879
|
-
const modelRoot = options.modelRoot ?
|
|
24382
|
+
const modelRoot = options.modelRoot ? path49.resolve(options.modelRoot) : null;
|
|
23880
24383
|
const models = modelRoot ? await Promise.all(loaded.recipe.models.map(async (model) => ({
|
|
23881
24384
|
...await verifyFile(modelRoot, model),
|
|
23882
24385
|
source: model.source,
|
|
@@ -23910,7 +24413,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
23910
24413
|
};
|
|
23911
24414
|
}
|
|
23912
24415
|
function renderStyle(style, destination, cwd) {
|
|
23913
|
-
const portableDir =
|
|
24416
|
+
const portableDir = path49.relative(cwd, destination).split(path49.sep).join("/") || ".";
|
|
23914
24417
|
const replace = (value) => {
|
|
23915
24418
|
if (typeof value === "string") return value.replaceAll(RECIPE_DIR_TOKEN, portableDir);
|
|
23916
24419
|
if (Array.isArray(value)) return value.map(replace);
|
|
@@ -23922,25 +24425,25 @@ function renderStyle(style, destination, cwd) {
|
|
|
23922
24425
|
return replace(style);
|
|
23923
24426
|
}
|
|
23924
24427
|
async function installRecipe(target, options = {}) {
|
|
23925
|
-
const cwd =
|
|
24428
|
+
const cwd = path49.resolve(options.cwd ?? process.cwd());
|
|
23926
24429
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
23927
24430
|
const verification = await verifyRecipe(loaded.path);
|
|
23928
24431
|
if (!verification.ok) {
|
|
23929
24432
|
throw new Error(`Recipe ${loaded.recipe.id}@${loaded.recipe.version} failed integrity verification.`);
|
|
23930
24433
|
}
|
|
23931
|
-
const destination = options.out ?
|
|
24434
|
+
const destination = options.out ? path49.resolve(cwd, options.out) : path49.join(cwd, "pixelkiln-recipes", ...loaded.recipe.id.split("/"), loaded.recipe.version);
|
|
23932
24435
|
const sources = [
|
|
23933
24436
|
{ path: RECIPE_FILE, source: loaded.path },
|
|
23934
|
-
...loaded.recipe.files.map((file) => ({ path: file.path, source:
|
|
24437
|
+
...loaded.recipe.files.map((file) => ({ path: file.path, source: path49.join(loaded.dir, ...file.path.split("/")) }))
|
|
23935
24438
|
];
|
|
23936
24439
|
const files = await Promise.all(sources.map(async (file) => ({
|
|
23937
|
-
path:
|
|
23938
|
-
data: await
|
|
24440
|
+
path: path49.join(destination, ...file.path.split("/")),
|
|
24441
|
+
data: await readFile35(file.source)
|
|
23939
24442
|
})));
|
|
23940
24443
|
if (!options.force) {
|
|
23941
24444
|
for (const file of files) {
|
|
23942
|
-
if (!
|
|
23943
|
-
const current = await
|
|
24445
|
+
if (!existsSync39(file.path)) continue;
|
|
24446
|
+
const current = await readFile35(file.path);
|
|
23944
24447
|
if (!current.equals(file.data)) {
|
|
23945
24448
|
throw new OverwriteRefusedError(
|
|
23946
24449
|
`Recipe destination has local changes: ${file.path}. Choose another --out or pass --force to replace declared recipe files.`,
|
|
@@ -24034,14 +24537,14 @@ async function runRecipe(args) {
|
|
|
24034
24537
|
}, null, 2));
|
|
24035
24538
|
} else {
|
|
24036
24539
|
log(` installed ${result.recipe.id}@${result.recipe.version}`);
|
|
24037
|
-
log(` ${
|
|
24540
|
+
log(` ${path50.relative(process.cwd(), result.destination) || "."}`);
|
|
24038
24541
|
log(`
|
|
24039
24542
|
Add this entry under your manifest's styles object:`);
|
|
24040
24543
|
log(JSON.stringify({ [result.styleId]: result.style }, null, 2));
|
|
24041
24544
|
if (result.recipe.models.length) {
|
|
24042
24545
|
log(`
|
|
24043
24546
|
Models are not downloaded automatically. Verify them with:`);
|
|
24044
|
-
log(` pixelkiln recipe verify ${
|
|
24547
|
+
log(` pixelkiln recipe verify ${path50.relative(process.cwd(), result.destination)} --model-root <ComfyUI/models>`);
|
|
24045
24548
|
}
|
|
24046
24549
|
}
|
|
24047
24550
|
return;
|
|
@@ -24049,7 +24552,7 @@ async function runRecipe(args) {
|
|
|
24049
24552
|
}
|
|
24050
24553
|
|
|
24051
24554
|
// src/cli/commands/refine.ts
|
|
24052
|
-
import
|
|
24555
|
+
import path51 from "path";
|
|
24053
24556
|
async function runRefine(args) {
|
|
24054
24557
|
if (args.from || args.subcommand === "approve") {
|
|
24055
24558
|
if (!args.from) {
|
|
@@ -24079,12 +24582,12 @@ async function runRefine(args) {
|
|
|
24079
24582
|
` recovered ${result3.detection.columns}x${result3.detection.rows} native grid (${result3.detection.confidence}: ${result3.detection.consensus})`
|
|
24080
24583
|
);
|
|
24081
24584
|
log(` enforced ${result3.palette.length}-color palette without dithering`);
|
|
24082
|
-
log(` wrote ${
|
|
24083
|
-
log(` quality record: ${
|
|
24585
|
+
log(` wrote ${path51.relative(process.cwd(), result3.output)}`);
|
|
24586
|
+
log(` quality record: ${path51.relative(process.cwd(), result3.record)}`);
|
|
24084
24587
|
log(`
|
|
24085
24588
|
Automated checks passed. Human 1\xD7 review is still required:`);
|
|
24086
24589
|
log(
|
|
24087
|
-
` pixelkiln refine approve --from ${
|
|
24590
|
+
` pixelkiln refine approve --from ${path51.relative(process.cwd(), result3.record)} --reviewer "Your Name"`
|
|
24088
24591
|
);
|
|
24089
24592
|
}
|
|
24090
24593
|
return;
|
|
@@ -24112,7 +24615,7 @@ async function runRefine(args) {
|
|
|
24112
24615
|
if (args.json) log(JSON.stringify(result3, null, 2));
|
|
24113
24616
|
else {
|
|
24114
24617
|
log(
|
|
24115
|
-
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${
|
|
24618
|
+
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${path51.relative(process.cwd(), result3.record)} by ${args.reviewer.trim()}` : ` approved ${path51.relative(process.cwd(), result3.output)} by ${args.reviewer.trim()}`
|
|
24116
24619
|
);
|
|
24117
24620
|
}
|
|
24118
24621
|
return;
|
|
@@ -24121,7 +24624,7 @@ async function runRefine(args) {
|
|
|
24121
24624
|
if (args.json) {
|
|
24122
24625
|
log(JSON.stringify(result2, null, 2));
|
|
24123
24626
|
} else {
|
|
24124
|
-
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${
|
|
24627
|
+
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${path51.relative(process.cwd(), result2.output || result2.record)}`);
|
|
24125
24628
|
for (const reason of result2.reasons) log(` ${reason}`);
|
|
24126
24629
|
}
|
|
24127
24630
|
if (!result2.safe) process.exitCode = 1;
|
|
@@ -24167,7 +24670,7 @@ async function runRefine(args) {
|
|
|
24167
24670
|
log(` ${item.state.padEnd(16)} ${item.key} ${item.reason}`);
|
|
24168
24671
|
if (item.state === "needs-approval") {
|
|
24169
24672
|
log(
|
|
24170
|
-
` pixelkiln refine approve --from ${
|
|
24673
|
+
` pixelkiln refine approve --from ${path51.relative(process.cwd(), item.record)} --reviewer "Your Name"`
|
|
24171
24674
|
);
|
|
24172
24675
|
}
|
|
24173
24676
|
}
|
|
@@ -24178,9 +24681,9 @@ async function runRefine(args) {
|
|
|
24178
24681
|
}
|
|
24179
24682
|
|
|
24180
24683
|
// src/cli/commands/skeleton.ts
|
|
24181
|
-
import
|
|
24182
|
-
import { existsSync as
|
|
24183
|
-
import { readFile as
|
|
24684
|
+
import path52 from "path";
|
|
24685
|
+
import { existsSync as existsSync40 } from "fs";
|
|
24686
|
+
import { readFile as readFile36, writeFile as writeFile20 } from "fs/promises";
|
|
24184
24687
|
|
|
24185
24688
|
// src/skeleton-preview.ts
|
|
24186
24689
|
var RIGHT = [255, 140, 40, 255];
|
|
@@ -24291,12 +24794,12 @@ var Canvas = class {
|
|
|
24291
24794
|
async function runEstimateSkeleton(args) {
|
|
24292
24795
|
const image = args.target;
|
|
24293
24796
|
if (!image) throw new UsageError("estimate-skeleton needs an image path: pixelkiln estimate-skeleton <image> [--out keypoints.json]");
|
|
24294
|
-
if (args.out &&
|
|
24797
|
+
if (args.out && existsSync40(path52.resolve(args.out)) && !args.force) {
|
|
24295
24798
|
throw new UsageError(`${args.out} already exists; pass --force to replace it`);
|
|
24296
24799
|
}
|
|
24297
|
-
loadEnvFiles(
|
|
24800
|
+
loadEnvFiles(path52.dirname(path52.resolve(args.manifest)));
|
|
24298
24801
|
loadEnvFiles(process.cwd());
|
|
24299
|
-
const bytes = await
|
|
24802
|
+
const bytes = await readFile36(path52.resolve(image));
|
|
24300
24803
|
const metadata = imageMetadata(bytes);
|
|
24301
24804
|
if (!metadata) throw new UsageError(`${image} is not a readable PNG or JPEG`);
|
|
24302
24805
|
const sizeProblem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
|
|
@@ -24308,7 +24811,7 @@ async function runEstimateSkeleton(args) {
|
|
|
24308
24811
|
const frames = args.frames ?? DEFAULT_SCAFFOLD_FRAMES;
|
|
24309
24812
|
const json = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames), null, 2);
|
|
24310
24813
|
if (args.out) {
|
|
24311
|
-
await writeFile20(
|
|
24814
|
+
await writeFile20(path52.resolve(args.out), json + "\n");
|
|
24312
24815
|
log(` wrote ${args.out}: the estimated pose and ${frames} frames to edit`);
|
|
24313
24816
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
24314
24817
|
} else {
|
|
@@ -24321,8 +24824,8 @@ async function runSkeletonPreview(args) {
|
|
|
24321
24824
|
let sourceFile;
|
|
24322
24825
|
let label;
|
|
24323
24826
|
if (target.endsWith(".json")) {
|
|
24324
|
-
keypointsFile =
|
|
24325
|
-
sourceFile = args.from ?
|
|
24827
|
+
keypointsFile = path52.resolve(target);
|
|
24828
|
+
sourceFile = args.from ? path52.resolve(args.from) : void 0;
|
|
24326
24829
|
label = target;
|
|
24327
24830
|
} else {
|
|
24328
24831
|
const loaded = await loadManifest(args.manifest);
|
|
@@ -24334,31 +24837,31 @@ async function runSkeletonPreview(args) {
|
|
|
24334
24837
|
);
|
|
24335
24838
|
}
|
|
24336
24839
|
keypointsFile = spec.revision.keypointsFile;
|
|
24337
|
-
sourceFile = args.from ?
|
|
24840
|
+
sourceFile = args.from ? path52.resolve(args.from) : spec.revision.sourceFile;
|
|
24338
24841
|
label = `${spec.styleId}/${spec.assetId}`;
|
|
24339
24842
|
}
|
|
24340
|
-
if (!
|
|
24843
|
+
if (!existsSync40(keypointsFile)) throw new UsageError(`Keypoints file does not exist yet: ${keypointsFile}`);
|
|
24341
24844
|
let json;
|
|
24342
24845
|
try {
|
|
24343
|
-
json = JSON.parse(await
|
|
24846
|
+
json = JSON.parse(await readFile36(keypointsFile, "utf8"));
|
|
24344
24847
|
} catch (error) {
|
|
24345
24848
|
throw new UsageError(`${keypointsFile} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
24346
24849
|
}
|
|
24347
24850
|
const set = parseSkeletonSet(json, keypointsFile);
|
|
24348
24851
|
let source;
|
|
24349
24852
|
if (sourceFile) {
|
|
24350
|
-
if (!
|
|
24853
|
+
if (!existsSync40(sourceFile)) {
|
|
24351
24854
|
log(` source image does not exist yet, drawing on a plain ground: ${sourceFile}`);
|
|
24352
24855
|
} else {
|
|
24353
|
-
const bytes = await
|
|
24856
|
+
const bytes = await readFile36(sourceFile);
|
|
24354
24857
|
if (imageMetadata(bytes)?.format !== "png") throw new UsageError(`${sourceFile} must be a PNG to preview over`);
|
|
24355
24858
|
source = decodePng(bytes);
|
|
24356
24859
|
}
|
|
24357
24860
|
}
|
|
24358
|
-
const out =
|
|
24861
|
+
const out = path52.resolve(args.out ?? keypointsFile.replace(/\.json$/, "") + ".preview.png");
|
|
24359
24862
|
await writeFile20(out, renderSkeletonSheet(set, { source }));
|
|
24360
24863
|
log(` ${label}: ${set.frames.length} frames after the starting pose`);
|
|
24361
|
-
const shown =
|
|
24864
|
+
const shown = path52.relative(process.cwd(), out);
|
|
24362
24865
|
log(` wrote ${shown.startsWith("..") ? out : shown}`);
|
|
24363
24866
|
}
|
|
24364
24867
|
|
|
@@ -24404,15 +24907,15 @@ async function runTools(args) {
|
|
|
24404
24907
|
}
|
|
24405
24908
|
|
|
24406
24909
|
// src/cli/commands/workspace.ts
|
|
24407
|
-
import
|
|
24408
|
-
import { existsSync as
|
|
24910
|
+
import path53 from "path";
|
|
24911
|
+
import { existsSync as existsSync41 } from "fs";
|
|
24409
24912
|
async function runWorkspace(args) {
|
|
24410
|
-
const workspacePath =
|
|
24411
|
-
const dir =
|
|
24913
|
+
const workspacePath = path53.resolve(args.workspace ?? "pixelkiln.workspace.json");
|
|
24914
|
+
const dir = path53.dirname(workspacePath);
|
|
24412
24915
|
if (args.subcommand === "add") {
|
|
24413
|
-
const manifestPath =
|
|
24916
|
+
const manifestPath = path53.resolve(args.target);
|
|
24414
24917
|
const loadedTarget = await loadManifest(manifestPath);
|
|
24415
|
-
const lockPath = args.explicitLock ?
|
|
24918
|
+
const lockPath = args.explicitLock ? path53.resolve(args.explicitLock) : path53.join(path53.dirname(manifestPath), "pixelkiln.lock.json");
|
|
24416
24919
|
const ws = await loadWorkspace(workspacePath);
|
|
24417
24920
|
const id = args.name ?? loadedTarget.manifest.name;
|
|
24418
24921
|
if (ws.projects.some((p) => p.id === id)) {
|
|
@@ -24432,10 +24935,10 @@ async function runWorkspace(args) {
|
|
|
24432
24935
|
...args.account ? { account: args.account } : {}
|
|
24433
24936
|
};
|
|
24434
24937
|
await saveWorkspace(workspacePath, { version: 1, projects: [...ws.projects, project] });
|
|
24435
|
-
log(` registered "${id}" in ${
|
|
24938
|
+
log(` registered "${id}" in ${path53.relative(process.cwd(), workspacePath)}`);
|
|
24436
24939
|
log(` manifest: ${project.manifest}`);
|
|
24437
24940
|
log(` lock: ${project.lock}`);
|
|
24438
|
-
if (!
|
|
24941
|
+
if (!existsSync41(lockPath)) {
|
|
24439
24942
|
log(
|
|
24440
24943
|
` warning: no lockfile there yet; this project contributes no claims until one is generated`
|
|
24441
24944
|
);
|
|
@@ -24444,7 +24947,7 @@ async function runWorkspace(args) {
|
|
|
24444
24947
|
}
|
|
24445
24948
|
if (args.subcommand === "remove") {
|
|
24446
24949
|
const ws = await loadWorkspace(workspacePath);
|
|
24447
|
-
const resolvedTarget =
|
|
24950
|
+
const resolvedTarget = path53.resolve(args.target);
|
|
24448
24951
|
const match = ws.projects.find(
|
|
24449
24952
|
(p) => p.id === args.target || resolveProject(dir, p).manifestPath === resolvedTarget
|
|
24450
24953
|
);
|
|
@@ -24455,11 +24958,11 @@ async function runWorkspace(args) {
|
|
|
24455
24958
|
version: 1,
|
|
24456
24959
|
projects: ws.projects.filter((p) => p !== match)
|
|
24457
24960
|
});
|
|
24458
|
-
log(` removed "${match.id}" from ${
|
|
24961
|
+
log(` removed "${match.id}" from ${path53.relative(process.cwd(), workspacePath)}`);
|
|
24459
24962
|
return;
|
|
24460
24963
|
}
|
|
24461
24964
|
if (args.subcommand === "list") {
|
|
24462
|
-
if (!
|
|
24965
|
+
if (!existsSync41(workspacePath)) {
|
|
24463
24966
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
24464
24967
|
}
|
|
24465
24968
|
const ws = await loadWorkspace(workspacePath);
|
|
@@ -24467,9 +24970,9 @@ async function runWorkspace(args) {
|
|
|
24467
24970
|
if (args.json) {
|
|
24468
24971
|
log(JSON.stringify({ version: 1, workspace: workspacePath, projects: ws.projects, diagnostics }, null, 2));
|
|
24469
24972
|
} else if (!ws.projects.length) {
|
|
24470
|
-
log(` no projects registered in ${
|
|
24973
|
+
log(` no projects registered in ${path53.relative(process.cwd(), workspacePath)}`);
|
|
24471
24974
|
} else {
|
|
24472
|
-
log(` ${ws.projects.length} project(s) in ${
|
|
24975
|
+
log(` ${ws.projects.length} project(s) in ${path53.relative(process.cwd(), workspacePath)}:`);
|
|
24473
24976
|
for (const p of ws.projects) {
|
|
24474
24977
|
log(` ${p.id.padEnd(24)} ${p.manifest.padEnd(40)} (${p.provider}${p.account ? `, ${p.account}` : ""})`);
|
|
24475
24978
|
}
|
|
@@ -24479,7 +24982,7 @@ async function runWorkspace(args) {
|
|
|
24479
24982
|
return;
|
|
24480
24983
|
}
|
|
24481
24984
|
if (args.subcommand === "status") {
|
|
24482
|
-
if (!
|
|
24985
|
+
if (!existsSync41(workspacePath)) {
|
|
24483
24986
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
24484
24987
|
}
|
|
24485
24988
|
const ws = await loadWorkspace(workspacePath);
|
|
@@ -24487,7 +24990,7 @@ async function runWorkspace(args) {
|
|
|
24487
24990
|
if (args.json) {
|
|
24488
24991
|
log(JSON.stringify({ ...report, workspace: workspacePath }, null, 2));
|
|
24489
24992
|
} else {
|
|
24490
|
-
log(` workspace: ${
|
|
24993
|
+
log(` workspace: ${path53.relative(process.cwd(), workspacePath)}`);
|
|
24491
24994
|
for (const p of report.projects) {
|
|
24492
24995
|
if (p.error) {
|
|
24493
24996
|
log(`
|
|
@@ -24541,8 +25044,8 @@ async function runHelp() {
|
|
|
24541
25044
|
async function runVersion() {
|
|
24542
25045
|
for (const up of ["../package.json", "../../package.json"]) {
|
|
24543
25046
|
const url = new URL(up, import.meta.url);
|
|
24544
|
-
if (!
|
|
24545
|
-
const pkg = JSON.parse(await
|
|
25047
|
+
if (!existsSync42(url)) continue;
|
|
25048
|
+
const pkg = JSON.parse(await readFile37(url, "utf8"));
|
|
24546
25049
|
if (pkg.name === "pixelkiln") {
|
|
24547
25050
|
log(`${pkg.name} ${pkg.version}`);
|
|
24548
25051
|
return;
|
|
@@ -24558,6 +25061,7 @@ var RUNNERS = {
|
|
|
24558
25061
|
"-v": runVersion,
|
|
24559
25062
|
init: runInit,
|
|
24560
25063
|
plan: runPlan,
|
|
25064
|
+
hash: runHash,
|
|
24561
25065
|
doctor: runDoctor,
|
|
24562
25066
|
gen: runGenerate,
|
|
24563
25067
|
submit: runGenerate,
|