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/cli.js
CHANGED
|
@@ -104,6 +104,12 @@ var VALUE_FLAGS = [
|
|
|
104
104
|
"--note",
|
|
105
105
|
"--source",
|
|
106
106
|
"--object-id",
|
|
107
|
+
"--tool",
|
|
108
|
+
"--prompt",
|
|
109
|
+
"--seed",
|
|
110
|
+
"--cost",
|
|
111
|
+
"--step",
|
|
112
|
+
"--raw",
|
|
107
113
|
"--model-root",
|
|
108
114
|
"--generation",
|
|
109
115
|
"--quantize",
|
|
@@ -424,6 +430,13 @@ function parseArgs(argv) {
|
|
|
424
430
|
strict: rest.includes("--strict"),
|
|
425
431
|
source: get("--source"),
|
|
426
432
|
objectId: get("--object-id"),
|
|
433
|
+
tool: get("--tool"),
|
|
434
|
+
importPrompt: get("--prompt"),
|
|
435
|
+
seed: numberOption("--seed", { min: 0, integer: true }),
|
|
436
|
+
importCost: numberOption("--cost", { min: 0 }),
|
|
437
|
+
// Steps are free text that may contain commas, so they are not split.
|
|
438
|
+
steps: rest.flatMap((token, i) => token === "--step" && rest[i + 1] ? [rest[i + 1].trim()] : []).filter(Boolean),
|
|
439
|
+
raw: get("--raw"),
|
|
427
440
|
from: get("--from"),
|
|
428
441
|
out: get("--out"),
|
|
429
442
|
generator: get("--generator"),
|
|
@@ -491,7 +504,8 @@ Commands
|
|
|
491
504
|
--generation <n|hash> brings a previous generation back instead.
|
|
492
505
|
history List the generations each asset has replaced and can restore.
|
|
493
506
|
adopt Match existing account objects to files already in the repo.
|
|
494
|
-
--local records them offline (no key): --source, --note, --object-id, --
|
|
507
|
+
--local records them offline (no key): --source, --note, --object-id, --tool,
|
|
508
|
+
--prompt, --seed, --cost, --step (repeatable), --raw, --dry-run.
|
|
495
509
|
hash Print each asset's spec hash, file hash and would-be lock entry (offline).
|
|
496
510
|
accept Keep existing art after a style reword. Re-baseline, do not regenerate.
|
|
497
511
|
salvage Triage account objects no lockfile claims. Recovers usable art.
|
|
@@ -1135,10 +1149,10 @@ function normalizeHex(value) {
|
|
|
1135
1149
|
function sha256(data) {
|
|
1136
1150
|
return createHash("sha256").update(data).digest("hex");
|
|
1137
1151
|
}
|
|
1138
|
-
async function sha256File(
|
|
1152
|
+
async function sha256File(path57) {
|
|
1139
1153
|
return new Promise((resolve, reject) => {
|
|
1140
1154
|
const hash = createHash("sha256");
|
|
1141
|
-
const stream = createReadStream(
|
|
1155
|
+
const stream = createReadStream(path57);
|
|
1142
1156
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
1143
1157
|
stream.on("error", reject);
|
|
1144
1158
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -2481,7 +2495,7 @@ var AssetDeriveSchema = z.object({
|
|
|
2481
2495
|
/** scale: `nearest` (default) keeps hard edges; `box` averages the covered pixels. */
|
|
2482
2496
|
mode: z.enum(["nearest", "box"]).optional()
|
|
2483
2497
|
}).strict().superRefine((derive, context) => {
|
|
2484
|
-
const issue = (message6,
|
|
2498
|
+
const issue = (message6, path57) => context.addIssue({ code: z.ZodIssueCode.custom, message: message6, path: [path57] });
|
|
2485
2499
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
2486
2500
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
2487
2501
|
}
|
|
@@ -2782,6 +2796,18 @@ var PostprocessSchema = z.object({
|
|
|
2782
2796
|
distance: z.literal("redmean")
|
|
2783
2797
|
}).optional()
|
|
2784
2798
|
});
|
|
2799
|
+
var LockOriginSchema = z.object({
|
|
2800
|
+
tool: z.string().min(1).optional(),
|
|
2801
|
+
prompt: z.string().optional(),
|
|
2802
|
+
seed: z.number().int().optional(),
|
|
2803
|
+
steps: z.array(z.string().min(1)).optional(),
|
|
2804
|
+
raw: z.object({ sha256: z.string().regex(/^[0-9a-f]{64}$/) }).optional()
|
|
2805
|
+
});
|
|
2806
|
+
var LockImportedSchema = z.object({
|
|
2807
|
+
source: z.string().min(1),
|
|
2808
|
+
note: z.string().optional(),
|
|
2809
|
+
importedAt: z.string()
|
|
2810
|
+
}).strict();
|
|
2785
2811
|
var LockSourceSchema = z.object({
|
|
2786
2812
|
url: z.string(),
|
|
2787
2813
|
role: z.string().optional(),
|
|
@@ -2832,6 +2858,9 @@ var LockHistoryEntrySchema = z.object({
|
|
|
2832
2858
|
motionShare: LockMotionShareSchema.optional(),
|
|
2833
2859
|
/** A terrain set's settings outside specHash; see LockEntrySchema.terrainSettings. */
|
|
2834
2860
|
terrainSettings: LockTerrainSettingsSchema.optional(),
|
|
2861
|
+
/** Imported art keeps its provenance when it is replaced and when it comes back. */
|
|
2862
|
+
imported: LockImportedSchema.optional(),
|
|
2863
|
+
origin: LockOriginSchema.optional(),
|
|
2835
2864
|
/** When the replacement was submitted. */
|
|
2836
2865
|
retiredAt: z.string()
|
|
2837
2866
|
});
|
|
@@ -3004,11 +3033,9 @@ var LockEntrySchema = z.object({
|
|
|
3004
3033
|
* hand edit, another tool) and brought in with `adopt --local`: nothing was
|
|
3005
3034
|
* submitted, so jobId and cost are empty. Absent on generated entries.
|
|
3006
3035
|
*/
|
|
3007
|
-
imported:
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
importedAt: z.string()
|
|
3011
|
-
}).strict().optional(),
|
|
3036
|
+
imported: LockImportedSchema.optional(),
|
|
3037
|
+
/** More on imported art: tool, prompt, seed, post-process steps, raw original. See LockOriginSchema. */
|
|
3038
|
+
origin: LockOriginSchema.optional(),
|
|
3012
3039
|
/**
|
|
3013
3040
|
* For a derived asset: what it was made from, and a hash of that input when
|
|
3014
3041
|
* this was made. Compared with the input's current bytes by the plan, so a
|
|
@@ -5331,6 +5358,15 @@ async function anyOutputModified(entry, spec) {
|
|
|
5331
5358
|
}
|
|
5332
5359
|
return false;
|
|
5333
5360
|
}
|
|
5361
|
+
async function modifiedReason(entry, spec) {
|
|
5362
|
+
if (!entry.imported) return "output modified since download";
|
|
5363
|
+
const raw = entry.origin?.raw?.sha256;
|
|
5364
|
+
if (raw && existsSync7(currentEntryOutputPath(entry, spec, 0)) && await sha256File(currentEntryOutputPath(entry, spec, 0)) === raw) {
|
|
5365
|
+
const steps = entry.origin?.steps?.length ? ` (${entry.origin.steps.join("; ")})` : "";
|
|
5366
|
+
return `file is the unprocessed original; apply the recorded post-processing again${steps}, or run adopt --local --force to record it as it is`;
|
|
5367
|
+
}
|
|
5368
|
+
return "file changed since it was imported; run adopt --local --force to record the new version";
|
|
5369
|
+
}
|
|
5334
5370
|
function dependencies(spec) {
|
|
5335
5371
|
return [
|
|
5336
5372
|
spec.mirror?.sourceSpec,
|
|
@@ -5484,7 +5520,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
5484
5520
|
reason = entry.outputs.length === 0 ? "no recorded output files" : `missing on disk: ${entry.outputs.filter((_output, index) => !existsSync7(currentEntryOutputPath(entry, spec, index))).map((o) => o.role ?? "asset").join(", ")}`;
|
|
5485
5521
|
} else if (await anyOutputModified(entry, spec)) {
|
|
5486
5522
|
state = "orphaned";
|
|
5487
|
-
reason =
|
|
5523
|
+
reason = await modifiedReason(entry, spec);
|
|
5488
5524
|
} else if (spec.derive) {
|
|
5489
5525
|
state = "ok";
|
|
5490
5526
|
reason = "up to date";
|
|
@@ -5703,8 +5739,8 @@ async function confirm(question, auto) {
|
|
|
5703
5739
|
}
|
|
5704
5740
|
|
|
5705
5741
|
// src/cli/commands/account.ts
|
|
5706
|
-
import
|
|
5707
|
-
import { existsSync as
|
|
5742
|
+
import path29 from "path";
|
|
5743
|
+
import { existsSync as existsSync23 } from "fs";
|
|
5708
5744
|
|
|
5709
5745
|
// src/env.ts
|
|
5710
5746
|
import { readFileSync, existsSync as existsSync8 } from "fs";
|
|
@@ -7168,9 +7204,9 @@ var PixelLabClient = class {
|
|
|
7168
7204
|
apiKey;
|
|
7169
7205
|
http;
|
|
7170
7206
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
7171
|
-
async request(
|
|
7207
|
+
async request(path57, init) {
|
|
7172
7208
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
7173
|
-
const res = await this.http(`${BASE}${
|
|
7209
|
+
const res = await this.http(`${BASE}${path57}`, {
|
|
7174
7210
|
...init,
|
|
7175
7211
|
headers: {
|
|
7176
7212
|
Authorization: auth,
|
|
@@ -7181,13 +7217,13 @@ var PixelLabClient = class {
|
|
|
7181
7217
|
const text = await res.text();
|
|
7182
7218
|
if (!res.ok) {
|
|
7183
7219
|
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' : "";
|
|
7184
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
7220
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path57} \u2192 ${res.status}${hint}`, res.status, text);
|
|
7185
7221
|
}
|
|
7186
7222
|
if (!text) return {};
|
|
7187
7223
|
try {
|
|
7188
7224
|
return JSON.parse(text);
|
|
7189
7225
|
} catch {
|
|
7190
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
7226
|
+
throw new Error(`${init?.method ?? "GET"} ${path57} returned invalid JSON`);
|
|
7191
7227
|
}
|
|
7192
7228
|
}
|
|
7193
7229
|
async balance() {
|
|
@@ -7640,10 +7676,10 @@ var PixelLabClient = class {
|
|
|
7640
7676
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
7641
7677
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
7642
7678
|
const south = args.reference?.south;
|
|
7643
|
-
let
|
|
7679
|
+
let path57;
|
|
7644
7680
|
let body;
|
|
7645
7681
|
if (args.mode === "v3") {
|
|
7646
|
-
|
|
7682
|
+
path57 = "/create-character-v3";
|
|
7647
7683
|
body = {
|
|
7648
7684
|
description: args.description,
|
|
7649
7685
|
image_size: imageSize,
|
|
@@ -7657,7 +7693,7 @@ var PixelLabClient = class {
|
|
|
7657
7693
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
7658
7694
|
};
|
|
7659
7695
|
} else if (args.mode === "pro-flash") {
|
|
7660
|
-
|
|
7696
|
+
path57 = "/create-character-pro-flash";
|
|
7661
7697
|
const traits = args.styleTraits;
|
|
7662
7698
|
body = {
|
|
7663
7699
|
description: args.description,
|
|
@@ -7681,7 +7717,7 @@ var PixelLabClient = class {
|
|
|
7681
7717
|
} : {}
|
|
7682
7718
|
};
|
|
7683
7719
|
} else if (args.mode === "pro") {
|
|
7684
|
-
|
|
7720
|
+
path57 = "/create-character-pro";
|
|
7685
7721
|
body = {
|
|
7686
7722
|
description: args.description,
|
|
7687
7723
|
image_size: imageSize,
|
|
@@ -7695,7 +7731,7 @@ var PixelLabClient = class {
|
|
|
7695
7731
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
7696
7732
|
};
|
|
7697
7733
|
} else {
|
|
7698
|
-
|
|
7734
|
+
path57 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
7699
7735
|
body = {
|
|
7700
7736
|
description: args.description,
|
|
7701
7737
|
image_size: imageSize,
|
|
@@ -7713,8 +7749,8 @@ var PixelLabClient = class {
|
|
|
7713
7749
|
};
|
|
7714
7750
|
}
|
|
7715
7751
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
7716
|
-
const raw = await this.request(
|
|
7717
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
7752
|
+
const raw = await this.request(path57, { method: "POST", body: JSON.stringify(body) });
|
|
7753
|
+
return validateResponse(CharacterSubmitSchema, raw, path57.slice(1));
|
|
7718
7754
|
}
|
|
7719
7755
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
7720
7756
|
async createCharacterState(args) {
|
|
@@ -12137,9 +12173,9 @@ var RetroDiffusionClient = class {
|
|
|
12137
12173
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
12138
12174
|
return Buffer.from(await response.arrayBuffer());
|
|
12139
12175
|
}
|
|
12140
|
-
async call(
|
|
12176
|
+
async call(path57, init = {}) {
|
|
12141
12177
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
12142
|
-
const response = await this.request(`${this.baseUrl}${
|
|
12178
|
+
const response = await this.request(`${this.baseUrl}${path57}`, {
|
|
12143
12179
|
...init,
|
|
12144
12180
|
headers: {
|
|
12145
12181
|
"Content-Type": "application/json",
|
|
@@ -14907,17 +14943,186 @@ async function pushTags(provider, specs, lock, opts = {}) {
|
|
|
14907
14943
|
}
|
|
14908
14944
|
|
|
14909
14945
|
// src/pipeline/import.ts
|
|
14910
|
-
import { existsSync as
|
|
14946
|
+
import { existsSync as existsSync16 } from "fs";
|
|
14911
14947
|
import { readFile as readFile11 } from "fs/promises";
|
|
14948
|
+
import path21 from "path";
|
|
14949
|
+
|
|
14950
|
+
// src/pipeline/history.ts
|
|
14951
|
+
import { existsSync as existsSync15 } from "fs";
|
|
14952
|
+
import path20 from "path";
|
|
14953
|
+
var HISTORY_ENV = "PIXELKILN_HISTORY";
|
|
14954
|
+
function historyLimit(manifest, env = process.env) {
|
|
14955
|
+
if (manifest?.history !== void 0) return manifest.history;
|
|
14956
|
+
const raw = env[HISTORY_ENV]?.trim();
|
|
14957
|
+
if (raw === void 0 || raw === "") return DEFAULT_HISTORY_LIMIT;
|
|
14958
|
+
const value = Number(raw);
|
|
14959
|
+
if (!Number.isInteger(value) || value < 0 || value > 100) {
|
|
14960
|
+
throw new Error(`${HISTORY_ENV} must be a whole number from 0 to 100, got "${raw}"`);
|
|
14961
|
+
}
|
|
14962
|
+
return value;
|
|
14963
|
+
}
|
|
14964
|
+
function retireGeneration(entry, retiredAt) {
|
|
14965
|
+
return {
|
|
14966
|
+
specHash: entry.specHash,
|
|
14967
|
+
generator: entry.generator,
|
|
14968
|
+
tileFeature: entry.tileFeature,
|
|
14969
|
+
prompt: entry.prompt,
|
|
14970
|
+
width: entry.width,
|
|
14971
|
+
height: entry.height,
|
|
14972
|
+
jobId: entry.jobId,
|
|
14973
|
+
objectId: entry.objectId,
|
|
14974
|
+
candidateIndex: entry.candidateIndex,
|
|
14975
|
+
sourceUrl: entry.sourceUrl,
|
|
14976
|
+
sourceUrls: entry.sourceUrls,
|
|
14977
|
+
outputs: entry.outputs,
|
|
14978
|
+
providerMetadata: entry.providerMetadata,
|
|
14979
|
+
submittedAt: entry.submittedAt,
|
|
14980
|
+
downloadedAt: entry.downloadedAt,
|
|
14981
|
+
cost: entry.cost,
|
|
14982
|
+
costUnit: entry.costUnit,
|
|
14983
|
+
billed: entry.billed,
|
|
14984
|
+
provider: entry.provider,
|
|
14985
|
+
postprocess: entry.postprocess,
|
|
14986
|
+
...entry.terrainConnect ? { terrainConnect: entry.terrainConnect } : {},
|
|
14987
|
+
...entry.motionShare ? { motionShare: entry.motionShare } : {},
|
|
14988
|
+
...entry.terrainSettings ? { terrainSettings: entry.terrainSettings } : {},
|
|
14989
|
+
...entry.imported ? { imported: entry.imported } : {},
|
|
14990
|
+
...entry.origin ? { origin: entry.origin } : {},
|
|
14991
|
+
retiredAt
|
|
14992
|
+
};
|
|
14993
|
+
}
|
|
14994
|
+
function historyAfterReplacing(previous, limit, retiredAt) {
|
|
14995
|
+
if (!previous) return void 0;
|
|
14996
|
+
const kept = previous.history ?? [];
|
|
14997
|
+
const outgoing = previous.status === "downloaded" && previous.outputs.length ? [retireGeneration(previous, retiredAt)] : [];
|
|
14998
|
+
const history = [...outgoing, ...kept].slice(0, limit);
|
|
14999
|
+
return history.length ? history : void 0;
|
|
15000
|
+
}
|
|
15001
|
+
function referencedHashes(lock) {
|
|
15002
|
+
const hashes = /* @__PURE__ */ new Set();
|
|
15003
|
+
const add = (output) => {
|
|
15004
|
+
hashes.add(output.sha256);
|
|
15005
|
+
if (output.raw) hashes.add(output.raw);
|
|
15006
|
+
};
|
|
15007
|
+
for (const entry of Object.values(lock.entries)) {
|
|
15008
|
+
for (const output of entry.outputs) add(output);
|
|
15009
|
+
for (const generation of entry.history ?? []) for (const output of generation.outputs) add(output);
|
|
15010
|
+
}
|
|
15011
|
+
return hashes;
|
|
15012
|
+
}
|
|
15013
|
+
function pickHistory(entry, selector) {
|
|
15014
|
+
const history = entry.history ?? [];
|
|
15015
|
+
if (!history.length) throw new Error(`${entry.styleId}/${entry.assetId} has no previous generations recorded`);
|
|
15016
|
+
if (typeof selector === "number" || /^\d{1,3}$/.test(selector)) {
|
|
15017
|
+
const index = Number(selector);
|
|
15018
|
+
const generation = history[index - 1];
|
|
15019
|
+
if (!generation) throw new Error(`${entry.styleId}/${entry.assetId} keeps ${history.length} previous generation(s); there is no #${index}`);
|
|
15020
|
+
return { index, generation };
|
|
15021
|
+
}
|
|
15022
|
+
const prefix = selector.toLowerCase();
|
|
15023
|
+
const matches = history.map((generation, i) => ({ index: i + 1, generation })).filter(({ generation }) => generation.outputs.some((output) => output.sha256.startsWith(prefix)));
|
|
15024
|
+
if (matches.length !== 1) {
|
|
15025
|
+
throw new Error(
|
|
15026
|
+
matches.length ? `"${selector}" matches ${matches.length} previous generations of ${entry.styleId}/${entry.assetId}; give more of the hash` : `no previous generation of ${entry.styleId}/${entry.assetId} has an output hash starting with "${selector}"`
|
|
15027
|
+
);
|
|
15028
|
+
}
|
|
15029
|
+
return matches[0];
|
|
15030
|
+
}
|
|
15031
|
+
async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
15032
|
+
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
15033
|
+
const entry = lock.entries[key2];
|
|
15034
|
+
if (!entry) throw new Error(`${key2} is not in the lockfile`);
|
|
15035
|
+
if (entry.status !== "downloaded") {
|
|
15036
|
+
throw new Error(`${key2} is ${entry.status}; finish or fetch the current generation before restoring an older one`);
|
|
15037
|
+
}
|
|
15038
|
+
const { index, generation } = pickHistory(entry, opts.generation);
|
|
15039
|
+
if (generation.provider !== provider.id) {
|
|
15040
|
+
throw new Error(`${key2}'s previous generation #${index} came from ${generation.provider}, not ${provider.id}`);
|
|
15041
|
+
}
|
|
15042
|
+
for (let i = 0; i < entry.outputs.length; i++) {
|
|
15043
|
+
const file = currentEntryOutputPath(entry, spec, i);
|
|
15044
|
+
if (!existsSync15(file)) continue;
|
|
15045
|
+
if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
|
|
15046
|
+
throw new OverwriteRefusedError(
|
|
15047
|
+
`${path20.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
|
|
15048
|
+
[file]
|
|
15049
|
+
);
|
|
15050
|
+
}
|
|
15051
|
+
}
|
|
15052
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
15053
|
+
const remaining = (entry.history ?? []).filter((_, i) => i !== index - 1);
|
|
15054
|
+
const history = [retireGeneration(entry, now), ...remaining];
|
|
15055
|
+
upsert(lock, key2, {
|
|
15056
|
+
specHash: generation.specHash,
|
|
15057
|
+
generator: generation.generator,
|
|
15058
|
+
tileFeature: generation.tileFeature,
|
|
15059
|
+
prompt: generation.prompt,
|
|
15060
|
+
width: generation.width,
|
|
15061
|
+
height: generation.height,
|
|
15062
|
+
jobId: generation.jobId,
|
|
15063
|
+
objectId: generation.objectId,
|
|
15064
|
+
candidateIndex: generation.candidateIndex,
|
|
15065
|
+
reviewObjectId: null,
|
|
15066
|
+
status: "downloaded",
|
|
15067
|
+
error: null,
|
|
15068
|
+
sourceUrl: generation.sourceUrl,
|
|
15069
|
+
sourceUrls: generation.sourceUrls,
|
|
15070
|
+
outputs: generation.outputs,
|
|
15071
|
+
// The files on disk are the outgoing generation's; that record authorizes
|
|
15072
|
+
// replacing them without --force, exactly as after a regeneration.
|
|
15073
|
+
supersededOutputs: entry.outputs,
|
|
15074
|
+
providerMetadata: generation.providerMetadata,
|
|
15075
|
+
submittedAt: generation.submittedAt,
|
|
15076
|
+
downloadedAt: generation.downloadedAt,
|
|
15077
|
+
cost: generation.cost,
|
|
15078
|
+
costUnit: generation.costUnit,
|
|
15079
|
+
billed: generation.billed,
|
|
15080
|
+
provider: generation.provider,
|
|
15081
|
+
postprocess: generation.postprocess,
|
|
15082
|
+
// A connected set comes back with the connection it was drawn from, so
|
|
15083
|
+
// the plan compares the restored generation, not the one it replaced.
|
|
15084
|
+
terrainConnect: generation.terrainConnect,
|
|
15085
|
+
// Likewise a loop that shared another direction's motion.
|
|
15086
|
+
motionShare: generation.motionShare,
|
|
15087
|
+
// Likewise its settings; a generation from before they were recorded
|
|
15088
|
+
// comes back with none and is taken as current.
|
|
15089
|
+
terrainSettings: generation.terrainSettings,
|
|
15090
|
+
// Imported art comes back as imported, with its provenance; a generated
|
|
15091
|
+
// one clears both, so the plan does not call it imported.
|
|
15092
|
+
imported: generation.imported,
|
|
15093
|
+
origin: generation.origin,
|
|
15094
|
+
history
|
|
15095
|
+
});
|
|
15096
|
+
await saveLock(lockPath, lock);
|
|
15097
|
+
const result = await fetchAssets(provider, [spec], lock, lockPath, {
|
|
15098
|
+
onProgress: opts.onProgress,
|
|
15099
|
+
repair: true,
|
|
15100
|
+
force: opts.force,
|
|
15101
|
+
cacheDir: opts.cacheDir
|
|
15102
|
+
});
|
|
15103
|
+
if (result.failed) {
|
|
15104
|
+
throw new Error(`the previous generation's bytes could not be written back; run pixelkiln restore --only ${spec.assetId} --style ${spec.styleId} once the provider is reachable`);
|
|
15105
|
+
}
|
|
15106
|
+
return { restored: generation, index, downloaded: result.downloaded };
|
|
15107
|
+
}
|
|
15108
|
+
|
|
15109
|
+
// src/pipeline/import.ts
|
|
14912
15110
|
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
14913
15111
|
const png = decodePng(bytes);
|
|
14914
15112
|
const at = now.toISOString();
|
|
15113
|
+
const origin = {
|
|
15114
|
+
...opts.tool ? { tool: opts.tool } : {},
|
|
15115
|
+
...opts.prompt ? { prompt: opts.prompt } : {},
|
|
15116
|
+
...opts.seed !== void 0 ? { seed: opts.seed } : {},
|
|
15117
|
+
...opts.steps?.length ? { steps: opts.steps } : {},
|
|
15118
|
+
...opts.rawSha256 ? { raw: { sha256: opts.rawSha256 } } : {}
|
|
15119
|
+
};
|
|
14915
15120
|
return {
|
|
14916
15121
|
styleId: spec.styleId,
|
|
14917
15122
|
assetId: spec.assetId,
|
|
14918
15123
|
specHash: spec.specHash,
|
|
14919
15124
|
generator: spec.generator,
|
|
14920
|
-
prompt: spec.prompt,
|
|
15125
|
+
prompt: opts.prompt ?? spec.prompt,
|
|
14921
15126
|
width: png.width,
|
|
14922
15127
|
height: png.height,
|
|
14923
15128
|
jobId: opts.objectId ?? null,
|
|
@@ -14931,9 +15136,10 @@ function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Da
|
|
|
14931
15136
|
outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
|
|
14932
15137
|
submittedAt: null,
|
|
14933
15138
|
downloadedAt: at,
|
|
14934
|
-
cost: 0,
|
|
15139
|
+
cost: opts.cost ?? 0,
|
|
14935
15140
|
costUnit: spec.costUnit,
|
|
14936
15141
|
provider: spec.provider,
|
|
15142
|
+
...Object.keys(origin).length ? { origin } : {},
|
|
14937
15143
|
...spec.external ? { external: { builder: spec.external.builder, inputs: spec.external.inputs } } : {},
|
|
14938
15144
|
imported: {
|
|
14939
15145
|
source: opts.source ?? "external",
|
|
@@ -14952,6 +15158,19 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
14952
15158
|
if (opts.objectId && specs.length !== 1) {
|
|
14953
15159
|
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
14954
15160
|
}
|
|
15161
|
+
const cacheDir = opts.cacheDir === false ? null : path21.resolve(opts.cacheDir ?? path21.join(path21.dirname(lockPath), ".pixelkiln", "cache"));
|
|
15162
|
+
let rawSha256;
|
|
15163
|
+
let rawBytes;
|
|
15164
|
+
if (opts.raw) {
|
|
15165
|
+
if (specs.length !== 1) throw new Error(`--raw names one original; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
15166
|
+
try {
|
|
15167
|
+
rawBytes = await readFile11(opts.raw);
|
|
15168
|
+
decodePng(rawBytes);
|
|
15169
|
+
} catch (error) {
|
|
15170
|
+
throw new Error(`--raw ${opts.raw} is not a readable PNG: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
15171
|
+
}
|
|
15172
|
+
rawSha256 = sha256(rawBytes);
|
|
15173
|
+
}
|
|
14955
15174
|
const imported = [];
|
|
14956
15175
|
const skipped = [];
|
|
14957
15176
|
for (const spec of specs) {
|
|
@@ -14961,7 +15180,7 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
14961
15180
|
skipped.push({ key: key2, reason });
|
|
14962
15181
|
continue;
|
|
14963
15182
|
}
|
|
14964
|
-
if (!
|
|
15183
|
+
if (!existsSync16(spec.outFile)) {
|
|
14965
15184
|
skipped.push({ key: key2, reason: `no file at ${spec.outFile}` });
|
|
14966
15185
|
continue;
|
|
14967
15186
|
}
|
|
@@ -14970,8 +15189,10 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
14970
15189
|
continue;
|
|
14971
15190
|
}
|
|
14972
15191
|
let patch;
|
|
15192
|
+
let bytes;
|
|
14973
15193
|
try {
|
|
14974
|
-
|
|
15194
|
+
bytes = await readFile11(spec.outFile);
|
|
15195
|
+
patch = buildImportedEntry(spec, bytes, { ...opts, rawSha256 }, /* @__PURE__ */ new Date());
|
|
14975
15196
|
} catch (error) {
|
|
14976
15197
|
skipped.push({ key: key2, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
14977
15198
|
continue;
|
|
@@ -14980,7 +15201,19 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
14980
15201
|
imported.push({ key: key2, entry: patch });
|
|
14981
15202
|
continue;
|
|
14982
15203
|
}
|
|
14983
|
-
|
|
15204
|
+
const existing = lock.entries[key2];
|
|
15205
|
+
const history = existing?.outputs[0]?.sha256 === sha256(bytes) ? existing.history : historyAfterReplacing(existing, opts.historyLimit ?? DEFAULT_HISTORY_LIMIT, patch.downloadedAt ?? (/* @__PURE__ */ new Date()).toISOString());
|
|
15206
|
+
if (cacheDir) {
|
|
15207
|
+
await cacheMedia(cacheDir, bytes, MediaType.PNG);
|
|
15208
|
+
if (rawBytes) await cacheMedia(cacheDir, rawBytes, MediaType.PNG);
|
|
15209
|
+
}
|
|
15210
|
+
imported.push({ key: key2, entry: upsert(lock, key2, {
|
|
15211
|
+
...patch,
|
|
15212
|
+
// An import replaces the whole record: clear what the entry held that
|
|
15213
|
+
// an import never has, or a regenerated entry would keep stale links.
|
|
15214
|
+
origin: patch.origin,
|
|
15215
|
+
history
|
|
15216
|
+
}) });
|
|
14984
15217
|
}
|
|
14985
15218
|
if (!opts.dryRun && imported.length) await saveLock(lockPath, lock);
|
|
14986
15219
|
return { imported, skipped };
|
|
@@ -14990,7 +15223,7 @@ async function reportSpecHashes(specs, lock) {
|
|
|
14990
15223
|
for (const spec of specs) {
|
|
14991
15224
|
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
14992
15225
|
let bytes = null;
|
|
14993
|
-
if (
|
|
15226
|
+
if (existsSync16(spec.outFile)) bytes = await readFile11(spec.outFile);
|
|
14994
15227
|
let wouldImport = null;
|
|
14995
15228
|
if (bytes && !unimportable(spec)) {
|
|
14996
15229
|
try {
|
|
@@ -15019,13 +15252,13 @@ async function reportSpecHashes(specs, lock) {
|
|
|
15019
15252
|
}
|
|
15020
15253
|
|
|
15021
15254
|
// src/pipeline/adopt.ts
|
|
15022
|
-
import { existsSync as
|
|
15255
|
+
import { existsSync as existsSync18 } from "fs";
|
|
15023
15256
|
import { readFile as readFile13, writeFile as writeFile9 } from "fs/promises";
|
|
15024
|
-
import
|
|
15257
|
+
import path22 from "path";
|
|
15025
15258
|
|
|
15026
15259
|
// src/cache.ts
|
|
15027
15260
|
import { mkdir as mkdir8, readFile as readFile12, rename as rename6, rm as rm5, writeFile as writeFile8 } from "fs/promises";
|
|
15028
|
-
import { existsSync as
|
|
15261
|
+
import { existsSync as existsSync17 } from "fs";
|
|
15029
15262
|
import pathModule from "path";
|
|
15030
15263
|
import { z as z4 } from "zod";
|
|
15031
15264
|
var HashCacheSchema = z4.object({
|
|
@@ -15040,10 +15273,10 @@ function isSha256Hash(value) {
|
|
|
15040
15273
|
function parseCache(value) {
|
|
15041
15274
|
return HashCacheSchema.parse(value);
|
|
15042
15275
|
}
|
|
15043
|
-
async function loadCache(
|
|
15044
|
-
if (!
|
|
15276
|
+
async function loadCache(path57) {
|
|
15277
|
+
if (!existsSync17(path57)) return { version: 1, hashes: {} };
|
|
15045
15278
|
try {
|
|
15046
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile12(
|
|
15279
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile12(path57, "utf8")));
|
|
15047
15280
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
15048
15281
|
return {
|
|
15049
15282
|
version: 1,
|
|
@@ -15055,18 +15288,18 @@ async function loadCache(path56) {
|
|
|
15055
15288
|
return { version: 1, hashes: {} };
|
|
15056
15289
|
}
|
|
15057
15290
|
}
|
|
15058
|
-
async function saveCache(
|
|
15291
|
+
async function saveCache(path57, cache) {
|
|
15059
15292
|
const sorted = {};
|
|
15060
15293
|
for (const key2 of Object.keys(cache.hashes).sort()) {
|
|
15061
15294
|
const hash = cache.hashes[key2];
|
|
15062
15295
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key2}`);
|
|
15063
15296
|
sorted[key2] = hash;
|
|
15064
15297
|
}
|
|
15065
|
-
await mkdir8(pathModule.dirname(pathModule.resolve(
|
|
15066
|
-
const tmp = `${
|
|
15298
|
+
await mkdir8(pathModule.dirname(pathModule.resolve(path57)), { recursive: true });
|
|
15299
|
+
const tmp = `${path57}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
15067
15300
|
try {
|
|
15068
15301
|
await writeFile8(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
15069
|
-
await rename6(tmp,
|
|
15302
|
+
await rename6(tmp, path57);
|
|
15070
15303
|
} finally {
|
|
15071
15304
|
await rm5(tmp, { force: true });
|
|
15072
15305
|
}
|
|
@@ -15100,7 +15333,7 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
15100
15333
|
const localByHash = /* @__PURE__ */ new Map();
|
|
15101
15334
|
const unmatchedLocal = [];
|
|
15102
15335
|
for (const spec of specs) {
|
|
15103
|
-
if (!
|
|
15336
|
+
if (!existsSync18(spec.outFile)) {
|
|
15104
15337
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
15105
15338
|
continue;
|
|
15106
15339
|
}
|
|
@@ -15257,9 +15490,9 @@ function formatUnmatchedRemote(objects, limit = 15) {
|
|
|
15257
15490
|
}
|
|
15258
15491
|
|
|
15259
15492
|
// src/pipeline/adopt-characters.ts
|
|
15260
|
-
import { existsSync as
|
|
15493
|
+
import { existsSync as existsSync19 } from "fs";
|
|
15261
15494
|
import { mkdir as mkdir9, readFile as readFile14, writeFile as writeFile10 } from "fs/promises";
|
|
15262
|
-
import
|
|
15495
|
+
import path23 from "path";
|
|
15263
15496
|
async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
15264
15497
|
const log2 = opts.onProgress ?? (() => {
|
|
15265
15498
|
});
|
|
@@ -15310,12 +15543,12 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
15310
15543
|
const bytes = await download(source.url);
|
|
15311
15544
|
const hash = sha256(bytes);
|
|
15312
15545
|
const file = expectedOutputPath(spec, source.role, index, sources.length);
|
|
15313
|
-
if (
|
|
15314
|
-
if (sha256(await readFile14(file)) !== hash) result.differing.push(
|
|
15546
|
+
if (existsSync19(file)) {
|
|
15547
|
+
if (sha256(await readFile14(file)) !== hash) result.differing.push(path23.relative(process.cwd(), file));
|
|
15315
15548
|
} else {
|
|
15316
|
-
await mkdir9(
|
|
15549
|
+
await mkdir9(path23.dirname(file), { recursive: true });
|
|
15317
15550
|
await writeFile10(file, bytes);
|
|
15318
|
-
result.written.push(
|
|
15551
|
+
result.written.push(path23.relative(process.cwd(), file));
|
|
15319
15552
|
}
|
|
15320
15553
|
outputs.push({ path: portableOutputPath(file, spec.root), sha256: hash, ...source.role ? { role: source.role } : {} });
|
|
15321
15554
|
}
|
|
@@ -15353,8 +15586,8 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
15353
15586
|
if (!match) throw new Error(`remoteId ${spec.remoteId} is not a character on this account`);
|
|
15354
15587
|
} else {
|
|
15355
15588
|
const south = expectedOutputPath(spec, "south", 0, spec.character.directions);
|
|
15356
|
-
if (!
|
|
15357
|
-
result.unmatched.push(`${key2}: no remoteId and no ${
|
|
15589
|
+
if (!existsSync19(south)) {
|
|
15590
|
+
result.unmatched.push(`${key2}: no remoteId and no ${path23.relative(process.cwd(), south)} to match by`);
|
|
15358
15591
|
return false;
|
|
15359
15592
|
}
|
|
15360
15593
|
const localHash = sha256(await readFile14(south));
|
|
@@ -15366,7 +15599,7 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
15366
15599
|
}
|
|
15367
15600
|
}
|
|
15368
15601
|
if (!match) {
|
|
15369
|
-
result.unmatched.push(`${key2}: no character's south rotation has the bytes of ${
|
|
15602
|
+
result.unmatched.push(`${key2}: no character's south rotation has the bytes of ${path23.relative(process.cwd(), south)}`);
|
|
15370
15603
|
return false;
|
|
15371
15604
|
}
|
|
15372
15605
|
}
|
|
@@ -15433,10 +15666,10 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
15433
15666
|
if (!match) throw new Error(`remoteId ${spec.remoteId} names no ${animation.direction} animation of character ${parentId}`);
|
|
15434
15667
|
} else {
|
|
15435
15668
|
const first = expectedOutputPath(spec, "frame-00", 0, 2);
|
|
15436
|
-
if (!
|
|
15669
|
+
if (!existsSync19(first)) {
|
|
15437
15670
|
const byName = candidates.find((a) => a.name === characterAnimationName(spec));
|
|
15438
15671
|
if (!byName) {
|
|
15439
|
-
result.unmatched.push(`${key2}: no remoteId and no ${
|
|
15672
|
+
result.unmatched.push(`${key2}: no remoteId and no ${path23.relative(process.cwd(), first)} to match by`);
|
|
15440
15673
|
return false;
|
|
15441
15674
|
}
|
|
15442
15675
|
match = byName;
|
|
@@ -15449,7 +15682,7 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
15449
15682
|
}
|
|
15450
15683
|
}
|
|
15451
15684
|
if (!match) {
|
|
15452
|
-
result.unmatched.push(`${key2}: no ${animation.direction} animation of character ${parentId} starts with the bytes of ${
|
|
15685
|
+
result.unmatched.push(`${key2}: no ${animation.direction} animation of character ${parentId} starts with the bytes of ${path23.relative(process.cwd(), first)}`);
|
|
15453
15686
|
return false;
|
|
15454
15687
|
}
|
|
15455
15688
|
}
|
|
@@ -15510,15 +15743,15 @@ async function adoptCharacters(provider, specs, lock, lockPath, opts) {
|
|
|
15510
15743
|
|
|
15511
15744
|
// src/pipeline/salvage.ts
|
|
15512
15745
|
import { readFile as readFile15 } from "fs/promises";
|
|
15513
|
-
import { existsSync as
|
|
15514
|
-
import
|
|
15746
|
+
import { existsSync as existsSync20 } from "fs";
|
|
15747
|
+
import path24 from "path";
|
|
15515
15748
|
function providerClaimId(provider, objectId) {
|
|
15516
15749
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
15517
15750
|
}
|
|
15518
15751
|
async function loadClaims(lockPaths, opts = {}) {
|
|
15519
15752
|
const claimed = /* @__PURE__ */ new Set();
|
|
15520
15753
|
for (const p of lockPaths) {
|
|
15521
|
-
if (!
|
|
15754
|
+
if (!existsSync20(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
15522
15755
|
let parsed;
|
|
15523
15756
|
try {
|
|
15524
15757
|
parsed = parseLock(JSON.parse(await readFile15(p, "utf8")));
|
|
@@ -15688,20 +15921,20 @@ function matchStyleByPattern(prompt, manifest) {
|
|
|
15688
15921
|
return null;
|
|
15689
15922
|
}
|
|
15690
15923
|
async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
|
|
15691
|
-
const own =
|
|
15924
|
+
const own = path24.resolve(ownManifestPath);
|
|
15692
15925
|
const siblingManifestPaths = [
|
|
15693
15926
|
.../* @__PURE__ */ new Set([
|
|
15694
15927
|
...workspaceManifestPaths,
|
|
15695
|
-
...claimPaths.map((c) =>
|
|
15928
|
+
...claimPaths.map((c) => path24.join(path24.dirname(path24.resolve(c)), "pixelkiln.manifest.json"))
|
|
15696
15929
|
])
|
|
15697
15930
|
];
|
|
15698
15931
|
const siblings = [];
|
|
15699
15932
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
15700
|
-
if (
|
|
15701
|
-
if (!
|
|
15933
|
+
if (path24.resolve(siblingManifestPath) === own) continue;
|
|
15934
|
+
if (!existsSync20(siblingManifestPath)) continue;
|
|
15702
15935
|
try {
|
|
15703
15936
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
15704
|
-
siblings.push({ label:
|
|
15937
|
+
siblings.push({ label: path24.basename(path24.dirname(siblingManifestPath)), manifest });
|
|
15705
15938
|
} catch {
|
|
15706
15939
|
}
|
|
15707
15940
|
}
|
|
@@ -15822,8 +16055,8 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
15822
16055
|
|
|
15823
16056
|
// src/workspace.ts
|
|
15824
16057
|
import { mkdir as mkdir10, readFile as readFile16, rename as rename7, rm as rm6, writeFile as writeFile11 } from "fs/promises";
|
|
15825
|
-
import { existsSync as
|
|
15826
|
-
import
|
|
16058
|
+
import { existsSync as existsSync21 } from "fs";
|
|
16059
|
+
import path25 from "path";
|
|
15827
16060
|
import { z as z5 } from "zod";
|
|
15828
16061
|
var WorkspaceProjectSchema = z5.object({
|
|
15829
16062
|
id: z5.string().min(1),
|
|
@@ -15848,7 +16081,7 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
|
|
|
15848
16081
|
);
|
|
15849
16082
|
}
|
|
15850
16083
|
async function loadWorkspace(workspacePath) {
|
|
15851
|
-
if (!
|
|
16084
|
+
if (!existsSync21(workspacePath)) return { version: 1, projects: [] };
|
|
15852
16085
|
let raw;
|
|
15853
16086
|
try {
|
|
15854
16087
|
raw = JSON.parse(await readFile16(workspacePath, "utf8"));
|
|
@@ -15865,7 +16098,7 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
15865
16098
|
version: 1,
|
|
15866
16099
|
projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
|
|
15867
16100
|
};
|
|
15868
|
-
await mkdir10(
|
|
16101
|
+
await mkdir10(path25.dirname(path25.resolve(workspacePath)), { recursive: true });
|
|
15869
16102
|
const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
15870
16103
|
try {
|
|
15871
16104
|
await writeFile11(tmp, JSON.stringify(sorted, null, 2) + "\n");
|
|
@@ -15875,12 +16108,12 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
15875
16108
|
}
|
|
15876
16109
|
}
|
|
15877
16110
|
function toPortablePath(dir, absolute) {
|
|
15878
|
-
return
|
|
16111
|
+
return path25.relative(dir, absolute).split(path25.sep).join("/");
|
|
15879
16112
|
}
|
|
15880
16113
|
function resolveProject(dir, project) {
|
|
15881
16114
|
return {
|
|
15882
|
-
manifestPath:
|
|
15883
|
-
lockPath:
|
|
16115
|
+
manifestPath: path25.resolve(dir, project.manifest.split("/").join(path25.sep)),
|
|
16116
|
+
lockPath: path25.resolve(dir, project.lock.split("/").join(path25.sep))
|
|
15884
16117
|
};
|
|
15885
16118
|
}
|
|
15886
16119
|
function validateWorkspace(ws, dir) {
|
|
@@ -15893,21 +16126,21 @@ function validateWorkspace(ws, dir) {
|
|
|
15893
16126
|
const { manifestPath, lockPath } = resolveProject(dir, project);
|
|
15894
16127
|
lockOwners.set(lockPath, [...lockOwners.get(lockPath) ?? [], project.id]);
|
|
15895
16128
|
manifestOwners.set(manifestPath, [...manifestOwners.get(manifestPath) ?? [], project.id]);
|
|
15896
|
-
if (
|
|
16129
|
+
if (path25.isAbsolute(project.manifest) || path25.isAbsolute(project.lock)) {
|
|
15897
16130
|
diagnostics.push({
|
|
15898
16131
|
id: "absolute-path",
|
|
15899
16132
|
level: "warning",
|
|
15900
16133
|
message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
|
|
15901
16134
|
});
|
|
15902
16135
|
}
|
|
15903
|
-
if (!
|
|
16136
|
+
if (!existsSync21(manifestPath)) {
|
|
15904
16137
|
diagnostics.push({
|
|
15905
16138
|
id: "missing-manifest",
|
|
15906
16139
|
level: "error",
|
|
15907
16140
|
message: `project "${project.id}" manifest not found: ${manifestPath}`
|
|
15908
16141
|
});
|
|
15909
16142
|
}
|
|
15910
|
-
if (!
|
|
16143
|
+
if (!existsSync21(lockPath)) {
|
|
15911
16144
|
diagnostics.push({
|
|
15912
16145
|
id: "missing-lock",
|
|
15913
16146
|
level: "error",
|
|
@@ -15955,7 +16188,7 @@ function validateWorkspace(ws, dir) {
|
|
|
15955
16188
|
|
|
15956
16189
|
// src/pick/salvage-server.ts
|
|
15957
16190
|
import { mkdir as mkdir11, writeFile as writeFile12, readFile as readFile18 } from "fs/promises";
|
|
15958
|
-
import
|
|
16191
|
+
import path26 from "path";
|
|
15959
16192
|
|
|
15960
16193
|
// src/pick/salvage-sheet.ts
|
|
15961
16194
|
var escapeHtml = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -16220,7 +16453,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
16220
16453
|
});
|
|
16221
16454
|
const html = renderSalvageSheet(orphans, {
|
|
16222
16455
|
styleId: ctx.styleId,
|
|
16223
|
-
importDir:
|
|
16456
|
+
importDir: path26.relative(process.cwd(), ctx.importDir) || "."
|
|
16224
16457
|
});
|
|
16225
16458
|
const byId = new Map(orphans.map((o) => [o.id, o]));
|
|
16226
16459
|
const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
|
|
@@ -16276,9 +16509,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
16276
16509
|
if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
|
|
16277
16510
|
decodePng(buf);
|
|
16278
16511
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
16279
|
-
const rel =
|
|
16280
|
-
const outFile =
|
|
16281
|
-
await mkdir11(
|
|
16512
|
+
const rel = path26.join("_salvaged", `${assetId}.png`);
|
|
16513
|
+
const outFile = path26.resolve(ctx.importDir, rel);
|
|
16514
|
+
await mkdir11(path26.dirname(outFile), { recursive: true });
|
|
16282
16515
|
await writeFile12(outFile, buf);
|
|
16283
16516
|
ctx.manifest.assets[assetId] = {
|
|
16284
16517
|
prompt: orphan.prompt,
|
|
@@ -16311,7 +16544,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
16311
16544
|
sourceUrl: durableSource,
|
|
16312
16545
|
sourceUrls: durableSource ? [{ url: durableSource }] : [],
|
|
16313
16546
|
outputs: [{
|
|
16314
|
-
path: portableOutputPath(outFile,
|
|
16547
|
+
path: portableOutputPath(outFile, path26.dirname(ctx.manifestPath)),
|
|
16315
16548
|
sha256: sha256(buf)
|
|
16316
16549
|
}],
|
|
16317
16550
|
submittedAt: orphan.createdAt,
|
|
@@ -16346,19 +16579,19 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
16346
16579
|
}
|
|
16347
16580
|
|
|
16348
16581
|
// src/cli/project.ts
|
|
16349
|
-
import
|
|
16350
|
-
import { existsSync as
|
|
16582
|
+
import path28 from "path";
|
|
16583
|
+
import { existsSync as existsSync22 } from "fs";
|
|
16351
16584
|
|
|
16352
16585
|
// src/project.ts
|
|
16353
|
-
import
|
|
16586
|
+
import path27 from "path";
|
|
16354
16587
|
async function openProject(manifestPath = "pixelkiln.manifest.json", opts = {}) {
|
|
16355
|
-
const absolute =
|
|
16356
|
-
const root =
|
|
16588
|
+
const absolute = path27.resolve(manifestPath);
|
|
16589
|
+
const root = path27.dirname(absolute);
|
|
16357
16590
|
if (opts.env !== false) {
|
|
16358
16591
|
loadEnvFiles(root);
|
|
16359
|
-
if (
|
|
16592
|
+
if (path27.resolve(process.cwd()) !== root) loadEnvFiles(process.cwd());
|
|
16360
16593
|
}
|
|
16361
|
-
const lockPath =
|
|
16594
|
+
const lockPath = path27.resolve(opts.lockPath ?? path27.join(root, "pixelkiln.lock.json"));
|
|
16362
16595
|
let loaded = await loadManifest(absolute, { lenient: opts.lenient });
|
|
16363
16596
|
const unresolved = [];
|
|
16364
16597
|
const specs = await resolveSpecs(loaded, {
|
|
@@ -16495,11 +16728,11 @@ async function workspaceStatus(ws, dir) {
|
|
|
16495
16728
|
|
|
16496
16729
|
// src/cli/project.ts
|
|
16497
16730
|
async function provenanceFile(id, file) {
|
|
16498
|
-
const absolute =
|
|
16731
|
+
const absolute = path28.resolve(file);
|
|
16499
16732
|
return {
|
|
16500
16733
|
id,
|
|
16501
16734
|
path: absolute,
|
|
16502
|
-
sha256:
|
|
16735
|
+
sha256: existsSync22(absolute) ? await sha256File(absolute) : null,
|
|
16503
16736
|
included: true
|
|
16504
16737
|
};
|
|
16505
16738
|
}
|
|
@@ -16571,10 +16804,10 @@ function budgetsForPlan(plan, args) {
|
|
|
16571
16804
|
return out;
|
|
16572
16805
|
}
|
|
16573
16806
|
async function requireCompleteWorkspaceClaims(workspacePath) {
|
|
16574
|
-
if (!
|
|
16807
|
+
if (!existsSync22(workspacePath)) {
|
|
16575
16808
|
throw new ProjectError(`Workspace catalog not found: ${workspacePath}`);
|
|
16576
16809
|
}
|
|
16577
|
-
const dir =
|
|
16810
|
+
const dir = path28.dirname(path28.resolve(workspacePath));
|
|
16578
16811
|
const ws = await loadWorkspace(workspacePath);
|
|
16579
16812
|
const diagnostics = validateWorkspace(ws, dir);
|
|
16580
16813
|
const errors = diagnostics.filter((d) => d.level === "error");
|
|
@@ -16597,9 +16830,9 @@ async function openAccountProject(args) {
|
|
|
16597
16830
|
return project;
|
|
16598
16831
|
}
|
|
16599
16832
|
async function open(args) {
|
|
16600
|
-
if (!
|
|
16833
|
+
if (!existsSync22(path28.resolve(args.manifest))) {
|
|
16601
16834
|
throw new ProjectError(
|
|
16602
|
-
`No manifest at ${
|
|
16835
|
+
`No manifest at ${path28.resolve(args.manifest)}. Pass --manifest, or run \`pixelkiln init --from <dir>\`.`
|
|
16603
16836
|
);
|
|
16604
16837
|
}
|
|
16605
16838
|
const lenient = (args.command === "plan" || args.command === "hash" || args.command === "doctor") && !args.strict;
|
|
@@ -16642,7 +16875,7 @@ function providerCache(mode2) {
|
|
|
16642
16875
|
|
|
16643
16876
|
// src/cli/commands/account.ts
|
|
16644
16877
|
async function runBalance(args) {
|
|
16645
|
-
loadEnvFiles(
|
|
16878
|
+
loadEnvFiles(path29.dirname(path29.resolve(args.manifest)));
|
|
16646
16879
|
loadEnvFiles(process.cwd());
|
|
16647
16880
|
const loaded = await loadManifest(args.manifest);
|
|
16648
16881
|
const selectedProvider = accountProviderId(loaded.manifest, args.provider, "balance");
|
|
@@ -16656,11 +16889,18 @@ async function runAdoptLocal(args) {
|
|
|
16656
16889
|
if (args.tag || args.writePrompts) {
|
|
16657
16890
|
throw new UsageError("--tag and --write-prompts talk to the account; they cannot be combined with --local.");
|
|
16658
16891
|
}
|
|
16659
|
-
const { specs, lock } = await openProject2(args);
|
|
16892
|
+
const { loaded, specs, lock } = await openProject2(args);
|
|
16660
16893
|
const result = await importLocal(specs, lock, args.lock, {
|
|
16661
16894
|
source: args.source,
|
|
16662
16895
|
note: args.note,
|
|
16663
16896
|
objectId: args.objectId,
|
|
16897
|
+
tool: args.tool,
|
|
16898
|
+
prompt: args.importPrompt,
|
|
16899
|
+
seed: args.seed,
|
|
16900
|
+
cost: args.importCost,
|
|
16901
|
+
steps: args.steps,
|
|
16902
|
+
raw: args.raw,
|
|
16903
|
+
historyLimit: historyLimit(loaded.manifest),
|
|
16664
16904
|
force: args.force,
|
|
16665
16905
|
dryRun: args.dryRun
|
|
16666
16906
|
});
|
|
@@ -16743,12 +16983,12 @@ async function runAdopt(args) {
|
|
|
16743
16983
|
tagged ${n} object(s) upstream`);
|
|
16744
16984
|
}
|
|
16745
16985
|
if (args.writePrompts) {
|
|
16746
|
-
const { filled, stillEmpty } = await writePromptsBack(
|
|
16986
|
+
const { filled, stillEmpty } = await writePromptsBack(path29.resolve(args.manifest), lock, {
|
|
16747
16987
|
onProgress: log,
|
|
16748
16988
|
provider: provider.id,
|
|
16749
16989
|
assetIds: specs.map((spec) => spec.assetId)
|
|
16750
16990
|
});
|
|
16751
|
-
log(` recovered ${filled} prompt(s) into ${
|
|
16991
|
+
log(` recovered ${filled} prompt(s) into ${path29.relative(process.cwd(), args.manifest)}`);
|
|
16752
16992
|
const reloaded = await loadManifest(args.manifest);
|
|
16753
16993
|
const rebased = (await resolveSpecs(reloaded, {
|
|
16754
16994
|
styles: args.styles,
|
|
@@ -16778,12 +17018,12 @@ async function runSalvage2(args) {
|
|
|
16778
17018
|
const provider = providerFor(accountProvider);
|
|
16779
17019
|
const jsonMode = args.dryRun && args.json;
|
|
16780
17020
|
const diag = jsonMode ? (msg = "") => console.error(msg) : log;
|
|
16781
|
-
const ownLock =
|
|
17021
|
+
const ownLock = path29.resolve(args.lock);
|
|
16782
17022
|
let workspaceProjects = [];
|
|
16783
17023
|
let workspaceDir = "";
|
|
16784
17024
|
if (args.workspace) {
|
|
16785
|
-
const workspacePath =
|
|
16786
|
-
workspaceDir =
|
|
17025
|
+
const workspacePath = path29.resolve(args.workspace);
|
|
17026
|
+
workspaceDir = path29.dirname(workspacePath);
|
|
16787
17027
|
const complete = await requireCompleteWorkspaceClaims(workspacePath);
|
|
16788
17028
|
workspaceProjects = complete.ws.projects;
|
|
16789
17029
|
for (const d of complete.diagnostics) diag(` WARN ${d.id}: ${d.message}`);
|
|
@@ -16792,12 +17032,12 @@ async function runSalvage2(args) {
|
|
|
16792
17032
|
const lockPaths = [
|
|
16793
17033
|
.../* @__PURE__ */ new Set([
|
|
16794
17034
|
...workspaceLockPaths,
|
|
16795
|
-
...
|
|
16796
|
-
...args.claims.map((c) =>
|
|
17035
|
+
...existsSync23(ownLock) ? [ownLock] : [],
|
|
17036
|
+
...args.claims.map((c) => path29.resolve(c))
|
|
16797
17037
|
])
|
|
16798
17038
|
];
|
|
16799
17039
|
diag(` claim set (${lockPaths.length} lockfile(s)):`);
|
|
16800
|
-
for (const p of lockPaths) diag(` ${
|
|
17040
|
+
for (const p of lockPaths) diag(` ${path29.relative(process.cwd(), p)}`);
|
|
16801
17041
|
if (!args.claims.length && !args.workspace) {
|
|
16802
17042
|
diag(
|
|
16803
17043
|
`
|
|
@@ -16805,7 +17045,7 @@ async function runSalvage2(args) {
|
|
|
16805
17045
|
pass every other project's lockfile via --claims a.json,b.json, or
|
|
16806
17046
|
register every project in a workspace catalog and pass --workspace.`
|
|
16807
17047
|
);
|
|
16808
|
-
} else if (args.workspace && !workspaceProjects.some((p) => resolveProject(workspaceDir, p).manifestPath ===
|
|
17048
|
+
} else if (args.workspace && !workspaceProjects.some((p) => resolveProject(workspaceDir, p).manifestPath === path29.resolve(args.manifest))) {
|
|
16809
17049
|
diag(
|
|
16810
17050
|
`
|
|
16811
17051
|
This project's manifest is not registered in the workspace catalog. Its own
|
|
@@ -16924,7 +17164,7 @@ async function runSalvage2(args) {
|
|
|
16924
17164
|
manifestPath: loaded.path,
|
|
16925
17165
|
manifest: accountManifest,
|
|
16926
17166
|
styleId,
|
|
16927
|
-
importDir:
|
|
17167
|
+
importDir: path29.resolve(loaded.root, style.outDir),
|
|
16928
17168
|
lock,
|
|
16929
17169
|
lockPath: args.lock
|
|
16930
17170
|
},
|
|
@@ -17051,20 +17291,20 @@ async function runTag(args) {
|
|
|
17051
17291
|
}
|
|
17052
17292
|
|
|
17053
17293
|
// src/cli/commands/edit.ts
|
|
17054
|
-
import
|
|
17294
|
+
import path32 from "path";
|
|
17055
17295
|
|
|
17056
17296
|
// src/pipeline/hand-edit.ts
|
|
17057
|
-
import { existsSync as
|
|
17297
|
+
import { existsSync as existsSync24 } from "fs";
|
|
17058
17298
|
import { copyFile, mkdir as mkdir12, readFile as readFile20, rename as rename9, rm as rm8, writeFile as writeFile14 } from "fs/promises";
|
|
17059
|
-
import
|
|
17299
|
+
import path31 from "path";
|
|
17060
17300
|
import { z as z7 } from "zod";
|
|
17061
17301
|
|
|
17062
17302
|
// src/manifest-edit.ts
|
|
17063
17303
|
import { readFile as readFile19, rename as rename8, rm as rm7, writeFile as writeFile13 } from "fs/promises";
|
|
17064
|
-
import
|
|
17304
|
+
import path30 from "path";
|
|
17065
17305
|
import { z as z6 } from "zod";
|
|
17066
17306
|
var HexSha = z6.string().regex(/^[0-9a-f]{64}$/);
|
|
17067
|
-
var ProjectFileSchema = z6.string().min(1).refine((file) => !
|
|
17307
|
+
var ProjectFileSchema = z6.string().min(1).refine((file) => !path30.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
|
|
17068
17308
|
var AssetPatchSchema = z6.object({
|
|
17069
17309
|
prompt: z6.string().optional(),
|
|
17070
17310
|
/** Per-style override for the style being viewed; null removes it. */
|
|
@@ -17484,7 +17724,7 @@ function applyEdit(raw, edit) {
|
|
|
17484
17724
|
}
|
|
17485
17725
|
}
|
|
17486
17726
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
17487
|
-
const absolute =
|
|
17727
|
+
const absolute = path30.resolve(manifestPath);
|
|
17488
17728
|
const original = await readFile19(absolute, "utf8");
|
|
17489
17729
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
17490
17730
|
let raw;
|
|
@@ -17498,9 +17738,9 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
17498
17738
|
applyEdit(raw, edit);
|
|
17499
17739
|
const next = serializeLike(original, raw);
|
|
17500
17740
|
if (next === original) return unchanged(absolute, original);
|
|
17501
|
-
const tmp =
|
|
17502
|
-
|
|
17503
|
-
`.${
|
|
17741
|
+
const tmp = path30.join(
|
|
17742
|
+
path30.dirname(absolute),
|
|
17743
|
+
`.${path30.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
|
|
17504
17744
|
);
|
|
17505
17745
|
try {
|
|
17506
17746
|
await writeFile13(tmp, next);
|
|
@@ -17573,11 +17813,11 @@ async function priceManifestEdit(manifestPath, edit, opts = {}) {
|
|
|
17573
17813
|
var HAND_EDIT_DIR = "edits";
|
|
17574
17814
|
function handEditPath(loaded, spec) {
|
|
17575
17815
|
const style = loaded.manifest.styles[spec.styleId];
|
|
17576
|
-
const outDir =
|
|
17577
|
-
const relative =
|
|
17578
|
-
const inside = relative && !relative.startsWith("..") && !
|
|
17579
|
-
const file = inside ? relative :
|
|
17580
|
-
return
|
|
17816
|
+
const outDir = path31.resolve(loaded.root, style?.outDir ?? ".");
|
|
17817
|
+
const relative = path31.relative(outDir, spec.outFile);
|
|
17818
|
+
const inside = relative && !relative.startsWith("..") && !path31.isAbsolute(relative);
|
|
17819
|
+
const file = inside ? relative : path31.basename(spec.outFile);
|
|
17820
|
+
return path31.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
|
|
17581
17821
|
}
|
|
17582
17822
|
function handEditBases(spec, lock) {
|
|
17583
17823
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -17590,10 +17830,10 @@ function handEditBases(spec, lock) {
|
|
|
17590
17830
|
}));
|
|
17591
17831
|
if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
|
|
17592
17832
|
if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
|
|
17593
|
-
if (!members.every((member) =>
|
|
17833
|
+
if (!members.every((member) => existsSync24(member.path))) return null;
|
|
17594
17834
|
return members.map(({ role, path: file }) => ({ role, path: file }));
|
|
17595
17835
|
}
|
|
17596
|
-
return
|
|
17836
|
+
return existsSync24(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
|
|
17597
17837
|
}
|
|
17598
17838
|
function handEditMembers(loaded, spec, lock, editPath) {
|
|
17599
17839
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -17619,18 +17859,18 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
17619
17859
|
`${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`
|
|
17620
17860
|
);
|
|
17621
17861
|
}
|
|
17622
|
-
const existing = spec.source ?
|
|
17862
|
+
const existing = spec.source ? path31.resolve(loaded.root, spec.source) : null;
|
|
17623
17863
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
17624
17864
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
17625
17865
|
let created = false;
|
|
17626
17866
|
for (const member of members) {
|
|
17627
|
-
if (
|
|
17867
|
+
if (existsSync24(member.path)) continue;
|
|
17628
17868
|
if (!member.base) {
|
|
17629
17869
|
throw new ManifestEditError(
|
|
17630
17870
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
17631
17871
|
);
|
|
17632
17872
|
}
|
|
17633
|
-
await mkdir12(
|
|
17873
|
+
await mkdir12(path31.dirname(member.path), { recursive: true });
|
|
17634
17874
|
await copyFile(member.base, member.path);
|
|
17635
17875
|
created = true;
|
|
17636
17876
|
}
|
|
@@ -17768,7 +18008,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
17768
18008
|
editor: input.editor,
|
|
17769
18009
|
protocol: input.protocol,
|
|
17770
18010
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
17771
|
-
project: projectPath ?
|
|
18011
|
+
project: projectPath ? path31.basename(projectPath) : null,
|
|
17772
18012
|
outputs: incoming.map((frame, index) => ({
|
|
17773
18013
|
role: frame.role,
|
|
17774
18014
|
basedOn: basedOnHash(entry, index),
|
|
@@ -17828,7 +18068,7 @@ async function runEdit(args) {
|
|
|
17828
18068
|
const set = started.members.length > 1;
|
|
17829
18069
|
const kind = spec.generator === "frames" ? "frames" : "members";
|
|
17830
18070
|
log(` ${started.created ? "created" : "found"} ${started.source}${set ? ` (${started.members.length} ${kind})` : ""}${started.declared ? " and declared it as the asset's source" : ""}`);
|
|
17831
|
-
if (set) for (const member of started.members) log(` ${member.role ?? ""} ${
|
|
18071
|
+
if (set) for (const member of started.members) log(` ${member.role ?? ""} ${path32.relative(process.cwd(), member.path)}`);
|
|
17832
18072
|
if (args.noOpen) {
|
|
17833
18073
|
log(` edit ${set ? "them" : "it"} with your own tool, then run pixelkiln plan; mount and pack place ${set ? "them" : "it"} in place of the generated art`);
|
|
17834
18074
|
} else {
|
|
@@ -17838,24 +18078,24 @@ async function runEdit(args) {
|
|
|
17838
18078
|
}
|
|
17839
18079
|
|
|
17840
18080
|
// src/cli/commands/gallery.ts
|
|
17841
|
-
import
|
|
18081
|
+
import path41 from "path";
|
|
17842
18082
|
import { existsSync as existsSync33 } from "fs";
|
|
17843
18083
|
|
|
17844
18084
|
// src/gallery/snapshot.ts
|
|
17845
18085
|
import { createHash as createHash4 } from "crypto";
|
|
17846
18086
|
import { existsSync as existsSync28 } from "fs";
|
|
17847
18087
|
import { readFile as readFile24, stat as stat2 } from "fs/promises";
|
|
17848
|
-
import
|
|
18088
|
+
import path37 from "path";
|
|
17849
18089
|
|
|
17850
18090
|
// src/gallery/edit.ts
|
|
17851
18091
|
import { readFile as readFile23, rename as rename10, writeFile as writeFile18 } from "fs/promises";
|
|
17852
|
-
import
|
|
18092
|
+
import path36 from "path";
|
|
17853
18093
|
import { z as z11 } from "zod";
|
|
17854
18094
|
|
|
17855
18095
|
// src/gallery/upload.ts
|
|
17856
|
-
import { existsSync as
|
|
18096
|
+
import { existsSync as existsSync25 } from "fs";
|
|
17857
18097
|
import { mkdir as mkdir13, writeFile as writeFile15 } from "fs/promises";
|
|
17858
|
-
import
|
|
18098
|
+
import path33 from "path";
|
|
17859
18099
|
import { z as z8 } from "zod";
|
|
17860
18100
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
17861
18101
|
var UploadImageSchema = z8.object({
|
|
@@ -17868,12 +18108,12 @@ var UploadImageSchema = z8.object({
|
|
|
17868
18108
|
overwrite: z8.boolean().optional()
|
|
17869
18109
|
}).strict();
|
|
17870
18110
|
async function saveProjectImage(root, request) {
|
|
17871
|
-
const file =
|
|
17872
|
-
const relative =
|
|
17873
|
-
if (relative.startsWith("..") ||
|
|
18111
|
+
const file = path33.resolve(root, request.path);
|
|
18112
|
+
const relative = path33.relative(root, file);
|
|
18113
|
+
if (relative.startsWith("..") || path33.isAbsolute(relative)) {
|
|
17874
18114
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
17875
18115
|
}
|
|
17876
|
-
const extension =
|
|
18116
|
+
const extension = path33.extname(file).toLowerCase();
|
|
17877
18117
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
17878
18118
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
17879
18119
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -17885,18 +18125,18 @@ async function saveProjectImage(root, request) {
|
|
|
17885
18125
|
if (metadata.format !== expected) {
|
|
17886
18126
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
17887
18127
|
}
|
|
17888
|
-
if (
|
|
17889
|
-
throw new ManifestEditError(`${relative.split(
|
|
18128
|
+
if (existsSync25(file) && !request.overwrite) {
|
|
18129
|
+
throw new ManifestEditError(`${relative.split(path33.sep).join("/")} already exists; choose another name, or replace it`);
|
|
17890
18130
|
}
|
|
17891
|
-
await mkdir13(
|
|
18131
|
+
await mkdir13(path33.dirname(file), { recursive: true });
|
|
17892
18132
|
await writeFile15(file, bytes);
|
|
17893
|
-
return relative.split(
|
|
18133
|
+
return relative.split(path33.sep).join("/");
|
|
17894
18134
|
}
|
|
17895
18135
|
|
|
17896
18136
|
// src/gallery/image-revision.ts
|
|
17897
|
-
import { existsSync as
|
|
18137
|
+
import { existsSync as existsSync26 } from "fs";
|
|
17898
18138
|
import { readFile as readFile21, rm as rm9, writeFile as writeFile16 } from "fs/promises";
|
|
17899
|
-
import
|
|
18139
|
+
import path34 from "path";
|
|
17900
18140
|
import { z as z9 } from "zod";
|
|
17901
18141
|
var InpaintRevisionRequestSchema = z9.object({
|
|
17902
18142
|
action: z9.literal("create-inpaint-revision"),
|
|
@@ -17915,15 +18155,15 @@ var InpaintRevisionRequestSchema = z9.object({
|
|
|
17915
18155
|
overwrite: z9.boolean().optional()
|
|
17916
18156
|
}).strict();
|
|
17917
18157
|
async function createInpaintRevision(manifestPath, request) {
|
|
17918
|
-
const root =
|
|
17919
|
-
if (
|
|
18158
|
+
const root = path34.dirname(path34.resolve(manifestPath));
|
|
18159
|
+
if (path34.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
17920
18160
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
17921
18161
|
}
|
|
17922
18162
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
17923
18163
|
const metadata = imageMetadata(bytes);
|
|
17924
18164
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
17925
|
-
const file =
|
|
17926
|
-
const previous =
|
|
18165
|
+
const file = path34.resolve(root, request.maskPath);
|
|
18166
|
+
const previous = existsSync26(file) ? await readFile21(file) : null;
|
|
17927
18167
|
const mask = await saveProjectImage(root, {
|
|
17928
18168
|
action: "upload-image",
|
|
17929
18169
|
path: request.maskPath,
|
|
@@ -17950,9 +18190,9 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
17950
18190
|
}
|
|
17951
18191
|
|
|
17952
18192
|
// src/gallery/skeleton.ts
|
|
17953
|
-
import { existsSync as
|
|
18193
|
+
import { existsSync as existsSync27 } from "fs";
|
|
17954
18194
|
import { mkdir as mkdir14, readFile as readFile22, rm as rm10, writeFile as writeFile17 } from "fs/promises";
|
|
17955
|
-
import
|
|
18195
|
+
import path35 from "path";
|
|
17956
18196
|
import { z as z10 } from "zod";
|
|
17957
18197
|
var SkeletonEstimateRequestSchema = z10.object({
|
|
17958
18198
|
project: z10.string().min(1).optional(),
|
|
@@ -17992,8 +18232,8 @@ var SkeletonKeypointsUpdateSchema = z10.object({
|
|
|
17992
18232
|
}).strict();
|
|
17993
18233
|
var DEFAULT_ESTIMATE_LIMIT = 10;
|
|
17994
18234
|
function skeletonSourceFile(spec) {
|
|
17995
|
-
if (spec.source) return
|
|
17996
|
-
if (spec.quality &&
|
|
18235
|
+
if (spec.source) return path35.resolve(spec.root, spec.source);
|
|
18236
|
+
if (spec.quality && existsSync27(spec.quality.outFile)) return spec.quality.outFile;
|
|
17997
18237
|
return spec.outFile;
|
|
17998
18238
|
}
|
|
17999
18239
|
function createGallerySkeletonHandlers(opts) {
|
|
@@ -18014,10 +18254,10 @@ function createGallerySkeletonHandlers(opts) {
|
|
|
18014
18254
|
const spec = ctx.specs.find((candidate) => lockKey(candidate.styleId, candidate.assetId) === key2);
|
|
18015
18255
|
if (!spec) throw new ManifestEditError(`"${key2}" is not declared by the manifest`);
|
|
18016
18256
|
const file = skeletonSourceFile(spec);
|
|
18017
|
-
if (!
|
|
18257
|
+
if (!existsSync27(file)) throw new ManifestEditError(`${key2} has no image on disk to estimate from`);
|
|
18018
18258
|
const bytes = await readFile22(file);
|
|
18019
18259
|
const metadata = imageMetadata(bytes);
|
|
18020
|
-
if (!metadata) throw new ManifestEditError(`${
|
|
18260
|
+
if (!metadata) throw new ManifestEditError(`${path35.basename(file)} is not a readable PNG or JPEG`);
|
|
18021
18261
|
const problem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
|
|
18022
18262
|
if (problem) throw new ManifestEditError(`${key2} is ${problem}`);
|
|
18023
18263
|
if (used >= limit) {
|
|
@@ -18034,7 +18274,7 @@ function createGallerySkeletonHandlers(opts) {
|
|
|
18034
18274
|
log2(` estimated a skeleton for ${key2} (PixelLab estimate-skeleton, ${used}/${limit} this session${billed ? `, billed ${billed.amount} ${billed.unit}` : ""})`);
|
|
18035
18275
|
return {
|
|
18036
18276
|
set: scaffoldSkeletonSet(res.keypoints, request.frames ?? DEFAULT_SCAFFOLD_FRAMES),
|
|
18037
|
-
source:
|
|
18277
|
+
source: path35.relative(ctx.loaded.root, file).split(path35.sep).join("/"),
|
|
18038
18278
|
session: status()
|
|
18039
18279
|
};
|
|
18040
18280
|
}
|
|
@@ -18048,20 +18288,20 @@ function billedAmount(usage) {
|
|
|
18048
18288
|
return typeof amount === "number" && Number.isFinite(amount) ? { unit: type, amount } : null;
|
|
18049
18289
|
}
|
|
18050
18290
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
18051
|
-
const root =
|
|
18052
|
-
const file =
|
|
18053
|
-
const relative =
|
|
18054
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
18291
|
+
const root = path35.dirname(path35.resolve(manifestPath));
|
|
18292
|
+
const file = path35.resolve(root, request.keypointsFile);
|
|
18293
|
+
const relative = path35.relative(root, file);
|
|
18294
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path35.isAbsolute(relative)) {
|
|
18055
18295
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
18056
18296
|
}
|
|
18057
|
-
const existed =
|
|
18297
|
+
const existed = existsSync27(file);
|
|
18058
18298
|
let previous = null;
|
|
18059
18299
|
if (request.set) {
|
|
18060
18300
|
if (existed && !request.overwrite) {
|
|
18061
18301
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
18062
18302
|
}
|
|
18063
18303
|
if (existed) previous = await readFile22(file);
|
|
18064
|
-
await mkdir14(
|
|
18304
|
+
await mkdir14(path35.dirname(file), { recursive: true });
|
|
18065
18305
|
await writeFile17(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18066
18306
|
} else if (!existed) {
|
|
18067
18307
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
@@ -18077,7 +18317,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
18077
18317
|
revision: {
|
|
18078
18318
|
mode: "animate-skeleton",
|
|
18079
18319
|
from: request.from,
|
|
18080
|
-
keypointsFile: relative.split(
|
|
18320
|
+
keypointsFile: relative.split(path35.sep).join("/"),
|
|
18081
18321
|
direction: request.direction,
|
|
18082
18322
|
description: request.description,
|
|
18083
18323
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -18098,19 +18338,19 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
18098
18338
|
if (!spec) throw new ManifestEditError(`"${key2}" is not declared by the manifest`);
|
|
18099
18339
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
18100
18340
|
if (!file) throw new ManifestEditError(`${key2} is not an animate-skeleton revision`);
|
|
18101
|
-
const relative =
|
|
18102
|
-
if (relative.startsWith("..") ||
|
|
18341
|
+
const relative = path35.relative(ctx.loaded.root, file);
|
|
18342
|
+
if (relative.startsWith("..") || path35.isAbsolute(relative)) {
|
|
18103
18343
|
throw new ManifestEditError(`${key2}'s keypoints file is outside the project; edit it by hand`);
|
|
18104
18344
|
}
|
|
18105
|
-
const current =
|
|
18345
|
+
const current = existsSync27(file) ? sha256(await readFile22(file)) : null;
|
|
18106
18346
|
if (current !== request.expectedSha256) {
|
|
18107
18347
|
throw Object.assign(
|
|
18108
|
-
new Error(`${relative.split(
|
|
18348
|
+
new Error(`${relative.split(path35.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
18109
18349
|
{ status: 409 }
|
|
18110
18350
|
);
|
|
18111
18351
|
}
|
|
18112
18352
|
await writeFile17(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18113
|
-
return relative.split(
|
|
18353
|
+
return relative.split(path35.sep).join("/");
|
|
18114
18354
|
}
|
|
18115
18355
|
|
|
18116
18356
|
// src/gallery/edit.ts
|
|
@@ -18164,7 +18404,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18164
18404
|
const history = /* @__PURE__ */ new Map();
|
|
18165
18405
|
const manifestOf = async (project) => {
|
|
18166
18406
|
try {
|
|
18167
|
-
return
|
|
18407
|
+
return path36.resolve(await opts.manifestFor(typeof project === "string" ? project : void 0));
|
|
18168
18408
|
} catch {
|
|
18169
18409
|
return null;
|
|
18170
18410
|
}
|
|
@@ -18187,7 +18427,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18187
18427
|
await writeFile18(tmp, last.before);
|
|
18188
18428
|
await rename10(tmp, manifestPath2);
|
|
18189
18429
|
stack.pop();
|
|
18190
|
-
log2(` manifest edit undone in ${
|
|
18430
|
+
log2(` manifest edit undone in ${path36.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
18191
18431
|
return opts.reload();
|
|
18192
18432
|
}
|
|
18193
18433
|
const manifestPath = await manifestOf(body?.project);
|
|
@@ -18249,7 +18489,7 @@ function createEditApplier(opts, log2) {
|
|
|
18249
18489
|
} catch (error) {
|
|
18250
18490
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
18251
18491
|
}
|
|
18252
|
-
const written = await saveProjectImage(
|
|
18492
|
+
const written = await saveProjectImage(path36.dirname(path36.resolve(manifestPath2)), upload.data);
|
|
18253
18493
|
log2(` image added: ${written}`);
|
|
18254
18494
|
return opts.reload();
|
|
18255
18495
|
}
|
|
@@ -18316,7 +18556,7 @@ function createEditApplier(opts, log2) {
|
|
|
18316
18556
|
}
|
|
18317
18557
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
18318
18558
|
if (result.changed) {
|
|
18319
|
-
const relative =
|
|
18559
|
+
const relative = path36.relative(process.cwd(), result.manifestPath);
|
|
18320
18560
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
18321
18561
|
log2(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
18322
18562
|
}
|
|
@@ -18366,163 +18606,10 @@ function createGalleryPriceHandler(opts) {
|
|
|
18366
18606
|
};
|
|
18367
18607
|
}
|
|
18368
18608
|
|
|
18369
|
-
// src/pipeline/history.ts
|
|
18370
|
-
import { existsSync as existsSync27 } from "fs";
|
|
18371
|
-
import path35 from "path";
|
|
18372
|
-
var HISTORY_ENV = "PIXELKILN_HISTORY";
|
|
18373
|
-
function historyLimit(manifest, env = process.env) {
|
|
18374
|
-
if (manifest?.history !== void 0) return manifest.history;
|
|
18375
|
-
const raw = env[HISTORY_ENV]?.trim();
|
|
18376
|
-
if (raw === void 0 || raw === "") return DEFAULT_HISTORY_LIMIT;
|
|
18377
|
-
const value = Number(raw);
|
|
18378
|
-
if (!Number.isInteger(value) || value < 0 || value > 100) {
|
|
18379
|
-
throw new Error(`${HISTORY_ENV} must be a whole number from 0 to 100, got "${raw}"`);
|
|
18380
|
-
}
|
|
18381
|
-
return value;
|
|
18382
|
-
}
|
|
18383
|
-
function retireGeneration(entry, retiredAt) {
|
|
18384
|
-
return {
|
|
18385
|
-
specHash: entry.specHash,
|
|
18386
|
-
generator: entry.generator,
|
|
18387
|
-
tileFeature: entry.tileFeature,
|
|
18388
|
-
prompt: entry.prompt,
|
|
18389
|
-
width: entry.width,
|
|
18390
|
-
height: entry.height,
|
|
18391
|
-
jobId: entry.jobId,
|
|
18392
|
-
objectId: entry.objectId,
|
|
18393
|
-
candidateIndex: entry.candidateIndex,
|
|
18394
|
-
sourceUrl: entry.sourceUrl,
|
|
18395
|
-
sourceUrls: entry.sourceUrls,
|
|
18396
|
-
outputs: entry.outputs,
|
|
18397
|
-
providerMetadata: entry.providerMetadata,
|
|
18398
|
-
submittedAt: entry.submittedAt,
|
|
18399
|
-
downloadedAt: entry.downloadedAt,
|
|
18400
|
-
cost: entry.cost,
|
|
18401
|
-
costUnit: entry.costUnit,
|
|
18402
|
-
billed: entry.billed,
|
|
18403
|
-
provider: entry.provider,
|
|
18404
|
-
postprocess: entry.postprocess,
|
|
18405
|
-
...entry.terrainConnect ? { terrainConnect: entry.terrainConnect } : {},
|
|
18406
|
-
...entry.motionShare ? { motionShare: entry.motionShare } : {},
|
|
18407
|
-
...entry.terrainSettings ? { terrainSettings: entry.terrainSettings } : {},
|
|
18408
|
-
retiredAt
|
|
18409
|
-
};
|
|
18410
|
-
}
|
|
18411
|
-
function historyAfterReplacing(previous, limit, retiredAt) {
|
|
18412
|
-
if (!previous) return void 0;
|
|
18413
|
-
const kept = previous.history ?? [];
|
|
18414
|
-
const outgoing = previous.status === "downloaded" && previous.outputs.length ? [retireGeneration(previous, retiredAt)] : [];
|
|
18415
|
-
const history = [...outgoing, ...kept].slice(0, limit);
|
|
18416
|
-
return history.length ? history : void 0;
|
|
18417
|
-
}
|
|
18418
|
-
function referencedHashes(lock) {
|
|
18419
|
-
const hashes = /* @__PURE__ */ new Set();
|
|
18420
|
-
const add = (output) => {
|
|
18421
|
-
hashes.add(output.sha256);
|
|
18422
|
-
if (output.raw) hashes.add(output.raw);
|
|
18423
|
-
};
|
|
18424
|
-
for (const entry of Object.values(lock.entries)) {
|
|
18425
|
-
for (const output of entry.outputs) add(output);
|
|
18426
|
-
for (const generation of entry.history ?? []) for (const output of generation.outputs) add(output);
|
|
18427
|
-
}
|
|
18428
|
-
return hashes;
|
|
18429
|
-
}
|
|
18430
|
-
function pickHistory(entry, selector) {
|
|
18431
|
-
const history = entry.history ?? [];
|
|
18432
|
-
if (!history.length) throw new Error(`${entry.styleId}/${entry.assetId} has no previous generations recorded`);
|
|
18433
|
-
if (typeof selector === "number" || /^\d{1,3}$/.test(selector)) {
|
|
18434
|
-
const index = Number(selector);
|
|
18435
|
-
const generation = history[index - 1];
|
|
18436
|
-
if (!generation) throw new Error(`${entry.styleId}/${entry.assetId} keeps ${history.length} previous generation(s); there is no #${index}`);
|
|
18437
|
-
return { index, generation };
|
|
18438
|
-
}
|
|
18439
|
-
const prefix = selector.toLowerCase();
|
|
18440
|
-
const matches = history.map((generation, i) => ({ index: i + 1, generation })).filter(({ generation }) => generation.outputs.some((output) => output.sha256.startsWith(prefix)));
|
|
18441
|
-
if (matches.length !== 1) {
|
|
18442
|
-
throw new Error(
|
|
18443
|
-
matches.length ? `"${selector}" matches ${matches.length} previous generations of ${entry.styleId}/${entry.assetId}; give more of the hash` : `no previous generation of ${entry.styleId}/${entry.assetId} has an output hash starting with "${selector}"`
|
|
18444
|
-
);
|
|
18445
|
-
}
|
|
18446
|
-
return matches[0];
|
|
18447
|
-
}
|
|
18448
|
-
async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
18449
|
-
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
18450
|
-
const entry = lock.entries[key2];
|
|
18451
|
-
if (!entry) throw new Error(`${key2} is not in the lockfile`);
|
|
18452
|
-
if (entry.status !== "downloaded") {
|
|
18453
|
-
throw new Error(`${key2} is ${entry.status}; finish or fetch the current generation before restoring an older one`);
|
|
18454
|
-
}
|
|
18455
|
-
const { index, generation } = pickHistory(entry, opts.generation);
|
|
18456
|
-
if (generation.provider !== provider.id) {
|
|
18457
|
-
throw new Error(`${key2}'s previous generation #${index} came from ${generation.provider}, not ${provider.id}`);
|
|
18458
|
-
}
|
|
18459
|
-
for (let i = 0; i < entry.outputs.length; i++) {
|
|
18460
|
-
const file = currentEntryOutputPath(entry, spec, i);
|
|
18461
|
-
if (!existsSync27(file)) continue;
|
|
18462
|
-
if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
|
|
18463
|
-
throw new OverwriteRefusedError(
|
|
18464
|
-
`${path35.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
|
|
18465
|
-
[file]
|
|
18466
|
-
);
|
|
18467
|
-
}
|
|
18468
|
-
}
|
|
18469
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
18470
|
-
const remaining = (entry.history ?? []).filter((_, i) => i !== index - 1);
|
|
18471
|
-
const history = [retireGeneration(entry, now), ...remaining];
|
|
18472
|
-
upsert(lock, key2, {
|
|
18473
|
-
specHash: generation.specHash,
|
|
18474
|
-
generator: generation.generator,
|
|
18475
|
-
tileFeature: generation.tileFeature,
|
|
18476
|
-
prompt: generation.prompt,
|
|
18477
|
-
width: generation.width,
|
|
18478
|
-
height: generation.height,
|
|
18479
|
-
jobId: generation.jobId,
|
|
18480
|
-
objectId: generation.objectId,
|
|
18481
|
-
candidateIndex: generation.candidateIndex,
|
|
18482
|
-
reviewObjectId: null,
|
|
18483
|
-
status: "downloaded",
|
|
18484
|
-
error: null,
|
|
18485
|
-
sourceUrl: generation.sourceUrl,
|
|
18486
|
-
sourceUrls: generation.sourceUrls,
|
|
18487
|
-
outputs: generation.outputs,
|
|
18488
|
-
// The files on disk are the outgoing generation's; that record authorizes
|
|
18489
|
-
// replacing them without --force, exactly as after a regeneration.
|
|
18490
|
-
supersededOutputs: entry.outputs,
|
|
18491
|
-
providerMetadata: generation.providerMetadata,
|
|
18492
|
-
submittedAt: generation.submittedAt,
|
|
18493
|
-
downloadedAt: generation.downloadedAt,
|
|
18494
|
-
cost: generation.cost,
|
|
18495
|
-
costUnit: generation.costUnit,
|
|
18496
|
-
billed: generation.billed,
|
|
18497
|
-
provider: generation.provider,
|
|
18498
|
-
postprocess: generation.postprocess,
|
|
18499
|
-
// A connected set comes back with the connection it was drawn from, so
|
|
18500
|
-
// the plan compares the restored generation, not the one it replaced.
|
|
18501
|
-
terrainConnect: generation.terrainConnect,
|
|
18502
|
-
// Likewise a loop that shared another direction's motion.
|
|
18503
|
-
motionShare: generation.motionShare,
|
|
18504
|
-
// Likewise its settings; a generation from before they were recorded
|
|
18505
|
-
// comes back with none and is taken as current.
|
|
18506
|
-
terrainSettings: generation.terrainSettings,
|
|
18507
|
-
history
|
|
18508
|
-
});
|
|
18509
|
-
await saveLock(lockPath, lock);
|
|
18510
|
-
const result = await fetchAssets(provider, [spec], lock, lockPath, {
|
|
18511
|
-
onProgress: opts.onProgress,
|
|
18512
|
-
repair: true,
|
|
18513
|
-
force: opts.force,
|
|
18514
|
-
cacheDir: opts.cacheDir
|
|
18515
|
-
});
|
|
18516
|
-
if (result.failed) {
|
|
18517
|
-
throw new Error(`the previous generation's bytes could not be written back; run pixelkiln restore --only ${spec.assetId} --style ${spec.styleId} once the provider is reachable`);
|
|
18518
|
-
}
|
|
18519
|
-
return { restored: generation, index, downloaded: result.downloaded };
|
|
18520
|
-
}
|
|
18521
|
-
|
|
18522
18609
|
// src/gallery/snapshot.ts
|
|
18523
18610
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
18524
18611
|
function galleryMediaId(absolutePath) {
|
|
18525
|
-
return createHash4("sha256").update(
|
|
18612
|
+
return createHash4("sha256").update(path37.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
18526
18613
|
}
|
|
18527
18614
|
function galleryMediaRoute(id) {
|
|
18528
18615
|
return `/media/${id}`;
|
|
@@ -18546,7 +18633,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
18546
18633
|
return (entry.history ?? []).map((generation, i) => {
|
|
18547
18634
|
const outputs = generation.outputs.map((output) => {
|
|
18548
18635
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
18549
|
-
const file =
|
|
18636
|
+
const file = path37.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
18550
18637
|
let url = null;
|
|
18551
18638
|
if (existsSync28(file)) {
|
|
18552
18639
|
const id = galleryMediaId(file);
|
|
@@ -18678,9 +18765,9 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
18678
18765
|
async function describeQuality(media, root, inspection) {
|
|
18679
18766
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
18680
18767
|
const outputs = await Promise.all(
|
|
18681
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
18768
|
+
outputPaths.map((file) => describeOutput(media, root, path37.resolve(root, file)))
|
|
18682
18769
|
);
|
|
18683
|
-
const recordPath =
|
|
18770
|
+
const recordPath = path37.resolve(root, inspection.record);
|
|
18684
18771
|
const recordExists = existsSync28(recordPath);
|
|
18685
18772
|
let options = null;
|
|
18686
18773
|
let check = null;
|
|
@@ -18700,7 +18787,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
18700
18787
|
return {
|
|
18701
18788
|
state: inspection.state,
|
|
18702
18789
|
reason: inspection.reason,
|
|
18703
|
-
output: portableOutputPath(
|
|
18790
|
+
output: portableOutputPath(path37.resolve(root, inspection.output), root),
|
|
18704
18791
|
record: portableOutputPath(recordPath, root),
|
|
18705
18792
|
recordExists,
|
|
18706
18793
|
outputs,
|
|
@@ -18740,7 +18827,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18740
18827
|
const items = [];
|
|
18741
18828
|
const manifestText = await readFile24(loaded.path, "utf8");
|
|
18742
18829
|
const manifestSha256 = sha256(manifestText);
|
|
18743
|
-
const cacheDir =
|
|
18830
|
+
const cacheDir = path37.resolve(path37.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
18744
18831
|
let rawStyles = {};
|
|
18745
18832
|
try {
|
|
18746
18833
|
const raw = JSON.parse(manifestText);
|
|
@@ -18764,7 +18851,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18764
18851
|
)
|
|
18765
18852
|
);
|
|
18766
18853
|
if (spec.source) {
|
|
18767
|
-
const editPath =
|
|
18854
|
+
const editPath = path37.resolve(root, spec.source);
|
|
18768
18855
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
18769
18856
|
const editShas = await Promise.all(
|
|
18770
18857
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
@@ -18813,7 +18900,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18813
18900
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
18814
18901
|
}
|
|
18815
18902
|
} else if (spec.source) {
|
|
18816
|
-
outputs = [await describeOutput(media, root,
|
|
18903
|
+
outputs = [await describeOutput(media, root, path37.resolve(root, spec.source))];
|
|
18817
18904
|
} else if (!entry && existsSync28(spec.outFile)) {
|
|
18818
18905
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
18819
18906
|
} else {
|
|
@@ -19018,7 +19105,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19018
19105
|
id: loaded.manifest.name,
|
|
19019
19106
|
name: loaded.manifest.name,
|
|
19020
19107
|
manifest: loaded.path,
|
|
19021
|
-
lock:
|
|
19108
|
+
lock: path37.resolve(opts.lockPath),
|
|
19022
19109
|
root,
|
|
19023
19110
|
provider: loaded.manifest.provider,
|
|
19024
19111
|
account: null,
|
|
@@ -19044,7 +19131,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19044
19131
|
return { snapshot, media };
|
|
19045
19132
|
}
|
|
19046
19133
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
19047
|
-
const dir =
|
|
19134
|
+
const dir = path37.dirname(path37.resolve(opts.workspacePath));
|
|
19048
19135
|
const media = /* @__PURE__ */ new Map();
|
|
19049
19136
|
const projects = [];
|
|
19050
19137
|
const items = [];
|
|
@@ -19087,7 +19174,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19087
19174
|
id: project.id,
|
|
19088
19175
|
name: loaded.manifest.name,
|
|
19089
19176
|
manifest: manifestPath,
|
|
19090
|
-
lock:
|
|
19177
|
+
lock: path37.resolve(lockPath),
|
|
19091
19178
|
root: loaded.root,
|
|
19092
19179
|
provider: loaded.manifest.provider,
|
|
19093
19180
|
account: project.account ?? null,
|
|
@@ -19103,8 +19190,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19103
19190
|
id: project.id,
|
|
19104
19191
|
name: project.id,
|
|
19105
19192
|
manifest: manifestPath,
|
|
19106
|
-
lock:
|
|
19107
|
-
root:
|
|
19193
|
+
lock: path37.resolve(lockPath),
|
|
19194
|
+
root: path37.dirname(manifestPath),
|
|
19108
19195
|
provider: project.provider,
|
|
19109
19196
|
account: project.account ?? null,
|
|
19110
19197
|
manifestSha256: null,
|
|
@@ -19131,7 +19218,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19131
19218
|
version: 1,
|
|
19132
19219
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
19133
19220
|
project: null,
|
|
19134
|
-
workspace: { path:
|
|
19221
|
+
workspace: { path: path37.resolve(opts.workspacePath), dir, projects },
|
|
19135
19222
|
filter,
|
|
19136
19223
|
totals: {
|
|
19137
19224
|
entries: projects.reduce((sum, project) => sum + project.entries, 0),
|
|
@@ -20048,7 +20135,7 @@ import { readFile as readFile27 } from "fs/promises";
|
|
|
20048
20135
|
// src/pipeline/init.ts
|
|
20049
20136
|
import { readdir, readFile as readFile26, writeFile as writeFile19 } from "fs/promises";
|
|
20050
20137
|
import { existsSync as existsSync30 } from "fs";
|
|
20051
|
-
import
|
|
20138
|
+
import path38 from "path";
|
|
20052
20139
|
function pngSize(buf) {
|
|
20053
20140
|
if (buf.length < 24) return null;
|
|
20054
20141
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -20062,7 +20149,7 @@ function slugify(value) {
|
|
|
20062
20149
|
async function walk(dir, exclude) {
|
|
20063
20150
|
const out = [];
|
|
20064
20151
|
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
20065
|
-
const full =
|
|
20152
|
+
const full = path38.join(dir, entry.name);
|
|
20066
20153
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
20067
20154
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
20068
20155
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -20081,9 +20168,9 @@ async function scanAssets(root, opts = {}) {
|
|
|
20081
20168
|
skipped.push(`${file} (not a readable PNG)`);
|
|
20082
20169
|
continue;
|
|
20083
20170
|
}
|
|
20084
|
-
const rel =
|
|
20085
|
-
const category =
|
|
20086
|
-
let id = slugify(
|
|
20171
|
+
const rel = path38.relative(root, file);
|
|
20172
|
+
const category = path38.dirname(rel) === "." ? "" : path38.dirname(rel);
|
|
20173
|
+
let id = slugify(path38.basename(rel));
|
|
20087
20174
|
if (seen.has(id)) {
|
|
20088
20175
|
const n = seen.get(id) + 1;
|
|
20089
20176
|
seen.set(id, n);
|
|
@@ -21132,14 +21219,14 @@ function createGenerateHandlers(opts) {
|
|
|
21132
21219
|
|
|
21133
21220
|
// src/gallery/editor.ts
|
|
21134
21221
|
import { readFile as readFile29 } from "fs/promises";
|
|
21135
|
-
import
|
|
21222
|
+
import path40 from "path";
|
|
21136
21223
|
|
|
21137
21224
|
// src/editor/install.ts
|
|
21138
21225
|
import { createHash as createHash5 } from "crypto";
|
|
21139
21226
|
import { existsSync as existsSync32 } from "fs";
|
|
21140
21227
|
import { mkdir as mkdir15, readFile as readFile28, rename as rename11, rm as rm11, stat as stat3, writeFile as writeFile20 } from "fs/promises";
|
|
21141
21228
|
import os3 from "os";
|
|
21142
|
-
import
|
|
21229
|
+
import path39 from "path";
|
|
21143
21230
|
|
|
21144
21231
|
// tools/pixelorama-bridge/pin.json
|
|
21145
21232
|
var pin_default = {
|
|
@@ -21203,15 +21290,15 @@ var EditorInstallError = class extends Error {
|
|
|
21203
21290
|
};
|
|
21204
21291
|
function editorToolsRoot() {
|
|
21205
21292
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
21206
|
-
if (override) return
|
|
21207
|
-
if (process.platform === "darwin") return
|
|
21293
|
+
if (override) return path39.resolve(override);
|
|
21294
|
+
if (process.platform === "darwin") return path39.join(os3.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
21208
21295
|
if (process.platform === "win32") {
|
|
21209
|
-
return
|
|
21296
|
+
return path39.join(process.env.LOCALAPPDATA ?? path39.join(os3.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
21210
21297
|
}
|
|
21211
|
-
return
|
|
21298
|
+
return path39.join(process.env.XDG_CACHE_HOME ?? path39.join(os3.homedir(), ".cache"), "pixelkiln", "tools");
|
|
21212
21299
|
}
|
|
21213
21300
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
21214
|
-
return
|
|
21301
|
+
return path39.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
21215
21302
|
}
|
|
21216
21303
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
21217
21304
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -21234,7 +21321,7 @@ async function editorStatus(opts = {}) {
|
|
|
21234
21321
|
let totalBytes = 0;
|
|
21235
21322
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
21236
21323
|
totalBytes += expected.bytes;
|
|
21237
|
-
const file =
|
|
21324
|
+
const file = path39.join(dir, name);
|
|
21238
21325
|
const info = existsSync32(file) ? await stat3(file).catch(() => null) : null;
|
|
21239
21326
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
21240
21327
|
installedBytes += expected.bytes;
|
|
@@ -21292,7 +21379,7 @@ async function installEditor(opts = {}) {
|
|
|
21292
21379
|
if (digest2 !== expected.sha256) {
|
|
21293
21380
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
21294
21381
|
}
|
|
21295
|
-
const final =
|
|
21382
|
+
const final = path39.join(dir, name);
|
|
21296
21383
|
const tmp = `${final}.${process.pid}.part`;
|
|
21297
21384
|
try {
|
|
21298
21385
|
await writeFile20(tmp, bytes);
|
|
@@ -21338,7 +21425,7 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
21338
21425
|
".json": "application/json; charset=utf-8"
|
|
21339
21426
|
};
|
|
21340
21427
|
function editorContentType(name) {
|
|
21341
|
-
return EDITOR_CONTENT_TYPES[
|
|
21428
|
+
return EDITOR_CONTENT_TYPES[path39.extname(name).toLowerCase()] ?? null;
|
|
21342
21429
|
}
|
|
21343
21430
|
|
|
21344
21431
|
// src/gallery/editor.ts
|
|
@@ -21414,7 +21501,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
21414
21501
|
if (!status.installed) return null;
|
|
21415
21502
|
let bytes;
|
|
21416
21503
|
try {
|
|
21417
|
-
bytes = await readFile29(
|
|
21504
|
+
bytes = await readFile29(path40.join(dir, name));
|
|
21418
21505
|
} catch {
|
|
21419
21506
|
verified = null;
|
|
21420
21507
|
return null;
|
|
@@ -21454,7 +21541,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
21454
21541
|
};
|
|
21455
21542
|
const loadProject = async (project) => {
|
|
21456
21543
|
const ctx = await access2.loadProject(project);
|
|
21457
|
-
loadProjectEnv(
|
|
21544
|
+
loadProjectEnv(path41.dirname(ctx.loaded.path));
|
|
21458
21545
|
return ctx;
|
|
21459
21546
|
};
|
|
21460
21547
|
const loadProjectEnv = (dir) => {
|
|
@@ -21463,7 +21550,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
21463
21550
|
for (const [name, value] of Object.entries(declared)) {
|
|
21464
21551
|
if (credentialNames.has(name) && name in process.env && process.env[name] !== value) {
|
|
21465
21552
|
throw new Error(
|
|
21466
|
-
`${
|
|
21553
|
+
`${path41.relative(process.cwd(), dir) || "."} sets ${name} to a different value than the one this gallery already loaded; run a separate gallery for that project so its work uses its own account.`
|
|
21467
21554
|
);
|
|
21468
21555
|
}
|
|
21469
21556
|
}
|
|
@@ -21471,7 +21558,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
21471
21558
|
};
|
|
21472
21559
|
const quoters = /* @__PURE__ */ new Map();
|
|
21473
21560
|
const quoteFor = async (project) => {
|
|
21474
|
-
loadProjectEnv(
|
|
21561
|
+
loadProjectEnv(path41.dirname(path41.resolve(await access2.manifestFor(project))));
|
|
21475
21562
|
const key2 = process.env.PIXELLAB_API_KEY;
|
|
21476
21563
|
if (!key2) return null;
|
|
21477
21564
|
let quoter = quoters.get(key2);
|
|
@@ -21522,7 +21609,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
21522
21609
|
}
|
|
21523
21610
|
async function runGallery(args) {
|
|
21524
21611
|
if (args.workspace) {
|
|
21525
|
-
const workspacePath =
|
|
21612
|
+
const workspacePath = path41.resolve(args.workspace);
|
|
21526
21613
|
if (!existsSync33(workspacePath)) {
|
|
21527
21614
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
21528
21615
|
}
|
|
@@ -21543,7 +21630,7 @@ async function runGallery(args) {
|
|
|
21543
21630
|
const registered = async (projectId) => {
|
|
21544
21631
|
const project = (await loadWorkspace(workspacePath)).projects.find((candidate) => candidate.id === projectId);
|
|
21545
21632
|
if (!projectId || !project) throw new Error(`unknown workspace project "${projectId ?? ""}"`);
|
|
21546
|
-
return resolveProject(
|
|
21633
|
+
return resolveProject(path41.dirname(workspacePath), project);
|
|
21547
21634
|
};
|
|
21548
21635
|
await serveUntilStopped(initial, build2, args, {
|
|
21549
21636
|
manifestFor: async (projectId) => (await registered(projectId)).manifestPath,
|
|
@@ -21568,7 +21655,7 @@ async function runGallery(args) {
|
|
|
21568
21655
|
return buildGallerySnapshot({ ...fresh, filter });
|
|
21569
21656
|
};
|
|
21570
21657
|
await serveUntilStopped(await build(), reload, args, {
|
|
21571
|
-
manifestFor: () =>
|
|
21658
|
+
manifestFor: () => path41.resolve(args.manifest),
|
|
21572
21659
|
loadProject: () => openProject(args.manifest, { lockPath: args.lock, env: false })
|
|
21573
21660
|
});
|
|
21574
21661
|
}
|
|
@@ -21820,6 +21907,11 @@ async function runLifecycle(args, wave, spent) {
|
|
|
21820
21907
|
}
|
|
21821
21908
|
|
|
21822
21909
|
// src/cli/commands/history.ts
|
|
21910
|
+
function importedNote(entry) {
|
|
21911
|
+
if (!entry.imported) return "";
|
|
21912
|
+
const parts = [entry.imported.source, entry.origin?.tool, ...entry.origin?.steps ?? []].filter(Boolean);
|
|
21913
|
+
return ` [imported: ${parts.join(", ")}]`;
|
|
21914
|
+
}
|
|
21823
21915
|
function billedNote(cost, costUnit, billed) {
|
|
21824
21916
|
if (!billed || billed.unit === costUnit && billed.amount === cost) return "";
|
|
21825
21917
|
return ` (billed ${formatCost(billed.unit, billed.amount)})`;
|
|
@@ -21834,7 +21926,7 @@ async function runHistory(args) {
|
|
|
21834
21926
|
limit,
|
|
21835
21927
|
assets: selected.map(({ spec, entry }) => ({
|
|
21836
21928
|
key: lockKey(spec.styleId, spec.assetId),
|
|
21837
|
-
current: entry ? { objectId: entry.objectId, outputs: entry.outputs, downloadedAt: entry.downloadedAt, cost: entry.cost, costUnit: entry.costUnit, billed: entry.billed } : null,
|
|
21929
|
+
current: entry ? { objectId: entry.objectId, outputs: entry.outputs, downloadedAt: entry.downloadedAt, cost: entry.cost, costUnit: entry.costUnit, billed: entry.billed, ...entry.imported ? { imported: entry.imported, ...entry.origin ? { origin: entry.origin } : {} } : {} } : null,
|
|
21838
21930
|
history: entry?.history ?? []
|
|
21839
21931
|
}))
|
|
21840
21932
|
}, null, 2));
|
|
@@ -21848,10 +21940,10 @@ async function runHistory(args) {
|
|
|
21848
21940
|
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
21849
21941
|
log(`
|
|
21850
21942
|
${key2}`);
|
|
21851
|
-
log(` current ${entry.outputs[0]?.sha256.slice(0, 12) ?? "\u2014"} ${entry.downloadedAt ?? ""} ${entry.objectId ?? ""}${billedNote(entry.cost, entry.costUnit, entry.billed)}`);
|
|
21943
|
+
log(` current ${entry.outputs[0]?.sha256.slice(0, 12) ?? "\u2014"} ${entry.downloadedAt ?? ""} ${entry.objectId ?? ""}${billedNote(entry.cost, entry.costUnit, entry.billed)}${importedNote(entry)}`);
|
|
21852
21944
|
for (const [i, generation] of entry.history.entries()) {
|
|
21853
21945
|
const changed = generation.prompt !== entry.prompt ? " (different prompt)" : "";
|
|
21854
|
-
log(` #${String(i + 1).padEnd(2)} ${generation.outputs[0]?.sha256.slice(0, 12) ?? "\u2014"} ${generation.downloadedAt ?? ""} ${generation.objectId ?? ""}${changed}${billedNote(generation.cost, generation.costUnit, generation.billed)}`);
|
|
21946
|
+
log(` #${String(i + 1).padEnd(2)} ${generation.outputs[0]?.sha256.slice(0, 12) ?? "\u2014"} ${generation.downloadedAt ?? ""} ${generation.objectId ?? ""}${changed}${billedNote(generation.cost, generation.costUnit, generation.billed)}${importedNote(generation)}`);
|
|
21855
21947
|
}
|
|
21856
21948
|
}
|
|
21857
21949
|
if (!shown) log(` no asset has a previous generation recorded${selected.length ? "" : " (nothing selected)"}`);
|
|
@@ -21885,13 +21977,13 @@ import { existsSync as existsSync35 } from "fs";
|
|
|
21885
21977
|
// src/pipeline/cache-health.ts
|
|
21886
21978
|
import { existsSync as existsSync34 } from "fs";
|
|
21887
21979
|
import { readFile as readFile30, readdir as readdir2, rm as rm12 } from "fs/promises";
|
|
21888
|
-
import
|
|
21980
|
+
import path42 from "path";
|
|
21889
21981
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
21890
21982
|
if (options.prune && !existsSync34(lockPath)) {
|
|
21891
|
-
throw new Error(`Refusing to prune without an existing lockfile at ${
|
|
21983
|
+
throw new Error(`Refusing to prune without an existing lockfile at ${path42.resolve(lockPath)}`);
|
|
21892
21984
|
}
|
|
21893
|
-
const contentDir =
|
|
21894
|
-
const remotePath =
|
|
21985
|
+
const contentDir = path42.resolve(path42.dirname(lockPath), ".pixelkiln", "cache");
|
|
21986
|
+
const remotePath = path42.resolve(cachePathFor(lockPath));
|
|
21895
21987
|
const referenced = referencedHashes(lock);
|
|
21896
21988
|
let content = await inspectContentCache(contentDir, referenced);
|
|
21897
21989
|
let remoteHashes = await inspectRemoteHashCache(remotePath);
|
|
@@ -21903,7 +21995,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
21903
21995
|
]);
|
|
21904
21996
|
for (const name of names) {
|
|
21905
21997
|
try {
|
|
21906
|
-
await rm12(
|
|
21998
|
+
await rm12(path42.join(contentDir, name), { force: true });
|
|
21907
21999
|
removed.contentFiles++;
|
|
21908
22000
|
} catch {
|
|
21909
22001
|
}
|
|
@@ -21951,7 +22043,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
21951
22043
|
continue;
|
|
21952
22044
|
}
|
|
21953
22045
|
report.files++;
|
|
21954
|
-
const file =
|
|
22046
|
+
const file = path42.join(contentDir, entry.name);
|
|
21955
22047
|
const mediaType = mediaTypeFromExtension(entry.name);
|
|
21956
22048
|
const expected = mediaType ? entry.name.slice(0, -4) : "";
|
|
21957
22049
|
let bytes;
|
|
@@ -22122,46 +22214,46 @@ This drops their provenance from the lockfile. The art on disk is`);
|
|
|
22122
22214
|
}
|
|
22123
22215
|
|
|
22124
22216
|
// src/cli/commands/init.ts
|
|
22125
|
-
import
|
|
22217
|
+
import path43 from "path";
|
|
22126
22218
|
import { existsSync as existsSync36 } from "fs";
|
|
22127
22219
|
async function runInit(args) {
|
|
22128
22220
|
if (!args.from) throw new Error("init needs --from <dir> pointing at your existing PNGs.");
|
|
22129
|
-
const root =
|
|
22221
|
+
const root = path43.resolve(args.from);
|
|
22130
22222
|
if (!existsSync36(root)) throw new Error(`No directory at ${root}`);
|
|
22131
22223
|
const generator = args.generator ?? "map";
|
|
22132
22224
|
if (generator !== "1dir" && generator !== "map") {
|
|
22133
22225
|
throw new Error(`--generator must be "1dir" or "map", got "${args.generator}".`);
|
|
22134
22226
|
}
|
|
22135
|
-
const target =
|
|
22227
|
+
const target = path43.resolve(args.out ?? "pixelkiln.manifest.json");
|
|
22136
22228
|
const { assets, skipped } = await scanAssets(root, { exclude: args.exclude });
|
|
22137
22229
|
if (!assets.length) throw new Error(`No PNGs found under ${root}`);
|
|
22138
22230
|
const manifest = buildManifest(
|
|
22139
|
-
args.name ??
|
|
22231
|
+
args.name ?? path43.basename(path43.dirname(target)),
|
|
22140
22232
|
args.styles[0] ?? "base",
|
|
22141
22233
|
generator,
|
|
22142
|
-
|
|
22234
|
+
path43.relative(path43.dirname(target), root) || ".",
|
|
22143
22235
|
assets
|
|
22144
22236
|
);
|
|
22145
22237
|
await writeManifestFile(target, manifest);
|
|
22146
|
-
log(` scanned ${assets.length} PNG(s) under ${
|
|
22238
|
+
log(` scanned ${assets.length} PNG(s) under ${path43.relative(process.cwd(), root)}`);
|
|
22147
22239
|
if (skipped.length) log(` skipped ${skipped.length} unreadable file(s)`);
|
|
22148
|
-
log(` wrote ${
|
|
22240
|
+
log(` wrote ${path43.relative(process.cwd(), target)}`);
|
|
22149
22241
|
log(`
|
|
22150
22242
|
Prompts are intentionally empty. To recover the real ones from your`);
|
|
22151
22243
|
log(` PixelLab account instead of inventing them:`);
|
|
22152
22244
|
log(`
|
|
22153
|
-
pixelkiln adopt --manifest ${
|
|
22245
|
+
pixelkiln adopt --manifest ${path43.relative(process.cwd(), target)} --write-prompts
|
|
22154
22246
|
`);
|
|
22155
22247
|
}
|
|
22156
22248
|
|
|
22157
22249
|
// src/pipeline/doctor.ts
|
|
22158
22250
|
import { constants, existsSync as existsSync38 } from "fs";
|
|
22159
22251
|
import { access, stat as stat4 } from "fs/promises";
|
|
22160
|
-
import
|
|
22252
|
+
import path45 from "path";
|
|
22161
22253
|
|
|
22162
22254
|
// src/pipeline/install-check.ts
|
|
22163
22255
|
import { existsSync as existsSync37, readFileSync as readFileSync7 } from "fs";
|
|
22164
|
-
import
|
|
22256
|
+
import path44 from "path";
|
|
22165
22257
|
function readJson(file) {
|
|
22166
22258
|
try {
|
|
22167
22259
|
return JSON.parse(readFileSync7(file, "utf8"));
|
|
@@ -22170,18 +22262,18 @@ function readJson(file) {
|
|
|
22170
22262
|
}
|
|
22171
22263
|
}
|
|
22172
22264
|
function readInstallFacts(manifestDir, running) {
|
|
22173
|
-
let dir =
|
|
22265
|
+
let dir = path44.resolve(manifestDir);
|
|
22174
22266
|
for (let depth = 0; depth < 4; depth++) {
|
|
22175
|
-
const pkg = readJson(
|
|
22267
|
+
const pkg = readJson(path44.join(dir, "package.json"));
|
|
22176
22268
|
if (pkg) {
|
|
22177
22269
|
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
22178
22270
|
if (pinned) {
|
|
22179
|
-
const installedPkg = readJson(
|
|
22271
|
+
const installedPkg = readJson(path44.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
22180
22272
|
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
22181
22273
|
return { pinned, installed, running };
|
|
22182
22274
|
}
|
|
22183
22275
|
}
|
|
22184
|
-
const parent =
|
|
22276
|
+
const parent = path44.dirname(dir);
|
|
22185
22277
|
if (parent === dir || !existsSync37(parent)) break;
|
|
22186
22278
|
dir = parent;
|
|
22187
22279
|
}
|
|
@@ -22245,12 +22337,12 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
22245
22337
|
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
22246
22338
|
);
|
|
22247
22339
|
}
|
|
22248
|
-
const facts = readInstallFacts(
|
|
22340
|
+
const facts = readInstallFacts(path45.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
22249
22341
|
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
22250
22342
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
22251
22343
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
22252
|
-
|
|
22253
|
-
...spec.quality ? [
|
|
22344
|
+
path45.dirname(spec.outFile),
|
|
22345
|
+
...spec.quality ? [path45.dirname(spec.quality.outFile)] : []
|
|
22254
22346
|
]))];
|
|
22255
22347
|
const unwritable = [];
|
|
22256
22348
|
for (const dir of dirs) {
|
|
@@ -22273,7 +22365,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
22273
22365
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
22274
22366
|
const output = entry.outputs[index];
|
|
22275
22367
|
const spec = specByKey.get(key2);
|
|
22276
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
22368
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, path45.dirname(lockPath));
|
|
22277
22369
|
const owner = outputOwners.get(absolute);
|
|
22278
22370
|
if (owner && owner !== key2) duplicateOutputs.push(`${output.path} (${owner}, ${key2})`);
|
|
22279
22371
|
outputOwners.set(absolute, key2);
|
|
@@ -22288,7 +22380,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
22288
22380
|
} else {
|
|
22289
22381
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
22290
22382
|
}
|
|
22291
|
-
const cacheDir =
|
|
22383
|
+
const cacheDir = path45.join(path45.dirname(lockPath), ".pixelkiln", "cache");
|
|
22292
22384
|
const stranded = [];
|
|
22293
22385
|
const invalidState = [];
|
|
22294
22386
|
const staleMapUrls = [];
|
|
@@ -22304,7 +22396,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
22304
22396
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
22305
22397
|
let hasCache = false;
|
|
22306
22398
|
for (const output of entry.outputs) {
|
|
22307
|
-
const cached2 =
|
|
22399
|
+
const cached2 = path45.join(
|
|
22308
22400
|
cacheDir,
|
|
22309
22401
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
22310
22402
|
);
|
|
@@ -22404,7 +22496,7 @@ async function nearestExistingDirectory(start) {
|
|
|
22404
22496
|
if ((await stat4(current)).isDirectory()) return current;
|
|
22405
22497
|
} catch {
|
|
22406
22498
|
}
|
|
22407
|
-
const parent =
|
|
22499
|
+
const parent = path45.dirname(current);
|
|
22408
22500
|
if (parent === current) return current;
|
|
22409
22501
|
current = parent;
|
|
22410
22502
|
}
|
|
@@ -22413,7 +22505,7 @@ async function nearestExistingDirectory(start) {
|
|
|
22413
22505
|
// src/pipeline/audit.ts
|
|
22414
22506
|
import { readFile as readFile31 } from "fs/promises";
|
|
22415
22507
|
import { existsSync as existsSync39 } from "fs";
|
|
22416
|
-
import
|
|
22508
|
+
import path46 from "path";
|
|
22417
22509
|
function paletteDistance(asset, reference) {
|
|
22418
22510
|
if (!asset.length || !reference.length) return 0;
|
|
22419
22511
|
let total = 0;
|
|
@@ -22478,7 +22570,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
22478
22570
|
let referenceFromStyleImages = false;
|
|
22479
22571
|
const refPalettes = [];
|
|
22480
22572
|
for (const img of style.styleImages) {
|
|
22481
|
-
const abs =
|
|
22573
|
+
const abs = path46.resolve(loaded.root, img.path);
|
|
22482
22574
|
if (!existsSync39(abs)) continue;
|
|
22483
22575
|
try {
|
|
22484
22576
|
refPalettes.push(extractPalette(decodePng(await readFile31(abs)), 12));
|
|
@@ -22647,6 +22739,7 @@ async function runPlan(args) {
|
|
|
22647
22739
|
}
|
|
22648
22740
|
} : {},
|
|
22649
22741
|
...quality ? { quality: { state: quality.state, reason: quality.reason } } : {},
|
|
22742
|
+
...entry?.imported ? { imported: entry.imported, ...entry.origin ? { origin: entry.origin } : {} } : {},
|
|
22650
22743
|
// The estimate a wave budget spent against; present alongside the
|
|
22651
22744
|
// provider's actual charge only when `poll` has read one and it
|
|
22652
22745
|
// differs, since that is the only time the gap is worth a look.
|
|
@@ -22735,24 +22828,24 @@ async function runHash(args) {
|
|
|
22735
22828
|
}
|
|
22736
22829
|
|
|
22737
22830
|
// src/cli/commands/pack.ts
|
|
22738
|
-
import
|
|
22831
|
+
import path48 from "path";
|
|
22739
22832
|
import { readFile as readFile32 } from "fs/promises";
|
|
22740
22833
|
|
|
22741
22834
|
// src/pipeline/pack.ts
|
|
22742
22835
|
import { readFileSync as readFileSync8 } from "fs";
|
|
22743
|
-
import
|
|
22836
|
+
import path47 from "path";
|
|
22744
22837
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
22745
22838
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
22746
22839
|
if (!Array.isArray(raw) || !raw.length) {
|
|
22747
22840
|
throw new Error("--inputs must be a non-empty JSON array of { id, path }");
|
|
22748
22841
|
}
|
|
22749
|
-
const baseDir =
|
|
22842
|
+
const baseDir = path47.dirname(path47.resolve(inputsFilePath));
|
|
22750
22843
|
return raw.map((entry, i) => {
|
|
22751
22844
|
const e = entry;
|
|
22752
22845
|
if (typeof e.id !== "string" || typeof e.path !== "string") {
|
|
22753
22846
|
throw new Error(`--inputs[${i}] needs string "id" and "path"`);
|
|
22754
22847
|
}
|
|
22755
|
-
return { id: e.id, path:
|
|
22848
|
+
return { id: e.id, path: path47.resolve(baseDir, e.path) };
|
|
22756
22849
|
});
|
|
22757
22850
|
}
|
|
22758
22851
|
function packSprites(inputs, options = {}) {
|
|
@@ -22836,7 +22929,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
22836
22929
|
}
|
|
22837
22930
|
const inputs2 = Object.entries(options.sourceOverrides).map(([id, source]) => ({
|
|
22838
22931
|
id,
|
|
22839
|
-
path:
|
|
22932
|
+
path: path47.resolve(source)
|
|
22840
22933
|
}));
|
|
22841
22934
|
if (!inputs2.length) throw new Error(`No approved quality outputs for style "${styleId}".`);
|
|
22842
22935
|
const packed2 = packSprites(inputs2, options);
|
|
@@ -22860,7 +22953,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
22860
22953
|
let outputs = resolveEntryOutputs(entry, id, manifestDir);
|
|
22861
22954
|
const source = sources[id];
|
|
22862
22955
|
if (source && outputs.length <= 1) {
|
|
22863
|
-
inputs.push({ id, path:
|
|
22956
|
+
inputs.push({ id, path: path47.resolve(manifestDir, source) });
|
|
22864
22957
|
continue;
|
|
22865
22958
|
}
|
|
22866
22959
|
if (source && sourceIsStem(source, entry, manifestDir)) {
|
|
@@ -22895,7 +22988,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
22895
22988
|
}
|
|
22896
22989
|
}
|
|
22897
22990
|
for (const [id, source] of Object.entries(sources)) {
|
|
22898
|
-
if (!locked.has(id)) inputs.push({ id, path:
|
|
22991
|
+
if (!locked.has(id)) inputs.push({ id, path: path47.resolve(manifestDir, source) });
|
|
22899
22992
|
}
|
|
22900
22993
|
if (!inputs.length) {
|
|
22901
22994
|
throw new Error(`No readable sprites for style "${styleId}"; ${noOutput.length} skipped.`);
|
|
@@ -23003,7 +23096,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
23003
23096
|
const source = sources[id];
|
|
23004
23097
|
const entry = lock.entries[`${styleId}/${id}`];
|
|
23005
23098
|
if (source && !(entry && sourceIsStem(source, entry, manifestDir))) {
|
|
23006
|
-
placements.push({ id, path:
|
|
23099
|
+
placements.push({ id, path: path47.resolve(manifestDir, source), cell });
|
|
23007
23100
|
continue;
|
|
23008
23101
|
}
|
|
23009
23102
|
if (source && entry) {
|
|
@@ -23036,7 +23129,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
23036
23129
|
`Nothing to mount for style "${styleId}": ${ids.length} asset(s) declare a cell, but none has generated output or a \`source\`. Run \`pixelkiln gen --style ${styleId}\`, or point each at a file.${detail}`
|
|
23037
23130
|
);
|
|
23038
23131
|
}
|
|
23039
|
-
const basePng = mount.base ? readFileSync8(
|
|
23132
|
+
const basePng = mount.base ? readFileSync8(path47.resolve(manifestDir, mount.base)) : void 0;
|
|
23040
23133
|
const mounted = mountSprites(placements, {
|
|
23041
23134
|
cellWidth: mount.cellWidth,
|
|
23042
23135
|
cellHeight: mount.cellHeight,
|
|
@@ -23046,7 +23139,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
23046
23139
|
...mounted,
|
|
23047
23140
|
sources: mount.base ? [{
|
|
23048
23141
|
id: "$base",
|
|
23049
|
-
path:
|
|
23142
|
+
path: path47.resolve(manifestDir, mount.base),
|
|
23050
23143
|
sha256: sha256(basePng),
|
|
23051
23144
|
included: true
|
|
23052
23145
|
}, ...mounted.sources] : mounted.sources,
|
|
@@ -23450,12 +23543,12 @@ async function runPack(args) {
|
|
|
23450
23543
|
if (args.primaryOnly || args.outputRoles.length) {
|
|
23451
23544
|
throw new Error("--primary-only and --output-role require manifest-driven pack");
|
|
23452
23545
|
}
|
|
23453
|
-
const raw = JSON.parse(await readFile32(
|
|
23546
|
+
const raw = JSON.parse(await readFile32(path48.resolve(args.inputs), "utf8"));
|
|
23454
23547
|
const inputs = resolvePackInputs(raw, args.inputs);
|
|
23455
23548
|
const { png, atlas, skipped, sources } = packSprites(inputs, { columns: args.columns });
|
|
23456
23549
|
const format = sheetFormat(args);
|
|
23457
|
-
const base =
|
|
23458
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
23550
|
+
const base = path48.resolve(args.out.replace(/\.(?:png|json|tres)$/i, ""));
|
|
23551
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path48.basename(`${base}.png`) });
|
|
23459
23552
|
const outputs = [
|
|
23460
23553
|
{ path: `${base}.png`, data: png },
|
|
23461
23554
|
{ path: `${base}${extension}`, data: document }
|
|
@@ -23468,7 +23561,7 @@ async function runPack(args) {
|
|
|
23468
23561
|
log(
|
|
23469
23562
|
` ${atlas.frames.length} sprite(s), ${atlas.sheet.width}x${atlas.sheet.height} in ${atlas.columns} column(s), ${(png.length / 1024).toFixed(1)} KB (${format})`
|
|
23470
23563
|
);
|
|
23471
|
-
log(` ${
|
|
23564
|
+
log(` ${path48.relative(process.cwd(), base)}.png + ${extension} + .pixelkiln.json`);
|
|
23472
23565
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
23473
23566
|
return;
|
|
23474
23567
|
}
|
|
@@ -23476,7 +23569,7 @@ async function runPack(args) {
|
|
|
23476
23569
|
if (args.primaryOnly && args.outputRoles.length) {
|
|
23477
23570
|
throw new Error("pack accepts either --primary-only or --output-role, not both");
|
|
23478
23571
|
}
|
|
23479
|
-
const manifestDir =
|
|
23572
|
+
const manifestDir = path48.dirname(path48.resolve(args.manifest));
|
|
23480
23573
|
const styleIds = args.styles.length ? args.styles : Object.keys(loaded.manifest.styles);
|
|
23481
23574
|
for (const styleId of styleIds) {
|
|
23482
23575
|
const style = loaded.manifest.styles[styleId];
|
|
@@ -23491,9 +23584,9 @@ async function runPack(args) {
|
|
|
23491
23584
|
sourceOverrides: qualitySources,
|
|
23492
23585
|
sources: manifestSources(loaded.manifest, styleId)
|
|
23493
23586
|
});
|
|
23494
|
-
const base = args.out ?
|
|
23587
|
+
const base = args.out ? path48.resolve(args.out.replace(/\.(?:png|json|tres)$/i, "")) : path48.resolve(manifestDir, style.outDir, `${styleId}-sheet`);
|
|
23495
23588
|
const format = sheetFormat(args);
|
|
23496
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
23589
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path48.basename(`${base}.png`) });
|
|
23497
23590
|
const outputs = [
|
|
23498
23591
|
{ path: `${base}.png`, data: png },
|
|
23499
23592
|
{ path: `${base}${extension}`, data: document }
|
|
@@ -23525,13 +23618,13 @@ async function runPack(args) {
|
|
|
23525
23618
|
log(
|
|
23526
23619
|
` ${styleId}: ${atlas.frames.length} sprite(s), ${atlas.sheet.width}x${atlas.sheet.height} in ${atlas.columns} column(s)` + (atlas.sets?.length ? `, ${atlas.sets.length} set(s)` : "") + ` (${format})`
|
|
23527
23620
|
);
|
|
23528
|
-
log(` ${
|
|
23621
|
+
log(` ${path48.relative(process.cwd(), base)}.png + ${extension} + .pixelkiln.json`);
|
|
23529
23622
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
23530
23623
|
}
|
|
23531
23624
|
}
|
|
23532
23625
|
async function runMount(args) {
|
|
23533
23626
|
const { loaded, lock } = await openProject2(args);
|
|
23534
|
-
const manifestDir =
|
|
23627
|
+
const manifestDir = path48.dirname(path48.resolve(args.manifest));
|
|
23535
23628
|
const styleIds = args.styles.length ? args.styles : Object.keys(loaded.manifest.styles);
|
|
23536
23629
|
for (const styleId of styleIds) {
|
|
23537
23630
|
const style = loaded.manifest.styles[styleId];
|
|
@@ -23570,9 +23663,9 @@ async function runMount(args) {
|
|
|
23570
23663
|
sources,
|
|
23571
23664
|
outputRoles
|
|
23572
23665
|
);
|
|
23573
|
-
const out =
|
|
23666
|
+
const out = path48.resolve(manifestDir, style.mount.out);
|
|
23574
23667
|
const format = sheetFormat(args);
|
|
23575
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
23668
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path48.basename(out) });
|
|
23576
23669
|
const metadata = out.replace(/\.png$/, "") + extension;
|
|
23577
23670
|
const companion = out.replace(/\.png$/, "") + ".pixelkiln.json";
|
|
23578
23671
|
const outputs = [
|
|
@@ -23592,7 +23685,7 @@ async function runMount(args) {
|
|
|
23592
23685
|
await provenanceFile("$lock", args.lock),
|
|
23593
23686
|
...qualityRecords,
|
|
23594
23687
|
...artifactSources.filter(
|
|
23595
|
-
(source) => source.id !== "$base" ||
|
|
23688
|
+
(source) => source.id !== "$base" || path48.resolve(source.path) !== out
|
|
23596
23689
|
)
|
|
23597
23690
|
],
|
|
23598
23691
|
options: {
|
|
@@ -23606,14 +23699,14 @@ async function runMount(args) {
|
|
|
23606
23699
|
log(
|
|
23607
23700
|
` ${styleId}: ${atlas.frames.length} cell(s) into ${atlas.sheet.width}x${atlas.sheet.height}` + (overBase ? ` over ${style.mount.base}` : " (new sheet)")
|
|
23608
23701
|
);
|
|
23609
|
-
log(` ${
|
|
23702
|
+
log(` ${path48.relative(process.cwd(), out)} + atlas/provenance JSON`);
|
|
23610
23703
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
23611
23704
|
}
|
|
23612
23705
|
}
|
|
23613
23706
|
async function runExport(args) {
|
|
23614
23707
|
const { loaded, specs, lock } = await openProject2(args);
|
|
23615
23708
|
const format = args.format ?? "generic";
|
|
23616
|
-
const manifestDir =
|
|
23709
|
+
const manifestDir = path48.dirname(path48.resolve(args.manifest));
|
|
23617
23710
|
const selected = specs.filter((spec) => {
|
|
23618
23711
|
if (spec.generator !== "tiles" && spec.generator !== "terrain") return false;
|
|
23619
23712
|
if (args.styles.length && !args.styles.includes(spec.styleId)) return false;
|
|
@@ -23629,12 +23722,12 @@ async function runExport(args) {
|
|
|
23629
23722
|
for (const spec of selected) {
|
|
23630
23723
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
23631
23724
|
const style = loaded.manifest.styles[spec.styleId];
|
|
23632
|
-
const defaultBase =
|
|
23633
|
-
const base = args.out ?
|
|
23725
|
+
const defaultBase = path48.resolve(manifestDir, style.outDir, `${spec.assetId}-tileset`);
|
|
23726
|
+
const base = args.out ? path48.resolve(args.out.replace(/\.(?:png|json|tsj|tres)$/i, "")) : defaultBase;
|
|
23634
23727
|
const result = exportTileset(entry, spec, {
|
|
23635
23728
|
format,
|
|
23636
23729
|
manifestDir,
|
|
23637
|
-
imageName:
|
|
23730
|
+
imageName: path48.basename(`${base}.png`),
|
|
23638
23731
|
columns: args.columns
|
|
23639
23732
|
});
|
|
23640
23733
|
const outputs = [
|
|
@@ -23652,7 +23745,7 @@ async function runExport(args) {
|
|
|
23652
23745
|
asset: spec.assetId,
|
|
23653
23746
|
columns: args.columns ?? null,
|
|
23654
23747
|
format,
|
|
23655
|
-
image:
|
|
23748
|
+
image: path48.basename(`${base}.png`),
|
|
23656
23749
|
providerRules: result.generic.providerRules,
|
|
23657
23750
|
style: spec.styleId,
|
|
23658
23751
|
tileType: spec.tileType ?? null
|
|
@@ -23662,7 +23755,7 @@ async function runExport(args) {
|
|
|
23662
23755
|
` ${spec.styleId}/${spec.assetId}: ${result.generic.tiles.length} tile(s), ${result.generic.sheet.width}x${result.generic.sheet.height} (${format})`
|
|
23663
23756
|
);
|
|
23664
23757
|
log(
|
|
23665
|
-
` ${
|
|
23758
|
+
` ${path48.relative(process.cwd(), base)}.png + ${path48.basename(base)}${result.extension} + .pixelkiln.json`
|
|
23666
23759
|
);
|
|
23667
23760
|
}
|
|
23668
23761
|
}
|
|
@@ -23676,9 +23769,9 @@ function sheetFormat(args) {
|
|
|
23676
23769
|
|
|
23677
23770
|
// src/cli/commands/pixellab-utils.ts
|
|
23678
23771
|
import { readFile as readFile33 } from "fs/promises";
|
|
23679
|
-
import
|
|
23772
|
+
import path49 from "path";
|
|
23680
23773
|
function loadKeys(args) {
|
|
23681
|
-
loadEnvFiles(
|
|
23774
|
+
loadEnvFiles(path49.dirname(path49.resolve(args.manifest)));
|
|
23682
23775
|
loadEnvFiles(process.cwd());
|
|
23683
23776
|
}
|
|
23684
23777
|
async function runUnzoom(args) {
|
|
@@ -23835,7 +23928,7 @@ async function runVfx(args) {
|
|
|
23835
23928
|
const fromRecipe = args.recipe ? await readVfxRecipe(args.recipe) : void 0;
|
|
23836
23929
|
const sprite = args.sprite ?? fromRecipe?.sprite;
|
|
23837
23930
|
const recipeName = typeof fromRecipe?.recipe.name === "string" ? fromRecipe.recipe.name : void 0;
|
|
23838
|
-
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ??
|
|
23931
|
+
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ?? path49.basename(paths.sheet, ".png"));
|
|
23839
23932
|
const from = args.preset ? `preset ${args.preset}` : args.recipe ? `recipe ${args.recipe}` : args.effect ? `saved effect ${args.effect}` : "nothing";
|
|
23840
23933
|
log(
|
|
23841
23934
|
` vfx ${name ? `"${name}"` : "(keeping its saved name)"} from ${from}${args.parts.length ? ` + ${args.parts.join(", ")}` : ""}${sprite ? ` around ${sprite}` : ""} \u2192 ${paths.sheet} (+ .gif, .json, .vfx.json${args.gamePack ? ", -game.zip" : ""})`
|
|
@@ -23902,7 +23995,7 @@ async function runVfxArtist(args, out) {
|
|
|
23902
23995
|
);
|
|
23903
23996
|
if (args.effect) {
|
|
23904
23997
|
log(
|
|
23905
|
-
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${
|
|
23998
|
+
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${path49.basename(paths.provenance)})` : `; ${path49.basename(paths.provenance)} holds no conversation for it, so PixelLab prices it as a new effect`)
|
|
23906
23999
|
);
|
|
23907
24000
|
}
|
|
23908
24001
|
log(` cost: about ${quote} generations by PixelLab's table, billed on delivery; at most ${ceiling} if the effect runs long`);
|
|
@@ -23950,11 +24043,11 @@ async function runVfxArtist(args, out) {
|
|
|
23950
24043
|
}
|
|
23951
24044
|
|
|
23952
24045
|
// src/cli/commands/quality.ts
|
|
23953
|
-
import
|
|
24046
|
+
import path51 from "path";
|
|
23954
24047
|
import { readFile as readFile35 } from "fs/promises";
|
|
23955
24048
|
|
|
23956
24049
|
// src/pipeline/quality-regression.ts
|
|
23957
|
-
import
|
|
24050
|
+
import path50 from "path";
|
|
23958
24051
|
import { existsSync as existsSync40 } from "fs";
|
|
23959
24052
|
import { readFile as readFile34 } from "fs/promises";
|
|
23960
24053
|
import { z as z13 } from "zod";
|
|
@@ -23962,7 +24055,7 @@ var SHA256_RE = /^[0-9a-f]{64}$/;
|
|
|
23962
24055
|
var HEX_RE = /^#[0-9a-f]{6}$/;
|
|
23963
24056
|
var MAX_REDMEAN_DISTANCE = 765;
|
|
23964
24057
|
var QualityPathSchema = z13.string().min(1).refine(
|
|
23965
|
-
(value) => !
|
|
24058
|
+
(value) => !path50.posix.isAbsolute(value) && !value.includes("\\"),
|
|
23966
24059
|
"expected a portable relative path"
|
|
23967
24060
|
);
|
|
23968
24061
|
var DEFAULT_QUALITY_TOLERANCES = {
|
|
@@ -24109,7 +24202,7 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
24109
24202
|
};
|
|
24110
24203
|
}
|
|
24111
24204
|
async function measureImageQuality(file) {
|
|
24112
|
-
const absolute =
|
|
24205
|
+
const absolute = path50.resolve(file);
|
|
24113
24206
|
let bytes;
|
|
24114
24207
|
try {
|
|
24115
24208
|
bytes = await readFile34(absolute);
|
|
@@ -24131,11 +24224,11 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
24131
24224
|
}
|
|
24132
24225
|
const ids = parsed.data.map((entry) => entry.id);
|
|
24133
24226
|
if (new Set(ids).size !== ids.length) throw new Error("--inputs contains a duplicate quality case id.");
|
|
24134
|
-
const root =
|
|
24227
|
+
const root = path50.dirname(path50.resolve(inputsFilePath));
|
|
24135
24228
|
return parsed.data.map((entry) => ({
|
|
24136
24229
|
id: entry.id,
|
|
24137
|
-
file:
|
|
24138
|
-
...entry.record ? { record:
|
|
24230
|
+
file: path50.resolve(root, entry.path),
|
|
24231
|
+
...entry.record ? { record: path50.resolve(root, entry.record) } : {},
|
|
24139
24232
|
tolerances: QualityToleranceSchema.parse({
|
|
24140
24233
|
...DEFAULT_QUALITY_TOLERANCES,
|
|
24141
24234
|
...entry.tolerances
|
|
@@ -24143,7 +24236,7 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
24143
24236
|
}));
|
|
24144
24237
|
}
|
|
24145
24238
|
function portableRelative2(from, to) {
|
|
24146
|
-
return
|
|
24239
|
+
return path50.relative(from, path50.resolve(to)).split(path50.sep).join("/") || ".";
|
|
24147
24240
|
}
|
|
24148
24241
|
async function verifyRecordForImage(recordPath, imagePath) {
|
|
24149
24242
|
const verification = await verifyArtifactBundle(recordPath);
|
|
@@ -24158,20 +24251,20 @@ async function verifyRecordForImage(recordPath, imagePath) {
|
|
|
24158
24251
|
if (record.kind !== "refine" || options === null || typeof options !== "object" || options.schema !== "pixelkiln-quality") {
|
|
24159
24252
|
throw new Error(`Quality record ${recordPath} is not a PixelKiln refinement record.`);
|
|
24160
24253
|
}
|
|
24161
|
-
const outputs = record.outputs.map((output) =>
|
|
24162
|
-
if (!outputs.includes(
|
|
24254
|
+
const outputs = record.outputs.map((output) => path50.resolve(path50.dirname(recordPath), output.path));
|
|
24255
|
+
if (!outputs.includes(path50.resolve(imagePath))) {
|
|
24163
24256
|
throw new Error(`Quality record ${recordPath} does not own ${imagePath}.`);
|
|
24164
24257
|
}
|
|
24165
24258
|
}
|
|
24166
24259
|
async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
24167
24260
|
if (!inputs.length) throw new Error("Cannot snapshot an empty quality baseline.");
|
|
24168
|
-
const absolute =
|
|
24261
|
+
const absolute = path50.resolve(baselinePath);
|
|
24169
24262
|
for (const input of inputs) {
|
|
24170
|
-
if (
|
|
24263
|
+
if (path50.resolve(input.file) === absolute || input.record && path50.resolve(input.record) === absolute) {
|
|
24171
24264
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
24172
24265
|
}
|
|
24173
24266
|
}
|
|
24174
|
-
const root =
|
|
24267
|
+
const root = path50.dirname(absolute);
|
|
24175
24268
|
const cases = [];
|
|
24176
24269
|
for (const input of [...inputs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
24177
24270
|
const expected = await measureImageQuality(input.file);
|
|
@@ -24211,7 +24304,7 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
24211
24304
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
24212
24305
|
}
|
|
24213
24306
|
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
24214
|
-
const absolute =
|
|
24307
|
+
const absolute = path50.resolve(baselinePath);
|
|
24215
24308
|
if (!existsSync40(absolute)) {
|
|
24216
24309
|
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
24217
24310
|
}
|
|
@@ -24227,12 +24320,12 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
24227
24320
|
if (unknown.length) {
|
|
24228
24321
|
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
24229
24322
|
}
|
|
24230
|
-
const root =
|
|
24323
|
+
const root = path50.dirname(absolute);
|
|
24231
24324
|
const cases = [...raw.cases];
|
|
24232
24325
|
const report = [];
|
|
24233
24326
|
for (const id of only) {
|
|
24234
24327
|
const input = byId.get(id);
|
|
24235
|
-
if (
|
|
24328
|
+
if (path50.resolve(input.file) === absolute || input.record && path50.resolve(input.record) === absolute) {
|
|
24236
24329
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
24237
24330
|
}
|
|
24238
24331
|
const expected = await measureImageQuality(input.file);
|
|
@@ -24268,7 +24361,7 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
24268
24361
|
return { baseline, path: absolute, changed, cases: report };
|
|
24269
24362
|
}
|
|
24270
24363
|
async function readQualityBaseline(baselinePath) {
|
|
24271
|
-
const absolute =
|
|
24364
|
+
const absolute = path50.resolve(baselinePath);
|
|
24272
24365
|
let raw;
|
|
24273
24366
|
try {
|
|
24274
24367
|
raw = JSON.parse(await readFile34(absolute, "utf8"));
|
|
@@ -24293,7 +24386,7 @@ async function readQualityBaseline(baselinePath) {
|
|
|
24293
24386
|
throw new Error(
|
|
24294
24387
|
`Invalid quality baseline ${absolute}:
|
|
24295
24388
|
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
24296
|
-
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${
|
|
24389
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path50.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
24297
24390
|
);
|
|
24298
24391
|
}
|
|
24299
24392
|
return parsed.data;
|
|
@@ -24355,12 +24448,12 @@ function regressionViolations(expected, actual, tolerances) {
|
|
|
24355
24448
|
return { violations, warnings };
|
|
24356
24449
|
}
|
|
24357
24450
|
async function checkQualityBaseline(baselinePath) {
|
|
24358
|
-
const absolute =
|
|
24451
|
+
const absolute = path50.resolve(baselinePath);
|
|
24359
24452
|
const baseline = await readQualityBaseline(absolute);
|
|
24360
|
-
const root =
|
|
24453
|
+
const root = path50.dirname(absolute);
|
|
24361
24454
|
const cases = [];
|
|
24362
24455
|
for (const entry of baseline.cases) {
|
|
24363
|
-
const file =
|
|
24456
|
+
const file = path50.resolve(root, entry.file);
|
|
24364
24457
|
let actual = null;
|
|
24365
24458
|
const violations = [];
|
|
24366
24459
|
const warnings = [];
|
|
@@ -24373,7 +24466,7 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
24373
24466
|
violations.push(message4(error));
|
|
24374
24467
|
}
|
|
24375
24468
|
if (entry.record) {
|
|
24376
|
-
const recordPath =
|
|
24469
|
+
const recordPath = path50.resolve(root, entry.record.path);
|
|
24377
24470
|
try {
|
|
24378
24471
|
const recordHash = await sha256File(recordPath);
|
|
24379
24472
|
if (recordHash !== entry.record.sha256) violations.push("quality record hash changed");
|
|
@@ -24415,15 +24508,15 @@ async function runQuality(args) {
|
|
|
24415
24508
|
if (!args.out) throw new Error("quality snapshot needs --out <pixelkiln.quality.json>.");
|
|
24416
24509
|
let raw;
|
|
24417
24510
|
try {
|
|
24418
|
-
raw = JSON.parse(await readFile35(
|
|
24511
|
+
raw = JSON.parse(await readFile35(path51.resolve(args.inputs), "utf8"));
|
|
24419
24512
|
} catch (error) {
|
|
24420
24513
|
throw new Error(
|
|
24421
|
-
`Could not read quality inputs ${
|
|
24514
|
+
`Could not read quality inputs ${path51.resolve(args.inputs)}: ${error instanceof Error ? error.message : String(error)}`,
|
|
24422
24515
|
{ cause: error }
|
|
24423
24516
|
);
|
|
24424
24517
|
}
|
|
24425
24518
|
const inputs = resolveQualityInputs(raw, args.inputs);
|
|
24426
|
-
if (
|
|
24519
|
+
if (path51.resolve(args.inputs) === path51.resolve(args.out)) {
|
|
24427
24520
|
throw new Error("quality snapshot --out must not overwrite its --inputs file.");
|
|
24428
24521
|
}
|
|
24429
24522
|
if (args.assets.length) {
|
|
@@ -24438,7 +24531,7 @@ async function runQuality(args) {
|
|
|
24438
24531
|
}
|
|
24439
24532
|
log(
|
|
24440
24533
|
`
|
|
24441
|
-
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${
|
|
24534
|
+
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${path51.relative(process.cwd(), result2.path)}; other cases left as they were.`
|
|
24442
24535
|
);
|
|
24443
24536
|
return;
|
|
24444
24537
|
}
|
|
@@ -24453,7 +24546,7 @@ async function runQuality(args) {
|
|
|
24453
24546
|
}, null, 2));
|
|
24454
24547
|
} else {
|
|
24455
24548
|
log(
|
|
24456
|
-
` ${result.changed ? "wrote" : "unchanged"} ${
|
|
24549
|
+
` ${result.changed ? "wrote" : "unchanged"} ${path51.relative(process.cwd(), result.path)} (${result.baseline.cases.length} case(s))`
|
|
24457
24550
|
);
|
|
24458
24551
|
log(` Review the tolerances, commit the baseline, then run quality check in CI.`);
|
|
24459
24552
|
}
|
|
@@ -24479,10 +24572,10 @@ async function runQuality(args) {
|
|
|
24479
24572
|
}
|
|
24480
24573
|
|
|
24481
24574
|
// src/cli/commands/recipe.ts
|
|
24482
|
-
import
|
|
24575
|
+
import path53 from "path";
|
|
24483
24576
|
|
|
24484
24577
|
// src/recipes.ts
|
|
24485
|
-
import
|
|
24578
|
+
import path52 from "path";
|
|
24486
24579
|
import { existsSync as existsSync41 } from "fs";
|
|
24487
24580
|
import { readdir as readdir3, readFile as readFile36 } from "fs/promises";
|
|
24488
24581
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
@@ -24493,7 +24586,7 @@ var VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
|
24493
24586
|
var RECIPE_FILE = "pixelkiln.recipe.json";
|
|
24494
24587
|
var RECIPE_DIR_TOKEN = "{{recipeDir}}";
|
|
24495
24588
|
var PortablePathSchema = z14.string().min(1).refine((value) => {
|
|
24496
|
-
if (value.includes("\\") ||
|
|
24589
|
+
if (value.includes("\\") || path52.posix.isAbsolute(value)) return false;
|
|
24497
24590
|
const parts = value.split("/");
|
|
24498
24591
|
return !parts.includes("") && !parts.includes(".") && !parts.includes("..");
|
|
24499
24592
|
}, "expected a portable relative path without '.', '..', or backslashes");
|
|
@@ -24669,7 +24762,7 @@ function message5(error) {
|
|
|
24669
24762
|
return error instanceof Error ? error.message : String(error);
|
|
24670
24763
|
}
|
|
24671
24764
|
async function readRecipeFile(recipePath, bundled) {
|
|
24672
|
-
const absolute =
|
|
24765
|
+
const absolute = path52.resolve(recipePath);
|
|
24673
24766
|
let raw;
|
|
24674
24767
|
try {
|
|
24675
24768
|
raw = JSON.parse(await readFile36(absolute, "utf8"));
|
|
@@ -24683,13 +24776,13 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
24683
24776
|
` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
|
|
24684
24777
|
);
|
|
24685
24778
|
}
|
|
24686
|
-
return { recipe: parsed.data, authored: raw, path: absolute, dir:
|
|
24779
|
+
return { recipe: parsed.data, authored: raw, path: absolute, dir: path52.dirname(absolute), bundled };
|
|
24687
24780
|
}
|
|
24688
24781
|
async function walkRecipeFiles(root) {
|
|
24689
24782
|
if (!existsSync41(root)) return [];
|
|
24690
24783
|
const out = [];
|
|
24691
24784
|
for (const entry of await readdir3(root, { withFileTypes: true })) {
|
|
24692
|
-
const resolved =
|
|
24785
|
+
const resolved = path52.join(root, entry.name);
|
|
24693
24786
|
if (entry.isDirectory()) out.push(...await walkRecipeFiles(resolved));
|
|
24694
24787
|
else if (entry.isFile() && entry.name === RECIPE_FILE) out.push(resolved);
|
|
24695
24788
|
}
|
|
@@ -24700,7 +24793,7 @@ function bundledRecipeRoot() {
|
|
|
24700
24793
|
}
|
|
24701
24794
|
async function listBundledRecipes(root = bundledRecipeRoot()) {
|
|
24702
24795
|
const recipes = await Promise.all(
|
|
24703
|
-
(await walkRecipeFiles(
|
|
24796
|
+
(await walkRecipeFiles(path52.resolve(root))).map((file) => readRecipeFile(file, true))
|
|
24704
24797
|
);
|
|
24705
24798
|
return recipes.sort(
|
|
24706
24799
|
(a, b) => a.recipe.id.localeCompare(b.recipe.id) || compareVersions(b.recipe.version, a.recipe.version)
|
|
@@ -24723,9 +24816,9 @@ function parseSelector(selector) {
|
|
|
24723
24816
|
return { id: match[1], version: match[2] };
|
|
24724
24817
|
}
|
|
24725
24818
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
24726
|
-
const local =
|
|
24819
|
+
const local = path52.resolve(target);
|
|
24727
24820
|
if (existsSync41(local)) {
|
|
24728
|
-
const recipePath =
|
|
24821
|
+
const recipePath = path52.basename(local) === RECIPE_FILE ? local : path52.join(local, RECIPE_FILE);
|
|
24729
24822
|
return readRecipeFile(recipePath, false);
|
|
24730
24823
|
}
|
|
24731
24824
|
if (target.startsWith(".") || target.startsWith("/") || target.includes("\\")) {
|
|
@@ -24739,7 +24832,7 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
24739
24832
|
return matches[0];
|
|
24740
24833
|
}
|
|
24741
24834
|
async function verifyFile(root, file) {
|
|
24742
|
-
const absolute =
|
|
24835
|
+
const absolute = path52.resolve(root, ...file.path.split("/"));
|
|
24743
24836
|
if (!existsSync41(absolute)) {
|
|
24744
24837
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
24745
24838
|
}
|
|
@@ -24755,7 +24848,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
24755
24848
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
24756
24849
|
const actualIntegrity = recipeDigest(loaded.authored);
|
|
24757
24850
|
const files = await Promise.all(loaded.recipe.files.map((file) => verifyFile(loaded.dir, file)));
|
|
24758
|
-
const modelRoot = options.modelRoot ?
|
|
24851
|
+
const modelRoot = options.modelRoot ? path52.resolve(options.modelRoot) : null;
|
|
24759
24852
|
const models = modelRoot ? await Promise.all(loaded.recipe.models.map(async (model) => ({
|
|
24760
24853
|
...await verifyFile(modelRoot, model),
|
|
24761
24854
|
source: model.source,
|
|
@@ -24789,7 +24882,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
24789
24882
|
};
|
|
24790
24883
|
}
|
|
24791
24884
|
function renderStyle(style, destination, cwd) {
|
|
24792
|
-
const portableDir =
|
|
24885
|
+
const portableDir = path52.relative(cwd, destination).split(path52.sep).join("/") || ".";
|
|
24793
24886
|
const replace = (value) => {
|
|
24794
24887
|
if (typeof value === "string") return value.replaceAll(RECIPE_DIR_TOKEN, portableDir);
|
|
24795
24888
|
if (Array.isArray(value)) return value.map(replace);
|
|
@@ -24801,19 +24894,19 @@ function renderStyle(style, destination, cwd) {
|
|
|
24801
24894
|
return replace(style);
|
|
24802
24895
|
}
|
|
24803
24896
|
async function installRecipe(target, options = {}) {
|
|
24804
|
-
const cwd =
|
|
24897
|
+
const cwd = path52.resolve(options.cwd ?? process.cwd());
|
|
24805
24898
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
24806
24899
|
const verification = await verifyRecipe(loaded.path);
|
|
24807
24900
|
if (!verification.ok) {
|
|
24808
24901
|
throw new Error(`Recipe ${loaded.recipe.id}@${loaded.recipe.version} failed integrity verification.`);
|
|
24809
24902
|
}
|
|
24810
|
-
const destination = options.out ?
|
|
24903
|
+
const destination = options.out ? path52.resolve(cwd, options.out) : path52.join(cwd, "pixelkiln-recipes", ...loaded.recipe.id.split("/"), loaded.recipe.version);
|
|
24811
24904
|
const sources = [
|
|
24812
24905
|
{ path: RECIPE_FILE, source: loaded.path },
|
|
24813
|
-
...loaded.recipe.files.map((file) => ({ path: file.path, source:
|
|
24906
|
+
...loaded.recipe.files.map((file) => ({ path: file.path, source: path52.join(loaded.dir, ...file.path.split("/")) }))
|
|
24814
24907
|
];
|
|
24815
24908
|
const files = await Promise.all(sources.map(async (file) => ({
|
|
24816
|
-
path:
|
|
24909
|
+
path: path52.join(destination, ...file.path.split("/")),
|
|
24817
24910
|
data: await readFile36(file.source)
|
|
24818
24911
|
})));
|
|
24819
24912
|
if (!options.force) {
|
|
@@ -24913,14 +25006,14 @@ async function runRecipe(args) {
|
|
|
24913
25006
|
}, null, 2));
|
|
24914
25007
|
} else {
|
|
24915
25008
|
log(` installed ${result.recipe.id}@${result.recipe.version}`);
|
|
24916
|
-
log(` ${
|
|
25009
|
+
log(` ${path53.relative(process.cwd(), result.destination) || "."}`);
|
|
24917
25010
|
log(`
|
|
24918
25011
|
Add this entry under your manifest's styles object:`);
|
|
24919
25012
|
log(JSON.stringify({ [result.styleId]: result.style }, null, 2));
|
|
24920
25013
|
if (result.recipe.models.length) {
|
|
24921
25014
|
log(`
|
|
24922
25015
|
Models are not downloaded automatically. Verify them with:`);
|
|
24923
|
-
log(` pixelkiln recipe verify ${
|
|
25016
|
+
log(` pixelkiln recipe verify ${path53.relative(process.cwd(), result.destination)} --model-root <ComfyUI/models>`);
|
|
24924
25017
|
}
|
|
24925
25018
|
}
|
|
24926
25019
|
return;
|
|
@@ -24928,7 +25021,7 @@ async function runRecipe(args) {
|
|
|
24928
25021
|
}
|
|
24929
25022
|
|
|
24930
25023
|
// src/cli/commands/refine.ts
|
|
24931
|
-
import
|
|
25024
|
+
import path54 from "path";
|
|
24932
25025
|
async function runRefine(args) {
|
|
24933
25026
|
if (args.from || args.subcommand === "approve") {
|
|
24934
25027
|
if (!args.from) {
|
|
@@ -24958,12 +25051,12 @@ async function runRefine(args) {
|
|
|
24958
25051
|
` recovered ${result3.detection.columns}x${result3.detection.rows} native grid (${result3.detection.confidence}: ${result3.detection.consensus})`
|
|
24959
25052
|
);
|
|
24960
25053
|
log(` enforced ${result3.palette.length}-color palette without dithering`);
|
|
24961
|
-
log(` wrote ${
|
|
24962
|
-
log(` quality record: ${
|
|
25054
|
+
log(` wrote ${path54.relative(process.cwd(), result3.output)}`);
|
|
25055
|
+
log(` quality record: ${path54.relative(process.cwd(), result3.record)}`);
|
|
24963
25056
|
log(`
|
|
24964
25057
|
Automated checks passed. Human 1\xD7 review is still required:`);
|
|
24965
25058
|
log(
|
|
24966
|
-
` pixelkiln refine approve --from ${
|
|
25059
|
+
` pixelkiln refine approve --from ${path54.relative(process.cwd(), result3.record)} --reviewer "Your Name"`
|
|
24967
25060
|
);
|
|
24968
25061
|
}
|
|
24969
25062
|
return;
|
|
@@ -24991,7 +25084,7 @@ async function runRefine(args) {
|
|
|
24991
25084
|
if (args.json) log(JSON.stringify(result3, null, 2));
|
|
24992
25085
|
else {
|
|
24993
25086
|
log(
|
|
24994
|
-
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${
|
|
25087
|
+
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${path54.relative(process.cwd(), result3.record)} by ${args.reviewer.trim()}` : ` approved ${path54.relative(process.cwd(), result3.output)} by ${args.reviewer.trim()}`
|
|
24995
25088
|
);
|
|
24996
25089
|
}
|
|
24997
25090
|
return;
|
|
@@ -25000,7 +25093,7 @@ async function runRefine(args) {
|
|
|
25000
25093
|
if (args.json) {
|
|
25001
25094
|
log(JSON.stringify(result2, null, 2));
|
|
25002
25095
|
} else {
|
|
25003
|
-
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${
|
|
25096
|
+
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${path54.relative(process.cwd(), result2.output || result2.record)}`);
|
|
25004
25097
|
for (const reason of result2.reasons) log(` ${reason}`);
|
|
25005
25098
|
}
|
|
25006
25099
|
if (!result2.safe) process.exitCode = 1;
|
|
@@ -25046,7 +25139,7 @@ async function runRefine(args) {
|
|
|
25046
25139
|
log(` ${item.state.padEnd(16)} ${item.key} ${item.reason}`);
|
|
25047
25140
|
if (item.state === "needs-approval") {
|
|
25048
25141
|
log(
|
|
25049
|
-
` pixelkiln refine approve --from ${
|
|
25142
|
+
` pixelkiln refine approve --from ${path54.relative(process.cwd(), item.record)} --reviewer "Your Name"`
|
|
25050
25143
|
);
|
|
25051
25144
|
}
|
|
25052
25145
|
}
|
|
@@ -25057,7 +25150,7 @@ async function runRefine(args) {
|
|
|
25057
25150
|
}
|
|
25058
25151
|
|
|
25059
25152
|
// src/cli/commands/skeleton.ts
|
|
25060
|
-
import
|
|
25153
|
+
import path55 from "path";
|
|
25061
25154
|
import { existsSync as existsSync42 } from "fs";
|
|
25062
25155
|
import { readFile as readFile37, writeFile as writeFile21 } from "fs/promises";
|
|
25063
25156
|
|
|
@@ -25170,12 +25263,12 @@ var Canvas = class {
|
|
|
25170
25263
|
async function runEstimateSkeleton(args) {
|
|
25171
25264
|
const image = args.target;
|
|
25172
25265
|
if (!image) throw new UsageError("estimate-skeleton needs an image path: pixelkiln estimate-skeleton <image> [--out keypoints.json]");
|
|
25173
|
-
if (args.out && existsSync42(
|
|
25266
|
+
if (args.out && existsSync42(path55.resolve(args.out)) && !args.force) {
|
|
25174
25267
|
throw new UsageError(`${args.out} already exists; pass --force to replace it`);
|
|
25175
25268
|
}
|
|
25176
|
-
loadEnvFiles(
|
|
25269
|
+
loadEnvFiles(path55.dirname(path55.resolve(args.manifest)));
|
|
25177
25270
|
loadEnvFiles(process.cwd());
|
|
25178
|
-
const bytes = await readFile37(
|
|
25271
|
+
const bytes = await readFile37(path55.resolve(image));
|
|
25179
25272
|
const metadata = imageMetadata(bytes);
|
|
25180
25273
|
if (!metadata) throw new UsageError(`${image} is not a readable PNG or JPEG`);
|
|
25181
25274
|
const sizeProblem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
|
|
@@ -25187,7 +25280,7 @@ async function runEstimateSkeleton(args) {
|
|
|
25187
25280
|
const frames = args.frames ?? DEFAULT_SCAFFOLD_FRAMES;
|
|
25188
25281
|
const json = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames), null, 2);
|
|
25189
25282
|
if (args.out) {
|
|
25190
|
-
await writeFile21(
|
|
25283
|
+
await writeFile21(path55.resolve(args.out), json + "\n");
|
|
25191
25284
|
log(` wrote ${args.out}: the estimated pose and ${frames} frames to edit`);
|
|
25192
25285
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
25193
25286
|
} else {
|
|
@@ -25200,8 +25293,8 @@ async function runSkeletonPreview(args) {
|
|
|
25200
25293
|
let sourceFile2;
|
|
25201
25294
|
let label;
|
|
25202
25295
|
if (target.endsWith(".json")) {
|
|
25203
|
-
keypointsFile =
|
|
25204
|
-
sourceFile2 = args.from ?
|
|
25296
|
+
keypointsFile = path55.resolve(target);
|
|
25297
|
+
sourceFile2 = args.from ? path55.resolve(args.from) : void 0;
|
|
25205
25298
|
label = target;
|
|
25206
25299
|
} else {
|
|
25207
25300
|
const loaded = await loadManifest(args.manifest);
|
|
@@ -25213,7 +25306,7 @@ async function runSkeletonPreview(args) {
|
|
|
25213
25306
|
);
|
|
25214
25307
|
}
|
|
25215
25308
|
keypointsFile = spec.revision.keypointsFile;
|
|
25216
|
-
sourceFile2 = args.from ?
|
|
25309
|
+
sourceFile2 = args.from ? path55.resolve(args.from) : spec.revision.sourceFile;
|
|
25217
25310
|
label = `${spec.styleId}/${spec.assetId}`;
|
|
25218
25311
|
}
|
|
25219
25312
|
if (!existsSync42(keypointsFile)) throw new UsageError(`Keypoints file does not exist yet: ${keypointsFile}`);
|
|
@@ -25234,10 +25327,10 @@ async function runSkeletonPreview(args) {
|
|
|
25234
25327
|
source = decodePng(bytes);
|
|
25235
25328
|
}
|
|
25236
25329
|
}
|
|
25237
|
-
const out =
|
|
25330
|
+
const out = path55.resolve(args.out ?? keypointsFile.replace(/\.json$/, "") + ".preview.png");
|
|
25238
25331
|
await writeFile21(out, renderSkeletonSheet(set, { source }));
|
|
25239
25332
|
log(` ${label}: ${set.frames.length} frames after the starting pose`);
|
|
25240
|
-
const shown =
|
|
25333
|
+
const shown = path55.relative(process.cwd(), out);
|
|
25241
25334
|
log(` wrote ${shown.startsWith("..") ? out : shown}`);
|
|
25242
25335
|
}
|
|
25243
25336
|
|
|
@@ -25283,15 +25376,15 @@ async function runTools(args) {
|
|
|
25283
25376
|
}
|
|
25284
25377
|
|
|
25285
25378
|
// src/cli/commands/workspace.ts
|
|
25286
|
-
import
|
|
25379
|
+
import path56 from "path";
|
|
25287
25380
|
import { existsSync as existsSync43 } from "fs";
|
|
25288
25381
|
async function runWorkspace(args) {
|
|
25289
|
-
const workspacePath =
|
|
25290
|
-
const dir =
|
|
25382
|
+
const workspacePath = path56.resolve(args.workspace ?? "pixelkiln.workspace.json");
|
|
25383
|
+
const dir = path56.dirname(workspacePath);
|
|
25291
25384
|
if (args.subcommand === "add") {
|
|
25292
|
-
const manifestPath =
|
|
25385
|
+
const manifestPath = path56.resolve(args.target);
|
|
25293
25386
|
const loadedTarget = await loadManifest(manifestPath);
|
|
25294
|
-
const lockPath = args.explicitLock ?
|
|
25387
|
+
const lockPath = args.explicitLock ? path56.resolve(args.explicitLock) : path56.join(path56.dirname(manifestPath), "pixelkiln.lock.json");
|
|
25295
25388
|
const ws = await loadWorkspace(workspacePath);
|
|
25296
25389
|
const id = args.name ?? loadedTarget.manifest.name;
|
|
25297
25390
|
if (ws.projects.some((p) => p.id === id)) {
|
|
@@ -25311,7 +25404,7 @@ async function runWorkspace(args) {
|
|
|
25311
25404
|
...args.account ? { account: args.account } : {}
|
|
25312
25405
|
};
|
|
25313
25406
|
await saveWorkspace(workspacePath, { version: 1, projects: [...ws.projects, project] });
|
|
25314
|
-
log(` registered "${id}" in ${
|
|
25407
|
+
log(` registered "${id}" in ${path56.relative(process.cwd(), workspacePath)}`);
|
|
25315
25408
|
log(` manifest: ${project.manifest}`);
|
|
25316
25409
|
log(` lock: ${project.lock}`);
|
|
25317
25410
|
if (!existsSync43(lockPath)) {
|
|
@@ -25323,7 +25416,7 @@ async function runWorkspace(args) {
|
|
|
25323
25416
|
}
|
|
25324
25417
|
if (args.subcommand === "remove") {
|
|
25325
25418
|
const ws = await loadWorkspace(workspacePath);
|
|
25326
|
-
const resolvedTarget =
|
|
25419
|
+
const resolvedTarget = path56.resolve(args.target);
|
|
25327
25420
|
const match = ws.projects.find(
|
|
25328
25421
|
(p) => p.id === args.target || resolveProject(dir, p).manifestPath === resolvedTarget
|
|
25329
25422
|
);
|
|
@@ -25334,7 +25427,7 @@ async function runWorkspace(args) {
|
|
|
25334
25427
|
version: 1,
|
|
25335
25428
|
projects: ws.projects.filter((p) => p !== match)
|
|
25336
25429
|
});
|
|
25337
|
-
log(` removed "${match.id}" from ${
|
|
25430
|
+
log(` removed "${match.id}" from ${path56.relative(process.cwd(), workspacePath)}`);
|
|
25338
25431
|
return;
|
|
25339
25432
|
}
|
|
25340
25433
|
if (args.subcommand === "list") {
|
|
@@ -25346,9 +25439,9 @@ async function runWorkspace(args) {
|
|
|
25346
25439
|
if (args.json) {
|
|
25347
25440
|
log(JSON.stringify({ version: 1, workspace: workspacePath, projects: ws.projects, diagnostics }, null, 2));
|
|
25348
25441
|
} else if (!ws.projects.length) {
|
|
25349
|
-
log(` no projects registered in ${
|
|
25442
|
+
log(` no projects registered in ${path56.relative(process.cwd(), workspacePath)}`);
|
|
25350
25443
|
} else {
|
|
25351
|
-
log(` ${ws.projects.length} project(s) in ${
|
|
25444
|
+
log(` ${ws.projects.length} project(s) in ${path56.relative(process.cwd(), workspacePath)}:`);
|
|
25352
25445
|
for (const p of ws.projects) {
|
|
25353
25446
|
log(` ${p.id.padEnd(24)} ${p.manifest.padEnd(40)} (${p.provider}${p.account ? `, ${p.account}` : ""})`);
|
|
25354
25447
|
}
|
|
@@ -25366,7 +25459,7 @@ async function runWorkspace(args) {
|
|
|
25366
25459
|
if (args.json) {
|
|
25367
25460
|
log(JSON.stringify({ ...report, workspace: workspacePath }, null, 2));
|
|
25368
25461
|
} else {
|
|
25369
|
-
log(` workspace: ${
|
|
25462
|
+
log(` workspace: ${path56.relative(process.cwd(), workspacePath)}`);
|
|
25370
25463
|
for (const p of report.projects) {
|
|
25371
25464
|
if (p.error) {
|
|
25372
25465
|
log(`
|