pixelkiln 0.93.0 → 0.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +355 -175
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +317 -164
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -24
- package/dist/index.d.ts +58 -24
- package/dist/index.js +316 -163
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +17 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2139,9 +2139,9 @@ var PixelLabClient = class {
|
|
|
2139
2139
|
apiKey;
|
|
2140
2140
|
http;
|
|
2141
2141
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
2142
|
-
async request(
|
|
2142
|
+
async request(path40, init) {
|
|
2143
2143
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
2144
|
-
const res = await this.http(`${BASE}${
|
|
2144
|
+
const res = await this.http(`${BASE}${path40}`, {
|
|
2145
2145
|
...init,
|
|
2146
2146
|
headers: {
|
|
2147
2147
|
Authorization: auth,
|
|
@@ -2152,13 +2152,13 @@ var PixelLabClient = class {
|
|
|
2152
2152
|
const text = await res.text();
|
|
2153
2153
|
if (!res.ok) {
|
|
2154
2154
|
const hint = res.status === 500 && text.includes("Failed to start any animation jobs") ? '; a skeleton-v3 loop needs a character with a stored 3D skeleton (a v3 base), use mode: "template" on a standard one' : "";
|
|
2155
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
2155
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path40} \u2192 ${res.status}${hint}`, res.status, text);
|
|
2156
2156
|
}
|
|
2157
2157
|
if (!text) return {};
|
|
2158
2158
|
try {
|
|
2159
2159
|
return JSON.parse(text);
|
|
2160
2160
|
} catch {
|
|
2161
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
2161
|
+
throw new Error(`${init?.method ?? "GET"} ${path40} returned invalid JSON`);
|
|
2162
2162
|
}
|
|
2163
2163
|
}
|
|
2164
2164
|
async balance() {
|
|
@@ -2611,10 +2611,10 @@ var PixelLabClient = class {
|
|
|
2611
2611
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
2612
2612
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
2613
2613
|
const south = args.reference?.south;
|
|
2614
|
-
let
|
|
2614
|
+
let path40;
|
|
2615
2615
|
let body;
|
|
2616
2616
|
if (args.mode === "v3") {
|
|
2617
|
-
|
|
2617
|
+
path40 = "/create-character-v3";
|
|
2618
2618
|
body = {
|
|
2619
2619
|
description: args.description,
|
|
2620
2620
|
image_size: imageSize,
|
|
@@ -2628,7 +2628,7 @@ var PixelLabClient = class {
|
|
|
2628
2628
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
2629
2629
|
};
|
|
2630
2630
|
} else if (args.mode === "pro-flash") {
|
|
2631
|
-
|
|
2631
|
+
path40 = "/create-character-pro-flash";
|
|
2632
2632
|
const traits = args.styleTraits;
|
|
2633
2633
|
body = {
|
|
2634
2634
|
description: args.description,
|
|
@@ -2652,7 +2652,7 @@ var PixelLabClient = class {
|
|
|
2652
2652
|
} : {}
|
|
2653
2653
|
};
|
|
2654
2654
|
} else if (args.mode === "pro") {
|
|
2655
|
-
|
|
2655
|
+
path40 = "/create-character-pro";
|
|
2656
2656
|
body = {
|
|
2657
2657
|
description: args.description,
|
|
2658
2658
|
image_size: imageSize,
|
|
@@ -2666,7 +2666,7 @@ var PixelLabClient = class {
|
|
|
2666
2666
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
2667
2667
|
};
|
|
2668
2668
|
} else {
|
|
2669
|
-
|
|
2669
|
+
path40 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
2670
2670
|
body = {
|
|
2671
2671
|
description: args.description,
|
|
2672
2672
|
image_size: imageSize,
|
|
@@ -2684,8 +2684,8 @@ var PixelLabClient = class {
|
|
|
2684
2684
|
};
|
|
2685
2685
|
}
|
|
2686
2686
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
2687
|
-
const raw = await this.request(
|
|
2688
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
2687
|
+
const raw = await this.request(path40, { method: "POST", body: JSON.stringify(body) });
|
|
2688
|
+
return validateResponse(CharacterSubmitSchema, raw, path40.slice(1));
|
|
2689
2689
|
}
|
|
2690
2690
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
2691
2691
|
async createCharacterState(args) {
|
|
@@ -4022,10 +4022,10 @@ import { createReadStream } from "fs";
|
|
|
4022
4022
|
function sha256(data) {
|
|
4023
4023
|
return createHash("sha256").update(data).digest("hex");
|
|
4024
4024
|
}
|
|
4025
|
-
async function sha256File(
|
|
4025
|
+
async function sha256File(path40) {
|
|
4026
4026
|
return new Promise((resolve, reject) => {
|
|
4027
4027
|
const hash = createHash("sha256");
|
|
4028
|
-
const stream = createReadStream(
|
|
4028
|
+
const stream = createReadStream(path40);
|
|
4029
4029
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
4030
4030
|
stream.on("error", reject);
|
|
4031
4031
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -7844,9 +7844,9 @@ var RetroDiffusionClient = class {
|
|
|
7844
7844
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
7845
7845
|
return Buffer.from(await response.arrayBuffer());
|
|
7846
7846
|
}
|
|
7847
|
-
async call(
|
|
7847
|
+
async call(path40, init = {}) {
|
|
7848
7848
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
7849
|
-
const response = await this.request(`${this.baseUrl}${
|
|
7849
|
+
const response = await this.request(`${this.baseUrl}${path40}`, {
|
|
7850
7850
|
...init,
|
|
7851
7851
|
headers: {
|
|
7852
7852
|
"Content-Type": "application/json",
|
|
@@ -10356,7 +10356,7 @@ function pixelkilnVersion() {
|
|
|
10356
10356
|
}
|
|
10357
10357
|
|
|
10358
10358
|
// src/manifest.ts
|
|
10359
|
-
async function loadManifest(manifestPath) {
|
|
10359
|
+
async function loadManifest(manifestPath, opts = {}) {
|
|
10360
10360
|
const abs = path8.resolve(manifestPath);
|
|
10361
10361
|
if (!existsSync7(abs)) throw new ProjectError(`No manifest at ${abs}`);
|
|
10362
10362
|
const expansion = expandLoopDirections(JSON.parse(await readFile5(abs, "utf8")));
|
|
@@ -10364,6 +10364,63 @@ async function loadManifest(manifestPath) {
|
|
|
10364
10364
|
throw new ProjectError(`Manifest at ${abs} is invalid:
|
|
10365
10365
|
${expansion.issues.map((i) => ` ${i}`).join("\n")}`);
|
|
10366
10366
|
}
|
|
10367
|
+
if (!opts.lenient) return loadExpanded(abs, expansion);
|
|
10368
|
+
const invalid = [];
|
|
10369
|
+
const raw = pruneInvalidEntries(expansion.raw, invalid);
|
|
10370
|
+
for (let round2 = 0; ; round2++) {
|
|
10371
|
+
try {
|
|
10372
|
+
const loaded = await loadExpanded(abs, { ...expansion, raw });
|
|
10373
|
+
return invalid.length ? { ...loaded, invalid } : loaded;
|
|
10374
|
+
} catch (error) {
|
|
10375
|
+
const culprits = round2 < 50 && error instanceof ProjectError ? culpritEntries(error.message) : [];
|
|
10376
|
+
const fresh = culprits.filter((entry) => dropEntry(raw, entry));
|
|
10377
|
+
if (!fresh.length) throw error;
|
|
10378
|
+
invalid.push(...fresh);
|
|
10379
|
+
}
|
|
10380
|
+
}
|
|
10381
|
+
}
|
|
10382
|
+
function entryRecord(raw, kind) {
|
|
10383
|
+
const record = raw?.[kind === "style" ? "styles" : "assets"];
|
|
10384
|
+
return record && typeof record === "object" && !Array.isArray(record) ? record : null;
|
|
10385
|
+
}
|
|
10386
|
+
function dropEntry(raw, entry) {
|
|
10387
|
+
const record = entryRecord(raw, entry.kind);
|
|
10388
|
+
if (!record || !(entry.id in record)) return false;
|
|
10389
|
+
delete record[entry.id];
|
|
10390
|
+
return true;
|
|
10391
|
+
}
|
|
10392
|
+
function pruneInvalidEntries(raw, invalid) {
|
|
10393
|
+
for (const [kind, schema] of [["style", StyleInputSchema], ["asset", AssetSchema]]) {
|
|
10394
|
+
const record = entryRecord(raw, kind);
|
|
10395
|
+
if (!record) continue;
|
|
10396
|
+
for (const [id, value] of Object.entries(record)) {
|
|
10397
|
+
const parsed = schema.safeParse(value);
|
|
10398
|
+
if (parsed.success) continue;
|
|
10399
|
+
const prefix = `${kind === "style" ? "styles" : "assets"}.${id}`;
|
|
10400
|
+
const lines = flattenManifestIssues(parsed.error.issues).lines.map((line) => {
|
|
10401
|
+
const [fieldPath, ...rest] = line.trim().split(": ");
|
|
10402
|
+
return `${prefix}${fieldPath === "(manifest)" || !fieldPath ? "" : `.${fieldPath}`}: ${rest.join(": ")}`;
|
|
10403
|
+
});
|
|
10404
|
+
invalid.push({ kind, id, issues: lines.length ? lines : [`${prefix}: invalid`] });
|
|
10405
|
+
delete record[id];
|
|
10406
|
+
}
|
|
10407
|
+
}
|
|
10408
|
+
return raw;
|
|
10409
|
+
}
|
|
10410
|
+
function culpritEntries(message6) {
|
|
10411
|
+
const found = /* @__PURE__ */ new Map();
|
|
10412
|
+
for (const line of message6.split("\n")) {
|
|
10413
|
+
const match = /^ {2}(assets|styles)\.([^.:\s]+)[.:]/.exec(line);
|
|
10414
|
+
if (!match) continue;
|
|
10415
|
+
const kind = match[1] === "styles" ? "style" : "asset";
|
|
10416
|
+
const key = `${kind}:${match[2]}`;
|
|
10417
|
+
const entry = found.get(key) ?? { kind, id: match[2], issues: [] };
|
|
10418
|
+
entry.issues.push(line.trim());
|
|
10419
|
+
found.set(key, entry);
|
|
10420
|
+
}
|
|
10421
|
+
return [...found.values()];
|
|
10422
|
+
}
|
|
10423
|
+
async function loadExpanded(abs, expansion) {
|
|
10367
10424
|
const input = ManifestInputSchema.safeParse(expansion.raw);
|
|
10368
10425
|
if (!input.success) {
|
|
10369
10426
|
const issues = formatManifestIssues(input.error.issues);
|
|
@@ -11298,7 +11355,16 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11298
11355
|
if (!emitStyles.has(styleId)) continue;
|
|
11299
11356
|
for (const assetId of Object.keys(manifest.assets)) {
|
|
11300
11357
|
if (!requestedAssetIds.has(assetId) || !styleSpecs.has(assetId)) continue;
|
|
11301
|
-
|
|
11358
|
+
if (!filter?.onInvalid) {
|
|
11359
|
+
specs.push(await finalize(assetId));
|
|
11360
|
+
continue;
|
|
11361
|
+
}
|
|
11362
|
+
try {
|
|
11363
|
+
specs.push(await finalize(assetId));
|
|
11364
|
+
} catch (error) {
|
|
11365
|
+
const message6 = error instanceof Error ? error.message : String(error);
|
|
11366
|
+
filter.onInvalid({ kind: "asset", id: assetId, issues: [message6] });
|
|
11367
|
+
}
|
|
11302
11368
|
}
|
|
11303
11369
|
}
|
|
11304
11370
|
const byOutput = /* @__PURE__ */ new Map();
|
|
@@ -13571,8 +13637,14 @@ async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {})
|
|
|
13571
13637
|
if (path16.resolve(process.cwd()) !== root) loadEnvFiles(process.cwd());
|
|
13572
13638
|
}
|
|
13573
13639
|
const lockPath = path16.resolve(opts.lockPath ?? path16.join(root, "pixelkiln.lock.json"));
|
|
13574
|
-
|
|
13575
|
-
const
|
|
13640
|
+
let loaded = await loadManifest(absolute, { lenient: opts.lenient });
|
|
13641
|
+
const unresolved = [];
|
|
13642
|
+
const specs = await resolveSpecs(loaded, {
|
|
13643
|
+
styles: opts.styles ?? [],
|
|
13644
|
+
assets: opts.assets ?? [],
|
|
13645
|
+
...opts.lenient ? { onInvalid: (entry) => unresolved.push(entry) } : {}
|
|
13646
|
+
});
|
|
13647
|
+
if (unresolved.length) loaded = { ...loaded, invalid: [...loaded.invalid ?? [], ...unresolved] };
|
|
13576
13648
|
const lock = await loadLock(lockPath);
|
|
13577
13649
|
normalizeLockOutputPaths(lock, specs);
|
|
13578
13650
|
const adapters = /* @__PURE__ */ new Map();
|
|
@@ -14583,10 +14655,10 @@ function isSha256Hash(value) {
|
|
|
14583
14655
|
function parseCache(value) {
|
|
14584
14656
|
return HashCacheSchema.parse(value);
|
|
14585
14657
|
}
|
|
14586
|
-
async function loadCache(
|
|
14587
|
-
if (!existsSync15(
|
|
14658
|
+
async function loadCache(path40) {
|
|
14659
|
+
if (!existsSync15(path40)) return { version: 1, hashes: {} };
|
|
14588
14660
|
try {
|
|
14589
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile12(
|
|
14661
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile12(path40, "utf8")));
|
|
14590
14662
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
14591
14663
|
return {
|
|
14592
14664
|
version: 1,
|
|
@@ -14598,18 +14670,18 @@ async function loadCache(path39) {
|
|
|
14598
14670
|
return { version: 1, hashes: {} };
|
|
14599
14671
|
}
|
|
14600
14672
|
}
|
|
14601
|
-
async function saveCache(
|
|
14673
|
+
async function saveCache(path40, cache) {
|
|
14602
14674
|
const sorted = {};
|
|
14603
14675
|
for (const key of Object.keys(cache.hashes).sort()) {
|
|
14604
14676
|
const hash = cache.hashes[key];
|
|
14605
14677
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key}`);
|
|
14606
14678
|
sorted[key] = hash;
|
|
14607
14679
|
}
|
|
14608
|
-
await mkdir6(pathModule.dirname(pathModule.resolve(
|
|
14609
|
-
const tmp = `${
|
|
14680
|
+
await mkdir6(pathModule.dirname(pathModule.resolve(path40)), { recursive: true });
|
|
14681
|
+
const tmp = `${path40}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
14610
14682
|
try {
|
|
14611
14683
|
await writeFile6(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
14612
|
-
await rename4(tmp,
|
|
14684
|
+
await rename4(tmp, path40);
|
|
14613
14685
|
} finally {
|
|
14614
14686
|
await rm4(tmp, { force: true });
|
|
14615
14687
|
}
|
|
@@ -16389,9 +16461,81 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
16389
16461
|
}
|
|
16390
16462
|
|
|
16391
16463
|
// src/pipeline/doctor.ts
|
|
16392
|
-
import { constants, existsSync as
|
|
16464
|
+
import { constants, existsSync as existsSync20 } from "fs";
|
|
16393
16465
|
import { access, stat as stat2 } from "fs/promises";
|
|
16466
|
+
import path25 from "path";
|
|
16467
|
+
|
|
16468
|
+
// src/pipeline/install-check.ts
|
|
16469
|
+
import { existsSync as existsSync19, readFileSync as readFileSync7 } from "fs";
|
|
16394
16470
|
import path24 from "path";
|
|
16471
|
+
function readJson(file) {
|
|
16472
|
+
try {
|
|
16473
|
+
return JSON.parse(readFileSync7(file, "utf8"));
|
|
16474
|
+
} catch {
|
|
16475
|
+
return null;
|
|
16476
|
+
}
|
|
16477
|
+
}
|
|
16478
|
+
function readInstallFacts(manifestDir, running) {
|
|
16479
|
+
let dir = path24.resolve(manifestDir);
|
|
16480
|
+
for (let depth = 0; depth < 4; depth++) {
|
|
16481
|
+
const pkg = readJson(path24.join(dir, "package.json"));
|
|
16482
|
+
if (pkg) {
|
|
16483
|
+
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
16484
|
+
if (pinned) {
|
|
16485
|
+
const installedPkg = readJson(path24.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
16486
|
+
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
16487
|
+
return { pinned, installed, running };
|
|
16488
|
+
}
|
|
16489
|
+
}
|
|
16490
|
+
const parent = path24.dirname(dir);
|
|
16491
|
+
if (parent === dir || !existsSync19(parent)) break;
|
|
16492
|
+
dir = parent;
|
|
16493
|
+
}
|
|
16494
|
+
return null;
|
|
16495
|
+
}
|
|
16496
|
+
function parse(version) {
|
|
16497
|
+
const match = /(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
16498
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
16499
|
+
}
|
|
16500
|
+
function compare(a, b) {
|
|
16501
|
+
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
16502
|
+
}
|
|
16503
|
+
function checkInstall(facts) {
|
|
16504
|
+
const findings = [];
|
|
16505
|
+
const pin = parse(facts.pinned ?? "");
|
|
16506
|
+
const installed = facts.installed ? parse(facts.installed) : null;
|
|
16507
|
+
const running = facts.running ? parse(facts.running) : null;
|
|
16508
|
+
const exact = /^[=v]*\d+\.\d+\.\d+$/.test((facts.pinned ?? "").trim());
|
|
16509
|
+
if (pin && facts.installed && installed) {
|
|
16510
|
+
const behind = exact ? compare(installed, pin) !== 0 : compare(installed, pin) < 0;
|
|
16511
|
+
if (behind) {
|
|
16512
|
+
findings.push({
|
|
16513
|
+
level: "warning",
|
|
16514
|
+
message: `package.json asks for pixelkiln ${facts.pinned} but node_modules has ${facts.installed}; run \`npm install\` so the CLI matches the manifest.`
|
|
16515
|
+
});
|
|
16516
|
+
}
|
|
16517
|
+
} else if (pin && !facts.installed) {
|
|
16518
|
+
findings.push({
|
|
16519
|
+
level: "warning",
|
|
16520
|
+
message: `package.json asks for pixelkiln ${facts.pinned} but it is not installed in node_modules; run \`npm install\`.`
|
|
16521
|
+
});
|
|
16522
|
+
}
|
|
16523
|
+
if (running && installed && compare(running, installed) !== 0) {
|
|
16524
|
+
findings.push({
|
|
16525
|
+
level: "warning",
|
|
16526
|
+
message: `running pixelkiln ${facts.running}, but this project's node_modules has ${facts.installed}. Another install is first on your PATH; use \`npx pixelkiln\` or remove the global one.`
|
|
16527
|
+
});
|
|
16528
|
+
}
|
|
16529
|
+
if (!findings.length) {
|
|
16530
|
+
findings.push({
|
|
16531
|
+
level: "ok",
|
|
16532
|
+
message: `pixelkiln ${facts.running ?? facts.installed ?? "?"} matches package.json (${facts.pinned})`
|
|
16533
|
+
});
|
|
16534
|
+
}
|
|
16535
|
+
return findings;
|
|
16536
|
+
}
|
|
16537
|
+
|
|
16538
|
+
// src/pipeline/doctor.ts
|
|
16395
16539
|
async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
16396
16540
|
const checks = [];
|
|
16397
16541
|
const add = (id, level, message6) => checks.push({ id, level, message: message6 });
|
|
@@ -16400,10 +16544,19 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16400
16544
|
"ok",
|
|
16401
16545
|
`${Object.keys(loaded.manifest.styles).length} style(s), ${Object.keys(loaded.manifest.assets).length} asset(s), ${specs.length} resolved spec(s)`
|
|
16402
16546
|
);
|
|
16547
|
+
for (const entry of loaded.invalid ?? []) {
|
|
16548
|
+
add(
|
|
16549
|
+
"invalid-entry",
|
|
16550
|
+
"error",
|
|
16551
|
+
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
16552
|
+
);
|
|
16553
|
+
}
|
|
16554
|
+
const facts = readInstallFacts(path25.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
16555
|
+
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
16403
16556
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
16404
16557
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
16405
|
-
|
|
16406
|
-
...spec.quality ? [
|
|
16558
|
+
path25.dirname(spec.outFile),
|
|
16559
|
+
...spec.quality ? [path25.dirname(spec.quality.outFile)] : []
|
|
16407
16560
|
]))];
|
|
16408
16561
|
const unwritable = [];
|
|
16409
16562
|
for (const dir of dirs) {
|
|
@@ -16426,7 +16579,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16426
16579
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
16427
16580
|
const output = entry.outputs[index];
|
|
16428
16581
|
const spec = specByKey.get(key);
|
|
16429
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
16582
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, path25.dirname(lockPath));
|
|
16430
16583
|
const owner = outputOwners.get(absolute);
|
|
16431
16584
|
if (owner && owner !== key) duplicateOutputs.push(`${output.path} (${owner}, ${key})`);
|
|
16432
16585
|
outputOwners.set(absolute, key);
|
|
@@ -16441,7 +16594,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16441
16594
|
} else {
|
|
16442
16595
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
16443
16596
|
}
|
|
16444
|
-
const cacheDir =
|
|
16597
|
+
const cacheDir = path25.join(path25.dirname(lockPath), ".pixelkiln", "cache");
|
|
16445
16598
|
const stranded = [];
|
|
16446
16599
|
const invalidState = [];
|
|
16447
16600
|
const staleMapUrls = [];
|
|
@@ -16457,11 +16610,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16457
16610
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
16458
16611
|
let hasCache = false;
|
|
16459
16612
|
for (const output of entry.outputs) {
|
|
16460
|
-
const cached2 =
|
|
16613
|
+
const cached2 = path25.join(
|
|
16461
16614
|
cacheDir,
|
|
16462
16615
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
16463
16616
|
);
|
|
16464
|
-
if (
|
|
16617
|
+
if (existsSync20(cached2) && await sha256File(cached2) === output.sha256) {
|
|
16465
16618
|
hasCache = true;
|
|
16466
16619
|
break;
|
|
16467
16620
|
}
|
|
@@ -16557,16 +16710,16 @@ async function nearestExistingDirectory(start) {
|
|
|
16557
16710
|
if ((await stat2(current)).isDirectory()) return current;
|
|
16558
16711
|
} catch {
|
|
16559
16712
|
}
|
|
16560
|
-
const parent =
|
|
16713
|
+
const parent = path25.dirname(current);
|
|
16561
16714
|
if (parent === current) return current;
|
|
16562
16715
|
current = parent;
|
|
16563
16716
|
}
|
|
16564
16717
|
}
|
|
16565
16718
|
|
|
16566
16719
|
// src/pipeline/adopt.ts
|
|
16567
|
-
import { existsSync as
|
|
16720
|
+
import { existsSync as existsSync21 } from "fs";
|
|
16568
16721
|
import { readFile as readFile15, writeFile as writeFile8 } from "fs/promises";
|
|
16569
|
-
import
|
|
16722
|
+
import path26 from "path";
|
|
16570
16723
|
async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
16571
16724
|
const log = opts.onProgress ?? (() => {
|
|
16572
16725
|
});
|
|
@@ -16577,7 +16730,7 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
16577
16730
|
const localByHash = /* @__PURE__ */ new Map();
|
|
16578
16731
|
const unmatchedLocal = [];
|
|
16579
16732
|
for (const spec of specs) {
|
|
16580
|
-
if (!
|
|
16733
|
+
if (!existsSync21(spec.outFile)) {
|
|
16581
16734
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
16582
16735
|
continue;
|
|
16583
16736
|
}
|
|
@@ -16699,7 +16852,7 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
16699
16852
|
}
|
|
16700
16853
|
|
|
16701
16854
|
// src/pipeline/import.ts
|
|
16702
|
-
import { existsSync as
|
|
16855
|
+
import { existsSync as existsSync22 } from "fs";
|
|
16703
16856
|
import { readFile as readFile16 } from "fs/promises";
|
|
16704
16857
|
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
16705
16858
|
const png = decodePng(bytes);
|
|
@@ -16752,7 +16905,7 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
16752
16905
|
skipped.push({ key, reason });
|
|
16753
16906
|
continue;
|
|
16754
16907
|
}
|
|
16755
|
-
if (!
|
|
16908
|
+
if (!existsSync22(spec.outFile)) {
|
|
16756
16909
|
skipped.push({ key, reason: `no file at ${spec.outFile}` });
|
|
16757
16910
|
continue;
|
|
16758
16911
|
}
|
|
@@ -16781,7 +16934,7 @@ async function reportSpecHashes(specs, lock) {
|
|
|
16781
16934
|
for (const spec of specs) {
|
|
16782
16935
|
const key = lockKey(spec.styleId, spec.assetId);
|
|
16783
16936
|
let bytes = null;
|
|
16784
|
-
if (
|
|
16937
|
+
if (existsSync22(spec.outFile)) bytes = await readFile16(spec.outFile);
|
|
16785
16938
|
let wouldImport = null;
|
|
16786
16939
|
if (bytes && !unimportable(spec)) {
|
|
16787
16940
|
try {
|
|
@@ -16810,13 +16963,13 @@ async function reportSpecHashes(specs, lock) {
|
|
|
16810
16963
|
}
|
|
16811
16964
|
|
|
16812
16965
|
// src/pick/server.ts
|
|
16813
|
-
import { existsSync as
|
|
16966
|
+
import { existsSync as existsSync24 } from "fs";
|
|
16814
16967
|
import { readFile as readFile19 } from "fs/promises";
|
|
16815
16968
|
|
|
16816
16969
|
// src/pipeline/init.ts
|
|
16817
16970
|
import { readdir as readdir3, readFile as readFile17, writeFile as writeFile9 } from "fs/promises";
|
|
16818
|
-
import { existsSync as
|
|
16819
|
-
import
|
|
16971
|
+
import { existsSync as existsSync23 } from "fs";
|
|
16972
|
+
import path27 from "path";
|
|
16820
16973
|
function pngSize(buf) {
|
|
16821
16974
|
if (buf.length < 24) return null;
|
|
16822
16975
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -16830,7 +16983,7 @@ function slugify(value) {
|
|
|
16830
16983
|
async function walk(dir, exclude) {
|
|
16831
16984
|
const out = [];
|
|
16832
16985
|
for (const entry of await readdir3(dir, { withFileTypes: true })) {
|
|
16833
|
-
const full =
|
|
16986
|
+
const full = path27.join(dir, entry.name);
|
|
16834
16987
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
16835
16988
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
16836
16989
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -16849,9 +17002,9 @@ async function scanAssets(root, opts = {}) {
|
|
|
16849
17002
|
skipped.push(`${file} (not a readable PNG)`);
|
|
16850
17003
|
continue;
|
|
16851
17004
|
}
|
|
16852
|
-
const rel =
|
|
16853
|
-
const category =
|
|
16854
|
-
let id = slugify(
|
|
17005
|
+
const rel = path27.relative(root, file);
|
|
17006
|
+
const category = path27.dirname(rel) === "." ? "" : path27.dirname(rel);
|
|
17007
|
+
let id = slugify(path27.basename(rel));
|
|
16855
17008
|
if (seen.has(id)) {
|
|
16856
17009
|
const n = seen.get(id) + 1;
|
|
16857
17010
|
seen.set(id, n);
|
|
@@ -17410,7 +17563,7 @@ async function currentArt(entry, spec) {
|
|
|
17410
17563
|
const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
|
|
17411
17564
|
if (!previous) return null;
|
|
17412
17565
|
const file = resolveOutputPath(previous.path, spec.root);
|
|
17413
|
-
if (!
|
|
17566
|
+
if (!existsSync24(file)) return null;
|
|
17414
17567
|
const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
|
|
17415
17568
|
if (!contentType) return null;
|
|
17416
17569
|
let width = entry.width;
|
|
@@ -17610,14 +17763,14 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
17610
17763
|
|
|
17611
17764
|
// src/gallery/snapshot.ts
|
|
17612
17765
|
import { createHash as createHash5 } from "crypto";
|
|
17613
|
-
import { existsSync as
|
|
17766
|
+
import { existsSync as existsSync30 } from "fs";
|
|
17614
17767
|
import { readFile as readFile26, stat as stat3 } from "fs/promises";
|
|
17615
|
-
import
|
|
17768
|
+
import path35 from "path";
|
|
17616
17769
|
|
|
17617
17770
|
// src/workspace.ts
|
|
17618
17771
|
import { mkdir as mkdir8, readFile as readFile20, rename as rename6, rm as rm7, writeFile as writeFile10 } from "fs/promises";
|
|
17619
|
-
import { existsSync as
|
|
17620
|
-
import
|
|
17772
|
+
import { existsSync as existsSync25 } from "fs";
|
|
17773
|
+
import path28 from "path";
|
|
17621
17774
|
import { z as z7 } from "zod";
|
|
17622
17775
|
var WorkspaceProjectSchema = z7.object({
|
|
17623
17776
|
id: z7.string().min(1),
|
|
@@ -17642,7 +17795,7 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
|
|
|
17642
17795
|
);
|
|
17643
17796
|
}
|
|
17644
17797
|
async function loadWorkspace(workspacePath) {
|
|
17645
|
-
if (!
|
|
17798
|
+
if (!existsSync25(workspacePath)) return { version: 1, projects: [] };
|
|
17646
17799
|
let raw;
|
|
17647
17800
|
try {
|
|
17648
17801
|
raw = JSON.parse(await readFile20(workspacePath, "utf8"));
|
|
@@ -17659,7 +17812,7 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
17659
17812
|
version: 1,
|
|
17660
17813
|
projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
|
|
17661
17814
|
};
|
|
17662
|
-
await mkdir8(
|
|
17815
|
+
await mkdir8(path28.dirname(path28.resolve(workspacePath)), { recursive: true });
|
|
17663
17816
|
const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
17664
17817
|
try {
|
|
17665
17818
|
await writeFile10(tmp, JSON.stringify(sorted, null, 2) + "\n");
|
|
@@ -17669,12 +17822,12 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
17669
17822
|
}
|
|
17670
17823
|
}
|
|
17671
17824
|
function toPortablePath(dir, absolute) {
|
|
17672
|
-
return
|
|
17825
|
+
return path28.relative(dir, absolute).split(path28.sep).join("/");
|
|
17673
17826
|
}
|
|
17674
17827
|
function resolveProject(dir, project) {
|
|
17675
17828
|
return {
|
|
17676
|
-
manifestPath:
|
|
17677
|
-
lockPath:
|
|
17829
|
+
manifestPath: path28.resolve(dir, project.manifest.split("/").join(path28.sep)),
|
|
17830
|
+
lockPath: path28.resolve(dir, project.lock.split("/").join(path28.sep))
|
|
17678
17831
|
};
|
|
17679
17832
|
}
|
|
17680
17833
|
function validateWorkspace(ws, dir) {
|
|
@@ -17687,21 +17840,21 @@ function validateWorkspace(ws, dir) {
|
|
|
17687
17840
|
const { manifestPath, lockPath } = resolveProject(dir, project);
|
|
17688
17841
|
lockOwners.set(lockPath, [...lockOwners.get(lockPath) ?? [], project.id]);
|
|
17689
17842
|
manifestOwners.set(manifestPath, [...manifestOwners.get(manifestPath) ?? [], project.id]);
|
|
17690
|
-
if (
|
|
17843
|
+
if (path28.isAbsolute(project.manifest) || path28.isAbsolute(project.lock)) {
|
|
17691
17844
|
diagnostics.push({
|
|
17692
17845
|
id: "absolute-path",
|
|
17693
17846
|
level: "warning",
|
|
17694
17847
|
message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
|
|
17695
17848
|
});
|
|
17696
17849
|
}
|
|
17697
|
-
if (!
|
|
17850
|
+
if (!existsSync25(manifestPath)) {
|
|
17698
17851
|
diagnostics.push({
|
|
17699
17852
|
id: "missing-manifest",
|
|
17700
17853
|
level: "error",
|
|
17701
17854
|
message: `project "${project.id}" manifest not found: ${manifestPath}`
|
|
17702
17855
|
});
|
|
17703
17856
|
}
|
|
17704
|
-
if (!
|
|
17857
|
+
if (!existsSync25(lockPath)) {
|
|
17705
17858
|
diagnostics.push({
|
|
17706
17859
|
id: "missing-lock",
|
|
17707
17860
|
level: "error",
|
|
@@ -17749,15 +17902,15 @@ function validateWorkspace(ws, dir) {
|
|
|
17749
17902
|
|
|
17750
17903
|
// src/gallery/edit.ts
|
|
17751
17904
|
import { readFile as readFile25, rename as rename9, writeFile as writeFile16 } from "fs/promises";
|
|
17752
|
-
import
|
|
17905
|
+
import path34 from "path";
|
|
17753
17906
|
import { z as z13 } from "zod";
|
|
17754
17907
|
|
|
17755
17908
|
// src/manifest-edit.ts
|
|
17756
17909
|
import { readFile as readFile21, rename as rename7, rm as rm8, writeFile as writeFile11 } from "fs/promises";
|
|
17757
|
-
import
|
|
17910
|
+
import path29 from "path";
|
|
17758
17911
|
import { z as z8 } from "zod";
|
|
17759
17912
|
var HexSha = z8.string().regex(/^[0-9a-f]{64}$/);
|
|
17760
|
-
var ProjectFileSchema = z8.string().min(1).refine((file) => !
|
|
17913
|
+
var ProjectFileSchema = z8.string().min(1).refine((file) => !path29.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
|
|
17761
17914
|
var AssetPatchSchema = z8.object({
|
|
17762
17915
|
prompt: z8.string().optional(),
|
|
17763
17916
|
/** Per-style override for the style being viewed; null removes it. */
|
|
@@ -18177,7 +18330,7 @@ function applyEdit(raw, edit) {
|
|
|
18177
18330
|
}
|
|
18178
18331
|
}
|
|
18179
18332
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
18180
|
-
const absolute =
|
|
18333
|
+
const absolute = path29.resolve(manifestPath);
|
|
18181
18334
|
const original = await readFile21(absolute, "utf8");
|
|
18182
18335
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
18183
18336
|
let raw;
|
|
@@ -18191,9 +18344,9 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
18191
18344
|
applyEdit(raw, edit);
|
|
18192
18345
|
const next = serializeLike(original, raw);
|
|
18193
18346
|
if (next === original) return unchanged(absolute, original);
|
|
18194
|
-
const tmp =
|
|
18195
|
-
|
|
18196
|
-
`.${
|
|
18347
|
+
const tmp = path29.join(
|
|
18348
|
+
path29.dirname(absolute),
|
|
18349
|
+
`.${path29.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
|
|
18197
18350
|
);
|
|
18198
18351
|
try {
|
|
18199
18352
|
await writeFile11(tmp, next);
|
|
@@ -18222,18 +18375,18 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
18222
18375
|
}
|
|
18223
18376
|
|
|
18224
18377
|
// src/pipeline/hand-edit.ts
|
|
18225
|
-
import { existsSync as
|
|
18378
|
+
import { existsSync as existsSync26 } from "fs";
|
|
18226
18379
|
import { copyFile, mkdir as mkdir9, readFile as readFile22, rename as rename8, rm as rm9, writeFile as writeFile12 } from "fs/promises";
|
|
18227
|
-
import
|
|
18380
|
+
import path30 from "path";
|
|
18228
18381
|
import { z as z9 } from "zod";
|
|
18229
18382
|
var HAND_EDIT_DIR = "edits";
|
|
18230
18383
|
function handEditPath(loaded, spec) {
|
|
18231
18384
|
const style = loaded.manifest.styles[spec.styleId];
|
|
18232
|
-
const outDir =
|
|
18233
|
-
const relative =
|
|
18234
|
-
const inside = relative && !relative.startsWith("..") && !
|
|
18235
|
-
const file = inside ? relative :
|
|
18236
|
-
return
|
|
18385
|
+
const outDir = path30.resolve(loaded.root, style?.outDir ?? ".");
|
|
18386
|
+
const relative = path30.relative(outDir, spec.outFile);
|
|
18387
|
+
const inside = relative && !relative.startsWith("..") && !path30.isAbsolute(relative);
|
|
18388
|
+
const file = inside ? relative : path30.basename(spec.outFile);
|
|
18389
|
+
return path30.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
|
|
18237
18390
|
}
|
|
18238
18391
|
function handEditBases(spec, lock) {
|
|
18239
18392
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -18246,10 +18399,10 @@ function handEditBases(spec, lock) {
|
|
|
18246
18399
|
}));
|
|
18247
18400
|
if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
|
|
18248
18401
|
if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
|
|
18249
|
-
if (!members.every((member) =>
|
|
18402
|
+
if (!members.every((member) => existsSync26(member.path))) return null;
|
|
18250
18403
|
return members.map(({ role, path: file }) => ({ role, path: file }));
|
|
18251
18404
|
}
|
|
18252
|
-
return
|
|
18405
|
+
return existsSync26(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
|
|
18253
18406
|
}
|
|
18254
18407
|
function handEditBase(spec, lock) {
|
|
18255
18408
|
const bases = handEditBases(spec, lock);
|
|
@@ -18279,18 +18432,18 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
18279
18432
|
`${spec.styleId}/${spec.assetId} declares ${spec.source}, one committed file placed for the whole set; clear that source (pixelkiln edit detach) to hand-edit the members one by one`
|
|
18280
18433
|
);
|
|
18281
18434
|
}
|
|
18282
|
-
const existing = spec.source ?
|
|
18435
|
+
const existing = spec.source ? path30.resolve(loaded.root, spec.source) : null;
|
|
18283
18436
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
18284
18437
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
18285
18438
|
let created = false;
|
|
18286
18439
|
for (const member of members) {
|
|
18287
|
-
if (
|
|
18440
|
+
if (existsSync26(member.path)) continue;
|
|
18288
18441
|
if (!member.base) {
|
|
18289
18442
|
throw new ManifestEditError(
|
|
18290
18443
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
18291
18444
|
);
|
|
18292
18445
|
}
|
|
18293
|
-
await mkdir9(
|
|
18446
|
+
await mkdir9(path30.dirname(member.path), { recursive: true });
|
|
18294
18447
|
await copyFile(member.base, member.path);
|
|
18295
18448
|
created = true;
|
|
18296
18449
|
}
|
|
@@ -18428,7 +18581,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
18428
18581
|
editor: input.editor,
|
|
18429
18582
|
protocol: input.protocol,
|
|
18430
18583
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
18431
|
-
project: projectPath ?
|
|
18584
|
+
project: projectPath ? path30.basename(projectPath) : null,
|
|
18432
18585
|
outputs: incoming.map((frame, index) => ({
|
|
18433
18586
|
role: frame.role,
|
|
18434
18587
|
basedOn: basedOnHash(entry, index),
|
|
@@ -18470,9 +18623,9 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
18470
18623
|
}
|
|
18471
18624
|
|
|
18472
18625
|
// src/gallery/upload.ts
|
|
18473
|
-
import { existsSync as
|
|
18626
|
+
import { existsSync as existsSync27 } from "fs";
|
|
18474
18627
|
import { mkdir as mkdir10, writeFile as writeFile13 } from "fs/promises";
|
|
18475
|
-
import
|
|
18628
|
+
import path31 from "path";
|
|
18476
18629
|
import { z as z10 } from "zod";
|
|
18477
18630
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
18478
18631
|
var UploadImageSchema = z10.object({
|
|
@@ -18485,12 +18638,12 @@ var UploadImageSchema = z10.object({
|
|
|
18485
18638
|
overwrite: z10.boolean().optional()
|
|
18486
18639
|
}).strict();
|
|
18487
18640
|
async function saveProjectImage(root, request) {
|
|
18488
|
-
const file =
|
|
18489
|
-
const relative =
|
|
18490
|
-
if (relative.startsWith("..") ||
|
|
18641
|
+
const file = path31.resolve(root, request.path);
|
|
18642
|
+
const relative = path31.relative(root, file);
|
|
18643
|
+
if (relative.startsWith("..") || path31.isAbsolute(relative)) {
|
|
18491
18644
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
18492
18645
|
}
|
|
18493
|
-
const extension =
|
|
18646
|
+
const extension = path31.extname(file).toLowerCase();
|
|
18494
18647
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
18495
18648
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
18496
18649
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -18502,18 +18655,18 @@ async function saveProjectImage(root, request) {
|
|
|
18502
18655
|
if (metadata.format !== expected) {
|
|
18503
18656
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
18504
18657
|
}
|
|
18505
|
-
if (
|
|
18506
|
-
throw new ManifestEditError(`${relative.split(
|
|
18658
|
+
if (existsSync27(file) && !request.overwrite) {
|
|
18659
|
+
throw new ManifestEditError(`${relative.split(path31.sep).join("/")} already exists; choose another name, or replace it`);
|
|
18507
18660
|
}
|
|
18508
|
-
await mkdir10(
|
|
18661
|
+
await mkdir10(path31.dirname(file), { recursive: true });
|
|
18509
18662
|
await writeFile13(file, bytes);
|
|
18510
|
-
return relative.split(
|
|
18663
|
+
return relative.split(path31.sep).join("/");
|
|
18511
18664
|
}
|
|
18512
18665
|
|
|
18513
18666
|
// src/gallery/image-revision.ts
|
|
18514
|
-
import { existsSync as
|
|
18667
|
+
import { existsSync as existsSync28 } from "fs";
|
|
18515
18668
|
import { readFile as readFile23, rm as rm10, writeFile as writeFile14 } from "fs/promises";
|
|
18516
|
-
import
|
|
18669
|
+
import path32 from "path";
|
|
18517
18670
|
import { z as z11 } from "zod";
|
|
18518
18671
|
var InpaintRevisionRequestSchema = z11.object({
|
|
18519
18672
|
action: z11.literal("create-inpaint-revision"),
|
|
@@ -18532,15 +18685,15 @@ var InpaintRevisionRequestSchema = z11.object({
|
|
|
18532
18685
|
overwrite: z11.boolean().optional()
|
|
18533
18686
|
}).strict();
|
|
18534
18687
|
async function createInpaintRevision(manifestPath, request) {
|
|
18535
|
-
const root =
|
|
18536
|
-
if (
|
|
18688
|
+
const root = path32.dirname(path32.resolve(manifestPath));
|
|
18689
|
+
if (path32.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
18537
18690
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
18538
18691
|
}
|
|
18539
18692
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
18540
18693
|
const metadata = imageMetadata(bytes);
|
|
18541
18694
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
18542
|
-
const file =
|
|
18543
|
-
const previous =
|
|
18695
|
+
const file = path32.resolve(root, request.maskPath);
|
|
18696
|
+
const previous = existsSync28(file) ? await readFile23(file) : null;
|
|
18544
18697
|
const mask = await saveProjectImage(root, {
|
|
18545
18698
|
action: "upload-image",
|
|
18546
18699
|
path: request.maskPath,
|
|
@@ -18567,9 +18720,9 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
18567
18720
|
}
|
|
18568
18721
|
|
|
18569
18722
|
// src/gallery/skeleton.ts
|
|
18570
|
-
import { existsSync as
|
|
18723
|
+
import { existsSync as existsSync29 } from "fs";
|
|
18571
18724
|
import { mkdir as mkdir11, readFile as readFile24, rm as rm11, writeFile as writeFile15 } from "fs/promises";
|
|
18572
|
-
import
|
|
18725
|
+
import path33 from "path";
|
|
18573
18726
|
import { z as z12 } from "zod";
|
|
18574
18727
|
var SkeletonEstimateRequestSchema = z12.object({
|
|
18575
18728
|
project: z12.string().min(1).optional(),
|
|
@@ -18608,20 +18761,20 @@ var SkeletonKeypointsUpdateSchema = z12.object({
|
|
|
18608
18761
|
set: SkeletonSetSchema
|
|
18609
18762
|
}).strict();
|
|
18610
18763
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
18611
|
-
const root =
|
|
18612
|
-
const file =
|
|
18613
|
-
const relative =
|
|
18614
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
18764
|
+
const root = path33.dirname(path33.resolve(manifestPath));
|
|
18765
|
+
const file = path33.resolve(root, request.keypointsFile);
|
|
18766
|
+
const relative = path33.relative(root, file);
|
|
18767
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path33.isAbsolute(relative)) {
|
|
18615
18768
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
18616
18769
|
}
|
|
18617
|
-
const existed =
|
|
18770
|
+
const existed = existsSync29(file);
|
|
18618
18771
|
let previous = null;
|
|
18619
18772
|
if (request.set) {
|
|
18620
18773
|
if (existed && !request.overwrite) {
|
|
18621
18774
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
18622
18775
|
}
|
|
18623
18776
|
if (existed) previous = await readFile24(file);
|
|
18624
|
-
await mkdir11(
|
|
18777
|
+
await mkdir11(path33.dirname(file), { recursive: true });
|
|
18625
18778
|
await writeFile15(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18626
18779
|
} else if (!existed) {
|
|
18627
18780
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
@@ -18637,7 +18790,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
18637
18790
|
revision: {
|
|
18638
18791
|
mode: "animate-skeleton",
|
|
18639
18792
|
from: request.from,
|
|
18640
|
-
keypointsFile: relative.split(
|
|
18793
|
+
keypointsFile: relative.split(path33.sep).join("/"),
|
|
18641
18794
|
direction: request.direction,
|
|
18642
18795
|
description: request.description,
|
|
18643
18796
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -18658,19 +18811,19 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
18658
18811
|
if (!spec) throw new ManifestEditError(`"${key}" is not declared by the manifest`);
|
|
18659
18812
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
18660
18813
|
if (!file) throw new ManifestEditError(`${key} is not an animate-skeleton revision`);
|
|
18661
|
-
const relative =
|
|
18662
|
-
if (relative.startsWith("..") ||
|
|
18814
|
+
const relative = path33.relative(ctx.loaded.root, file);
|
|
18815
|
+
if (relative.startsWith("..") || path33.isAbsolute(relative)) {
|
|
18663
18816
|
throw new ManifestEditError(`${key}'s keypoints file is outside the project; edit it by hand`);
|
|
18664
18817
|
}
|
|
18665
|
-
const current =
|
|
18818
|
+
const current = existsSync29(file) ? sha256(await readFile24(file)) : null;
|
|
18666
18819
|
if (current !== request.expectedSha256) {
|
|
18667
18820
|
throw Object.assign(
|
|
18668
|
-
new Error(`${relative.split(
|
|
18821
|
+
new Error(`${relative.split(path33.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
18669
18822
|
{ status: 409 }
|
|
18670
18823
|
);
|
|
18671
18824
|
}
|
|
18672
18825
|
await writeFile15(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18673
|
-
return relative.split(
|
|
18826
|
+
return relative.split(path33.sep).join("/");
|
|
18674
18827
|
}
|
|
18675
18828
|
|
|
18676
18829
|
// src/gallery/edit.ts
|
|
@@ -18724,7 +18877,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18724
18877
|
const history = /* @__PURE__ */ new Map();
|
|
18725
18878
|
const manifestOf = async (project) => {
|
|
18726
18879
|
try {
|
|
18727
|
-
return
|
|
18880
|
+
return path34.resolve(await opts.manifestFor(typeof project === "string" ? project : void 0));
|
|
18728
18881
|
} catch {
|
|
18729
18882
|
return null;
|
|
18730
18883
|
}
|
|
@@ -18747,7 +18900,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18747
18900
|
await writeFile16(tmp, last.before);
|
|
18748
18901
|
await rename9(tmp, manifestPath2);
|
|
18749
18902
|
stack.pop();
|
|
18750
|
-
log(` manifest edit undone in ${
|
|
18903
|
+
log(` manifest edit undone in ${path34.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
18751
18904
|
return opts.reload();
|
|
18752
18905
|
}
|
|
18753
18906
|
const manifestPath = await manifestOf(body?.project);
|
|
@@ -18809,7 +18962,7 @@ function createEditApplier(opts, log) {
|
|
|
18809
18962
|
} catch (error) {
|
|
18810
18963
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
18811
18964
|
}
|
|
18812
|
-
const written = await saveProjectImage(
|
|
18965
|
+
const written = await saveProjectImage(path34.dirname(path34.resolve(manifestPath2)), upload.data);
|
|
18813
18966
|
log(` image added: ${written}`);
|
|
18814
18967
|
return opts.reload();
|
|
18815
18968
|
}
|
|
@@ -18876,7 +19029,7 @@ function createEditApplier(opts, log) {
|
|
|
18876
19029
|
}
|
|
18877
19030
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
18878
19031
|
if (result.changed) {
|
|
18879
|
-
const relative =
|
|
19032
|
+
const relative = path34.relative(process.cwd(), result.manifestPath);
|
|
18880
19033
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
18881
19034
|
log(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
18882
19035
|
}
|
|
@@ -18904,7 +19057,7 @@ function describeEdit(edit) {
|
|
|
18904
19057
|
// src/gallery/snapshot.ts
|
|
18905
19058
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
18906
19059
|
function galleryMediaId(absolutePath) {
|
|
18907
|
-
return createHash5("sha256").update(
|
|
19060
|
+
return createHash5("sha256").update(path35.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
18908
19061
|
}
|
|
18909
19062
|
function galleryMediaRoute(id) {
|
|
18910
19063
|
return `/media/${id}`;
|
|
@@ -18928,9 +19081,9 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
18928
19081
|
return (entry.history ?? []).map((generation, i) => {
|
|
18929
19082
|
const outputs = generation.outputs.map((output) => {
|
|
18930
19083
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
18931
|
-
const file =
|
|
19084
|
+
const file = path35.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
18932
19085
|
let url = null;
|
|
18933
|
-
if (
|
|
19086
|
+
if (existsSync30(file)) {
|
|
18934
19087
|
const id = galleryMediaId(file);
|
|
18935
19088
|
media.set(id, { path: file, contentType: mediaType });
|
|
18936
19089
|
url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
|
|
@@ -19060,10 +19213,10 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
19060
19213
|
async function describeQuality(media, root, inspection) {
|
|
19061
19214
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
19062
19215
|
const outputs = await Promise.all(
|
|
19063
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
19216
|
+
outputPaths.map((file) => describeOutput(media, root, path35.resolve(root, file)))
|
|
19064
19217
|
);
|
|
19065
|
-
const recordPath =
|
|
19066
|
-
const recordExists =
|
|
19218
|
+
const recordPath = path35.resolve(root, inspection.record);
|
|
19219
|
+
const recordExists = existsSync30(recordPath);
|
|
19067
19220
|
let options = null;
|
|
19068
19221
|
let check = null;
|
|
19069
19222
|
if (recordExists) {
|
|
@@ -19082,7 +19235,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
19082
19235
|
return {
|
|
19083
19236
|
state: inspection.state,
|
|
19084
19237
|
reason: inspection.reason,
|
|
19085
|
-
output: portableOutputPath(
|
|
19238
|
+
output: portableOutputPath(path35.resolve(root, inspection.output), root),
|
|
19086
19239
|
record: portableOutputPath(recordPath, root),
|
|
19087
19240
|
recordExists,
|
|
19088
19241
|
outputs,
|
|
@@ -19122,7 +19275,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19122
19275
|
const items = [];
|
|
19123
19276
|
const manifestText = await readFile26(loaded.path, "utf8");
|
|
19124
19277
|
const manifestSha256 = sha256(manifestText);
|
|
19125
|
-
const cacheDir =
|
|
19278
|
+
const cacheDir = path35.resolve(path35.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
19126
19279
|
let rawStyles = {};
|
|
19127
19280
|
try {
|
|
19128
19281
|
const raw = JSON.parse(manifestText);
|
|
@@ -19146,12 +19299,12 @@ async function buildGallerySnapshot(opts) {
|
|
|
19146
19299
|
)
|
|
19147
19300
|
);
|
|
19148
19301
|
if (spec.source) {
|
|
19149
|
-
const editPath =
|
|
19302
|
+
const editPath = path35.resolve(root, spec.source);
|
|
19150
19303
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
19151
19304
|
const editShas = await Promise.all(
|
|
19152
19305
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
19153
19306
|
const file = sourceOutputPath(spec.source, entry, index, root);
|
|
19154
|
-
return { file, sha256:
|
|
19307
|
+
return { file, sha256: existsSync30(file) ? await sha256File(file) : null };
|
|
19155
19308
|
})
|
|
19156
19309
|
);
|
|
19157
19310
|
edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
|
|
@@ -19159,7 +19312,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19159
19312
|
const companion = await readHandEditCompanion(editPath);
|
|
19160
19313
|
if (companion) {
|
|
19161
19314
|
const projectPath = handEditProjectPath(editPath);
|
|
19162
|
-
const project = companion.project &&
|
|
19315
|
+
const project = companion.project && existsSync30(projectPath) ? await fileInfo(projectPath) : null;
|
|
19163
19316
|
let projectUrl = null;
|
|
19164
19317
|
if (project) {
|
|
19165
19318
|
const id = galleryMediaId(projectPath);
|
|
@@ -19195,8 +19348,8 @@ async function buildGallerySnapshot(opts) {
|
|
|
19195
19348
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
19196
19349
|
}
|
|
19197
19350
|
} else if (spec.source) {
|
|
19198
|
-
outputs = [await describeOutput(media, root,
|
|
19199
|
-
} else if (!entry &&
|
|
19351
|
+
outputs = [await describeOutput(media, root, path35.resolve(root, spec.source))];
|
|
19352
|
+
} else if (!entry && existsSync30(spec.outFile)) {
|
|
19200
19353
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
19201
19354
|
} else {
|
|
19202
19355
|
outputs = [];
|
|
@@ -19400,7 +19553,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19400
19553
|
id: loaded.manifest.name,
|
|
19401
19554
|
name: loaded.manifest.name,
|
|
19402
19555
|
manifest: loaded.path,
|
|
19403
|
-
lock:
|
|
19556
|
+
lock: path35.resolve(opts.lockPath),
|
|
19404
19557
|
root,
|
|
19405
19558
|
provider: loaded.manifest.provider,
|
|
19406
19559
|
account: null,
|
|
@@ -19426,7 +19579,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19426
19579
|
return { snapshot, media };
|
|
19427
19580
|
}
|
|
19428
19581
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
19429
|
-
const dir =
|
|
19582
|
+
const dir = path35.dirname(path35.resolve(opts.workspacePath));
|
|
19430
19583
|
const media = /* @__PURE__ */ new Map();
|
|
19431
19584
|
const projects = [];
|
|
19432
19585
|
const items = [];
|
|
@@ -19469,7 +19622,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19469
19622
|
id: project.id,
|
|
19470
19623
|
name: loaded.manifest.name,
|
|
19471
19624
|
manifest: manifestPath,
|
|
19472
|
-
lock:
|
|
19625
|
+
lock: path35.resolve(lockPath),
|
|
19473
19626
|
root: loaded.root,
|
|
19474
19627
|
provider: loaded.manifest.provider,
|
|
19475
19628
|
account: project.account ?? null,
|
|
@@ -19485,8 +19638,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19485
19638
|
id: project.id,
|
|
19486
19639
|
name: project.id,
|
|
19487
19640
|
manifest: manifestPath,
|
|
19488
|
-
lock:
|
|
19489
|
-
root:
|
|
19641
|
+
lock: path35.resolve(lockPath),
|
|
19642
|
+
root: path35.dirname(manifestPath),
|
|
19490
19643
|
provider: project.provider,
|
|
19491
19644
|
account: project.account ?? null,
|
|
19492
19645
|
manifestSha256: null,
|
|
@@ -19513,7 +19666,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19513
19666
|
version: 1,
|
|
19514
19667
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
19515
19668
|
project: null,
|
|
19516
|
-
workspace: { path:
|
|
19669
|
+
workspace: { path: path35.resolve(opts.workspacePath), dir, projects },
|
|
19517
19670
|
filter,
|
|
19518
19671
|
totals: {
|
|
19519
19672
|
entries: projects.reduce((sum, project) => sum + project.entries, 0),
|
|
@@ -19530,7 +19683,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19530
19683
|
}
|
|
19531
19684
|
|
|
19532
19685
|
// src/gallery/page.ts
|
|
19533
|
-
import { existsSync as
|
|
19686
|
+
import { existsSync as existsSync31, readFileSync as readFileSync8 } from "fs";
|
|
19534
19687
|
|
|
19535
19688
|
// src/gallery/client-bundle.ts
|
|
19536
19689
|
import { createRequire } from "module";
|
|
@@ -19570,8 +19723,8 @@ var client;
|
|
|
19570
19723
|
function clientAssets() {
|
|
19571
19724
|
const prebuilt = new URL("gallery.js", CLIENT_DIR);
|
|
19572
19725
|
client ??= {
|
|
19573
|
-
css:
|
|
19574
|
-
js:
|
|
19726
|
+
css: readFileSync8(new URL("gallery.css", CLIENT_DIR), "utf8"),
|
|
19727
|
+
js: existsSync31(prebuilt) ? readFileSync8(prebuilt, "utf8") : bundleGalleryClient()
|
|
19575
19728
|
};
|
|
19576
19729
|
return client;
|
|
19577
19730
|
}
|
|
@@ -19714,10 +19867,10 @@ var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download
|
|
|
19714
19867
|
|
|
19715
19868
|
// src/editor/install.ts
|
|
19716
19869
|
import { createHash as createHash6 } from "crypto";
|
|
19717
|
-
import { existsSync as
|
|
19870
|
+
import { existsSync as existsSync32 } from "fs";
|
|
19718
19871
|
import { mkdir as mkdir12, readFile as readFile27, rename as rename10, rm as rm12, stat as stat4, writeFile as writeFile17 } from "fs/promises";
|
|
19719
19872
|
import os3 from "os";
|
|
19720
|
-
import
|
|
19873
|
+
import path36 from "path";
|
|
19721
19874
|
var EditorInstallError = class extends Error {
|
|
19722
19875
|
constructor(message6, file) {
|
|
19723
19876
|
super(message6);
|
|
@@ -19728,15 +19881,15 @@ var EditorInstallError = class extends Error {
|
|
|
19728
19881
|
};
|
|
19729
19882
|
function editorToolsRoot() {
|
|
19730
19883
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
19731
|
-
if (override) return
|
|
19732
|
-
if (process.platform === "darwin") return
|
|
19884
|
+
if (override) return path36.resolve(override);
|
|
19885
|
+
if (process.platform === "darwin") return path36.join(os3.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
19733
19886
|
if (process.platform === "win32") {
|
|
19734
|
-
return
|
|
19887
|
+
return path36.join(process.env.LOCALAPPDATA ?? path36.join(os3.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
19735
19888
|
}
|
|
19736
|
-
return
|
|
19889
|
+
return path36.join(process.env.XDG_CACHE_HOME ?? path36.join(os3.homedir(), ".cache"), "pixelkiln", "tools");
|
|
19737
19890
|
}
|
|
19738
19891
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
19739
|
-
return
|
|
19892
|
+
return path36.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
19740
19893
|
}
|
|
19741
19894
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
19742
19895
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -19759,8 +19912,8 @@ async function editorStatus(opts = {}) {
|
|
|
19759
19912
|
let totalBytes = 0;
|
|
19760
19913
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
19761
19914
|
totalBytes += expected.bytes;
|
|
19762
|
-
const file =
|
|
19763
|
-
const info =
|
|
19915
|
+
const file = path36.join(dir, name);
|
|
19916
|
+
const info = existsSync32(file) ? await stat4(file).catch(() => null) : null;
|
|
19764
19917
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
19765
19918
|
installedBytes += expected.bytes;
|
|
19766
19919
|
} else {
|
|
@@ -19817,7 +19970,7 @@ async function installEditor(opts = {}) {
|
|
|
19817
19970
|
if (digest2 !== expected.sha256) {
|
|
19818
19971
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
19819
19972
|
}
|
|
19820
|
-
const final =
|
|
19973
|
+
const final = path36.join(dir, name);
|
|
19821
19974
|
const tmp = `${final}.${process.pid}.part`;
|
|
19822
19975
|
try {
|
|
19823
19976
|
await writeFile17(tmp, bytes);
|
|
@@ -19863,12 +20016,12 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
19863
20016
|
".json": "application/json; charset=utf-8"
|
|
19864
20017
|
};
|
|
19865
20018
|
function editorContentType(name) {
|
|
19866
|
-
return EDITOR_CONTENT_TYPES[
|
|
20019
|
+
return EDITOR_CONTENT_TYPES[path36.extname(name).toLowerCase()] ?? null;
|
|
19867
20020
|
}
|
|
19868
20021
|
|
|
19869
20022
|
// src/gallery/editor.ts
|
|
19870
20023
|
import { readFile as readFile28 } from "fs/promises";
|
|
19871
|
-
import
|
|
20024
|
+
import path37 from "path";
|
|
19872
20025
|
function editorRoute(release, name = "index.html") {
|
|
19873
20026
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
19874
20027
|
}
|
|
@@ -19941,7 +20094,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
19941
20094
|
if (!status.installed) return null;
|
|
19942
20095
|
let bytes;
|
|
19943
20096
|
try {
|
|
19944
|
-
bytes = await readFile28(
|
|
20097
|
+
bytes = await readFile28(path37.join(dir, name));
|
|
19945
20098
|
} catch {
|
|
19946
20099
|
verified = null;
|
|
19947
20100
|
return null;
|
|
@@ -20633,15 +20786,15 @@ function createGenerateHandlers(opts) {
|
|
|
20633
20786
|
|
|
20634
20787
|
// src/pipeline/salvage.ts
|
|
20635
20788
|
import { readFile as readFile30 } from "fs/promises";
|
|
20636
|
-
import { existsSync as
|
|
20637
|
-
import
|
|
20789
|
+
import { existsSync as existsSync33 } from "fs";
|
|
20790
|
+
import path38 from "path";
|
|
20638
20791
|
function providerClaimId(provider, objectId) {
|
|
20639
20792
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
20640
20793
|
}
|
|
20641
20794
|
async function loadClaims(lockPaths, opts = {}) {
|
|
20642
20795
|
const claimed = /* @__PURE__ */ new Set();
|
|
20643
20796
|
for (const p of lockPaths) {
|
|
20644
|
-
if (!
|
|
20797
|
+
if (!existsSync33(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
20645
20798
|
let parsed;
|
|
20646
20799
|
try {
|
|
20647
20800
|
parsed = parseLock(JSON.parse(await readFile30(p, "utf8")));
|
|
@@ -20748,20 +20901,20 @@ function matchOrphanStyle(prompt, manifest) {
|
|
|
20748
20901
|
return matchStyleByPattern(prompt, manifest);
|
|
20749
20902
|
}
|
|
20750
20903
|
async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
|
|
20751
|
-
const own =
|
|
20904
|
+
const own = path38.resolve(ownManifestPath);
|
|
20752
20905
|
const siblingManifestPaths = [
|
|
20753
20906
|
.../* @__PURE__ */ new Set([
|
|
20754
20907
|
...workspaceManifestPaths,
|
|
20755
|
-
...claimPaths.map((c) =>
|
|
20908
|
+
...claimPaths.map((c) => path38.join(path38.dirname(path38.resolve(c)), "pixelkiln.manifest.json"))
|
|
20756
20909
|
])
|
|
20757
20910
|
];
|
|
20758
20911
|
const siblings = [];
|
|
20759
20912
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
20760
|
-
if (
|
|
20761
|
-
if (!
|
|
20913
|
+
if (path38.resolve(siblingManifestPath) === own) continue;
|
|
20914
|
+
if (!existsSync33(siblingManifestPath)) continue;
|
|
20762
20915
|
try {
|
|
20763
20916
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
20764
|
-
siblings.push({ label:
|
|
20917
|
+
siblings.push({ label: path38.basename(path38.dirname(siblingManifestPath)), manifest });
|
|
20765
20918
|
} catch {
|
|
20766
20919
|
}
|
|
20767
20920
|
}
|
|
@@ -20882,7 +21035,7 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
20882
21035
|
|
|
20883
21036
|
// src/pick/salvage-server.ts
|
|
20884
21037
|
import { mkdir as mkdir13, writeFile as writeFile18, readFile as readFile31 } from "fs/promises";
|
|
20885
|
-
import
|
|
21038
|
+
import path39 from "path";
|
|
20886
21039
|
|
|
20887
21040
|
// src/pick/salvage-sheet.ts
|
|
20888
21041
|
var escapeHtml3 = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -21048,7 +21201,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21048
21201
|
});
|
|
21049
21202
|
const html = renderSalvageSheet(orphans, {
|
|
21050
21203
|
styleId: ctx.styleId,
|
|
21051
|
-
importDir:
|
|
21204
|
+
importDir: path39.relative(process.cwd(), ctx.importDir) || "."
|
|
21052
21205
|
});
|
|
21053
21206
|
const byId = new Map(orphans.map((o) => [o.id, o]));
|
|
21054
21207
|
const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
|
|
@@ -21104,9 +21257,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21104
21257
|
if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
|
|
21105
21258
|
decodePng(buf);
|
|
21106
21259
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
21107
|
-
const rel =
|
|
21108
|
-
const outFile =
|
|
21109
|
-
await mkdir13(
|
|
21260
|
+
const rel = path39.join("_salvaged", `${assetId}.png`);
|
|
21261
|
+
const outFile = path39.resolve(ctx.importDir, rel);
|
|
21262
|
+
await mkdir13(path39.dirname(outFile), { recursive: true });
|
|
21110
21263
|
await writeFile18(outFile, buf);
|
|
21111
21264
|
ctx.manifest.assets[assetId] = {
|
|
21112
21265
|
prompt: orphan.prompt,
|
|
@@ -21139,7 +21292,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21139
21292
|
sourceUrl: durableSource,
|
|
21140
21293
|
sourceUrls: durableSource ? [{ url: durableSource }] : [],
|
|
21141
21294
|
outputs: [{
|
|
21142
|
-
path: portableOutputPath(outFile,
|
|
21295
|
+
path: portableOutputPath(outFile, path39.dirname(ctx.manifestPath)),
|
|
21143
21296
|
sha256: sha256(buf)
|
|
21144
21297
|
}],
|
|
21145
21298
|
submittedAt: orphan.createdAt,
|