pixelkiln 0.95.0 → 0.96.1
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 +608 -494
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +211 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +497 -38
- package/dist/index.d.ts +497 -38
- package/dist/index.js +210 -124
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +32 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1123,7 +1123,7 @@ var AssetDeriveSchema = z.object({
|
|
|
1123
1123
|
/** scale: `nearest` (default) keeps hard edges; `box` averages the covered pixels. */
|
|
1124
1124
|
mode: z.enum(["nearest", "box"]).optional()
|
|
1125
1125
|
}).strict().superRefine((derive, context) => {
|
|
1126
|
-
const issue = (message6,
|
|
1126
|
+
const issue = (message6, path43) => context.addIssue({ code: z.ZodIssueCode.custom, message: message6, path: [path43] });
|
|
1127
1127
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
1128
1128
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
1129
1129
|
}
|
|
@@ -1424,6 +1424,18 @@ var PostprocessSchema = z.object({
|
|
|
1424
1424
|
distance: z.literal("redmean")
|
|
1425
1425
|
}).optional()
|
|
1426
1426
|
});
|
|
1427
|
+
var LockOriginSchema = z.object({
|
|
1428
|
+
tool: z.string().min(1).optional(),
|
|
1429
|
+
prompt: z.string().optional(),
|
|
1430
|
+
seed: z.number().int().optional(),
|
|
1431
|
+
steps: z.array(z.string().min(1)).optional(),
|
|
1432
|
+
raw: z.object({ sha256: z.string().regex(/^[0-9a-f]{64}$/) }).optional()
|
|
1433
|
+
});
|
|
1434
|
+
var LockImportedSchema = z.object({
|
|
1435
|
+
source: z.string().min(1),
|
|
1436
|
+
note: z.string().optional(),
|
|
1437
|
+
importedAt: z.string()
|
|
1438
|
+
}).strict();
|
|
1427
1439
|
var LockSourceSchema = z.object({
|
|
1428
1440
|
url: z.string(),
|
|
1429
1441
|
role: z.string().optional(),
|
|
@@ -1474,6 +1486,9 @@ var LockHistoryEntrySchema = z.object({
|
|
|
1474
1486
|
motionShare: LockMotionShareSchema.optional(),
|
|
1475
1487
|
/** A terrain set's settings outside specHash; see LockEntrySchema.terrainSettings. */
|
|
1476
1488
|
terrainSettings: LockTerrainSettingsSchema.optional(),
|
|
1489
|
+
/** Imported art keeps its provenance when it is replaced and when it comes back. */
|
|
1490
|
+
imported: LockImportedSchema.optional(),
|
|
1491
|
+
origin: LockOriginSchema.optional(),
|
|
1477
1492
|
/** When the replacement was submitted. */
|
|
1478
1493
|
retiredAt: z.string()
|
|
1479
1494
|
});
|
|
@@ -1646,11 +1661,9 @@ var LockEntrySchema = z.object({
|
|
|
1646
1661
|
* hand edit, another tool) and brought in with `adopt --local`: nothing was
|
|
1647
1662
|
* submitted, so jobId and cost are empty. Absent on generated entries.
|
|
1648
1663
|
*/
|
|
1649
|
-
imported:
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
importedAt: z.string()
|
|
1653
|
-
}).strict().optional(),
|
|
1664
|
+
imported: LockImportedSchema.optional(),
|
|
1665
|
+
/** More on imported art: tool, prompt, seed, post-process steps, raw original. See LockOriginSchema. */
|
|
1666
|
+
origin: LockOriginSchema.optional(),
|
|
1654
1667
|
/**
|
|
1655
1668
|
* For a derived asset: what it was made from, and a hash of that input when
|
|
1656
1669
|
* this was made. Compared with the input's current bytes by the plan, so a
|
|
@@ -2217,9 +2230,9 @@ var PixelLabClient = class {
|
|
|
2217
2230
|
apiKey;
|
|
2218
2231
|
http;
|
|
2219
2232
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
2220
|
-
async request(
|
|
2233
|
+
async request(path43, init) {
|
|
2221
2234
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
2222
|
-
const res = await this.http(`${BASE}${
|
|
2235
|
+
const res = await this.http(`${BASE}${path43}`, {
|
|
2223
2236
|
...init,
|
|
2224
2237
|
headers: {
|
|
2225
2238
|
Authorization: auth,
|
|
@@ -2230,13 +2243,13 @@ var PixelLabClient = class {
|
|
|
2230
2243
|
const text = await res.text();
|
|
2231
2244
|
if (!res.ok) {
|
|
2232
2245
|
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' : "";
|
|
2233
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
2246
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path43} \u2192 ${res.status}${hint}`, res.status, text);
|
|
2234
2247
|
}
|
|
2235
2248
|
if (!text) return {};
|
|
2236
2249
|
try {
|
|
2237
2250
|
return JSON.parse(text);
|
|
2238
2251
|
} catch {
|
|
2239
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
2252
|
+
throw new Error(`${init?.method ?? "GET"} ${path43} returned invalid JSON`);
|
|
2240
2253
|
}
|
|
2241
2254
|
}
|
|
2242
2255
|
async balance() {
|
|
@@ -2689,10 +2702,10 @@ var PixelLabClient = class {
|
|
|
2689
2702
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
2690
2703
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
2691
2704
|
const south = args.reference?.south;
|
|
2692
|
-
let
|
|
2705
|
+
let path43;
|
|
2693
2706
|
let body;
|
|
2694
2707
|
if (args.mode === "v3") {
|
|
2695
|
-
|
|
2708
|
+
path43 = "/create-character-v3";
|
|
2696
2709
|
body = {
|
|
2697
2710
|
description: args.description,
|
|
2698
2711
|
image_size: imageSize,
|
|
@@ -2706,7 +2719,7 @@ var PixelLabClient = class {
|
|
|
2706
2719
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
2707
2720
|
};
|
|
2708
2721
|
} else if (args.mode === "pro-flash") {
|
|
2709
|
-
|
|
2722
|
+
path43 = "/create-character-pro-flash";
|
|
2710
2723
|
const traits = args.styleTraits;
|
|
2711
2724
|
body = {
|
|
2712
2725
|
description: args.description,
|
|
@@ -2730,7 +2743,7 @@ var PixelLabClient = class {
|
|
|
2730
2743
|
} : {}
|
|
2731
2744
|
};
|
|
2732
2745
|
} else if (args.mode === "pro") {
|
|
2733
|
-
|
|
2746
|
+
path43 = "/create-character-pro";
|
|
2734
2747
|
body = {
|
|
2735
2748
|
description: args.description,
|
|
2736
2749
|
image_size: imageSize,
|
|
@@ -2744,7 +2757,7 @@ var PixelLabClient = class {
|
|
|
2744
2757
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
2745
2758
|
};
|
|
2746
2759
|
} else {
|
|
2747
|
-
|
|
2760
|
+
path43 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
2748
2761
|
body = {
|
|
2749
2762
|
description: args.description,
|
|
2750
2763
|
image_size: imageSize,
|
|
@@ -2762,8 +2775,8 @@ var PixelLabClient = class {
|
|
|
2762
2775
|
};
|
|
2763
2776
|
}
|
|
2764
2777
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
2765
|
-
const raw = await this.request(
|
|
2766
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
2778
|
+
const raw = await this.request(path43, { method: "POST", body: JSON.stringify(body) });
|
|
2779
|
+
return validateResponse(CharacterSubmitSchema, raw, path43.slice(1));
|
|
2767
2780
|
}
|
|
2768
2781
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
2769
2782
|
async createCharacterState(args) {
|
|
@@ -4104,10 +4117,10 @@ function normalizeHex(value) {
|
|
|
4104
4117
|
function sha256(data) {
|
|
4105
4118
|
return createHash("sha256").update(data).digest("hex");
|
|
4106
4119
|
}
|
|
4107
|
-
async function sha256File(
|
|
4120
|
+
async function sha256File(path43) {
|
|
4108
4121
|
return new Promise((resolve, reject) => {
|
|
4109
4122
|
const hash = createHash("sha256");
|
|
4110
|
-
const stream = createReadStream(
|
|
4123
|
+
const stream = createReadStream(path43);
|
|
4111
4124
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
4112
4125
|
stream.on("error", reject);
|
|
4113
4126
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -7942,9 +7955,9 @@ var RetroDiffusionClient = class {
|
|
|
7942
7955
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
7943
7956
|
return Buffer.from(await response.arrayBuffer());
|
|
7944
7957
|
}
|
|
7945
|
-
async call(
|
|
7958
|
+
async call(path43, init = {}) {
|
|
7946
7959
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
7947
|
-
const response = await this.request(`${this.baseUrl}${
|
|
7960
|
+
const response = await this.request(`${this.baseUrl}${path43}`, {
|
|
7948
7961
|
...init,
|
|
7949
7962
|
headers: {
|
|
7950
7963
|
"Content-Type": "application/json",
|
|
@@ -13740,6 +13753,15 @@ async function anyOutputModified(entry, spec) {
|
|
|
13740
13753
|
}
|
|
13741
13754
|
return false;
|
|
13742
13755
|
}
|
|
13756
|
+
async function modifiedReason(entry, spec) {
|
|
13757
|
+
if (!entry.imported) return "output modified since download";
|
|
13758
|
+
const raw = entry.origin?.raw?.sha256;
|
|
13759
|
+
if (raw && existsSync13(currentEntryOutputPath(entry, spec, 0)) && await sha256File(currentEntryOutputPath(entry, spec, 0)) === raw) {
|
|
13760
|
+
const steps = entry.origin?.steps?.length ? ` (${entry.origin.steps.join("; ")})` : "";
|
|
13761
|
+
return `file is the unprocessed original; apply the recorded post-processing again${steps}, or run adopt --local --force to record it as it is`;
|
|
13762
|
+
}
|
|
13763
|
+
return "file changed since it was imported; run adopt --local --force to record the new version";
|
|
13764
|
+
}
|
|
13743
13765
|
function dependencies(spec) {
|
|
13744
13766
|
return [
|
|
13745
13767
|
spec.mirror?.sourceSpec,
|
|
@@ -13893,7 +13915,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
13893
13915
|
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !existsSync13(currentEntryOutputPath(entry, spec, index))).map((o) => o.role ?? "asset").join(", ")}`;
|
|
13894
13916
|
} else if (await anyOutputModified(entry, spec)) {
|
|
13895
13917
|
state = "orphaned";
|
|
13896
|
-
reason =
|
|
13918
|
+
reason = await modifiedReason(entry, spec);
|
|
13897
13919
|
} else if (spec.derive) {
|
|
13898
13920
|
state = "ok";
|
|
13899
13921
|
reason = "up to date";
|
|
@@ -15023,10 +15045,10 @@ function isSha256Hash(value) {
|
|
|
15023
15045
|
function parseCache(value) {
|
|
15024
15046
|
return HashCacheSchema.parse(value);
|
|
15025
15047
|
}
|
|
15026
|
-
async function loadCache(
|
|
15027
|
-
if (!existsSync17(
|
|
15048
|
+
async function loadCache(path43) {
|
|
15049
|
+
if (!existsSync17(path43)) return { version: 1, hashes: {} };
|
|
15028
15050
|
try {
|
|
15029
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(
|
|
15051
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(path43, "utf8")));
|
|
15030
15052
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
15031
15053
|
return {
|
|
15032
15054
|
version: 1,
|
|
@@ -15038,18 +15060,18 @@ async function loadCache(path42) {
|
|
|
15038
15060
|
return { version: 1, hashes: {} };
|
|
15039
15061
|
}
|
|
15040
15062
|
}
|
|
15041
|
-
async function saveCache(
|
|
15063
|
+
async function saveCache(path43, cache) {
|
|
15042
15064
|
const sorted = {};
|
|
15043
15065
|
for (const key2 of Object.keys(cache.hashes).sort()) {
|
|
15044
15066
|
const hash = cache.hashes[key2];
|
|
15045
15067
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key2}`);
|
|
15046
15068
|
sorted[key2] = hash;
|
|
15047
15069
|
}
|
|
15048
|
-
await mkdir7(pathModule.dirname(pathModule.resolve(
|
|
15049
|
-
const tmp = `${
|
|
15070
|
+
await mkdir7(pathModule.dirname(pathModule.resolve(path43)), { recursive: true });
|
|
15071
|
+
const tmp = `${path43}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
15050
15072
|
try {
|
|
15051
15073
|
await writeFile7(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
15052
|
-
await rename5(tmp,
|
|
15074
|
+
await rename5(tmp, path43);
|
|
15053
15075
|
} finally {
|
|
15054
15076
|
await rm4(tmp, { force: true });
|
|
15055
15077
|
}
|
|
@@ -15432,6 +15454,8 @@ function retireGeneration(entry, retiredAt) {
|
|
|
15432
15454
|
...entry.terrainConnect ? { terrainConnect: entry.terrainConnect } : {},
|
|
15433
15455
|
...entry.motionShare ? { motionShare: entry.motionShare } : {},
|
|
15434
15456
|
...entry.terrainSettings ? { terrainSettings: entry.terrainSettings } : {},
|
|
15457
|
+
...entry.imported ? { imported: entry.imported } : {},
|
|
15458
|
+
...entry.origin ? { origin: entry.origin } : {},
|
|
15435
15459
|
retiredAt
|
|
15436
15460
|
};
|
|
15437
15461
|
}
|
|
@@ -15531,6 +15555,10 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
15531
15555
|
// Likewise its settings; a generation from before they were recorded
|
|
15532
15556
|
// comes back with none and is taken as current.
|
|
15533
15557
|
terrainSettings: generation.terrainSettings,
|
|
15558
|
+
// Imported art comes back as imported, with its provenance; a generated
|
|
15559
|
+
// one clears both, so the plan does not call it imported.
|
|
15560
|
+
imported: generation.imported,
|
|
15561
|
+
origin: generation.origin,
|
|
15534
15562
|
history
|
|
15535
15563
|
});
|
|
15536
15564
|
await saveLock(lockPath, lock);
|
|
@@ -17224,15 +17252,23 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
17224
17252
|
// src/pipeline/import.ts
|
|
17225
17253
|
import { existsSync as existsSync24 } from "fs";
|
|
17226
17254
|
import { readFile as readFile17 } from "fs/promises";
|
|
17255
|
+
import path29 from "path";
|
|
17227
17256
|
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
17228
17257
|
const png = decodePng(bytes);
|
|
17229
17258
|
const at = now.toISOString();
|
|
17259
|
+
const origin = {
|
|
17260
|
+
...opts.tool ? { tool: opts.tool } : {},
|
|
17261
|
+
...opts.prompt ? { prompt: opts.prompt } : {},
|
|
17262
|
+
...opts.seed !== void 0 ? { seed: opts.seed } : {},
|
|
17263
|
+
...opts.steps?.length ? { steps: opts.steps } : {},
|
|
17264
|
+
...opts.rawSha256 ? { raw: { sha256: opts.rawSha256 } } : {}
|
|
17265
|
+
};
|
|
17230
17266
|
return {
|
|
17231
17267
|
styleId: spec.styleId,
|
|
17232
17268
|
assetId: spec.assetId,
|
|
17233
17269
|
specHash: spec.specHash,
|
|
17234
17270
|
generator: spec.generator,
|
|
17235
|
-
prompt: spec.prompt,
|
|
17271
|
+
prompt: opts.prompt ?? spec.prompt,
|
|
17236
17272
|
width: png.width,
|
|
17237
17273
|
height: png.height,
|
|
17238
17274
|
jobId: opts.objectId ?? null,
|
|
@@ -17246,9 +17282,10 @@ function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Da
|
|
|
17246
17282
|
outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
|
|
17247
17283
|
submittedAt: null,
|
|
17248
17284
|
downloadedAt: at,
|
|
17249
|
-
cost: 0,
|
|
17285
|
+
cost: opts.cost ?? 0,
|
|
17250
17286
|
costUnit: spec.costUnit,
|
|
17251
17287
|
provider: spec.provider,
|
|
17288
|
+
...Object.keys(origin).length ? { origin } : {},
|
|
17252
17289
|
...spec.external ? { external: { builder: spec.external.builder, inputs: spec.external.inputs } } : {},
|
|
17253
17290
|
imported: {
|
|
17254
17291
|
source: opts.source ?? "external",
|
|
@@ -17267,6 +17304,19 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
17267
17304
|
if (opts.objectId && specs.length !== 1) {
|
|
17268
17305
|
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
17269
17306
|
}
|
|
17307
|
+
const cacheDir = opts.cacheDir === false ? null : path29.resolve(opts.cacheDir ?? path29.join(path29.dirname(lockPath), ".pixelkiln", "cache"));
|
|
17308
|
+
let rawSha256;
|
|
17309
|
+
let rawBytes;
|
|
17310
|
+
if (opts.raw) {
|
|
17311
|
+
if (specs.length !== 1) throw new Error(`--raw names one original; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
17312
|
+
try {
|
|
17313
|
+
rawBytes = await readFile17(opts.raw);
|
|
17314
|
+
decodePng(rawBytes);
|
|
17315
|
+
} catch (error) {
|
|
17316
|
+
throw new Error(`--raw ${opts.raw} is not a readable PNG: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
17317
|
+
}
|
|
17318
|
+
rawSha256 = sha256(rawBytes);
|
|
17319
|
+
}
|
|
17270
17320
|
const imported = [];
|
|
17271
17321
|
const skipped = [];
|
|
17272
17322
|
for (const spec of specs) {
|
|
@@ -17285,8 +17335,10 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
17285
17335
|
continue;
|
|
17286
17336
|
}
|
|
17287
17337
|
let patch;
|
|
17338
|
+
let bytes;
|
|
17288
17339
|
try {
|
|
17289
|
-
|
|
17340
|
+
bytes = await readFile17(spec.outFile);
|
|
17341
|
+
patch = buildImportedEntry(spec, bytes, { ...opts, rawSha256 }, /* @__PURE__ */ new Date());
|
|
17290
17342
|
} catch (error) {
|
|
17291
17343
|
skipped.push({ key: key2, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
17292
17344
|
continue;
|
|
@@ -17295,7 +17347,19 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
17295
17347
|
imported.push({ key: key2, entry: patch });
|
|
17296
17348
|
continue;
|
|
17297
17349
|
}
|
|
17298
|
-
|
|
17350
|
+
const existing = lock.entries[key2];
|
|
17351
|
+
const history = existing?.outputs[0]?.sha256 === sha256(bytes) ? existing.history : historyAfterReplacing(existing, opts.historyLimit ?? DEFAULT_HISTORY_LIMIT, patch.downloadedAt ?? (/* @__PURE__ */ new Date()).toISOString());
|
|
17352
|
+
if (cacheDir) {
|
|
17353
|
+
await cacheMedia(cacheDir, bytes, MediaType.PNG);
|
|
17354
|
+
if (rawBytes) await cacheMedia(cacheDir, rawBytes, MediaType.PNG);
|
|
17355
|
+
}
|
|
17356
|
+
imported.push({ key: key2, entry: upsert(lock, key2, {
|
|
17357
|
+
...patch,
|
|
17358
|
+
// An import replaces the whole record: clear what the entry held that
|
|
17359
|
+
// an import never has, or a regenerated entry would keep stale links.
|
|
17360
|
+
origin: patch.origin,
|
|
17361
|
+
history
|
|
17362
|
+
}) });
|
|
17299
17363
|
}
|
|
17300
17364
|
if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
|
|
17301
17365
|
return { imported, skipped };
|
|
@@ -17340,7 +17404,7 @@ import { readFile as readFile20 } from "fs/promises";
|
|
|
17340
17404
|
// src/pipeline/init.ts
|
|
17341
17405
|
import { readdir as readdir3, readFile as readFile18, writeFile as writeFile10 } from "fs/promises";
|
|
17342
17406
|
import { existsSync as existsSync25 } from "fs";
|
|
17343
|
-
import
|
|
17407
|
+
import path30 from "path";
|
|
17344
17408
|
function pngSize(buf) {
|
|
17345
17409
|
if (buf.length < 24) return null;
|
|
17346
17410
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -17354,7 +17418,7 @@ function slugify(value) {
|
|
|
17354
17418
|
async function walk(dir, exclude) {
|
|
17355
17419
|
const out = [];
|
|
17356
17420
|
for (const entry of await readdir3(dir, { withFileTypes: true })) {
|
|
17357
|
-
const full =
|
|
17421
|
+
const full = path30.join(dir, entry.name);
|
|
17358
17422
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
17359
17423
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
17360
17424
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -17373,9 +17437,9 @@ async function scanAssets(root, opts = {}) {
|
|
|
17373
17437
|
skipped.push(`${file} (not a readable PNG)`);
|
|
17374
17438
|
continue;
|
|
17375
17439
|
}
|
|
17376
|
-
const rel =
|
|
17377
|
-
const category =
|
|
17378
|
-
let id = slugify(
|
|
17440
|
+
const rel = path30.relative(root, file);
|
|
17441
|
+
const category = path30.dirname(rel) === "." ? "" : path30.dirname(rel);
|
|
17442
|
+
let id = slugify(path30.basename(rel));
|
|
17379
17443
|
if (seen.has(id)) {
|
|
17380
17444
|
const n = seen.get(id) + 1;
|
|
17381
17445
|
seen.set(id, n);
|
|
@@ -18136,12 +18200,12 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
18136
18200
|
import { createHash as createHash5 } from "crypto";
|
|
18137
18201
|
import { existsSync as existsSync32 } from "fs";
|
|
18138
18202
|
import { readFile as readFile27, stat as stat3 } from "fs/promises";
|
|
18139
|
-
import
|
|
18203
|
+
import path38 from "path";
|
|
18140
18204
|
|
|
18141
18205
|
// src/workspace.ts
|
|
18142
18206
|
import { mkdir as mkdir9, readFile as readFile21, rename as rename7, rm as rm7, writeFile as writeFile11 } from "fs/promises";
|
|
18143
18207
|
import { existsSync as existsSync27 } from "fs";
|
|
18144
|
-
import
|
|
18208
|
+
import path31 from "path";
|
|
18145
18209
|
import { z as z7 } from "zod";
|
|
18146
18210
|
var WorkspaceProjectSchema = z7.object({
|
|
18147
18211
|
id: z7.string().min(1),
|
|
@@ -18183,7 +18247,7 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
18183
18247
|
version: 1,
|
|
18184
18248
|
projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
|
|
18185
18249
|
};
|
|
18186
|
-
await mkdir9(
|
|
18250
|
+
await mkdir9(path31.dirname(path31.resolve(workspacePath)), { recursive: true });
|
|
18187
18251
|
const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18188
18252
|
try {
|
|
18189
18253
|
await writeFile11(tmp, JSON.stringify(sorted, null, 2) + "\n");
|
|
@@ -18193,12 +18257,12 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
18193
18257
|
}
|
|
18194
18258
|
}
|
|
18195
18259
|
function toPortablePath(dir, absolute) {
|
|
18196
|
-
return
|
|
18260
|
+
return path31.relative(dir, absolute).split(path31.sep).join("/");
|
|
18197
18261
|
}
|
|
18198
18262
|
function resolveProject(dir, project) {
|
|
18199
18263
|
return {
|
|
18200
|
-
manifestPath:
|
|
18201
|
-
lockPath:
|
|
18264
|
+
manifestPath: path31.resolve(dir, project.manifest.split("/").join(path31.sep)),
|
|
18265
|
+
lockPath: path31.resolve(dir, project.lock.split("/").join(path31.sep))
|
|
18202
18266
|
};
|
|
18203
18267
|
}
|
|
18204
18268
|
function validateWorkspace(ws, dir) {
|
|
@@ -18211,7 +18275,7 @@ function validateWorkspace(ws, dir) {
|
|
|
18211
18275
|
const { manifestPath, lockPath } = resolveProject(dir, project);
|
|
18212
18276
|
lockOwners.set(lockPath, [...lockOwners.get(lockPath) ?? [], project.id]);
|
|
18213
18277
|
manifestOwners.set(manifestPath, [...manifestOwners.get(manifestPath) ?? [], project.id]);
|
|
18214
|
-
if (
|
|
18278
|
+
if (path31.isAbsolute(project.manifest) || path31.isAbsolute(project.lock)) {
|
|
18215
18279
|
diagnostics.push({
|
|
18216
18280
|
id: "absolute-path",
|
|
18217
18281
|
level: "warning",
|
|
@@ -18273,15 +18337,15 @@ function validateWorkspace(ws, dir) {
|
|
|
18273
18337
|
|
|
18274
18338
|
// src/gallery/edit.ts
|
|
18275
18339
|
import { readFile as readFile26, rename as rename10, writeFile as writeFile17 } from "fs/promises";
|
|
18276
|
-
import
|
|
18340
|
+
import path37 from "path";
|
|
18277
18341
|
import { z as z13 } from "zod";
|
|
18278
18342
|
|
|
18279
18343
|
// src/manifest-edit.ts
|
|
18280
18344
|
import { readFile as readFile22, rename as rename8, rm as rm8, writeFile as writeFile12 } from "fs/promises";
|
|
18281
|
-
import
|
|
18345
|
+
import path32 from "path";
|
|
18282
18346
|
import { z as z8 } from "zod";
|
|
18283
18347
|
var HexSha = z8.string().regex(/^[0-9a-f]{64}$/);
|
|
18284
|
-
var ProjectFileSchema = z8.string().min(1).refine((file) => !
|
|
18348
|
+
var ProjectFileSchema = z8.string().min(1).refine((file) => !path32.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
|
|
18285
18349
|
var AssetPatchSchema = z8.object({
|
|
18286
18350
|
prompt: z8.string().optional(),
|
|
18287
18351
|
/** Per-style override for the style being viewed; null removes it. */
|
|
@@ -18701,7 +18765,7 @@ function applyEdit(raw, edit) {
|
|
|
18701
18765
|
}
|
|
18702
18766
|
}
|
|
18703
18767
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
18704
|
-
const absolute =
|
|
18768
|
+
const absolute = path32.resolve(manifestPath);
|
|
18705
18769
|
const original = await readFile22(absolute, "utf8");
|
|
18706
18770
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
18707
18771
|
let raw;
|
|
@@ -18715,9 +18779,9 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
18715
18779
|
applyEdit(raw, edit);
|
|
18716
18780
|
const next = serializeLike(original, raw);
|
|
18717
18781
|
if (next === original) return unchanged(absolute, original);
|
|
18718
|
-
const tmp =
|
|
18719
|
-
|
|
18720
|
-
`.${
|
|
18782
|
+
const tmp = path32.join(
|
|
18783
|
+
path32.dirname(absolute),
|
|
18784
|
+
`.${path32.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
|
|
18721
18785
|
);
|
|
18722
18786
|
try {
|
|
18723
18787
|
await writeFile12(tmp, next);
|
|
@@ -18748,16 +18812,16 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
18748
18812
|
// src/pipeline/hand-edit.ts
|
|
18749
18813
|
import { existsSync as existsSync28 } from "fs";
|
|
18750
18814
|
import { copyFile, mkdir as mkdir10, readFile as readFile23, rename as rename9, rm as rm9, writeFile as writeFile13 } from "fs/promises";
|
|
18751
|
-
import
|
|
18815
|
+
import path33 from "path";
|
|
18752
18816
|
import { z as z9 } from "zod";
|
|
18753
18817
|
var HAND_EDIT_DIR = "edits";
|
|
18754
18818
|
function handEditPath(loaded, spec) {
|
|
18755
18819
|
const style = loaded.manifest.styles[spec.styleId];
|
|
18756
|
-
const outDir =
|
|
18757
|
-
const relative =
|
|
18758
|
-
const inside = relative && !relative.startsWith("..") && !
|
|
18759
|
-
const file = inside ? relative :
|
|
18760
|
-
return
|
|
18820
|
+
const outDir = path33.resolve(loaded.root, style?.outDir ?? ".");
|
|
18821
|
+
const relative = path33.relative(outDir, spec.outFile);
|
|
18822
|
+
const inside = relative && !relative.startsWith("..") && !path33.isAbsolute(relative);
|
|
18823
|
+
const file = inside ? relative : path33.basename(spec.outFile);
|
|
18824
|
+
return path33.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
|
|
18761
18825
|
}
|
|
18762
18826
|
function handEditBases(spec, lock) {
|
|
18763
18827
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -18791,7 +18855,27 @@ function handEditMembers(loaded, spec, lock, editPath) {
|
|
|
18791
18855
|
}
|
|
18792
18856
|
return [{ role: null, path: editPath, base: bases?.[0]?.path ?? null }];
|
|
18793
18857
|
}
|
|
18858
|
+
function refuseUneditable(spec) {
|
|
18859
|
+
const key2 = `${spec.styleId}/${spec.assetId}`;
|
|
18860
|
+
if (spec.derive) {
|
|
18861
|
+
const from = spec.derive.source.kind === "asset" ? spec.derive.source.assetId : spec.derive.source.file;
|
|
18862
|
+
throw new ManifestEditError(
|
|
18863
|
+
`${key2} is derived from ${from} (${spec.derive.transform}), so it has no hand edit of its own; edit its source, or change the derive transform in the manifest`
|
|
18864
|
+
);
|
|
18865
|
+
}
|
|
18866
|
+
if (spec.external) {
|
|
18867
|
+
throw new ManifestEditError(
|
|
18868
|
+
`${key2} is built outside pixelkiln (${spec.external.builder}); change it there, then run pixelkiln adopt --local --force to record the new file`
|
|
18869
|
+
);
|
|
18870
|
+
}
|
|
18871
|
+
if (spec.mirror) {
|
|
18872
|
+
throw new ManifestEditError(
|
|
18873
|
+
`${key2} is a flip of ${spec.mirror.sourceAssetId}, so it has no hand edit of its own; edit ${spec.mirror.sourceAssetId} and flip it again`
|
|
18874
|
+
);
|
|
18875
|
+
}
|
|
18876
|
+
}
|
|
18794
18877
|
async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
18878
|
+
refuseUneditable(spec);
|
|
18795
18879
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
18796
18880
|
if (entry && entry.outputs.length > 1 && !isMemberSetEntry(entry)) {
|
|
18797
18881
|
throw new ManifestEditError(
|
|
@@ -18803,7 +18887,7 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
18803
18887
|
`${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`
|
|
18804
18888
|
);
|
|
18805
18889
|
}
|
|
18806
|
-
const existing = spec.source ?
|
|
18890
|
+
const existing = spec.source ? path33.resolve(loaded.root, spec.source) : null;
|
|
18807
18891
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
18808
18892
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
18809
18893
|
let created = false;
|
|
@@ -18814,7 +18898,7 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
18814
18898
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
18815
18899
|
);
|
|
18816
18900
|
}
|
|
18817
|
-
await mkdir10(
|
|
18901
|
+
await mkdir10(path33.dirname(member.path), { recursive: true });
|
|
18818
18902
|
await copyFile(member.base, member.path);
|
|
18819
18903
|
created = true;
|
|
18820
18904
|
}
|
|
@@ -18905,6 +18989,7 @@ async function readHandEditCompanion(editPath) {
|
|
|
18905
18989
|
}
|
|
18906
18990
|
var MAX_HAND_EDIT_BYTES = 16 * 1024 * 1024;
|
|
18907
18991
|
async function saveHandEdit(loaded, lock, spec, input) {
|
|
18992
|
+
refuseUneditable(spec);
|
|
18908
18993
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
18909
18994
|
const memberSet = entry ? isMemberSetEntry(entry) : false;
|
|
18910
18995
|
const incoming = input.frames ?? (input.png ? [{ role: null, png: input.png }] : []);
|
|
@@ -18952,7 +19037,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
18952
19037
|
editor: input.editor,
|
|
18953
19038
|
protocol: input.protocol,
|
|
18954
19039
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
18955
|
-
project: projectPath ?
|
|
19040
|
+
project: projectPath ? path33.basename(projectPath) : null,
|
|
18956
19041
|
outputs: incoming.map((frame, index) => ({
|
|
18957
19042
|
role: frame.role,
|
|
18958
19043
|
basedOn: basedOnHash(entry, index),
|
|
@@ -18996,7 +19081,7 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
18996
19081
|
// src/gallery/upload.ts
|
|
18997
19082
|
import { existsSync as existsSync29 } from "fs";
|
|
18998
19083
|
import { mkdir as mkdir11, writeFile as writeFile14 } from "fs/promises";
|
|
18999
|
-
import
|
|
19084
|
+
import path34 from "path";
|
|
19000
19085
|
import { z as z10 } from "zod";
|
|
19001
19086
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
19002
19087
|
var UploadImageSchema = z10.object({
|
|
@@ -19009,12 +19094,12 @@ var UploadImageSchema = z10.object({
|
|
|
19009
19094
|
overwrite: z10.boolean().optional()
|
|
19010
19095
|
}).strict();
|
|
19011
19096
|
async function saveProjectImage(root, request) {
|
|
19012
|
-
const file =
|
|
19013
|
-
const relative =
|
|
19014
|
-
if (relative.startsWith("..") ||
|
|
19097
|
+
const file = path34.resolve(root, request.path);
|
|
19098
|
+
const relative = path34.relative(root, file);
|
|
19099
|
+
if (relative.startsWith("..") || path34.isAbsolute(relative)) {
|
|
19015
19100
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
19016
19101
|
}
|
|
19017
|
-
const extension =
|
|
19102
|
+
const extension = path34.extname(file).toLowerCase();
|
|
19018
19103
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
19019
19104
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
19020
19105
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -19027,17 +19112,17 @@ async function saveProjectImage(root, request) {
|
|
|
19027
19112
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
19028
19113
|
}
|
|
19029
19114
|
if (existsSync29(file) && !request.overwrite) {
|
|
19030
|
-
throw new ManifestEditError(`${relative.split(
|
|
19115
|
+
throw new ManifestEditError(`${relative.split(path34.sep).join("/")} already exists; choose another name, or replace it`);
|
|
19031
19116
|
}
|
|
19032
|
-
await mkdir11(
|
|
19117
|
+
await mkdir11(path34.dirname(file), { recursive: true });
|
|
19033
19118
|
await writeFile14(file, bytes);
|
|
19034
|
-
return relative.split(
|
|
19119
|
+
return relative.split(path34.sep).join("/");
|
|
19035
19120
|
}
|
|
19036
19121
|
|
|
19037
19122
|
// src/gallery/image-revision.ts
|
|
19038
19123
|
import { existsSync as existsSync30 } from "fs";
|
|
19039
19124
|
import { readFile as readFile24, rm as rm10, writeFile as writeFile15 } from "fs/promises";
|
|
19040
|
-
import
|
|
19125
|
+
import path35 from "path";
|
|
19041
19126
|
import { z as z11 } from "zod";
|
|
19042
19127
|
var InpaintRevisionRequestSchema = z11.object({
|
|
19043
19128
|
action: z11.literal("create-inpaint-revision"),
|
|
@@ -19056,14 +19141,14 @@ var InpaintRevisionRequestSchema = z11.object({
|
|
|
19056
19141
|
overwrite: z11.boolean().optional()
|
|
19057
19142
|
}).strict();
|
|
19058
19143
|
async function createInpaintRevision(manifestPath, request) {
|
|
19059
|
-
const root =
|
|
19060
|
-
if (
|
|
19144
|
+
const root = path35.dirname(path35.resolve(manifestPath));
|
|
19145
|
+
if (path35.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
19061
19146
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
19062
19147
|
}
|
|
19063
19148
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
19064
19149
|
const metadata = imageMetadata(bytes);
|
|
19065
19150
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
19066
|
-
const file =
|
|
19151
|
+
const file = path35.resolve(root, request.maskPath);
|
|
19067
19152
|
const previous = existsSync30(file) ? await readFile24(file) : null;
|
|
19068
19153
|
const mask = await saveProjectImage(root, {
|
|
19069
19154
|
action: "upload-image",
|
|
@@ -19093,7 +19178,7 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
19093
19178
|
// src/gallery/skeleton.ts
|
|
19094
19179
|
import { existsSync as existsSync31 } from "fs";
|
|
19095
19180
|
import { mkdir as mkdir12, readFile as readFile25, rm as rm11, writeFile as writeFile16 } from "fs/promises";
|
|
19096
|
-
import
|
|
19181
|
+
import path36 from "path";
|
|
19097
19182
|
import { z as z12 } from "zod";
|
|
19098
19183
|
var SkeletonEstimateRequestSchema = z12.object({
|
|
19099
19184
|
project: z12.string().min(1).optional(),
|
|
@@ -19132,10 +19217,10 @@ var SkeletonKeypointsUpdateSchema = z12.object({
|
|
|
19132
19217
|
set: SkeletonSetSchema
|
|
19133
19218
|
}).strict();
|
|
19134
19219
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
19135
|
-
const root =
|
|
19136
|
-
const file =
|
|
19137
|
-
const relative =
|
|
19138
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
19220
|
+
const root = path36.dirname(path36.resolve(manifestPath));
|
|
19221
|
+
const file = path36.resolve(root, request.keypointsFile);
|
|
19222
|
+
const relative = path36.relative(root, file);
|
|
19223
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path36.isAbsolute(relative)) {
|
|
19139
19224
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
19140
19225
|
}
|
|
19141
19226
|
const existed = existsSync31(file);
|
|
@@ -19145,7 +19230,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
19145
19230
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
19146
19231
|
}
|
|
19147
19232
|
if (existed) previous = await readFile25(file);
|
|
19148
|
-
await mkdir12(
|
|
19233
|
+
await mkdir12(path36.dirname(file), { recursive: true });
|
|
19149
19234
|
await writeFile16(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
19150
19235
|
} else if (!existed) {
|
|
19151
19236
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
@@ -19161,7 +19246,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
19161
19246
|
revision: {
|
|
19162
19247
|
mode: "animate-skeleton",
|
|
19163
19248
|
from: request.from,
|
|
19164
|
-
keypointsFile: relative.split(
|
|
19249
|
+
keypointsFile: relative.split(path36.sep).join("/"),
|
|
19165
19250
|
direction: request.direction,
|
|
19166
19251
|
description: request.description,
|
|
19167
19252
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -19182,19 +19267,19 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
19182
19267
|
if (!spec) throw new ManifestEditError(`"${key2}" is not declared by the manifest`);
|
|
19183
19268
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
19184
19269
|
if (!file) throw new ManifestEditError(`${key2} is not an animate-skeleton revision`);
|
|
19185
|
-
const relative =
|
|
19186
|
-
if (relative.startsWith("..") ||
|
|
19270
|
+
const relative = path36.relative(ctx.loaded.root, file);
|
|
19271
|
+
if (relative.startsWith("..") || path36.isAbsolute(relative)) {
|
|
19187
19272
|
throw new ManifestEditError(`${key2}'s keypoints file is outside the project; edit it by hand`);
|
|
19188
19273
|
}
|
|
19189
19274
|
const current = existsSync31(file) ? sha256(await readFile25(file)) : null;
|
|
19190
19275
|
if (current !== request.expectedSha256) {
|
|
19191
19276
|
throw Object.assign(
|
|
19192
|
-
new Error(`${relative.split(
|
|
19277
|
+
new Error(`${relative.split(path36.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
19193
19278
|
{ status: 409 }
|
|
19194
19279
|
);
|
|
19195
19280
|
}
|
|
19196
19281
|
await writeFile16(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
19197
|
-
return relative.split(
|
|
19282
|
+
return relative.split(path36.sep).join("/");
|
|
19198
19283
|
}
|
|
19199
19284
|
|
|
19200
19285
|
// src/gallery/edit.ts
|
|
@@ -19248,7 +19333,7 @@ function createGalleryEditHandler(opts) {
|
|
|
19248
19333
|
const history = /* @__PURE__ */ new Map();
|
|
19249
19334
|
const manifestOf = async (project) => {
|
|
19250
19335
|
try {
|
|
19251
|
-
return
|
|
19336
|
+
return path37.resolve(await opts.manifestFor(typeof project === "string" ? project : void 0));
|
|
19252
19337
|
} catch {
|
|
19253
19338
|
return null;
|
|
19254
19339
|
}
|
|
@@ -19271,7 +19356,7 @@ function createGalleryEditHandler(opts) {
|
|
|
19271
19356
|
await writeFile17(tmp, last.before);
|
|
19272
19357
|
await rename10(tmp, manifestPath2);
|
|
19273
19358
|
stack.pop();
|
|
19274
|
-
log(` manifest edit undone in ${
|
|
19359
|
+
log(` manifest edit undone in ${path37.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
19275
19360
|
return opts.reload();
|
|
19276
19361
|
}
|
|
19277
19362
|
const manifestPath = await manifestOf(body?.project);
|
|
@@ -19333,7 +19418,7 @@ function createEditApplier(opts, log) {
|
|
|
19333
19418
|
} catch (error) {
|
|
19334
19419
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
19335
19420
|
}
|
|
19336
|
-
const written = await saveProjectImage(
|
|
19421
|
+
const written = await saveProjectImage(path37.dirname(path37.resolve(manifestPath2)), upload.data);
|
|
19337
19422
|
log(` image added: ${written}`);
|
|
19338
19423
|
return opts.reload();
|
|
19339
19424
|
}
|
|
@@ -19400,7 +19485,7 @@ function createEditApplier(opts, log) {
|
|
|
19400
19485
|
}
|
|
19401
19486
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
19402
19487
|
if (result.changed) {
|
|
19403
|
-
const relative =
|
|
19488
|
+
const relative = path37.relative(process.cwd(), result.manifestPath);
|
|
19404
19489
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
19405
19490
|
log(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
19406
19491
|
}
|
|
@@ -19428,7 +19513,7 @@ function describeEdit(edit) {
|
|
|
19428
19513
|
// src/gallery/snapshot.ts
|
|
19429
19514
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
19430
19515
|
function galleryMediaId(absolutePath) {
|
|
19431
|
-
return createHash5("sha256").update(
|
|
19516
|
+
return createHash5("sha256").update(path38.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
19432
19517
|
}
|
|
19433
19518
|
function galleryMediaRoute(id) {
|
|
19434
19519
|
return `/media/${id}`;
|
|
@@ -19452,7 +19537,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
19452
19537
|
return (entry.history ?? []).map((generation, i) => {
|
|
19453
19538
|
const outputs = generation.outputs.map((output) => {
|
|
19454
19539
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
19455
|
-
const file =
|
|
19540
|
+
const file = path38.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
19456
19541
|
let url = null;
|
|
19457
19542
|
if (existsSync32(file)) {
|
|
19458
19543
|
const id = galleryMediaId(file);
|
|
@@ -19584,9 +19669,9 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
19584
19669
|
async function describeQuality(media, root, inspection) {
|
|
19585
19670
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
19586
19671
|
const outputs = await Promise.all(
|
|
19587
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
19672
|
+
outputPaths.map((file) => describeOutput(media, root, path38.resolve(root, file)))
|
|
19588
19673
|
);
|
|
19589
|
-
const recordPath =
|
|
19674
|
+
const recordPath = path38.resolve(root, inspection.record);
|
|
19590
19675
|
const recordExists = existsSync32(recordPath);
|
|
19591
19676
|
let options = null;
|
|
19592
19677
|
let check = null;
|
|
@@ -19606,7 +19691,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
19606
19691
|
return {
|
|
19607
19692
|
state: inspection.state,
|
|
19608
19693
|
reason: inspection.reason,
|
|
19609
|
-
output: portableOutputPath(
|
|
19694
|
+
output: portableOutputPath(path38.resolve(root, inspection.output), root),
|
|
19610
19695
|
record: portableOutputPath(recordPath, root),
|
|
19611
19696
|
recordExists,
|
|
19612
19697
|
outputs,
|
|
@@ -19646,7 +19731,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19646
19731
|
const items = [];
|
|
19647
19732
|
const manifestText = await readFile27(loaded.path, "utf8");
|
|
19648
19733
|
const manifestSha256 = sha256(manifestText);
|
|
19649
|
-
const cacheDir =
|
|
19734
|
+
const cacheDir = path38.resolve(path38.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
19650
19735
|
let rawStyles = {};
|
|
19651
19736
|
try {
|
|
19652
19737
|
const raw = JSON.parse(manifestText);
|
|
@@ -19670,7 +19755,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19670
19755
|
)
|
|
19671
19756
|
);
|
|
19672
19757
|
if (spec.source) {
|
|
19673
|
-
const editPath =
|
|
19758
|
+
const editPath = path38.resolve(root, spec.source);
|
|
19674
19759
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
19675
19760
|
const editShas = await Promise.all(
|
|
19676
19761
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
@@ -19719,7 +19804,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19719
19804
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
19720
19805
|
}
|
|
19721
19806
|
} else if (spec.source) {
|
|
19722
|
-
outputs = [await describeOutput(media, root,
|
|
19807
|
+
outputs = [await describeOutput(media, root, path38.resolve(root, spec.source))];
|
|
19723
19808
|
} else if (!entry && existsSync32(spec.outFile)) {
|
|
19724
19809
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
19725
19810
|
} else {
|
|
@@ -19924,7 +20009,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19924
20009
|
id: loaded.manifest.name,
|
|
19925
20010
|
name: loaded.manifest.name,
|
|
19926
20011
|
manifest: loaded.path,
|
|
19927
|
-
lock:
|
|
20012
|
+
lock: path38.resolve(opts.lockPath),
|
|
19928
20013
|
root,
|
|
19929
20014
|
provider: loaded.manifest.provider,
|
|
19930
20015
|
account: null,
|
|
@@ -19950,7 +20035,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19950
20035
|
return { snapshot, media };
|
|
19951
20036
|
}
|
|
19952
20037
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
19953
|
-
const dir =
|
|
20038
|
+
const dir = path38.dirname(path38.resolve(opts.workspacePath));
|
|
19954
20039
|
const media = /* @__PURE__ */ new Map();
|
|
19955
20040
|
const projects = [];
|
|
19956
20041
|
const items = [];
|
|
@@ -19993,7 +20078,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19993
20078
|
id: project.id,
|
|
19994
20079
|
name: loaded.manifest.name,
|
|
19995
20080
|
manifest: manifestPath,
|
|
19996
|
-
lock:
|
|
20081
|
+
lock: path38.resolve(lockPath),
|
|
19997
20082
|
root: loaded.root,
|
|
19998
20083
|
provider: loaded.manifest.provider,
|
|
19999
20084
|
account: project.account ?? null,
|
|
@@ -20009,8 +20094,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20009
20094
|
id: project.id,
|
|
20010
20095
|
name: project.id,
|
|
20011
20096
|
manifest: manifestPath,
|
|
20012
|
-
lock:
|
|
20013
|
-
root:
|
|
20097
|
+
lock: path38.resolve(lockPath),
|
|
20098
|
+
root: path38.dirname(manifestPath),
|
|
20014
20099
|
provider: project.provider,
|
|
20015
20100
|
account: project.account ?? null,
|
|
20016
20101
|
manifestSha256: null,
|
|
@@ -20037,7 +20122,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20037
20122
|
version: 1,
|
|
20038
20123
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
20039
20124
|
project: null,
|
|
20040
|
-
workspace: { path:
|
|
20125
|
+
workspace: { path: path38.resolve(opts.workspacePath), dir, projects },
|
|
20041
20126
|
filter,
|
|
20042
20127
|
totals: {
|
|
20043
20128
|
entries: projects.reduce((sum, project) => sum + project.entries, 0),
|
|
@@ -20241,7 +20326,7 @@ import { createHash as createHash6 } from "crypto";
|
|
|
20241
20326
|
import { existsSync as existsSync34 } from "fs";
|
|
20242
20327
|
import { mkdir as mkdir13, readFile as readFile28, rename as rename11, rm as rm12, stat as stat4, writeFile as writeFile18 } from "fs/promises";
|
|
20243
20328
|
import os3 from "os";
|
|
20244
|
-
import
|
|
20329
|
+
import path39 from "path";
|
|
20245
20330
|
var EditorInstallError = class extends Error {
|
|
20246
20331
|
constructor(message6, file) {
|
|
20247
20332
|
super(message6);
|
|
@@ -20252,15 +20337,15 @@ var EditorInstallError = class extends Error {
|
|
|
20252
20337
|
};
|
|
20253
20338
|
function editorToolsRoot() {
|
|
20254
20339
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
20255
|
-
if (override) return
|
|
20256
|
-
if (process.platform === "darwin") return
|
|
20340
|
+
if (override) return path39.resolve(override);
|
|
20341
|
+
if (process.platform === "darwin") return path39.join(os3.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
20257
20342
|
if (process.platform === "win32") {
|
|
20258
|
-
return
|
|
20343
|
+
return path39.join(process.env.LOCALAPPDATA ?? path39.join(os3.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
20259
20344
|
}
|
|
20260
|
-
return
|
|
20345
|
+
return path39.join(process.env.XDG_CACHE_HOME ?? path39.join(os3.homedir(), ".cache"), "pixelkiln", "tools");
|
|
20261
20346
|
}
|
|
20262
20347
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
20263
|
-
return
|
|
20348
|
+
return path39.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
20264
20349
|
}
|
|
20265
20350
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
20266
20351
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -20283,7 +20368,7 @@ async function editorStatus(opts = {}) {
|
|
|
20283
20368
|
let totalBytes = 0;
|
|
20284
20369
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
20285
20370
|
totalBytes += expected.bytes;
|
|
20286
|
-
const file =
|
|
20371
|
+
const file = path39.join(dir, name);
|
|
20287
20372
|
const info = existsSync34(file) ? await stat4(file).catch(() => null) : null;
|
|
20288
20373
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
20289
20374
|
installedBytes += expected.bytes;
|
|
@@ -20341,7 +20426,7 @@ async function installEditor(opts = {}) {
|
|
|
20341
20426
|
if (digest2 !== expected.sha256) {
|
|
20342
20427
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
20343
20428
|
}
|
|
20344
|
-
const final =
|
|
20429
|
+
const final = path39.join(dir, name);
|
|
20345
20430
|
const tmp = `${final}.${process.pid}.part`;
|
|
20346
20431
|
try {
|
|
20347
20432
|
await writeFile18(tmp, bytes);
|
|
@@ -20387,12 +20472,12 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
20387
20472
|
".json": "application/json; charset=utf-8"
|
|
20388
20473
|
};
|
|
20389
20474
|
function editorContentType(name) {
|
|
20390
|
-
return EDITOR_CONTENT_TYPES[
|
|
20475
|
+
return EDITOR_CONTENT_TYPES[path39.extname(name).toLowerCase()] ?? null;
|
|
20391
20476
|
}
|
|
20392
20477
|
|
|
20393
20478
|
// src/gallery/editor.ts
|
|
20394
20479
|
import { readFile as readFile29 } from "fs/promises";
|
|
20395
|
-
import
|
|
20480
|
+
import path40 from "path";
|
|
20396
20481
|
function editorRoute(release, name = "index.html") {
|
|
20397
20482
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
20398
20483
|
}
|
|
@@ -20465,7 +20550,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
20465
20550
|
if (!status.installed) return null;
|
|
20466
20551
|
let bytes;
|
|
20467
20552
|
try {
|
|
20468
|
-
bytes = await readFile29(
|
|
20553
|
+
bytes = await readFile29(path40.join(dir, name));
|
|
20469
20554
|
} catch {
|
|
20470
20555
|
verified = null;
|
|
20471
20556
|
return null;
|
|
@@ -21158,7 +21243,7 @@ function createGenerateHandlers(opts) {
|
|
|
21158
21243
|
// src/pipeline/salvage.ts
|
|
21159
21244
|
import { readFile as readFile31 } from "fs/promises";
|
|
21160
21245
|
import { existsSync as existsSync35 } from "fs";
|
|
21161
|
-
import
|
|
21246
|
+
import path41 from "path";
|
|
21162
21247
|
function providerClaimId(provider, objectId) {
|
|
21163
21248
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
21164
21249
|
}
|
|
@@ -21272,20 +21357,20 @@ function matchOrphanStyle(prompt, manifest) {
|
|
|
21272
21357
|
return matchStyleByPattern(prompt, manifest);
|
|
21273
21358
|
}
|
|
21274
21359
|
async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
|
|
21275
|
-
const own =
|
|
21360
|
+
const own = path41.resolve(ownManifestPath);
|
|
21276
21361
|
const siblingManifestPaths = [
|
|
21277
21362
|
.../* @__PURE__ */ new Set([
|
|
21278
21363
|
...workspaceManifestPaths,
|
|
21279
|
-
...claimPaths.map((c) =>
|
|
21364
|
+
...claimPaths.map((c) => path41.join(path41.dirname(path41.resolve(c)), "pixelkiln.manifest.json"))
|
|
21280
21365
|
])
|
|
21281
21366
|
];
|
|
21282
21367
|
const siblings = [];
|
|
21283
21368
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
21284
|
-
if (
|
|
21369
|
+
if (path41.resolve(siblingManifestPath) === own) continue;
|
|
21285
21370
|
if (!existsSync35(siblingManifestPath)) continue;
|
|
21286
21371
|
try {
|
|
21287
21372
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
21288
|
-
siblings.push({ label:
|
|
21373
|
+
siblings.push({ label: path41.basename(path41.dirname(siblingManifestPath)), manifest });
|
|
21289
21374
|
} catch {
|
|
21290
21375
|
}
|
|
21291
21376
|
}
|
|
@@ -21406,7 +21491,7 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
21406
21491
|
|
|
21407
21492
|
// src/pick/salvage-server.ts
|
|
21408
21493
|
import { mkdir as mkdir14, writeFile as writeFile19, readFile as readFile32 } from "fs/promises";
|
|
21409
|
-
import
|
|
21494
|
+
import path42 from "path";
|
|
21410
21495
|
|
|
21411
21496
|
// src/pick/salvage-sheet.ts
|
|
21412
21497
|
var escapeHtml3 = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -21572,7 +21657,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21572
21657
|
});
|
|
21573
21658
|
const html = renderSalvageSheet(orphans, {
|
|
21574
21659
|
styleId: ctx.styleId,
|
|
21575
|
-
importDir:
|
|
21660
|
+
importDir: path42.relative(process.cwd(), ctx.importDir) || "."
|
|
21576
21661
|
});
|
|
21577
21662
|
const byId = new Map(orphans.map((o) => [o.id, o]));
|
|
21578
21663
|
const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
|
|
@@ -21628,9 +21713,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21628
21713
|
if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
|
|
21629
21714
|
decodePng(buf);
|
|
21630
21715
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
21631
|
-
const rel =
|
|
21632
|
-
const outFile =
|
|
21633
|
-
await mkdir14(
|
|
21716
|
+
const rel = path42.join("_salvaged", `${assetId}.png`);
|
|
21717
|
+
const outFile = path42.resolve(ctx.importDir, rel);
|
|
21718
|
+
await mkdir14(path42.dirname(outFile), { recursive: true });
|
|
21634
21719
|
await writeFile19(outFile, buf);
|
|
21635
21720
|
ctx.manifest.assets[assetId] = {
|
|
21636
21721
|
prompt: orphan.prompt,
|
|
@@ -21663,7 +21748,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21663
21748
|
sourceUrl: durableSource,
|
|
21664
21749
|
sourceUrls: durableSource ? [{ url: durableSource }] : [],
|
|
21665
21750
|
outputs: [{
|
|
21666
|
-
path: portableOutputPath(outFile,
|
|
21751
|
+
path: portableOutputPath(outFile, path42.dirname(ctx.manifestPath)),
|
|
21667
21752
|
sha256: sha256(buf)
|
|
21668
21753
|
}],
|
|
21669
21754
|
submittedAt: orphan.createdAt,
|
|
@@ -21841,6 +21926,7 @@ export {
|
|
|
21841
21926
|
InheritedStyleSchema,
|
|
21842
21927
|
LockEntrySchema,
|
|
21843
21928
|
LockHistoryEntrySchema,
|
|
21929
|
+
LockOriginSchema,
|
|
21844
21930
|
LockSchema,
|
|
21845
21931
|
LockTerrainSettingsSchema,
|
|
21846
21932
|
MAX_DOWNLOAD_BYTES,
|