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.cjs
CHANGED
|
@@ -145,6 +145,7 @@ __export(index_exports, {
|
|
|
145
145
|
availableProviders: () => availableProviders,
|
|
146
146
|
backoffMs: () => backoffMs,
|
|
147
147
|
buildGallerySnapshot: () => buildGallerySnapshot,
|
|
148
|
+
buildImportedEntry: () => buildImportedEntry,
|
|
148
149
|
buildManifest: () => buildManifest,
|
|
149
150
|
buildPlan: () => buildPlan,
|
|
150
151
|
buildWorkspaceGallerySnapshot: () => buildWorkspaceGallerySnapshot,
|
|
@@ -207,6 +208,7 @@ __export(index_exports, {
|
|
|
207
208
|
historyLimit: () => historyLimit,
|
|
208
209
|
idFromPrompt: () => idFromPrompt,
|
|
209
210
|
imageMetadata: () => imageMetadata,
|
|
211
|
+
importLocal: () => importLocal,
|
|
210
212
|
inspectCaches: () => inspectCaches,
|
|
211
213
|
inspectQualityProfile: () => inspectQualityProfile,
|
|
212
214
|
inspectRevisionReadiness: () => inspectRevisionReadiness,
|
|
@@ -264,6 +266,7 @@ __export(index_exports, {
|
|
|
264
266
|
parseVfxStep: () => parseVfxStep,
|
|
265
267
|
parseWorkspace: () => parseWorkspace,
|
|
266
268
|
pickHistory: () => pickHistory,
|
|
269
|
+
pixMiniMaxCost: () => pixMiniMaxCost,
|
|
267
270
|
pixelateFile: () => pixelateFile,
|
|
268
271
|
pngSize: () => pngSize,
|
|
269
272
|
poll: () => poll,
|
|
@@ -298,6 +301,7 @@ __export(index_exports, {
|
|
|
298
301
|
renderSalvageSheet: () => renderSalvageSheet,
|
|
299
302
|
renderSheet: () => renderSheet,
|
|
300
303
|
renderSheetDocument: () => renderSheetDocument,
|
|
304
|
+
reportSpecHashes: () => reportSpecHashes,
|
|
301
305
|
requireApprovedQualitySources: () => requireApprovedQualitySources,
|
|
302
306
|
requireBalance: () => requireBalance,
|
|
303
307
|
requireDelete: () => requireDelete,
|
|
@@ -337,6 +341,7 @@ __export(index_exports, {
|
|
|
337
341
|
sliceVfxSheet: () => sliceVfxSheet,
|
|
338
342
|
slugify: () => slugify,
|
|
339
343
|
snapshotQualityBaseline: () => snapshotQualityBaseline,
|
|
344
|
+
snapshotQualityCases: () => snapshotQualityCases,
|
|
340
345
|
sourceIsStem: () => sourceIsStem,
|
|
341
346
|
sourceOutputPath: () => sourceOutputPath,
|
|
342
347
|
specHash: () => specHash,
|
|
@@ -355,6 +360,7 @@ __export(index_exports, {
|
|
|
355
360
|
tilesCost: () => tilesCost,
|
|
356
361
|
toPortablePath: () => toPortablePath,
|
|
357
362
|
totalSpend: () => totalSpend,
|
|
363
|
+
uiElementCandidateCount: () => uiElementCandidateCount,
|
|
358
364
|
unzoomFile: () => unzoomFile,
|
|
359
365
|
upsert: () => upsert,
|
|
360
366
|
validateCostEstimate: () => validateCostEstimate,
|
|
@@ -431,6 +437,17 @@ function candidateCount(size) {
|
|
|
431
437
|
if (size <= 170) return 4;
|
|
432
438
|
return 1;
|
|
433
439
|
}
|
|
440
|
+
function uiElementCandidateCount(size) {
|
|
441
|
+
if (size <= 32) return 64;
|
|
442
|
+
if (size <= 35) return 49;
|
|
443
|
+
if (size <= 41) return 36;
|
|
444
|
+
if (size <= 50) return 25;
|
|
445
|
+
if (size <= 64) return 16;
|
|
446
|
+
if (size <= 84) return 9;
|
|
447
|
+
if (size === 85) return 16;
|
|
448
|
+
if (size <= 170) return 4;
|
|
449
|
+
return 1;
|
|
450
|
+
}
|
|
434
451
|
function generationCost(width, height, generator = "map") {
|
|
435
452
|
if (generator === "vfx") return 0;
|
|
436
453
|
if (generator === "map" || generator === "pixflux") return 1;
|
|
@@ -447,6 +464,16 @@ function proTierCost(width, height) {
|
|
|
447
464
|
if (px <= 102400) return PRO_TIER_PRICES[1];
|
|
448
465
|
return PRO_TIER_PRICES[2];
|
|
449
466
|
}
|
|
467
|
+
function pixMiniMaxCost(width, height, frames, enhancePrompt = false) {
|
|
468
|
+
const f = width * height * Math.max(1, frames) / 4096;
|
|
469
|
+
let units;
|
|
470
|
+
if (f <= 8) units = 1;
|
|
471
|
+
else if (f <= 16) units = 1 + (f - 8) / 8;
|
|
472
|
+
else if (f <= 40) units = 2 + (f - 16) / 6;
|
|
473
|
+
else units = 6 + (f - 40) / 6;
|
|
474
|
+
const base = Math.max(1, Math.ceil(units - 1e-9));
|
|
475
|
+
return enhancePrompt ? base + 0.05 : base;
|
|
476
|
+
}
|
|
450
477
|
function tilesCost(tileSize, variations) {
|
|
451
478
|
const px = tileSize * tileSize * Math.max(1, variations);
|
|
452
479
|
if (px <= 1024) return PRO_TIER_PRICES[0];
|
|
@@ -1944,7 +1971,17 @@ var LockEntrySchema = import_zod.z.object({
|
|
|
1944
1971
|
/** Generations this entry replaced, newest first; see LockHistoryEntrySchema. */
|
|
1945
1972
|
history: import_zod.z.array(LockHistoryEntrySchema).optional(),
|
|
1946
1973
|
/** Post-processing applied to the recorded outputs; absent when the bytes are the provider's. */
|
|
1947
|
-
postprocess: PostprocessSchema.optional()
|
|
1974
|
+
postprocess: PostprocessSchema.optional(),
|
|
1975
|
+
/**
|
|
1976
|
+
* Set when the entry records art made outside pixelkiln (the PixelLab MCP, a
|
|
1977
|
+
* hand edit, another tool) and brought in with `adopt --local`: nothing was
|
|
1978
|
+
* submitted, so jobId and cost are empty. Absent on generated entries.
|
|
1979
|
+
*/
|
|
1980
|
+
imported: import_zod.z.object({
|
|
1981
|
+
source: import_zod.z.string().min(1),
|
|
1982
|
+
note: import_zod.z.string().optional(),
|
|
1983
|
+
importedAt: import_zod.z.string()
|
|
1984
|
+
}).strict().optional()
|
|
1948
1985
|
});
|
|
1949
1986
|
var LockSchema = import_zod.z.object({
|
|
1950
1987
|
version: import_zod.z.literal(2),
|
|
@@ -3266,10 +3303,10 @@ var PixelLabClient = class {
|
|
|
3266
3303
|
* limited to 400x400 and no style reference. Like a revision, this hands
|
|
3267
3304
|
* back a plain background job with no resource of its own; unlike a
|
|
3268
3305
|
* revision, one call returns several candidate images to pick from (the
|
|
3269
|
-
* same 4/16/64-by-size tiering as `1dir`), not a single result
|
|
3270
|
-
*
|
|
3271
|
-
* pixellab.ts fails loudly rather than guess if `last_response.images`
|
|
3272
|
-
*
|
|
3306
|
+
* same 4/16/64-by-size tiering as `1dir`), not a single result. It has run
|
|
3307
|
+
* live (a 64x64 call billed 10, October 2026); `pollImagePro` in
|
|
3308
|
+
* pixellab.ts still fails loudly rather than guess if `last_response.images`
|
|
3309
|
+
* is not the field name.
|
|
3273
3310
|
*
|
|
3274
3311
|
* Reference images and a style image (`reference_images`, `style_image` +
|
|
3275
3312
|
* `style_options`) exist on this endpoint but are not modeled here yet.
|
|
@@ -3380,7 +3417,8 @@ var PixelLabClient = class {
|
|
|
3380
3417
|
* guided by an optional concept image and a natural-language color
|
|
3381
3418
|
* palette. A plain background job; unlike `/create-ui-asset` there is no
|
|
3382
3419
|
* piece/element layout, and sizes start at 16px instead of 192. Its
|
|
3383
|
-
* completed shape
|
|
3420
|
+
* completed shape came back as a list of candidates on a live
|
|
3421
|
+
* 32x32 call (64 of them, billed 10); `pollUiElement` still reads it
|
|
3384
3422
|
* defensively.
|
|
3385
3423
|
*/
|
|
3386
3424
|
async generateUiV2(args) {
|
|
@@ -3626,11 +3664,10 @@ var PixelLabClient = class {
|
|
|
3626
3664
|
* no PixelLab character/object resource required — unlike `animateCharacter`
|
|
3627
3665
|
* / `animateObject`, `firstFrame` is whatever bytes the caller has on hand.
|
|
3628
3666
|
* A plain background job, like every other PixelLab async submission;
|
|
3629
|
-
*
|
|
3630
|
-
*
|
|
3631
|
-
*
|
|
3632
|
-
*
|
|
3633
|
-
* defensively, the same as `pollRevision` already does for image edits).
|
|
3667
|
+
* like `inpaintV3`/`editImagesV2`, it has run live (November 2026, a
|
|
3668
|
+
* 64x64 call of 4 frames billed 1 and returned 5 frames); `pollAnimateRevision`
|
|
3669
|
+
* in pixellab.ts still checks several plausible field names for the frame
|
|
3670
|
+
* list defensively, the same as `pollRevision` does for image edits.
|
|
3634
3671
|
*/
|
|
3635
3672
|
async animateWithTextV3(args) {
|
|
3636
3673
|
const body = { first_frame: args.firstFrame, action: args.action };
|
|
@@ -3714,8 +3751,8 @@ var PixelLabClient = class {
|
|
|
3714
3751
|
* `runEstimateSkeleton` in `src/cli/commands`) so the only PixelLab
|
|
3715
3752
|
* endpoint composed into `animate-with-skeleton-v3`'s submission is that
|
|
3716
3753
|
* one endpoint itself, not two unverified calls chained together.
|
|
3717
|
-
* Synchronous
|
|
3718
|
-
*
|
|
3754
|
+
* Synchronous, and it has run live (October 2026; see
|
|
3755
|
+
* `EstimateSkeletonResponseSchema`).
|
|
3719
3756
|
*/
|
|
3720
3757
|
async estimateSkeleton(args) {
|
|
3721
3758
|
const body = { image: { type: "base64", base64: args.image.base64, format: args.image.format } };
|
|
@@ -5627,12 +5664,15 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
5627
5664
|
const width = spec.revision.sourceWidth ?? spec.width;
|
|
5628
5665
|
const height = spec.revision.sourceHeight ?? spec.height;
|
|
5629
5666
|
const side = spec.revision.mode === "edit-animation" ? Math.ceil(Math.sqrt(Math.max(1, spec.revision.sourceMembers?.length ?? 1))) : 1;
|
|
5630
|
-
return { unit: "generations", amount:
|
|
5667
|
+
return { unit: "generations", amount: proTierCost(width * side, height * side), candidates: 1 };
|
|
5631
5668
|
}
|
|
5632
5669
|
if (spec.revision?.mode === "animate" || spec.revision?.mode === "animate-pixminimax") {
|
|
5633
5670
|
const width = spec.revision.sourceWidth ?? spec.width;
|
|
5634
5671
|
const height = spec.revision.sourceHeight ?? spec.height;
|
|
5635
5672
|
const frames = spec.revision.frames ?? 8;
|
|
5673
|
+
if (spec.revision.mode === "animate-pixminimax") {
|
|
5674
|
+
return { unit: "generations", amount: pixMiniMaxCost(width, height, frames, spec.revision.enhancePrompt), candidates: 1 };
|
|
5675
|
+
}
|
|
5636
5676
|
const base = Math.max(1, Math.ceil(width * height * frames / 65536));
|
|
5637
5677
|
return { unit: "generations", amount: spec.revision.enhancePrompt ? base + 0.05 : base, candidates: 1 };
|
|
5638
5678
|
}
|
|
@@ -5663,7 +5703,7 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
5663
5703
|
return {
|
|
5664
5704
|
unit: "generations",
|
|
5665
5705
|
amount: generationCost(spec.width, spec.height, spec.generator),
|
|
5666
|
-
candidates: spec.generator === "1dir" || spec.generator === "imagePro" ? candidateCount(spec.size) : 1
|
|
5706
|
+
candidates: spec.generator === "1dir" || spec.generator === "imagePro" ? candidateCount(spec.size) : spec.generator === "uiElement" ? uiElementCandidateCount(spec.size) : 1
|
|
5667
5707
|
};
|
|
5668
5708
|
}
|
|
5669
5709
|
validate(spec, styleImages) {
|
|
@@ -7351,13 +7391,13 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
7351
7391
|
async pollVfx(jobId, context) {
|
|
7352
7392
|
const dir = _PixelLabProvider.cacheDir("vfx");
|
|
7353
7393
|
const sidecar = import_node_path3.default.join(dir, `${jobId}.json`);
|
|
7354
|
-
const
|
|
7394
|
+
const cached2 = () => {
|
|
7355
7395
|
if (!(0, import_node_fs4.existsSync)(sidecar)) return null;
|
|
7356
7396
|
const facts2 = JSON.parse((0, import_node_fs4.readFileSync)(sidecar, "utf8"));
|
|
7357
7397
|
const files2 = Array.from({ length: facts2.count }, (_, index) => import_node_path3.default.join(dir, `${jobId}-${index}.png`));
|
|
7358
7398
|
return files2.every((file) => (0, import_node_fs4.existsSync)(file)) ? { facts: facts2, files: files2 } : null;
|
|
7359
7399
|
};
|
|
7360
|
-
let found =
|
|
7400
|
+
let found = cached2();
|
|
7361
7401
|
const recorded = context?.metadata?.vfx;
|
|
7362
7402
|
let artistDone;
|
|
7363
7403
|
if (!found && recorded?.artist) {
|
|
@@ -7377,11 +7417,11 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
7377
7417
|
}
|
|
7378
7418
|
artistDone.billed = billedFromUsage(job.usage);
|
|
7379
7419
|
}
|
|
7380
|
-
found =
|
|
7420
|
+
found = cached2();
|
|
7381
7421
|
} else if (!found && recorded?.downloadBase && Array.isArray(recorded.files)) {
|
|
7382
7422
|
const exported = recorded;
|
|
7383
7423
|
await this.cacheVfxFrames(jobId, exported, workbenchVfxUrls(exported));
|
|
7384
|
-
found =
|
|
7424
|
+
found = cached2();
|
|
7385
7425
|
}
|
|
7386
7426
|
if (!found) {
|
|
7387
7427
|
return {
|
|
@@ -7513,15 +7553,15 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
7513
7553
|
* `pollRevision` above, but completing with an ORDERED FRAME LIST instead
|
|
7514
7554
|
* of a single image — the same `review-set` shape `pollCharacterAnimation`
|
|
7515
7555
|
* returns, minus any character/object resource to look the result up on
|
|
7516
|
-
* (there is none; this operates on a loose image).
|
|
7517
|
-
*
|
|
7518
|
-
*
|
|
7519
|
-
*
|
|
7520
|
-
*
|
|
7521
|
-
*
|
|
7522
|
-
*
|
|
7523
|
-
*
|
|
7524
|
-
*
|
|
7556
|
+
* (there is none; this operates on a loose image). Both
|
|
7557
|
+
* `/animate-with-text-v3` and `/animate-pixminimax` have run live
|
|
7558
|
+
* (November 2026) and the completed jobs were read correctly. The checks
|
|
7559
|
+
* below stay defensive (hosted URLs under a plausible key name, the same
|
|
7560
|
+
* `storage_urls.frames` shape character animations use, or inline base64
|
|
7561
|
+
* per frame, decoded to a local cache file the same way `pollRevision`'s
|
|
7562
|
+
* single-image case is) and fail loudly, naming the keys actually
|
|
7563
|
+
* received, if a shape ever differs. PixMiniMax includes the input frame,
|
|
7564
|
+
* so a set holds the requested count plus one.
|
|
7525
7565
|
*/
|
|
7526
7566
|
async pollAnimateRevision(jobId, context) {
|
|
7527
7567
|
const job = await this.client.getBackgroundJob(jobId);
|
|
@@ -7662,7 +7702,7 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
7662
7702
|
}
|
|
7663
7703
|
return {
|
|
7664
7704
|
status: "failed",
|
|
7665
|
-
error: `Invalid PixelLab response for imagePro job ${jobId}: completed with no recognized images array (got: ${Object.keys(done).join(", ") || "no keys"});
|
|
7705
|
+
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`
|
|
7666
7706
|
};
|
|
7667
7707
|
}
|
|
7668
7708
|
/**
|
|
@@ -8579,8 +8619,8 @@ var ScenarioClient = class {
|
|
|
8579
8619
|
async uploadImage(image, projectId) {
|
|
8580
8620
|
const bytes = Buffer.from(image.base64, "base64");
|
|
8581
8621
|
const digest2 = sha256(bytes);
|
|
8582
|
-
const
|
|
8583
|
-
if (
|
|
8622
|
+
const cached2 = readUploadCache()[uploadCacheKey(this.baseUrl, projectId, digest2)];
|
|
8623
|
+
if (cached2) return cached2;
|
|
8584
8624
|
const response = await this.call(
|
|
8585
8625
|
"/assets",
|
|
8586
8626
|
{
|
|
@@ -10270,7 +10310,7 @@ registerProvider({
|
|
|
10270
10310
|
|
|
10271
10311
|
// src/manifest.ts
|
|
10272
10312
|
var import_promises5 = require("fs/promises");
|
|
10273
|
-
var
|
|
10313
|
+
var import_node_fs9 = require("fs");
|
|
10274
10314
|
var import_node_path8 = __toESM(require("path"), 1);
|
|
10275
10315
|
|
|
10276
10316
|
// src/loop-directions.ts
|
|
@@ -10685,10 +10725,31 @@ function frameSetLoop(entry) {
|
|
|
10685
10725
|
return typeof loop === "boolean" ? loop : null;
|
|
10686
10726
|
}
|
|
10687
10727
|
|
|
10728
|
+
// src/version.ts
|
|
10729
|
+
var import_node_fs8 = require("fs");
|
|
10730
|
+
var cached;
|
|
10731
|
+
function pixelkilnVersion() {
|
|
10732
|
+
if (cached !== void 0) return cached;
|
|
10733
|
+
cached = null;
|
|
10734
|
+
for (const up of ["../package.json", "../../package.json"]) {
|
|
10735
|
+
const url = new URL(up, importMetaUrl);
|
|
10736
|
+
if (!(0, import_node_fs8.existsSync)(url)) continue;
|
|
10737
|
+
try {
|
|
10738
|
+
const pkg = JSON.parse((0, import_node_fs8.readFileSync)(url, "utf8"));
|
|
10739
|
+
if (pkg.name === "pixelkiln" && pkg.version) {
|
|
10740
|
+
cached = pkg.version;
|
|
10741
|
+
break;
|
|
10742
|
+
}
|
|
10743
|
+
} catch {
|
|
10744
|
+
}
|
|
10745
|
+
}
|
|
10746
|
+
return cached;
|
|
10747
|
+
}
|
|
10748
|
+
|
|
10688
10749
|
// src/manifest.ts
|
|
10689
10750
|
async function loadManifest(manifestPath) {
|
|
10690
10751
|
const abs = import_node_path8.default.resolve(manifestPath);
|
|
10691
|
-
if (!(0,
|
|
10752
|
+
if (!(0, import_node_fs9.existsSync)(abs)) throw new ProjectError(`No manifest at ${abs}`);
|
|
10692
10753
|
const expansion = expandLoopDirections(JSON.parse(await (0, import_promises5.readFile)(abs, "utf8")));
|
|
10693
10754
|
if (expansion.issues.length) {
|
|
10694
10755
|
throw new ProjectError(`Manifest at ${abs} is invalid:
|
|
@@ -10840,19 +10901,45 @@ function dependencyAssetIds(asset, styleAnchors = []) {
|
|
|
10840
10901
|
].filter((id) => Boolean(id))
|
|
10841
10902
|
];
|
|
10842
10903
|
}
|
|
10904
|
+
var MAX_LISTED_MANIFEST_ISSUES = 20;
|
|
10905
|
+
function flattenManifestIssues(issues) {
|
|
10906
|
+
let unknownShape = false;
|
|
10907
|
+
const visit = (list) => list.flatMap((issue) => {
|
|
10908
|
+
if (issue.code === "invalid_union") return visit(issue.unionErrors.flatMap((error) => error.issues));
|
|
10909
|
+
if (issue.code === "unrecognized_keys" || issue.code === "invalid_enum_value") unknownShape = true;
|
|
10910
|
+
return [` ${issue.path.join(".") || "(manifest)"}: ${issue.message}`];
|
|
10911
|
+
});
|
|
10912
|
+
return { lines: [...new Set(visit(issues))], unknownShape };
|
|
10913
|
+
}
|
|
10843
10914
|
function formatManifestIssues(issues) {
|
|
10844
|
-
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10915
|
+
const { lines, unknownShape } = flattenManifestIssues(issues);
|
|
10916
|
+
const entries = [...new Set(
|
|
10917
|
+
lines.flatMap((line) => {
|
|
10918
|
+
const match = /^ {2}((?:assets|styles)\.[^.:\s]+)/.exec(line);
|
|
10919
|
+
return match ? [match[1]] : [];
|
|
10920
|
+
})
|
|
10921
|
+
)];
|
|
10922
|
+
const out = [];
|
|
10923
|
+
const version = pixelkilnVersion();
|
|
10924
|
+
if (unknownShape) {
|
|
10925
|
+
out.push(
|
|
10926
|
+
` 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.`
|
|
10927
|
+
);
|
|
10928
|
+
}
|
|
10929
|
+
if (entries.length) {
|
|
10930
|
+
out.push(` ${entries.length} invalid entr${entries.length === 1 ? "y" : "ies"}: ${entries.slice(0, 10).join(", ")}${entries.length > 10 ? ", \u2026" : ""}`);
|
|
10931
|
+
}
|
|
10932
|
+
out.push(...lines.slice(0, MAX_LISTED_MANIFEST_ISSUES));
|
|
10933
|
+
if (lines.length > MAX_LISTED_MANIFEST_ISSUES) {
|
|
10934
|
+
out.push(` \u2026 and ${lines.length - MAX_LISTED_MANIFEST_ISSUES} more`);
|
|
10935
|
+
}
|
|
10936
|
+
return out.join("\n");
|
|
10850
10937
|
}
|
|
10851
10938
|
function resolveStyleInheritance(styles) {
|
|
10852
10939
|
const resolved = /* @__PURE__ */ new Map();
|
|
10853
10940
|
const visit = (styleId, chain) => {
|
|
10854
|
-
const
|
|
10855
|
-
if (
|
|
10941
|
+
const cached2 = resolved.get(styleId);
|
|
10942
|
+
if (cached2) return cached2;
|
|
10856
10943
|
const cycleStart = chain.indexOf(styleId);
|
|
10857
10944
|
if (cycleStart >= 0) {
|
|
10858
10945
|
throw new Error(
|
|
@@ -10974,7 +11061,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
10974
11061
|
const abs = import_node_path8.default.resolve(root, rel);
|
|
10975
11062
|
let hit = styleImageCache.get(abs);
|
|
10976
11063
|
if (!hit) {
|
|
10977
|
-
if (!(0,
|
|
11064
|
+
if (!(0, import_node_fs9.existsSync)(abs)) throw new Error(`${what} not found: ${abs}`);
|
|
10978
11065
|
const buf = await (0, import_promises5.readFile)(abs);
|
|
10979
11066
|
const metadata = imageMetadata(buf);
|
|
10980
11067
|
if (!metadata) throw new Error(`${what} is not a readable PNG or JPEG: ${abs}`);
|
|
@@ -11325,7 +11412,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11325
11412
|
const file = memberPath(anchorSpec.outFile, "south", 0, anchorSpec.character.directions, MediaType.PNG);
|
|
11326
11413
|
resolved.character = {
|
|
11327
11414
|
...resolved.character,
|
|
11328
|
-
styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: (0,
|
|
11415
|
+
styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: (0, import_node_fs9.existsSync)(file) ? await sha256File(file) : null }
|
|
11329
11416
|
};
|
|
11330
11417
|
}
|
|
11331
11418
|
const characterParent = asset.state?.of ?? asset.animation?.of ?? asset.portrait?.of;
|
|
@@ -11338,7 +11425,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11338
11425
|
parentAssetId: characterParent,
|
|
11339
11426
|
parentSpec,
|
|
11340
11427
|
parentFile,
|
|
11341
|
-
parentSha256: (0,
|
|
11428
|
+
parentSha256: (0, import_node_fs9.existsSync)(parentFile) ? await sha256File(parentFile) : null,
|
|
11342
11429
|
// A state and its animations keep the engine and rotations of the base.
|
|
11343
11430
|
mode: resolved.character.kind === "base" ? resolved.character.mode : parentSpec.character?.mode ?? resolved.character.mode,
|
|
11344
11431
|
directions: resolved.character.kind === "base" ? resolved.character.directions : parentSpec.character?.directions ?? resolved.character.directions
|
|
@@ -11376,7 +11463,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11376
11463
|
parentAssetId: characterParent,
|
|
11377
11464
|
parentSpec,
|
|
11378
11465
|
parentFile,
|
|
11379
|
-
parentSha256: (0,
|
|
11466
|
+
parentSha256: (0, import_node_fs9.existsSync)(parentFile) ? await sha256File(parentFile) : null,
|
|
11380
11467
|
// A state and its animations keep the base's own rotation count.
|
|
11381
11468
|
directions: resolved.objectPro.kind === "base" ? resolved.objectPro.directions : parentSpec.objectPro.directions
|
|
11382
11469
|
};
|
|
@@ -11580,8 +11667,18 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11580
11667
|
providerOptionIdentity,
|
|
11581
11668
|
providerInputIdentities.get(assetId)
|
|
11582
11669
|
);
|
|
11583
|
-
|
|
11584
|
-
|
|
11670
|
+
let estimate;
|
|
11671
|
+
try {
|
|
11672
|
+
activeProvider.validate?.(resolved, resolvedImages);
|
|
11673
|
+
estimate = validateCostEstimate(activeProvider.id, activeProvider.estimate(resolved));
|
|
11674
|
+
} catch (error) {
|
|
11675
|
+
const message6 = error instanceof Error ? error.message : String(error);
|
|
11676
|
+
if (message6.includes(`assets.${assetId}`)) throw error;
|
|
11677
|
+
throw new Error(
|
|
11678
|
+
`assets.${assetId} (style "${styleId}", ${resolved.width}x${resolved.height}): ${message6}`,
|
|
11679
|
+
{ cause: error }
|
|
11680
|
+
);
|
|
11681
|
+
}
|
|
11585
11682
|
resolved.cost = estimate.amount;
|
|
11586
11683
|
resolved.costUnit = estimate.unit;
|
|
11587
11684
|
resolved.candidates = estimate.candidates;
|
|
@@ -11665,7 +11762,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
11665
11762
|
let recordedSprite;
|
|
11666
11763
|
if (vfx.recipe) {
|
|
11667
11764
|
const file = import_node_path8.default.resolve(root, vfx.recipe);
|
|
11668
|
-
if (!(0,
|
|
11765
|
+
if (!(0, import_node_fs9.existsSync)(file)) throw new Error(`assets.${assetId}.vfx.recipe: VFX recipe not found: ${file}`);
|
|
11669
11766
|
const read = await readVfxRecipe(file).catch((error) => {
|
|
11670
11767
|
throw new Error(`assets.${assetId}.vfx.recipe: ${error instanceof Error ? error.message : String(error)}`);
|
|
11671
11768
|
});
|
|
@@ -11692,7 +11789,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
11692
11789
|
};
|
|
11693
11790
|
}
|
|
11694
11791
|
async function optionalRevisionImage(file, label, requiredFormat) {
|
|
11695
|
-
if (!(0,
|
|
11792
|
+
if (!(0, import_node_fs9.existsSync)(file)) return null;
|
|
11696
11793
|
const bytes = await (0, import_promises5.readFile)(file);
|
|
11697
11794
|
const metadata = imageMetadata(bytes);
|
|
11698
11795
|
if (!metadata) throw new Error(`${label} is not a readable PNG or JPEG: ${file}`);
|
|
@@ -11702,7 +11799,7 @@ async function optionalRevisionImage(file, label, requiredFormat) {
|
|
|
11702
11799
|
return { hash: sha256(bytes), ...metadata };
|
|
11703
11800
|
}
|
|
11704
11801
|
async function optionalSkeletonSet(file) {
|
|
11705
|
-
if (!(0,
|
|
11802
|
+
if (!(0, import_node_fs9.existsSync)(file)) return null;
|
|
11706
11803
|
const bytes = await (0, import_promises5.readFile)(file);
|
|
11707
11804
|
let json;
|
|
11708
11805
|
try {
|
|
@@ -11713,17 +11810,17 @@ async function optionalSkeletonSet(file) {
|
|
|
11713
11810
|
return { hash: sha256(bytes), skeleton: parseSkeletonSet(json, file) };
|
|
11714
11811
|
}
|
|
11715
11812
|
async function revisionSourceMembers(stem, label) {
|
|
11716
|
-
if ((0,
|
|
11813
|
+
if ((0, import_node_fs9.existsSync)(stem)) return null;
|
|
11717
11814
|
const at = (role) => memberPath(stem, role, 0, 2, MediaType.PNG);
|
|
11718
11815
|
let roles = [];
|
|
11719
11816
|
for (const set of [CHARACTER_DIRECTIONS_8, CHARACTER_DIRECTIONS_4]) {
|
|
11720
|
-
if (set.every((direction) => (0,
|
|
11817
|
+
if (set.every((direction) => (0, import_node_fs9.existsSync)(at(direction)))) {
|
|
11721
11818
|
roles = [...set];
|
|
11722
11819
|
break;
|
|
11723
11820
|
}
|
|
11724
11821
|
}
|
|
11725
11822
|
if (!roles.length) {
|
|
11726
|
-
for (let index = 0; (0,
|
|
11823
|
+
for (let index = 0; (0, import_node_fs9.existsSync)(at(`frame-${String(index).padStart(2, "0")}`)); index++) {
|
|
11727
11824
|
roles.push(`frame-${String(index).padStart(2, "0")}`);
|
|
11728
11825
|
}
|
|
11729
11826
|
}
|
|
@@ -11891,7 +11988,7 @@ function characterDirections(directions) {
|
|
|
11891
11988
|
var import_node_path16 = __toESM(require("path"), 1);
|
|
11892
11989
|
|
|
11893
11990
|
// src/env.ts
|
|
11894
|
-
var
|
|
11991
|
+
var import_node_fs10 = require("fs");
|
|
11895
11992
|
var import_node_path9 = __toESM(require("path"), 1);
|
|
11896
11993
|
function loadEnvFiles(dir) {
|
|
11897
11994
|
const loaded = [];
|
|
@@ -11907,9 +12004,9 @@ function envFiles(dir) {
|
|
|
11907
12004
|
const out = [];
|
|
11908
12005
|
for (const name of [".env.local", ".env"]) {
|
|
11909
12006
|
const file = import_node_path9.default.join(dir, name);
|
|
11910
|
-
if (!(0,
|
|
12007
|
+
if (!(0, import_node_fs10.existsSync)(file)) continue;
|
|
11911
12008
|
try {
|
|
11912
|
-
out.push([file, parseEnv((0,
|
|
12009
|
+
out.push([file, parseEnv((0, import_node_fs10.readFileSync)(file, "utf8"))]);
|
|
11913
12010
|
} catch {
|
|
11914
12011
|
}
|
|
11915
12012
|
}
|
|
@@ -11935,7 +12032,7 @@ function parseEnv(contents) {
|
|
|
11935
12032
|
}
|
|
11936
12033
|
|
|
11937
12034
|
// src/pipeline/plan.ts
|
|
11938
|
-
var
|
|
12035
|
+
var import_node_fs13 = require("fs");
|
|
11939
12036
|
var import_node_path15 = __toESM(require("path"), 1);
|
|
11940
12037
|
|
|
11941
12038
|
// src/pipeline/mirror.ts
|
|
@@ -12141,7 +12238,7 @@ async function deriveMirror(spec, lock, lockPath, opts = {}) {
|
|
|
12141
12238
|
}
|
|
12142
12239
|
|
|
12143
12240
|
// src/pipeline/quality-profile.ts
|
|
12144
|
-
var
|
|
12241
|
+
var import_node_fs11 = require("fs");
|
|
12145
12242
|
var import_node_path13 = __toESM(require("path"), 1);
|
|
12146
12243
|
|
|
12147
12244
|
// src/pipeline/refine.ts
|
|
@@ -13124,7 +13221,7 @@ async function qualitySource(spec, lock) {
|
|
|
13124
13221
|
return { items: null, reason: "frame-set quality requires ordered downloaded provider outputs" };
|
|
13125
13222
|
}
|
|
13126
13223
|
const source = import_node_path13.default.resolve(spec.root, spec.source);
|
|
13127
|
-
return (0,
|
|
13224
|
+
return (0, import_node_fs11.existsSync)(source) ? { items: [{ role: "source", path: source }] } : { items: null, reason: `declared source is missing: ${spec.source}` };
|
|
13128
13225
|
}
|
|
13129
13226
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
13130
13227
|
if (!entry) return { items: null, reason: "raw provider output is not in the lockfile" };
|
|
@@ -13153,7 +13250,7 @@ async function qualitySource(spec, lock) {
|
|
|
13153
13250
|
}
|
|
13154
13251
|
if (role) roles.add(role);
|
|
13155
13252
|
const source = currentEntryOutputPath(entry, spec, index);
|
|
13156
|
-
if (!(0,
|
|
13253
|
+
if (!(0, import_node_fs11.existsSync)(source)) return { items: null, reason: `raw provider output is missing: ${source}` };
|
|
13157
13254
|
if (await sha256File(source) !== output.sha256) {
|
|
13158
13255
|
return { items: null, reason: "raw provider output was modified after download" };
|
|
13159
13256
|
}
|
|
@@ -13172,7 +13269,7 @@ async function inspectQualityProfile(spec, lock) {
|
|
|
13172
13269
|
}
|
|
13173
13270
|
const sourcePaths = source.items.map((item) => item.path);
|
|
13174
13271
|
const expectedOutputs = spec.generator === "frames" ? source.items.map((item, index) => qualityFrameOutputPath(output, item.role, index)) : [output];
|
|
13175
|
-
if (!(0,
|
|
13272
|
+
if (!(0, import_node_fs11.existsSync)(record)) {
|
|
13176
13273
|
return {
|
|
13177
13274
|
key,
|
|
13178
13275
|
state: "needs-refinement",
|
|
@@ -13353,7 +13450,7 @@ async function requireApprovedQualitySources(specs, lock, assetIds, outputRoles)
|
|
|
13353
13450
|
}
|
|
13354
13451
|
|
|
13355
13452
|
// src/pipeline/revision.ts
|
|
13356
|
-
var
|
|
13453
|
+
var import_node_fs12 = require("fs");
|
|
13357
13454
|
var import_node_path14 = __toESM(require("path"), 1);
|
|
13358
13455
|
async function inspectRevisionReadiness(spec, lock) {
|
|
13359
13456
|
if (spec.mirror) return inspectMirror(spec, lock, /* @__PURE__ */ new Set());
|
|
@@ -13375,7 +13472,7 @@ async function inspectStyleAnchor(spec, lock, seen) {
|
|
|
13375
13472
|
const label = `style anchor ${spec.styleId}/${anchor.assetId}`;
|
|
13376
13473
|
const dependency = await inspectParent(anchor.spec, lock, seen);
|
|
13377
13474
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13378
|
-
if (!anchor.sha256 || !(0,
|
|
13475
|
+
if (!anchor.sha256 || !(0, import_node_fs12.existsSync)(anchor.file)) return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13379
13476
|
if (await sha256File(anchor.file) !== anchor.sha256) {
|
|
13380
13477
|
return { ready: false, reason: `${label} changed after the manifest was resolved` };
|
|
13381
13478
|
}
|
|
@@ -13412,14 +13509,14 @@ async function inspectScene(spec) {
|
|
|
13412
13509
|
const files = [{ label: "scene image", file: scene.file, sha256: scene.sha256 }];
|
|
13413
13510
|
if (scene.placement.type === "mask") files.push({ label: "scene mask", file: scene.placement.file, sha256: scene.placement.sha256 });
|
|
13414
13511
|
for (const { label, file, sha256: sha2562 } of files) {
|
|
13415
|
-
if (!sha2562 || !(0,
|
|
13512
|
+
if (!sha2562 || !(0, import_node_fs12.existsSync)(file)) return { ready: false, reason: `${label} does not exist yet: ${file}` };
|
|
13416
13513
|
if (await sha256File(file) !== sha2562) return { ready: false, reason: `${label} changed after the manifest was resolved` };
|
|
13417
13514
|
}
|
|
13418
13515
|
return { ready: true, reason: "scene is current" };
|
|
13419
13516
|
}
|
|
13420
13517
|
async function inspectVfxSprite(spec) {
|
|
13421
13518
|
const sprite = spec.vfx.sprite;
|
|
13422
|
-
if (!sprite.sha256 || !(0,
|
|
13519
|
+
if (!sprite.sha256 || !(0, import_node_fs12.existsSync)(sprite.file)) return { ready: false, reason: `vfx sprite does not exist yet: ${sprite.file}` };
|
|
13423
13520
|
if (await sha256File(sprite.file) !== sprite.sha256) return { ready: false, reason: "vfx sprite changed after the manifest was resolved" };
|
|
13424
13521
|
return { ready: true, reason: "vfx sprite is current" };
|
|
13425
13522
|
}
|
|
@@ -13435,7 +13532,7 @@ async function inspectOutfit(spec, lock, seen) {
|
|
|
13435
13532
|
const label = `outfit source ${spec.styleId}/${character.parentAssetId}`;
|
|
13436
13533
|
const dependency = await inspectParent(character.parentSpec, lock, seen);
|
|
13437
13534
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13438
|
-
if (!(0,
|
|
13535
|
+
if (!(0, import_node_fs12.existsSync)(outfit.reference.path)) {
|
|
13439
13536
|
return { ready: false, reason: `outfit reference is missing: ${outfit.reference.path}` };
|
|
13440
13537
|
}
|
|
13441
13538
|
if (await sha256File(outfit.reference.path) !== outfit.reference.sha256) {
|
|
@@ -13449,7 +13546,7 @@ async function inspectCharacterParent(spec, lock, seen) {
|
|
|
13449
13546
|
const label = `${character.kind} parent ${spec.styleId}/${character.parentAssetId}`;
|
|
13450
13547
|
const dependency = await inspectParent(parentSpec, lock, seen);
|
|
13451
13548
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13452
|
-
if (!character.parentSha256 || !character.parentFile || !(0,
|
|
13549
|
+
if (!character.parentSha256 || !character.parentFile || !(0, import_node_fs12.existsSync)(character.parentFile)) {
|
|
13453
13550
|
return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13454
13551
|
}
|
|
13455
13552
|
if (await sha256File(character.parentFile) !== character.parentSha256) {
|
|
@@ -13467,7 +13564,7 @@ async function inspectObjectProParent(spec, lock, seen) {
|
|
|
13467
13564
|
const label = `${object.kind} parent ${spec.styleId}/${object.parentAssetId}`;
|
|
13468
13565
|
const dependency = await inspectParent(parentSpec, lock, seen);
|
|
13469
13566
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13470
|
-
if (!object.parentSha256 || !object.parentFile || !(0,
|
|
13567
|
+
if (!object.parentSha256 || !object.parentFile || !(0, import_node_fs12.existsSync)(object.parentFile)) {
|
|
13471
13568
|
return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13472
13569
|
}
|
|
13473
13570
|
if (await sha256File(object.parentFile) !== object.parentSha256) {
|
|
@@ -13493,7 +13590,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13493
13590
|
const members = await inspectSourceMembers(spec, lock);
|
|
13494
13591
|
if (!members.ready) return members;
|
|
13495
13592
|
} else {
|
|
13496
|
-
if (!revision.sourceSha256 || !(0,
|
|
13593
|
+
if (!revision.sourceSha256 || !(0, import_node_fs12.existsSync)(revision.sourceFile)) {
|
|
13497
13594
|
return { ready: false, reason: `revision source is missing: ${revision.sourceFile}` };
|
|
13498
13595
|
}
|
|
13499
13596
|
if (await sha256File(revision.sourceFile) !== revision.sourceSha256) {
|
|
@@ -13501,7 +13598,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13501
13598
|
}
|
|
13502
13599
|
}
|
|
13503
13600
|
if (revision.maskFile) {
|
|
13504
|
-
if (!revision.maskSha256 || !(0,
|
|
13601
|
+
if (!revision.maskSha256 || !(0, import_node_fs12.existsSync)(revision.maskFile)) {
|
|
13505
13602
|
return { ready: false, reason: `revision mask is missing: ${revision.maskFile}` };
|
|
13506
13603
|
}
|
|
13507
13604
|
if (await sha256File(revision.maskFile) !== revision.maskSha256) {
|
|
@@ -13509,7 +13606,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13509
13606
|
}
|
|
13510
13607
|
}
|
|
13511
13608
|
if (revision.lastFrameFile) {
|
|
13512
|
-
if (!revision.lastFrameSha256 || !(0,
|
|
13609
|
+
if (!revision.lastFrameSha256 || !(0, import_node_fs12.existsSync)(revision.lastFrameFile)) {
|
|
13513
13610
|
return { ready: false, reason: `revision last frame is missing: ${revision.lastFrameFile}` };
|
|
13514
13611
|
}
|
|
13515
13612
|
if (await sha256File(revision.lastFrameFile) !== revision.lastFrameSha256) {
|
|
@@ -13522,7 +13619,7 @@ async function inspectSourceMembers(spec, lock) {
|
|
|
13522
13619
|
const revision = spec.revision;
|
|
13523
13620
|
const members = revision.sourceMembers;
|
|
13524
13621
|
for (const member of members) {
|
|
13525
|
-
if (!(0,
|
|
13622
|
+
if (!(0, import_node_fs12.existsSync)(member.file)) return { ready: false, reason: `revision source member is missing: ${member.file}` };
|
|
13526
13623
|
if (await sha256File(member.file) !== member.sha256) {
|
|
13527
13624
|
return { ready: false, reason: `revision source member changed after the manifest was resolved: ${member.file}` };
|
|
13528
13625
|
}
|
|
@@ -13590,7 +13687,7 @@ async function inspectParent(spec, lock, seen) {
|
|
|
13590
13687
|
}
|
|
13591
13688
|
if (spec.source) {
|
|
13592
13689
|
const source = import_node_path14.default.resolve(spec.root, spec.source);
|
|
13593
|
-
return (0,
|
|
13690
|
+
return (0, import_node_fs12.existsSync)(source) ? { ready: true, reason: "declared source is present" } : { ready: false, reason: `declared source is missing: ${spec.source}` };
|
|
13594
13691
|
}
|
|
13595
13692
|
const entry = lock.entries[key];
|
|
13596
13693
|
if (!entry) return { ready: false, reason: "parent is not in the lockfile" };
|
|
@@ -13604,7 +13701,7 @@ async function inspectParent(spec, lock, seen) {
|
|
|
13604
13701
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
13605
13702
|
const output = entry.outputs[index];
|
|
13606
13703
|
const file = currentEntryOutputPath(entry, spec, index);
|
|
13607
|
-
if (!(0,
|
|
13704
|
+
if (!(0, import_node_fs12.existsSync)(file)) return { ready: false, reason: `parent output is missing: ${file}` };
|
|
13608
13705
|
if (await sha256File(file) !== output.sha256) {
|
|
13609
13706
|
return { ready: false, reason: `parent output was modified: ${file}` };
|
|
13610
13707
|
}
|
|
@@ -13699,7 +13796,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13699
13796
|
state = "missing";
|
|
13700
13797
|
reason = "--force";
|
|
13701
13798
|
} else if (!entry && spec.source && spec.generator !== "frames" && spec.generator !== "vfx") {
|
|
13702
|
-
if ((0,
|
|
13799
|
+
if ((0, import_node_fs13.existsSync)(import_node_path15.default.resolve(spec.root, spec.source))) {
|
|
13703
13800
|
state = "ok";
|
|
13704
13801
|
reason = `placed from ${spec.source}; not generated`;
|
|
13705
13802
|
} else {
|
|
@@ -13707,7 +13804,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13707
13804
|
reason = `declared source is missing: ${spec.source}`;
|
|
13708
13805
|
}
|
|
13709
13806
|
} else if (!entry) {
|
|
13710
|
-
if ((0,
|
|
13807
|
+
if ((0, import_node_fs13.existsSync)(spec.outFile)) {
|
|
13711
13808
|
state = "untracked";
|
|
13712
13809
|
reason = "file on disk, no provenance recorded";
|
|
13713
13810
|
} else {
|
|
@@ -13720,7 +13817,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13720
13817
|
} else if (spec.mirror && !mirrorCurrent(entry, lock.entries[lockKey(spec.styleId, spec.mirror.sourceAssetId)])) {
|
|
13721
13818
|
state = "stale";
|
|
13722
13819
|
reason = `mirror source ${spec.mirror.sourceAssetId} changed; flip it again (no generation cost)`;
|
|
13723
|
-
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !(0,
|
|
13820
|
+
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !(0, import_node_fs13.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
|
|
13724
13821
|
state = "stale";
|
|
13725
13822
|
reason = "mirror output missing on disk; flip it again (no generation cost)";
|
|
13726
13823
|
} else if (spec.character?.kind === "outfit" && entry.outfit?.sourceSha256 !== mirrorSourceHash(lock.entries[lockKey(spec.styleId, spec.character.parentAssetId)] ?? { outputs: [] })) {
|
|
@@ -13757,9 +13854,9 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13757
13854
|
} else if (entry.status !== "downloaded") {
|
|
13758
13855
|
state = "in-flight";
|
|
13759
13856
|
reason = `awaiting ${entry.status}`;
|
|
13760
|
-
} else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !(0,
|
|
13857
|
+
} else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !(0, import_node_fs13.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
|
|
13761
13858
|
state = "orphaned";
|
|
13762
|
-
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !(0,
|
|
13859
|
+
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !(0, import_node_fs13.existsSync)(currentEntryOutputPath(entry, spec, index))).map((o) => o.role ?? "asset").join(", ")}`;
|
|
13763
13860
|
} else if (await anyOutputModified(entry, spec)) {
|
|
13764
13861
|
state = "orphaned";
|
|
13765
13862
|
reason = "output modified since download";
|
|
@@ -13895,7 +13992,7 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
|
|
|
13895
13992
|
|
|
13896
13993
|
// src/recipes.ts
|
|
13897
13994
|
var import_node_path17 = __toESM(require("path"), 1);
|
|
13898
|
-
var
|
|
13995
|
+
var import_node_fs14 = require("fs");
|
|
13899
13996
|
var import_promises9 = require("fs/promises");
|
|
13900
13997
|
var import_node_url = require("url");
|
|
13901
13998
|
var import_zod4 = require("zod");
|
|
@@ -14098,7 +14195,7 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
14098
14195
|
return { recipe: parsed.data, authored: raw, path: absolute, dir: import_node_path17.default.dirname(absolute), bundled };
|
|
14099
14196
|
}
|
|
14100
14197
|
async function walkRecipeFiles(root) {
|
|
14101
|
-
if (!(0,
|
|
14198
|
+
if (!(0, import_node_fs14.existsSync)(root)) return [];
|
|
14102
14199
|
const out = [];
|
|
14103
14200
|
for (const entry of await (0, import_promises9.readdir)(root, { withFileTypes: true })) {
|
|
14104
14201
|
const resolved = import_node_path17.default.join(root, entry.name);
|
|
@@ -14136,7 +14233,7 @@ function parseSelector(selector) {
|
|
|
14136
14233
|
}
|
|
14137
14234
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
14138
14235
|
const local = import_node_path17.default.resolve(target);
|
|
14139
|
-
if ((0,
|
|
14236
|
+
if ((0, import_node_fs14.existsSync)(local)) {
|
|
14140
14237
|
const recipePath = import_node_path17.default.basename(local) === RECIPE_FILE ? local : import_node_path17.default.join(local, RECIPE_FILE);
|
|
14141
14238
|
return readRecipeFile(recipePath, false);
|
|
14142
14239
|
}
|
|
@@ -14152,7 +14249,7 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
14152
14249
|
}
|
|
14153
14250
|
async function verifyFile(root, file) {
|
|
14154
14251
|
const absolute = import_node_path17.default.resolve(root, ...file.path.split("/"));
|
|
14155
|
-
if (!(0,
|
|
14252
|
+
if (!(0, import_node_fs14.existsSync)(absolute)) {
|
|
14156
14253
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
14157
14254
|
}
|
|
14158
14255
|
const actualSha256 = await sha256File(absolute);
|
|
@@ -14230,7 +14327,7 @@ async function installRecipe(target, options = {}) {
|
|
|
14230
14327
|
})));
|
|
14231
14328
|
if (!options.force) {
|
|
14232
14329
|
for (const file of files) {
|
|
14233
|
-
if (!(0,
|
|
14330
|
+
if (!(0, import_node_fs14.existsSync)(file.path)) continue;
|
|
14234
14331
|
const current = await (0, import_promises9.readFile)(file.path);
|
|
14235
14332
|
if (!current.equals(file.data)) {
|
|
14236
14333
|
throw new OverwriteRefusedError(
|
|
@@ -14256,7 +14353,7 @@ async function installRecipe(target, options = {}) {
|
|
|
14256
14353
|
|
|
14257
14354
|
// src/pipeline/audit.ts
|
|
14258
14355
|
var import_promises10 = require("fs/promises");
|
|
14259
|
-
var
|
|
14356
|
+
var import_node_fs15 = require("fs");
|
|
14260
14357
|
var import_node_path18 = __toESM(require("path"), 1);
|
|
14261
14358
|
function paletteDistance(asset, reference) {
|
|
14262
14359
|
if (!asset.length || !reference.length) return 0;
|
|
@@ -14293,7 +14390,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
14293
14390
|
const unreadable = [];
|
|
14294
14391
|
for (const spec of mine) {
|
|
14295
14392
|
for (const output of resolveSpecOutputs(spec, lock, loaded.root)) {
|
|
14296
|
-
if (!(0,
|
|
14393
|
+
if (!(0, import_node_fs15.existsSync)(output.absolutePath)) {
|
|
14297
14394
|
missing.push(output.id);
|
|
14298
14395
|
continue;
|
|
14299
14396
|
}
|
|
@@ -14323,7 +14420,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
14323
14420
|
const refPalettes = [];
|
|
14324
14421
|
for (const img of style.styleImages) {
|
|
14325
14422
|
const abs = import_node_path18.default.resolve(loaded.root, img.path);
|
|
14326
|
-
if (!(0,
|
|
14423
|
+
if (!(0, import_node_fs15.existsSync)(abs)) continue;
|
|
14327
14424
|
try {
|
|
14328
14425
|
refPalettes.push(extractPalette(decodePng(await (0, import_promises10.readFile)(abs)), 12));
|
|
14329
14426
|
} catch {
|
|
@@ -14402,7 +14499,7 @@ function hex(c) {
|
|
|
14402
14499
|
|
|
14403
14500
|
// src/pipeline/quality-regression.ts
|
|
14404
14501
|
var import_node_path19 = __toESM(require("path"), 1);
|
|
14405
|
-
var
|
|
14502
|
+
var import_node_fs16 = require("fs");
|
|
14406
14503
|
var import_promises11 = require("fs/promises");
|
|
14407
14504
|
var import_zod5 = require("zod");
|
|
14408
14505
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
@@ -14645,7 +14742,7 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14645
14742
|
cases
|
|
14646
14743
|
});
|
|
14647
14744
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
14648
|
-
if ((0,
|
|
14745
|
+
if ((0, import_node_fs16.existsSync)(absolute) && !options.force) {
|
|
14649
14746
|
const current = await (0, import_promises11.readFile)(absolute);
|
|
14650
14747
|
if (!current.equals(data)) {
|
|
14651
14748
|
throw new OverwriteRefusedError(
|
|
@@ -14657,6 +14754,63 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14657
14754
|
const result = await writeArtifactBundle([{ path: absolute, data }]);
|
|
14658
14755
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
14659
14756
|
}
|
|
14757
|
+
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
14758
|
+
const absolute = import_node_path19.default.resolve(baselinePath);
|
|
14759
|
+
if (!(0, import_node_fs16.existsSync)(absolute)) {
|
|
14760
|
+
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
14761
|
+
}
|
|
14762
|
+
let raw;
|
|
14763
|
+
try {
|
|
14764
|
+
raw = JSON.parse(await (0, import_promises11.readFile)(absolute, "utf8"));
|
|
14765
|
+
} catch (error) {
|
|
14766
|
+
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
14767
|
+
}
|
|
14768
|
+
if (!Array.isArray(raw.cases)) throw new Error(`Quality baseline ${absolute} has no cases array.`);
|
|
14769
|
+
const byId = new Map(inputs.map((input) => [input.id, input]));
|
|
14770
|
+
const unknown = only.filter((id) => !byId.has(id));
|
|
14771
|
+
if (unknown.length) {
|
|
14772
|
+
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
14773
|
+
}
|
|
14774
|
+
const root = import_node_path19.default.dirname(absolute);
|
|
14775
|
+
const cases = [...raw.cases];
|
|
14776
|
+
const report = [];
|
|
14777
|
+
for (const id of only) {
|
|
14778
|
+
const input = byId.get(id);
|
|
14779
|
+
if (import_node_path19.default.resolve(input.file) === absolute || input.record && import_node_path19.default.resolve(input.record) === absolute) {
|
|
14780
|
+
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
14781
|
+
}
|
|
14782
|
+
const expected = await measureImageQuality(input.file);
|
|
14783
|
+
let record;
|
|
14784
|
+
if (input.record) {
|
|
14785
|
+
await verifyRecordForImage(input.record, input.file);
|
|
14786
|
+
record = { path: portableRelative2(root, input.record), sha256: await sha256File(input.record) };
|
|
14787
|
+
}
|
|
14788
|
+
const index = cases.findIndex((entry) => entry.id === id);
|
|
14789
|
+
const before = index >= 0 ? cases[index].expected ?? {} : {};
|
|
14790
|
+
const next = {
|
|
14791
|
+
id,
|
|
14792
|
+
file: portableRelative2(root, input.file),
|
|
14793
|
+
...record ? { record } : {},
|
|
14794
|
+
expected,
|
|
14795
|
+
tolerances: index >= 0 && cases[index].tolerances ? cases[index].tolerances : input.tolerances
|
|
14796
|
+
};
|
|
14797
|
+
if (index >= 0) cases[index] = next;
|
|
14798
|
+
else cases.push(next);
|
|
14799
|
+
const changes = [];
|
|
14800
|
+
for (const metric of Object.keys(expected)) {
|
|
14801
|
+
if (JSON.stringify(before[metric]) !== JSON.stringify(expected[metric])) {
|
|
14802
|
+
changes.push({ metric, before: before[metric] ?? null, after: expected[metric] });
|
|
14803
|
+
}
|
|
14804
|
+
}
|
|
14805
|
+
report.push({ id, kind: index < 0 ? "added" : changes.length ? "updated" : "unchanged", changes });
|
|
14806
|
+
}
|
|
14807
|
+
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
14808
|
+
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
14809
|
+
const current = await (0, import_promises11.readFile)(absolute);
|
|
14810
|
+
const changed = !current.equals(data);
|
|
14811
|
+
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
14812
|
+
return { baseline, path: absolute, changed, cases: report };
|
|
14813
|
+
}
|
|
14660
14814
|
async function readQualityBaseline(baselinePath) {
|
|
14661
14815
|
const absolute = import_node_path19.default.resolve(baselinePath);
|
|
14662
14816
|
let raw;
|
|
@@ -14667,9 +14821,23 @@ async function readQualityBaseline(baselinePath) {
|
|
|
14667
14821
|
}
|
|
14668
14822
|
const parsed = QualityBaselineSchema.safeParse(raw);
|
|
14669
14823
|
if (!parsed.success) {
|
|
14824
|
+
const cases = raw?.cases;
|
|
14825
|
+
const where = (issuePath) => {
|
|
14826
|
+
if (issuePath[0] === "cases" && typeof issuePath[1] === "number") {
|
|
14827
|
+
const id = cases?.[issuePath[1]]?.id;
|
|
14828
|
+
const rest = issuePath.slice(2).join(".");
|
|
14829
|
+
return typeof id === "string" ? `cases[${id}]${rest ? `.${rest}` : ""}` : issuePath.join(".");
|
|
14830
|
+
}
|
|
14831
|
+
return issuePath.join(".") || "$";
|
|
14832
|
+
};
|
|
14833
|
+
const missing = [...new Set(parsed.error.issues.flatMap((issue) => {
|
|
14834
|
+
const id = issue.path[0] === "cases" && typeof issue.path[1] === "number" ? cases?.[issue.path[1]]?.id : void 0;
|
|
14835
|
+
return issue.code === "invalid_type" && issue.received === "undefined" && typeof id === "string" ? [id] : [];
|
|
14836
|
+
}))];
|
|
14670
14837
|
throw new Error(
|
|
14671
14838
|
`Invalid quality baseline ${absolute}:
|
|
14672
|
-
` + parsed.error.issues.map((issue) => ` ${issue.path
|
|
14839
|
+
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
14840
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${import_node_path19.default.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
14673
14841
|
);
|
|
14674
14842
|
}
|
|
14675
14843
|
return parsed.data;
|
|
@@ -14785,13 +14953,13 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
14785
14953
|
}
|
|
14786
14954
|
|
|
14787
14955
|
// src/pipeline/cache-health.ts
|
|
14788
|
-
var
|
|
14956
|
+
var import_node_fs20 = require("fs");
|
|
14789
14957
|
var import_promises14 = require("fs/promises");
|
|
14790
14958
|
var import_node_path23 = __toESM(require("path"), 1);
|
|
14791
14959
|
|
|
14792
14960
|
// src/cache.ts
|
|
14793
14961
|
var import_promises12 = require("fs/promises");
|
|
14794
|
-
var
|
|
14962
|
+
var import_node_fs17 = require("fs");
|
|
14795
14963
|
var import_node_path20 = __toESM(require("path"), 1);
|
|
14796
14964
|
var import_zod6 = require("zod");
|
|
14797
14965
|
var HashCacheSchema = import_zod6.z.object({
|
|
@@ -14807,7 +14975,7 @@ function parseCache(value) {
|
|
|
14807
14975
|
return HashCacheSchema.parse(value);
|
|
14808
14976
|
}
|
|
14809
14977
|
async function loadCache(path39) {
|
|
14810
|
-
if (!(0,
|
|
14978
|
+
if (!(0, import_node_fs17.existsSync)(path39)) return { version: 1, hashes: {} };
|
|
14811
14979
|
try {
|
|
14812
14980
|
const parsed = HashCacheSchema.safeParse(JSON.parse(await (0, import_promises12.readFile)(path39, "utf8")));
|
|
14813
14981
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
@@ -14856,11 +15024,11 @@ function cachePathFor(lockPath) {
|
|
|
14856
15024
|
}
|
|
14857
15025
|
|
|
14858
15026
|
// src/pipeline/history.ts
|
|
14859
|
-
var
|
|
15027
|
+
var import_node_fs19 = require("fs");
|
|
14860
15028
|
var import_node_path22 = __toESM(require("path"), 1);
|
|
14861
15029
|
|
|
14862
15030
|
// src/pipeline/fetch.ts
|
|
14863
|
-
var
|
|
15031
|
+
var import_node_fs18 = require("fs");
|
|
14864
15032
|
var import_promises13 = require("fs/promises");
|
|
14865
15033
|
var import_node_path21 = __toESM(require("path"), 1);
|
|
14866
15034
|
async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
@@ -14880,15 +15048,15 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14880
15048
|
if (spec && e.specHash === spec.specHash && e.outputs.length && !postprocessCurrent(e, spec)) {
|
|
14881
15049
|
return Boolean(opts.force) || e.outputs.every((output) => {
|
|
14882
15050
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14883
|
-
return (0,
|
|
15051
|
+
return (0, import_node_fs18.existsSync)(file) && sha256((0, import_node_fs18.readFileSync)(file)) === output.sha256;
|
|
14884
15052
|
});
|
|
14885
15053
|
}
|
|
14886
15054
|
if (!opts.repair) return false;
|
|
14887
15055
|
if (e.outputs.length === 0 || !spec) return true;
|
|
14888
15056
|
return e.outputs.some((output) => {
|
|
14889
15057
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14890
|
-
if (!(0,
|
|
14891
|
-
const current = sha256((0,
|
|
15058
|
+
if (!(0, import_node_fs18.existsSync)(file)) return true;
|
|
15059
|
+
const current = sha256((0, import_node_fs18.readFileSync)(file));
|
|
14892
15060
|
if (current === output.sha256) return false;
|
|
14893
15061
|
return Boolean(opts.force) || (e.supersededOutputs ?? []).some((old) => old.sha256 === current);
|
|
14894
15062
|
});
|
|
@@ -14978,7 +15146,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14978
15146
|
}
|
|
14979
15147
|
let raw = null;
|
|
14980
15148
|
let final = null;
|
|
14981
|
-
if ((0,
|
|
15149
|
+
if ((0, import_node_fs18.existsSync)(target)) {
|
|
14982
15150
|
const currentHash = await sha256File(target);
|
|
14983
15151
|
if (recorded && currentHash === recorded.sha256) {
|
|
14984
15152
|
if (!fresh && !reapply) {
|
|
@@ -15124,7 +15292,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
15124
15292
|
}
|
|
15125
15293
|
async function readCachedMedia(cacheDir, hash, mediaType) {
|
|
15126
15294
|
const file = import_node_path21.default.join(cacheDir, cacheFileName(hash, mediaType));
|
|
15127
|
-
if (!(0,
|
|
15295
|
+
if (!(0, import_node_fs18.existsSync)(file)) return null;
|
|
15128
15296
|
try {
|
|
15129
15297
|
const buf = await (0, import_promises13.readFile)(file);
|
|
15130
15298
|
if (sha256(buf) !== hash) return null;
|
|
@@ -15145,7 +15313,7 @@ async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
|
|
|
15145
15313
|
try {
|
|
15146
15314
|
await (0, import_promises13.rename)(tmp, file);
|
|
15147
15315
|
} catch (err) {
|
|
15148
|
-
if (!(0,
|
|
15316
|
+
if (!(0, import_node_fs18.existsSync)(file)) throw err;
|
|
15149
15317
|
} finally {
|
|
15150
15318
|
await (0, import_promises13.rm)(tmp, { force: true });
|
|
15151
15319
|
}
|
|
@@ -15267,7 +15435,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
15267
15435
|
}
|
|
15268
15436
|
for (let i = 0; i < entry.outputs.length; i++) {
|
|
15269
15437
|
const file = currentEntryOutputPath(entry, spec, i);
|
|
15270
|
-
if (!(0,
|
|
15438
|
+
if (!(0, import_node_fs19.existsSync)(file)) continue;
|
|
15271
15439
|
if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
|
|
15272
15440
|
throw new OverwriteRefusedError(
|
|
15273
15441
|
`${import_node_path22.default.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
|
|
@@ -15330,7 +15498,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
15330
15498
|
|
|
15331
15499
|
// src/pipeline/cache-health.ts
|
|
15332
15500
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
15333
|
-
if (options.prune && !(0,
|
|
15501
|
+
if (options.prune && !(0, import_node_fs20.existsSync)(lockPath)) {
|
|
15334
15502
|
throw new Error(`Refusing to prune without an existing lockfile at ${import_node_path23.default.resolve(lockPath)}`);
|
|
15335
15503
|
}
|
|
15336
15504
|
const contentDir = import_node_path23.default.resolve(import_node_path23.default.dirname(lockPath), ".pixelkiln", "cache");
|
|
@@ -15373,7 +15541,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
15373
15541
|
async function inspectContentCache(contentDir, referenced) {
|
|
15374
15542
|
const report = {
|
|
15375
15543
|
path: contentDir,
|
|
15376
|
-
exists: (0,
|
|
15544
|
+
exists: (0, import_node_fs20.existsSync)(contentDir),
|
|
15377
15545
|
files: 0,
|
|
15378
15546
|
bytes: 0,
|
|
15379
15547
|
valid: 0,
|
|
@@ -15437,7 +15605,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
15437
15605
|
async function inspectRemoteHashCache(remotePath) {
|
|
15438
15606
|
const report = {
|
|
15439
15607
|
path: remotePath,
|
|
15440
|
-
exists: (0,
|
|
15608
|
+
exists: (0, import_node_fs20.existsSync)(remotePath),
|
|
15441
15609
|
entries: 0,
|
|
15442
15610
|
valid: 0,
|
|
15443
15611
|
invalidIds: [],
|
|
@@ -15461,7 +15629,7 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
15461
15629
|
}
|
|
15462
15630
|
|
|
15463
15631
|
// src/pipeline/pack.ts
|
|
15464
|
-
var
|
|
15632
|
+
var import_node_fs21 = require("fs");
|
|
15465
15633
|
var import_node_path24 = __toESM(require("path"), 1);
|
|
15466
15634
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
15467
15635
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
@@ -15495,7 +15663,7 @@ function packSprites(inputs, options = {}) {
|
|
|
15495
15663
|
for (const input of ordered) {
|
|
15496
15664
|
let sourceHash = null;
|
|
15497
15665
|
try {
|
|
15498
|
-
const bytes = (0,
|
|
15666
|
+
const bytes = (0, import_node_fs21.readFileSync)(input.path);
|
|
15499
15667
|
sourceHash = sha256(bytes);
|
|
15500
15668
|
const png = decodePng(bytes);
|
|
15501
15669
|
sprites.push({ id: input.id, width: png.width, height: png.height, pixels: png.pixels });
|
|
@@ -15654,7 +15822,7 @@ function mountSprites(placements, options) {
|
|
|
15654
15822
|
for (const p of placements) {
|
|
15655
15823
|
let sourceHash = null;
|
|
15656
15824
|
try {
|
|
15657
|
-
const bytes = (0,
|
|
15825
|
+
const bytes = (0, import_node_fs21.readFileSync)(p.path);
|
|
15658
15826
|
sourceHash = sha256(bytes);
|
|
15659
15827
|
const png = decodePng(bytes);
|
|
15660
15828
|
if (png.width > cellWidth || png.height > cellHeight) {
|
|
@@ -15758,7 +15926,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
15758
15926
|
`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}`
|
|
15759
15927
|
);
|
|
15760
15928
|
}
|
|
15761
|
-
const basePng = mount.base ? (0,
|
|
15929
|
+
const basePng = mount.base ? (0, import_node_fs21.readFileSync)(import_node_path24.default.resolve(manifestDir, mount.base)) : void 0;
|
|
15762
15930
|
const mounted = mountSprites(placements, {
|
|
15763
15931
|
cellWidth: mount.cellWidth,
|
|
15764
15932
|
cellHeight: mount.cellHeight,
|
|
@@ -16612,7 +16780,7 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
16612
16780
|
}
|
|
16613
16781
|
|
|
16614
16782
|
// src/pipeline/doctor.ts
|
|
16615
|
-
var
|
|
16783
|
+
var import_node_fs22 = require("fs");
|
|
16616
16784
|
var import_promises15 = require("fs/promises");
|
|
16617
16785
|
var import_node_path25 = __toESM(require("path"), 1);
|
|
16618
16786
|
async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
@@ -16632,7 +16800,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16632
16800
|
for (const dir of dirs) {
|
|
16633
16801
|
const ancestor = await nearestExistingDirectory(dir);
|
|
16634
16802
|
try {
|
|
16635
|
-
await (0, import_promises15.access)(ancestor,
|
|
16803
|
+
await (0, import_promises15.access)(ancestor, import_node_fs22.constants.W_OK);
|
|
16636
16804
|
} catch {
|
|
16637
16805
|
unwritable.push(dir);
|
|
16638
16806
|
}
|
|
@@ -16680,11 +16848,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16680
16848
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
16681
16849
|
let hasCache = false;
|
|
16682
16850
|
for (const output of entry.outputs) {
|
|
16683
|
-
const
|
|
16851
|
+
const cached2 = import_node_path25.default.join(
|
|
16684
16852
|
cacheDir,
|
|
16685
16853
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
16686
16854
|
);
|
|
16687
|
-
if ((0,
|
|
16855
|
+
if ((0, import_node_fs22.existsSync)(cached2) && await sha256File(cached2) === output.sha256) {
|
|
16688
16856
|
hasCache = true;
|
|
16689
16857
|
break;
|
|
16690
16858
|
}
|
|
@@ -16787,7 +16955,7 @@ async function nearestExistingDirectory(start) {
|
|
|
16787
16955
|
}
|
|
16788
16956
|
|
|
16789
16957
|
// src/pipeline/adopt.ts
|
|
16790
|
-
var
|
|
16958
|
+
var import_node_fs23 = require("fs");
|
|
16791
16959
|
var import_promises16 = require("fs/promises");
|
|
16792
16960
|
var import_node_path26 = __toESM(require("path"), 1);
|
|
16793
16961
|
async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
@@ -16800,7 +16968,7 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
16800
16968
|
const localByHash = /* @__PURE__ */ new Map();
|
|
16801
16969
|
const unmatchedLocal = [];
|
|
16802
16970
|
for (const spec of specs) {
|
|
16803
|
-
if (!(0,
|
|
16971
|
+
if (!(0, import_node_fs23.existsSync)(spec.outFile)) {
|
|
16804
16972
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
16805
16973
|
continue;
|
|
16806
16974
|
}
|
|
@@ -16921,13 +17089,124 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
16921
17089
|
return count;
|
|
16922
17090
|
}
|
|
16923
17091
|
|
|
16924
|
-
// src/
|
|
17092
|
+
// src/pipeline/import.ts
|
|
16925
17093
|
var import_node_fs24 = require("fs");
|
|
16926
|
-
var
|
|
17094
|
+
var import_promises17 = require("fs/promises");
|
|
17095
|
+
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
17096
|
+
const png = decodePng(bytes);
|
|
17097
|
+
const at = now.toISOString();
|
|
17098
|
+
return {
|
|
17099
|
+
styleId: spec.styleId,
|
|
17100
|
+
assetId: spec.assetId,
|
|
17101
|
+
specHash: spec.specHash,
|
|
17102
|
+
generator: spec.generator,
|
|
17103
|
+
prompt: spec.prompt,
|
|
17104
|
+
width: png.width,
|
|
17105
|
+
height: png.height,
|
|
17106
|
+
jobId: opts.objectId ?? null,
|
|
17107
|
+
objectId: opts.objectId ?? null,
|
|
17108
|
+
reviewObjectId: null,
|
|
17109
|
+
candidateIndex: null,
|
|
17110
|
+
status: "downloaded",
|
|
17111
|
+
error: null,
|
|
17112
|
+
sourceUrl: null,
|
|
17113
|
+
sourceUrls: [],
|
|
17114
|
+
outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
|
|
17115
|
+
submittedAt: null,
|
|
17116
|
+
downloadedAt: at,
|
|
17117
|
+
cost: 0,
|
|
17118
|
+
costUnit: spec.costUnit,
|
|
17119
|
+
provider: spec.provider,
|
|
17120
|
+
imported: {
|
|
17121
|
+
source: opts.source ?? "external",
|
|
17122
|
+
...opts.note ? { note: opts.note } : {},
|
|
17123
|
+
importedAt: at
|
|
17124
|
+
}
|
|
17125
|
+
};
|
|
17126
|
+
}
|
|
17127
|
+
function unimportable(spec) {
|
|
17128
|
+
if (spec.character) return "a character is several files; import it with account adopt";
|
|
17129
|
+
if (spec.vfx) return "an effect is rendered from its recipe, not imported";
|
|
17130
|
+
if (!spec.outFile.toLowerCase().endsWith(".png")) return "only a single PNG output can be imported";
|
|
17131
|
+
return null;
|
|
17132
|
+
}
|
|
17133
|
+
async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
17134
|
+
if (opts.objectId && specs.length !== 1) {
|
|
17135
|
+
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
17136
|
+
}
|
|
17137
|
+
const imported = [];
|
|
17138
|
+
const skipped = [];
|
|
17139
|
+
for (const spec of specs) {
|
|
17140
|
+
const key = lockKey(spec.styleId, spec.assetId);
|
|
17141
|
+
const reason = unimportable(spec);
|
|
17142
|
+
if (reason) {
|
|
17143
|
+
skipped.push({ key, reason });
|
|
17144
|
+
continue;
|
|
17145
|
+
}
|
|
17146
|
+
if (!(0, import_node_fs24.existsSync)(spec.outFile)) {
|
|
17147
|
+
skipped.push({ key, reason: `no file at ${spec.outFile}` });
|
|
17148
|
+
continue;
|
|
17149
|
+
}
|
|
17150
|
+
if (lock.entries[key] && !opts.force) {
|
|
17151
|
+
skipped.push({ key, reason: "already in the lockfile (use --force to replace it)" });
|
|
17152
|
+
continue;
|
|
17153
|
+
}
|
|
17154
|
+
let patch;
|
|
17155
|
+
try {
|
|
17156
|
+
patch = buildImportedEntry(spec, await (0, import_promises17.readFile)(spec.outFile), opts);
|
|
17157
|
+
} catch (error) {
|
|
17158
|
+
skipped.push({ key, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
17159
|
+
continue;
|
|
17160
|
+
}
|
|
17161
|
+
if (opts.dryRun) {
|
|
17162
|
+
imported.push({ key, entry: patch });
|
|
17163
|
+
continue;
|
|
17164
|
+
}
|
|
17165
|
+
imported.push({ key, entry: upsert(lock, key, patch) });
|
|
17166
|
+
}
|
|
17167
|
+
if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
|
|
17168
|
+
return { imported, skipped };
|
|
17169
|
+
}
|
|
17170
|
+
async function reportSpecHashes(specs, lock) {
|
|
17171
|
+
const reports = [];
|
|
17172
|
+
for (const spec of specs) {
|
|
17173
|
+
const key = lockKey(spec.styleId, spec.assetId);
|
|
17174
|
+
let bytes = null;
|
|
17175
|
+
if ((0, import_node_fs24.existsSync)(spec.outFile)) bytes = await (0, import_promises17.readFile)(spec.outFile);
|
|
17176
|
+
let wouldImport = null;
|
|
17177
|
+
if (bytes && !unimportable(spec)) {
|
|
17178
|
+
try {
|
|
17179
|
+
wouldImport = buildImportedEntry(spec, bytes);
|
|
17180
|
+
} catch {
|
|
17181
|
+
wouldImport = null;
|
|
17182
|
+
}
|
|
17183
|
+
}
|
|
17184
|
+
const entry = lock.entries[key];
|
|
17185
|
+
const fileSha256 = bytes ? sha256(bytes) : null;
|
|
17186
|
+
const outputSha256 = entry?.outputs[0]?.sha256 ?? null;
|
|
17187
|
+
reports.push({
|
|
17188
|
+
key,
|
|
17189
|
+
specHash: spec.specHash,
|
|
17190
|
+
file: spec.outFile,
|
|
17191
|
+
fileSha256,
|
|
17192
|
+
lock: entry ? {
|
|
17193
|
+
specHash: entry.specHash,
|
|
17194
|
+
outputSha256,
|
|
17195
|
+
matches: entry.specHash === spec.specHash && outputSha256 !== null && outputSha256 === fileSha256
|
|
17196
|
+
} : null,
|
|
17197
|
+
wouldImport
|
|
17198
|
+
});
|
|
17199
|
+
}
|
|
17200
|
+
return reports;
|
|
17201
|
+
}
|
|
17202
|
+
|
|
17203
|
+
// src/pick/server.ts
|
|
17204
|
+
var import_node_fs26 = require("fs");
|
|
17205
|
+
var import_promises20 = require("fs/promises");
|
|
16927
17206
|
|
|
16928
17207
|
// src/pipeline/init.ts
|
|
16929
|
-
var
|
|
16930
|
-
var
|
|
17208
|
+
var import_promises18 = require("fs/promises");
|
|
17209
|
+
var import_node_fs25 = require("fs");
|
|
16931
17210
|
var import_node_path27 = __toESM(require("path"), 1);
|
|
16932
17211
|
function pngSize(buf) {
|
|
16933
17212
|
if (buf.length < 24) return null;
|
|
@@ -16941,7 +17220,7 @@ function slugify(value) {
|
|
|
16941
17220
|
}
|
|
16942
17221
|
async function walk(dir, exclude) {
|
|
16943
17222
|
const out = [];
|
|
16944
|
-
for (const entry of await (0,
|
|
17223
|
+
for (const entry of await (0, import_promises18.readdir)(dir, { withFileTypes: true })) {
|
|
16945
17224
|
const full = import_node_path27.default.join(dir, entry.name);
|
|
16946
17225
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
16947
17226
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
@@ -16956,7 +17235,7 @@ async function scanAssets(root, opts = {}) {
|
|
|
16956
17235
|
const skipped = [];
|
|
16957
17236
|
const seen = /* @__PURE__ */ new Map();
|
|
16958
17237
|
for (const file of files.sort()) {
|
|
16959
|
-
const size = pngSize(await (0,
|
|
17238
|
+
const size = pngSize(await (0, import_promises18.readFile)(file));
|
|
16960
17239
|
if (!size) {
|
|
16961
17240
|
skipped.push(`${file} (not a readable PNG)`);
|
|
16962
17241
|
continue;
|
|
@@ -17437,7 +17716,7 @@ document.getElementById('submit').onclick = async () => {
|
|
|
17437
17716
|
|
|
17438
17717
|
// src/pick/review-server.ts
|
|
17439
17718
|
var import_node_http = require("http");
|
|
17440
|
-
var
|
|
17719
|
+
var import_promises19 = require("fs/promises");
|
|
17441
17720
|
function serveReviewPage(opts) {
|
|
17442
17721
|
const log = opts.onProgress ?? (() => {
|
|
17443
17722
|
});
|
|
@@ -17446,7 +17725,7 @@ function serveReviewPage(opts) {
|
|
|
17446
17725
|
if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
|
|
17447
17726
|
try {
|
|
17448
17727
|
const asset = opts.assets.get(req.url);
|
|
17449
|
-
const bytes = await (0,
|
|
17728
|
+
const bytes = await (0, import_promises19.readFile)(asset.path);
|
|
17450
17729
|
res.writeHead(200, {
|
|
17451
17730
|
"Content-Type": asset.contentType,
|
|
17452
17731
|
"Cache-Control": "no-store",
|
|
@@ -17522,13 +17801,13 @@ async function currentArt(entry, spec) {
|
|
|
17522
17801
|
const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
|
|
17523
17802
|
if (!previous) return null;
|
|
17524
17803
|
const file = resolveOutputPath(previous.path, spec.root);
|
|
17525
|
-
if (!(0,
|
|
17804
|
+
if (!(0, import_node_fs26.existsSync)(file)) return null;
|
|
17526
17805
|
const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
|
|
17527
17806
|
if (!contentType) return null;
|
|
17528
17807
|
let width = entry.width;
|
|
17529
17808
|
let height = entry.height;
|
|
17530
17809
|
if (contentType === "image/png") {
|
|
17531
|
-
const size = pngSize(await (0,
|
|
17810
|
+
const size = pngSize(await (0, import_promises20.readFile)(file));
|
|
17532
17811
|
if (size) ({ width, height } = size);
|
|
17533
17812
|
}
|
|
17534
17813
|
return { path: file, contentType, width, height };
|
|
@@ -17536,7 +17815,7 @@ async function currentArt(entry, spec) {
|
|
|
17536
17815
|
async function cachedFrame(url) {
|
|
17537
17816
|
if (!url.startsWith("file://")) return null;
|
|
17538
17817
|
const file = url.slice("file://".length);
|
|
17539
|
-
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await (0,
|
|
17818
|
+
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await (0, import_promises20.readFile)(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
|
|
17540
17819
|
return { path: file, contentType };
|
|
17541
17820
|
}
|
|
17542
17821
|
async function prepareReview(provider, lock, opts = {}) {
|
|
@@ -17562,15 +17841,15 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17562
17841
|
const frameAssets = [];
|
|
17563
17842
|
const frameSizes = [];
|
|
17564
17843
|
for (const [index, url] of urls.entries()) {
|
|
17565
|
-
const
|
|
17566
|
-
if (!
|
|
17844
|
+
const cached2 = await cachedFrame(url);
|
|
17845
|
+
if (!cached2) {
|
|
17567
17846
|
frameUrls.push(url);
|
|
17568
17847
|
frameSizes.push(null);
|
|
17569
17848
|
continue;
|
|
17570
17849
|
}
|
|
17571
|
-
frameSizes.push(
|
|
17850
|
+
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await (0, import_promises20.readFile)(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
17572
17851
|
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
17573
|
-
frameAssets.push([route,
|
|
17852
|
+
frameAssets.push([route, cached2]);
|
|
17574
17853
|
frameUrls.push(route);
|
|
17575
17854
|
}
|
|
17576
17855
|
const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String(groups.length))}` : null;
|
|
@@ -17722,13 +18001,13 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
17722
18001
|
|
|
17723
18002
|
// src/gallery/snapshot.ts
|
|
17724
18003
|
var import_node_crypto7 = require("crypto");
|
|
17725
|
-
var
|
|
17726
|
-
var
|
|
18004
|
+
var import_node_fs32 = require("fs");
|
|
18005
|
+
var import_promises28 = require("fs/promises");
|
|
17727
18006
|
var import_node_path35 = __toESM(require("path"), 1);
|
|
17728
18007
|
|
|
17729
18008
|
// src/workspace.ts
|
|
17730
|
-
var
|
|
17731
|
-
var
|
|
18009
|
+
var import_promises21 = require("fs/promises");
|
|
18010
|
+
var import_node_fs27 = require("fs");
|
|
17732
18011
|
var import_node_path28 = __toESM(require("path"), 1);
|
|
17733
18012
|
var import_zod7 = require("zod");
|
|
17734
18013
|
var WorkspaceProjectSchema = import_zod7.z.object({
|
|
@@ -17754,10 +18033,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
|
|
|
17754
18033
|
);
|
|
17755
18034
|
}
|
|
17756
18035
|
async function loadWorkspace(workspacePath) {
|
|
17757
|
-
if (!(0,
|
|
18036
|
+
if (!(0, import_node_fs27.existsSync)(workspacePath)) return { version: 1, projects: [] };
|
|
17758
18037
|
let raw;
|
|
17759
18038
|
try {
|
|
17760
|
-
raw = JSON.parse(await (0,
|
|
18039
|
+
raw = JSON.parse(await (0, import_promises21.readFile)(workspacePath, "utf8"));
|
|
17761
18040
|
} catch (err) {
|
|
17762
18041
|
throw new ProjectError(
|
|
17763
18042
|
`Workspace catalog at ${workspacePath} is malformed:
|
|
@@ -17771,13 +18050,13 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
17771
18050
|
version: 1,
|
|
17772
18051
|
projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
|
|
17773
18052
|
};
|
|
17774
|
-
await (0,
|
|
18053
|
+
await (0, import_promises21.mkdir)(import_node_path28.default.dirname(import_node_path28.default.resolve(workspacePath)), { recursive: true });
|
|
17775
18054
|
const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
17776
18055
|
try {
|
|
17777
|
-
await (0,
|
|
17778
|
-
await (0,
|
|
18056
|
+
await (0, import_promises21.writeFile)(tmp, JSON.stringify(sorted, null, 2) + "\n");
|
|
18057
|
+
await (0, import_promises21.rename)(tmp, workspacePath);
|
|
17779
18058
|
} finally {
|
|
17780
|
-
await (0,
|
|
18059
|
+
await (0, import_promises21.rm)(tmp, { force: true });
|
|
17781
18060
|
}
|
|
17782
18061
|
}
|
|
17783
18062
|
function toPortablePath(dir, absolute) {
|
|
@@ -17806,14 +18085,14 @@ function validateWorkspace(ws, dir) {
|
|
|
17806
18085
|
message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
|
|
17807
18086
|
});
|
|
17808
18087
|
}
|
|
17809
|
-
if (!(0,
|
|
18088
|
+
if (!(0, import_node_fs27.existsSync)(manifestPath)) {
|
|
17810
18089
|
diagnostics.push({
|
|
17811
18090
|
id: "missing-manifest",
|
|
17812
18091
|
level: "error",
|
|
17813
18092
|
message: `project "${project.id}" manifest not found: ${manifestPath}`
|
|
17814
18093
|
});
|
|
17815
18094
|
}
|
|
17816
|
-
if (!(0,
|
|
18095
|
+
if (!(0, import_node_fs27.existsSync)(lockPath)) {
|
|
17817
18096
|
diagnostics.push({
|
|
17818
18097
|
id: "missing-lock",
|
|
17819
18098
|
level: "error",
|
|
@@ -17860,12 +18139,12 @@ function validateWorkspace(ws, dir) {
|
|
|
17860
18139
|
}
|
|
17861
18140
|
|
|
17862
18141
|
// src/gallery/edit.ts
|
|
17863
|
-
var
|
|
18142
|
+
var import_promises27 = require("fs/promises");
|
|
17864
18143
|
var import_node_path34 = __toESM(require("path"), 1);
|
|
17865
18144
|
var import_zod13 = require("zod");
|
|
17866
18145
|
|
|
17867
18146
|
// src/manifest-edit.ts
|
|
17868
|
-
var
|
|
18147
|
+
var import_promises22 = require("fs/promises");
|
|
17869
18148
|
var import_node_path29 = __toESM(require("path"), 1);
|
|
17870
18149
|
var import_zod8 = require("zod");
|
|
17871
18150
|
var HexSha = import_zod8.z.string().regex(/^[0-9a-f]{64}$/);
|
|
@@ -18290,7 +18569,7 @@ function applyEdit(raw, edit) {
|
|
|
18290
18569
|
}
|
|
18291
18570
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
18292
18571
|
const absolute = import_node_path29.default.resolve(manifestPath);
|
|
18293
|
-
const original = await (0,
|
|
18572
|
+
const original = await (0, import_promises22.readFile)(absolute, "utf8");
|
|
18294
18573
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
18295
18574
|
let raw;
|
|
18296
18575
|
try {
|
|
@@ -18308,7 +18587,7 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
18308
18587
|
`.${import_node_path29.default.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
|
|
18309
18588
|
);
|
|
18310
18589
|
try {
|
|
18311
|
-
await (0,
|
|
18590
|
+
await (0, import_promises22.writeFile)(tmp, next);
|
|
18312
18591
|
let specs;
|
|
18313
18592
|
try {
|
|
18314
18593
|
specs = await resolveSpecs(await loadManifest(tmp));
|
|
@@ -18318,7 +18597,7 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
18318
18597
|
}
|
|
18319
18598
|
return await use({ absolute, original, next, tmp, specs });
|
|
18320
18599
|
} finally {
|
|
18321
|
-
await (0,
|
|
18600
|
+
await (0, import_promises22.rm)(tmp, { force: true });
|
|
18322
18601
|
}
|
|
18323
18602
|
}
|
|
18324
18603
|
async function applyManifestEdit(manifestPath, edit) {
|
|
@@ -18326,7 +18605,7 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
18326
18605
|
manifestPath,
|
|
18327
18606
|
edit,
|
|
18328
18607
|
async ({ absolute, next, tmp }) => {
|
|
18329
|
-
await (0,
|
|
18608
|
+
await (0, import_promises22.rename)(tmp, absolute);
|
|
18330
18609
|
return { manifestPath: absolute, sha256: sha256(next), changed: true };
|
|
18331
18610
|
},
|
|
18332
18611
|
(absolute, original) => ({ manifestPath: absolute, sha256: sha256(original), changed: false })
|
|
@@ -18334,8 +18613,8 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
18334
18613
|
}
|
|
18335
18614
|
|
|
18336
18615
|
// src/pipeline/hand-edit.ts
|
|
18337
|
-
var
|
|
18338
|
-
var
|
|
18616
|
+
var import_node_fs28 = require("fs");
|
|
18617
|
+
var import_promises23 = require("fs/promises");
|
|
18339
18618
|
var import_node_path30 = __toESM(require("path"), 1);
|
|
18340
18619
|
var import_zod9 = require("zod");
|
|
18341
18620
|
var HAND_EDIT_DIR = "edits";
|
|
@@ -18358,10 +18637,10 @@ function handEditBases(spec, lock) {
|
|
|
18358
18637
|
}));
|
|
18359
18638
|
if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
|
|
18360
18639
|
if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
|
|
18361
|
-
if (!members.every((member) => (0,
|
|
18640
|
+
if (!members.every((member) => (0, import_node_fs28.existsSync)(member.path))) return null;
|
|
18362
18641
|
return members.map(({ role, path: file }) => ({ role, path: file }));
|
|
18363
18642
|
}
|
|
18364
|
-
return (0,
|
|
18643
|
+
return (0, import_node_fs28.existsSync)(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
|
|
18365
18644
|
}
|
|
18366
18645
|
function handEditBase(spec, lock) {
|
|
18367
18646
|
const bases = handEditBases(spec, lock);
|
|
@@ -18396,14 +18675,14 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
18396
18675
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
18397
18676
|
let created = false;
|
|
18398
18677
|
for (const member of members) {
|
|
18399
|
-
if ((0,
|
|
18678
|
+
if ((0, import_node_fs28.existsSync)(member.path)) continue;
|
|
18400
18679
|
if (!member.base) {
|
|
18401
18680
|
throw new ManifestEditError(
|
|
18402
18681
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
18403
18682
|
);
|
|
18404
18683
|
}
|
|
18405
|
-
await (0,
|
|
18406
|
-
await (0,
|
|
18684
|
+
await (0, import_promises23.mkdir)(import_node_path30.default.dirname(member.path), { recursive: true });
|
|
18685
|
+
await (0, import_promises23.copyFile)(member.base, member.path);
|
|
18407
18686
|
created = true;
|
|
18408
18687
|
}
|
|
18409
18688
|
const source = portableOutputPath(editPath, loaded.root);
|
|
@@ -18481,7 +18760,7 @@ function handEditProjectPath(editPath) {
|
|
|
18481
18760
|
async function readHandEditCompanion(editPath) {
|
|
18482
18761
|
let text;
|
|
18483
18762
|
try {
|
|
18484
|
-
text = await (0,
|
|
18763
|
+
text = await (0, import_promises23.readFile)(handEditCompanionPath(editPath), "utf8");
|
|
18485
18764
|
} catch {
|
|
18486
18765
|
return null;
|
|
18487
18766
|
}
|
|
@@ -18524,7 +18803,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
18524
18803
|
}
|
|
18525
18804
|
});
|
|
18526
18805
|
const bases = handEditBases(spec, lock);
|
|
18527
|
-
const expectedSize = bases?.[0] ? decodePng(await (0,
|
|
18806
|
+
const expectedSize = bases?.[0] ? decodePng(await (0, import_promises23.readFile)(bases[0].path)) : { width: spec.width, height: spec.height };
|
|
18528
18807
|
for (const [index, image] of decoded.entries()) {
|
|
18529
18808
|
if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
|
|
18530
18809
|
const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
|
|
@@ -18570,10 +18849,10 @@ function basedOnHash(entry, index) {
|
|
|
18570
18849
|
async function replaceFile(file, bytes) {
|
|
18571
18850
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18572
18851
|
try {
|
|
18573
|
-
await (0,
|
|
18574
|
-
await (0,
|
|
18852
|
+
await (0, import_promises23.writeFile)(tmp, bytes);
|
|
18853
|
+
await (0, import_promises23.rename)(tmp, file);
|
|
18575
18854
|
} finally {
|
|
18576
|
-
await (0,
|
|
18855
|
+
await (0, import_promises23.rm)(tmp, { force: true });
|
|
18577
18856
|
}
|
|
18578
18857
|
}
|
|
18579
18858
|
function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
@@ -18582,8 +18861,8 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
18582
18861
|
}
|
|
18583
18862
|
|
|
18584
18863
|
// src/gallery/upload.ts
|
|
18585
|
-
var
|
|
18586
|
-
var
|
|
18864
|
+
var import_node_fs29 = require("fs");
|
|
18865
|
+
var import_promises24 = require("fs/promises");
|
|
18587
18866
|
var import_node_path31 = __toESM(require("path"), 1);
|
|
18588
18867
|
var import_zod10 = require("zod");
|
|
18589
18868
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
@@ -18614,17 +18893,17 @@ async function saveProjectImage(root, request) {
|
|
|
18614
18893
|
if (metadata.format !== expected) {
|
|
18615
18894
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
18616
18895
|
}
|
|
18617
|
-
if ((0,
|
|
18896
|
+
if ((0, import_node_fs29.existsSync)(file) && !request.overwrite) {
|
|
18618
18897
|
throw new ManifestEditError(`${relative.split(import_node_path31.default.sep).join("/")} already exists; choose another name, or replace it`);
|
|
18619
18898
|
}
|
|
18620
|
-
await (0,
|
|
18621
|
-
await (0,
|
|
18899
|
+
await (0, import_promises24.mkdir)(import_node_path31.default.dirname(file), { recursive: true });
|
|
18900
|
+
await (0, import_promises24.writeFile)(file, bytes);
|
|
18622
18901
|
return relative.split(import_node_path31.default.sep).join("/");
|
|
18623
18902
|
}
|
|
18624
18903
|
|
|
18625
18904
|
// src/gallery/image-revision.ts
|
|
18626
|
-
var
|
|
18627
|
-
var
|
|
18905
|
+
var import_node_fs30 = require("fs");
|
|
18906
|
+
var import_promises25 = require("fs/promises");
|
|
18628
18907
|
var import_node_path32 = __toESM(require("path"), 1);
|
|
18629
18908
|
var import_zod11 = require("zod");
|
|
18630
18909
|
var InpaintRevisionRequestSchema = import_zod11.z.object({
|
|
@@ -18652,7 +18931,7 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
18652
18931
|
const metadata = imageMetadata(bytes);
|
|
18653
18932
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
18654
18933
|
const file = import_node_path32.default.resolve(root, request.maskPath);
|
|
18655
|
-
const previous = (0,
|
|
18934
|
+
const previous = (0, import_node_fs30.existsSync)(file) ? await (0, import_promises25.readFile)(file) : null;
|
|
18656
18935
|
const mask = await saveProjectImage(root, {
|
|
18657
18936
|
action: "upload-image",
|
|
18658
18937
|
path: request.maskPath,
|
|
@@ -18671,16 +18950,16 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
18671
18950
|
}
|
|
18672
18951
|
});
|
|
18673
18952
|
} catch (error) {
|
|
18674
|
-
if (previous) await (0,
|
|
18675
|
-
else await (0,
|
|
18953
|
+
if (previous) await (0, import_promises25.writeFile)(file, previous);
|
|
18954
|
+
else await (0, import_promises25.rm)(file, { force: true });
|
|
18676
18955
|
throw error;
|
|
18677
18956
|
}
|
|
18678
18957
|
return mask;
|
|
18679
18958
|
}
|
|
18680
18959
|
|
|
18681
18960
|
// src/gallery/skeleton.ts
|
|
18682
|
-
var
|
|
18683
|
-
var
|
|
18961
|
+
var import_node_fs31 = require("fs");
|
|
18962
|
+
var import_promises26 = require("fs/promises");
|
|
18684
18963
|
var import_node_path33 = __toESM(require("path"), 1);
|
|
18685
18964
|
var import_zod12 = require("zod");
|
|
18686
18965
|
var SkeletonEstimateRequestSchema = import_zod12.z.object({
|
|
@@ -18726,15 +19005,15 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
18726
19005
|
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || import_node_path33.default.isAbsolute(relative)) {
|
|
18727
19006
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
18728
19007
|
}
|
|
18729
|
-
const existed = (0,
|
|
19008
|
+
const existed = (0, import_node_fs31.existsSync)(file);
|
|
18730
19009
|
let previous = null;
|
|
18731
19010
|
if (request.set) {
|
|
18732
19011
|
if (existed && !request.overwrite) {
|
|
18733
19012
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
18734
19013
|
}
|
|
18735
|
-
if (existed) previous = await (0,
|
|
18736
|
-
await (0,
|
|
18737
|
-
await (0,
|
|
19014
|
+
if (existed) previous = await (0, import_promises26.readFile)(file);
|
|
19015
|
+
await (0, import_promises26.mkdir)(import_node_path33.default.dirname(file), { recursive: true });
|
|
19016
|
+
await (0, import_promises26.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18738
19017
|
} else if (!existed) {
|
|
18739
19018
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
18740
19019
|
}
|
|
@@ -18758,8 +19037,8 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
18758
19037
|
});
|
|
18759
19038
|
} catch (error) {
|
|
18760
19039
|
if (request.set) {
|
|
18761
|
-
if (previous) await (0,
|
|
18762
|
-
else await (0,
|
|
19040
|
+
if (previous) await (0, import_promises26.writeFile)(file, previous);
|
|
19041
|
+
else await (0, import_promises26.rm)(file, { force: true });
|
|
18763
19042
|
}
|
|
18764
19043
|
throw error;
|
|
18765
19044
|
}
|
|
@@ -18774,14 +19053,14 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
18774
19053
|
if (relative.startsWith("..") || import_node_path33.default.isAbsolute(relative)) {
|
|
18775
19054
|
throw new ManifestEditError(`${key}'s keypoints file is outside the project; edit it by hand`);
|
|
18776
19055
|
}
|
|
18777
|
-
const current = (0,
|
|
19056
|
+
const current = (0, import_node_fs31.existsSync)(file) ? sha256(await (0, import_promises26.readFile)(file)) : null;
|
|
18778
19057
|
if (current !== request.expectedSha256) {
|
|
18779
19058
|
throw Object.assign(
|
|
18780
19059
|
new Error(`${relative.split(import_node_path33.default.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
18781
19060
|
{ status: 409 }
|
|
18782
19061
|
);
|
|
18783
19062
|
}
|
|
18784
|
-
await (0,
|
|
19063
|
+
await (0, import_promises26.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18785
19064
|
return relative.split(import_node_path33.default.sep).join("/");
|
|
18786
19065
|
}
|
|
18787
19066
|
|
|
@@ -18846,7 +19125,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18846
19125
|
if (undo.success) {
|
|
18847
19126
|
const manifestPath2 = await manifestOf(undo.data.project);
|
|
18848
19127
|
if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
|
|
18849
|
-
const current = await (0,
|
|
19128
|
+
const current = await (0, import_promises27.readFile)(manifestPath2, "utf8");
|
|
18850
19129
|
if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
|
|
18851
19130
|
const stack = history.get(manifestPath2) ?? [];
|
|
18852
19131
|
const last = stack[stack.length - 1];
|
|
@@ -18856,17 +19135,17 @@ function createGalleryEditHandler(opts) {
|
|
|
18856
19135
|
throw Object.assign(new Error("the manifest changed outside the gallery since its last edit; undo would discard that change"), { status: 409 });
|
|
18857
19136
|
}
|
|
18858
19137
|
const tmp = manifestPath2 + ".pixelkiln-undo";
|
|
18859
|
-
await (0,
|
|
18860
|
-
await (0,
|
|
19138
|
+
await (0, import_promises27.writeFile)(tmp, last.before);
|
|
19139
|
+
await (0, import_promises27.rename)(tmp, manifestPath2);
|
|
18861
19140
|
stack.pop();
|
|
18862
19141
|
log(` manifest edit undone in ${import_node_path34.default.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
18863
19142
|
return opts.reload();
|
|
18864
19143
|
}
|
|
18865
19144
|
const manifestPath = await manifestOf(body?.project);
|
|
18866
|
-
const before = manifestPath ? await (0,
|
|
19145
|
+
const before = manifestPath ? await (0, import_promises27.readFile)(manifestPath, "utf8").catch(() => null) : null;
|
|
18867
19146
|
const build = await apply(body);
|
|
18868
19147
|
if (manifestPath && before !== null) {
|
|
18869
|
-
const after = await (0,
|
|
19148
|
+
const after = await (0, import_promises27.readFile)(manifestPath, "utf8").catch(() => null);
|
|
18870
19149
|
if (after !== null && after !== before) {
|
|
18871
19150
|
const stack = history.get(manifestPath) ?? [];
|
|
18872
19151
|
stack.push({ before, afterSha: sha256(after) });
|
|
@@ -19042,7 +19321,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
19042
19321
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
19043
19322
|
const file = import_node_path35.default.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
19044
19323
|
let url = null;
|
|
19045
|
-
if ((0,
|
|
19324
|
+
if ((0, import_node_fs32.existsSync)(file)) {
|
|
19046
19325
|
const id = galleryMediaId(file);
|
|
19047
19326
|
media.set(id, { path: file, contentType: mediaType });
|
|
19048
19327
|
url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
|
|
@@ -19074,7 +19353,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
19074
19353
|
var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
|
|
19075
19354
|
async function samePixels(a, b) {
|
|
19076
19355
|
try {
|
|
19077
|
-
const [left, right] = await Promise.all([(0,
|
|
19356
|
+
const [left, right] = await Promise.all([(0, import_promises28.readFile)(a), (0, import_promises28.readFile)(b)]);
|
|
19078
19357
|
if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
|
|
19079
19358
|
const x = decodePng(left);
|
|
19080
19359
|
const y = decodePng(right);
|
|
@@ -19140,7 +19419,7 @@ function describeCharacter(spec, entry) {
|
|
|
19140
19419
|
}
|
|
19141
19420
|
async function fileInfo(absolutePath) {
|
|
19142
19421
|
try {
|
|
19143
|
-
const info = await (0,
|
|
19422
|
+
const info = await (0, import_promises28.stat)(absolutePath);
|
|
19144
19423
|
return info.isFile() ? { bytes: info.size, modifiedAt: info.mtime.toISOString() } : null;
|
|
19145
19424
|
} catch {
|
|
19146
19425
|
return null;
|
|
@@ -19175,7 +19454,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
19175
19454
|
outputPaths.map((file) => describeOutput(media, root, import_node_path35.default.resolve(root, file)))
|
|
19176
19455
|
);
|
|
19177
19456
|
const recordPath = import_node_path35.default.resolve(root, inspection.record);
|
|
19178
|
-
const recordExists = (0,
|
|
19457
|
+
const recordExists = (0, import_node_fs32.existsSync)(recordPath);
|
|
19179
19458
|
let options = null;
|
|
19180
19459
|
let check = null;
|
|
19181
19460
|
if (recordExists) {
|
|
@@ -19232,7 +19511,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19232
19511
|
const media = /* @__PURE__ */ new Map();
|
|
19233
19512
|
const plan = await buildPlan(specs, lock);
|
|
19234
19513
|
const items = [];
|
|
19235
|
-
const manifestText = await (0,
|
|
19514
|
+
const manifestText = await (0, import_promises28.readFile)(loaded.path, "utf8");
|
|
19236
19515
|
const manifestSha256 = sha256(manifestText);
|
|
19237
19516
|
const cacheDir = import_node_path35.default.resolve(import_node_path35.default.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
19238
19517
|
let rawStyles = {};
|
|
@@ -19263,7 +19542,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19263
19542
|
const editShas = await Promise.all(
|
|
19264
19543
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
19265
19544
|
const file = sourceOutputPath(spec.source, entry, index, root);
|
|
19266
|
-
return { file, sha256: (0,
|
|
19545
|
+
return { file, sha256: (0, import_node_fs32.existsSync)(file) ? await sha256File(file) : null };
|
|
19267
19546
|
})
|
|
19268
19547
|
);
|
|
19269
19548
|
edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
|
|
@@ -19271,7 +19550,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19271
19550
|
const companion = await readHandEditCompanion(editPath);
|
|
19272
19551
|
if (companion) {
|
|
19273
19552
|
const projectPath = handEditProjectPath(editPath);
|
|
19274
|
-
const project = companion.project && (0,
|
|
19553
|
+
const project = companion.project && (0, import_node_fs32.existsSync)(projectPath) ? await fileInfo(projectPath) : null;
|
|
19275
19554
|
let projectUrl = null;
|
|
19276
19555
|
if (project) {
|
|
19277
19556
|
const id = galleryMediaId(projectPath);
|
|
@@ -19308,7 +19587,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19308
19587
|
}
|
|
19309
19588
|
} else if (spec.source) {
|
|
19310
19589
|
outputs = [await describeOutput(media, root, import_node_path35.default.resolve(root, spec.source))];
|
|
19311
|
-
} else if (!entry && (0,
|
|
19590
|
+
} else if (!entry && (0, import_node_fs32.existsSync)(spec.outFile)) {
|
|
19312
19591
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
19313
19592
|
} else {
|
|
19314
19593
|
outputs = [];
|
|
@@ -19585,7 +19864,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19585
19864
|
root: loaded.root,
|
|
19586
19865
|
provider: loaded.manifest.provider,
|
|
19587
19866
|
account: project.account ?? null,
|
|
19588
|
-
manifestSha256: manifestSha256 ?? sha256(await (0,
|
|
19867
|
+
manifestSha256: manifestSha256 ?? sha256(await (0, import_promises28.readFile)(manifestPath, "utf8")),
|
|
19589
19868
|
historyLimit: historyLimit(loaded.manifest),
|
|
19590
19869
|
entries: Object.keys(lock.entries).length,
|
|
19591
19870
|
items: projectItems.length,
|
|
@@ -19642,7 +19921,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19642
19921
|
}
|
|
19643
19922
|
|
|
19644
19923
|
// src/gallery/page.ts
|
|
19645
|
-
var
|
|
19924
|
+
var import_node_fs33 = require("fs");
|
|
19646
19925
|
|
|
19647
19926
|
// src/gallery/client-bundle.ts
|
|
19648
19927
|
var import_node_module = require("module");
|
|
@@ -19682,8 +19961,8 @@ var client;
|
|
|
19682
19961
|
function clientAssets() {
|
|
19683
19962
|
const prebuilt = new URL("gallery.js", CLIENT_DIR);
|
|
19684
19963
|
client ??= {
|
|
19685
|
-
css: (0,
|
|
19686
|
-
js: (0,
|
|
19964
|
+
css: (0, import_node_fs33.readFileSync)(new URL("gallery.css", CLIENT_DIR), "utf8"),
|
|
19965
|
+
js: (0, import_node_fs33.existsSync)(prebuilt) ? (0, import_node_fs33.readFileSync)(prebuilt, "utf8") : bundleGalleryClient()
|
|
19687
19966
|
};
|
|
19688
19967
|
return client;
|
|
19689
19968
|
}
|
|
@@ -19826,8 +20105,8 @@ var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download
|
|
|
19826
20105
|
|
|
19827
20106
|
// src/editor/install.ts
|
|
19828
20107
|
var import_node_crypto8 = require("crypto");
|
|
19829
|
-
var
|
|
19830
|
-
var
|
|
20108
|
+
var import_node_fs34 = require("fs");
|
|
20109
|
+
var import_promises29 = require("fs/promises");
|
|
19831
20110
|
var import_node_os4 = __toESM(require("os"), 1);
|
|
19832
20111
|
var import_node_path36 = __toESM(require("path"), 1);
|
|
19833
20112
|
var EditorInstallError = class extends Error {
|
|
@@ -19858,7 +20137,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
|
|
|
19858
20137
|
}
|
|
19859
20138
|
async function sha256Of(file) {
|
|
19860
20139
|
try {
|
|
19861
|
-
return (0, import_node_crypto8.createHash)("sha256").update(await (0,
|
|
20140
|
+
return (0, import_node_crypto8.createHash)("sha256").update(await (0, import_promises29.readFile)(file)).digest("hex");
|
|
19862
20141
|
} catch {
|
|
19863
20142
|
return null;
|
|
19864
20143
|
}
|
|
@@ -19872,7 +20151,7 @@ async function editorStatus(opts = {}) {
|
|
|
19872
20151
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
19873
20152
|
totalBytes += expected.bytes;
|
|
19874
20153
|
const file = import_node_path36.default.join(dir, name);
|
|
19875
|
-
const info = (0,
|
|
20154
|
+
const info = (0, import_node_fs34.existsSync)(file) ? await (0, import_promises29.stat)(file).catch(() => null) : null;
|
|
19876
20155
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
19877
20156
|
installedBytes += expected.bytes;
|
|
19878
20157
|
} else {
|
|
@@ -19901,7 +20180,7 @@ async function installEditor(opts = {}) {
|
|
|
19901
20180
|
);
|
|
19902
20181
|
}
|
|
19903
20182
|
if (!baseUrl) throw new EditorInstallError("no download location for the editor build");
|
|
19904
|
-
await (0,
|
|
20183
|
+
await (0, import_promises29.mkdir)(dir, { recursive: true });
|
|
19905
20184
|
const downloaded = [];
|
|
19906
20185
|
const skipped = Object.keys(pin.files).filter((name) => !before.missing.includes(name));
|
|
19907
20186
|
let fetchedBytes = before.installedBytes;
|
|
@@ -19932,10 +20211,10 @@ async function installEditor(opts = {}) {
|
|
|
19932
20211
|
const final = import_node_path36.default.join(dir, name);
|
|
19933
20212
|
const tmp = `${final}.${process.pid}.part`;
|
|
19934
20213
|
try {
|
|
19935
|
-
await (0,
|
|
19936
|
-
await (0,
|
|
20214
|
+
await (0, import_promises29.writeFile)(tmp, bytes);
|
|
20215
|
+
await (0, import_promises29.rename)(tmp, final);
|
|
19937
20216
|
} finally {
|
|
19938
|
-
await (0,
|
|
20217
|
+
await (0, import_promises29.rm)(tmp, { force: true });
|
|
19939
20218
|
}
|
|
19940
20219
|
fetchedBytes += bytes.length;
|
|
19941
20220
|
downloaded.push(name);
|
|
@@ -19979,7 +20258,7 @@ function editorContentType(name) {
|
|
|
19979
20258
|
}
|
|
19980
20259
|
|
|
19981
20260
|
// src/gallery/editor.ts
|
|
19982
|
-
var
|
|
20261
|
+
var import_promises30 = require("fs/promises");
|
|
19983
20262
|
var import_node_path37 = __toESM(require("path"), 1);
|
|
19984
20263
|
function editorRoute(release, name = "index.html") {
|
|
19985
20264
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
@@ -20053,7 +20332,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
20053
20332
|
if (!status.installed) return null;
|
|
20054
20333
|
let bytes;
|
|
20055
20334
|
try {
|
|
20056
|
-
bytes = await (0,
|
|
20335
|
+
bytes = await (0, import_promises30.readFile)(import_node_path37.default.join(dir, name));
|
|
20057
20336
|
} catch {
|
|
20058
20337
|
verified = null;
|
|
20059
20338
|
return null;
|
|
@@ -20070,7 +20349,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
20070
20349
|
// src/gallery/server.ts
|
|
20071
20350
|
var import_node_crypto9 = require("crypto");
|
|
20072
20351
|
var import_node_http2 = require("http");
|
|
20073
|
-
var
|
|
20352
|
+
var import_promises31 = require("fs/promises");
|
|
20074
20353
|
var MAX_EDIT_BYTES = 48 * 1024 * 1024;
|
|
20075
20354
|
var EDITOR_CSP = [
|
|
20076
20355
|
"default-src 'self'",
|
|
@@ -20251,7 +20530,7 @@ async function serveGallery(opts) {
|
|
|
20251
20530
|
const asset = reviewAssets.get(jobId)?.get(url2.pathname);
|
|
20252
20531
|
if (!asset) return fail(404, "no such review asset");
|
|
20253
20532
|
try {
|
|
20254
|
-
const bytes = await (0,
|
|
20533
|
+
const bytes = await (0, import_promises31.readFile)(asset.path);
|
|
20255
20534
|
res.writeHead(200, {
|
|
20256
20535
|
"Content-Type": asset.contentType,
|
|
20257
20536
|
"Cache-Control": "no-store",
|
|
@@ -20334,7 +20613,7 @@ async function serveGallery(opts) {
|
|
|
20334
20613
|
if (!asset) return fail(404, "no such gallery media");
|
|
20335
20614
|
let bytes;
|
|
20336
20615
|
try {
|
|
20337
|
-
bytes = await (0,
|
|
20616
|
+
bytes = await (0, import_promises31.readFile)(asset.path);
|
|
20338
20617
|
} catch {
|
|
20339
20618
|
return fail(404, "gallery media is no longer on disk; refresh the page");
|
|
20340
20619
|
}
|
|
@@ -20744,8 +21023,8 @@ function createGenerateHandlers(opts) {
|
|
|
20744
21023
|
}
|
|
20745
21024
|
|
|
20746
21025
|
// src/pipeline/salvage.ts
|
|
20747
|
-
var
|
|
20748
|
-
var
|
|
21026
|
+
var import_promises32 = require("fs/promises");
|
|
21027
|
+
var import_node_fs35 = require("fs");
|
|
20749
21028
|
var import_node_path38 = __toESM(require("path"), 1);
|
|
20750
21029
|
function providerClaimId(provider, objectId) {
|
|
20751
21030
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
@@ -20753,10 +21032,10 @@ function providerClaimId(provider, objectId) {
|
|
|
20753
21032
|
async function loadClaims(lockPaths, opts = {}) {
|
|
20754
21033
|
const claimed = /* @__PURE__ */ new Set();
|
|
20755
21034
|
for (const p of lockPaths) {
|
|
20756
|
-
if (!(0,
|
|
21035
|
+
if (!(0, import_node_fs35.existsSync)(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
20757
21036
|
let parsed;
|
|
20758
21037
|
try {
|
|
20759
|
-
parsed = parseLock(JSON.parse(await (0,
|
|
21038
|
+
parsed = parseLock(JSON.parse(await (0, import_promises32.readFile)(p, "utf8")));
|
|
20760
21039
|
} catch {
|
|
20761
21040
|
throw new Error(`Claim lockfile is malformed: ${p}`);
|
|
20762
21041
|
}
|
|
@@ -20870,7 +21149,7 @@ async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, cla
|
|
|
20870
21149
|
const siblings = [];
|
|
20871
21150
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
20872
21151
|
if (import_node_path38.default.resolve(siblingManifestPath) === own) continue;
|
|
20873
|
-
if (!(0,
|
|
21152
|
+
if (!(0, import_node_fs35.existsSync)(siblingManifestPath)) continue;
|
|
20874
21153
|
try {
|
|
20875
21154
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
20876
21155
|
siblings.push({ label: import_node_path38.default.basename(import_node_path38.default.dirname(siblingManifestPath)), manifest });
|
|
@@ -20993,7 +21272,7 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
20993
21272
|
}
|
|
20994
21273
|
|
|
20995
21274
|
// src/pick/salvage-server.ts
|
|
20996
|
-
var
|
|
21275
|
+
var import_promises33 = require("fs/promises");
|
|
20997
21276
|
var import_node_path39 = __toESM(require("path"), 1);
|
|
20998
21277
|
|
|
20999
21278
|
// src/pick/salvage-sheet.ts
|
|
@@ -21218,8 +21497,8 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21218
21497
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
21219
21498
|
const rel = import_node_path39.default.join("_salvaged", `${assetId}.png`);
|
|
21220
21499
|
const outFile = import_node_path39.default.resolve(ctx.importDir, rel);
|
|
21221
|
-
await (0,
|
|
21222
|
-
await (0,
|
|
21500
|
+
await (0, import_promises33.mkdir)(import_node_path39.default.dirname(outFile), { recursive: true });
|
|
21501
|
+
await (0, import_promises33.writeFile)(outFile, buf);
|
|
21223
21502
|
ctx.manifest.assets[assetId] = {
|
|
21224
21503
|
prompt: orphan.prompt,
|
|
21225
21504
|
promptByStyle: {},
|
|
@@ -21275,9 +21554,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21275
21554
|
}
|
|
21276
21555
|
}
|
|
21277
21556
|
await applyTags(provider, decisions, existingTags, { onProgress: log, characters: characterMembers });
|
|
21278
|
-
const raw = JSON.parse(await (0,
|
|
21557
|
+
const raw = JSON.parse(await (0, import_promises33.readFile)(ctx.manifestPath, "utf8"));
|
|
21279
21558
|
for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
|
|
21280
|
-
await (0,
|
|
21559
|
+
await (0, import_promises33.writeFile)(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
|
|
21281
21560
|
await saveLock(ctx.lockPath, ctx.lock);
|
|
21282
21561
|
if (characterAssetIds.length) result.characterAssetIds = characterAssetIds;
|
|
21283
21562
|
return result;
|
|
@@ -21501,6 +21780,7 @@ async function workspaceStatus(ws, dir) {
|
|
|
21501
21780
|
availableProviders,
|
|
21502
21781
|
backoffMs,
|
|
21503
21782
|
buildGallerySnapshot,
|
|
21783
|
+
buildImportedEntry,
|
|
21504
21784
|
buildManifest,
|
|
21505
21785
|
buildPlan,
|
|
21506
21786
|
buildWorkspaceGallerySnapshot,
|
|
@@ -21563,6 +21843,7 @@ async function workspaceStatus(ws, dir) {
|
|
|
21563
21843
|
historyLimit,
|
|
21564
21844
|
idFromPrompt,
|
|
21565
21845
|
imageMetadata,
|
|
21846
|
+
importLocal,
|
|
21566
21847
|
inspectCaches,
|
|
21567
21848
|
inspectQualityProfile,
|
|
21568
21849
|
inspectRevisionReadiness,
|
|
@@ -21620,6 +21901,7 @@ async function workspaceStatus(ws, dir) {
|
|
|
21620
21901
|
parseVfxStep,
|
|
21621
21902
|
parseWorkspace,
|
|
21622
21903
|
pickHistory,
|
|
21904
|
+
pixMiniMaxCost,
|
|
21623
21905
|
pixelateFile,
|
|
21624
21906
|
pngSize,
|
|
21625
21907
|
poll,
|
|
@@ -21654,6 +21936,7 @@ async function workspaceStatus(ws, dir) {
|
|
|
21654
21936
|
renderSalvageSheet,
|
|
21655
21937
|
renderSheet,
|
|
21656
21938
|
renderSheetDocument,
|
|
21939
|
+
reportSpecHashes,
|
|
21657
21940
|
requireApprovedQualitySources,
|
|
21658
21941
|
requireBalance,
|
|
21659
21942
|
requireDelete,
|
|
@@ -21693,6 +21976,7 @@ async function workspaceStatus(ws, dir) {
|
|
|
21693
21976
|
sliceVfxSheet,
|
|
21694
21977
|
slugify,
|
|
21695
21978
|
snapshotQualityBaseline,
|
|
21979
|
+
snapshotQualityCases,
|
|
21696
21980
|
sourceIsStem,
|
|
21697
21981
|
sourceOutputPath,
|
|
21698
21982
|
specHash,
|
|
@@ -21711,6 +21995,7 @@ async function workspaceStatus(ws, dir) {
|
|
|
21711
21995
|
tilesCost,
|
|
21712
21996
|
toPortablePath,
|
|
21713
21997
|
totalSpend,
|
|
21998
|
+
uiElementCandidateCount,
|
|
21714
21999
|
unzoomFile,
|
|
21715
22000
|
upsert,
|
|
21716
22001
|
validateCostEstimate,
|