pixelkiln 0.92.2 → 0.93.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/PROVIDERS.md +2 -2
- package/dist/cli.js +578 -230
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +505 -220
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +193 -26
- package/dist/index.d.ts +193 -26
- package/dist/index.js +465 -186
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +51 -1
- package/docs/ENDPOINTS.md +39 -37
- package/docs/GENERATORS.md +36 -27
- package/docs/PIXELLAB.md +2 -2
- package/docs/REVISIONS.md +31 -27
- package/package.json +1 -1
- package/skills/pixelkiln/references/pixellab-fidelity.md +2 -1
- package/skills/pixelkiln/references/pixellab-roadmap.md +31 -23
- package/skills/pixelkiln/references/pixellab.md +19 -16
package/dist/index.js
CHANGED
|
@@ -46,6 +46,17 @@ function candidateCount(size) {
|
|
|
46
46
|
if (size <= 170) return 4;
|
|
47
47
|
return 1;
|
|
48
48
|
}
|
|
49
|
+
function uiElementCandidateCount(size) {
|
|
50
|
+
if (size <= 32) return 64;
|
|
51
|
+
if (size <= 35) return 49;
|
|
52
|
+
if (size <= 41) return 36;
|
|
53
|
+
if (size <= 50) return 25;
|
|
54
|
+
if (size <= 64) return 16;
|
|
55
|
+
if (size <= 84) return 9;
|
|
56
|
+
if (size === 85) return 16;
|
|
57
|
+
if (size <= 170) return 4;
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
49
60
|
function generationCost(width, height, generator = "map") {
|
|
50
61
|
if (generator === "vfx") return 0;
|
|
51
62
|
if (generator === "map" || generator === "pixflux") return 1;
|
|
@@ -62,6 +73,16 @@ function proTierCost(width, height) {
|
|
|
62
73
|
if (px <= 102400) return PRO_TIER_PRICES[1];
|
|
63
74
|
return PRO_TIER_PRICES[2];
|
|
64
75
|
}
|
|
76
|
+
function pixMiniMaxCost(width, height, frames, enhancePrompt = false) {
|
|
77
|
+
const f = width * height * Math.max(1, frames) / 4096;
|
|
78
|
+
let units;
|
|
79
|
+
if (f <= 8) units = 1;
|
|
80
|
+
else if (f <= 16) units = 1 + (f - 8) / 8;
|
|
81
|
+
else if (f <= 40) units = 2 + (f - 16) / 6;
|
|
82
|
+
else units = 6 + (f - 40) / 6;
|
|
83
|
+
const base = Math.max(1, Math.ceil(units - 1e-9));
|
|
84
|
+
return enhancePrompt ? base + 0.05 : base;
|
|
85
|
+
}
|
|
65
86
|
function tilesCost(tileSize, variations) {
|
|
66
87
|
const px = tileSize * tileSize * Math.max(1, variations);
|
|
67
88
|
if (px <= 1024) return PRO_TIER_PRICES[0];
|
|
@@ -1559,7 +1580,17 @@ var LockEntrySchema = z.object({
|
|
|
1559
1580
|
/** Generations this entry replaced, newest first; see LockHistoryEntrySchema. */
|
|
1560
1581
|
history: z.array(LockHistoryEntrySchema).optional(),
|
|
1561
1582
|
/** Post-processing applied to the recorded outputs; absent when the bytes are the provider's. */
|
|
1562
|
-
postprocess: PostprocessSchema.optional()
|
|
1583
|
+
postprocess: PostprocessSchema.optional(),
|
|
1584
|
+
/**
|
|
1585
|
+
* Set when the entry records art made outside pixelkiln (the PixelLab MCP, a
|
|
1586
|
+
* hand edit, another tool) and brought in with `adopt --local`: nothing was
|
|
1587
|
+
* submitted, so jobId and cost are empty. Absent on generated entries.
|
|
1588
|
+
*/
|
|
1589
|
+
imported: z.object({
|
|
1590
|
+
source: z.string().min(1),
|
|
1591
|
+
note: z.string().optional(),
|
|
1592
|
+
importedAt: z.string()
|
|
1593
|
+
}).strict().optional()
|
|
1563
1594
|
});
|
|
1564
1595
|
var LockSchema = z.object({
|
|
1565
1596
|
version: z.literal(2),
|
|
@@ -2881,10 +2912,10 @@ var PixelLabClient = class {
|
|
|
2881
2912
|
* limited to 400x400 and no style reference. Like a revision, this hands
|
|
2882
2913
|
* back a plain background job with no resource of its own; unlike a
|
|
2883
2914
|
* revision, one call returns several candidate images to pick from (the
|
|
2884
|
-
* same 4/16/64-by-size tiering as `1dir`), not a single result
|
|
2885
|
-
*
|
|
2886
|
-
* pixellab.ts fails loudly rather than guess if `last_response.images`
|
|
2887
|
-
*
|
|
2915
|
+
* same 4/16/64-by-size tiering as `1dir`), not a single result. It has run
|
|
2916
|
+
* live (a 64x64 call billed 10, October 2026); `pollImagePro` in
|
|
2917
|
+
* pixellab.ts still fails loudly rather than guess if `last_response.images`
|
|
2918
|
+
* is not the field name.
|
|
2888
2919
|
*
|
|
2889
2920
|
* Reference images and a style image (`reference_images`, `style_image` +
|
|
2890
2921
|
* `style_options`) exist on this endpoint but are not modeled here yet.
|
|
@@ -2995,7 +3026,8 @@ var PixelLabClient = class {
|
|
|
2995
3026
|
* guided by an optional concept image and a natural-language color
|
|
2996
3027
|
* palette. A plain background job; unlike `/create-ui-asset` there is no
|
|
2997
3028
|
* piece/element layout, and sizes start at 16px instead of 192. Its
|
|
2998
|
-
* completed shape
|
|
3029
|
+
* completed shape came back as a list of candidates on a live
|
|
3030
|
+
* 32x32 call (64 of them, billed 10); `pollUiElement` still reads it
|
|
2999
3031
|
* defensively.
|
|
3000
3032
|
*/
|
|
3001
3033
|
async generateUiV2(args) {
|
|
@@ -3241,11 +3273,10 @@ var PixelLabClient = class {
|
|
|
3241
3273
|
* no PixelLab character/object resource required — unlike `animateCharacter`
|
|
3242
3274
|
* / `animateObject`, `firstFrame` is whatever bytes the caller has on hand.
|
|
3243
3275
|
* A plain background job, like every other PixelLab async submission;
|
|
3244
|
-
*
|
|
3245
|
-
*
|
|
3246
|
-
*
|
|
3247
|
-
*
|
|
3248
|
-
* defensively, the same as `pollRevision` already does for image edits).
|
|
3276
|
+
* like `inpaintV3`/`editImagesV2`, it has run live (November 2026, a
|
|
3277
|
+
* 64x64 call of 4 frames billed 1 and returned 5 frames); `pollAnimateRevision`
|
|
3278
|
+
* in pixellab.ts still checks several plausible field names for the frame
|
|
3279
|
+
* list defensively, the same as `pollRevision` does for image edits.
|
|
3249
3280
|
*/
|
|
3250
3281
|
async animateWithTextV3(args) {
|
|
3251
3282
|
const body = { first_frame: args.firstFrame, action: args.action };
|
|
@@ -3329,8 +3360,8 @@ var PixelLabClient = class {
|
|
|
3329
3360
|
* `runEstimateSkeleton` in `src/cli/commands`) so the only PixelLab
|
|
3330
3361
|
* endpoint composed into `animate-with-skeleton-v3`'s submission is that
|
|
3331
3362
|
* one endpoint itself, not two unverified calls chained together.
|
|
3332
|
-
* Synchronous
|
|
3333
|
-
*
|
|
3363
|
+
* Synchronous, and it has run live (October 2026; see
|
|
3364
|
+
* `EstimateSkeletonResponseSchema`).
|
|
3334
3365
|
*/
|
|
3335
3366
|
async estimateSkeleton(args) {
|
|
3336
3367
|
const body = { image: { type: "base64", base64: args.image.base64, format: args.image.format } };
|
|
@@ -5242,12 +5273,15 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
5242
5273
|
const width = spec.revision.sourceWidth ?? spec.width;
|
|
5243
5274
|
const height = spec.revision.sourceHeight ?? spec.height;
|
|
5244
5275
|
const side = spec.revision.mode === "edit-animation" ? Math.ceil(Math.sqrt(Math.max(1, spec.revision.sourceMembers?.length ?? 1))) : 1;
|
|
5245
|
-
return { unit: "generations", amount:
|
|
5276
|
+
return { unit: "generations", amount: proTierCost(width * side, height * side), candidates: 1 };
|
|
5246
5277
|
}
|
|
5247
5278
|
if (spec.revision?.mode === "animate" || spec.revision?.mode === "animate-pixminimax") {
|
|
5248
5279
|
const width = spec.revision.sourceWidth ?? spec.width;
|
|
5249
5280
|
const height = spec.revision.sourceHeight ?? spec.height;
|
|
5250
5281
|
const frames = spec.revision.frames ?? 8;
|
|
5282
|
+
if (spec.revision.mode === "animate-pixminimax") {
|
|
5283
|
+
return { unit: "generations", amount: pixMiniMaxCost(width, height, frames, spec.revision.enhancePrompt), candidates: 1 };
|
|
5284
|
+
}
|
|
5251
5285
|
const base = Math.max(1, Math.ceil(width * height * frames / 65536));
|
|
5252
5286
|
return { unit: "generations", amount: spec.revision.enhancePrompt ? base + 0.05 : base, candidates: 1 };
|
|
5253
5287
|
}
|
|
@@ -5278,7 +5312,7 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
5278
5312
|
return {
|
|
5279
5313
|
unit: "generations",
|
|
5280
5314
|
amount: generationCost(spec.width, spec.height, spec.generator),
|
|
5281
|
-
candidates: spec.generator === "1dir" || spec.generator === "imagePro" ? candidateCount(spec.size) : 1
|
|
5315
|
+
candidates: spec.generator === "1dir" || spec.generator === "imagePro" ? candidateCount(spec.size) : spec.generator === "uiElement" ? uiElementCandidateCount(spec.size) : 1
|
|
5282
5316
|
};
|
|
5283
5317
|
}
|
|
5284
5318
|
validate(spec, styleImages) {
|
|
@@ -6966,13 +7000,13 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
6966
7000
|
async pollVfx(jobId, context) {
|
|
6967
7001
|
const dir = _PixelLabProvider.cacheDir("vfx");
|
|
6968
7002
|
const sidecar = path3.join(dir, `${jobId}.json`);
|
|
6969
|
-
const
|
|
7003
|
+
const cached2 = () => {
|
|
6970
7004
|
if (!existsSync3(sidecar)) return null;
|
|
6971
7005
|
const facts2 = JSON.parse(readFileSync(sidecar, "utf8"));
|
|
6972
7006
|
const files2 = Array.from({ length: facts2.count }, (_, index) => path3.join(dir, `${jobId}-${index}.png`));
|
|
6973
7007
|
return files2.every((file) => existsSync3(file)) ? { facts: facts2, files: files2 } : null;
|
|
6974
7008
|
};
|
|
6975
|
-
let found =
|
|
7009
|
+
let found = cached2();
|
|
6976
7010
|
const recorded = context?.metadata?.vfx;
|
|
6977
7011
|
let artistDone;
|
|
6978
7012
|
if (!found && recorded?.artist) {
|
|
@@ -6992,11 +7026,11 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
6992
7026
|
}
|
|
6993
7027
|
artistDone.billed = billedFromUsage(job.usage);
|
|
6994
7028
|
}
|
|
6995
|
-
found =
|
|
7029
|
+
found = cached2();
|
|
6996
7030
|
} else if (!found && recorded?.downloadBase && Array.isArray(recorded.files)) {
|
|
6997
7031
|
const exported = recorded;
|
|
6998
7032
|
await this.cacheVfxFrames(jobId, exported, workbenchVfxUrls(exported));
|
|
6999
|
-
found =
|
|
7033
|
+
found = cached2();
|
|
7000
7034
|
}
|
|
7001
7035
|
if (!found) {
|
|
7002
7036
|
return {
|
|
@@ -7128,15 +7162,15 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
7128
7162
|
* `pollRevision` above, but completing with an ORDERED FRAME LIST instead
|
|
7129
7163
|
* of a single image — the same `review-set` shape `pollCharacterAnimation`
|
|
7130
7164
|
* returns, minus any character/object resource to look the result up on
|
|
7131
|
-
* (there is none; this operates on a loose image).
|
|
7132
|
-
*
|
|
7133
|
-
*
|
|
7134
|
-
*
|
|
7135
|
-
*
|
|
7136
|
-
*
|
|
7137
|
-
*
|
|
7138
|
-
*
|
|
7139
|
-
*
|
|
7165
|
+
* (there is none; this operates on a loose image). Both
|
|
7166
|
+
* `/animate-with-text-v3` and `/animate-pixminimax` have run live
|
|
7167
|
+
* (November 2026) and the completed jobs were read correctly. The checks
|
|
7168
|
+
* below stay defensive (hosted URLs under a plausible key name, the same
|
|
7169
|
+
* `storage_urls.frames` shape character animations use, or inline base64
|
|
7170
|
+
* per frame, decoded to a local cache file the same way `pollRevision`'s
|
|
7171
|
+
* single-image case is) and fail loudly, naming the keys actually
|
|
7172
|
+
* received, if a shape ever differs. PixMiniMax includes the input frame,
|
|
7173
|
+
* so a set holds the requested count plus one.
|
|
7140
7174
|
*/
|
|
7141
7175
|
async pollAnimateRevision(jobId, context) {
|
|
7142
7176
|
const job = await this.client.getBackgroundJob(jobId);
|
|
@@ -7277,7 +7311,7 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
7277
7311
|
}
|
|
7278
7312
|
return {
|
|
7279
7313
|
status: "failed",
|
|
7280
|
-
error: `Invalid PixelLab response for imagePro job ${jobId}: completed with no recognized images array (got: ${Object.keys(done).join(", ") || "no keys"});
|
|
7314
|
+
error: `Invalid PixelLab response for imagePro job ${jobId}: completed with no recognized images array (got: ${Object.keys(done).join(", ") || "no keys"}); update pollImagePro in src/providers/pixellab.ts with the real shape`
|
|
7281
7315
|
};
|
|
7282
7316
|
}
|
|
7283
7317
|
/**
|
|
@@ -8194,8 +8228,8 @@ var ScenarioClient = class {
|
|
|
8194
8228
|
async uploadImage(image, projectId) {
|
|
8195
8229
|
const bytes = Buffer.from(image.base64, "base64");
|
|
8196
8230
|
const digest2 = sha256(bytes);
|
|
8197
|
-
const
|
|
8198
|
-
if (
|
|
8231
|
+
const cached2 = readUploadCache()[uploadCacheKey(this.baseUrl, projectId, digest2)];
|
|
8232
|
+
if (cached2) return cached2;
|
|
8199
8233
|
const response = await this.call(
|
|
8200
8234
|
"/assets",
|
|
8201
8235
|
{
|
|
@@ -9885,7 +9919,7 @@ registerProvider({
|
|
|
9885
9919
|
|
|
9886
9920
|
// src/manifest.ts
|
|
9887
9921
|
import { readFile as readFile5 } from "fs/promises";
|
|
9888
|
-
import { existsSync as
|
|
9922
|
+
import { existsSync as existsSync7 } from "fs";
|
|
9889
9923
|
import path8 from "path";
|
|
9890
9924
|
|
|
9891
9925
|
// src/loop-directions.ts
|
|
@@ -10300,10 +10334,31 @@ function frameSetLoop(entry) {
|
|
|
10300
10334
|
return typeof loop === "boolean" ? loop : null;
|
|
10301
10335
|
}
|
|
10302
10336
|
|
|
10337
|
+
// src/version.ts
|
|
10338
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "fs";
|
|
10339
|
+
var cached;
|
|
10340
|
+
function pixelkilnVersion() {
|
|
10341
|
+
if (cached !== void 0) return cached;
|
|
10342
|
+
cached = null;
|
|
10343
|
+
for (const up of ["../package.json", "../../package.json"]) {
|
|
10344
|
+
const url = new URL(up, import.meta.url);
|
|
10345
|
+
if (!existsSync6(url)) continue;
|
|
10346
|
+
try {
|
|
10347
|
+
const pkg = JSON.parse(readFileSync3(url, "utf8"));
|
|
10348
|
+
if (pkg.name === "pixelkiln" && pkg.version) {
|
|
10349
|
+
cached = pkg.version;
|
|
10350
|
+
break;
|
|
10351
|
+
}
|
|
10352
|
+
} catch {
|
|
10353
|
+
}
|
|
10354
|
+
}
|
|
10355
|
+
return cached;
|
|
10356
|
+
}
|
|
10357
|
+
|
|
10303
10358
|
// src/manifest.ts
|
|
10304
10359
|
async function loadManifest(manifestPath) {
|
|
10305
10360
|
const abs = path8.resolve(manifestPath);
|
|
10306
|
-
if (!
|
|
10361
|
+
if (!existsSync7(abs)) throw new ProjectError(`No manifest at ${abs}`);
|
|
10307
10362
|
const expansion = expandLoopDirections(JSON.parse(await readFile5(abs, "utf8")));
|
|
10308
10363
|
if (expansion.issues.length) {
|
|
10309
10364
|
throw new ProjectError(`Manifest at ${abs} is invalid:
|
|
@@ -10455,19 +10510,45 @@ function dependencyAssetIds(asset, styleAnchors = []) {
|
|
|
10455
10510
|
].filter((id) => Boolean(id))
|
|
10456
10511
|
];
|
|
10457
10512
|
}
|
|
10513
|
+
var MAX_LISTED_MANIFEST_ISSUES = 20;
|
|
10514
|
+
function flattenManifestIssues(issues) {
|
|
10515
|
+
let unknownShape = false;
|
|
10516
|
+
const visit = (list) => list.flatMap((issue) => {
|
|
10517
|
+
if (issue.code === "invalid_union") return visit(issue.unionErrors.flatMap((error) => error.issues));
|
|
10518
|
+
if (issue.code === "unrecognized_keys" || issue.code === "invalid_enum_value") unknownShape = true;
|
|
10519
|
+
return [` ${issue.path.join(".") || "(manifest)"}: ${issue.message}`];
|
|
10520
|
+
});
|
|
10521
|
+
return { lines: [...new Set(visit(issues))], unknownShape };
|
|
10522
|
+
}
|
|
10458
10523
|
function formatManifestIssues(issues) {
|
|
10459
|
-
|
|
10460
|
-
|
|
10461
|
-
|
|
10462
|
-
|
|
10463
|
-
|
|
10464
|
-
|
|
10524
|
+
const { lines, unknownShape } = flattenManifestIssues(issues);
|
|
10525
|
+
const entries = [...new Set(
|
|
10526
|
+
lines.flatMap((line) => {
|
|
10527
|
+
const match = /^ {2}((?:assets|styles)\.[^.:\s]+)/.exec(line);
|
|
10528
|
+
return match ? [match[1]] : [];
|
|
10529
|
+
})
|
|
10530
|
+
)];
|
|
10531
|
+
const out = [];
|
|
10532
|
+
const version = pixelkilnVersion();
|
|
10533
|
+
if (unknownShape) {
|
|
10534
|
+
out.push(
|
|
10535
|
+
` 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.`
|
|
10536
|
+
);
|
|
10537
|
+
}
|
|
10538
|
+
if (entries.length) {
|
|
10539
|
+
out.push(` ${entries.length} invalid entr${entries.length === 1 ? "y" : "ies"}: ${entries.slice(0, 10).join(", ")}${entries.length > 10 ? ", \u2026" : ""}`);
|
|
10540
|
+
}
|
|
10541
|
+
out.push(...lines.slice(0, MAX_LISTED_MANIFEST_ISSUES));
|
|
10542
|
+
if (lines.length > MAX_LISTED_MANIFEST_ISSUES) {
|
|
10543
|
+
out.push(` \u2026 and ${lines.length - MAX_LISTED_MANIFEST_ISSUES} more`);
|
|
10544
|
+
}
|
|
10545
|
+
return out.join("\n");
|
|
10465
10546
|
}
|
|
10466
10547
|
function resolveStyleInheritance(styles) {
|
|
10467
10548
|
const resolved = /* @__PURE__ */ new Map();
|
|
10468
10549
|
const visit = (styleId, chain) => {
|
|
10469
|
-
const
|
|
10470
|
-
if (
|
|
10550
|
+
const cached2 = resolved.get(styleId);
|
|
10551
|
+
if (cached2) return cached2;
|
|
10471
10552
|
const cycleStart = chain.indexOf(styleId);
|
|
10472
10553
|
if (cycleStart >= 0) {
|
|
10473
10554
|
throw new Error(
|
|
@@ -10589,7 +10670,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
10589
10670
|
const abs = path8.resolve(root, rel);
|
|
10590
10671
|
let hit = styleImageCache.get(abs);
|
|
10591
10672
|
if (!hit) {
|
|
10592
|
-
if (!
|
|
10673
|
+
if (!existsSync7(abs)) throw new Error(`${what} not found: ${abs}`);
|
|
10593
10674
|
const buf = await readFile5(abs);
|
|
10594
10675
|
const metadata = imageMetadata(buf);
|
|
10595
10676
|
if (!metadata) throw new Error(`${what} is not a readable PNG or JPEG: ${abs}`);
|
|
@@ -10940,7 +11021,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
10940
11021
|
const file = memberPath(anchorSpec.outFile, "south", 0, anchorSpec.character.directions, MediaType.PNG);
|
|
10941
11022
|
resolved.character = {
|
|
10942
11023
|
...resolved.character,
|
|
10943
|
-
styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256:
|
|
11024
|
+
styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: existsSync7(file) ? await sha256File(file) : null }
|
|
10944
11025
|
};
|
|
10945
11026
|
}
|
|
10946
11027
|
const characterParent = asset.state?.of ?? asset.animation?.of ?? asset.portrait?.of;
|
|
@@ -10953,7 +11034,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
10953
11034
|
parentAssetId: characterParent,
|
|
10954
11035
|
parentSpec,
|
|
10955
11036
|
parentFile,
|
|
10956
|
-
parentSha256:
|
|
11037
|
+
parentSha256: existsSync7(parentFile) ? await sha256File(parentFile) : null,
|
|
10957
11038
|
// A state and its animations keep the engine and rotations of the base.
|
|
10958
11039
|
mode: resolved.character.kind === "base" ? resolved.character.mode : parentSpec.character?.mode ?? resolved.character.mode,
|
|
10959
11040
|
directions: resolved.character.kind === "base" ? resolved.character.directions : parentSpec.character?.directions ?? resolved.character.directions
|
|
@@ -10991,7 +11072,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
10991
11072
|
parentAssetId: characterParent,
|
|
10992
11073
|
parentSpec,
|
|
10993
11074
|
parentFile,
|
|
10994
|
-
parentSha256:
|
|
11075
|
+
parentSha256: existsSync7(parentFile) ? await sha256File(parentFile) : null,
|
|
10995
11076
|
// A state and its animations keep the base's own rotation count.
|
|
10996
11077
|
directions: resolved.objectPro.kind === "base" ? resolved.objectPro.directions : parentSpec.objectPro.directions
|
|
10997
11078
|
};
|
|
@@ -11195,8 +11276,18 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11195
11276
|
providerOptionIdentity,
|
|
11196
11277
|
providerInputIdentities.get(assetId)
|
|
11197
11278
|
);
|
|
11198
|
-
|
|
11199
|
-
|
|
11279
|
+
let estimate;
|
|
11280
|
+
try {
|
|
11281
|
+
activeProvider.validate?.(resolved, resolvedImages);
|
|
11282
|
+
estimate = validateCostEstimate(activeProvider.id, activeProvider.estimate(resolved));
|
|
11283
|
+
} catch (error) {
|
|
11284
|
+
const message6 = error instanceof Error ? error.message : String(error);
|
|
11285
|
+
if (message6.includes(`assets.${assetId}`)) throw error;
|
|
11286
|
+
throw new Error(
|
|
11287
|
+
`assets.${assetId} (style "${styleId}", ${resolved.width}x${resolved.height}): ${message6}`,
|
|
11288
|
+
{ cause: error }
|
|
11289
|
+
);
|
|
11290
|
+
}
|
|
11200
11291
|
resolved.cost = estimate.amount;
|
|
11201
11292
|
resolved.costUnit = estimate.unit;
|
|
11202
11293
|
resolved.candidates = estimate.candidates;
|
|
@@ -11280,7 +11371,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
11280
11371
|
let recordedSprite;
|
|
11281
11372
|
if (vfx.recipe) {
|
|
11282
11373
|
const file = path8.resolve(root, vfx.recipe);
|
|
11283
|
-
if (!
|
|
11374
|
+
if (!existsSync7(file)) throw new Error(`assets.${assetId}.vfx.recipe: VFX recipe not found: ${file}`);
|
|
11284
11375
|
const read = await readVfxRecipe(file).catch((error) => {
|
|
11285
11376
|
throw new Error(`assets.${assetId}.vfx.recipe: ${error instanceof Error ? error.message : String(error)}`);
|
|
11286
11377
|
});
|
|
@@ -11307,7 +11398,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
11307
11398
|
};
|
|
11308
11399
|
}
|
|
11309
11400
|
async function optionalRevisionImage(file, label, requiredFormat) {
|
|
11310
|
-
if (!
|
|
11401
|
+
if (!existsSync7(file)) return null;
|
|
11311
11402
|
const bytes = await readFile5(file);
|
|
11312
11403
|
const metadata = imageMetadata(bytes);
|
|
11313
11404
|
if (!metadata) throw new Error(`${label} is not a readable PNG or JPEG: ${file}`);
|
|
@@ -11317,7 +11408,7 @@ async function optionalRevisionImage(file, label, requiredFormat) {
|
|
|
11317
11408
|
return { hash: sha256(bytes), ...metadata };
|
|
11318
11409
|
}
|
|
11319
11410
|
async function optionalSkeletonSet(file) {
|
|
11320
|
-
if (!
|
|
11411
|
+
if (!existsSync7(file)) return null;
|
|
11321
11412
|
const bytes = await readFile5(file);
|
|
11322
11413
|
let json;
|
|
11323
11414
|
try {
|
|
@@ -11328,17 +11419,17 @@ async function optionalSkeletonSet(file) {
|
|
|
11328
11419
|
return { hash: sha256(bytes), skeleton: parseSkeletonSet(json, file) };
|
|
11329
11420
|
}
|
|
11330
11421
|
async function revisionSourceMembers(stem, label) {
|
|
11331
|
-
if (
|
|
11422
|
+
if (existsSync7(stem)) return null;
|
|
11332
11423
|
const at = (role) => memberPath(stem, role, 0, 2, MediaType.PNG);
|
|
11333
11424
|
let roles = [];
|
|
11334
11425
|
for (const set of [CHARACTER_DIRECTIONS_8, CHARACTER_DIRECTIONS_4]) {
|
|
11335
|
-
if (set.every((direction) =>
|
|
11426
|
+
if (set.every((direction) => existsSync7(at(direction)))) {
|
|
11336
11427
|
roles = [...set];
|
|
11337
11428
|
break;
|
|
11338
11429
|
}
|
|
11339
11430
|
}
|
|
11340
11431
|
if (!roles.length) {
|
|
11341
|
-
for (let index = 0;
|
|
11432
|
+
for (let index = 0; existsSync7(at(`frame-${String(index).padStart(2, "0")}`)); index++) {
|
|
11342
11433
|
roles.push(`frame-${String(index).padStart(2, "0")}`);
|
|
11343
11434
|
}
|
|
11344
11435
|
}
|
|
@@ -11506,7 +11597,7 @@ function characterDirections(directions) {
|
|
|
11506
11597
|
import path16 from "path";
|
|
11507
11598
|
|
|
11508
11599
|
// src/env.ts
|
|
11509
|
-
import { readFileSync as
|
|
11600
|
+
import { readFileSync as readFileSync4, existsSync as existsSync8 } from "fs";
|
|
11510
11601
|
import path9 from "path";
|
|
11511
11602
|
function loadEnvFiles(dir) {
|
|
11512
11603
|
const loaded = [];
|
|
@@ -11522,9 +11613,9 @@ function envFiles(dir) {
|
|
|
11522
11613
|
const out = [];
|
|
11523
11614
|
for (const name of [".env.local", ".env"]) {
|
|
11524
11615
|
const file = path9.join(dir, name);
|
|
11525
|
-
if (!
|
|
11616
|
+
if (!existsSync8(file)) continue;
|
|
11526
11617
|
try {
|
|
11527
|
-
out.push([file, parseEnv(
|
|
11618
|
+
out.push([file, parseEnv(readFileSync4(file, "utf8"))]);
|
|
11528
11619
|
} catch {
|
|
11529
11620
|
}
|
|
11530
11621
|
}
|
|
@@ -11550,7 +11641,7 @@ function parseEnv(contents) {
|
|
|
11550
11641
|
}
|
|
11551
11642
|
|
|
11552
11643
|
// src/pipeline/plan.ts
|
|
11553
|
-
import { existsSync as
|
|
11644
|
+
import { existsSync as existsSync11 } from "fs";
|
|
11554
11645
|
import path15 from "path";
|
|
11555
11646
|
|
|
11556
11647
|
// src/pipeline/mirror.ts
|
|
@@ -11756,7 +11847,7 @@ async function deriveMirror(spec, lock, lockPath, opts = {}) {
|
|
|
11756
11847
|
}
|
|
11757
11848
|
|
|
11758
11849
|
// src/pipeline/quality-profile.ts
|
|
11759
|
-
import { existsSync as
|
|
11850
|
+
import { existsSync as existsSync9 } from "fs";
|
|
11760
11851
|
import path13 from "path";
|
|
11761
11852
|
|
|
11762
11853
|
// src/pipeline/refine.ts
|
|
@@ -12739,7 +12830,7 @@ async function qualitySource(spec, lock) {
|
|
|
12739
12830
|
return { items: null, reason: "frame-set quality requires ordered downloaded provider outputs" };
|
|
12740
12831
|
}
|
|
12741
12832
|
const source = path13.resolve(spec.root, spec.source);
|
|
12742
|
-
return
|
|
12833
|
+
return existsSync9(source) ? { items: [{ role: "source", path: source }] } : { items: null, reason: `declared source is missing: ${spec.source}` };
|
|
12743
12834
|
}
|
|
12744
12835
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
12745
12836
|
if (!entry) return { items: null, reason: "raw provider output is not in the lockfile" };
|
|
@@ -12768,7 +12859,7 @@ async function qualitySource(spec, lock) {
|
|
|
12768
12859
|
}
|
|
12769
12860
|
if (role) roles.add(role);
|
|
12770
12861
|
const source = currentEntryOutputPath(entry, spec, index);
|
|
12771
|
-
if (!
|
|
12862
|
+
if (!existsSync9(source)) return { items: null, reason: `raw provider output is missing: ${source}` };
|
|
12772
12863
|
if (await sha256File(source) !== output.sha256) {
|
|
12773
12864
|
return { items: null, reason: "raw provider output was modified after download" };
|
|
12774
12865
|
}
|
|
@@ -12787,7 +12878,7 @@ async function inspectQualityProfile(spec, lock) {
|
|
|
12787
12878
|
}
|
|
12788
12879
|
const sourcePaths = source.items.map((item) => item.path);
|
|
12789
12880
|
const expectedOutputs = spec.generator === "frames" ? source.items.map((item, index) => qualityFrameOutputPath(output, item.role, index)) : [output];
|
|
12790
|
-
if (!
|
|
12881
|
+
if (!existsSync9(record)) {
|
|
12791
12882
|
return {
|
|
12792
12883
|
key,
|
|
12793
12884
|
state: "needs-refinement",
|
|
@@ -12968,7 +13059,7 @@ async function requireApprovedQualitySources(specs, lock, assetIds, outputRoles)
|
|
|
12968
13059
|
}
|
|
12969
13060
|
|
|
12970
13061
|
// src/pipeline/revision.ts
|
|
12971
|
-
import { existsSync as
|
|
13062
|
+
import { existsSync as existsSync10 } from "fs";
|
|
12972
13063
|
import path14 from "path";
|
|
12973
13064
|
async function inspectRevisionReadiness(spec, lock) {
|
|
12974
13065
|
if (spec.mirror) return inspectMirror(spec, lock, /* @__PURE__ */ new Set());
|
|
@@ -12990,7 +13081,7 @@ async function inspectStyleAnchor(spec, lock, seen) {
|
|
|
12990
13081
|
const label = `style anchor ${spec.styleId}/${anchor.assetId}`;
|
|
12991
13082
|
const dependency = await inspectParent(anchor.spec, lock, seen);
|
|
12992
13083
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
12993
|
-
if (!anchor.sha256 || !
|
|
13084
|
+
if (!anchor.sha256 || !existsSync10(anchor.file)) return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
12994
13085
|
if (await sha256File(anchor.file) !== anchor.sha256) {
|
|
12995
13086
|
return { ready: false, reason: `${label} changed after the manifest was resolved` };
|
|
12996
13087
|
}
|
|
@@ -13027,14 +13118,14 @@ async function inspectScene(spec) {
|
|
|
13027
13118
|
const files = [{ label: "scene image", file: scene.file, sha256: scene.sha256 }];
|
|
13028
13119
|
if (scene.placement.type === "mask") files.push({ label: "scene mask", file: scene.placement.file, sha256: scene.placement.sha256 });
|
|
13029
13120
|
for (const { label, file, sha256: sha2562 } of files) {
|
|
13030
|
-
if (!sha2562 || !
|
|
13121
|
+
if (!sha2562 || !existsSync10(file)) return { ready: false, reason: `${label} does not exist yet: ${file}` };
|
|
13031
13122
|
if (await sha256File(file) !== sha2562) return { ready: false, reason: `${label} changed after the manifest was resolved` };
|
|
13032
13123
|
}
|
|
13033
13124
|
return { ready: true, reason: "scene is current" };
|
|
13034
13125
|
}
|
|
13035
13126
|
async function inspectVfxSprite(spec) {
|
|
13036
13127
|
const sprite = spec.vfx.sprite;
|
|
13037
|
-
if (!sprite.sha256 || !
|
|
13128
|
+
if (!sprite.sha256 || !existsSync10(sprite.file)) return { ready: false, reason: `vfx sprite does not exist yet: ${sprite.file}` };
|
|
13038
13129
|
if (await sha256File(sprite.file) !== sprite.sha256) return { ready: false, reason: "vfx sprite changed after the manifest was resolved" };
|
|
13039
13130
|
return { ready: true, reason: "vfx sprite is current" };
|
|
13040
13131
|
}
|
|
@@ -13050,7 +13141,7 @@ async function inspectOutfit(spec, lock, seen) {
|
|
|
13050
13141
|
const label = `outfit source ${spec.styleId}/${character.parentAssetId}`;
|
|
13051
13142
|
const dependency = await inspectParent(character.parentSpec, lock, seen);
|
|
13052
13143
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13053
|
-
if (!
|
|
13144
|
+
if (!existsSync10(outfit.reference.path)) {
|
|
13054
13145
|
return { ready: false, reason: `outfit reference is missing: ${outfit.reference.path}` };
|
|
13055
13146
|
}
|
|
13056
13147
|
if (await sha256File(outfit.reference.path) !== outfit.reference.sha256) {
|
|
@@ -13064,7 +13155,7 @@ async function inspectCharacterParent(spec, lock, seen) {
|
|
|
13064
13155
|
const label = `${character.kind} parent ${spec.styleId}/${character.parentAssetId}`;
|
|
13065
13156
|
const dependency = await inspectParent(parentSpec, lock, seen);
|
|
13066
13157
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13067
|
-
if (!character.parentSha256 || !character.parentFile || !
|
|
13158
|
+
if (!character.parentSha256 || !character.parentFile || !existsSync10(character.parentFile)) {
|
|
13068
13159
|
return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13069
13160
|
}
|
|
13070
13161
|
if (await sha256File(character.parentFile) !== character.parentSha256) {
|
|
@@ -13082,7 +13173,7 @@ async function inspectObjectProParent(spec, lock, seen) {
|
|
|
13082
13173
|
const label = `${object.kind} parent ${spec.styleId}/${object.parentAssetId}`;
|
|
13083
13174
|
const dependency = await inspectParent(parentSpec, lock, seen);
|
|
13084
13175
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13085
|
-
if (!object.parentSha256 || !object.parentFile || !
|
|
13176
|
+
if (!object.parentSha256 || !object.parentFile || !existsSync10(object.parentFile)) {
|
|
13086
13177
|
return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13087
13178
|
}
|
|
13088
13179
|
if (await sha256File(object.parentFile) !== object.parentSha256) {
|
|
@@ -13108,7 +13199,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13108
13199
|
const members = await inspectSourceMembers(spec, lock);
|
|
13109
13200
|
if (!members.ready) return members;
|
|
13110
13201
|
} else {
|
|
13111
|
-
if (!revision.sourceSha256 || !
|
|
13202
|
+
if (!revision.sourceSha256 || !existsSync10(revision.sourceFile)) {
|
|
13112
13203
|
return { ready: false, reason: `revision source is missing: ${revision.sourceFile}` };
|
|
13113
13204
|
}
|
|
13114
13205
|
if (await sha256File(revision.sourceFile) !== revision.sourceSha256) {
|
|
@@ -13116,7 +13207,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13116
13207
|
}
|
|
13117
13208
|
}
|
|
13118
13209
|
if (revision.maskFile) {
|
|
13119
|
-
if (!revision.maskSha256 || !
|
|
13210
|
+
if (!revision.maskSha256 || !existsSync10(revision.maskFile)) {
|
|
13120
13211
|
return { ready: false, reason: `revision mask is missing: ${revision.maskFile}` };
|
|
13121
13212
|
}
|
|
13122
13213
|
if (await sha256File(revision.maskFile) !== revision.maskSha256) {
|
|
@@ -13124,7 +13215,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13124
13215
|
}
|
|
13125
13216
|
}
|
|
13126
13217
|
if (revision.lastFrameFile) {
|
|
13127
|
-
if (!revision.lastFrameSha256 || !
|
|
13218
|
+
if (!revision.lastFrameSha256 || !existsSync10(revision.lastFrameFile)) {
|
|
13128
13219
|
return { ready: false, reason: `revision last frame is missing: ${revision.lastFrameFile}` };
|
|
13129
13220
|
}
|
|
13130
13221
|
if (await sha256File(revision.lastFrameFile) !== revision.lastFrameSha256) {
|
|
@@ -13137,7 +13228,7 @@ async function inspectSourceMembers(spec, lock) {
|
|
|
13137
13228
|
const revision = spec.revision;
|
|
13138
13229
|
const members = revision.sourceMembers;
|
|
13139
13230
|
for (const member of members) {
|
|
13140
|
-
if (!
|
|
13231
|
+
if (!existsSync10(member.file)) return { ready: false, reason: `revision source member is missing: ${member.file}` };
|
|
13141
13232
|
if (await sha256File(member.file) !== member.sha256) {
|
|
13142
13233
|
return { ready: false, reason: `revision source member changed after the manifest was resolved: ${member.file}` };
|
|
13143
13234
|
}
|
|
@@ -13205,7 +13296,7 @@ async function inspectParent(spec, lock, seen) {
|
|
|
13205
13296
|
}
|
|
13206
13297
|
if (spec.source) {
|
|
13207
13298
|
const source = path14.resolve(spec.root, spec.source);
|
|
13208
|
-
return
|
|
13299
|
+
return existsSync10(source) ? { ready: true, reason: "declared source is present" } : { ready: false, reason: `declared source is missing: ${spec.source}` };
|
|
13209
13300
|
}
|
|
13210
13301
|
const entry = lock.entries[key];
|
|
13211
13302
|
if (!entry) return { ready: false, reason: "parent is not in the lockfile" };
|
|
@@ -13219,7 +13310,7 @@ async function inspectParent(spec, lock, seen) {
|
|
|
13219
13310
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
13220
13311
|
const output = entry.outputs[index];
|
|
13221
13312
|
const file = currentEntryOutputPath(entry, spec, index);
|
|
13222
|
-
if (!
|
|
13313
|
+
if (!existsSync10(file)) return { ready: false, reason: `parent output is missing: ${file}` };
|
|
13223
13314
|
if (await sha256File(file) !== output.sha256) {
|
|
13224
13315
|
return { ready: false, reason: `parent output was modified: ${file}` };
|
|
13225
13316
|
}
|
|
@@ -13314,7 +13405,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13314
13405
|
state = "missing";
|
|
13315
13406
|
reason = "--force";
|
|
13316
13407
|
} else if (!entry && spec.source && spec.generator !== "frames" && spec.generator !== "vfx") {
|
|
13317
|
-
if (
|
|
13408
|
+
if (existsSync11(path15.resolve(spec.root, spec.source))) {
|
|
13318
13409
|
state = "ok";
|
|
13319
13410
|
reason = `placed from ${spec.source}; not generated`;
|
|
13320
13411
|
} else {
|
|
@@ -13322,7 +13413,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13322
13413
|
reason = `declared source is missing: ${spec.source}`;
|
|
13323
13414
|
}
|
|
13324
13415
|
} else if (!entry) {
|
|
13325
|
-
if (
|
|
13416
|
+
if (existsSync11(spec.outFile)) {
|
|
13326
13417
|
state = "untracked";
|
|
13327
13418
|
reason = "file on disk, no provenance recorded";
|
|
13328
13419
|
} else {
|
|
@@ -13335,7 +13426,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13335
13426
|
} else if (spec.mirror && !mirrorCurrent(entry, lock.entries[lockKey(spec.styleId, spec.mirror.sourceAssetId)])) {
|
|
13336
13427
|
state = "stale";
|
|
13337
13428
|
reason = `mirror source ${spec.mirror.sourceAssetId} changed; flip it again (no generation cost)`;
|
|
13338
|
-
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !
|
|
13429
|
+
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !existsSync11(currentEntryOutputPath(entry, spec, index)))) {
|
|
13339
13430
|
state = "stale";
|
|
13340
13431
|
reason = "mirror output missing on disk; flip it again (no generation cost)";
|
|
13341
13432
|
} else if (spec.character?.kind === "outfit" && entry.outfit?.sourceSha256 !== mirrorSourceHash(lock.entries[lockKey(spec.styleId, spec.character.parentAssetId)] ?? { outputs: [] })) {
|
|
@@ -13372,9 +13463,9 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13372
13463
|
} else if (entry.status !== "downloaded") {
|
|
13373
13464
|
state = "in-flight";
|
|
13374
13465
|
reason = `awaiting ${entry.status}`;
|
|
13375
|
-
} else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !
|
|
13466
|
+
} else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !existsSync11(currentEntryOutputPath(entry, spec, index)))) {
|
|
13376
13467
|
state = "orphaned";
|
|
13377
|
-
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !
|
|
13468
|
+
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !existsSync11(currentEntryOutputPath(entry, spec, index))).map((o) => o.role ?? "asset").join(", ")}`;
|
|
13378
13469
|
} else if (await anyOutputModified(entry, spec)) {
|
|
13379
13470
|
state = "orphaned";
|
|
13380
13471
|
reason = "output modified since download";
|
|
@@ -13510,7 +13601,7 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
|
|
|
13510
13601
|
|
|
13511
13602
|
// src/recipes.ts
|
|
13512
13603
|
import path17 from "path";
|
|
13513
|
-
import { existsSync as
|
|
13604
|
+
import { existsSync as existsSync12 } from "fs";
|
|
13514
13605
|
import { readdir, readFile as readFile9 } from "fs/promises";
|
|
13515
13606
|
import { fileURLToPath } from "url";
|
|
13516
13607
|
import { z as z4 } from "zod";
|
|
@@ -13713,7 +13804,7 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
13713
13804
|
return { recipe: parsed.data, authored: raw, path: absolute, dir: path17.dirname(absolute), bundled };
|
|
13714
13805
|
}
|
|
13715
13806
|
async function walkRecipeFiles(root) {
|
|
13716
|
-
if (!
|
|
13807
|
+
if (!existsSync12(root)) return [];
|
|
13717
13808
|
const out = [];
|
|
13718
13809
|
for (const entry of await readdir(root, { withFileTypes: true })) {
|
|
13719
13810
|
const resolved = path17.join(root, entry.name);
|
|
@@ -13751,7 +13842,7 @@ function parseSelector(selector) {
|
|
|
13751
13842
|
}
|
|
13752
13843
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
13753
13844
|
const local = path17.resolve(target);
|
|
13754
|
-
if (
|
|
13845
|
+
if (existsSync12(local)) {
|
|
13755
13846
|
const recipePath = path17.basename(local) === RECIPE_FILE ? local : path17.join(local, RECIPE_FILE);
|
|
13756
13847
|
return readRecipeFile(recipePath, false);
|
|
13757
13848
|
}
|
|
@@ -13767,7 +13858,7 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
13767
13858
|
}
|
|
13768
13859
|
async function verifyFile(root, file) {
|
|
13769
13860
|
const absolute = path17.resolve(root, ...file.path.split("/"));
|
|
13770
|
-
if (!
|
|
13861
|
+
if (!existsSync12(absolute)) {
|
|
13771
13862
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
13772
13863
|
}
|
|
13773
13864
|
const actualSha256 = await sha256File(absolute);
|
|
@@ -13845,7 +13936,7 @@ async function installRecipe(target, options = {}) {
|
|
|
13845
13936
|
})));
|
|
13846
13937
|
if (!options.force) {
|
|
13847
13938
|
for (const file of files) {
|
|
13848
|
-
if (!
|
|
13939
|
+
if (!existsSync12(file.path)) continue;
|
|
13849
13940
|
const current = await readFile9(file.path);
|
|
13850
13941
|
if (!current.equals(file.data)) {
|
|
13851
13942
|
throw new OverwriteRefusedError(
|
|
@@ -13871,7 +13962,7 @@ async function installRecipe(target, options = {}) {
|
|
|
13871
13962
|
|
|
13872
13963
|
// src/pipeline/audit.ts
|
|
13873
13964
|
import { readFile as readFile10 } from "fs/promises";
|
|
13874
|
-
import { existsSync as
|
|
13965
|
+
import { existsSync as existsSync13 } from "fs";
|
|
13875
13966
|
import path18 from "path";
|
|
13876
13967
|
function paletteDistance(asset, reference) {
|
|
13877
13968
|
if (!asset.length || !reference.length) return 0;
|
|
@@ -13908,7 +13999,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
13908
13999
|
const unreadable = [];
|
|
13909
14000
|
for (const spec of mine) {
|
|
13910
14001
|
for (const output of resolveSpecOutputs(spec, lock, loaded.root)) {
|
|
13911
|
-
if (!
|
|
14002
|
+
if (!existsSync13(output.absolutePath)) {
|
|
13912
14003
|
missing.push(output.id);
|
|
13913
14004
|
continue;
|
|
13914
14005
|
}
|
|
@@ -13938,7 +14029,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
13938
14029
|
const refPalettes = [];
|
|
13939
14030
|
for (const img of style.styleImages) {
|
|
13940
14031
|
const abs = path18.resolve(loaded.root, img.path);
|
|
13941
|
-
if (!
|
|
14032
|
+
if (!existsSync13(abs)) continue;
|
|
13942
14033
|
try {
|
|
13943
14034
|
refPalettes.push(extractPalette(decodePng(await readFile10(abs)), 12));
|
|
13944
14035
|
} catch {
|
|
@@ -14017,7 +14108,7 @@ function hex(c) {
|
|
|
14017
14108
|
|
|
14018
14109
|
// src/pipeline/quality-regression.ts
|
|
14019
14110
|
import path19 from "path";
|
|
14020
|
-
import { existsSync as
|
|
14111
|
+
import { existsSync as existsSync14 } from "fs";
|
|
14021
14112
|
import { readFile as readFile11 } from "fs/promises";
|
|
14022
14113
|
import { z as z5 } from "zod";
|
|
14023
14114
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
@@ -14260,7 +14351,7 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14260
14351
|
cases
|
|
14261
14352
|
});
|
|
14262
14353
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
14263
|
-
if (
|
|
14354
|
+
if (existsSync14(absolute) && !options.force) {
|
|
14264
14355
|
const current = await readFile11(absolute);
|
|
14265
14356
|
if (!current.equals(data)) {
|
|
14266
14357
|
throw new OverwriteRefusedError(
|
|
@@ -14272,6 +14363,63 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14272
14363
|
const result = await writeArtifactBundle([{ path: absolute, data }]);
|
|
14273
14364
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
14274
14365
|
}
|
|
14366
|
+
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
14367
|
+
const absolute = path19.resolve(baselinePath);
|
|
14368
|
+
if (!existsSync14(absolute)) {
|
|
14369
|
+
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
14370
|
+
}
|
|
14371
|
+
let raw;
|
|
14372
|
+
try {
|
|
14373
|
+
raw = JSON.parse(await readFile11(absolute, "utf8"));
|
|
14374
|
+
} catch (error) {
|
|
14375
|
+
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
14376
|
+
}
|
|
14377
|
+
if (!Array.isArray(raw.cases)) throw new Error(`Quality baseline ${absolute} has no cases array.`);
|
|
14378
|
+
const byId = new Map(inputs.map((input) => [input.id, input]));
|
|
14379
|
+
const unknown = only.filter((id) => !byId.has(id));
|
|
14380
|
+
if (unknown.length) {
|
|
14381
|
+
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
14382
|
+
}
|
|
14383
|
+
const root = path19.dirname(absolute);
|
|
14384
|
+
const cases = [...raw.cases];
|
|
14385
|
+
const report = [];
|
|
14386
|
+
for (const id of only) {
|
|
14387
|
+
const input = byId.get(id);
|
|
14388
|
+
if (path19.resolve(input.file) === absolute || input.record && path19.resolve(input.record) === absolute) {
|
|
14389
|
+
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
14390
|
+
}
|
|
14391
|
+
const expected = await measureImageQuality(input.file);
|
|
14392
|
+
let record;
|
|
14393
|
+
if (input.record) {
|
|
14394
|
+
await verifyRecordForImage(input.record, input.file);
|
|
14395
|
+
record = { path: portableRelative2(root, input.record), sha256: await sha256File(input.record) };
|
|
14396
|
+
}
|
|
14397
|
+
const index = cases.findIndex((entry) => entry.id === id);
|
|
14398
|
+
const before = index >= 0 ? cases[index].expected ?? {} : {};
|
|
14399
|
+
const next = {
|
|
14400
|
+
id,
|
|
14401
|
+
file: portableRelative2(root, input.file),
|
|
14402
|
+
...record ? { record } : {},
|
|
14403
|
+
expected,
|
|
14404
|
+
tolerances: index >= 0 && cases[index].tolerances ? cases[index].tolerances : input.tolerances
|
|
14405
|
+
};
|
|
14406
|
+
if (index >= 0) cases[index] = next;
|
|
14407
|
+
else cases.push(next);
|
|
14408
|
+
const changes = [];
|
|
14409
|
+
for (const metric of Object.keys(expected)) {
|
|
14410
|
+
if (JSON.stringify(before[metric]) !== JSON.stringify(expected[metric])) {
|
|
14411
|
+
changes.push({ metric, before: before[metric] ?? null, after: expected[metric] });
|
|
14412
|
+
}
|
|
14413
|
+
}
|
|
14414
|
+
report.push({ id, kind: index < 0 ? "added" : changes.length ? "updated" : "unchanged", changes });
|
|
14415
|
+
}
|
|
14416
|
+
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
14417
|
+
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
14418
|
+
const current = await readFile11(absolute);
|
|
14419
|
+
const changed = !current.equals(data);
|
|
14420
|
+
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
14421
|
+
return { baseline, path: absolute, changed, cases: report };
|
|
14422
|
+
}
|
|
14275
14423
|
async function readQualityBaseline(baselinePath) {
|
|
14276
14424
|
const absolute = path19.resolve(baselinePath);
|
|
14277
14425
|
let raw;
|
|
@@ -14282,9 +14430,23 @@ async function readQualityBaseline(baselinePath) {
|
|
|
14282
14430
|
}
|
|
14283
14431
|
const parsed = QualityBaselineSchema.safeParse(raw);
|
|
14284
14432
|
if (!parsed.success) {
|
|
14433
|
+
const cases = raw?.cases;
|
|
14434
|
+
const where = (issuePath) => {
|
|
14435
|
+
if (issuePath[0] === "cases" && typeof issuePath[1] === "number") {
|
|
14436
|
+
const id = cases?.[issuePath[1]]?.id;
|
|
14437
|
+
const rest = issuePath.slice(2).join(".");
|
|
14438
|
+
return typeof id === "string" ? `cases[${id}]${rest ? `.${rest}` : ""}` : issuePath.join(".");
|
|
14439
|
+
}
|
|
14440
|
+
return issuePath.join(".") || "$";
|
|
14441
|
+
};
|
|
14442
|
+
const missing = [...new Set(parsed.error.issues.flatMap((issue) => {
|
|
14443
|
+
const id = issue.path[0] === "cases" && typeof issue.path[1] === "number" ? cases?.[issue.path[1]]?.id : void 0;
|
|
14444
|
+
return issue.code === "invalid_type" && issue.received === "undefined" && typeof id === "string" ? [id] : [];
|
|
14445
|
+
}))];
|
|
14285
14446
|
throw new Error(
|
|
14286
14447
|
`Invalid quality baseline ${absolute}:
|
|
14287
|
-
` + parsed.error.issues.map((issue) => ` ${issue.path
|
|
14448
|
+
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
14449
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path19.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
14288
14450
|
);
|
|
14289
14451
|
}
|
|
14290
14452
|
return parsed.data;
|
|
@@ -14400,13 +14562,13 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
14400
14562
|
}
|
|
14401
14563
|
|
|
14402
14564
|
// src/pipeline/cache-health.ts
|
|
14403
|
-
import { existsSync as
|
|
14565
|
+
import { existsSync as existsSync18 } from "fs";
|
|
14404
14566
|
import { readFile as readFile14, readdir as readdir2, rm as rm6 } from "fs/promises";
|
|
14405
14567
|
import path22 from "path";
|
|
14406
14568
|
|
|
14407
14569
|
// src/cache.ts
|
|
14408
14570
|
import { mkdir as mkdir6, readFile as readFile12, rename as rename4, rm as rm4, writeFile as writeFile6 } from "fs/promises";
|
|
14409
|
-
import { existsSync as
|
|
14571
|
+
import { existsSync as existsSync15 } from "fs";
|
|
14410
14572
|
import pathModule from "path";
|
|
14411
14573
|
import { z as z6 } from "zod";
|
|
14412
14574
|
var HashCacheSchema = z6.object({
|
|
@@ -14422,7 +14584,7 @@ function parseCache(value) {
|
|
|
14422
14584
|
return HashCacheSchema.parse(value);
|
|
14423
14585
|
}
|
|
14424
14586
|
async function loadCache(path39) {
|
|
14425
|
-
if (!
|
|
14587
|
+
if (!existsSync15(path39)) return { version: 1, hashes: {} };
|
|
14426
14588
|
try {
|
|
14427
14589
|
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile12(path39, "utf8")));
|
|
14428
14590
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
@@ -14471,11 +14633,11 @@ function cachePathFor(lockPath) {
|
|
|
14471
14633
|
}
|
|
14472
14634
|
|
|
14473
14635
|
// src/pipeline/history.ts
|
|
14474
|
-
import { existsSync as
|
|
14636
|
+
import { existsSync as existsSync17 } from "fs";
|
|
14475
14637
|
import path21 from "path";
|
|
14476
14638
|
|
|
14477
14639
|
// src/pipeline/fetch.ts
|
|
14478
|
-
import { existsSync as
|
|
14640
|
+
import { existsSync as existsSync16, readFileSync as readFileSync5 } from "fs";
|
|
14479
14641
|
import { mkdir as mkdir7, readFile as readFile13, rename as rename5, rm as rm5, writeFile as writeFile7 } from "fs/promises";
|
|
14480
14642
|
import path20 from "path";
|
|
14481
14643
|
async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
@@ -14495,15 +14657,15 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14495
14657
|
if (spec && e.specHash === spec.specHash && e.outputs.length && !postprocessCurrent(e, spec)) {
|
|
14496
14658
|
return Boolean(opts.force) || e.outputs.every((output) => {
|
|
14497
14659
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14498
|
-
return
|
|
14660
|
+
return existsSync16(file) && sha256(readFileSync5(file)) === output.sha256;
|
|
14499
14661
|
});
|
|
14500
14662
|
}
|
|
14501
14663
|
if (!opts.repair) return false;
|
|
14502
14664
|
if (e.outputs.length === 0 || !spec) return true;
|
|
14503
14665
|
return e.outputs.some((output) => {
|
|
14504
14666
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14505
|
-
if (!
|
|
14506
|
-
const current = sha256(
|
|
14667
|
+
if (!existsSync16(file)) return true;
|
|
14668
|
+
const current = sha256(readFileSync5(file));
|
|
14507
14669
|
if (current === output.sha256) return false;
|
|
14508
14670
|
return Boolean(opts.force) || (e.supersededOutputs ?? []).some((old) => old.sha256 === current);
|
|
14509
14671
|
});
|
|
@@ -14593,7 +14755,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14593
14755
|
}
|
|
14594
14756
|
let raw = null;
|
|
14595
14757
|
let final = null;
|
|
14596
|
-
if (
|
|
14758
|
+
if (existsSync16(target)) {
|
|
14597
14759
|
const currentHash = await sha256File(target);
|
|
14598
14760
|
if (recorded && currentHash === recorded.sha256) {
|
|
14599
14761
|
if (!fresh && !reapply) {
|
|
@@ -14739,7 +14901,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14739
14901
|
}
|
|
14740
14902
|
async function readCachedMedia(cacheDir, hash, mediaType) {
|
|
14741
14903
|
const file = path20.join(cacheDir, cacheFileName(hash, mediaType));
|
|
14742
|
-
if (!
|
|
14904
|
+
if (!existsSync16(file)) return null;
|
|
14743
14905
|
try {
|
|
14744
14906
|
const buf = await readFile13(file);
|
|
14745
14907
|
if (sha256(buf) !== hash) return null;
|
|
@@ -14760,7 +14922,7 @@ async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
|
|
|
14760
14922
|
try {
|
|
14761
14923
|
await rename5(tmp, file);
|
|
14762
14924
|
} catch (err) {
|
|
14763
|
-
if (!
|
|
14925
|
+
if (!existsSync16(file)) throw err;
|
|
14764
14926
|
} finally {
|
|
14765
14927
|
await rm5(tmp, { force: true });
|
|
14766
14928
|
}
|
|
@@ -14882,7 +15044,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
14882
15044
|
}
|
|
14883
15045
|
for (let i = 0; i < entry.outputs.length; i++) {
|
|
14884
15046
|
const file = currentEntryOutputPath(entry, spec, i);
|
|
14885
|
-
if (!
|
|
15047
|
+
if (!existsSync17(file)) continue;
|
|
14886
15048
|
if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
|
|
14887
15049
|
throw new OverwriteRefusedError(
|
|
14888
15050
|
`${path21.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
|
|
@@ -14945,7 +15107,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
14945
15107
|
|
|
14946
15108
|
// src/pipeline/cache-health.ts
|
|
14947
15109
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
14948
|
-
if (options.prune && !
|
|
15110
|
+
if (options.prune && !existsSync18(lockPath)) {
|
|
14949
15111
|
throw new Error(`Refusing to prune without an existing lockfile at ${path22.resolve(lockPath)}`);
|
|
14950
15112
|
}
|
|
14951
15113
|
const contentDir = path22.resolve(path22.dirname(lockPath), ".pixelkiln", "cache");
|
|
@@ -14988,7 +15150,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
14988
15150
|
async function inspectContentCache(contentDir, referenced) {
|
|
14989
15151
|
const report = {
|
|
14990
15152
|
path: contentDir,
|
|
14991
|
-
exists:
|
|
15153
|
+
exists: existsSync18(contentDir),
|
|
14992
15154
|
files: 0,
|
|
14993
15155
|
bytes: 0,
|
|
14994
15156
|
valid: 0,
|
|
@@ -15052,7 +15214,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
15052
15214
|
async function inspectRemoteHashCache(remotePath) {
|
|
15053
15215
|
const report = {
|
|
15054
15216
|
path: remotePath,
|
|
15055
|
-
exists:
|
|
15217
|
+
exists: existsSync18(remotePath),
|
|
15056
15218
|
entries: 0,
|
|
15057
15219
|
valid: 0,
|
|
15058
15220
|
invalidIds: [],
|
|
@@ -15076,7 +15238,7 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
15076
15238
|
}
|
|
15077
15239
|
|
|
15078
15240
|
// src/pipeline/pack.ts
|
|
15079
|
-
import { readFileSync as
|
|
15241
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
15080
15242
|
import path23 from "path";
|
|
15081
15243
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
15082
15244
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
@@ -15110,7 +15272,7 @@ function packSprites(inputs, options = {}) {
|
|
|
15110
15272
|
for (const input of ordered) {
|
|
15111
15273
|
let sourceHash = null;
|
|
15112
15274
|
try {
|
|
15113
|
-
const bytes =
|
|
15275
|
+
const bytes = readFileSync6(input.path);
|
|
15114
15276
|
sourceHash = sha256(bytes);
|
|
15115
15277
|
const png = decodePng(bytes);
|
|
15116
15278
|
sprites.push({ id: input.id, width: png.width, height: png.height, pixels: png.pixels });
|
|
@@ -15269,7 +15431,7 @@ function mountSprites(placements, options) {
|
|
|
15269
15431
|
for (const p of placements) {
|
|
15270
15432
|
let sourceHash = null;
|
|
15271
15433
|
try {
|
|
15272
|
-
const bytes =
|
|
15434
|
+
const bytes = readFileSync6(p.path);
|
|
15273
15435
|
sourceHash = sha256(bytes);
|
|
15274
15436
|
const png = decodePng(bytes);
|
|
15275
15437
|
if (png.width > cellWidth || png.height > cellHeight) {
|
|
@@ -15373,7 +15535,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
15373
15535
|
`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}`
|
|
15374
15536
|
);
|
|
15375
15537
|
}
|
|
15376
|
-
const basePng = mount.base ?
|
|
15538
|
+
const basePng = mount.base ? readFileSync6(path23.resolve(manifestDir, mount.base)) : void 0;
|
|
15377
15539
|
const mounted = mountSprites(placements, {
|
|
15378
15540
|
cellWidth: mount.cellWidth,
|
|
15379
15541
|
cellHeight: mount.cellHeight,
|
|
@@ -16227,7 +16389,7 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
16227
16389
|
}
|
|
16228
16390
|
|
|
16229
16391
|
// src/pipeline/doctor.ts
|
|
16230
|
-
import { constants, existsSync as
|
|
16392
|
+
import { constants, existsSync as existsSync19 } from "fs";
|
|
16231
16393
|
import { access, stat as stat2 } from "fs/promises";
|
|
16232
16394
|
import path24 from "path";
|
|
16233
16395
|
async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
@@ -16295,11 +16457,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16295
16457
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
16296
16458
|
let hasCache = false;
|
|
16297
16459
|
for (const output of entry.outputs) {
|
|
16298
|
-
const
|
|
16460
|
+
const cached2 = path24.join(
|
|
16299
16461
|
cacheDir,
|
|
16300
16462
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
16301
16463
|
);
|
|
16302
|
-
if (
|
|
16464
|
+
if (existsSync19(cached2) && await sha256File(cached2) === output.sha256) {
|
|
16303
16465
|
hasCache = true;
|
|
16304
16466
|
break;
|
|
16305
16467
|
}
|
|
@@ -16402,7 +16564,7 @@ async function nearestExistingDirectory(start) {
|
|
|
16402
16564
|
}
|
|
16403
16565
|
|
|
16404
16566
|
// src/pipeline/adopt.ts
|
|
16405
|
-
import { existsSync as
|
|
16567
|
+
import { existsSync as existsSync20 } from "fs";
|
|
16406
16568
|
import { readFile as readFile15, writeFile as writeFile8 } from "fs/promises";
|
|
16407
16569
|
import path25 from "path";
|
|
16408
16570
|
async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
@@ -16415,7 +16577,7 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
16415
16577
|
const localByHash = /* @__PURE__ */ new Map();
|
|
16416
16578
|
const unmatchedLocal = [];
|
|
16417
16579
|
for (const spec of specs) {
|
|
16418
|
-
if (!
|
|
16580
|
+
if (!existsSync20(spec.outFile)) {
|
|
16419
16581
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
16420
16582
|
continue;
|
|
16421
16583
|
}
|
|
@@ -16536,13 +16698,124 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
16536
16698
|
return count;
|
|
16537
16699
|
}
|
|
16538
16700
|
|
|
16539
|
-
// src/
|
|
16701
|
+
// src/pipeline/import.ts
|
|
16540
16702
|
import { existsSync as existsSync21 } from "fs";
|
|
16541
|
-
import { readFile as
|
|
16703
|
+
import { readFile as readFile16 } from "fs/promises";
|
|
16704
|
+
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
16705
|
+
const png = decodePng(bytes);
|
|
16706
|
+
const at = now.toISOString();
|
|
16707
|
+
return {
|
|
16708
|
+
styleId: spec.styleId,
|
|
16709
|
+
assetId: spec.assetId,
|
|
16710
|
+
specHash: spec.specHash,
|
|
16711
|
+
generator: spec.generator,
|
|
16712
|
+
prompt: spec.prompt,
|
|
16713
|
+
width: png.width,
|
|
16714
|
+
height: png.height,
|
|
16715
|
+
jobId: opts.objectId ?? null,
|
|
16716
|
+
objectId: opts.objectId ?? null,
|
|
16717
|
+
reviewObjectId: null,
|
|
16718
|
+
candidateIndex: null,
|
|
16719
|
+
status: "downloaded",
|
|
16720
|
+
error: null,
|
|
16721
|
+
sourceUrl: null,
|
|
16722
|
+
sourceUrls: [],
|
|
16723
|
+
outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
|
|
16724
|
+
submittedAt: null,
|
|
16725
|
+
downloadedAt: at,
|
|
16726
|
+
cost: 0,
|
|
16727
|
+
costUnit: spec.costUnit,
|
|
16728
|
+
provider: spec.provider,
|
|
16729
|
+
imported: {
|
|
16730
|
+
source: opts.source ?? "external",
|
|
16731
|
+
...opts.note ? { note: opts.note } : {},
|
|
16732
|
+
importedAt: at
|
|
16733
|
+
}
|
|
16734
|
+
};
|
|
16735
|
+
}
|
|
16736
|
+
function unimportable(spec) {
|
|
16737
|
+
if (spec.character) return "a character is several files; import it with account adopt";
|
|
16738
|
+
if (spec.vfx) return "an effect is rendered from its recipe, not imported";
|
|
16739
|
+
if (!spec.outFile.toLowerCase().endsWith(".png")) return "only a single PNG output can be imported";
|
|
16740
|
+
return null;
|
|
16741
|
+
}
|
|
16742
|
+
async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
16743
|
+
if (opts.objectId && specs.length !== 1) {
|
|
16744
|
+
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
16745
|
+
}
|
|
16746
|
+
const imported = [];
|
|
16747
|
+
const skipped = [];
|
|
16748
|
+
for (const spec of specs) {
|
|
16749
|
+
const key = lockKey(spec.styleId, spec.assetId);
|
|
16750
|
+
const reason = unimportable(spec);
|
|
16751
|
+
if (reason) {
|
|
16752
|
+
skipped.push({ key, reason });
|
|
16753
|
+
continue;
|
|
16754
|
+
}
|
|
16755
|
+
if (!existsSync21(spec.outFile)) {
|
|
16756
|
+
skipped.push({ key, reason: `no file at ${spec.outFile}` });
|
|
16757
|
+
continue;
|
|
16758
|
+
}
|
|
16759
|
+
if (lock.entries[key] && !opts.force) {
|
|
16760
|
+
skipped.push({ key, reason: "already in the lockfile (use --force to replace it)" });
|
|
16761
|
+
continue;
|
|
16762
|
+
}
|
|
16763
|
+
let patch;
|
|
16764
|
+
try {
|
|
16765
|
+
patch = buildImportedEntry(spec, await readFile16(spec.outFile), opts);
|
|
16766
|
+
} catch (error) {
|
|
16767
|
+
skipped.push({ key, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
16768
|
+
continue;
|
|
16769
|
+
}
|
|
16770
|
+
if (opts.dryRun) {
|
|
16771
|
+
imported.push({ key, entry: patch });
|
|
16772
|
+
continue;
|
|
16773
|
+
}
|
|
16774
|
+
imported.push({ key, entry: upsert(lock, key, patch) });
|
|
16775
|
+
}
|
|
16776
|
+
if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
|
|
16777
|
+
return { imported, skipped };
|
|
16778
|
+
}
|
|
16779
|
+
async function reportSpecHashes(specs, lock) {
|
|
16780
|
+
const reports = [];
|
|
16781
|
+
for (const spec of specs) {
|
|
16782
|
+
const key = lockKey(spec.styleId, spec.assetId);
|
|
16783
|
+
let bytes = null;
|
|
16784
|
+
if (existsSync21(spec.outFile)) bytes = await readFile16(spec.outFile);
|
|
16785
|
+
let wouldImport = null;
|
|
16786
|
+
if (bytes && !unimportable(spec)) {
|
|
16787
|
+
try {
|
|
16788
|
+
wouldImport = buildImportedEntry(spec, bytes);
|
|
16789
|
+
} catch {
|
|
16790
|
+
wouldImport = null;
|
|
16791
|
+
}
|
|
16792
|
+
}
|
|
16793
|
+
const entry = lock.entries[key];
|
|
16794
|
+
const fileSha256 = bytes ? sha256(bytes) : null;
|
|
16795
|
+
const outputSha256 = entry?.outputs[0]?.sha256 ?? null;
|
|
16796
|
+
reports.push({
|
|
16797
|
+
key,
|
|
16798
|
+
specHash: spec.specHash,
|
|
16799
|
+
file: spec.outFile,
|
|
16800
|
+
fileSha256,
|
|
16801
|
+
lock: entry ? {
|
|
16802
|
+
specHash: entry.specHash,
|
|
16803
|
+
outputSha256,
|
|
16804
|
+
matches: entry.specHash === spec.specHash && outputSha256 !== null && outputSha256 === fileSha256
|
|
16805
|
+
} : null,
|
|
16806
|
+
wouldImport
|
|
16807
|
+
});
|
|
16808
|
+
}
|
|
16809
|
+
return reports;
|
|
16810
|
+
}
|
|
16811
|
+
|
|
16812
|
+
// src/pick/server.ts
|
|
16813
|
+
import { existsSync as existsSync23 } from "fs";
|
|
16814
|
+
import { readFile as readFile19 } from "fs/promises";
|
|
16542
16815
|
|
|
16543
16816
|
// src/pipeline/init.ts
|
|
16544
|
-
import { readdir as readdir3, readFile as
|
|
16545
|
-
import { existsSync as
|
|
16817
|
+
import { readdir as readdir3, readFile as readFile17, writeFile as writeFile9 } from "fs/promises";
|
|
16818
|
+
import { existsSync as existsSync22 } from "fs";
|
|
16546
16819
|
import path26 from "path";
|
|
16547
16820
|
function pngSize(buf) {
|
|
16548
16821
|
if (buf.length < 24) return null;
|
|
@@ -16571,7 +16844,7 @@ async function scanAssets(root, opts = {}) {
|
|
|
16571
16844
|
const skipped = [];
|
|
16572
16845
|
const seen = /* @__PURE__ */ new Map();
|
|
16573
16846
|
for (const file of files.sort()) {
|
|
16574
|
-
const size = pngSize(await
|
|
16847
|
+
const size = pngSize(await readFile17(file));
|
|
16575
16848
|
if (!size) {
|
|
16576
16849
|
skipped.push(`${file} (not a readable PNG)`);
|
|
16577
16850
|
continue;
|
|
@@ -17052,7 +17325,7 @@ document.getElementById('submit').onclick = async () => {
|
|
|
17052
17325
|
|
|
17053
17326
|
// src/pick/review-server.ts
|
|
17054
17327
|
import { createServer } from "http";
|
|
17055
|
-
import { readFile as
|
|
17328
|
+
import { readFile as readFile18 } from "fs/promises";
|
|
17056
17329
|
function serveReviewPage(opts) {
|
|
17057
17330
|
const log = opts.onProgress ?? (() => {
|
|
17058
17331
|
});
|
|
@@ -17061,7 +17334,7 @@ function serveReviewPage(opts) {
|
|
|
17061
17334
|
if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
|
|
17062
17335
|
try {
|
|
17063
17336
|
const asset = opts.assets.get(req.url);
|
|
17064
|
-
const bytes = await
|
|
17337
|
+
const bytes = await readFile18(asset.path);
|
|
17065
17338
|
res.writeHead(200, {
|
|
17066
17339
|
"Content-Type": asset.contentType,
|
|
17067
17340
|
"Cache-Control": "no-store",
|
|
@@ -17137,13 +17410,13 @@ async function currentArt(entry, spec) {
|
|
|
17137
17410
|
const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
|
|
17138
17411
|
if (!previous) return null;
|
|
17139
17412
|
const file = resolveOutputPath(previous.path, spec.root);
|
|
17140
|
-
if (!
|
|
17413
|
+
if (!existsSync23(file)) return null;
|
|
17141
17414
|
const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
|
|
17142
17415
|
if (!contentType) return null;
|
|
17143
17416
|
let width = entry.width;
|
|
17144
17417
|
let height = entry.height;
|
|
17145
17418
|
if (contentType === "image/png") {
|
|
17146
|
-
const size = pngSize(await
|
|
17419
|
+
const size = pngSize(await readFile19(file));
|
|
17147
17420
|
if (size) ({ width, height } = size);
|
|
17148
17421
|
}
|
|
17149
17422
|
return { path: file, contentType, width, height };
|
|
@@ -17151,7 +17424,7 @@ async function currentArt(entry, spec) {
|
|
|
17151
17424
|
async function cachedFrame(url) {
|
|
17152
17425
|
if (!url.startsWith("file://")) return null;
|
|
17153
17426
|
const file = url.slice("file://".length);
|
|
17154
|
-
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await
|
|
17427
|
+
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await readFile19(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
|
|
17155
17428
|
return { path: file, contentType };
|
|
17156
17429
|
}
|
|
17157
17430
|
async function prepareReview(provider, lock, opts = {}) {
|
|
@@ -17177,15 +17450,15 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17177
17450
|
const frameAssets = [];
|
|
17178
17451
|
const frameSizes = [];
|
|
17179
17452
|
for (const [index, url] of urls.entries()) {
|
|
17180
|
-
const
|
|
17181
|
-
if (!
|
|
17453
|
+
const cached2 = await cachedFrame(url);
|
|
17454
|
+
if (!cached2) {
|
|
17182
17455
|
frameUrls.push(url);
|
|
17183
17456
|
frameSizes.push(null);
|
|
17184
17457
|
continue;
|
|
17185
17458
|
}
|
|
17186
|
-
frameSizes.push(
|
|
17459
|
+
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await readFile19(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
17187
17460
|
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
17188
|
-
frameAssets.push([route,
|
|
17461
|
+
frameAssets.push([route, cached2]);
|
|
17189
17462
|
frameUrls.push(route);
|
|
17190
17463
|
}
|
|
17191
17464
|
const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String(groups.length))}` : null;
|
|
@@ -17337,13 +17610,13 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
17337
17610
|
|
|
17338
17611
|
// src/gallery/snapshot.ts
|
|
17339
17612
|
import { createHash as createHash5 } from "crypto";
|
|
17340
|
-
import { existsSync as
|
|
17341
|
-
import { readFile as
|
|
17613
|
+
import { existsSync as existsSync29 } from "fs";
|
|
17614
|
+
import { readFile as readFile26, stat as stat3 } from "fs/promises";
|
|
17342
17615
|
import path34 from "path";
|
|
17343
17616
|
|
|
17344
17617
|
// src/workspace.ts
|
|
17345
|
-
import { mkdir as mkdir8, readFile as
|
|
17346
|
-
import { existsSync as
|
|
17618
|
+
import { mkdir as mkdir8, readFile as readFile20, rename as rename6, rm as rm7, writeFile as writeFile10 } from "fs/promises";
|
|
17619
|
+
import { existsSync as existsSync24 } from "fs";
|
|
17347
17620
|
import path27 from "path";
|
|
17348
17621
|
import { z as z7 } from "zod";
|
|
17349
17622
|
var WorkspaceProjectSchema = z7.object({
|
|
@@ -17369,10 +17642,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
|
|
|
17369
17642
|
);
|
|
17370
17643
|
}
|
|
17371
17644
|
async function loadWorkspace(workspacePath) {
|
|
17372
|
-
if (!
|
|
17645
|
+
if (!existsSync24(workspacePath)) return { version: 1, projects: [] };
|
|
17373
17646
|
let raw;
|
|
17374
17647
|
try {
|
|
17375
|
-
raw = JSON.parse(await
|
|
17648
|
+
raw = JSON.parse(await readFile20(workspacePath, "utf8"));
|
|
17376
17649
|
} catch (err) {
|
|
17377
17650
|
throw new ProjectError(
|
|
17378
17651
|
`Workspace catalog at ${workspacePath} is malformed:
|
|
@@ -17421,14 +17694,14 @@ function validateWorkspace(ws, dir) {
|
|
|
17421
17694
|
message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
|
|
17422
17695
|
});
|
|
17423
17696
|
}
|
|
17424
|
-
if (!
|
|
17697
|
+
if (!existsSync24(manifestPath)) {
|
|
17425
17698
|
diagnostics.push({
|
|
17426
17699
|
id: "missing-manifest",
|
|
17427
17700
|
level: "error",
|
|
17428
17701
|
message: `project "${project.id}" manifest not found: ${manifestPath}`
|
|
17429
17702
|
});
|
|
17430
17703
|
}
|
|
17431
|
-
if (!
|
|
17704
|
+
if (!existsSync24(lockPath)) {
|
|
17432
17705
|
diagnostics.push({
|
|
17433
17706
|
id: "missing-lock",
|
|
17434
17707
|
level: "error",
|
|
@@ -17475,12 +17748,12 @@ function validateWorkspace(ws, dir) {
|
|
|
17475
17748
|
}
|
|
17476
17749
|
|
|
17477
17750
|
// src/gallery/edit.ts
|
|
17478
|
-
import { readFile as
|
|
17751
|
+
import { readFile as readFile25, rename as rename9, writeFile as writeFile16 } from "fs/promises";
|
|
17479
17752
|
import path33 from "path";
|
|
17480
17753
|
import { z as z13 } from "zod";
|
|
17481
17754
|
|
|
17482
17755
|
// src/manifest-edit.ts
|
|
17483
|
-
import { readFile as
|
|
17756
|
+
import { readFile as readFile21, rename as rename7, rm as rm8, writeFile as writeFile11 } from "fs/promises";
|
|
17484
17757
|
import path28 from "path";
|
|
17485
17758
|
import { z as z8 } from "zod";
|
|
17486
17759
|
var HexSha = z8.string().regex(/^[0-9a-f]{64}$/);
|
|
@@ -17905,7 +18178,7 @@ function applyEdit(raw, edit) {
|
|
|
17905
18178
|
}
|
|
17906
18179
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
17907
18180
|
const absolute = path28.resolve(manifestPath);
|
|
17908
|
-
const original = await
|
|
18181
|
+
const original = await readFile21(absolute, "utf8");
|
|
17909
18182
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
17910
18183
|
let raw;
|
|
17911
18184
|
try {
|
|
@@ -17949,8 +18222,8 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
17949
18222
|
}
|
|
17950
18223
|
|
|
17951
18224
|
// src/pipeline/hand-edit.ts
|
|
17952
|
-
import { existsSync as
|
|
17953
|
-
import { copyFile, mkdir as mkdir9, readFile as
|
|
18225
|
+
import { existsSync as existsSync25 } from "fs";
|
|
18226
|
+
import { copyFile, mkdir as mkdir9, readFile as readFile22, rename as rename8, rm as rm9, writeFile as writeFile12 } from "fs/promises";
|
|
17954
18227
|
import path29 from "path";
|
|
17955
18228
|
import { z as z9 } from "zod";
|
|
17956
18229
|
var HAND_EDIT_DIR = "edits";
|
|
@@ -17973,10 +18246,10 @@ function handEditBases(spec, lock) {
|
|
|
17973
18246
|
}));
|
|
17974
18247
|
if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
|
|
17975
18248
|
if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
|
|
17976
|
-
if (!members.every((member) =>
|
|
18249
|
+
if (!members.every((member) => existsSync25(member.path))) return null;
|
|
17977
18250
|
return members.map(({ role, path: file }) => ({ role, path: file }));
|
|
17978
18251
|
}
|
|
17979
|
-
return
|
|
18252
|
+
return existsSync25(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
|
|
17980
18253
|
}
|
|
17981
18254
|
function handEditBase(spec, lock) {
|
|
17982
18255
|
const bases = handEditBases(spec, lock);
|
|
@@ -18011,7 +18284,7 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
18011
18284
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
18012
18285
|
let created = false;
|
|
18013
18286
|
for (const member of members) {
|
|
18014
|
-
if (
|
|
18287
|
+
if (existsSync25(member.path)) continue;
|
|
18015
18288
|
if (!member.base) {
|
|
18016
18289
|
throw new ManifestEditError(
|
|
18017
18290
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
@@ -18096,7 +18369,7 @@ function handEditProjectPath(editPath) {
|
|
|
18096
18369
|
async function readHandEditCompanion(editPath) {
|
|
18097
18370
|
let text;
|
|
18098
18371
|
try {
|
|
18099
|
-
text = await
|
|
18372
|
+
text = await readFile22(handEditCompanionPath(editPath), "utf8");
|
|
18100
18373
|
} catch {
|
|
18101
18374
|
return null;
|
|
18102
18375
|
}
|
|
@@ -18139,7 +18412,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
18139
18412
|
}
|
|
18140
18413
|
});
|
|
18141
18414
|
const bases = handEditBases(spec, lock);
|
|
18142
|
-
const expectedSize = bases?.[0] ? decodePng(await
|
|
18415
|
+
const expectedSize = bases?.[0] ? decodePng(await readFile22(bases[0].path)) : { width: spec.width, height: spec.height };
|
|
18143
18416
|
for (const [index, image] of decoded.entries()) {
|
|
18144
18417
|
if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
|
|
18145
18418
|
const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
|
|
@@ -18197,7 +18470,7 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
18197
18470
|
}
|
|
18198
18471
|
|
|
18199
18472
|
// src/gallery/upload.ts
|
|
18200
|
-
import { existsSync as
|
|
18473
|
+
import { existsSync as existsSync26 } from "fs";
|
|
18201
18474
|
import { mkdir as mkdir10, writeFile as writeFile13 } from "fs/promises";
|
|
18202
18475
|
import path30 from "path";
|
|
18203
18476
|
import { z as z10 } from "zod";
|
|
@@ -18229,7 +18502,7 @@ async function saveProjectImage(root, request) {
|
|
|
18229
18502
|
if (metadata.format !== expected) {
|
|
18230
18503
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
18231
18504
|
}
|
|
18232
|
-
if (
|
|
18505
|
+
if (existsSync26(file) && !request.overwrite) {
|
|
18233
18506
|
throw new ManifestEditError(`${relative.split(path30.sep).join("/")} already exists; choose another name, or replace it`);
|
|
18234
18507
|
}
|
|
18235
18508
|
await mkdir10(path30.dirname(file), { recursive: true });
|
|
@@ -18238,8 +18511,8 @@ async function saveProjectImage(root, request) {
|
|
|
18238
18511
|
}
|
|
18239
18512
|
|
|
18240
18513
|
// src/gallery/image-revision.ts
|
|
18241
|
-
import { existsSync as
|
|
18242
|
-
import { readFile as
|
|
18514
|
+
import { existsSync as existsSync27 } from "fs";
|
|
18515
|
+
import { readFile as readFile23, rm as rm10, writeFile as writeFile14 } from "fs/promises";
|
|
18243
18516
|
import path31 from "path";
|
|
18244
18517
|
import { z as z11 } from "zod";
|
|
18245
18518
|
var InpaintRevisionRequestSchema = z11.object({
|
|
@@ -18267,7 +18540,7 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
18267
18540
|
const metadata = imageMetadata(bytes);
|
|
18268
18541
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
18269
18542
|
const file = path31.resolve(root, request.maskPath);
|
|
18270
|
-
const previous =
|
|
18543
|
+
const previous = existsSync27(file) ? await readFile23(file) : null;
|
|
18271
18544
|
const mask = await saveProjectImage(root, {
|
|
18272
18545
|
action: "upload-image",
|
|
18273
18546
|
path: request.maskPath,
|
|
@@ -18294,8 +18567,8 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
18294
18567
|
}
|
|
18295
18568
|
|
|
18296
18569
|
// src/gallery/skeleton.ts
|
|
18297
|
-
import { existsSync as
|
|
18298
|
-
import { mkdir as mkdir11, readFile as
|
|
18570
|
+
import { existsSync as existsSync28 } from "fs";
|
|
18571
|
+
import { mkdir as mkdir11, readFile as readFile24, rm as rm11, writeFile as writeFile15 } from "fs/promises";
|
|
18299
18572
|
import path32 from "path";
|
|
18300
18573
|
import { z as z12 } from "zod";
|
|
18301
18574
|
var SkeletonEstimateRequestSchema = z12.object({
|
|
@@ -18341,13 +18614,13 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
18341
18614
|
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path32.isAbsolute(relative)) {
|
|
18342
18615
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
18343
18616
|
}
|
|
18344
|
-
const existed =
|
|
18617
|
+
const existed = existsSync28(file);
|
|
18345
18618
|
let previous = null;
|
|
18346
18619
|
if (request.set) {
|
|
18347
18620
|
if (existed && !request.overwrite) {
|
|
18348
18621
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
18349
18622
|
}
|
|
18350
|
-
if (existed) previous = await
|
|
18623
|
+
if (existed) previous = await readFile24(file);
|
|
18351
18624
|
await mkdir11(path32.dirname(file), { recursive: true });
|
|
18352
18625
|
await writeFile15(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18353
18626
|
} else if (!existed) {
|
|
@@ -18389,7 +18662,7 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
18389
18662
|
if (relative.startsWith("..") || path32.isAbsolute(relative)) {
|
|
18390
18663
|
throw new ManifestEditError(`${key}'s keypoints file is outside the project; edit it by hand`);
|
|
18391
18664
|
}
|
|
18392
|
-
const current =
|
|
18665
|
+
const current = existsSync28(file) ? sha256(await readFile24(file)) : null;
|
|
18393
18666
|
if (current !== request.expectedSha256) {
|
|
18394
18667
|
throw Object.assign(
|
|
18395
18668
|
new Error(`${relative.split(path32.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
@@ -18461,7 +18734,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18461
18734
|
if (undo.success) {
|
|
18462
18735
|
const manifestPath2 = await manifestOf(undo.data.project);
|
|
18463
18736
|
if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
|
|
18464
|
-
const current = await
|
|
18737
|
+
const current = await readFile25(manifestPath2, "utf8");
|
|
18465
18738
|
if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
|
|
18466
18739
|
const stack = history.get(manifestPath2) ?? [];
|
|
18467
18740
|
const last = stack[stack.length - 1];
|
|
@@ -18478,10 +18751,10 @@ function createGalleryEditHandler(opts) {
|
|
|
18478
18751
|
return opts.reload();
|
|
18479
18752
|
}
|
|
18480
18753
|
const manifestPath = await manifestOf(body?.project);
|
|
18481
|
-
const before = manifestPath ? await
|
|
18754
|
+
const before = manifestPath ? await readFile25(manifestPath, "utf8").catch(() => null) : null;
|
|
18482
18755
|
const build = await apply(body);
|
|
18483
18756
|
if (manifestPath && before !== null) {
|
|
18484
|
-
const after = await
|
|
18757
|
+
const after = await readFile25(manifestPath, "utf8").catch(() => null);
|
|
18485
18758
|
if (after !== null && after !== before) {
|
|
18486
18759
|
const stack = history.get(manifestPath) ?? [];
|
|
18487
18760
|
stack.push({ before, afterSha: sha256(after) });
|
|
@@ -18657,7 +18930,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
18657
18930
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
18658
18931
|
const file = path34.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
18659
18932
|
let url = null;
|
|
18660
|
-
if (
|
|
18933
|
+
if (existsSync29(file)) {
|
|
18661
18934
|
const id = galleryMediaId(file);
|
|
18662
18935
|
media.set(id, { path: file, contentType: mediaType });
|
|
18663
18936
|
url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
|
|
@@ -18689,7 +18962,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
18689
18962
|
var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
|
|
18690
18963
|
async function samePixels(a, b) {
|
|
18691
18964
|
try {
|
|
18692
|
-
const [left, right] = await Promise.all([
|
|
18965
|
+
const [left, right] = await Promise.all([readFile26(a), readFile26(b)]);
|
|
18693
18966
|
if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
|
|
18694
18967
|
const x = decodePng(left);
|
|
18695
18968
|
const y = decodePng(right);
|
|
@@ -18790,7 +19063,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
18790
19063
|
outputPaths.map((file) => describeOutput(media, root, path34.resolve(root, file)))
|
|
18791
19064
|
);
|
|
18792
19065
|
const recordPath = path34.resolve(root, inspection.record);
|
|
18793
|
-
const recordExists =
|
|
19066
|
+
const recordExists = existsSync29(recordPath);
|
|
18794
19067
|
let options = null;
|
|
18795
19068
|
let check = null;
|
|
18796
19069
|
if (recordExists) {
|
|
@@ -18847,7 +19120,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18847
19120
|
const media = /* @__PURE__ */ new Map();
|
|
18848
19121
|
const plan = await buildPlan(specs, lock);
|
|
18849
19122
|
const items = [];
|
|
18850
|
-
const manifestText = await
|
|
19123
|
+
const manifestText = await readFile26(loaded.path, "utf8");
|
|
18851
19124
|
const manifestSha256 = sha256(manifestText);
|
|
18852
19125
|
const cacheDir = path34.resolve(path34.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
18853
19126
|
let rawStyles = {};
|
|
@@ -18878,7 +19151,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18878
19151
|
const editShas = await Promise.all(
|
|
18879
19152
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
18880
19153
|
const file = sourceOutputPath(spec.source, entry, index, root);
|
|
18881
|
-
return { file, sha256:
|
|
19154
|
+
return { file, sha256: existsSync29(file) ? await sha256File(file) : null };
|
|
18882
19155
|
})
|
|
18883
19156
|
);
|
|
18884
19157
|
edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
|
|
@@ -18886,7 +19159,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18886
19159
|
const companion = await readHandEditCompanion(editPath);
|
|
18887
19160
|
if (companion) {
|
|
18888
19161
|
const projectPath = handEditProjectPath(editPath);
|
|
18889
|
-
const project = companion.project &&
|
|
19162
|
+
const project = companion.project && existsSync29(projectPath) ? await fileInfo(projectPath) : null;
|
|
18890
19163
|
let projectUrl = null;
|
|
18891
19164
|
if (project) {
|
|
18892
19165
|
const id = galleryMediaId(projectPath);
|
|
@@ -18923,7 +19196,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18923
19196
|
}
|
|
18924
19197
|
} else if (spec.source) {
|
|
18925
19198
|
outputs = [await describeOutput(media, root, path34.resolve(root, spec.source))];
|
|
18926
|
-
} else if (!entry &&
|
|
19199
|
+
} else if (!entry && existsSync29(spec.outFile)) {
|
|
18927
19200
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
18928
19201
|
} else {
|
|
18929
19202
|
outputs = [];
|
|
@@ -19200,7 +19473,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19200
19473
|
root: loaded.root,
|
|
19201
19474
|
provider: loaded.manifest.provider,
|
|
19202
19475
|
account: project.account ?? null,
|
|
19203
|
-
manifestSha256: manifestSha256 ?? sha256(await
|
|
19476
|
+
manifestSha256: manifestSha256 ?? sha256(await readFile26(manifestPath, "utf8")),
|
|
19204
19477
|
historyLimit: historyLimit(loaded.manifest),
|
|
19205
19478
|
entries: Object.keys(lock.entries).length,
|
|
19206
19479
|
items: projectItems.length,
|
|
@@ -19257,7 +19530,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19257
19530
|
}
|
|
19258
19531
|
|
|
19259
19532
|
// src/gallery/page.ts
|
|
19260
|
-
import { existsSync as
|
|
19533
|
+
import { existsSync as existsSync30, readFileSync as readFileSync7 } from "fs";
|
|
19261
19534
|
|
|
19262
19535
|
// src/gallery/client-bundle.ts
|
|
19263
19536
|
import { createRequire } from "module";
|
|
@@ -19297,8 +19570,8 @@ var client;
|
|
|
19297
19570
|
function clientAssets() {
|
|
19298
19571
|
const prebuilt = new URL("gallery.js", CLIENT_DIR);
|
|
19299
19572
|
client ??= {
|
|
19300
|
-
css:
|
|
19301
|
-
js:
|
|
19573
|
+
css: readFileSync7(new URL("gallery.css", CLIENT_DIR), "utf8"),
|
|
19574
|
+
js: existsSync30(prebuilt) ? readFileSync7(prebuilt, "utf8") : bundleGalleryClient()
|
|
19302
19575
|
};
|
|
19303
19576
|
return client;
|
|
19304
19577
|
}
|
|
@@ -19441,8 +19714,8 @@ var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download
|
|
|
19441
19714
|
|
|
19442
19715
|
// src/editor/install.ts
|
|
19443
19716
|
import { createHash as createHash6 } from "crypto";
|
|
19444
|
-
import { existsSync as
|
|
19445
|
-
import { mkdir as mkdir12, readFile as
|
|
19717
|
+
import { existsSync as existsSync31 } from "fs";
|
|
19718
|
+
import { mkdir as mkdir12, readFile as readFile27, rename as rename10, rm as rm12, stat as stat4, writeFile as writeFile17 } from "fs/promises";
|
|
19446
19719
|
import os3 from "os";
|
|
19447
19720
|
import path35 from "path";
|
|
19448
19721
|
var EditorInstallError = class extends Error {
|
|
@@ -19473,7 +19746,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
|
|
|
19473
19746
|
}
|
|
19474
19747
|
async function sha256Of(file) {
|
|
19475
19748
|
try {
|
|
19476
|
-
return createHash6("sha256").update(await
|
|
19749
|
+
return createHash6("sha256").update(await readFile27(file)).digest("hex");
|
|
19477
19750
|
} catch {
|
|
19478
19751
|
return null;
|
|
19479
19752
|
}
|
|
@@ -19487,7 +19760,7 @@ async function editorStatus(opts = {}) {
|
|
|
19487
19760
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
19488
19761
|
totalBytes += expected.bytes;
|
|
19489
19762
|
const file = path35.join(dir, name);
|
|
19490
|
-
const info =
|
|
19763
|
+
const info = existsSync31(file) ? await stat4(file).catch(() => null) : null;
|
|
19491
19764
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
19492
19765
|
installedBytes += expected.bytes;
|
|
19493
19766
|
} else {
|
|
@@ -19594,7 +19867,7 @@ function editorContentType(name) {
|
|
|
19594
19867
|
}
|
|
19595
19868
|
|
|
19596
19869
|
// src/gallery/editor.ts
|
|
19597
|
-
import { readFile as
|
|
19870
|
+
import { readFile as readFile28 } from "fs/promises";
|
|
19598
19871
|
import path36 from "path";
|
|
19599
19872
|
function editorRoute(release, name = "index.html") {
|
|
19600
19873
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
@@ -19668,7 +19941,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
19668
19941
|
if (!status.installed) return null;
|
|
19669
19942
|
let bytes;
|
|
19670
19943
|
try {
|
|
19671
|
-
bytes = await
|
|
19944
|
+
bytes = await readFile28(path36.join(dir, name));
|
|
19672
19945
|
} catch {
|
|
19673
19946
|
verified = null;
|
|
19674
19947
|
return null;
|
|
@@ -19685,7 +19958,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
19685
19958
|
// src/gallery/server.ts
|
|
19686
19959
|
import { randomBytes } from "crypto";
|
|
19687
19960
|
import { createServer as createServer2 } from "http";
|
|
19688
|
-
import { readFile as
|
|
19961
|
+
import { readFile as readFile29 } from "fs/promises";
|
|
19689
19962
|
var MAX_EDIT_BYTES = 48 * 1024 * 1024;
|
|
19690
19963
|
var EDITOR_CSP = [
|
|
19691
19964
|
"default-src 'self'",
|
|
@@ -19866,7 +20139,7 @@ async function serveGallery(opts) {
|
|
|
19866
20139
|
const asset = reviewAssets.get(jobId)?.get(url2.pathname);
|
|
19867
20140
|
if (!asset) return fail(404, "no such review asset");
|
|
19868
20141
|
try {
|
|
19869
|
-
const bytes = await
|
|
20142
|
+
const bytes = await readFile29(asset.path);
|
|
19870
20143
|
res.writeHead(200, {
|
|
19871
20144
|
"Content-Type": asset.contentType,
|
|
19872
20145
|
"Cache-Control": "no-store",
|
|
@@ -19949,7 +20222,7 @@ async function serveGallery(opts) {
|
|
|
19949
20222
|
if (!asset) return fail(404, "no such gallery media");
|
|
19950
20223
|
let bytes;
|
|
19951
20224
|
try {
|
|
19952
|
-
bytes = await
|
|
20225
|
+
bytes = await readFile29(asset.path);
|
|
19953
20226
|
} catch {
|
|
19954
20227
|
return fail(404, "gallery media is no longer on disk; refresh the page");
|
|
19955
20228
|
}
|
|
@@ -20359,8 +20632,8 @@ function createGenerateHandlers(opts) {
|
|
|
20359
20632
|
}
|
|
20360
20633
|
|
|
20361
20634
|
// src/pipeline/salvage.ts
|
|
20362
|
-
import { readFile as
|
|
20363
|
-
import { existsSync as
|
|
20635
|
+
import { readFile as readFile30 } from "fs/promises";
|
|
20636
|
+
import { existsSync as existsSync32 } from "fs";
|
|
20364
20637
|
import path37 from "path";
|
|
20365
20638
|
function providerClaimId(provider, objectId) {
|
|
20366
20639
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
@@ -20368,10 +20641,10 @@ function providerClaimId(provider, objectId) {
|
|
|
20368
20641
|
async function loadClaims(lockPaths, opts = {}) {
|
|
20369
20642
|
const claimed = /* @__PURE__ */ new Set();
|
|
20370
20643
|
for (const p of lockPaths) {
|
|
20371
|
-
if (!
|
|
20644
|
+
if (!existsSync32(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
20372
20645
|
let parsed;
|
|
20373
20646
|
try {
|
|
20374
|
-
parsed = parseLock(JSON.parse(await
|
|
20647
|
+
parsed = parseLock(JSON.parse(await readFile30(p, "utf8")));
|
|
20375
20648
|
} catch {
|
|
20376
20649
|
throw new Error(`Claim lockfile is malformed: ${p}`);
|
|
20377
20650
|
}
|
|
@@ -20485,7 +20758,7 @@ async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, cla
|
|
|
20485
20758
|
const siblings = [];
|
|
20486
20759
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
20487
20760
|
if (path37.resolve(siblingManifestPath) === own) continue;
|
|
20488
|
-
if (!
|
|
20761
|
+
if (!existsSync32(siblingManifestPath)) continue;
|
|
20489
20762
|
try {
|
|
20490
20763
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
20491
20764
|
siblings.push({ label: path37.basename(path37.dirname(siblingManifestPath)), manifest });
|
|
@@ -20608,7 +20881,7 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
20608
20881
|
}
|
|
20609
20882
|
|
|
20610
20883
|
// src/pick/salvage-server.ts
|
|
20611
|
-
import { mkdir as mkdir13, writeFile as writeFile18, readFile as
|
|
20884
|
+
import { mkdir as mkdir13, writeFile as writeFile18, readFile as readFile31 } from "fs/promises";
|
|
20612
20885
|
import path38 from "path";
|
|
20613
20886
|
|
|
20614
20887
|
// src/pick/salvage-sheet.ts
|
|
@@ -20890,7 +21163,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
20890
21163
|
}
|
|
20891
21164
|
}
|
|
20892
21165
|
await applyTags(provider, decisions, existingTags, { onProgress: log, characters: characterMembers });
|
|
20893
|
-
const raw = JSON.parse(await
|
|
21166
|
+
const raw = JSON.parse(await readFile31(ctx.manifestPath, "utf8"));
|
|
20894
21167
|
for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
|
|
20895
21168
|
await writeFile18(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
|
|
20896
21169
|
await saveLock(ctx.lockPath, ctx.lock);
|
|
@@ -21115,6 +21388,7 @@ export {
|
|
|
21115
21388
|
availableProviders,
|
|
21116
21389
|
backoffMs,
|
|
21117
21390
|
buildGallerySnapshot,
|
|
21391
|
+
buildImportedEntry,
|
|
21118
21392
|
buildManifest,
|
|
21119
21393
|
buildPlan,
|
|
21120
21394
|
buildWorkspaceGallerySnapshot,
|
|
@@ -21177,6 +21451,7 @@ export {
|
|
|
21177
21451
|
historyLimit,
|
|
21178
21452
|
idFromPrompt,
|
|
21179
21453
|
imageMetadata,
|
|
21454
|
+
importLocal,
|
|
21180
21455
|
inspectCaches,
|
|
21181
21456
|
inspectQualityProfile,
|
|
21182
21457
|
inspectRevisionReadiness,
|
|
@@ -21234,6 +21509,7 @@ export {
|
|
|
21234
21509
|
parseVfxStep,
|
|
21235
21510
|
parseWorkspace,
|
|
21236
21511
|
pickHistory,
|
|
21512
|
+
pixMiniMaxCost,
|
|
21237
21513
|
pixelateFile,
|
|
21238
21514
|
pngSize,
|
|
21239
21515
|
poll,
|
|
@@ -21268,6 +21544,7 @@ export {
|
|
|
21268
21544
|
renderSalvageSheet,
|
|
21269
21545
|
renderSheet,
|
|
21270
21546
|
renderSheetDocument,
|
|
21547
|
+
reportSpecHashes,
|
|
21271
21548
|
requireApprovedQualitySources,
|
|
21272
21549
|
requireBalance,
|
|
21273
21550
|
requireDelete,
|
|
@@ -21307,6 +21584,7 @@ export {
|
|
|
21307
21584
|
sliceVfxSheet,
|
|
21308
21585
|
slugify,
|
|
21309
21586
|
snapshotQualityBaseline,
|
|
21587
|
+
snapshotQualityCases,
|
|
21310
21588
|
sourceIsStem,
|
|
21311
21589
|
sourceOutputPath,
|
|
21312
21590
|
specHash,
|
|
@@ -21325,6 +21603,7 @@ export {
|
|
|
21325
21603
|
tilesCost,
|
|
21326
21604
|
toPortablePath,
|
|
21327
21605
|
totalSpend,
|
|
21606
|
+
uiElementCandidateCount,
|
|
21328
21607
|
unzoomFile,
|
|
21329
21608
|
upsert,
|
|
21330
21609
|
validateCostEstimate,
|