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.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)];
|
|
@@ -19184,7 +19249,27 @@ function handEditMembers(loaded, spec, lock, editPath) {
|
|
|
19184
19249
|
}
|
|
19185
19250
|
return [{ role: null, path: editPath, base: bases?.[0]?.path ?? null }];
|
|
19186
19251
|
}
|
|
19252
|
+
function refuseUneditable(spec) {
|
|
19253
|
+
const key2 = `${spec.styleId}/${spec.assetId}`;
|
|
19254
|
+
if (spec.derive) {
|
|
19255
|
+
const from = spec.derive.source.kind === "asset" ? spec.derive.source.assetId : spec.derive.source.file;
|
|
19256
|
+
throw new ManifestEditError(
|
|
19257
|
+
`${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`
|
|
19258
|
+
);
|
|
19259
|
+
}
|
|
19260
|
+
if (spec.external) {
|
|
19261
|
+
throw new ManifestEditError(
|
|
19262
|
+
`${key2} is built outside pixelkiln (${spec.external.builder}); change it there, then run pixelkiln adopt --local --force to record the new file`
|
|
19263
|
+
);
|
|
19264
|
+
}
|
|
19265
|
+
if (spec.mirror) {
|
|
19266
|
+
throw new ManifestEditError(
|
|
19267
|
+
`${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`
|
|
19268
|
+
);
|
|
19269
|
+
}
|
|
19270
|
+
}
|
|
19187
19271
|
async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
19272
|
+
refuseUneditable(spec);
|
|
19188
19273
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
19189
19274
|
if (entry && entry.outputs.length > 1 && !isMemberSetEntry(entry)) {
|
|
19190
19275
|
throw new ManifestEditError(
|
|
@@ -19196,7 +19281,7 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
19196
19281
|
`${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
19282
|
);
|
|
19198
19283
|
}
|
|
19199
|
-
const existing = spec.source ?
|
|
19284
|
+
const existing = spec.source ? import_node_path34.default.resolve(loaded.root, spec.source) : null;
|
|
19200
19285
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
19201
19286
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
19202
19287
|
let created = false;
|
|
@@ -19207,7 +19292,7 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
19207
19292
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
19208
19293
|
);
|
|
19209
19294
|
}
|
|
19210
|
-
await (0, import_promises24.mkdir)(
|
|
19295
|
+
await (0, import_promises24.mkdir)(import_node_path34.default.dirname(member.path), { recursive: true });
|
|
19211
19296
|
await (0, import_promises24.copyFile)(member.base, member.path);
|
|
19212
19297
|
created = true;
|
|
19213
19298
|
}
|
|
@@ -19298,6 +19383,7 @@ async function readHandEditCompanion(editPath) {
|
|
|
19298
19383
|
}
|
|
19299
19384
|
var MAX_HAND_EDIT_BYTES = 16 * 1024 * 1024;
|
|
19300
19385
|
async function saveHandEdit(loaded, lock, spec, input) {
|
|
19386
|
+
refuseUneditable(spec);
|
|
19301
19387
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
19302
19388
|
const memberSet = entry ? isMemberSetEntry(entry) : false;
|
|
19303
19389
|
const incoming = input.frames ?? (input.png ? [{ role: null, png: input.png }] : []);
|
|
@@ -19345,7 +19431,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
19345
19431
|
editor: input.editor,
|
|
19346
19432
|
protocol: input.protocol,
|
|
19347
19433
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
19348
|
-
project: projectPath ?
|
|
19434
|
+
project: projectPath ? import_node_path34.default.basename(projectPath) : null,
|
|
19349
19435
|
outputs: incoming.map((frame, index) => ({
|
|
19350
19436
|
role: frame.role,
|
|
19351
19437
|
basedOn: basedOnHash(entry, index),
|
|
@@ -19389,7 +19475,7 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
19389
19475
|
// src/gallery/upload.ts
|
|
19390
19476
|
var import_node_fs32 = require("fs");
|
|
19391
19477
|
var import_promises25 = require("fs/promises");
|
|
19392
|
-
var
|
|
19478
|
+
var import_node_path35 = __toESM(require("path"), 1);
|
|
19393
19479
|
var import_zod10 = require("zod");
|
|
19394
19480
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
19395
19481
|
var UploadImageSchema = import_zod10.z.object({
|
|
@@ -19402,12 +19488,12 @@ var UploadImageSchema = import_zod10.z.object({
|
|
|
19402
19488
|
overwrite: import_zod10.z.boolean().optional()
|
|
19403
19489
|
}).strict();
|
|
19404
19490
|
async function saveProjectImage(root, request) {
|
|
19405
|
-
const file =
|
|
19406
|
-
const relative =
|
|
19407
|
-
if (relative.startsWith("..") ||
|
|
19491
|
+
const file = import_node_path35.default.resolve(root, request.path);
|
|
19492
|
+
const relative = import_node_path35.default.relative(root, file);
|
|
19493
|
+
if (relative.startsWith("..") || import_node_path35.default.isAbsolute(relative)) {
|
|
19408
19494
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
19409
19495
|
}
|
|
19410
|
-
const extension =
|
|
19496
|
+
const extension = import_node_path35.default.extname(file).toLowerCase();
|
|
19411
19497
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
19412
19498
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
19413
19499
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -19420,17 +19506,17 @@ async function saveProjectImage(root, request) {
|
|
|
19420
19506
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
19421
19507
|
}
|
|
19422
19508
|
if ((0, import_node_fs32.existsSync)(file) && !request.overwrite) {
|
|
19423
|
-
throw new ManifestEditError(`${relative.split(
|
|
19509
|
+
throw new ManifestEditError(`${relative.split(import_node_path35.default.sep).join("/")} already exists; choose another name, or replace it`);
|
|
19424
19510
|
}
|
|
19425
|
-
await (0, import_promises25.mkdir)(
|
|
19511
|
+
await (0, import_promises25.mkdir)(import_node_path35.default.dirname(file), { recursive: true });
|
|
19426
19512
|
await (0, import_promises25.writeFile)(file, bytes);
|
|
19427
|
-
return relative.split(
|
|
19513
|
+
return relative.split(import_node_path35.default.sep).join("/");
|
|
19428
19514
|
}
|
|
19429
19515
|
|
|
19430
19516
|
// src/gallery/image-revision.ts
|
|
19431
19517
|
var import_node_fs33 = require("fs");
|
|
19432
19518
|
var import_promises26 = require("fs/promises");
|
|
19433
|
-
var
|
|
19519
|
+
var import_node_path36 = __toESM(require("path"), 1);
|
|
19434
19520
|
var import_zod11 = require("zod");
|
|
19435
19521
|
var InpaintRevisionRequestSchema = import_zod11.z.object({
|
|
19436
19522
|
action: import_zod11.z.literal("create-inpaint-revision"),
|
|
@@ -19449,14 +19535,14 @@ var InpaintRevisionRequestSchema = import_zod11.z.object({
|
|
|
19449
19535
|
overwrite: import_zod11.z.boolean().optional()
|
|
19450
19536
|
}).strict();
|
|
19451
19537
|
async function createInpaintRevision(manifestPath, request) {
|
|
19452
|
-
const root =
|
|
19453
|
-
if (
|
|
19538
|
+
const root = import_node_path36.default.dirname(import_node_path36.default.resolve(manifestPath));
|
|
19539
|
+
if (import_node_path36.default.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
19454
19540
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
19455
19541
|
}
|
|
19456
19542
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
19457
19543
|
const metadata = imageMetadata(bytes);
|
|
19458
19544
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
19459
|
-
const file =
|
|
19545
|
+
const file = import_node_path36.default.resolve(root, request.maskPath);
|
|
19460
19546
|
const previous = (0, import_node_fs33.existsSync)(file) ? await (0, import_promises26.readFile)(file) : null;
|
|
19461
19547
|
const mask = await saveProjectImage(root, {
|
|
19462
19548
|
action: "upload-image",
|
|
@@ -19486,7 +19572,7 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
19486
19572
|
// src/gallery/skeleton.ts
|
|
19487
19573
|
var import_node_fs34 = require("fs");
|
|
19488
19574
|
var import_promises27 = require("fs/promises");
|
|
19489
|
-
var
|
|
19575
|
+
var import_node_path37 = __toESM(require("path"), 1);
|
|
19490
19576
|
var import_zod12 = require("zod");
|
|
19491
19577
|
var SkeletonEstimateRequestSchema = import_zod12.z.object({
|
|
19492
19578
|
project: import_zod12.z.string().min(1).optional(),
|
|
@@ -19525,10 +19611,10 @@ var SkeletonKeypointsUpdateSchema = import_zod12.z.object({
|
|
|
19525
19611
|
set: SkeletonSetSchema
|
|
19526
19612
|
}).strict();
|
|
19527
19613
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
19528
|
-
const root =
|
|
19529
|
-
const file =
|
|
19530
|
-
const relative =
|
|
19531
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
19614
|
+
const root = import_node_path37.default.dirname(import_node_path37.default.resolve(manifestPath));
|
|
19615
|
+
const file = import_node_path37.default.resolve(root, request.keypointsFile);
|
|
19616
|
+
const relative = import_node_path37.default.relative(root, file);
|
|
19617
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || import_node_path37.default.isAbsolute(relative)) {
|
|
19532
19618
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
19533
19619
|
}
|
|
19534
19620
|
const existed = (0, import_node_fs34.existsSync)(file);
|
|
@@ -19538,7 +19624,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
19538
19624
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
19539
19625
|
}
|
|
19540
19626
|
if (existed) previous = await (0, import_promises27.readFile)(file);
|
|
19541
|
-
await (0, import_promises27.mkdir)(
|
|
19627
|
+
await (0, import_promises27.mkdir)(import_node_path37.default.dirname(file), { recursive: true });
|
|
19542
19628
|
await (0, import_promises27.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
19543
19629
|
} else if (!existed) {
|
|
19544
19630
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
@@ -19554,7 +19640,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
19554
19640
|
revision: {
|
|
19555
19641
|
mode: "animate-skeleton",
|
|
19556
19642
|
from: request.from,
|
|
19557
|
-
keypointsFile: relative.split(
|
|
19643
|
+
keypointsFile: relative.split(import_node_path37.default.sep).join("/"),
|
|
19558
19644
|
direction: request.direction,
|
|
19559
19645
|
description: request.description,
|
|
19560
19646
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -19575,19 +19661,19 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
19575
19661
|
if (!spec) throw new ManifestEditError(`"${key2}" is not declared by the manifest`);
|
|
19576
19662
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
19577
19663
|
if (!file) throw new ManifestEditError(`${key2} is not an animate-skeleton revision`);
|
|
19578
|
-
const relative =
|
|
19579
|
-
if (relative.startsWith("..") ||
|
|
19664
|
+
const relative = import_node_path37.default.relative(ctx.loaded.root, file);
|
|
19665
|
+
if (relative.startsWith("..") || import_node_path37.default.isAbsolute(relative)) {
|
|
19580
19666
|
throw new ManifestEditError(`${key2}'s keypoints file is outside the project; edit it by hand`);
|
|
19581
19667
|
}
|
|
19582
19668
|
const current = (0, import_node_fs34.existsSync)(file) ? sha256(await (0, import_promises27.readFile)(file)) : null;
|
|
19583
19669
|
if (current !== request.expectedSha256) {
|
|
19584
19670
|
throw Object.assign(
|
|
19585
|
-
new Error(`${relative.split(
|
|
19671
|
+
new Error(`${relative.split(import_node_path37.default.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
19586
19672
|
{ status: 409 }
|
|
19587
19673
|
);
|
|
19588
19674
|
}
|
|
19589
19675
|
await (0, import_promises27.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
19590
|
-
return relative.split(
|
|
19676
|
+
return relative.split(import_node_path37.default.sep).join("/");
|
|
19591
19677
|
}
|
|
19592
19678
|
|
|
19593
19679
|
// src/gallery/edit.ts
|
|
@@ -19641,7 +19727,7 @@ function createGalleryEditHandler(opts) {
|
|
|
19641
19727
|
const history = /* @__PURE__ */ new Map();
|
|
19642
19728
|
const manifestOf = async (project) => {
|
|
19643
19729
|
try {
|
|
19644
|
-
return
|
|
19730
|
+
return import_node_path38.default.resolve(await opts.manifestFor(typeof project === "string" ? project : void 0));
|
|
19645
19731
|
} catch {
|
|
19646
19732
|
return null;
|
|
19647
19733
|
}
|
|
@@ -19664,7 +19750,7 @@ function createGalleryEditHandler(opts) {
|
|
|
19664
19750
|
await (0, import_promises28.writeFile)(tmp, last.before);
|
|
19665
19751
|
await (0, import_promises28.rename)(tmp, manifestPath2);
|
|
19666
19752
|
stack.pop();
|
|
19667
|
-
log(` manifest edit undone in ${
|
|
19753
|
+
log(` manifest edit undone in ${import_node_path38.default.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
19668
19754
|
return opts.reload();
|
|
19669
19755
|
}
|
|
19670
19756
|
const manifestPath = await manifestOf(body?.project);
|
|
@@ -19726,7 +19812,7 @@ function createEditApplier(opts, log) {
|
|
|
19726
19812
|
} catch (error) {
|
|
19727
19813
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
19728
19814
|
}
|
|
19729
|
-
const written = await saveProjectImage(
|
|
19815
|
+
const written = await saveProjectImage(import_node_path38.default.dirname(import_node_path38.default.resolve(manifestPath2)), upload.data);
|
|
19730
19816
|
log(` image added: ${written}`);
|
|
19731
19817
|
return opts.reload();
|
|
19732
19818
|
}
|
|
@@ -19793,7 +19879,7 @@ function createEditApplier(opts, log) {
|
|
|
19793
19879
|
}
|
|
19794
19880
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
19795
19881
|
if (result.changed) {
|
|
19796
|
-
const relative =
|
|
19882
|
+
const relative = import_node_path38.default.relative(process.cwd(), result.manifestPath);
|
|
19797
19883
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
19798
19884
|
log(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
19799
19885
|
}
|
|
@@ -19821,7 +19907,7 @@ function describeEdit(edit) {
|
|
|
19821
19907
|
// src/gallery/snapshot.ts
|
|
19822
19908
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
19823
19909
|
function galleryMediaId(absolutePath) {
|
|
19824
|
-
return (0, import_node_crypto7.createHash)("sha256").update(
|
|
19910
|
+
return (0, import_node_crypto7.createHash)("sha256").update(import_node_path39.default.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
19825
19911
|
}
|
|
19826
19912
|
function galleryMediaRoute(id) {
|
|
19827
19913
|
return `/media/${id}`;
|
|
@@ -19845,7 +19931,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
19845
19931
|
return (entry.history ?? []).map((generation, i) => {
|
|
19846
19932
|
const outputs = generation.outputs.map((output) => {
|
|
19847
19933
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
19848
|
-
const file =
|
|
19934
|
+
const file = import_node_path39.default.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
19849
19935
|
let url = null;
|
|
19850
19936
|
if ((0, import_node_fs35.existsSync)(file)) {
|
|
19851
19937
|
const id = galleryMediaId(file);
|
|
@@ -19977,9 +20063,9 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
19977
20063
|
async function describeQuality(media, root, inspection) {
|
|
19978
20064
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
19979
20065
|
const outputs = await Promise.all(
|
|
19980
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
20066
|
+
outputPaths.map((file) => describeOutput(media, root, import_node_path39.default.resolve(root, file)))
|
|
19981
20067
|
);
|
|
19982
|
-
const recordPath =
|
|
20068
|
+
const recordPath = import_node_path39.default.resolve(root, inspection.record);
|
|
19983
20069
|
const recordExists = (0, import_node_fs35.existsSync)(recordPath);
|
|
19984
20070
|
let options = null;
|
|
19985
20071
|
let check = null;
|
|
@@ -19999,7 +20085,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
19999
20085
|
return {
|
|
20000
20086
|
state: inspection.state,
|
|
20001
20087
|
reason: inspection.reason,
|
|
20002
|
-
output: portableOutputPath(
|
|
20088
|
+
output: portableOutputPath(import_node_path39.default.resolve(root, inspection.output), root),
|
|
20003
20089
|
record: portableOutputPath(recordPath, root),
|
|
20004
20090
|
recordExists,
|
|
20005
20091
|
outputs,
|
|
@@ -20039,7 +20125,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20039
20125
|
const items = [];
|
|
20040
20126
|
const manifestText = await (0, import_promises29.readFile)(loaded.path, "utf8");
|
|
20041
20127
|
const manifestSha256 = sha256(manifestText);
|
|
20042
|
-
const cacheDir =
|
|
20128
|
+
const cacheDir = import_node_path39.default.resolve(import_node_path39.default.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
20043
20129
|
let rawStyles = {};
|
|
20044
20130
|
try {
|
|
20045
20131
|
const raw = JSON.parse(manifestText);
|
|
@@ -20063,7 +20149,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20063
20149
|
)
|
|
20064
20150
|
);
|
|
20065
20151
|
if (spec.source) {
|
|
20066
|
-
const editPath =
|
|
20152
|
+
const editPath = import_node_path39.default.resolve(root, spec.source);
|
|
20067
20153
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
20068
20154
|
const editShas = await Promise.all(
|
|
20069
20155
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
@@ -20112,7 +20198,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20112
20198
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
20113
20199
|
}
|
|
20114
20200
|
} else if (spec.source) {
|
|
20115
|
-
outputs = [await describeOutput(media, root,
|
|
20201
|
+
outputs = [await describeOutput(media, root, import_node_path39.default.resolve(root, spec.source))];
|
|
20116
20202
|
} else if (!entry && (0, import_node_fs35.existsSync)(spec.outFile)) {
|
|
20117
20203
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
20118
20204
|
} else {
|
|
@@ -20317,7 +20403,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20317
20403
|
id: loaded.manifest.name,
|
|
20318
20404
|
name: loaded.manifest.name,
|
|
20319
20405
|
manifest: loaded.path,
|
|
20320
|
-
lock:
|
|
20406
|
+
lock: import_node_path39.default.resolve(opts.lockPath),
|
|
20321
20407
|
root,
|
|
20322
20408
|
provider: loaded.manifest.provider,
|
|
20323
20409
|
account: null,
|
|
@@ -20343,7 +20429,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20343
20429
|
return { snapshot, media };
|
|
20344
20430
|
}
|
|
20345
20431
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
20346
|
-
const dir =
|
|
20432
|
+
const dir = import_node_path39.default.dirname(import_node_path39.default.resolve(opts.workspacePath));
|
|
20347
20433
|
const media = /* @__PURE__ */ new Map();
|
|
20348
20434
|
const projects = [];
|
|
20349
20435
|
const items = [];
|
|
@@ -20386,7 +20472,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20386
20472
|
id: project.id,
|
|
20387
20473
|
name: loaded.manifest.name,
|
|
20388
20474
|
manifest: manifestPath,
|
|
20389
|
-
lock:
|
|
20475
|
+
lock: import_node_path39.default.resolve(lockPath),
|
|
20390
20476
|
root: loaded.root,
|
|
20391
20477
|
provider: loaded.manifest.provider,
|
|
20392
20478
|
account: project.account ?? null,
|
|
@@ -20402,8 +20488,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20402
20488
|
id: project.id,
|
|
20403
20489
|
name: project.id,
|
|
20404
20490
|
manifest: manifestPath,
|
|
20405
|
-
lock:
|
|
20406
|
-
root:
|
|
20491
|
+
lock: import_node_path39.default.resolve(lockPath),
|
|
20492
|
+
root: import_node_path39.default.dirname(manifestPath),
|
|
20407
20493
|
provider: project.provider,
|
|
20408
20494
|
account: project.account ?? null,
|
|
20409
20495
|
manifestSha256: null,
|
|
@@ -20430,7 +20516,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20430
20516
|
version: 1,
|
|
20431
20517
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
20432
20518
|
project: null,
|
|
20433
|
-
workspace: { path:
|
|
20519
|
+
workspace: { path: import_node_path39.default.resolve(opts.workspacePath), dir, projects },
|
|
20434
20520
|
filter,
|
|
20435
20521
|
totals: {
|
|
20436
20522
|
entries: projects.reduce((sum, project) => sum + project.entries, 0),
|
|
@@ -20634,7 +20720,7 @@ var import_node_crypto8 = require("crypto");
|
|
|
20634
20720
|
var import_node_fs37 = require("fs");
|
|
20635
20721
|
var import_promises30 = require("fs/promises");
|
|
20636
20722
|
var import_node_os4 = __toESM(require("os"), 1);
|
|
20637
|
-
var
|
|
20723
|
+
var import_node_path40 = __toESM(require("path"), 1);
|
|
20638
20724
|
var EditorInstallError = class extends Error {
|
|
20639
20725
|
constructor(message6, file) {
|
|
20640
20726
|
super(message6);
|
|
@@ -20645,15 +20731,15 @@ var EditorInstallError = class extends Error {
|
|
|
20645
20731
|
};
|
|
20646
20732
|
function editorToolsRoot() {
|
|
20647
20733
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
20648
|
-
if (override) return
|
|
20649
|
-
if (process.platform === "darwin") return
|
|
20734
|
+
if (override) return import_node_path40.default.resolve(override);
|
|
20735
|
+
if (process.platform === "darwin") return import_node_path40.default.join(import_node_os4.default.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
20650
20736
|
if (process.platform === "win32") {
|
|
20651
|
-
return
|
|
20737
|
+
return import_node_path40.default.join(process.env.LOCALAPPDATA ?? import_node_path40.default.join(import_node_os4.default.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
20652
20738
|
}
|
|
20653
|
-
return
|
|
20739
|
+
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
20740
|
}
|
|
20655
20741
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
20656
|
-
return
|
|
20742
|
+
return import_node_path40.default.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
20657
20743
|
}
|
|
20658
20744
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
20659
20745
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -20676,7 +20762,7 @@ async function editorStatus(opts = {}) {
|
|
|
20676
20762
|
let totalBytes = 0;
|
|
20677
20763
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
20678
20764
|
totalBytes += expected.bytes;
|
|
20679
|
-
const file =
|
|
20765
|
+
const file = import_node_path40.default.join(dir, name);
|
|
20680
20766
|
const info = (0, import_node_fs37.existsSync)(file) ? await (0, import_promises30.stat)(file).catch(() => null) : null;
|
|
20681
20767
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
20682
20768
|
installedBytes += expected.bytes;
|
|
@@ -20734,7 +20820,7 @@ async function installEditor(opts = {}) {
|
|
|
20734
20820
|
if (digest2 !== expected.sha256) {
|
|
20735
20821
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
20736
20822
|
}
|
|
20737
|
-
const final =
|
|
20823
|
+
const final = import_node_path40.default.join(dir, name);
|
|
20738
20824
|
const tmp = `${final}.${process.pid}.part`;
|
|
20739
20825
|
try {
|
|
20740
20826
|
await (0, import_promises30.writeFile)(tmp, bytes);
|
|
@@ -20780,12 +20866,12 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
20780
20866
|
".json": "application/json; charset=utf-8"
|
|
20781
20867
|
};
|
|
20782
20868
|
function editorContentType(name) {
|
|
20783
|
-
return EDITOR_CONTENT_TYPES[
|
|
20869
|
+
return EDITOR_CONTENT_TYPES[import_node_path40.default.extname(name).toLowerCase()] ?? null;
|
|
20784
20870
|
}
|
|
20785
20871
|
|
|
20786
20872
|
// src/gallery/editor.ts
|
|
20787
20873
|
var import_promises31 = require("fs/promises");
|
|
20788
|
-
var
|
|
20874
|
+
var import_node_path41 = __toESM(require("path"), 1);
|
|
20789
20875
|
function editorRoute(release, name = "index.html") {
|
|
20790
20876
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
20791
20877
|
}
|
|
@@ -20858,7 +20944,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
20858
20944
|
if (!status.installed) return null;
|
|
20859
20945
|
let bytes;
|
|
20860
20946
|
try {
|
|
20861
|
-
bytes = await (0, import_promises31.readFile)(
|
|
20947
|
+
bytes = await (0, import_promises31.readFile)(import_node_path41.default.join(dir, name));
|
|
20862
20948
|
} catch {
|
|
20863
20949
|
verified = null;
|
|
20864
20950
|
return null;
|
|
@@ -21551,7 +21637,7 @@ function createGenerateHandlers(opts) {
|
|
|
21551
21637
|
// src/pipeline/salvage.ts
|
|
21552
21638
|
var import_promises33 = require("fs/promises");
|
|
21553
21639
|
var import_node_fs38 = require("fs");
|
|
21554
|
-
var
|
|
21640
|
+
var import_node_path42 = __toESM(require("path"), 1);
|
|
21555
21641
|
function providerClaimId(provider, objectId) {
|
|
21556
21642
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
21557
21643
|
}
|
|
@@ -21665,20 +21751,20 @@ function matchOrphanStyle(prompt, manifest) {
|
|
|
21665
21751
|
return matchStyleByPattern(prompt, manifest);
|
|
21666
21752
|
}
|
|
21667
21753
|
async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
|
|
21668
|
-
const own =
|
|
21754
|
+
const own = import_node_path42.default.resolve(ownManifestPath);
|
|
21669
21755
|
const siblingManifestPaths = [
|
|
21670
21756
|
.../* @__PURE__ */ new Set([
|
|
21671
21757
|
...workspaceManifestPaths,
|
|
21672
|
-
...claimPaths.map((c) =>
|
|
21758
|
+
...claimPaths.map((c) => import_node_path42.default.join(import_node_path42.default.dirname(import_node_path42.default.resolve(c)), "pixelkiln.manifest.json"))
|
|
21673
21759
|
])
|
|
21674
21760
|
];
|
|
21675
21761
|
const siblings = [];
|
|
21676
21762
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
21677
|
-
if (
|
|
21763
|
+
if (import_node_path42.default.resolve(siblingManifestPath) === own) continue;
|
|
21678
21764
|
if (!(0, import_node_fs38.existsSync)(siblingManifestPath)) continue;
|
|
21679
21765
|
try {
|
|
21680
21766
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
21681
|
-
siblings.push({ label:
|
|
21767
|
+
siblings.push({ label: import_node_path42.default.basename(import_node_path42.default.dirname(siblingManifestPath)), manifest });
|
|
21682
21768
|
} catch {
|
|
21683
21769
|
}
|
|
21684
21770
|
}
|
|
@@ -21799,7 +21885,7 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
21799
21885
|
|
|
21800
21886
|
// src/pick/salvage-server.ts
|
|
21801
21887
|
var import_promises34 = require("fs/promises");
|
|
21802
|
-
var
|
|
21888
|
+
var import_node_path43 = __toESM(require("path"), 1);
|
|
21803
21889
|
|
|
21804
21890
|
// src/pick/salvage-sheet.ts
|
|
21805
21891
|
var escapeHtml3 = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -21965,7 +22051,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21965
22051
|
});
|
|
21966
22052
|
const html = renderSalvageSheet(orphans, {
|
|
21967
22053
|
styleId: ctx.styleId,
|
|
21968
|
-
importDir:
|
|
22054
|
+
importDir: import_node_path43.default.relative(process.cwd(), ctx.importDir) || "."
|
|
21969
22055
|
});
|
|
21970
22056
|
const byId = new Map(orphans.map((o) => [o.id, o]));
|
|
21971
22057
|
const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
|
|
@@ -22021,9 +22107,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
22021
22107
|
if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
|
|
22022
22108
|
decodePng(buf);
|
|
22023
22109
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
22024
|
-
const rel =
|
|
22025
|
-
const outFile =
|
|
22026
|
-
await (0, import_promises34.mkdir)(
|
|
22110
|
+
const rel = import_node_path43.default.join("_salvaged", `${assetId}.png`);
|
|
22111
|
+
const outFile = import_node_path43.default.resolve(ctx.importDir, rel);
|
|
22112
|
+
await (0, import_promises34.mkdir)(import_node_path43.default.dirname(outFile), { recursive: true });
|
|
22027
22113
|
await (0, import_promises34.writeFile)(outFile, buf);
|
|
22028
22114
|
ctx.manifest.assets[assetId] = {
|
|
22029
22115
|
prompt: orphan.prompt,
|
|
@@ -22056,7 +22142,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
22056
22142
|
sourceUrl: durableSource,
|
|
22057
22143
|
sourceUrls: durableSource ? [{ url: durableSource }] : [],
|
|
22058
22144
|
outputs: [{
|
|
22059
|
-
path: portableOutputPath(outFile,
|
|
22145
|
+
path: portableOutputPath(outFile, import_node_path43.default.dirname(ctx.manifestPath)),
|
|
22060
22146
|
sha256: sha256(buf)
|
|
22061
22147
|
}],
|
|
22062
22148
|
submittedAt: orphan.createdAt,
|
|
@@ -22235,6 +22321,7 @@ async function workspaceStatus(ws, dir) {
|
|
|
22235
22321
|
InheritedStyleSchema,
|
|
22236
22322
|
LockEntrySchema,
|
|
22237
22323
|
LockHistoryEntrySchema,
|
|
22324
|
+
LockOriginSchema,
|
|
22238
22325
|
LockSchema,
|
|
22239
22326
|
LockTerrainSettingsSchema,
|
|
22240
22327
|
MAX_DOWNLOAD_BYTES,
|