pixelkiln 0.95.0 → 0.96.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 +587 -494
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +190 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +497 -32
- package/dist/index.d.ts +497 -32
- package/dist/index.js +189 -124
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +27 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -74,6 +74,7 @@ __export(index_exports, {
|
|
|
74
74
|
InheritedStyleSchema: () => InheritedStyleSchema,
|
|
75
75
|
LockEntrySchema: () => LockEntrySchema,
|
|
76
76
|
LockHistoryEntrySchema: () => LockHistoryEntrySchema,
|
|
77
|
+
LockOriginSchema: () => LockOriginSchema,
|
|
77
78
|
LockSchema: () => LockSchema,
|
|
78
79
|
LockTerrainSettingsSchema: () => LockTerrainSettingsSchema,
|
|
79
80
|
MAX_DOWNLOAD_BYTES: () => MAX_DOWNLOAD_BYTES,
|
|
@@ -1516,7 +1517,7 @@ var AssetDeriveSchema = import_zod.z.object({
|
|
|
1516
1517
|
/** scale: `nearest` (default) keeps hard edges; `box` averages the covered pixels. */
|
|
1517
1518
|
mode: import_zod.z.enum(["nearest", "box"]).optional()
|
|
1518
1519
|
}).strict().superRefine((derive, context) => {
|
|
1519
|
-
const issue = (message6,
|
|
1520
|
+
const issue = (message6, path43) => context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: message6, path: [path43] });
|
|
1520
1521
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
1521
1522
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
1522
1523
|
}
|
|
@@ -1817,6 +1818,18 @@ var PostprocessSchema = import_zod.z.object({
|
|
|
1817
1818
|
distance: import_zod.z.literal("redmean")
|
|
1818
1819
|
}).optional()
|
|
1819
1820
|
});
|
|
1821
|
+
var LockOriginSchema = import_zod.z.object({
|
|
1822
|
+
tool: import_zod.z.string().min(1).optional(),
|
|
1823
|
+
prompt: import_zod.z.string().optional(),
|
|
1824
|
+
seed: import_zod.z.number().int().optional(),
|
|
1825
|
+
steps: import_zod.z.array(import_zod.z.string().min(1)).optional(),
|
|
1826
|
+
raw: import_zod.z.object({ sha256: import_zod.z.string().regex(/^[0-9a-f]{64}$/) }).optional()
|
|
1827
|
+
});
|
|
1828
|
+
var LockImportedSchema = import_zod.z.object({
|
|
1829
|
+
source: import_zod.z.string().min(1),
|
|
1830
|
+
note: import_zod.z.string().optional(),
|
|
1831
|
+
importedAt: import_zod.z.string()
|
|
1832
|
+
}).strict();
|
|
1820
1833
|
var LockSourceSchema = import_zod.z.object({
|
|
1821
1834
|
url: import_zod.z.string(),
|
|
1822
1835
|
role: import_zod.z.string().optional(),
|
|
@@ -1867,6 +1880,9 @@ var LockHistoryEntrySchema = import_zod.z.object({
|
|
|
1867
1880
|
motionShare: LockMotionShareSchema.optional(),
|
|
1868
1881
|
/** A terrain set's settings outside specHash; see LockEntrySchema.terrainSettings. */
|
|
1869
1882
|
terrainSettings: LockTerrainSettingsSchema.optional(),
|
|
1883
|
+
/** Imported art keeps its provenance when it is replaced and when it comes back. */
|
|
1884
|
+
imported: LockImportedSchema.optional(),
|
|
1885
|
+
origin: LockOriginSchema.optional(),
|
|
1870
1886
|
/** When the replacement was submitted. */
|
|
1871
1887
|
retiredAt: import_zod.z.string()
|
|
1872
1888
|
});
|
|
@@ -2039,11 +2055,9 @@ var LockEntrySchema = import_zod.z.object({
|
|
|
2039
2055
|
* hand edit, another tool) and brought in with `adopt --local`: nothing was
|
|
2040
2056
|
* submitted, so jobId and cost are empty. Absent on generated entries.
|
|
2041
2057
|
*/
|
|
2042
|
-
imported:
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
importedAt: import_zod.z.string()
|
|
2046
|
-
}).strict().optional(),
|
|
2058
|
+
imported: LockImportedSchema.optional(),
|
|
2059
|
+
/** More on imported art: tool, prompt, seed, post-process steps, raw original. See LockOriginSchema. */
|
|
2060
|
+
origin: LockOriginSchema.optional(),
|
|
2047
2061
|
/**
|
|
2048
2062
|
* For a derived asset: what it was made from, and a hash of that input when
|
|
2049
2063
|
* this was made. Compared with the input's current bytes by the plan, so a
|
|
@@ -2610,9 +2624,9 @@ var PixelLabClient = class {
|
|
|
2610
2624
|
apiKey;
|
|
2611
2625
|
http;
|
|
2612
2626
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
2613
|
-
async request(
|
|
2627
|
+
async request(path43, init) {
|
|
2614
2628
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
2615
|
-
const res = await this.http(`${BASE}${
|
|
2629
|
+
const res = await this.http(`${BASE}${path43}`, {
|
|
2616
2630
|
...init,
|
|
2617
2631
|
headers: {
|
|
2618
2632
|
Authorization: auth,
|
|
@@ -2623,13 +2637,13 @@ var PixelLabClient = class {
|
|
|
2623
2637
|
const text = await res.text();
|
|
2624
2638
|
if (!res.ok) {
|
|
2625
2639
|
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' : "";
|
|
2626
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
2640
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path43} \u2192 ${res.status}${hint}`, res.status, text);
|
|
2627
2641
|
}
|
|
2628
2642
|
if (!text) return {};
|
|
2629
2643
|
try {
|
|
2630
2644
|
return JSON.parse(text);
|
|
2631
2645
|
} catch {
|
|
2632
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
2646
|
+
throw new Error(`${init?.method ?? "GET"} ${path43} returned invalid JSON`);
|
|
2633
2647
|
}
|
|
2634
2648
|
}
|
|
2635
2649
|
async balance() {
|
|
@@ -3082,10 +3096,10 @@ var PixelLabClient = class {
|
|
|
3082
3096
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
3083
3097
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
3084
3098
|
const south = args.reference?.south;
|
|
3085
|
-
let
|
|
3099
|
+
let path43;
|
|
3086
3100
|
let body;
|
|
3087
3101
|
if (args.mode === "v3") {
|
|
3088
|
-
|
|
3102
|
+
path43 = "/create-character-v3";
|
|
3089
3103
|
body = {
|
|
3090
3104
|
description: args.description,
|
|
3091
3105
|
image_size: imageSize,
|
|
@@ -3099,7 +3113,7 @@ var PixelLabClient = class {
|
|
|
3099
3113
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
3100
3114
|
};
|
|
3101
3115
|
} else if (args.mode === "pro-flash") {
|
|
3102
|
-
|
|
3116
|
+
path43 = "/create-character-pro-flash";
|
|
3103
3117
|
const traits = args.styleTraits;
|
|
3104
3118
|
body = {
|
|
3105
3119
|
description: args.description,
|
|
@@ -3123,7 +3137,7 @@ var PixelLabClient = class {
|
|
|
3123
3137
|
} : {}
|
|
3124
3138
|
};
|
|
3125
3139
|
} else if (args.mode === "pro") {
|
|
3126
|
-
|
|
3140
|
+
path43 = "/create-character-pro";
|
|
3127
3141
|
body = {
|
|
3128
3142
|
description: args.description,
|
|
3129
3143
|
image_size: imageSize,
|
|
@@ -3137,7 +3151,7 @@ var PixelLabClient = class {
|
|
|
3137
3151
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
3138
3152
|
};
|
|
3139
3153
|
} else {
|
|
3140
|
-
|
|
3154
|
+
path43 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
3141
3155
|
body = {
|
|
3142
3156
|
description: args.description,
|
|
3143
3157
|
image_size: imageSize,
|
|
@@ -3155,8 +3169,8 @@ var PixelLabClient = class {
|
|
|
3155
3169
|
};
|
|
3156
3170
|
}
|
|
3157
3171
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
3158
|
-
const raw = await this.request(
|
|
3159
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
3172
|
+
const raw = await this.request(path43, { method: "POST", body: JSON.stringify(body) });
|
|
3173
|
+
return validateResponse(CharacterSubmitSchema, raw, path43.slice(1));
|
|
3160
3174
|
}
|
|
3161
3175
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
3162
3176
|
async createCharacterState(args) {
|
|
@@ -4497,10 +4511,10 @@ function normalizeHex(value) {
|
|
|
4497
4511
|
function sha256(data) {
|
|
4498
4512
|
return (0, import_node_crypto.createHash)("sha256").update(data).digest("hex");
|
|
4499
4513
|
}
|
|
4500
|
-
async function sha256File(
|
|
4514
|
+
async function sha256File(path43) {
|
|
4501
4515
|
return new Promise((resolve, reject) => {
|
|
4502
4516
|
const hash = (0, import_node_crypto.createHash)("sha256");
|
|
4503
|
-
const stream = (0, import_node_fs.createReadStream)(
|
|
4517
|
+
const stream = (0, import_node_fs.createReadStream)(path43);
|
|
4504
4518
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
4505
4519
|
stream.on("error", reject);
|
|
4506
4520
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -8335,9 +8349,9 @@ var RetroDiffusionClient = class {
|
|
|
8335
8349
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
8336
8350
|
return Buffer.from(await response.arrayBuffer());
|
|
8337
8351
|
}
|
|
8338
|
-
async call(
|
|
8352
|
+
async call(path43, init = {}) {
|
|
8339
8353
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
8340
|
-
const response = await this.request(`${this.baseUrl}${
|
|
8354
|
+
const response = await this.request(`${this.baseUrl}${path43}`, {
|
|
8341
8355
|
...init,
|
|
8342
8356
|
headers: {
|
|
8343
8357
|
"Content-Type": "application/json",
|
|
@@ -14133,6 +14147,15 @@ async function anyOutputModified(entry, spec) {
|
|
|
14133
14147
|
}
|
|
14134
14148
|
return false;
|
|
14135
14149
|
}
|
|
14150
|
+
async function modifiedReason(entry, spec) {
|
|
14151
|
+
if (!entry.imported) return "output modified since download";
|
|
14152
|
+
const raw = entry.origin?.raw?.sha256;
|
|
14153
|
+
if (raw && (0, import_node_fs15.existsSync)(currentEntryOutputPath(entry, spec, 0)) && await sha256File(currentEntryOutputPath(entry, spec, 0)) === raw) {
|
|
14154
|
+
const steps = entry.origin?.steps?.length ? ` (${entry.origin.steps.join("; ")})` : "";
|
|
14155
|
+
return `file is the unprocessed original; apply the recorded post-processing again${steps}, or run adopt --local --force to record it as it is`;
|
|
14156
|
+
}
|
|
14157
|
+
return "file changed since it was imported; run adopt --local --force to record the new version";
|
|
14158
|
+
}
|
|
14136
14159
|
function dependencies(spec) {
|
|
14137
14160
|
return [
|
|
14138
14161
|
spec.mirror?.sourceSpec,
|
|
@@ -14286,7 +14309,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
14286
14309
|
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !(0, import_node_fs15.existsSync)(currentEntryOutputPath(entry, spec, index))).map((o) => o.role ?? "asset").join(", ")}`;
|
|
14287
14310
|
} else if (await anyOutputModified(entry, spec)) {
|
|
14288
14311
|
state = "orphaned";
|
|
14289
|
-
reason =
|
|
14312
|
+
reason = await modifiedReason(entry, spec);
|
|
14290
14313
|
} else if (spec.derive) {
|
|
14291
14314
|
state = "ok";
|
|
14292
14315
|
reason = "up to date";
|
|
@@ -15416,10 +15439,10 @@ function isSha256Hash(value) {
|
|
|
15416
15439
|
function parseCache(value) {
|
|
15417
15440
|
return HashCacheSchema.parse(value);
|
|
15418
15441
|
}
|
|
15419
|
-
async function loadCache(
|
|
15420
|
-
if (!(0, import_node_fs19.existsSync)(
|
|
15442
|
+
async function loadCache(path43) {
|
|
15443
|
+
if (!(0, import_node_fs19.existsSync)(path43)) return { version: 1, hashes: {} };
|
|
15421
15444
|
try {
|
|
15422
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await (0, import_promises13.readFile)(
|
|
15445
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await (0, import_promises13.readFile)(path43, "utf8")));
|
|
15423
15446
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
15424
15447
|
return {
|
|
15425
15448
|
version: 1,
|
|
@@ -15431,18 +15454,18 @@ async function loadCache(path42) {
|
|
|
15431
15454
|
return { version: 1, hashes: {} };
|
|
15432
15455
|
}
|
|
15433
15456
|
}
|
|
15434
|
-
async function saveCache(
|
|
15457
|
+
async function saveCache(path43, cache) {
|
|
15435
15458
|
const sorted = {};
|
|
15436
15459
|
for (const key2 of Object.keys(cache.hashes).sort()) {
|
|
15437
15460
|
const hash = cache.hashes[key2];
|
|
15438
15461
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key2}`);
|
|
15439
15462
|
sorted[key2] = hash;
|
|
15440
15463
|
}
|
|
15441
|
-
await (0, import_promises13.mkdir)(import_node_path22.default.dirname(import_node_path22.default.resolve(
|
|
15442
|
-
const tmp = `${
|
|
15464
|
+
await (0, import_promises13.mkdir)(import_node_path22.default.dirname(import_node_path22.default.resolve(path43)), { recursive: true });
|
|
15465
|
+
const tmp = `${path43}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
15443
15466
|
try {
|
|
15444
15467
|
await (0, import_promises13.writeFile)(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
15445
|
-
await (0, import_promises13.rename)(tmp,
|
|
15468
|
+
await (0, import_promises13.rename)(tmp, path43);
|
|
15446
15469
|
} finally {
|
|
15447
15470
|
await (0, import_promises13.rm)(tmp, { force: true });
|
|
15448
15471
|
}
|
|
@@ -15825,6 +15848,8 @@ function retireGeneration(entry, retiredAt) {
|
|
|
15825
15848
|
...entry.terrainConnect ? { terrainConnect: entry.terrainConnect } : {},
|
|
15826
15849
|
...entry.motionShare ? { motionShare: entry.motionShare } : {},
|
|
15827
15850
|
...entry.terrainSettings ? { terrainSettings: entry.terrainSettings } : {},
|
|
15851
|
+
...entry.imported ? { imported: entry.imported } : {},
|
|
15852
|
+
...entry.origin ? { origin: entry.origin } : {},
|
|
15828
15853
|
retiredAt
|
|
15829
15854
|
};
|
|
15830
15855
|
}
|
|
@@ -15924,6 +15949,10 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
15924
15949
|
// Likewise its settings; a generation from before they were recorded
|
|
15925
15950
|
// comes back with none and is taken as current.
|
|
15926
15951
|
terrainSettings: generation.terrainSettings,
|
|
15952
|
+
// Imported art comes back as imported, with its provenance; a generated
|
|
15953
|
+
// one clears both, so the plan does not call it imported.
|
|
15954
|
+
imported: generation.imported,
|
|
15955
|
+
origin: generation.origin,
|
|
15927
15956
|
history
|
|
15928
15957
|
});
|
|
15929
15958
|
await saveLock(lockPath, lock);
|
|
@@ -17617,15 +17646,23 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
17617
17646
|
// src/pipeline/import.ts
|
|
17618
17647
|
var import_node_fs27 = require("fs");
|
|
17619
17648
|
var import_promises18 = require("fs/promises");
|
|
17649
|
+
var import_node_path30 = __toESM(require("path"), 1);
|
|
17620
17650
|
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
17621
17651
|
const png = decodePng(bytes);
|
|
17622
17652
|
const at = now.toISOString();
|
|
17653
|
+
const origin = {
|
|
17654
|
+
...opts.tool ? { tool: opts.tool } : {},
|
|
17655
|
+
...opts.prompt ? { prompt: opts.prompt } : {},
|
|
17656
|
+
...opts.seed !== void 0 ? { seed: opts.seed } : {},
|
|
17657
|
+
...opts.steps?.length ? { steps: opts.steps } : {},
|
|
17658
|
+
...opts.rawSha256 ? { raw: { sha256: opts.rawSha256 } } : {}
|
|
17659
|
+
};
|
|
17623
17660
|
return {
|
|
17624
17661
|
styleId: spec.styleId,
|
|
17625
17662
|
assetId: spec.assetId,
|
|
17626
17663
|
specHash: spec.specHash,
|
|
17627
17664
|
generator: spec.generator,
|
|
17628
|
-
prompt: spec.prompt,
|
|
17665
|
+
prompt: opts.prompt ?? spec.prompt,
|
|
17629
17666
|
width: png.width,
|
|
17630
17667
|
height: png.height,
|
|
17631
17668
|
jobId: opts.objectId ?? null,
|
|
@@ -17639,9 +17676,10 @@ function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Da
|
|
|
17639
17676
|
outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
|
|
17640
17677
|
submittedAt: null,
|
|
17641
17678
|
downloadedAt: at,
|
|
17642
|
-
cost: 0,
|
|
17679
|
+
cost: opts.cost ?? 0,
|
|
17643
17680
|
costUnit: spec.costUnit,
|
|
17644
17681
|
provider: spec.provider,
|
|
17682
|
+
...Object.keys(origin).length ? { origin } : {},
|
|
17645
17683
|
...spec.external ? { external: { builder: spec.external.builder, inputs: spec.external.inputs } } : {},
|
|
17646
17684
|
imported: {
|
|
17647
17685
|
source: opts.source ?? "external",
|
|
@@ -17660,6 +17698,19 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
17660
17698
|
if (opts.objectId && specs.length !== 1) {
|
|
17661
17699
|
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
17662
17700
|
}
|
|
17701
|
+
const cacheDir = opts.cacheDir === false ? null : import_node_path30.default.resolve(opts.cacheDir ?? import_node_path30.default.join(import_node_path30.default.dirname(lockPath), ".pixelkiln", "cache"));
|
|
17702
|
+
let rawSha256;
|
|
17703
|
+
let rawBytes;
|
|
17704
|
+
if (opts.raw) {
|
|
17705
|
+
if (specs.length !== 1) throw new Error(`--raw names one original; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
17706
|
+
try {
|
|
17707
|
+
rawBytes = await (0, import_promises18.readFile)(opts.raw);
|
|
17708
|
+
decodePng(rawBytes);
|
|
17709
|
+
} catch (error) {
|
|
17710
|
+
throw new Error(`--raw ${opts.raw} is not a readable PNG: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
17711
|
+
}
|
|
17712
|
+
rawSha256 = sha256(rawBytes);
|
|
17713
|
+
}
|
|
17663
17714
|
const imported = [];
|
|
17664
17715
|
const skipped = [];
|
|
17665
17716
|
for (const spec of specs) {
|
|
@@ -17678,8 +17729,10 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
17678
17729
|
continue;
|
|
17679
17730
|
}
|
|
17680
17731
|
let patch;
|
|
17732
|
+
let bytes;
|
|
17681
17733
|
try {
|
|
17682
|
-
|
|
17734
|
+
bytes = await (0, import_promises18.readFile)(spec.outFile);
|
|
17735
|
+
patch = buildImportedEntry(spec, bytes, { ...opts, rawSha256 }, /* @__PURE__ */ new Date());
|
|
17683
17736
|
} catch (error) {
|
|
17684
17737
|
skipped.push({ key: key2, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
17685
17738
|
continue;
|
|
@@ -17688,7 +17741,19 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
17688
17741
|
imported.push({ key: key2, entry: patch });
|
|
17689
17742
|
continue;
|
|
17690
17743
|
}
|
|
17691
|
-
|
|
17744
|
+
const existing = lock.entries[key2];
|
|
17745
|
+
const history = existing?.outputs[0]?.sha256 === sha256(bytes) ? existing.history : historyAfterReplacing(existing, opts.historyLimit ?? DEFAULT_HISTORY_LIMIT, patch.downloadedAt ?? (/* @__PURE__ */ new Date()).toISOString());
|
|
17746
|
+
if (cacheDir) {
|
|
17747
|
+
await cacheMedia(cacheDir, bytes, MediaType.PNG);
|
|
17748
|
+
if (rawBytes) await cacheMedia(cacheDir, rawBytes, MediaType.PNG);
|
|
17749
|
+
}
|
|
17750
|
+
imported.push({ key: key2, entry: upsert(lock, key2, {
|
|
17751
|
+
...patch,
|
|
17752
|
+
// An import replaces the whole record: clear what the entry held that
|
|
17753
|
+
// an import never has, or a regenerated entry would keep stale links.
|
|
17754
|
+
origin: patch.origin,
|
|
17755
|
+
history
|
|
17756
|
+
}) });
|
|
17692
17757
|
}
|
|
17693
17758
|
if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
|
|
17694
17759
|
return { imported, skipped };
|
|
@@ -17733,7 +17798,7 @@ var import_promises21 = require("fs/promises");
|
|
|
17733
17798
|
// src/pipeline/init.ts
|
|
17734
17799
|
var import_promises19 = require("fs/promises");
|
|
17735
17800
|
var import_node_fs28 = require("fs");
|
|
17736
|
-
var
|
|
17801
|
+
var import_node_path31 = __toESM(require("path"), 1);
|
|
17737
17802
|
function pngSize(buf) {
|
|
17738
17803
|
if (buf.length < 24) return null;
|
|
17739
17804
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -17747,7 +17812,7 @@ function slugify(value) {
|
|
|
17747
17812
|
async function walk(dir, exclude) {
|
|
17748
17813
|
const out = [];
|
|
17749
17814
|
for (const entry of await (0, import_promises19.readdir)(dir, { withFileTypes: true })) {
|
|
17750
|
-
const full =
|
|
17815
|
+
const full = import_node_path31.default.join(dir, entry.name);
|
|
17751
17816
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
17752
17817
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
17753
17818
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -17766,9 +17831,9 @@ async function scanAssets(root, opts = {}) {
|
|
|
17766
17831
|
skipped.push(`${file} (not a readable PNG)`);
|
|
17767
17832
|
continue;
|
|
17768
17833
|
}
|
|
17769
|
-
const rel =
|
|
17770
|
-
const category =
|
|
17771
|
-
let id = slugify(
|
|
17834
|
+
const rel = import_node_path31.default.relative(root, file);
|
|
17835
|
+
const category = import_node_path31.default.dirname(rel) === "." ? "" : import_node_path31.default.dirname(rel);
|
|
17836
|
+
let id = slugify(import_node_path31.default.basename(rel));
|
|
17772
17837
|
if (seen.has(id)) {
|
|
17773
17838
|
const n = seen.get(id) + 1;
|
|
17774
17839
|
seen.set(id, n);
|
|
@@ -18529,12 +18594,12 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
18529
18594
|
var import_node_crypto7 = require("crypto");
|
|
18530
18595
|
var import_node_fs35 = require("fs");
|
|
18531
18596
|
var import_promises29 = require("fs/promises");
|
|
18532
|
-
var
|
|
18597
|
+
var import_node_path39 = __toESM(require("path"), 1);
|
|
18533
18598
|
|
|
18534
18599
|
// src/workspace.ts
|
|
18535
18600
|
var import_promises22 = require("fs/promises");
|
|
18536
18601
|
var import_node_fs30 = require("fs");
|
|
18537
|
-
var
|
|
18602
|
+
var import_node_path32 = __toESM(require("path"), 1);
|
|
18538
18603
|
var import_zod7 = require("zod");
|
|
18539
18604
|
var WorkspaceProjectSchema = import_zod7.z.object({
|
|
18540
18605
|
id: import_zod7.z.string().min(1),
|
|
@@ -18576,7 +18641,7 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
18576
18641
|
version: 1,
|
|
18577
18642
|
projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
|
|
18578
18643
|
};
|
|
18579
|
-
await (0, import_promises22.mkdir)(
|
|
18644
|
+
await (0, import_promises22.mkdir)(import_node_path32.default.dirname(import_node_path32.default.resolve(workspacePath)), { recursive: true });
|
|
18580
18645
|
const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18581
18646
|
try {
|
|
18582
18647
|
await (0, import_promises22.writeFile)(tmp, JSON.stringify(sorted, null, 2) + "\n");
|
|
@@ -18586,12 +18651,12 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
18586
18651
|
}
|
|
18587
18652
|
}
|
|
18588
18653
|
function toPortablePath(dir, absolute) {
|
|
18589
|
-
return
|
|
18654
|
+
return import_node_path32.default.relative(dir, absolute).split(import_node_path32.default.sep).join("/");
|
|
18590
18655
|
}
|
|
18591
18656
|
function resolveProject(dir, project) {
|
|
18592
18657
|
return {
|
|
18593
|
-
manifestPath:
|
|
18594
|
-
lockPath:
|
|
18658
|
+
manifestPath: import_node_path32.default.resolve(dir, project.manifest.split("/").join(import_node_path32.default.sep)),
|
|
18659
|
+
lockPath: import_node_path32.default.resolve(dir, project.lock.split("/").join(import_node_path32.default.sep))
|
|
18595
18660
|
};
|
|
18596
18661
|
}
|
|
18597
18662
|
function validateWorkspace(ws, dir) {
|
|
@@ -18604,7 +18669,7 @@ function validateWorkspace(ws, dir) {
|
|
|
18604
18669
|
const { manifestPath, lockPath } = resolveProject(dir, project);
|
|
18605
18670
|
lockOwners.set(lockPath, [...lockOwners.get(lockPath) ?? [], project.id]);
|
|
18606
18671
|
manifestOwners.set(manifestPath, [...manifestOwners.get(manifestPath) ?? [], project.id]);
|
|
18607
|
-
if (
|
|
18672
|
+
if (import_node_path32.default.isAbsolute(project.manifest) || import_node_path32.default.isAbsolute(project.lock)) {
|
|
18608
18673
|
diagnostics.push({
|
|
18609
18674
|
id: "absolute-path",
|
|
18610
18675
|
level: "warning",
|
|
@@ -18666,15 +18731,15 @@ function validateWorkspace(ws, dir) {
|
|
|
18666
18731
|
|
|
18667
18732
|
// src/gallery/edit.ts
|
|
18668
18733
|
var import_promises28 = require("fs/promises");
|
|
18669
|
-
var
|
|
18734
|
+
var import_node_path38 = __toESM(require("path"), 1);
|
|
18670
18735
|
var import_zod13 = require("zod");
|
|
18671
18736
|
|
|
18672
18737
|
// src/manifest-edit.ts
|
|
18673
18738
|
var import_promises23 = require("fs/promises");
|
|
18674
|
-
var
|
|
18739
|
+
var import_node_path33 = __toESM(require("path"), 1);
|
|
18675
18740
|
var import_zod8 = require("zod");
|
|
18676
18741
|
var HexSha = import_zod8.z.string().regex(/^[0-9a-f]{64}$/);
|
|
18677
|
-
var ProjectFileSchema = import_zod8.z.string().min(1).refine((file) => !
|
|
18742
|
+
var ProjectFileSchema = import_zod8.z.string().min(1).refine((file) => !import_node_path33.default.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
|
|
18678
18743
|
var AssetPatchSchema = import_zod8.z.object({
|
|
18679
18744
|
prompt: import_zod8.z.string().optional(),
|
|
18680
18745
|
/** Per-style override for the style being viewed; null removes it. */
|
|
@@ -19094,7 +19159,7 @@ function applyEdit(raw, edit) {
|
|
|
19094
19159
|
}
|
|
19095
19160
|
}
|
|
19096
19161
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
19097
|
-
const absolute =
|
|
19162
|
+
const absolute = import_node_path33.default.resolve(manifestPath);
|
|
19098
19163
|
const original = await (0, import_promises23.readFile)(absolute, "utf8");
|
|
19099
19164
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
19100
19165
|
let raw;
|
|
@@ -19108,9 +19173,9 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
19108
19173
|
applyEdit(raw, edit);
|
|
19109
19174
|
const next = serializeLike(original, raw);
|
|
19110
19175
|
if (next === original) return unchanged(absolute, original);
|
|
19111
|
-
const tmp =
|
|
19112
|
-
|
|
19113
|
-
`.${
|
|
19176
|
+
const tmp = import_node_path33.default.join(
|
|
19177
|
+
import_node_path33.default.dirname(absolute),
|
|
19178
|
+
`.${import_node_path33.default.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
|
|
19114
19179
|
);
|
|
19115
19180
|
try {
|
|
19116
19181
|
await (0, import_promises23.writeFile)(tmp, next);
|
|
@@ -19141,16 +19206,16 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
19141
19206
|
// src/pipeline/hand-edit.ts
|
|
19142
19207
|
var import_node_fs31 = require("fs");
|
|
19143
19208
|
var import_promises24 = require("fs/promises");
|
|
19144
|
-
var
|
|
19209
|
+
var import_node_path34 = __toESM(require("path"), 1);
|
|
19145
19210
|
var import_zod9 = require("zod");
|
|
19146
19211
|
var HAND_EDIT_DIR = "edits";
|
|
19147
19212
|
function handEditPath(loaded, spec) {
|
|
19148
19213
|
const style = loaded.manifest.styles[spec.styleId];
|
|
19149
|
-
const outDir =
|
|
19150
|
-
const relative =
|
|
19151
|
-
const inside = relative && !relative.startsWith("..") && !
|
|
19152
|
-
const file = inside ? relative :
|
|
19153
|
-
return
|
|
19214
|
+
const outDir = import_node_path34.default.resolve(loaded.root, style?.outDir ?? ".");
|
|
19215
|
+
const relative = import_node_path34.default.relative(outDir, spec.outFile);
|
|
19216
|
+
const inside = relative && !relative.startsWith("..") && !import_node_path34.default.isAbsolute(relative);
|
|
19217
|
+
const file = inside ? relative : import_node_path34.default.basename(spec.outFile);
|
|
19218
|
+
return import_node_path34.default.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
|
|
19154
19219
|
}
|
|
19155
19220
|
function handEditBases(spec, lock) {
|
|
19156
19221
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -19196,7 +19261,7 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
19196
19261
|
`${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`
|
|
19197
19262
|
);
|
|
19198
19263
|
}
|
|
19199
|
-
const existing = spec.source ?
|
|
19264
|
+
const existing = spec.source ? import_node_path34.default.resolve(loaded.root, spec.source) : null;
|
|
19200
19265
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
19201
19266
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
19202
19267
|
let created = false;
|
|
@@ -19207,7 +19272,7 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
19207
19272
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
19208
19273
|
);
|
|
19209
19274
|
}
|
|
19210
|
-
await (0, import_promises24.mkdir)(
|
|
19275
|
+
await (0, import_promises24.mkdir)(import_node_path34.default.dirname(member.path), { recursive: true });
|
|
19211
19276
|
await (0, import_promises24.copyFile)(member.base, member.path);
|
|
19212
19277
|
created = true;
|
|
19213
19278
|
}
|
|
@@ -19345,7 +19410,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
19345
19410
|
editor: input.editor,
|
|
19346
19411
|
protocol: input.protocol,
|
|
19347
19412
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
19348
|
-
project: projectPath ?
|
|
19413
|
+
project: projectPath ? import_node_path34.default.basename(projectPath) : null,
|
|
19349
19414
|
outputs: incoming.map((frame, index) => ({
|
|
19350
19415
|
role: frame.role,
|
|
19351
19416
|
basedOn: basedOnHash(entry, index),
|
|
@@ -19389,7 +19454,7 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
19389
19454
|
// src/gallery/upload.ts
|
|
19390
19455
|
var import_node_fs32 = require("fs");
|
|
19391
19456
|
var import_promises25 = require("fs/promises");
|
|
19392
|
-
var
|
|
19457
|
+
var import_node_path35 = __toESM(require("path"), 1);
|
|
19393
19458
|
var import_zod10 = require("zod");
|
|
19394
19459
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
19395
19460
|
var UploadImageSchema = import_zod10.z.object({
|
|
@@ -19402,12 +19467,12 @@ var UploadImageSchema = import_zod10.z.object({
|
|
|
19402
19467
|
overwrite: import_zod10.z.boolean().optional()
|
|
19403
19468
|
}).strict();
|
|
19404
19469
|
async function saveProjectImage(root, request) {
|
|
19405
|
-
const file =
|
|
19406
|
-
const relative =
|
|
19407
|
-
if (relative.startsWith("..") ||
|
|
19470
|
+
const file = import_node_path35.default.resolve(root, request.path);
|
|
19471
|
+
const relative = import_node_path35.default.relative(root, file);
|
|
19472
|
+
if (relative.startsWith("..") || import_node_path35.default.isAbsolute(relative)) {
|
|
19408
19473
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
19409
19474
|
}
|
|
19410
|
-
const extension =
|
|
19475
|
+
const extension = import_node_path35.default.extname(file).toLowerCase();
|
|
19411
19476
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
19412
19477
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
19413
19478
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -19420,17 +19485,17 @@ async function saveProjectImage(root, request) {
|
|
|
19420
19485
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
19421
19486
|
}
|
|
19422
19487
|
if ((0, import_node_fs32.existsSync)(file) && !request.overwrite) {
|
|
19423
|
-
throw new ManifestEditError(`${relative.split(
|
|
19488
|
+
throw new ManifestEditError(`${relative.split(import_node_path35.default.sep).join("/")} already exists; choose another name, or replace it`);
|
|
19424
19489
|
}
|
|
19425
|
-
await (0, import_promises25.mkdir)(
|
|
19490
|
+
await (0, import_promises25.mkdir)(import_node_path35.default.dirname(file), { recursive: true });
|
|
19426
19491
|
await (0, import_promises25.writeFile)(file, bytes);
|
|
19427
|
-
return relative.split(
|
|
19492
|
+
return relative.split(import_node_path35.default.sep).join("/");
|
|
19428
19493
|
}
|
|
19429
19494
|
|
|
19430
19495
|
// src/gallery/image-revision.ts
|
|
19431
19496
|
var import_node_fs33 = require("fs");
|
|
19432
19497
|
var import_promises26 = require("fs/promises");
|
|
19433
|
-
var
|
|
19498
|
+
var import_node_path36 = __toESM(require("path"), 1);
|
|
19434
19499
|
var import_zod11 = require("zod");
|
|
19435
19500
|
var InpaintRevisionRequestSchema = import_zod11.z.object({
|
|
19436
19501
|
action: import_zod11.z.literal("create-inpaint-revision"),
|
|
@@ -19449,14 +19514,14 @@ var InpaintRevisionRequestSchema = import_zod11.z.object({
|
|
|
19449
19514
|
overwrite: import_zod11.z.boolean().optional()
|
|
19450
19515
|
}).strict();
|
|
19451
19516
|
async function createInpaintRevision(manifestPath, request) {
|
|
19452
|
-
const root =
|
|
19453
|
-
if (
|
|
19517
|
+
const root = import_node_path36.default.dirname(import_node_path36.default.resolve(manifestPath));
|
|
19518
|
+
if (import_node_path36.default.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
19454
19519
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
19455
19520
|
}
|
|
19456
19521
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
19457
19522
|
const metadata = imageMetadata(bytes);
|
|
19458
19523
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
19459
|
-
const file =
|
|
19524
|
+
const file = import_node_path36.default.resolve(root, request.maskPath);
|
|
19460
19525
|
const previous = (0, import_node_fs33.existsSync)(file) ? await (0, import_promises26.readFile)(file) : null;
|
|
19461
19526
|
const mask = await saveProjectImage(root, {
|
|
19462
19527
|
action: "upload-image",
|
|
@@ -19486,7 +19551,7 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
19486
19551
|
// src/gallery/skeleton.ts
|
|
19487
19552
|
var import_node_fs34 = require("fs");
|
|
19488
19553
|
var import_promises27 = require("fs/promises");
|
|
19489
|
-
var
|
|
19554
|
+
var import_node_path37 = __toESM(require("path"), 1);
|
|
19490
19555
|
var import_zod12 = require("zod");
|
|
19491
19556
|
var SkeletonEstimateRequestSchema = import_zod12.z.object({
|
|
19492
19557
|
project: import_zod12.z.string().min(1).optional(),
|
|
@@ -19525,10 +19590,10 @@ var SkeletonKeypointsUpdateSchema = import_zod12.z.object({
|
|
|
19525
19590
|
set: SkeletonSetSchema
|
|
19526
19591
|
}).strict();
|
|
19527
19592
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
19528
|
-
const root =
|
|
19529
|
-
const file =
|
|
19530
|
-
const relative =
|
|
19531
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
19593
|
+
const root = import_node_path37.default.dirname(import_node_path37.default.resolve(manifestPath));
|
|
19594
|
+
const file = import_node_path37.default.resolve(root, request.keypointsFile);
|
|
19595
|
+
const relative = import_node_path37.default.relative(root, file);
|
|
19596
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || import_node_path37.default.isAbsolute(relative)) {
|
|
19532
19597
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
19533
19598
|
}
|
|
19534
19599
|
const existed = (0, import_node_fs34.existsSync)(file);
|
|
@@ -19538,7 +19603,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
19538
19603
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
19539
19604
|
}
|
|
19540
19605
|
if (existed) previous = await (0, import_promises27.readFile)(file);
|
|
19541
|
-
await (0, import_promises27.mkdir)(
|
|
19606
|
+
await (0, import_promises27.mkdir)(import_node_path37.default.dirname(file), { recursive: true });
|
|
19542
19607
|
await (0, import_promises27.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
19543
19608
|
} else if (!existed) {
|
|
19544
19609
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
@@ -19554,7 +19619,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
19554
19619
|
revision: {
|
|
19555
19620
|
mode: "animate-skeleton",
|
|
19556
19621
|
from: request.from,
|
|
19557
|
-
keypointsFile: relative.split(
|
|
19622
|
+
keypointsFile: relative.split(import_node_path37.default.sep).join("/"),
|
|
19558
19623
|
direction: request.direction,
|
|
19559
19624
|
description: request.description,
|
|
19560
19625
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -19575,19 +19640,19 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
19575
19640
|
if (!spec) throw new ManifestEditError(`"${key2}" is not declared by the manifest`);
|
|
19576
19641
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
19577
19642
|
if (!file) throw new ManifestEditError(`${key2} is not an animate-skeleton revision`);
|
|
19578
|
-
const relative =
|
|
19579
|
-
if (relative.startsWith("..") ||
|
|
19643
|
+
const relative = import_node_path37.default.relative(ctx.loaded.root, file);
|
|
19644
|
+
if (relative.startsWith("..") || import_node_path37.default.isAbsolute(relative)) {
|
|
19580
19645
|
throw new ManifestEditError(`${key2}'s keypoints file is outside the project; edit it by hand`);
|
|
19581
19646
|
}
|
|
19582
19647
|
const current = (0, import_node_fs34.existsSync)(file) ? sha256(await (0, import_promises27.readFile)(file)) : null;
|
|
19583
19648
|
if (current !== request.expectedSha256) {
|
|
19584
19649
|
throw Object.assign(
|
|
19585
|
-
new Error(`${relative.split(
|
|
19650
|
+
new Error(`${relative.split(import_node_path37.default.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
19586
19651
|
{ status: 409 }
|
|
19587
19652
|
);
|
|
19588
19653
|
}
|
|
19589
19654
|
await (0, import_promises27.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
19590
|
-
return relative.split(
|
|
19655
|
+
return relative.split(import_node_path37.default.sep).join("/");
|
|
19591
19656
|
}
|
|
19592
19657
|
|
|
19593
19658
|
// src/gallery/edit.ts
|
|
@@ -19641,7 +19706,7 @@ function createGalleryEditHandler(opts) {
|
|
|
19641
19706
|
const history = /* @__PURE__ */ new Map();
|
|
19642
19707
|
const manifestOf = async (project) => {
|
|
19643
19708
|
try {
|
|
19644
|
-
return
|
|
19709
|
+
return import_node_path38.default.resolve(await opts.manifestFor(typeof project === "string" ? project : void 0));
|
|
19645
19710
|
} catch {
|
|
19646
19711
|
return null;
|
|
19647
19712
|
}
|
|
@@ -19664,7 +19729,7 @@ function createGalleryEditHandler(opts) {
|
|
|
19664
19729
|
await (0, import_promises28.writeFile)(tmp, last.before);
|
|
19665
19730
|
await (0, import_promises28.rename)(tmp, manifestPath2);
|
|
19666
19731
|
stack.pop();
|
|
19667
|
-
log(` manifest edit undone in ${
|
|
19732
|
+
log(` manifest edit undone in ${import_node_path38.default.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
19668
19733
|
return opts.reload();
|
|
19669
19734
|
}
|
|
19670
19735
|
const manifestPath = await manifestOf(body?.project);
|
|
@@ -19726,7 +19791,7 @@ function createEditApplier(opts, log) {
|
|
|
19726
19791
|
} catch (error) {
|
|
19727
19792
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
19728
19793
|
}
|
|
19729
|
-
const written = await saveProjectImage(
|
|
19794
|
+
const written = await saveProjectImage(import_node_path38.default.dirname(import_node_path38.default.resolve(manifestPath2)), upload.data);
|
|
19730
19795
|
log(` image added: ${written}`);
|
|
19731
19796
|
return opts.reload();
|
|
19732
19797
|
}
|
|
@@ -19793,7 +19858,7 @@ function createEditApplier(opts, log) {
|
|
|
19793
19858
|
}
|
|
19794
19859
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
19795
19860
|
if (result.changed) {
|
|
19796
|
-
const relative =
|
|
19861
|
+
const relative = import_node_path38.default.relative(process.cwd(), result.manifestPath);
|
|
19797
19862
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
19798
19863
|
log(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
19799
19864
|
}
|
|
@@ -19821,7 +19886,7 @@ function describeEdit(edit) {
|
|
|
19821
19886
|
// src/gallery/snapshot.ts
|
|
19822
19887
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
19823
19888
|
function galleryMediaId(absolutePath) {
|
|
19824
|
-
return (0, import_node_crypto7.createHash)("sha256").update(
|
|
19889
|
+
return (0, import_node_crypto7.createHash)("sha256").update(import_node_path39.default.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
19825
19890
|
}
|
|
19826
19891
|
function galleryMediaRoute(id) {
|
|
19827
19892
|
return `/media/${id}`;
|
|
@@ -19845,7 +19910,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
19845
19910
|
return (entry.history ?? []).map((generation, i) => {
|
|
19846
19911
|
const outputs = generation.outputs.map((output) => {
|
|
19847
19912
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
19848
|
-
const file =
|
|
19913
|
+
const file = import_node_path39.default.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
19849
19914
|
let url = null;
|
|
19850
19915
|
if ((0, import_node_fs35.existsSync)(file)) {
|
|
19851
19916
|
const id = galleryMediaId(file);
|
|
@@ -19977,9 +20042,9 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
19977
20042
|
async function describeQuality(media, root, inspection) {
|
|
19978
20043
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
19979
20044
|
const outputs = await Promise.all(
|
|
19980
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
20045
|
+
outputPaths.map((file) => describeOutput(media, root, import_node_path39.default.resolve(root, file)))
|
|
19981
20046
|
);
|
|
19982
|
-
const recordPath =
|
|
20047
|
+
const recordPath = import_node_path39.default.resolve(root, inspection.record);
|
|
19983
20048
|
const recordExists = (0, import_node_fs35.existsSync)(recordPath);
|
|
19984
20049
|
let options = null;
|
|
19985
20050
|
let check = null;
|
|
@@ -19999,7 +20064,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
19999
20064
|
return {
|
|
20000
20065
|
state: inspection.state,
|
|
20001
20066
|
reason: inspection.reason,
|
|
20002
|
-
output: portableOutputPath(
|
|
20067
|
+
output: portableOutputPath(import_node_path39.default.resolve(root, inspection.output), root),
|
|
20003
20068
|
record: portableOutputPath(recordPath, root),
|
|
20004
20069
|
recordExists,
|
|
20005
20070
|
outputs,
|
|
@@ -20039,7 +20104,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20039
20104
|
const items = [];
|
|
20040
20105
|
const manifestText = await (0, import_promises29.readFile)(loaded.path, "utf8");
|
|
20041
20106
|
const manifestSha256 = sha256(manifestText);
|
|
20042
|
-
const cacheDir =
|
|
20107
|
+
const cacheDir = import_node_path39.default.resolve(import_node_path39.default.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
20043
20108
|
let rawStyles = {};
|
|
20044
20109
|
try {
|
|
20045
20110
|
const raw = JSON.parse(manifestText);
|
|
@@ -20063,7 +20128,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20063
20128
|
)
|
|
20064
20129
|
);
|
|
20065
20130
|
if (spec.source) {
|
|
20066
|
-
const editPath =
|
|
20131
|
+
const editPath = import_node_path39.default.resolve(root, spec.source);
|
|
20067
20132
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
20068
20133
|
const editShas = await Promise.all(
|
|
20069
20134
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
@@ -20112,7 +20177,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20112
20177
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
20113
20178
|
}
|
|
20114
20179
|
} else if (spec.source) {
|
|
20115
|
-
outputs = [await describeOutput(media, root,
|
|
20180
|
+
outputs = [await describeOutput(media, root, import_node_path39.default.resolve(root, spec.source))];
|
|
20116
20181
|
} else if (!entry && (0, import_node_fs35.existsSync)(spec.outFile)) {
|
|
20117
20182
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
20118
20183
|
} else {
|
|
@@ -20317,7 +20382,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20317
20382
|
id: loaded.manifest.name,
|
|
20318
20383
|
name: loaded.manifest.name,
|
|
20319
20384
|
manifest: loaded.path,
|
|
20320
|
-
lock:
|
|
20385
|
+
lock: import_node_path39.default.resolve(opts.lockPath),
|
|
20321
20386
|
root,
|
|
20322
20387
|
provider: loaded.manifest.provider,
|
|
20323
20388
|
account: null,
|
|
@@ -20343,7 +20408,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20343
20408
|
return { snapshot, media };
|
|
20344
20409
|
}
|
|
20345
20410
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
20346
|
-
const dir =
|
|
20411
|
+
const dir = import_node_path39.default.dirname(import_node_path39.default.resolve(opts.workspacePath));
|
|
20347
20412
|
const media = /* @__PURE__ */ new Map();
|
|
20348
20413
|
const projects = [];
|
|
20349
20414
|
const items = [];
|
|
@@ -20386,7 +20451,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20386
20451
|
id: project.id,
|
|
20387
20452
|
name: loaded.manifest.name,
|
|
20388
20453
|
manifest: manifestPath,
|
|
20389
|
-
lock:
|
|
20454
|
+
lock: import_node_path39.default.resolve(lockPath),
|
|
20390
20455
|
root: loaded.root,
|
|
20391
20456
|
provider: loaded.manifest.provider,
|
|
20392
20457
|
account: project.account ?? null,
|
|
@@ -20402,8 +20467,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20402
20467
|
id: project.id,
|
|
20403
20468
|
name: project.id,
|
|
20404
20469
|
manifest: manifestPath,
|
|
20405
|
-
lock:
|
|
20406
|
-
root:
|
|
20470
|
+
lock: import_node_path39.default.resolve(lockPath),
|
|
20471
|
+
root: import_node_path39.default.dirname(manifestPath),
|
|
20407
20472
|
provider: project.provider,
|
|
20408
20473
|
account: project.account ?? null,
|
|
20409
20474
|
manifestSha256: null,
|
|
@@ -20430,7 +20495,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20430
20495
|
version: 1,
|
|
20431
20496
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
20432
20497
|
project: null,
|
|
20433
|
-
workspace: { path:
|
|
20498
|
+
workspace: { path: import_node_path39.default.resolve(opts.workspacePath), dir, projects },
|
|
20434
20499
|
filter,
|
|
20435
20500
|
totals: {
|
|
20436
20501
|
entries: projects.reduce((sum, project) => sum + project.entries, 0),
|
|
@@ -20634,7 +20699,7 @@ var import_node_crypto8 = require("crypto");
|
|
|
20634
20699
|
var import_node_fs37 = require("fs");
|
|
20635
20700
|
var import_promises30 = require("fs/promises");
|
|
20636
20701
|
var import_node_os4 = __toESM(require("os"), 1);
|
|
20637
|
-
var
|
|
20702
|
+
var import_node_path40 = __toESM(require("path"), 1);
|
|
20638
20703
|
var EditorInstallError = class extends Error {
|
|
20639
20704
|
constructor(message6, file) {
|
|
20640
20705
|
super(message6);
|
|
@@ -20645,15 +20710,15 @@ var EditorInstallError = class extends Error {
|
|
|
20645
20710
|
};
|
|
20646
20711
|
function editorToolsRoot() {
|
|
20647
20712
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
20648
|
-
if (override) return
|
|
20649
|
-
if (process.platform === "darwin") return
|
|
20713
|
+
if (override) return import_node_path40.default.resolve(override);
|
|
20714
|
+
if (process.platform === "darwin") return import_node_path40.default.join(import_node_os4.default.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
20650
20715
|
if (process.platform === "win32") {
|
|
20651
|
-
return
|
|
20716
|
+
return import_node_path40.default.join(process.env.LOCALAPPDATA ?? import_node_path40.default.join(import_node_os4.default.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
20652
20717
|
}
|
|
20653
|
-
return
|
|
20718
|
+
return import_node_path40.default.join(process.env.XDG_CACHE_HOME ?? import_node_path40.default.join(import_node_os4.default.homedir(), ".cache"), "pixelkiln", "tools");
|
|
20654
20719
|
}
|
|
20655
20720
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
20656
|
-
return
|
|
20721
|
+
return import_node_path40.default.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
20657
20722
|
}
|
|
20658
20723
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
20659
20724
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -20676,7 +20741,7 @@ async function editorStatus(opts = {}) {
|
|
|
20676
20741
|
let totalBytes = 0;
|
|
20677
20742
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
20678
20743
|
totalBytes += expected.bytes;
|
|
20679
|
-
const file =
|
|
20744
|
+
const file = import_node_path40.default.join(dir, name);
|
|
20680
20745
|
const info = (0, import_node_fs37.existsSync)(file) ? await (0, import_promises30.stat)(file).catch(() => null) : null;
|
|
20681
20746
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
20682
20747
|
installedBytes += expected.bytes;
|
|
@@ -20734,7 +20799,7 @@ async function installEditor(opts = {}) {
|
|
|
20734
20799
|
if (digest2 !== expected.sha256) {
|
|
20735
20800
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
20736
20801
|
}
|
|
20737
|
-
const final =
|
|
20802
|
+
const final = import_node_path40.default.join(dir, name);
|
|
20738
20803
|
const tmp = `${final}.${process.pid}.part`;
|
|
20739
20804
|
try {
|
|
20740
20805
|
await (0, import_promises30.writeFile)(tmp, bytes);
|
|
@@ -20780,12 +20845,12 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
20780
20845
|
".json": "application/json; charset=utf-8"
|
|
20781
20846
|
};
|
|
20782
20847
|
function editorContentType(name) {
|
|
20783
|
-
return EDITOR_CONTENT_TYPES[
|
|
20848
|
+
return EDITOR_CONTENT_TYPES[import_node_path40.default.extname(name).toLowerCase()] ?? null;
|
|
20784
20849
|
}
|
|
20785
20850
|
|
|
20786
20851
|
// src/gallery/editor.ts
|
|
20787
20852
|
var import_promises31 = require("fs/promises");
|
|
20788
|
-
var
|
|
20853
|
+
var import_node_path41 = __toESM(require("path"), 1);
|
|
20789
20854
|
function editorRoute(release, name = "index.html") {
|
|
20790
20855
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
20791
20856
|
}
|
|
@@ -20858,7 +20923,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
20858
20923
|
if (!status.installed) return null;
|
|
20859
20924
|
let bytes;
|
|
20860
20925
|
try {
|
|
20861
|
-
bytes = await (0, import_promises31.readFile)(
|
|
20926
|
+
bytes = await (0, import_promises31.readFile)(import_node_path41.default.join(dir, name));
|
|
20862
20927
|
} catch {
|
|
20863
20928
|
verified = null;
|
|
20864
20929
|
return null;
|
|
@@ -21551,7 +21616,7 @@ function createGenerateHandlers(opts) {
|
|
|
21551
21616
|
// src/pipeline/salvage.ts
|
|
21552
21617
|
var import_promises33 = require("fs/promises");
|
|
21553
21618
|
var import_node_fs38 = require("fs");
|
|
21554
|
-
var
|
|
21619
|
+
var import_node_path42 = __toESM(require("path"), 1);
|
|
21555
21620
|
function providerClaimId(provider, objectId) {
|
|
21556
21621
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
21557
21622
|
}
|
|
@@ -21665,20 +21730,20 @@ function matchOrphanStyle(prompt, manifest) {
|
|
|
21665
21730
|
return matchStyleByPattern(prompt, manifest);
|
|
21666
21731
|
}
|
|
21667
21732
|
async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
|
|
21668
|
-
const own =
|
|
21733
|
+
const own = import_node_path42.default.resolve(ownManifestPath);
|
|
21669
21734
|
const siblingManifestPaths = [
|
|
21670
21735
|
.../* @__PURE__ */ new Set([
|
|
21671
21736
|
...workspaceManifestPaths,
|
|
21672
|
-
...claimPaths.map((c) =>
|
|
21737
|
+
...claimPaths.map((c) => import_node_path42.default.join(import_node_path42.default.dirname(import_node_path42.default.resolve(c)), "pixelkiln.manifest.json"))
|
|
21673
21738
|
])
|
|
21674
21739
|
];
|
|
21675
21740
|
const siblings = [];
|
|
21676
21741
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
21677
|
-
if (
|
|
21742
|
+
if (import_node_path42.default.resolve(siblingManifestPath) === own) continue;
|
|
21678
21743
|
if (!(0, import_node_fs38.existsSync)(siblingManifestPath)) continue;
|
|
21679
21744
|
try {
|
|
21680
21745
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
21681
|
-
siblings.push({ label:
|
|
21746
|
+
siblings.push({ label: import_node_path42.default.basename(import_node_path42.default.dirname(siblingManifestPath)), manifest });
|
|
21682
21747
|
} catch {
|
|
21683
21748
|
}
|
|
21684
21749
|
}
|
|
@@ -21799,7 +21864,7 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
21799
21864
|
|
|
21800
21865
|
// src/pick/salvage-server.ts
|
|
21801
21866
|
var import_promises34 = require("fs/promises");
|
|
21802
|
-
var
|
|
21867
|
+
var import_node_path43 = __toESM(require("path"), 1);
|
|
21803
21868
|
|
|
21804
21869
|
// src/pick/salvage-sheet.ts
|
|
21805
21870
|
var escapeHtml3 = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -21965,7 +22030,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21965
22030
|
});
|
|
21966
22031
|
const html = renderSalvageSheet(orphans, {
|
|
21967
22032
|
styleId: ctx.styleId,
|
|
21968
|
-
importDir:
|
|
22033
|
+
importDir: import_node_path43.default.relative(process.cwd(), ctx.importDir) || "."
|
|
21969
22034
|
});
|
|
21970
22035
|
const byId = new Map(orphans.map((o) => [o.id, o]));
|
|
21971
22036
|
const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
|
|
@@ -22021,9 +22086,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
22021
22086
|
if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
|
|
22022
22087
|
decodePng(buf);
|
|
22023
22088
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
22024
|
-
const rel =
|
|
22025
|
-
const outFile =
|
|
22026
|
-
await (0, import_promises34.mkdir)(
|
|
22089
|
+
const rel = import_node_path43.default.join("_salvaged", `${assetId}.png`);
|
|
22090
|
+
const outFile = import_node_path43.default.resolve(ctx.importDir, rel);
|
|
22091
|
+
await (0, import_promises34.mkdir)(import_node_path43.default.dirname(outFile), { recursive: true });
|
|
22027
22092
|
await (0, import_promises34.writeFile)(outFile, buf);
|
|
22028
22093
|
ctx.manifest.assets[assetId] = {
|
|
22029
22094
|
prompt: orphan.prompt,
|
|
@@ -22056,7 +22121,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
22056
22121
|
sourceUrl: durableSource,
|
|
22057
22122
|
sourceUrls: durableSource ? [{ url: durableSource }] : [],
|
|
22058
22123
|
outputs: [{
|
|
22059
|
-
path: portableOutputPath(outFile,
|
|
22124
|
+
path: portableOutputPath(outFile, import_node_path43.default.dirname(ctx.manifestPath)),
|
|
22060
22125
|
sha256: sha256(buf)
|
|
22061
22126
|
}],
|
|
22062
22127
|
submittedAt: orphan.createdAt,
|
|
@@ -22235,6 +22300,7 @@ async function workspaceStatus(ws, dir) {
|
|
|
22235
22300
|
InheritedStyleSchema,
|
|
22236
22301
|
LockEntrySchema,
|
|
22237
22302
|
LockHistoryEntrySchema,
|
|
22303
|
+
LockOriginSchema,
|
|
22238
22304
|
LockSchema,
|
|
22239
22305
|
LockTerrainSettingsSchema,
|
|
22240
22306
|
MAX_DOWNLOAD_BYTES,
|