pixelkiln 0.92.3 → 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/dist/cli.js +530 -206
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +453 -196
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +142 -1
- package/dist/index.d.ts +142 -1
- package/dist/index.js +415 -162
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +51 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1580,7 +1580,17 @@ var LockEntrySchema = z.object({
|
|
|
1580
1580
|
/** Generations this entry replaced, newest first; see LockHistoryEntrySchema. */
|
|
1581
1581
|
history: z.array(LockHistoryEntrySchema).optional(),
|
|
1582
1582
|
/** Post-processing applied to the recorded outputs; absent when the bytes are the provider's. */
|
|
1583
|
-
postprocess: PostprocessSchema.optional()
|
|
1583
|
+
postprocess: PostprocessSchema.optional(),
|
|
1584
|
+
/**
|
|
1585
|
+
* Set when the entry records art made outside pixelkiln (the PixelLab MCP, a
|
|
1586
|
+
* hand edit, another tool) and brought in with `adopt --local`: nothing was
|
|
1587
|
+
* submitted, so jobId and cost are empty. Absent on generated entries.
|
|
1588
|
+
*/
|
|
1589
|
+
imported: z.object({
|
|
1590
|
+
source: z.string().min(1),
|
|
1591
|
+
note: z.string().optional(),
|
|
1592
|
+
importedAt: z.string()
|
|
1593
|
+
}).strict().optional()
|
|
1584
1594
|
});
|
|
1585
1595
|
var LockSchema = z.object({
|
|
1586
1596
|
version: z.literal(2),
|
|
@@ -6990,13 +7000,13 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
6990
7000
|
async pollVfx(jobId, context) {
|
|
6991
7001
|
const dir = _PixelLabProvider.cacheDir("vfx");
|
|
6992
7002
|
const sidecar = path3.join(dir, `${jobId}.json`);
|
|
6993
|
-
const
|
|
7003
|
+
const cached2 = () => {
|
|
6994
7004
|
if (!existsSync3(sidecar)) return null;
|
|
6995
7005
|
const facts2 = JSON.parse(readFileSync(sidecar, "utf8"));
|
|
6996
7006
|
const files2 = Array.from({ length: facts2.count }, (_, index) => path3.join(dir, `${jobId}-${index}.png`));
|
|
6997
7007
|
return files2.every((file) => existsSync3(file)) ? { facts: facts2, files: files2 } : null;
|
|
6998
7008
|
};
|
|
6999
|
-
let found =
|
|
7009
|
+
let found = cached2();
|
|
7000
7010
|
const recorded = context?.metadata?.vfx;
|
|
7001
7011
|
let artistDone;
|
|
7002
7012
|
if (!found && recorded?.artist) {
|
|
@@ -7016,11 +7026,11 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
7016
7026
|
}
|
|
7017
7027
|
artistDone.billed = billedFromUsage(job.usage);
|
|
7018
7028
|
}
|
|
7019
|
-
found =
|
|
7029
|
+
found = cached2();
|
|
7020
7030
|
} else if (!found && recorded?.downloadBase && Array.isArray(recorded.files)) {
|
|
7021
7031
|
const exported = recorded;
|
|
7022
7032
|
await this.cacheVfxFrames(jobId, exported, workbenchVfxUrls(exported));
|
|
7023
|
-
found =
|
|
7033
|
+
found = cached2();
|
|
7024
7034
|
}
|
|
7025
7035
|
if (!found) {
|
|
7026
7036
|
return {
|
|
@@ -8218,8 +8228,8 @@ var ScenarioClient = class {
|
|
|
8218
8228
|
async uploadImage(image, projectId) {
|
|
8219
8229
|
const bytes = Buffer.from(image.base64, "base64");
|
|
8220
8230
|
const digest2 = sha256(bytes);
|
|
8221
|
-
const
|
|
8222
|
-
if (
|
|
8231
|
+
const cached2 = readUploadCache()[uploadCacheKey(this.baseUrl, projectId, digest2)];
|
|
8232
|
+
if (cached2) return cached2;
|
|
8223
8233
|
const response = await this.call(
|
|
8224
8234
|
"/assets",
|
|
8225
8235
|
{
|
|
@@ -9909,7 +9919,7 @@ registerProvider({
|
|
|
9909
9919
|
|
|
9910
9920
|
// src/manifest.ts
|
|
9911
9921
|
import { readFile as readFile5 } from "fs/promises";
|
|
9912
|
-
import { existsSync as
|
|
9922
|
+
import { existsSync as existsSync7 } from "fs";
|
|
9913
9923
|
import path8 from "path";
|
|
9914
9924
|
|
|
9915
9925
|
// src/loop-directions.ts
|
|
@@ -10324,10 +10334,31 @@ function frameSetLoop(entry) {
|
|
|
10324
10334
|
return typeof loop === "boolean" ? loop : null;
|
|
10325
10335
|
}
|
|
10326
10336
|
|
|
10337
|
+
// src/version.ts
|
|
10338
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "fs";
|
|
10339
|
+
var cached;
|
|
10340
|
+
function pixelkilnVersion() {
|
|
10341
|
+
if (cached !== void 0) return cached;
|
|
10342
|
+
cached = null;
|
|
10343
|
+
for (const up of ["../package.json", "../../package.json"]) {
|
|
10344
|
+
const url = new URL(up, import.meta.url);
|
|
10345
|
+
if (!existsSync6(url)) continue;
|
|
10346
|
+
try {
|
|
10347
|
+
const pkg = JSON.parse(readFileSync3(url, "utf8"));
|
|
10348
|
+
if (pkg.name === "pixelkiln" && pkg.version) {
|
|
10349
|
+
cached = pkg.version;
|
|
10350
|
+
break;
|
|
10351
|
+
}
|
|
10352
|
+
} catch {
|
|
10353
|
+
}
|
|
10354
|
+
}
|
|
10355
|
+
return cached;
|
|
10356
|
+
}
|
|
10357
|
+
|
|
10327
10358
|
// src/manifest.ts
|
|
10328
10359
|
async function loadManifest(manifestPath) {
|
|
10329
10360
|
const abs = path8.resolve(manifestPath);
|
|
10330
|
-
if (!
|
|
10361
|
+
if (!existsSync7(abs)) throw new ProjectError(`No manifest at ${abs}`);
|
|
10331
10362
|
const expansion = expandLoopDirections(JSON.parse(await readFile5(abs, "utf8")));
|
|
10332
10363
|
if (expansion.issues.length) {
|
|
10333
10364
|
throw new ProjectError(`Manifest at ${abs} is invalid:
|
|
@@ -10479,19 +10510,45 @@ function dependencyAssetIds(asset, styleAnchors = []) {
|
|
|
10479
10510
|
].filter((id) => Boolean(id))
|
|
10480
10511
|
];
|
|
10481
10512
|
}
|
|
10513
|
+
var MAX_LISTED_MANIFEST_ISSUES = 20;
|
|
10514
|
+
function flattenManifestIssues(issues) {
|
|
10515
|
+
let unknownShape = false;
|
|
10516
|
+
const visit = (list) => list.flatMap((issue) => {
|
|
10517
|
+
if (issue.code === "invalid_union") return visit(issue.unionErrors.flatMap((error) => error.issues));
|
|
10518
|
+
if (issue.code === "unrecognized_keys" || issue.code === "invalid_enum_value") unknownShape = true;
|
|
10519
|
+
return [` ${issue.path.join(".") || "(manifest)"}: ${issue.message}`];
|
|
10520
|
+
});
|
|
10521
|
+
return { lines: [...new Set(visit(issues))], unknownShape };
|
|
10522
|
+
}
|
|
10482
10523
|
function formatManifestIssues(issues) {
|
|
10483
|
-
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10524
|
+
const { lines, unknownShape } = flattenManifestIssues(issues);
|
|
10525
|
+
const entries = [...new Set(
|
|
10526
|
+
lines.flatMap((line) => {
|
|
10527
|
+
const match = /^ {2}((?:assets|styles)\.[^.:\s]+)/.exec(line);
|
|
10528
|
+
return match ? [match[1]] : [];
|
|
10529
|
+
})
|
|
10530
|
+
)];
|
|
10531
|
+
const out = [];
|
|
10532
|
+
const version = pixelkilnVersion();
|
|
10533
|
+
if (unknownShape) {
|
|
10534
|
+
out.push(
|
|
10535
|
+
` This manifest uses fields or values pixelkiln ${version ?? "(this version)"} does not know. If it was written by a newer release, run \`npx pixelkiln@latest\` or update the install before editing it.`
|
|
10536
|
+
);
|
|
10537
|
+
}
|
|
10538
|
+
if (entries.length) {
|
|
10539
|
+
out.push(` ${entries.length} invalid entr${entries.length === 1 ? "y" : "ies"}: ${entries.slice(0, 10).join(", ")}${entries.length > 10 ? ", \u2026" : ""}`);
|
|
10540
|
+
}
|
|
10541
|
+
out.push(...lines.slice(0, MAX_LISTED_MANIFEST_ISSUES));
|
|
10542
|
+
if (lines.length > MAX_LISTED_MANIFEST_ISSUES) {
|
|
10543
|
+
out.push(` \u2026 and ${lines.length - MAX_LISTED_MANIFEST_ISSUES} more`);
|
|
10544
|
+
}
|
|
10545
|
+
return out.join("\n");
|
|
10489
10546
|
}
|
|
10490
10547
|
function resolveStyleInheritance(styles) {
|
|
10491
10548
|
const resolved = /* @__PURE__ */ new Map();
|
|
10492
10549
|
const visit = (styleId, chain) => {
|
|
10493
|
-
const
|
|
10494
|
-
if (
|
|
10550
|
+
const cached2 = resolved.get(styleId);
|
|
10551
|
+
if (cached2) return cached2;
|
|
10495
10552
|
const cycleStart = chain.indexOf(styleId);
|
|
10496
10553
|
if (cycleStart >= 0) {
|
|
10497
10554
|
throw new Error(
|
|
@@ -10613,7 +10670,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
10613
10670
|
const abs = path8.resolve(root, rel);
|
|
10614
10671
|
let hit = styleImageCache.get(abs);
|
|
10615
10672
|
if (!hit) {
|
|
10616
|
-
if (!
|
|
10673
|
+
if (!existsSync7(abs)) throw new Error(`${what} not found: ${abs}`);
|
|
10617
10674
|
const buf = await readFile5(abs);
|
|
10618
10675
|
const metadata = imageMetadata(buf);
|
|
10619
10676
|
if (!metadata) throw new Error(`${what} is not a readable PNG or JPEG: ${abs}`);
|
|
@@ -10964,7 +11021,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
10964
11021
|
const file = memberPath(anchorSpec.outFile, "south", 0, anchorSpec.character.directions, MediaType.PNG);
|
|
10965
11022
|
resolved.character = {
|
|
10966
11023
|
...resolved.character,
|
|
10967
|
-
styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256:
|
|
11024
|
+
styleAnchor: { assetId: anchorId, spec: anchorSpec, file, sha256: existsSync7(file) ? await sha256File(file) : null }
|
|
10968
11025
|
};
|
|
10969
11026
|
}
|
|
10970
11027
|
const characterParent = asset.state?.of ?? asset.animation?.of ?? asset.portrait?.of;
|
|
@@ -10977,7 +11034,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
10977
11034
|
parentAssetId: characterParent,
|
|
10978
11035
|
parentSpec,
|
|
10979
11036
|
parentFile,
|
|
10980
|
-
parentSha256:
|
|
11037
|
+
parentSha256: existsSync7(parentFile) ? await sha256File(parentFile) : null,
|
|
10981
11038
|
// A state and its animations keep the engine and rotations of the base.
|
|
10982
11039
|
mode: resolved.character.kind === "base" ? resolved.character.mode : parentSpec.character?.mode ?? resolved.character.mode,
|
|
10983
11040
|
directions: resolved.character.kind === "base" ? resolved.character.directions : parentSpec.character?.directions ?? resolved.character.directions
|
|
@@ -11015,7 +11072,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11015
11072
|
parentAssetId: characterParent,
|
|
11016
11073
|
parentSpec,
|
|
11017
11074
|
parentFile,
|
|
11018
|
-
parentSha256:
|
|
11075
|
+
parentSha256: existsSync7(parentFile) ? await sha256File(parentFile) : null,
|
|
11019
11076
|
// A state and its animations keep the base's own rotation count.
|
|
11020
11077
|
directions: resolved.objectPro.kind === "base" ? resolved.objectPro.directions : parentSpec.objectPro.directions
|
|
11021
11078
|
};
|
|
@@ -11219,8 +11276,18 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11219
11276
|
providerOptionIdentity,
|
|
11220
11277
|
providerInputIdentities.get(assetId)
|
|
11221
11278
|
);
|
|
11222
|
-
|
|
11223
|
-
|
|
11279
|
+
let estimate;
|
|
11280
|
+
try {
|
|
11281
|
+
activeProvider.validate?.(resolved, resolvedImages);
|
|
11282
|
+
estimate = validateCostEstimate(activeProvider.id, activeProvider.estimate(resolved));
|
|
11283
|
+
} catch (error) {
|
|
11284
|
+
const message6 = error instanceof Error ? error.message : String(error);
|
|
11285
|
+
if (message6.includes(`assets.${assetId}`)) throw error;
|
|
11286
|
+
throw new Error(
|
|
11287
|
+
`assets.${assetId} (style "${styleId}", ${resolved.width}x${resolved.height}): ${message6}`,
|
|
11288
|
+
{ cause: error }
|
|
11289
|
+
);
|
|
11290
|
+
}
|
|
11224
11291
|
resolved.cost = estimate.amount;
|
|
11225
11292
|
resolved.costUnit = estimate.unit;
|
|
11226
11293
|
resolved.candidates = estimate.candidates;
|
|
@@ -11304,7 +11371,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
11304
11371
|
let recordedSprite;
|
|
11305
11372
|
if (vfx.recipe) {
|
|
11306
11373
|
const file = path8.resolve(root, vfx.recipe);
|
|
11307
|
-
if (!
|
|
11374
|
+
if (!existsSync7(file)) throw new Error(`assets.${assetId}.vfx.recipe: VFX recipe not found: ${file}`);
|
|
11308
11375
|
const read = await readVfxRecipe(file).catch((error) => {
|
|
11309
11376
|
throw new Error(`assets.${assetId}.vfx.recipe: ${error instanceof Error ? error.message : String(error)}`);
|
|
11310
11377
|
});
|
|
@@ -11331,7 +11398,7 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
11331
11398
|
};
|
|
11332
11399
|
}
|
|
11333
11400
|
async function optionalRevisionImage(file, label, requiredFormat) {
|
|
11334
|
-
if (!
|
|
11401
|
+
if (!existsSync7(file)) return null;
|
|
11335
11402
|
const bytes = await readFile5(file);
|
|
11336
11403
|
const metadata = imageMetadata(bytes);
|
|
11337
11404
|
if (!metadata) throw new Error(`${label} is not a readable PNG or JPEG: ${file}`);
|
|
@@ -11341,7 +11408,7 @@ async function optionalRevisionImage(file, label, requiredFormat) {
|
|
|
11341
11408
|
return { hash: sha256(bytes), ...metadata };
|
|
11342
11409
|
}
|
|
11343
11410
|
async function optionalSkeletonSet(file) {
|
|
11344
|
-
if (!
|
|
11411
|
+
if (!existsSync7(file)) return null;
|
|
11345
11412
|
const bytes = await readFile5(file);
|
|
11346
11413
|
let json;
|
|
11347
11414
|
try {
|
|
@@ -11352,17 +11419,17 @@ async function optionalSkeletonSet(file) {
|
|
|
11352
11419
|
return { hash: sha256(bytes), skeleton: parseSkeletonSet(json, file) };
|
|
11353
11420
|
}
|
|
11354
11421
|
async function revisionSourceMembers(stem, label) {
|
|
11355
|
-
if (
|
|
11422
|
+
if (existsSync7(stem)) return null;
|
|
11356
11423
|
const at = (role) => memberPath(stem, role, 0, 2, MediaType.PNG);
|
|
11357
11424
|
let roles = [];
|
|
11358
11425
|
for (const set of [CHARACTER_DIRECTIONS_8, CHARACTER_DIRECTIONS_4]) {
|
|
11359
|
-
if (set.every((direction) =>
|
|
11426
|
+
if (set.every((direction) => existsSync7(at(direction)))) {
|
|
11360
11427
|
roles = [...set];
|
|
11361
11428
|
break;
|
|
11362
11429
|
}
|
|
11363
11430
|
}
|
|
11364
11431
|
if (!roles.length) {
|
|
11365
|
-
for (let index = 0;
|
|
11432
|
+
for (let index = 0; existsSync7(at(`frame-${String(index).padStart(2, "0")}`)); index++) {
|
|
11366
11433
|
roles.push(`frame-${String(index).padStart(2, "0")}`);
|
|
11367
11434
|
}
|
|
11368
11435
|
}
|
|
@@ -11530,7 +11597,7 @@ function characterDirections(directions) {
|
|
|
11530
11597
|
import path16 from "path";
|
|
11531
11598
|
|
|
11532
11599
|
// src/env.ts
|
|
11533
|
-
import { readFileSync as
|
|
11600
|
+
import { readFileSync as readFileSync4, existsSync as existsSync8 } from "fs";
|
|
11534
11601
|
import path9 from "path";
|
|
11535
11602
|
function loadEnvFiles(dir) {
|
|
11536
11603
|
const loaded = [];
|
|
@@ -11546,9 +11613,9 @@ function envFiles(dir) {
|
|
|
11546
11613
|
const out = [];
|
|
11547
11614
|
for (const name of [".env.local", ".env"]) {
|
|
11548
11615
|
const file = path9.join(dir, name);
|
|
11549
|
-
if (!
|
|
11616
|
+
if (!existsSync8(file)) continue;
|
|
11550
11617
|
try {
|
|
11551
|
-
out.push([file, parseEnv(
|
|
11618
|
+
out.push([file, parseEnv(readFileSync4(file, "utf8"))]);
|
|
11552
11619
|
} catch {
|
|
11553
11620
|
}
|
|
11554
11621
|
}
|
|
@@ -11574,7 +11641,7 @@ function parseEnv(contents) {
|
|
|
11574
11641
|
}
|
|
11575
11642
|
|
|
11576
11643
|
// src/pipeline/plan.ts
|
|
11577
|
-
import { existsSync as
|
|
11644
|
+
import { existsSync as existsSync11 } from "fs";
|
|
11578
11645
|
import path15 from "path";
|
|
11579
11646
|
|
|
11580
11647
|
// src/pipeline/mirror.ts
|
|
@@ -11780,7 +11847,7 @@ async function deriveMirror(spec, lock, lockPath, opts = {}) {
|
|
|
11780
11847
|
}
|
|
11781
11848
|
|
|
11782
11849
|
// src/pipeline/quality-profile.ts
|
|
11783
|
-
import { existsSync as
|
|
11850
|
+
import { existsSync as existsSync9 } from "fs";
|
|
11784
11851
|
import path13 from "path";
|
|
11785
11852
|
|
|
11786
11853
|
// src/pipeline/refine.ts
|
|
@@ -12763,7 +12830,7 @@ async function qualitySource(spec, lock) {
|
|
|
12763
12830
|
return { items: null, reason: "frame-set quality requires ordered downloaded provider outputs" };
|
|
12764
12831
|
}
|
|
12765
12832
|
const source = path13.resolve(spec.root, spec.source);
|
|
12766
|
-
return
|
|
12833
|
+
return existsSync9(source) ? { items: [{ role: "source", path: source }] } : { items: null, reason: `declared source is missing: ${spec.source}` };
|
|
12767
12834
|
}
|
|
12768
12835
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
12769
12836
|
if (!entry) return { items: null, reason: "raw provider output is not in the lockfile" };
|
|
@@ -12792,7 +12859,7 @@ async function qualitySource(spec, lock) {
|
|
|
12792
12859
|
}
|
|
12793
12860
|
if (role) roles.add(role);
|
|
12794
12861
|
const source = currentEntryOutputPath(entry, spec, index);
|
|
12795
|
-
if (!
|
|
12862
|
+
if (!existsSync9(source)) return { items: null, reason: `raw provider output is missing: ${source}` };
|
|
12796
12863
|
if (await sha256File(source) !== output.sha256) {
|
|
12797
12864
|
return { items: null, reason: "raw provider output was modified after download" };
|
|
12798
12865
|
}
|
|
@@ -12811,7 +12878,7 @@ async function inspectQualityProfile(spec, lock) {
|
|
|
12811
12878
|
}
|
|
12812
12879
|
const sourcePaths = source.items.map((item) => item.path);
|
|
12813
12880
|
const expectedOutputs = spec.generator === "frames" ? source.items.map((item, index) => qualityFrameOutputPath(output, item.role, index)) : [output];
|
|
12814
|
-
if (!
|
|
12881
|
+
if (!existsSync9(record)) {
|
|
12815
12882
|
return {
|
|
12816
12883
|
key,
|
|
12817
12884
|
state: "needs-refinement",
|
|
@@ -12992,7 +13059,7 @@ async function requireApprovedQualitySources(specs, lock, assetIds, outputRoles)
|
|
|
12992
13059
|
}
|
|
12993
13060
|
|
|
12994
13061
|
// src/pipeline/revision.ts
|
|
12995
|
-
import { existsSync as
|
|
13062
|
+
import { existsSync as existsSync10 } from "fs";
|
|
12996
13063
|
import path14 from "path";
|
|
12997
13064
|
async function inspectRevisionReadiness(spec, lock) {
|
|
12998
13065
|
if (spec.mirror) return inspectMirror(spec, lock, /* @__PURE__ */ new Set());
|
|
@@ -13014,7 +13081,7 @@ async function inspectStyleAnchor(spec, lock, seen) {
|
|
|
13014
13081
|
const label = `style anchor ${spec.styleId}/${anchor.assetId}`;
|
|
13015
13082
|
const dependency = await inspectParent(anchor.spec, lock, seen);
|
|
13016
13083
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13017
|
-
if (!anchor.sha256 || !
|
|
13084
|
+
if (!anchor.sha256 || !existsSync10(anchor.file)) return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13018
13085
|
if (await sha256File(anchor.file) !== anchor.sha256) {
|
|
13019
13086
|
return { ready: false, reason: `${label} changed after the manifest was resolved` };
|
|
13020
13087
|
}
|
|
@@ -13051,14 +13118,14 @@ async function inspectScene(spec) {
|
|
|
13051
13118
|
const files = [{ label: "scene image", file: scene.file, sha256: scene.sha256 }];
|
|
13052
13119
|
if (scene.placement.type === "mask") files.push({ label: "scene mask", file: scene.placement.file, sha256: scene.placement.sha256 });
|
|
13053
13120
|
for (const { label, file, sha256: sha2562 } of files) {
|
|
13054
|
-
if (!sha2562 || !
|
|
13121
|
+
if (!sha2562 || !existsSync10(file)) return { ready: false, reason: `${label} does not exist yet: ${file}` };
|
|
13055
13122
|
if (await sha256File(file) !== sha2562) return { ready: false, reason: `${label} changed after the manifest was resolved` };
|
|
13056
13123
|
}
|
|
13057
13124
|
return { ready: true, reason: "scene is current" };
|
|
13058
13125
|
}
|
|
13059
13126
|
async function inspectVfxSprite(spec) {
|
|
13060
13127
|
const sprite = spec.vfx.sprite;
|
|
13061
|
-
if (!sprite.sha256 || !
|
|
13128
|
+
if (!sprite.sha256 || !existsSync10(sprite.file)) return { ready: false, reason: `vfx sprite does not exist yet: ${sprite.file}` };
|
|
13062
13129
|
if (await sha256File(sprite.file) !== sprite.sha256) return { ready: false, reason: "vfx sprite changed after the manifest was resolved" };
|
|
13063
13130
|
return { ready: true, reason: "vfx sprite is current" };
|
|
13064
13131
|
}
|
|
@@ -13074,7 +13141,7 @@ async function inspectOutfit(spec, lock, seen) {
|
|
|
13074
13141
|
const label = `outfit source ${spec.styleId}/${character.parentAssetId}`;
|
|
13075
13142
|
const dependency = await inspectParent(character.parentSpec, lock, seen);
|
|
13076
13143
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13077
|
-
if (!
|
|
13144
|
+
if (!existsSync10(outfit.reference.path)) {
|
|
13078
13145
|
return { ready: false, reason: `outfit reference is missing: ${outfit.reference.path}` };
|
|
13079
13146
|
}
|
|
13080
13147
|
if (await sha256File(outfit.reference.path) !== outfit.reference.sha256) {
|
|
@@ -13088,7 +13155,7 @@ async function inspectCharacterParent(spec, lock, seen) {
|
|
|
13088
13155
|
const label = `${character.kind} parent ${spec.styleId}/${character.parentAssetId}`;
|
|
13089
13156
|
const dependency = await inspectParent(parentSpec, lock, seen);
|
|
13090
13157
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13091
|
-
if (!character.parentSha256 || !character.parentFile || !
|
|
13158
|
+
if (!character.parentSha256 || !character.parentFile || !existsSync10(character.parentFile)) {
|
|
13092
13159
|
return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13093
13160
|
}
|
|
13094
13161
|
if (await sha256File(character.parentFile) !== character.parentSha256) {
|
|
@@ -13106,7 +13173,7 @@ async function inspectObjectProParent(spec, lock, seen) {
|
|
|
13106
13173
|
const label = `${object.kind} parent ${spec.styleId}/${object.parentAssetId}`;
|
|
13107
13174
|
const dependency = await inspectParent(parentSpec, lock, seen);
|
|
13108
13175
|
if (!dependency.ready) return { ready: false, reason: `${label} is not ready: ${dependency.reason}` };
|
|
13109
|
-
if (!object.parentSha256 || !object.parentFile || !
|
|
13176
|
+
if (!object.parentSha256 || !object.parentFile || !existsSync10(object.parentFile)) {
|
|
13110
13177
|
return { ready: false, reason: `${label} has no generated south-facing file yet` };
|
|
13111
13178
|
}
|
|
13112
13179
|
if (await sha256File(object.parentFile) !== object.parentSha256) {
|
|
@@ -13132,7 +13199,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13132
13199
|
const members = await inspectSourceMembers(spec, lock);
|
|
13133
13200
|
if (!members.ready) return members;
|
|
13134
13201
|
} else {
|
|
13135
|
-
if (!revision.sourceSha256 || !
|
|
13202
|
+
if (!revision.sourceSha256 || !existsSync10(revision.sourceFile)) {
|
|
13136
13203
|
return { ready: false, reason: `revision source is missing: ${revision.sourceFile}` };
|
|
13137
13204
|
}
|
|
13138
13205
|
if (await sha256File(revision.sourceFile) !== revision.sourceSha256) {
|
|
@@ -13140,7 +13207,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13140
13207
|
}
|
|
13141
13208
|
}
|
|
13142
13209
|
if (revision.maskFile) {
|
|
13143
|
-
if (!revision.maskSha256 || !
|
|
13210
|
+
if (!revision.maskSha256 || !existsSync10(revision.maskFile)) {
|
|
13144
13211
|
return { ready: false, reason: `revision mask is missing: ${revision.maskFile}` };
|
|
13145
13212
|
}
|
|
13146
13213
|
if (await sha256File(revision.maskFile) !== revision.maskSha256) {
|
|
@@ -13148,7 +13215,7 @@ async function inspectRevision(spec, lock, seen) {
|
|
|
13148
13215
|
}
|
|
13149
13216
|
}
|
|
13150
13217
|
if (revision.lastFrameFile) {
|
|
13151
|
-
if (!revision.lastFrameSha256 || !
|
|
13218
|
+
if (!revision.lastFrameSha256 || !existsSync10(revision.lastFrameFile)) {
|
|
13152
13219
|
return { ready: false, reason: `revision last frame is missing: ${revision.lastFrameFile}` };
|
|
13153
13220
|
}
|
|
13154
13221
|
if (await sha256File(revision.lastFrameFile) !== revision.lastFrameSha256) {
|
|
@@ -13161,7 +13228,7 @@ async function inspectSourceMembers(spec, lock) {
|
|
|
13161
13228
|
const revision = spec.revision;
|
|
13162
13229
|
const members = revision.sourceMembers;
|
|
13163
13230
|
for (const member of members) {
|
|
13164
|
-
if (!
|
|
13231
|
+
if (!existsSync10(member.file)) return { ready: false, reason: `revision source member is missing: ${member.file}` };
|
|
13165
13232
|
if (await sha256File(member.file) !== member.sha256) {
|
|
13166
13233
|
return { ready: false, reason: `revision source member changed after the manifest was resolved: ${member.file}` };
|
|
13167
13234
|
}
|
|
@@ -13229,7 +13296,7 @@ async function inspectParent(spec, lock, seen) {
|
|
|
13229
13296
|
}
|
|
13230
13297
|
if (spec.source) {
|
|
13231
13298
|
const source = path14.resolve(spec.root, spec.source);
|
|
13232
|
-
return
|
|
13299
|
+
return existsSync10(source) ? { ready: true, reason: "declared source is present" } : { ready: false, reason: `declared source is missing: ${spec.source}` };
|
|
13233
13300
|
}
|
|
13234
13301
|
const entry = lock.entries[key];
|
|
13235
13302
|
if (!entry) return { ready: false, reason: "parent is not in the lockfile" };
|
|
@@ -13243,7 +13310,7 @@ async function inspectParent(spec, lock, seen) {
|
|
|
13243
13310
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
13244
13311
|
const output = entry.outputs[index];
|
|
13245
13312
|
const file = currentEntryOutputPath(entry, spec, index);
|
|
13246
|
-
if (!
|
|
13313
|
+
if (!existsSync10(file)) return { ready: false, reason: `parent output is missing: ${file}` };
|
|
13247
13314
|
if (await sha256File(file) !== output.sha256) {
|
|
13248
13315
|
return { ready: false, reason: `parent output was modified: ${file}` };
|
|
13249
13316
|
}
|
|
@@ -13338,7 +13405,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13338
13405
|
state = "missing";
|
|
13339
13406
|
reason = "--force";
|
|
13340
13407
|
} else if (!entry && spec.source && spec.generator !== "frames" && spec.generator !== "vfx") {
|
|
13341
|
-
if (
|
|
13408
|
+
if (existsSync11(path15.resolve(spec.root, spec.source))) {
|
|
13342
13409
|
state = "ok";
|
|
13343
13410
|
reason = `placed from ${spec.source}; not generated`;
|
|
13344
13411
|
} else {
|
|
@@ -13346,7 +13413,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13346
13413
|
reason = `declared source is missing: ${spec.source}`;
|
|
13347
13414
|
}
|
|
13348
13415
|
} else if (!entry) {
|
|
13349
|
-
if (
|
|
13416
|
+
if (existsSync11(spec.outFile)) {
|
|
13350
13417
|
state = "untracked";
|
|
13351
13418
|
reason = "file on disk, no provenance recorded";
|
|
13352
13419
|
} else {
|
|
@@ -13359,7 +13426,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13359
13426
|
} else if (spec.mirror && !mirrorCurrent(entry, lock.entries[lockKey(spec.styleId, spec.mirror.sourceAssetId)])) {
|
|
13360
13427
|
state = "stale";
|
|
13361
13428
|
reason = `mirror source ${spec.mirror.sourceAssetId} changed; flip it again (no generation cost)`;
|
|
13362
|
-
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !
|
|
13429
|
+
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !existsSync11(currentEntryOutputPath(entry, spec, index)))) {
|
|
13363
13430
|
state = "stale";
|
|
13364
13431
|
reason = "mirror output missing on disk; flip it again (no generation cost)";
|
|
13365
13432
|
} else if (spec.character?.kind === "outfit" && entry.outfit?.sourceSha256 !== mirrorSourceHash(lock.entries[lockKey(spec.styleId, spec.character.parentAssetId)] ?? { outputs: [] })) {
|
|
@@ -13396,9 +13463,9 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13396
13463
|
} else if (entry.status !== "downloaded") {
|
|
13397
13464
|
state = "in-flight";
|
|
13398
13465
|
reason = `awaiting ${entry.status}`;
|
|
13399
|
-
} else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !
|
|
13466
|
+
} else if (entry.outputs.length === 0 || entry.outputs.some((_output, index) => !existsSync11(currentEntryOutputPath(entry, spec, index)))) {
|
|
13400
13467
|
state = "orphaned";
|
|
13401
|
-
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !
|
|
13468
|
+
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !existsSync11(currentEntryOutputPath(entry, spec, index))).map((o) => o.role ?? "asset").join(", ")}`;
|
|
13402
13469
|
} else if (await anyOutputModified(entry, spec)) {
|
|
13403
13470
|
state = "orphaned";
|
|
13404
13471
|
reason = "output modified since download";
|
|
@@ -13534,7 +13601,7 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
|
|
|
13534
13601
|
|
|
13535
13602
|
// src/recipes.ts
|
|
13536
13603
|
import path17 from "path";
|
|
13537
|
-
import { existsSync as
|
|
13604
|
+
import { existsSync as existsSync12 } from "fs";
|
|
13538
13605
|
import { readdir, readFile as readFile9 } from "fs/promises";
|
|
13539
13606
|
import { fileURLToPath } from "url";
|
|
13540
13607
|
import { z as z4 } from "zod";
|
|
@@ -13737,7 +13804,7 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
13737
13804
|
return { recipe: parsed.data, authored: raw, path: absolute, dir: path17.dirname(absolute), bundled };
|
|
13738
13805
|
}
|
|
13739
13806
|
async function walkRecipeFiles(root) {
|
|
13740
|
-
if (!
|
|
13807
|
+
if (!existsSync12(root)) return [];
|
|
13741
13808
|
const out = [];
|
|
13742
13809
|
for (const entry of await readdir(root, { withFileTypes: true })) {
|
|
13743
13810
|
const resolved = path17.join(root, entry.name);
|
|
@@ -13775,7 +13842,7 @@ function parseSelector(selector) {
|
|
|
13775
13842
|
}
|
|
13776
13843
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
13777
13844
|
const local = path17.resolve(target);
|
|
13778
|
-
if (
|
|
13845
|
+
if (existsSync12(local)) {
|
|
13779
13846
|
const recipePath = path17.basename(local) === RECIPE_FILE ? local : path17.join(local, RECIPE_FILE);
|
|
13780
13847
|
return readRecipeFile(recipePath, false);
|
|
13781
13848
|
}
|
|
@@ -13791,7 +13858,7 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
13791
13858
|
}
|
|
13792
13859
|
async function verifyFile(root, file) {
|
|
13793
13860
|
const absolute = path17.resolve(root, ...file.path.split("/"));
|
|
13794
|
-
if (!
|
|
13861
|
+
if (!existsSync12(absolute)) {
|
|
13795
13862
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
13796
13863
|
}
|
|
13797
13864
|
const actualSha256 = await sha256File(absolute);
|
|
@@ -13869,7 +13936,7 @@ async function installRecipe(target, options = {}) {
|
|
|
13869
13936
|
})));
|
|
13870
13937
|
if (!options.force) {
|
|
13871
13938
|
for (const file of files) {
|
|
13872
|
-
if (!
|
|
13939
|
+
if (!existsSync12(file.path)) continue;
|
|
13873
13940
|
const current = await readFile9(file.path);
|
|
13874
13941
|
if (!current.equals(file.data)) {
|
|
13875
13942
|
throw new OverwriteRefusedError(
|
|
@@ -13895,7 +13962,7 @@ async function installRecipe(target, options = {}) {
|
|
|
13895
13962
|
|
|
13896
13963
|
// src/pipeline/audit.ts
|
|
13897
13964
|
import { readFile as readFile10 } from "fs/promises";
|
|
13898
|
-
import { existsSync as
|
|
13965
|
+
import { existsSync as existsSync13 } from "fs";
|
|
13899
13966
|
import path18 from "path";
|
|
13900
13967
|
function paletteDistance(asset, reference) {
|
|
13901
13968
|
if (!asset.length || !reference.length) return 0;
|
|
@@ -13932,7 +13999,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
13932
13999
|
const unreadable = [];
|
|
13933
14000
|
for (const spec of mine) {
|
|
13934
14001
|
for (const output of resolveSpecOutputs(spec, lock, loaded.root)) {
|
|
13935
|
-
if (!
|
|
14002
|
+
if (!existsSync13(output.absolutePath)) {
|
|
13936
14003
|
missing.push(output.id);
|
|
13937
14004
|
continue;
|
|
13938
14005
|
}
|
|
@@ -13962,7 +14029,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
13962
14029
|
const refPalettes = [];
|
|
13963
14030
|
for (const img of style.styleImages) {
|
|
13964
14031
|
const abs = path18.resolve(loaded.root, img.path);
|
|
13965
|
-
if (!
|
|
14032
|
+
if (!existsSync13(abs)) continue;
|
|
13966
14033
|
try {
|
|
13967
14034
|
refPalettes.push(extractPalette(decodePng(await readFile10(abs)), 12));
|
|
13968
14035
|
} catch {
|
|
@@ -14041,7 +14108,7 @@ function hex(c) {
|
|
|
14041
14108
|
|
|
14042
14109
|
// src/pipeline/quality-regression.ts
|
|
14043
14110
|
import path19 from "path";
|
|
14044
|
-
import { existsSync as
|
|
14111
|
+
import { existsSync as existsSync14 } from "fs";
|
|
14045
14112
|
import { readFile as readFile11 } from "fs/promises";
|
|
14046
14113
|
import { z as z5 } from "zod";
|
|
14047
14114
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
@@ -14284,7 +14351,7 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14284
14351
|
cases
|
|
14285
14352
|
});
|
|
14286
14353
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
14287
|
-
if (
|
|
14354
|
+
if (existsSync14(absolute) && !options.force) {
|
|
14288
14355
|
const current = await readFile11(absolute);
|
|
14289
14356
|
if (!current.equals(data)) {
|
|
14290
14357
|
throw new OverwriteRefusedError(
|
|
@@ -14296,6 +14363,63 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14296
14363
|
const result = await writeArtifactBundle([{ path: absolute, data }]);
|
|
14297
14364
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
14298
14365
|
}
|
|
14366
|
+
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
14367
|
+
const absolute = path19.resolve(baselinePath);
|
|
14368
|
+
if (!existsSync14(absolute)) {
|
|
14369
|
+
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
14370
|
+
}
|
|
14371
|
+
let raw;
|
|
14372
|
+
try {
|
|
14373
|
+
raw = JSON.parse(await readFile11(absolute, "utf8"));
|
|
14374
|
+
} catch (error) {
|
|
14375
|
+
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
14376
|
+
}
|
|
14377
|
+
if (!Array.isArray(raw.cases)) throw new Error(`Quality baseline ${absolute} has no cases array.`);
|
|
14378
|
+
const byId = new Map(inputs.map((input) => [input.id, input]));
|
|
14379
|
+
const unknown = only.filter((id) => !byId.has(id));
|
|
14380
|
+
if (unknown.length) {
|
|
14381
|
+
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
14382
|
+
}
|
|
14383
|
+
const root = path19.dirname(absolute);
|
|
14384
|
+
const cases = [...raw.cases];
|
|
14385
|
+
const report = [];
|
|
14386
|
+
for (const id of only) {
|
|
14387
|
+
const input = byId.get(id);
|
|
14388
|
+
if (path19.resolve(input.file) === absolute || input.record && path19.resolve(input.record) === absolute) {
|
|
14389
|
+
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
14390
|
+
}
|
|
14391
|
+
const expected = await measureImageQuality(input.file);
|
|
14392
|
+
let record;
|
|
14393
|
+
if (input.record) {
|
|
14394
|
+
await verifyRecordForImage(input.record, input.file);
|
|
14395
|
+
record = { path: portableRelative2(root, input.record), sha256: await sha256File(input.record) };
|
|
14396
|
+
}
|
|
14397
|
+
const index = cases.findIndex((entry) => entry.id === id);
|
|
14398
|
+
const before = index >= 0 ? cases[index].expected ?? {} : {};
|
|
14399
|
+
const next = {
|
|
14400
|
+
id,
|
|
14401
|
+
file: portableRelative2(root, input.file),
|
|
14402
|
+
...record ? { record } : {},
|
|
14403
|
+
expected,
|
|
14404
|
+
tolerances: index >= 0 && cases[index].tolerances ? cases[index].tolerances : input.tolerances
|
|
14405
|
+
};
|
|
14406
|
+
if (index >= 0) cases[index] = next;
|
|
14407
|
+
else cases.push(next);
|
|
14408
|
+
const changes = [];
|
|
14409
|
+
for (const metric of Object.keys(expected)) {
|
|
14410
|
+
if (JSON.stringify(before[metric]) !== JSON.stringify(expected[metric])) {
|
|
14411
|
+
changes.push({ metric, before: before[metric] ?? null, after: expected[metric] });
|
|
14412
|
+
}
|
|
14413
|
+
}
|
|
14414
|
+
report.push({ id, kind: index < 0 ? "added" : changes.length ? "updated" : "unchanged", changes });
|
|
14415
|
+
}
|
|
14416
|
+
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
14417
|
+
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
14418
|
+
const current = await readFile11(absolute);
|
|
14419
|
+
const changed = !current.equals(data);
|
|
14420
|
+
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
14421
|
+
return { baseline, path: absolute, changed, cases: report };
|
|
14422
|
+
}
|
|
14299
14423
|
async function readQualityBaseline(baselinePath) {
|
|
14300
14424
|
const absolute = path19.resolve(baselinePath);
|
|
14301
14425
|
let raw;
|
|
@@ -14306,9 +14430,23 @@ async function readQualityBaseline(baselinePath) {
|
|
|
14306
14430
|
}
|
|
14307
14431
|
const parsed = QualityBaselineSchema.safeParse(raw);
|
|
14308
14432
|
if (!parsed.success) {
|
|
14433
|
+
const cases = raw?.cases;
|
|
14434
|
+
const where = (issuePath) => {
|
|
14435
|
+
if (issuePath[0] === "cases" && typeof issuePath[1] === "number") {
|
|
14436
|
+
const id = cases?.[issuePath[1]]?.id;
|
|
14437
|
+
const rest = issuePath.slice(2).join(".");
|
|
14438
|
+
return typeof id === "string" ? `cases[${id}]${rest ? `.${rest}` : ""}` : issuePath.join(".");
|
|
14439
|
+
}
|
|
14440
|
+
return issuePath.join(".") || "$";
|
|
14441
|
+
};
|
|
14442
|
+
const missing = [...new Set(parsed.error.issues.flatMap((issue) => {
|
|
14443
|
+
const id = issue.path[0] === "cases" && typeof issue.path[1] === "number" ? cases?.[issue.path[1]]?.id : void 0;
|
|
14444
|
+
return issue.code === "invalid_type" && issue.received === "undefined" && typeof id === "string" ? [id] : [];
|
|
14445
|
+
}))];
|
|
14309
14446
|
throw new Error(
|
|
14310
14447
|
`Invalid quality baseline ${absolute}:
|
|
14311
|
-
` + parsed.error.issues.map((issue) => ` ${issue.path
|
|
14448
|
+
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
14449
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path19.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
14312
14450
|
);
|
|
14313
14451
|
}
|
|
14314
14452
|
return parsed.data;
|
|
@@ -14424,13 +14562,13 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
14424
14562
|
}
|
|
14425
14563
|
|
|
14426
14564
|
// src/pipeline/cache-health.ts
|
|
14427
|
-
import { existsSync as
|
|
14565
|
+
import { existsSync as existsSync18 } from "fs";
|
|
14428
14566
|
import { readFile as readFile14, readdir as readdir2, rm as rm6 } from "fs/promises";
|
|
14429
14567
|
import path22 from "path";
|
|
14430
14568
|
|
|
14431
14569
|
// src/cache.ts
|
|
14432
14570
|
import { mkdir as mkdir6, readFile as readFile12, rename as rename4, rm as rm4, writeFile as writeFile6 } from "fs/promises";
|
|
14433
|
-
import { existsSync as
|
|
14571
|
+
import { existsSync as existsSync15 } from "fs";
|
|
14434
14572
|
import pathModule from "path";
|
|
14435
14573
|
import { z as z6 } from "zod";
|
|
14436
14574
|
var HashCacheSchema = z6.object({
|
|
@@ -14446,7 +14584,7 @@ function parseCache(value) {
|
|
|
14446
14584
|
return HashCacheSchema.parse(value);
|
|
14447
14585
|
}
|
|
14448
14586
|
async function loadCache(path39) {
|
|
14449
|
-
if (!
|
|
14587
|
+
if (!existsSync15(path39)) return { version: 1, hashes: {} };
|
|
14450
14588
|
try {
|
|
14451
14589
|
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile12(path39, "utf8")));
|
|
14452
14590
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
@@ -14495,11 +14633,11 @@ function cachePathFor(lockPath) {
|
|
|
14495
14633
|
}
|
|
14496
14634
|
|
|
14497
14635
|
// src/pipeline/history.ts
|
|
14498
|
-
import { existsSync as
|
|
14636
|
+
import { existsSync as existsSync17 } from "fs";
|
|
14499
14637
|
import path21 from "path";
|
|
14500
14638
|
|
|
14501
14639
|
// src/pipeline/fetch.ts
|
|
14502
|
-
import { existsSync as
|
|
14640
|
+
import { existsSync as existsSync16, readFileSync as readFileSync5 } from "fs";
|
|
14503
14641
|
import { mkdir as mkdir7, readFile as readFile13, rename as rename5, rm as rm5, writeFile as writeFile7 } from "fs/promises";
|
|
14504
14642
|
import path20 from "path";
|
|
14505
14643
|
async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
@@ -14519,15 +14657,15 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14519
14657
|
if (spec && e.specHash === spec.specHash && e.outputs.length && !postprocessCurrent(e, spec)) {
|
|
14520
14658
|
return Boolean(opts.force) || e.outputs.every((output) => {
|
|
14521
14659
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14522
|
-
return
|
|
14660
|
+
return existsSync16(file) && sha256(readFileSync5(file)) === output.sha256;
|
|
14523
14661
|
});
|
|
14524
14662
|
}
|
|
14525
14663
|
if (!opts.repair) return false;
|
|
14526
14664
|
if (e.outputs.length === 0 || !spec) return true;
|
|
14527
14665
|
return e.outputs.some((output) => {
|
|
14528
14666
|
const file = resolveOutputPath(output.path, spec.root);
|
|
14529
|
-
if (!
|
|
14530
|
-
const current = sha256(
|
|
14667
|
+
if (!existsSync16(file)) return true;
|
|
14668
|
+
const current = sha256(readFileSync5(file));
|
|
14531
14669
|
if (current === output.sha256) return false;
|
|
14532
14670
|
return Boolean(opts.force) || (e.supersededOutputs ?? []).some((old) => old.sha256 === current);
|
|
14533
14671
|
});
|
|
@@ -14617,7 +14755,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14617
14755
|
}
|
|
14618
14756
|
let raw = null;
|
|
14619
14757
|
let final = null;
|
|
14620
|
-
if (
|
|
14758
|
+
if (existsSync16(target)) {
|
|
14621
14759
|
const currentHash = await sha256File(target);
|
|
14622
14760
|
if (recorded && currentHash === recorded.sha256) {
|
|
14623
14761
|
if (!fresh && !reapply) {
|
|
@@ -14763,7 +14901,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
14763
14901
|
}
|
|
14764
14902
|
async function readCachedMedia(cacheDir, hash, mediaType) {
|
|
14765
14903
|
const file = path20.join(cacheDir, cacheFileName(hash, mediaType));
|
|
14766
|
-
if (!
|
|
14904
|
+
if (!existsSync16(file)) return null;
|
|
14767
14905
|
try {
|
|
14768
14906
|
const buf = await readFile13(file);
|
|
14769
14907
|
if (sha256(buf) !== hash) return null;
|
|
@@ -14784,7 +14922,7 @@ async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
|
|
|
14784
14922
|
try {
|
|
14785
14923
|
await rename5(tmp, file);
|
|
14786
14924
|
} catch (err) {
|
|
14787
|
-
if (!
|
|
14925
|
+
if (!existsSync16(file)) throw err;
|
|
14788
14926
|
} finally {
|
|
14789
14927
|
await rm5(tmp, { force: true });
|
|
14790
14928
|
}
|
|
@@ -14906,7 +15044,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
14906
15044
|
}
|
|
14907
15045
|
for (let i = 0; i < entry.outputs.length; i++) {
|
|
14908
15046
|
const file = currentEntryOutputPath(entry, spec, i);
|
|
14909
|
-
if (!
|
|
15047
|
+
if (!existsSync17(file)) continue;
|
|
14910
15048
|
if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
|
|
14911
15049
|
throw new OverwriteRefusedError(
|
|
14912
15050
|
`${path21.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
|
|
@@ -14969,7 +15107,7 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
14969
15107
|
|
|
14970
15108
|
// src/pipeline/cache-health.ts
|
|
14971
15109
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
14972
|
-
if (options.prune && !
|
|
15110
|
+
if (options.prune && !existsSync18(lockPath)) {
|
|
14973
15111
|
throw new Error(`Refusing to prune without an existing lockfile at ${path22.resolve(lockPath)}`);
|
|
14974
15112
|
}
|
|
14975
15113
|
const contentDir = path22.resolve(path22.dirname(lockPath), ".pixelkiln", "cache");
|
|
@@ -15012,7 +15150,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
15012
15150
|
async function inspectContentCache(contentDir, referenced) {
|
|
15013
15151
|
const report = {
|
|
15014
15152
|
path: contentDir,
|
|
15015
|
-
exists:
|
|
15153
|
+
exists: existsSync18(contentDir),
|
|
15016
15154
|
files: 0,
|
|
15017
15155
|
bytes: 0,
|
|
15018
15156
|
valid: 0,
|
|
@@ -15076,7 +15214,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
15076
15214
|
async function inspectRemoteHashCache(remotePath) {
|
|
15077
15215
|
const report = {
|
|
15078
15216
|
path: remotePath,
|
|
15079
|
-
exists:
|
|
15217
|
+
exists: existsSync18(remotePath),
|
|
15080
15218
|
entries: 0,
|
|
15081
15219
|
valid: 0,
|
|
15082
15220
|
invalidIds: [],
|
|
@@ -15100,7 +15238,7 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
15100
15238
|
}
|
|
15101
15239
|
|
|
15102
15240
|
// src/pipeline/pack.ts
|
|
15103
|
-
import { readFileSync as
|
|
15241
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
15104
15242
|
import path23 from "path";
|
|
15105
15243
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
15106
15244
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
@@ -15134,7 +15272,7 @@ function packSprites(inputs, options = {}) {
|
|
|
15134
15272
|
for (const input of ordered) {
|
|
15135
15273
|
let sourceHash = null;
|
|
15136
15274
|
try {
|
|
15137
|
-
const bytes =
|
|
15275
|
+
const bytes = readFileSync6(input.path);
|
|
15138
15276
|
sourceHash = sha256(bytes);
|
|
15139
15277
|
const png = decodePng(bytes);
|
|
15140
15278
|
sprites.push({ id: input.id, width: png.width, height: png.height, pixels: png.pixels });
|
|
@@ -15293,7 +15431,7 @@ function mountSprites(placements, options) {
|
|
|
15293
15431
|
for (const p of placements) {
|
|
15294
15432
|
let sourceHash = null;
|
|
15295
15433
|
try {
|
|
15296
|
-
const bytes =
|
|
15434
|
+
const bytes = readFileSync6(p.path);
|
|
15297
15435
|
sourceHash = sha256(bytes);
|
|
15298
15436
|
const png = decodePng(bytes);
|
|
15299
15437
|
if (png.width > cellWidth || png.height > cellHeight) {
|
|
@@ -15397,7 +15535,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
15397
15535
|
`Nothing to mount for style "${styleId}": ${ids.length} asset(s) declare a cell, but none has generated output or a \`source\`. Run \`pixelkiln gen --style ${styleId}\`, or point each at a file.${detail}`
|
|
15398
15536
|
);
|
|
15399
15537
|
}
|
|
15400
|
-
const basePng = mount.base ?
|
|
15538
|
+
const basePng = mount.base ? readFileSync6(path23.resolve(manifestDir, mount.base)) : void 0;
|
|
15401
15539
|
const mounted = mountSprites(placements, {
|
|
15402
15540
|
cellWidth: mount.cellWidth,
|
|
15403
15541
|
cellHeight: mount.cellHeight,
|
|
@@ -16251,7 +16389,7 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
16251
16389
|
}
|
|
16252
16390
|
|
|
16253
16391
|
// src/pipeline/doctor.ts
|
|
16254
|
-
import { constants, existsSync as
|
|
16392
|
+
import { constants, existsSync as existsSync19 } from "fs";
|
|
16255
16393
|
import { access, stat as stat2 } from "fs/promises";
|
|
16256
16394
|
import path24 from "path";
|
|
16257
16395
|
async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
@@ -16319,11 +16457,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16319
16457
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
16320
16458
|
let hasCache = false;
|
|
16321
16459
|
for (const output of entry.outputs) {
|
|
16322
|
-
const
|
|
16460
|
+
const cached2 = path24.join(
|
|
16323
16461
|
cacheDir,
|
|
16324
16462
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
16325
16463
|
);
|
|
16326
|
-
if (
|
|
16464
|
+
if (existsSync19(cached2) && await sha256File(cached2) === output.sha256) {
|
|
16327
16465
|
hasCache = true;
|
|
16328
16466
|
break;
|
|
16329
16467
|
}
|
|
@@ -16426,7 +16564,7 @@ async function nearestExistingDirectory(start) {
|
|
|
16426
16564
|
}
|
|
16427
16565
|
|
|
16428
16566
|
// src/pipeline/adopt.ts
|
|
16429
|
-
import { existsSync as
|
|
16567
|
+
import { existsSync as existsSync20 } from "fs";
|
|
16430
16568
|
import { readFile as readFile15, writeFile as writeFile8 } from "fs/promises";
|
|
16431
16569
|
import path25 from "path";
|
|
16432
16570
|
async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
@@ -16439,7 +16577,7 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
16439
16577
|
const localByHash = /* @__PURE__ */ new Map();
|
|
16440
16578
|
const unmatchedLocal = [];
|
|
16441
16579
|
for (const spec of specs) {
|
|
16442
|
-
if (!
|
|
16580
|
+
if (!existsSync20(spec.outFile)) {
|
|
16443
16581
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
16444
16582
|
continue;
|
|
16445
16583
|
}
|
|
@@ -16560,13 +16698,124 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
16560
16698
|
return count;
|
|
16561
16699
|
}
|
|
16562
16700
|
|
|
16563
|
-
// src/
|
|
16701
|
+
// src/pipeline/import.ts
|
|
16564
16702
|
import { existsSync as existsSync21 } from "fs";
|
|
16565
|
-
import { readFile as
|
|
16703
|
+
import { readFile as readFile16 } from "fs/promises";
|
|
16704
|
+
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
16705
|
+
const png = decodePng(bytes);
|
|
16706
|
+
const at = now.toISOString();
|
|
16707
|
+
return {
|
|
16708
|
+
styleId: spec.styleId,
|
|
16709
|
+
assetId: spec.assetId,
|
|
16710
|
+
specHash: spec.specHash,
|
|
16711
|
+
generator: spec.generator,
|
|
16712
|
+
prompt: spec.prompt,
|
|
16713
|
+
width: png.width,
|
|
16714
|
+
height: png.height,
|
|
16715
|
+
jobId: opts.objectId ?? null,
|
|
16716
|
+
objectId: opts.objectId ?? null,
|
|
16717
|
+
reviewObjectId: null,
|
|
16718
|
+
candidateIndex: null,
|
|
16719
|
+
status: "downloaded",
|
|
16720
|
+
error: null,
|
|
16721
|
+
sourceUrl: null,
|
|
16722
|
+
sourceUrls: [],
|
|
16723
|
+
outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
|
|
16724
|
+
submittedAt: null,
|
|
16725
|
+
downloadedAt: at,
|
|
16726
|
+
cost: 0,
|
|
16727
|
+
costUnit: spec.costUnit,
|
|
16728
|
+
provider: spec.provider,
|
|
16729
|
+
imported: {
|
|
16730
|
+
source: opts.source ?? "external",
|
|
16731
|
+
...opts.note ? { note: opts.note } : {},
|
|
16732
|
+
importedAt: at
|
|
16733
|
+
}
|
|
16734
|
+
};
|
|
16735
|
+
}
|
|
16736
|
+
function unimportable(spec) {
|
|
16737
|
+
if (spec.character) return "a character is several files; import it with account adopt";
|
|
16738
|
+
if (spec.vfx) return "an effect is rendered from its recipe, not imported";
|
|
16739
|
+
if (!spec.outFile.toLowerCase().endsWith(".png")) return "only a single PNG output can be imported";
|
|
16740
|
+
return null;
|
|
16741
|
+
}
|
|
16742
|
+
async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
16743
|
+
if (opts.objectId && specs.length !== 1) {
|
|
16744
|
+
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
16745
|
+
}
|
|
16746
|
+
const imported = [];
|
|
16747
|
+
const skipped = [];
|
|
16748
|
+
for (const spec of specs) {
|
|
16749
|
+
const key = lockKey(spec.styleId, spec.assetId);
|
|
16750
|
+
const reason = unimportable(spec);
|
|
16751
|
+
if (reason) {
|
|
16752
|
+
skipped.push({ key, reason });
|
|
16753
|
+
continue;
|
|
16754
|
+
}
|
|
16755
|
+
if (!existsSync21(spec.outFile)) {
|
|
16756
|
+
skipped.push({ key, reason: `no file at ${spec.outFile}` });
|
|
16757
|
+
continue;
|
|
16758
|
+
}
|
|
16759
|
+
if (lock.entries[key] && !opts.force) {
|
|
16760
|
+
skipped.push({ key, reason: "already in the lockfile (use --force to replace it)" });
|
|
16761
|
+
continue;
|
|
16762
|
+
}
|
|
16763
|
+
let patch;
|
|
16764
|
+
try {
|
|
16765
|
+
patch = buildImportedEntry(spec, await readFile16(spec.outFile), opts);
|
|
16766
|
+
} catch (error) {
|
|
16767
|
+
skipped.push({ key, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
16768
|
+
continue;
|
|
16769
|
+
}
|
|
16770
|
+
if (opts.dryRun) {
|
|
16771
|
+
imported.push({ key, entry: patch });
|
|
16772
|
+
continue;
|
|
16773
|
+
}
|
|
16774
|
+
imported.push({ key, entry: upsert(lock, key, patch) });
|
|
16775
|
+
}
|
|
16776
|
+
if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
|
|
16777
|
+
return { imported, skipped };
|
|
16778
|
+
}
|
|
16779
|
+
async function reportSpecHashes(specs, lock) {
|
|
16780
|
+
const reports = [];
|
|
16781
|
+
for (const spec of specs) {
|
|
16782
|
+
const key = lockKey(spec.styleId, spec.assetId);
|
|
16783
|
+
let bytes = null;
|
|
16784
|
+
if (existsSync21(spec.outFile)) bytes = await readFile16(spec.outFile);
|
|
16785
|
+
let wouldImport = null;
|
|
16786
|
+
if (bytes && !unimportable(spec)) {
|
|
16787
|
+
try {
|
|
16788
|
+
wouldImport = buildImportedEntry(spec, bytes);
|
|
16789
|
+
} catch {
|
|
16790
|
+
wouldImport = null;
|
|
16791
|
+
}
|
|
16792
|
+
}
|
|
16793
|
+
const entry = lock.entries[key];
|
|
16794
|
+
const fileSha256 = bytes ? sha256(bytes) : null;
|
|
16795
|
+
const outputSha256 = entry?.outputs[0]?.sha256 ?? null;
|
|
16796
|
+
reports.push({
|
|
16797
|
+
key,
|
|
16798
|
+
specHash: spec.specHash,
|
|
16799
|
+
file: spec.outFile,
|
|
16800
|
+
fileSha256,
|
|
16801
|
+
lock: entry ? {
|
|
16802
|
+
specHash: entry.specHash,
|
|
16803
|
+
outputSha256,
|
|
16804
|
+
matches: entry.specHash === spec.specHash && outputSha256 !== null && outputSha256 === fileSha256
|
|
16805
|
+
} : null,
|
|
16806
|
+
wouldImport
|
|
16807
|
+
});
|
|
16808
|
+
}
|
|
16809
|
+
return reports;
|
|
16810
|
+
}
|
|
16811
|
+
|
|
16812
|
+
// src/pick/server.ts
|
|
16813
|
+
import { existsSync as existsSync23 } from "fs";
|
|
16814
|
+
import { readFile as readFile19 } from "fs/promises";
|
|
16566
16815
|
|
|
16567
16816
|
// src/pipeline/init.ts
|
|
16568
|
-
import { readdir as readdir3, readFile as
|
|
16569
|
-
import { existsSync as
|
|
16817
|
+
import { readdir as readdir3, readFile as readFile17, writeFile as writeFile9 } from "fs/promises";
|
|
16818
|
+
import { existsSync as existsSync22 } from "fs";
|
|
16570
16819
|
import path26 from "path";
|
|
16571
16820
|
function pngSize(buf) {
|
|
16572
16821
|
if (buf.length < 24) return null;
|
|
@@ -16595,7 +16844,7 @@ async function scanAssets(root, opts = {}) {
|
|
|
16595
16844
|
const skipped = [];
|
|
16596
16845
|
const seen = /* @__PURE__ */ new Map();
|
|
16597
16846
|
for (const file of files.sort()) {
|
|
16598
|
-
const size = pngSize(await
|
|
16847
|
+
const size = pngSize(await readFile17(file));
|
|
16599
16848
|
if (!size) {
|
|
16600
16849
|
skipped.push(`${file} (not a readable PNG)`);
|
|
16601
16850
|
continue;
|
|
@@ -17076,7 +17325,7 @@ document.getElementById('submit').onclick = async () => {
|
|
|
17076
17325
|
|
|
17077
17326
|
// src/pick/review-server.ts
|
|
17078
17327
|
import { createServer } from "http";
|
|
17079
|
-
import { readFile as
|
|
17328
|
+
import { readFile as readFile18 } from "fs/promises";
|
|
17080
17329
|
function serveReviewPage(opts) {
|
|
17081
17330
|
const log = opts.onProgress ?? (() => {
|
|
17082
17331
|
});
|
|
@@ -17085,7 +17334,7 @@ function serveReviewPage(opts) {
|
|
|
17085
17334
|
if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
|
|
17086
17335
|
try {
|
|
17087
17336
|
const asset = opts.assets.get(req.url);
|
|
17088
|
-
const bytes = await
|
|
17337
|
+
const bytes = await readFile18(asset.path);
|
|
17089
17338
|
res.writeHead(200, {
|
|
17090
17339
|
"Content-Type": asset.contentType,
|
|
17091
17340
|
"Cache-Control": "no-store",
|
|
@@ -17161,13 +17410,13 @@ async function currentArt(entry, spec) {
|
|
|
17161
17410
|
const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
|
|
17162
17411
|
if (!previous) return null;
|
|
17163
17412
|
const file = resolveOutputPath(previous.path, spec.root);
|
|
17164
|
-
if (!
|
|
17413
|
+
if (!existsSync23(file)) return null;
|
|
17165
17414
|
const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
|
|
17166
17415
|
if (!contentType) return null;
|
|
17167
17416
|
let width = entry.width;
|
|
17168
17417
|
let height = entry.height;
|
|
17169
17418
|
if (contentType === "image/png") {
|
|
17170
|
-
const size = pngSize(await
|
|
17419
|
+
const size = pngSize(await readFile19(file));
|
|
17171
17420
|
if (size) ({ width, height } = size);
|
|
17172
17421
|
}
|
|
17173
17422
|
return { path: file, contentType, width, height };
|
|
@@ -17175,7 +17424,7 @@ async function currentArt(entry, spec) {
|
|
|
17175
17424
|
async function cachedFrame(url) {
|
|
17176
17425
|
if (!url.startsWith("file://")) return null;
|
|
17177
17426
|
const file = url.slice("file://".length);
|
|
17178
|
-
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await
|
|
17427
|
+
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await readFile19(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
|
|
17179
17428
|
return { path: file, contentType };
|
|
17180
17429
|
}
|
|
17181
17430
|
async function prepareReview(provider, lock, opts = {}) {
|
|
@@ -17201,15 +17450,15 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
17201
17450
|
const frameAssets = [];
|
|
17202
17451
|
const frameSizes = [];
|
|
17203
17452
|
for (const [index, url] of urls.entries()) {
|
|
17204
|
-
const
|
|
17205
|
-
if (!
|
|
17453
|
+
const cached2 = await cachedFrame(url);
|
|
17454
|
+
if (!cached2) {
|
|
17206
17455
|
frameUrls.push(url);
|
|
17207
17456
|
frameSizes.push(null);
|
|
17208
17457
|
continue;
|
|
17209
17458
|
}
|
|
17210
|
-
frameSizes.push(
|
|
17459
|
+
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await readFile19(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
17211
17460
|
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
17212
|
-
frameAssets.push([route,
|
|
17461
|
+
frameAssets.push([route, cached2]);
|
|
17213
17462
|
frameUrls.push(route);
|
|
17214
17463
|
}
|
|
17215
17464
|
const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String(groups.length))}` : null;
|
|
@@ -17361,13 +17610,13 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
17361
17610
|
|
|
17362
17611
|
// src/gallery/snapshot.ts
|
|
17363
17612
|
import { createHash as createHash5 } from "crypto";
|
|
17364
|
-
import { existsSync as
|
|
17365
|
-
import { readFile as
|
|
17613
|
+
import { existsSync as existsSync29 } from "fs";
|
|
17614
|
+
import { readFile as readFile26, stat as stat3 } from "fs/promises";
|
|
17366
17615
|
import path34 from "path";
|
|
17367
17616
|
|
|
17368
17617
|
// src/workspace.ts
|
|
17369
|
-
import { mkdir as mkdir8, readFile as
|
|
17370
|
-
import { existsSync as
|
|
17618
|
+
import { mkdir as mkdir8, readFile as readFile20, rename as rename6, rm as rm7, writeFile as writeFile10 } from "fs/promises";
|
|
17619
|
+
import { existsSync as existsSync24 } from "fs";
|
|
17371
17620
|
import path27 from "path";
|
|
17372
17621
|
import { z as z7 } from "zod";
|
|
17373
17622
|
var WorkspaceProjectSchema = z7.object({
|
|
@@ -17393,10 +17642,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
|
|
|
17393
17642
|
);
|
|
17394
17643
|
}
|
|
17395
17644
|
async function loadWorkspace(workspacePath) {
|
|
17396
|
-
if (!
|
|
17645
|
+
if (!existsSync24(workspacePath)) return { version: 1, projects: [] };
|
|
17397
17646
|
let raw;
|
|
17398
17647
|
try {
|
|
17399
|
-
raw = JSON.parse(await
|
|
17648
|
+
raw = JSON.parse(await readFile20(workspacePath, "utf8"));
|
|
17400
17649
|
} catch (err) {
|
|
17401
17650
|
throw new ProjectError(
|
|
17402
17651
|
`Workspace catalog at ${workspacePath} is malformed:
|
|
@@ -17445,14 +17694,14 @@ function validateWorkspace(ws, dir) {
|
|
|
17445
17694
|
message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
|
|
17446
17695
|
});
|
|
17447
17696
|
}
|
|
17448
|
-
if (!
|
|
17697
|
+
if (!existsSync24(manifestPath)) {
|
|
17449
17698
|
diagnostics.push({
|
|
17450
17699
|
id: "missing-manifest",
|
|
17451
17700
|
level: "error",
|
|
17452
17701
|
message: `project "${project.id}" manifest not found: ${manifestPath}`
|
|
17453
17702
|
});
|
|
17454
17703
|
}
|
|
17455
|
-
if (!
|
|
17704
|
+
if (!existsSync24(lockPath)) {
|
|
17456
17705
|
diagnostics.push({
|
|
17457
17706
|
id: "missing-lock",
|
|
17458
17707
|
level: "error",
|
|
@@ -17499,12 +17748,12 @@ function validateWorkspace(ws, dir) {
|
|
|
17499
17748
|
}
|
|
17500
17749
|
|
|
17501
17750
|
// src/gallery/edit.ts
|
|
17502
|
-
import { readFile as
|
|
17751
|
+
import { readFile as readFile25, rename as rename9, writeFile as writeFile16 } from "fs/promises";
|
|
17503
17752
|
import path33 from "path";
|
|
17504
17753
|
import { z as z13 } from "zod";
|
|
17505
17754
|
|
|
17506
17755
|
// src/manifest-edit.ts
|
|
17507
|
-
import { readFile as
|
|
17756
|
+
import { readFile as readFile21, rename as rename7, rm as rm8, writeFile as writeFile11 } from "fs/promises";
|
|
17508
17757
|
import path28 from "path";
|
|
17509
17758
|
import { z as z8 } from "zod";
|
|
17510
17759
|
var HexSha = z8.string().regex(/^[0-9a-f]{64}$/);
|
|
@@ -17929,7 +18178,7 @@ function applyEdit(raw, edit) {
|
|
|
17929
18178
|
}
|
|
17930
18179
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
17931
18180
|
const absolute = path28.resolve(manifestPath);
|
|
17932
|
-
const original = await
|
|
18181
|
+
const original = await readFile21(absolute, "utf8");
|
|
17933
18182
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
17934
18183
|
let raw;
|
|
17935
18184
|
try {
|
|
@@ -17973,8 +18222,8 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
17973
18222
|
}
|
|
17974
18223
|
|
|
17975
18224
|
// src/pipeline/hand-edit.ts
|
|
17976
|
-
import { existsSync as
|
|
17977
|
-
import { copyFile, mkdir as mkdir9, readFile as
|
|
18225
|
+
import { existsSync as existsSync25 } from "fs";
|
|
18226
|
+
import { copyFile, mkdir as mkdir9, readFile as readFile22, rename as rename8, rm as rm9, writeFile as writeFile12 } from "fs/promises";
|
|
17978
18227
|
import path29 from "path";
|
|
17979
18228
|
import { z as z9 } from "zod";
|
|
17980
18229
|
var HAND_EDIT_DIR = "edits";
|
|
@@ -17997,10 +18246,10 @@ function handEditBases(spec, lock) {
|
|
|
17997
18246
|
}));
|
|
17998
18247
|
if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
|
|
17999
18248
|
if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
|
|
18000
|
-
if (!members.every((member) =>
|
|
18249
|
+
if (!members.every((member) => existsSync25(member.path))) return null;
|
|
18001
18250
|
return members.map(({ role, path: file }) => ({ role, path: file }));
|
|
18002
18251
|
}
|
|
18003
|
-
return
|
|
18252
|
+
return existsSync25(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
|
|
18004
18253
|
}
|
|
18005
18254
|
function handEditBase(spec, lock) {
|
|
18006
18255
|
const bases = handEditBases(spec, lock);
|
|
@@ -18035,7 +18284,7 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
18035
18284
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
18036
18285
|
let created = false;
|
|
18037
18286
|
for (const member of members) {
|
|
18038
|
-
if (
|
|
18287
|
+
if (existsSync25(member.path)) continue;
|
|
18039
18288
|
if (!member.base) {
|
|
18040
18289
|
throw new ManifestEditError(
|
|
18041
18290
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
@@ -18120,7 +18369,7 @@ function handEditProjectPath(editPath) {
|
|
|
18120
18369
|
async function readHandEditCompanion(editPath) {
|
|
18121
18370
|
let text;
|
|
18122
18371
|
try {
|
|
18123
|
-
text = await
|
|
18372
|
+
text = await readFile22(handEditCompanionPath(editPath), "utf8");
|
|
18124
18373
|
} catch {
|
|
18125
18374
|
return null;
|
|
18126
18375
|
}
|
|
@@ -18163,7 +18412,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
18163
18412
|
}
|
|
18164
18413
|
});
|
|
18165
18414
|
const bases = handEditBases(spec, lock);
|
|
18166
|
-
const expectedSize = bases?.[0] ? decodePng(await
|
|
18415
|
+
const expectedSize = bases?.[0] ? decodePng(await readFile22(bases[0].path)) : { width: spec.width, height: spec.height };
|
|
18167
18416
|
for (const [index, image] of decoded.entries()) {
|
|
18168
18417
|
if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
|
|
18169
18418
|
const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
|
|
@@ -18221,7 +18470,7 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
18221
18470
|
}
|
|
18222
18471
|
|
|
18223
18472
|
// src/gallery/upload.ts
|
|
18224
|
-
import { existsSync as
|
|
18473
|
+
import { existsSync as existsSync26 } from "fs";
|
|
18225
18474
|
import { mkdir as mkdir10, writeFile as writeFile13 } from "fs/promises";
|
|
18226
18475
|
import path30 from "path";
|
|
18227
18476
|
import { z as z10 } from "zod";
|
|
@@ -18253,7 +18502,7 @@ async function saveProjectImage(root, request) {
|
|
|
18253
18502
|
if (metadata.format !== expected) {
|
|
18254
18503
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
18255
18504
|
}
|
|
18256
|
-
if (
|
|
18505
|
+
if (existsSync26(file) && !request.overwrite) {
|
|
18257
18506
|
throw new ManifestEditError(`${relative.split(path30.sep).join("/")} already exists; choose another name, or replace it`);
|
|
18258
18507
|
}
|
|
18259
18508
|
await mkdir10(path30.dirname(file), { recursive: true });
|
|
@@ -18262,8 +18511,8 @@ async function saveProjectImage(root, request) {
|
|
|
18262
18511
|
}
|
|
18263
18512
|
|
|
18264
18513
|
// src/gallery/image-revision.ts
|
|
18265
|
-
import { existsSync as
|
|
18266
|
-
import { readFile as
|
|
18514
|
+
import { existsSync as existsSync27 } from "fs";
|
|
18515
|
+
import { readFile as readFile23, rm as rm10, writeFile as writeFile14 } from "fs/promises";
|
|
18267
18516
|
import path31 from "path";
|
|
18268
18517
|
import { z as z11 } from "zod";
|
|
18269
18518
|
var InpaintRevisionRequestSchema = z11.object({
|
|
@@ -18291,7 +18540,7 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
18291
18540
|
const metadata = imageMetadata(bytes);
|
|
18292
18541
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
18293
18542
|
const file = path31.resolve(root, request.maskPath);
|
|
18294
|
-
const previous =
|
|
18543
|
+
const previous = existsSync27(file) ? await readFile23(file) : null;
|
|
18295
18544
|
const mask = await saveProjectImage(root, {
|
|
18296
18545
|
action: "upload-image",
|
|
18297
18546
|
path: request.maskPath,
|
|
@@ -18318,8 +18567,8 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
18318
18567
|
}
|
|
18319
18568
|
|
|
18320
18569
|
// src/gallery/skeleton.ts
|
|
18321
|
-
import { existsSync as
|
|
18322
|
-
import { mkdir as mkdir11, readFile as
|
|
18570
|
+
import { existsSync as existsSync28 } from "fs";
|
|
18571
|
+
import { mkdir as mkdir11, readFile as readFile24, rm as rm11, writeFile as writeFile15 } from "fs/promises";
|
|
18323
18572
|
import path32 from "path";
|
|
18324
18573
|
import { z as z12 } from "zod";
|
|
18325
18574
|
var SkeletonEstimateRequestSchema = z12.object({
|
|
@@ -18365,13 +18614,13 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
18365
18614
|
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path32.isAbsolute(relative)) {
|
|
18366
18615
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
18367
18616
|
}
|
|
18368
|
-
const existed =
|
|
18617
|
+
const existed = existsSync28(file);
|
|
18369
18618
|
let previous = null;
|
|
18370
18619
|
if (request.set) {
|
|
18371
18620
|
if (existed && !request.overwrite) {
|
|
18372
18621
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
18373
18622
|
}
|
|
18374
|
-
if (existed) previous = await
|
|
18623
|
+
if (existed) previous = await readFile24(file);
|
|
18375
18624
|
await mkdir11(path32.dirname(file), { recursive: true });
|
|
18376
18625
|
await writeFile15(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18377
18626
|
} else if (!existed) {
|
|
@@ -18413,7 +18662,7 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
18413
18662
|
if (relative.startsWith("..") || path32.isAbsolute(relative)) {
|
|
18414
18663
|
throw new ManifestEditError(`${key}'s keypoints file is outside the project; edit it by hand`);
|
|
18415
18664
|
}
|
|
18416
|
-
const current =
|
|
18665
|
+
const current = existsSync28(file) ? sha256(await readFile24(file)) : null;
|
|
18417
18666
|
if (current !== request.expectedSha256) {
|
|
18418
18667
|
throw Object.assign(
|
|
18419
18668
|
new Error(`${relative.split(path32.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
@@ -18485,7 +18734,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18485
18734
|
if (undo.success) {
|
|
18486
18735
|
const manifestPath2 = await manifestOf(undo.data.project);
|
|
18487
18736
|
if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
|
|
18488
|
-
const current = await
|
|
18737
|
+
const current = await readFile25(manifestPath2, "utf8");
|
|
18489
18738
|
if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
|
|
18490
18739
|
const stack = history.get(manifestPath2) ?? [];
|
|
18491
18740
|
const last = stack[stack.length - 1];
|
|
@@ -18502,10 +18751,10 @@ function createGalleryEditHandler(opts) {
|
|
|
18502
18751
|
return opts.reload();
|
|
18503
18752
|
}
|
|
18504
18753
|
const manifestPath = await manifestOf(body?.project);
|
|
18505
|
-
const before = manifestPath ? await
|
|
18754
|
+
const before = manifestPath ? await readFile25(manifestPath, "utf8").catch(() => null) : null;
|
|
18506
18755
|
const build = await apply(body);
|
|
18507
18756
|
if (manifestPath && before !== null) {
|
|
18508
|
-
const after = await
|
|
18757
|
+
const after = await readFile25(manifestPath, "utf8").catch(() => null);
|
|
18509
18758
|
if (after !== null && after !== before) {
|
|
18510
18759
|
const stack = history.get(manifestPath) ?? [];
|
|
18511
18760
|
stack.push({ before, afterSha: sha256(after) });
|
|
@@ -18681,7 +18930,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
18681
18930
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
18682
18931
|
const file = path34.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
18683
18932
|
let url = null;
|
|
18684
|
-
if (
|
|
18933
|
+
if (existsSync29(file)) {
|
|
18685
18934
|
const id = galleryMediaId(file);
|
|
18686
18935
|
media.set(id, { path: file, contentType: mediaType });
|
|
18687
18936
|
url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
|
|
@@ -18713,7 +18962,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
18713
18962
|
var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
|
|
18714
18963
|
async function samePixels(a, b) {
|
|
18715
18964
|
try {
|
|
18716
|
-
const [left, right] = await Promise.all([
|
|
18965
|
+
const [left, right] = await Promise.all([readFile26(a), readFile26(b)]);
|
|
18717
18966
|
if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
|
|
18718
18967
|
const x = decodePng(left);
|
|
18719
18968
|
const y = decodePng(right);
|
|
@@ -18814,7 +19063,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
18814
19063
|
outputPaths.map((file) => describeOutput(media, root, path34.resolve(root, file)))
|
|
18815
19064
|
);
|
|
18816
19065
|
const recordPath = path34.resolve(root, inspection.record);
|
|
18817
|
-
const recordExists =
|
|
19066
|
+
const recordExists = existsSync29(recordPath);
|
|
18818
19067
|
let options = null;
|
|
18819
19068
|
let check = null;
|
|
18820
19069
|
if (recordExists) {
|
|
@@ -18871,7 +19120,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18871
19120
|
const media = /* @__PURE__ */ new Map();
|
|
18872
19121
|
const plan = await buildPlan(specs, lock);
|
|
18873
19122
|
const items = [];
|
|
18874
|
-
const manifestText = await
|
|
19123
|
+
const manifestText = await readFile26(loaded.path, "utf8");
|
|
18875
19124
|
const manifestSha256 = sha256(manifestText);
|
|
18876
19125
|
const cacheDir = path34.resolve(path34.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
18877
19126
|
let rawStyles = {};
|
|
@@ -18902,7 +19151,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18902
19151
|
const editShas = await Promise.all(
|
|
18903
19152
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
18904
19153
|
const file = sourceOutputPath(spec.source, entry, index, root);
|
|
18905
|
-
return { file, sha256:
|
|
19154
|
+
return { file, sha256: existsSync29(file) ? await sha256File(file) : null };
|
|
18906
19155
|
})
|
|
18907
19156
|
);
|
|
18908
19157
|
edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
|
|
@@ -18910,7 +19159,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18910
19159
|
const companion = await readHandEditCompanion(editPath);
|
|
18911
19160
|
if (companion) {
|
|
18912
19161
|
const projectPath = handEditProjectPath(editPath);
|
|
18913
|
-
const project = companion.project &&
|
|
19162
|
+
const project = companion.project && existsSync29(projectPath) ? await fileInfo(projectPath) : null;
|
|
18914
19163
|
let projectUrl = null;
|
|
18915
19164
|
if (project) {
|
|
18916
19165
|
const id = galleryMediaId(projectPath);
|
|
@@ -18947,7 +19196,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18947
19196
|
}
|
|
18948
19197
|
} else if (spec.source) {
|
|
18949
19198
|
outputs = [await describeOutput(media, root, path34.resolve(root, spec.source))];
|
|
18950
|
-
} else if (!entry &&
|
|
19199
|
+
} else if (!entry && existsSync29(spec.outFile)) {
|
|
18951
19200
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
18952
19201
|
} else {
|
|
18953
19202
|
outputs = [];
|
|
@@ -19224,7 +19473,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19224
19473
|
root: loaded.root,
|
|
19225
19474
|
provider: loaded.manifest.provider,
|
|
19226
19475
|
account: project.account ?? null,
|
|
19227
|
-
manifestSha256: manifestSha256 ?? sha256(await
|
|
19476
|
+
manifestSha256: manifestSha256 ?? sha256(await readFile26(manifestPath, "utf8")),
|
|
19228
19477
|
historyLimit: historyLimit(loaded.manifest),
|
|
19229
19478
|
entries: Object.keys(lock.entries).length,
|
|
19230
19479
|
items: projectItems.length,
|
|
@@ -19281,7 +19530,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19281
19530
|
}
|
|
19282
19531
|
|
|
19283
19532
|
// src/gallery/page.ts
|
|
19284
|
-
import { existsSync as
|
|
19533
|
+
import { existsSync as existsSync30, readFileSync as readFileSync7 } from "fs";
|
|
19285
19534
|
|
|
19286
19535
|
// src/gallery/client-bundle.ts
|
|
19287
19536
|
import { createRequire } from "module";
|
|
@@ -19321,8 +19570,8 @@ var client;
|
|
|
19321
19570
|
function clientAssets() {
|
|
19322
19571
|
const prebuilt = new URL("gallery.js", CLIENT_DIR);
|
|
19323
19572
|
client ??= {
|
|
19324
|
-
css:
|
|
19325
|
-
js:
|
|
19573
|
+
css: readFileSync7(new URL("gallery.css", CLIENT_DIR), "utf8"),
|
|
19574
|
+
js: existsSync30(prebuilt) ? readFileSync7(prebuilt, "utf8") : bundleGalleryClient()
|
|
19326
19575
|
};
|
|
19327
19576
|
return client;
|
|
19328
19577
|
}
|
|
@@ -19465,8 +19714,8 @@ var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download
|
|
|
19465
19714
|
|
|
19466
19715
|
// src/editor/install.ts
|
|
19467
19716
|
import { createHash as createHash6 } from "crypto";
|
|
19468
|
-
import { existsSync as
|
|
19469
|
-
import { mkdir as mkdir12, readFile as
|
|
19717
|
+
import { existsSync as existsSync31 } from "fs";
|
|
19718
|
+
import { mkdir as mkdir12, readFile as readFile27, rename as rename10, rm as rm12, stat as stat4, writeFile as writeFile17 } from "fs/promises";
|
|
19470
19719
|
import os3 from "os";
|
|
19471
19720
|
import path35 from "path";
|
|
19472
19721
|
var EditorInstallError = class extends Error {
|
|
@@ -19497,7 +19746,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
|
|
|
19497
19746
|
}
|
|
19498
19747
|
async function sha256Of(file) {
|
|
19499
19748
|
try {
|
|
19500
|
-
return createHash6("sha256").update(await
|
|
19749
|
+
return createHash6("sha256").update(await readFile27(file)).digest("hex");
|
|
19501
19750
|
} catch {
|
|
19502
19751
|
return null;
|
|
19503
19752
|
}
|
|
@@ -19511,7 +19760,7 @@ async function editorStatus(opts = {}) {
|
|
|
19511
19760
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
19512
19761
|
totalBytes += expected.bytes;
|
|
19513
19762
|
const file = path35.join(dir, name);
|
|
19514
|
-
const info =
|
|
19763
|
+
const info = existsSync31(file) ? await stat4(file).catch(() => null) : null;
|
|
19515
19764
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
19516
19765
|
installedBytes += expected.bytes;
|
|
19517
19766
|
} else {
|
|
@@ -19618,7 +19867,7 @@ function editorContentType(name) {
|
|
|
19618
19867
|
}
|
|
19619
19868
|
|
|
19620
19869
|
// src/gallery/editor.ts
|
|
19621
|
-
import { readFile as
|
|
19870
|
+
import { readFile as readFile28 } from "fs/promises";
|
|
19622
19871
|
import path36 from "path";
|
|
19623
19872
|
function editorRoute(release, name = "index.html") {
|
|
19624
19873
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
@@ -19692,7 +19941,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
19692
19941
|
if (!status.installed) return null;
|
|
19693
19942
|
let bytes;
|
|
19694
19943
|
try {
|
|
19695
|
-
bytes = await
|
|
19944
|
+
bytes = await readFile28(path36.join(dir, name));
|
|
19696
19945
|
} catch {
|
|
19697
19946
|
verified = null;
|
|
19698
19947
|
return null;
|
|
@@ -19709,7 +19958,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
19709
19958
|
// src/gallery/server.ts
|
|
19710
19959
|
import { randomBytes } from "crypto";
|
|
19711
19960
|
import { createServer as createServer2 } from "http";
|
|
19712
|
-
import { readFile as
|
|
19961
|
+
import { readFile as readFile29 } from "fs/promises";
|
|
19713
19962
|
var MAX_EDIT_BYTES = 48 * 1024 * 1024;
|
|
19714
19963
|
var EDITOR_CSP = [
|
|
19715
19964
|
"default-src 'self'",
|
|
@@ -19890,7 +20139,7 @@ async function serveGallery(opts) {
|
|
|
19890
20139
|
const asset = reviewAssets.get(jobId)?.get(url2.pathname);
|
|
19891
20140
|
if (!asset) return fail(404, "no such review asset");
|
|
19892
20141
|
try {
|
|
19893
|
-
const bytes = await
|
|
20142
|
+
const bytes = await readFile29(asset.path);
|
|
19894
20143
|
res.writeHead(200, {
|
|
19895
20144
|
"Content-Type": asset.contentType,
|
|
19896
20145
|
"Cache-Control": "no-store",
|
|
@@ -19973,7 +20222,7 @@ async function serveGallery(opts) {
|
|
|
19973
20222
|
if (!asset) return fail(404, "no such gallery media");
|
|
19974
20223
|
let bytes;
|
|
19975
20224
|
try {
|
|
19976
|
-
bytes = await
|
|
20225
|
+
bytes = await readFile29(asset.path);
|
|
19977
20226
|
} catch {
|
|
19978
20227
|
return fail(404, "gallery media is no longer on disk; refresh the page");
|
|
19979
20228
|
}
|
|
@@ -20383,8 +20632,8 @@ function createGenerateHandlers(opts) {
|
|
|
20383
20632
|
}
|
|
20384
20633
|
|
|
20385
20634
|
// src/pipeline/salvage.ts
|
|
20386
|
-
import { readFile as
|
|
20387
|
-
import { existsSync as
|
|
20635
|
+
import { readFile as readFile30 } from "fs/promises";
|
|
20636
|
+
import { existsSync as existsSync32 } from "fs";
|
|
20388
20637
|
import path37 from "path";
|
|
20389
20638
|
function providerClaimId(provider, objectId) {
|
|
20390
20639
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
@@ -20392,10 +20641,10 @@ function providerClaimId(provider, objectId) {
|
|
|
20392
20641
|
async function loadClaims(lockPaths, opts = {}) {
|
|
20393
20642
|
const claimed = /* @__PURE__ */ new Set();
|
|
20394
20643
|
for (const p of lockPaths) {
|
|
20395
|
-
if (!
|
|
20644
|
+
if (!existsSync32(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
20396
20645
|
let parsed;
|
|
20397
20646
|
try {
|
|
20398
|
-
parsed = parseLock(JSON.parse(await
|
|
20647
|
+
parsed = parseLock(JSON.parse(await readFile30(p, "utf8")));
|
|
20399
20648
|
} catch {
|
|
20400
20649
|
throw new Error(`Claim lockfile is malformed: ${p}`);
|
|
20401
20650
|
}
|
|
@@ -20509,7 +20758,7 @@ async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, cla
|
|
|
20509
20758
|
const siblings = [];
|
|
20510
20759
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
20511
20760
|
if (path37.resolve(siblingManifestPath) === own) continue;
|
|
20512
|
-
if (!
|
|
20761
|
+
if (!existsSync32(siblingManifestPath)) continue;
|
|
20513
20762
|
try {
|
|
20514
20763
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
20515
20764
|
siblings.push({ label: path37.basename(path37.dirname(siblingManifestPath)), manifest });
|
|
@@ -20632,7 +20881,7 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
20632
20881
|
}
|
|
20633
20882
|
|
|
20634
20883
|
// src/pick/salvage-server.ts
|
|
20635
|
-
import { mkdir as mkdir13, writeFile as writeFile18, readFile as
|
|
20884
|
+
import { mkdir as mkdir13, writeFile as writeFile18, readFile as readFile31 } from "fs/promises";
|
|
20636
20885
|
import path38 from "path";
|
|
20637
20886
|
|
|
20638
20887
|
// src/pick/salvage-sheet.ts
|
|
@@ -20914,7 +21163,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
20914
21163
|
}
|
|
20915
21164
|
}
|
|
20916
21165
|
await applyTags(provider, decisions, existingTags, { onProgress: log, characters: characterMembers });
|
|
20917
|
-
const raw = JSON.parse(await
|
|
21166
|
+
const raw = JSON.parse(await readFile31(ctx.manifestPath, "utf8"));
|
|
20918
21167
|
for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
|
|
20919
21168
|
await writeFile18(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
|
|
20920
21169
|
await saveLock(ctx.lockPath, ctx.lock);
|
|
@@ -21139,6 +21388,7 @@ export {
|
|
|
21139
21388
|
availableProviders,
|
|
21140
21389
|
backoffMs,
|
|
21141
21390
|
buildGallerySnapshot,
|
|
21391
|
+
buildImportedEntry,
|
|
21142
21392
|
buildManifest,
|
|
21143
21393
|
buildPlan,
|
|
21144
21394
|
buildWorkspaceGallerySnapshot,
|
|
@@ -21201,6 +21451,7 @@ export {
|
|
|
21201
21451
|
historyLimit,
|
|
21202
21452
|
idFromPrompt,
|
|
21203
21453
|
imageMetadata,
|
|
21454
|
+
importLocal,
|
|
21204
21455
|
inspectCaches,
|
|
21205
21456
|
inspectQualityProfile,
|
|
21206
21457
|
inspectRevisionReadiness,
|
|
@@ -21293,6 +21544,7 @@ export {
|
|
|
21293
21544
|
renderSalvageSheet,
|
|
21294
21545
|
renderSheet,
|
|
21295
21546
|
renderSheetDocument,
|
|
21547
|
+
reportSpecHashes,
|
|
21296
21548
|
requireApprovedQualitySources,
|
|
21297
21549
|
requireBalance,
|
|
21298
21550
|
requireDelete,
|
|
@@ -21332,6 +21584,7 @@ export {
|
|
|
21332
21584
|
sliceVfxSheet,
|
|
21333
21585
|
slugify,
|
|
21334
21586
|
snapshotQualityBaseline,
|
|
21587
|
+
snapshotQualityCases,
|
|
21335
21588
|
sourceIsStem,
|
|
21336
21589
|
sourceOutputPath,
|
|
21337
21590
|
specHash,
|