pixelkiln 0.95.0 → 0.96.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +608 -494
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +211 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +497 -38
- package/dist/index.d.ts +497 -38
- package/dist/index.js +210 -124
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +32 -0
- package/package.json +1 -1
package/dist/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)];
|
|
@@ -17607,7 +17847,27 @@ function handEditMembers(loaded, spec, lock, editPath) {
|
|
|
17607
17847
|
}
|
|
17608
17848
|
return [{ role: null, path: editPath, base: bases?.[0]?.path ?? null }];
|
|
17609
17849
|
}
|
|
17850
|
+
function refuseUneditable(spec) {
|
|
17851
|
+
const key2 = `${spec.styleId}/${spec.assetId}`;
|
|
17852
|
+
if (spec.derive) {
|
|
17853
|
+
const from = spec.derive.source.kind === "asset" ? spec.derive.source.assetId : spec.derive.source.file;
|
|
17854
|
+
throw new ManifestEditError(
|
|
17855
|
+
`${key2} is derived from ${from} (${spec.derive.transform}), so it has no hand edit of its own; edit its source, or change the derive transform in the manifest`
|
|
17856
|
+
);
|
|
17857
|
+
}
|
|
17858
|
+
if (spec.external) {
|
|
17859
|
+
throw new ManifestEditError(
|
|
17860
|
+
`${key2} is built outside pixelkiln (${spec.external.builder}); change it there, then run pixelkiln adopt --local --force to record the new file`
|
|
17861
|
+
);
|
|
17862
|
+
}
|
|
17863
|
+
if (spec.mirror) {
|
|
17864
|
+
throw new ManifestEditError(
|
|
17865
|
+
`${key2} is a flip of ${spec.mirror.sourceAssetId}, so it has no hand edit of its own; edit ${spec.mirror.sourceAssetId} and flip it again`
|
|
17866
|
+
);
|
|
17867
|
+
}
|
|
17868
|
+
}
|
|
17610
17869
|
async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
17870
|
+
refuseUneditable(spec);
|
|
17611
17871
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
17612
17872
|
if (entry && entry.outputs.length > 1 && !isMemberSetEntry(entry)) {
|
|
17613
17873
|
throw new ManifestEditError(
|
|
@@ -17619,18 +17879,18 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
17619
17879
|
`${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
17880
|
);
|
|
17621
17881
|
}
|
|
17622
|
-
const existing = spec.source ?
|
|
17882
|
+
const existing = spec.source ? path31.resolve(loaded.root, spec.source) : null;
|
|
17623
17883
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
17624
17884
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
17625
17885
|
let created = false;
|
|
17626
17886
|
for (const member of members) {
|
|
17627
|
-
if (
|
|
17887
|
+
if (existsSync24(member.path)) continue;
|
|
17628
17888
|
if (!member.base) {
|
|
17629
17889
|
throw new ManifestEditError(
|
|
17630
17890
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
17631
17891
|
);
|
|
17632
17892
|
}
|
|
17633
|
-
await mkdir12(
|
|
17893
|
+
await mkdir12(path31.dirname(member.path), { recursive: true });
|
|
17634
17894
|
await copyFile(member.base, member.path);
|
|
17635
17895
|
created = true;
|
|
17636
17896
|
}
|
|
@@ -17721,6 +17981,7 @@ async function readHandEditCompanion(editPath) {
|
|
|
17721
17981
|
}
|
|
17722
17982
|
var MAX_HAND_EDIT_BYTES = 16 * 1024 * 1024;
|
|
17723
17983
|
async function saveHandEdit(loaded, lock, spec, input) {
|
|
17984
|
+
refuseUneditable(spec);
|
|
17724
17985
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
17725
17986
|
const memberSet = entry ? isMemberSetEntry(entry) : false;
|
|
17726
17987
|
const incoming = input.frames ?? (input.png ? [{ role: null, png: input.png }] : []);
|
|
@@ -17768,7 +18029,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
17768
18029
|
editor: input.editor,
|
|
17769
18030
|
protocol: input.protocol,
|
|
17770
18031
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
17771
|
-
project: projectPath ?
|
|
18032
|
+
project: projectPath ? path31.basename(projectPath) : null,
|
|
17772
18033
|
outputs: incoming.map((frame, index) => ({
|
|
17773
18034
|
role: frame.role,
|
|
17774
18035
|
basedOn: basedOnHash(entry, index),
|
|
@@ -17828,7 +18089,7 @@ async function runEdit(args) {
|
|
|
17828
18089
|
const set = started.members.length > 1;
|
|
17829
18090
|
const kind = spec.generator === "frames" ? "frames" : "members";
|
|
17830
18091
|
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 ?? ""} ${
|
|
18092
|
+
if (set) for (const member of started.members) log(` ${member.role ?? ""} ${path32.relative(process.cwd(), member.path)}`);
|
|
17832
18093
|
if (args.noOpen) {
|
|
17833
18094
|
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
18095
|
} else {
|
|
@@ -17838,24 +18099,24 @@ async function runEdit(args) {
|
|
|
17838
18099
|
}
|
|
17839
18100
|
|
|
17840
18101
|
// src/cli/commands/gallery.ts
|
|
17841
|
-
import
|
|
18102
|
+
import path41 from "path";
|
|
17842
18103
|
import { existsSync as existsSync33 } from "fs";
|
|
17843
18104
|
|
|
17844
18105
|
// src/gallery/snapshot.ts
|
|
17845
18106
|
import { createHash as createHash4 } from "crypto";
|
|
17846
18107
|
import { existsSync as existsSync28 } from "fs";
|
|
17847
18108
|
import { readFile as readFile24, stat as stat2 } from "fs/promises";
|
|
17848
|
-
import
|
|
18109
|
+
import path37 from "path";
|
|
17849
18110
|
|
|
17850
18111
|
// src/gallery/edit.ts
|
|
17851
18112
|
import { readFile as readFile23, rename as rename10, writeFile as writeFile18 } from "fs/promises";
|
|
17852
|
-
import
|
|
18113
|
+
import path36 from "path";
|
|
17853
18114
|
import { z as z11 } from "zod";
|
|
17854
18115
|
|
|
17855
18116
|
// src/gallery/upload.ts
|
|
17856
|
-
import { existsSync as
|
|
18117
|
+
import { existsSync as existsSync25 } from "fs";
|
|
17857
18118
|
import { mkdir as mkdir13, writeFile as writeFile15 } from "fs/promises";
|
|
17858
|
-
import
|
|
18119
|
+
import path33 from "path";
|
|
17859
18120
|
import { z as z8 } from "zod";
|
|
17860
18121
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
17861
18122
|
var UploadImageSchema = z8.object({
|
|
@@ -17868,12 +18129,12 @@ var UploadImageSchema = z8.object({
|
|
|
17868
18129
|
overwrite: z8.boolean().optional()
|
|
17869
18130
|
}).strict();
|
|
17870
18131
|
async function saveProjectImage(root, request) {
|
|
17871
|
-
const file =
|
|
17872
|
-
const relative =
|
|
17873
|
-
if (relative.startsWith("..") ||
|
|
18132
|
+
const file = path33.resolve(root, request.path);
|
|
18133
|
+
const relative = path33.relative(root, file);
|
|
18134
|
+
if (relative.startsWith("..") || path33.isAbsolute(relative)) {
|
|
17874
18135
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
17875
18136
|
}
|
|
17876
|
-
const extension =
|
|
18137
|
+
const extension = path33.extname(file).toLowerCase();
|
|
17877
18138
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
17878
18139
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
17879
18140
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -17885,18 +18146,18 @@ async function saveProjectImage(root, request) {
|
|
|
17885
18146
|
if (metadata.format !== expected) {
|
|
17886
18147
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
17887
18148
|
}
|
|
17888
|
-
if (
|
|
17889
|
-
throw new ManifestEditError(`${relative.split(
|
|
18149
|
+
if (existsSync25(file) && !request.overwrite) {
|
|
18150
|
+
throw new ManifestEditError(`${relative.split(path33.sep).join("/")} already exists; choose another name, or replace it`);
|
|
17890
18151
|
}
|
|
17891
|
-
await mkdir13(
|
|
18152
|
+
await mkdir13(path33.dirname(file), { recursive: true });
|
|
17892
18153
|
await writeFile15(file, bytes);
|
|
17893
|
-
return relative.split(
|
|
18154
|
+
return relative.split(path33.sep).join("/");
|
|
17894
18155
|
}
|
|
17895
18156
|
|
|
17896
18157
|
// src/gallery/image-revision.ts
|
|
17897
|
-
import { existsSync as
|
|
18158
|
+
import { existsSync as existsSync26 } from "fs";
|
|
17898
18159
|
import { readFile as readFile21, rm as rm9, writeFile as writeFile16 } from "fs/promises";
|
|
17899
|
-
import
|
|
18160
|
+
import path34 from "path";
|
|
17900
18161
|
import { z as z9 } from "zod";
|
|
17901
18162
|
var InpaintRevisionRequestSchema = z9.object({
|
|
17902
18163
|
action: z9.literal("create-inpaint-revision"),
|
|
@@ -17915,15 +18176,15 @@ var InpaintRevisionRequestSchema = z9.object({
|
|
|
17915
18176
|
overwrite: z9.boolean().optional()
|
|
17916
18177
|
}).strict();
|
|
17917
18178
|
async function createInpaintRevision(manifestPath, request) {
|
|
17918
|
-
const root =
|
|
17919
|
-
if (
|
|
18179
|
+
const root = path34.dirname(path34.resolve(manifestPath));
|
|
18180
|
+
if (path34.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
17920
18181
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
17921
18182
|
}
|
|
17922
18183
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
17923
18184
|
const metadata = imageMetadata(bytes);
|
|
17924
18185
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
17925
|
-
const file =
|
|
17926
|
-
const previous =
|
|
18186
|
+
const file = path34.resolve(root, request.maskPath);
|
|
18187
|
+
const previous = existsSync26(file) ? await readFile21(file) : null;
|
|
17927
18188
|
const mask = await saveProjectImage(root, {
|
|
17928
18189
|
action: "upload-image",
|
|
17929
18190
|
path: request.maskPath,
|
|
@@ -17950,9 +18211,9 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
17950
18211
|
}
|
|
17951
18212
|
|
|
17952
18213
|
// src/gallery/skeleton.ts
|
|
17953
|
-
import { existsSync as
|
|
18214
|
+
import { existsSync as existsSync27 } from "fs";
|
|
17954
18215
|
import { mkdir as mkdir14, readFile as readFile22, rm as rm10, writeFile as writeFile17 } from "fs/promises";
|
|
17955
|
-
import
|
|
18216
|
+
import path35 from "path";
|
|
17956
18217
|
import { z as z10 } from "zod";
|
|
17957
18218
|
var SkeletonEstimateRequestSchema = z10.object({
|
|
17958
18219
|
project: z10.string().min(1).optional(),
|
|
@@ -17992,8 +18253,8 @@ var SkeletonKeypointsUpdateSchema = z10.object({
|
|
|
17992
18253
|
}).strict();
|
|
17993
18254
|
var DEFAULT_ESTIMATE_LIMIT = 10;
|
|
17994
18255
|
function skeletonSourceFile(spec) {
|
|
17995
|
-
if (spec.source) return
|
|
17996
|
-
if (spec.quality &&
|
|
18256
|
+
if (spec.source) return path35.resolve(spec.root, spec.source);
|
|
18257
|
+
if (spec.quality && existsSync27(spec.quality.outFile)) return spec.quality.outFile;
|
|
17997
18258
|
return spec.outFile;
|
|
17998
18259
|
}
|
|
17999
18260
|
function createGallerySkeletonHandlers(opts) {
|
|
@@ -18014,10 +18275,10 @@ function createGallerySkeletonHandlers(opts) {
|
|
|
18014
18275
|
const spec = ctx.specs.find((candidate) => lockKey(candidate.styleId, candidate.assetId) === key2);
|
|
18015
18276
|
if (!spec) throw new ManifestEditError(`"${key2}" is not declared by the manifest`);
|
|
18016
18277
|
const file = skeletonSourceFile(spec);
|
|
18017
|
-
if (!
|
|
18278
|
+
if (!existsSync27(file)) throw new ManifestEditError(`${key2} has no image on disk to estimate from`);
|
|
18018
18279
|
const bytes = await readFile22(file);
|
|
18019
18280
|
const metadata = imageMetadata(bytes);
|
|
18020
|
-
if (!metadata) throw new ManifestEditError(`${
|
|
18281
|
+
if (!metadata) throw new ManifestEditError(`${path35.basename(file)} is not a readable PNG or JPEG`);
|
|
18021
18282
|
const problem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
|
|
18022
18283
|
if (problem) throw new ManifestEditError(`${key2} is ${problem}`);
|
|
18023
18284
|
if (used >= limit) {
|
|
@@ -18034,7 +18295,7 @@ function createGallerySkeletonHandlers(opts) {
|
|
|
18034
18295
|
log2(` estimated a skeleton for ${key2} (PixelLab estimate-skeleton, ${used}/${limit} this session${billed ? `, billed ${billed.amount} ${billed.unit}` : ""})`);
|
|
18035
18296
|
return {
|
|
18036
18297
|
set: scaffoldSkeletonSet(res.keypoints, request.frames ?? DEFAULT_SCAFFOLD_FRAMES),
|
|
18037
|
-
source:
|
|
18298
|
+
source: path35.relative(ctx.loaded.root, file).split(path35.sep).join("/"),
|
|
18038
18299
|
session: status()
|
|
18039
18300
|
};
|
|
18040
18301
|
}
|
|
@@ -18048,20 +18309,20 @@ function billedAmount(usage) {
|
|
|
18048
18309
|
return typeof amount === "number" && Number.isFinite(amount) ? { unit: type, amount } : null;
|
|
18049
18310
|
}
|
|
18050
18311
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
18051
|
-
const root =
|
|
18052
|
-
const file =
|
|
18053
|
-
const relative =
|
|
18054
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
18312
|
+
const root = path35.dirname(path35.resolve(manifestPath));
|
|
18313
|
+
const file = path35.resolve(root, request.keypointsFile);
|
|
18314
|
+
const relative = path35.relative(root, file);
|
|
18315
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path35.isAbsolute(relative)) {
|
|
18055
18316
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
18056
18317
|
}
|
|
18057
|
-
const existed =
|
|
18318
|
+
const existed = existsSync27(file);
|
|
18058
18319
|
let previous = null;
|
|
18059
18320
|
if (request.set) {
|
|
18060
18321
|
if (existed && !request.overwrite) {
|
|
18061
18322
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
18062
18323
|
}
|
|
18063
18324
|
if (existed) previous = await readFile22(file);
|
|
18064
|
-
await mkdir14(
|
|
18325
|
+
await mkdir14(path35.dirname(file), { recursive: true });
|
|
18065
18326
|
await writeFile17(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18066
18327
|
} else if (!existed) {
|
|
18067
18328
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
@@ -18077,7 +18338,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
18077
18338
|
revision: {
|
|
18078
18339
|
mode: "animate-skeleton",
|
|
18079
18340
|
from: request.from,
|
|
18080
|
-
keypointsFile: relative.split(
|
|
18341
|
+
keypointsFile: relative.split(path35.sep).join("/"),
|
|
18081
18342
|
direction: request.direction,
|
|
18082
18343
|
description: request.description,
|
|
18083
18344
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -18098,19 +18359,19 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
18098
18359
|
if (!spec) throw new ManifestEditError(`"${key2}" is not declared by the manifest`);
|
|
18099
18360
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
18100
18361
|
if (!file) throw new ManifestEditError(`${key2} is not an animate-skeleton revision`);
|
|
18101
|
-
const relative =
|
|
18102
|
-
if (relative.startsWith("..") ||
|
|
18362
|
+
const relative = path35.relative(ctx.loaded.root, file);
|
|
18363
|
+
if (relative.startsWith("..") || path35.isAbsolute(relative)) {
|
|
18103
18364
|
throw new ManifestEditError(`${key2}'s keypoints file is outside the project; edit it by hand`);
|
|
18104
18365
|
}
|
|
18105
|
-
const current =
|
|
18366
|
+
const current = existsSync27(file) ? sha256(await readFile22(file)) : null;
|
|
18106
18367
|
if (current !== request.expectedSha256) {
|
|
18107
18368
|
throw Object.assign(
|
|
18108
|
-
new Error(`${relative.split(
|
|
18369
|
+
new Error(`${relative.split(path35.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
18109
18370
|
{ status: 409 }
|
|
18110
18371
|
);
|
|
18111
18372
|
}
|
|
18112
18373
|
await writeFile17(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
18113
|
-
return relative.split(
|
|
18374
|
+
return relative.split(path35.sep).join("/");
|
|
18114
18375
|
}
|
|
18115
18376
|
|
|
18116
18377
|
// src/gallery/edit.ts
|
|
@@ -18164,7 +18425,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18164
18425
|
const history = /* @__PURE__ */ new Map();
|
|
18165
18426
|
const manifestOf = async (project) => {
|
|
18166
18427
|
try {
|
|
18167
|
-
return
|
|
18428
|
+
return path36.resolve(await opts.manifestFor(typeof project === "string" ? project : void 0));
|
|
18168
18429
|
} catch {
|
|
18169
18430
|
return null;
|
|
18170
18431
|
}
|
|
@@ -18187,7 +18448,7 @@ function createGalleryEditHandler(opts) {
|
|
|
18187
18448
|
await writeFile18(tmp, last.before);
|
|
18188
18449
|
await rename10(tmp, manifestPath2);
|
|
18189
18450
|
stack.pop();
|
|
18190
|
-
log2(` manifest edit undone in ${
|
|
18451
|
+
log2(` manifest edit undone in ${path36.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
18191
18452
|
return opts.reload();
|
|
18192
18453
|
}
|
|
18193
18454
|
const manifestPath = await manifestOf(body?.project);
|
|
@@ -18249,7 +18510,7 @@ function createEditApplier(opts, log2) {
|
|
|
18249
18510
|
} catch (error) {
|
|
18250
18511
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
18251
18512
|
}
|
|
18252
|
-
const written = await saveProjectImage(
|
|
18513
|
+
const written = await saveProjectImage(path36.dirname(path36.resolve(manifestPath2)), upload.data);
|
|
18253
18514
|
log2(` image added: ${written}`);
|
|
18254
18515
|
return opts.reload();
|
|
18255
18516
|
}
|
|
@@ -18316,7 +18577,7 @@ function createEditApplier(opts, log2) {
|
|
|
18316
18577
|
}
|
|
18317
18578
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
18318
18579
|
if (result.changed) {
|
|
18319
|
-
const relative =
|
|
18580
|
+
const relative = path36.relative(process.cwd(), result.manifestPath);
|
|
18320
18581
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
18321
18582
|
log2(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
18322
18583
|
}
|
|
@@ -18366,163 +18627,10 @@ function createGalleryPriceHandler(opts) {
|
|
|
18366
18627
|
};
|
|
18367
18628
|
}
|
|
18368
18629
|
|
|
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
18630
|
// src/gallery/snapshot.ts
|
|
18523
18631
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
18524
18632
|
function galleryMediaId(absolutePath) {
|
|
18525
|
-
return createHash4("sha256").update(
|
|
18633
|
+
return createHash4("sha256").update(path37.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
18526
18634
|
}
|
|
18527
18635
|
function galleryMediaRoute(id) {
|
|
18528
18636
|
return `/media/${id}`;
|
|
@@ -18546,7 +18654,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
18546
18654
|
return (entry.history ?? []).map((generation, i) => {
|
|
18547
18655
|
const outputs = generation.outputs.map((output) => {
|
|
18548
18656
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
18549
|
-
const file =
|
|
18657
|
+
const file = path37.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
18550
18658
|
let url = null;
|
|
18551
18659
|
if (existsSync28(file)) {
|
|
18552
18660
|
const id = galleryMediaId(file);
|
|
@@ -18678,9 +18786,9 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
18678
18786
|
async function describeQuality(media, root, inspection) {
|
|
18679
18787
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
18680
18788
|
const outputs = await Promise.all(
|
|
18681
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
18789
|
+
outputPaths.map((file) => describeOutput(media, root, path37.resolve(root, file)))
|
|
18682
18790
|
);
|
|
18683
|
-
const recordPath =
|
|
18791
|
+
const recordPath = path37.resolve(root, inspection.record);
|
|
18684
18792
|
const recordExists = existsSync28(recordPath);
|
|
18685
18793
|
let options = null;
|
|
18686
18794
|
let check = null;
|
|
@@ -18700,7 +18808,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
18700
18808
|
return {
|
|
18701
18809
|
state: inspection.state,
|
|
18702
18810
|
reason: inspection.reason,
|
|
18703
|
-
output: portableOutputPath(
|
|
18811
|
+
output: portableOutputPath(path37.resolve(root, inspection.output), root),
|
|
18704
18812
|
record: portableOutputPath(recordPath, root),
|
|
18705
18813
|
recordExists,
|
|
18706
18814
|
outputs,
|
|
@@ -18740,7 +18848,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18740
18848
|
const items = [];
|
|
18741
18849
|
const manifestText = await readFile24(loaded.path, "utf8");
|
|
18742
18850
|
const manifestSha256 = sha256(manifestText);
|
|
18743
|
-
const cacheDir =
|
|
18851
|
+
const cacheDir = path37.resolve(path37.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
18744
18852
|
let rawStyles = {};
|
|
18745
18853
|
try {
|
|
18746
18854
|
const raw = JSON.parse(manifestText);
|
|
@@ -18764,7 +18872,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18764
18872
|
)
|
|
18765
18873
|
);
|
|
18766
18874
|
if (spec.source) {
|
|
18767
|
-
const editPath =
|
|
18875
|
+
const editPath = path37.resolve(root, spec.source);
|
|
18768
18876
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
18769
18877
|
const editShas = await Promise.all(
|
|
18770
18878
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
@@ -18813,7 +18921,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
18813
18921
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
18814
18922
|
}
|
|
18815
18923
|
} else if (spec.source) {
|
|
18816
|
-
outputs = [await describeOutput(media, root,
|
|
18924
|
+
outputs = [await describeOutput(media, root, path37.resolve(root, spec.source))];
|
|
18817
18925
|
} else if (!entry && existsSync28(spec.outFile)) {
|
|
18818
18926
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
18819
18927
|
} else {
|
|
@@ -19018,7 +19126,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19018
19126
|
id: loaded.manifest.name,
|
|
19019
19127
|
name: loaded.manifest.name,
|
|
19020
19128
|
manifest: loaded.path,
|
|
19021
|
-
lock:
|
|
19129
|
+
lock: path37.resolve(opts.lockPath),
|
|
19022
19130
|
root,
|
|
19023
19131
|
provider: loaded.manifest.provider,
|
|
19024
19132
|
account: null,
|
|
@@ -19044,7 +19152,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19044
19152
|
return { snapshot, media };
|
|
19045
19153
|
}
|
|
19046
19154
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
19047
|
-
const dir =
|
|
19155
|
+
const dir = path37.dirname(path37.resolve(opts.workspacePath));
|
|
19048
19156
|
const media = /* @__PURE__ */ new Map();
|
|
19049
19157
|
const projects = [];
|
|
19050
19158
|
const items = [];
|
|
@@ -19087,7 +19195,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19087
19195
|
id: project.id,
|
|
19088
19196
|
name: loaded.manifest.name,
|
|
19089
19197
|
manifest: manifestPath,
|
|
19090
|
-
lock:
|
|
19198
|
+
lock: path37.resolve(lockPath),
|
|
19091
19199
|
root: loaded.root,
|
|
19092
19200
|
provider: loaded.manifest.provider,
|
|
19093
19201
|
account: project.account ?? null,
|
|
@@ -19103,8 +19211,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19103
19211
|
id: project.id,
|
|
19104
19212
|
name: project.id,
|
|
19105
19213
|
manifest: manifestPath,
|
|
19106
|
-
lock:
|
|
19107
|
-
root:
|
|
19214
|
+
lock: path37.resolve(lockPath),
|
|
19215
|
+
root: path37.dirname(manifestPath),
|
|
19108
19216
|
provider: project.provider,
|
|
19109
19217
|
account: project.account ?? null,
|
|
19110
19218
|
manifestSha256: null,
|
|
@@ -19131,7 +19239,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
19131
19239
|
version: 1,
|
|
19132
19240
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
19133
19241
|
project: null,
|
|
19134
|
-
workspace: { path:
|
|
19242
|
+
workspace: { path: path37.resolve(opts.workspacePath), dir, projects },
|
|
19135
19243
|
filter,
|
|
19136
19244
|
totals: {
|
|
19137
19245
|
entries: projects.reduce((sum, project) => sum + project.entries, 0),
|
|
@@ -20048,7 +20156,7 @@ import { readFile as readFile27 } from "fs/promises";
|
|
|
20048
20156
|
// src/pipeline/init.ts
|
|
20049
20157
|
import { readdir, readFile as readFile26, writeFile as writeFile19 } from "fs/promises";
|
|
20050
20158
|
import { existsSync as existsSync30 } from "fs";
|
|
20051
|
-
import
|
|
20159
|
+
import path38 from "path";
|
|
20052
20160
|
function pngSize(buf) {
|
|
20053
20161
|
if (buf.length < 24) return null;
|
|
20054
20162
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -20062,7 +20170,7 @@ function slugify(value) {
|
|
|
20062
20170
|
async function walk(dir, exclude) {
|
|
20063
20171
|
const out = [];
|
|
20064
20172
|
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
20065
|
-
const full =
|
|
20173
|
+
const full = path38.join(dir, entry.name);
|
|
20066
20174
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
20067
20175
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
20068
20176
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -20081,9 +20189,9 @@ async function scanAssets(root, opts = {}) {
|
|
|
20081
20189
|
skipped.push(`${file} (not a readable PNG)`);
|
|
20082
20190
|
continue;
|
|
20083
20191
|
}
|
|
20084
|
-
const rel =
|
|
20085
|
-
const category =
|
|
20086
|
-
let id = slugify(
|
|
20192
|
+
const rel = path38.relative(root, file);
|
|
20193
|
+
const category = path38.dirname(rel) === "." ? "" : path38.dirname(rel);
|
|
20194
|
+
let id = slugify(path38.basename(rel));
|
|
20087
20195
|
if (seen.has(id)) {
|
|
20088
20196
|
const n = seen.get(id) + 1;
|
|
20089
20197
|
seen.set(id, n);
|
|
@@ -21132,14 +21240,14 @@ function createGenerateHandlers(opts) {
|
|
|
21132
21240
|
|
|
21133
21241
|
// src/gallery/editor.ts
|
|
21134
21242
|
import { readFile as readFile29 } from "fs/promises";
|
|
21135
|
-
import
|
|
21243
|
+
import path40 from "path";
|
|
21136
21244
|
|
|
21137
21245
|
// src/editor/install.ts
|
|
21138
21246
|
import { createHash as createHash5 } from "crypto";
|
|
21139
21247
|
import { existsSync as existsSync32 } from "fs";
|
|
21140
21248
|
import { mkdir as mkdir15, readFile as readFile28, rename as rename11, rm as rm11, stat as stat3, writeFile as writeFile20 } from "fs/promises";
|
|
21141
21249
|
import os3 from "os";
|
|
21142
|
-
import
|
|
21250
|
+
import path39 from "path";
|
|
21143
21251
|
|
|
21144
21252
|
// tools/pixelorama-bridge/pin.json
|
|
21145
21253
|
var pin_default = {
|
|
@@ -21203,15 +21311,15 @@ var EditorInstallError = class extends Error {
|
|
|
21203
21311
|
};
|
|
21204
21312
|
function editorToolsRoot() {
|
|
21205
21313
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
21206
|
-
if (override) return
|
|
21207
|
-
if (process.platform === "darwin") return
|
|
21314
|
+
if (override) return path39.resolve(override);
|
|
21315
|
+
if (process.platform === "darwin") return path39.join(os3.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
21208
21316
|
if (process.platform === "win32") {
|
|
21209
|
-
return
|
|
21317
|
+
return path39.join(process.env.LOCALAPPDATA ?? path39.join(os3.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
21210
21318
|
}
|
|
21211
|
-
return
|
|
21319
|
+
return path39.join(process.env.XDG_CACHE_HOME ?? path39.join(os3.homedir(), ".cache"), "pixelkiln", "tools");
|
|
21212
21320
|
}
|
|
21213
21321
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
21214
|
-
return
|
|
21322
|
+
return path39.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
21215
21323
|
}
|
|
21216
21324
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
21217
21325
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -21234,7 +21342,7 @@ async function editorStatus(opts = {}) {
|
|
|
21234
21342
|
let totalBytes = 0;
|
|
21235
21343
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
21236
21344
|
totalBytes += expected.bytes;
|
|
21237
|
-
const file =
|
|
21345
|
+
const file = path39.join(dir, name);
|
|
21238
21346
|
const info = existsSync32(file) ? await stat3(file).catch(() => null) : null;
|
|
21239
21347
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
21240
21348
|
installedBytes += expected.bytes;
|
|
@@ -21292,7 +21400,7 @@ async function installEditor(opts = {}) {
|
|
|
21292
21400
|
if (digest2 !== expected.sha256) {
|
|
21293
21401
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
21294
21402
|
}
|
|
21295
|
-
const final =
|
|
21403
|
+
const final = path39.join(dir, name);
|
|
21296
21404
|
const tmp = `${final}.${process.pid}.part`;
|
|
21297
21405
|
try {
|
|
21298
21406
|
await writeFile20(tmp, bytes);
|
|
@@ -21338,7 +21446,7 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
21338
21446
|
".json": "application/json; charset=utf-8"
|
|
21339
21447
|
};
|
|
21340
21448
|
function editorContentType(name) {
|
|
21341
|
-
return EDITOR_CONTENT_TYPES[
|
|
21449
|
+
return EDITOR_CONTENT_TYPES[path39.extname(name).toLowerCase()] ?? null;
|
|
21342
21450
|
}
|
|
21343
21451
|
|
|
21344
21452
|
// src/gallery/editor.ts
|
|
@@ -21414,7 +21522,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
21414
21522
|
if (!status.installed) return null;
|
|
21415
21523
|
let bytes;
|
|
21416
21524
|
try {
|
|
21417
|
-
bytes = await readFile29(
|
|
21525
|
+
bytes = await readFile29(path40.join(dir, name));
|
|
21418
21526
|
} catch {
|
|
21419
21527
|
verified = null;
|
|
21420
21528
|
return null;
|
|
@@ -21454,7 +21562,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
21454
21562
|
};
|
|
21455
21563
|
const loadProject = async (project) => {
|
|
21456
21564
|
const ctx = await access2.loadProject(project);
|
|
21457
|
-
loadProjectEnv(
|
|
21565
|
+
loadProjectEnv(path41.dirname(ctx.loaded.path));
|
|
21458
21566
|
return ctx;
|
|
21459
21567
|
};
|
|
21460
21568
|
const loadProjectEnv = (dir) => {
|
|
@@ -21463,7 +21571,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
21463
21571
|
for (const [name, value] of Object.entries(declared)) {
|
|
21464
21572
|
if (credentialNames.has(name) && name in process.env && process.env[name] !== value) {
|
|
21465
21573
|
throw new Error(
|
|
21466
|
-
`${
|
|
21574
|
+
`${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
21575
|
);
|
|
21468
21576
|
}
|
|
21469
21577
|
}
|
|
@@ -21471,7 +21579,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
21471
21579
|
};
|
|
21472
21580
|
const quoters = /* @__PURE__ */ new Map();
|
|
21473
21581
|
const quoteFor = async (project) => {
|
|
21474
|
-
loadProjectEnv(
|
|
21582
|
+
loadProjectEnv(path41.dirname(path41.resolve(await access2.manifestFor(project))));
|
|
21475
21583
|
const key2 = process.env.PIXELLAB_API_KEY;
|
|
21476
21584
|
if (!key2) return null;
|
|
21477
21585
|
let quoter = quoters.get(key2);
|
|
@@ -21522,7 +21630,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
21522
21630
|
}
|
|
21523
21631
|
async function runGallery(args) {
|
|
21524
21632
|
if (args.workspace) {
|
|
21525
|
-
const workspacePath =
|
|
21633
|
+
const workspacePath = path41.resolve(args.workspace);
|
|
21526
21634
|
if (!existsSync33(workspacePath)) {
|
|
21527
21635
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
21528
21636
|
}
|
|
@@ -21543,7 +21651,7 @@ async function runGallery(args) {
|
|
|
21543
21651
|
const registered = async (projectId) => {
|
|
21544
21652
|
const project = (await loadWorkspace(workspacePath)).projects.find((candidate) => candidate.id === projectId);
|
|
21545
21653
|
if (!projectId || !project) throw new Error(`unknown workspace project "${projectId ?? ""}"`);
|
|
21546
|
-
return resolveProject(
|
|
21654
|
+
return resolveProject(path41.dirname(workspacePath), project);
|
|
21547
21655
|
};
|
|
21548
21656
|
await serveUntilStopped(initial, build2, args, {
|
|
21549
21657
|
manifestFor: async (projectId) => (await registered(projectId)).manifestPath,
|
|
@@ -21568,7 +21676,7 @@ async function runGallery(args) {
|
|
|
21568
21676
|
return buildGallerySnapshot({ ...fresh, filter });
|
|
21569
21677
|
};
|
|
21570
21678
|
await serveUntilStopped(await build(), reload, args, {
|
|
21571
|
-
manifestFor: () =>
|
|
21679
|
+
manifestFor: () => path41.resolve(args.manifest),
|
|
21572
21680
|
loadProject: () => openProject(args.manifest, { lockPath: args.lock, env: false })
|
|
21573
21681
|
});
|
|
21574
21682
|
}
|
|
@@ -21820,6 +21928,11 @@ async function runLifecycle(args, wave, spent) {
|
|
|
21820
21928
|
}
|
|
21821
21929
|
|
|
21822
21930
|
// src/cli/commands/history.ts
|
|
21931
|
+
function importedNote(entry) {
|
|
21932
|
+
if (!entry.imported) return "";
|
|
21933
|
+
const parts = [entry.imported.source, entry.origin?.tool, ...entry.origin?.steps ?? []].filter(Boolean);
|
|
21934
|
+
return ` [imported: ${parts.join(", ")}]`;
|
|
21935
|
+
}
|
|
21823
21936
|
function billedNote(cost, costUnit, billed) {
|
|
21824
21937
|
if (!billed || billed.unit === costUnit && billed.amount === cost) return "";
|
|
21825
21938
|
return ` (billed ${formatCost(billed.unit, billed.amount)})`;
|
|
@@ -21834,7 +21947,7 @@ async function runHistory(args) {
|
|
|
21834
21947
|
limit,
|
|
21835
21948
|
assets: selected.map(({ spec, entry }) => ({
|
|
21836
21949
|
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,
|
|
21950
|
+
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
21951
|
history: entry?.history ?? []
|
|
21839
21952
|
}))
|
|
21840
21953
|
}, null, 2));
|
|
@@ -21848,10 +21961,10 @@ async function runHistory(args) {
|
|
|
21848
21961
|
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
21849
21962
|
log(`
|
|
21850
21963
|
${key2}`);
|
|
21851
|
-
log(` current ${entry.outputs[0]?.sha256.slice(0, 12) ?? "\u2014"} ${entry.downloadedAt ?? ""} ${entry.objectId ?? ""}${billedNote(entry.cost, entry.costUnit, entry.billed)}`);
|
|
21964
|
+
log(` current ${entry.outputs[0]?.sha256.slice(0, 12) ?? "\u2014"} ${entry.downloadedAt ?? ""} ${entry.objectId ?? ""}${billedNote(entry.cost, entry.costUnit, entry.billed)}${importedNote(entry)}`);
|
|
21852
21965
|
for (const [i, generation] of entry.history.entries()) {
|
|
21853
21966
|
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)}`);
|
|
21967
|
+
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
21968
|
}
|
|
21856
21969
|
}
|
|
21857
21970
|
if (!shown) log(` no asset has a previous generation recorded${selected.length ? "" : " (nothing selected)"}`);
|
|
@@ -21885,13 +21998,13 @@ import { existsSync as existsSync35 } from "fs";
|
|
|
21885
21998
|
// src/pipeline/cache-health.ts
|
|
21886
21999
|
import { existsSync as existsSync34 } from "fs";
|
|
21887
22000
|
import { readFile as readFile30, readdir as readdir2, rm as rm12 } from "fs/promises";
|
|
21888
|
-
import
|
|
22001
|
+
import path42 from "path";
|
|
21889
22002
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
21890
22003
|
if (options.prune && !existsSync34(lockPath)) {
|
|
21891
|
-
throw new Error(`Refusing to prune without an existing lockfile at ${
|
|
22004
|
+
throw new Error(`Refusing to prune without an existing lockfile at ${path42.resolve(lockPath)}`);
|
|
21892
22005
|
}
|
|
21893
|
-
const contentDir =
|
|
21894
|
-
const remotePath =
|
|
22006
|
+
const contentDir = path42.resolve(path42.dirname(lockPath), ".pixelkiln", "cache");
|
|
22007
|
+
const remotePath = path42.resolve(cachePathFor(lockPath));
|
|
21895
22008
|
const referenced = referencedHashes(lock);
|
|
21896
22009
|
let content = await inspectContentCache(contentDir, referenced);
|
|
21897
22010
|
let remoteHashes = await inspectRemoteHashCache(remotePath);
|
|
@@ -21903,7 +22016,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
21903
22016
|
]);
|
|
21904
22017
|
for (const name of names) {
|
|
21905
22018
|
try {
|
|
21906
|
-
await rm12(
|
|
22019
|
+
await rm12(path42.join(contentDir, name), { force: true });
|
|
21907
22020
|
removed.contentFiles++;
|
|
21908
22021
|
} catch {
|
|
21909
22022
|
}
|
|
@@ -21951,7 +22064,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
21951
22064
|
continue;
|
|
21952
22065
|
}
|
|
21953
22066
|
report.files++;
|
|
21954
|
-
const file =
|
|
22067
|
+
const file = path42.join(contentDir, entry.name);
|
|
21955
22068
|
const mediaType = mediaTypeFromExtension(entry.name);
|
|
21956
22069
|
const expected = mediaType ? entry.name.slice(0, -4) : "";
|
|
21957
22070
|
let bytes;
|
|
@@ -22122,46 +22235,46 @@ This drops their provenance from the lockfile. The art on disk is`);
|
|
|
22122
22235
|
}
|
|
22123
22236
|
|
|
22124
22237
|
// src/cli/commands/init.ts
|
|
22125
|
-
import
|
|
22238
|
+
import path43 from "path";
|
|
22126
22239
|
import { existsSync as existsSync36 } from "fs";
|
|
22127
22240
|
async function runInit(args) {
|
|
22128
22241
|
if (!args.from) throw new Error("init needs --from <dir> pointing at your existing PNGs.");
|
|
22129
|
-
const root =
|
|
22242
|
+
const root = path43.resolve(args.from);
|
|
22130
22243
|
if (!existsSync36(root)) throw new Error(`No directory at ${root}`);
|
|
22131
22244
|
const generator = args.generator ?? "map";
|
|
22132
22245
|
if (generator !== "1dir" && generator !== "map") {
|
|
22133
22246
|
throw new Error(`--generator must be "1dir" or "map", got "${args.generator}".`);
|
|
22134
22247
|
}
|
|
22135
|
-
const target =
|
|
22248
|
+
const target = path43.resolve(args.out ?? "pixelkiln.manifest.json");
|
|
22136
22249
|
const { assets, skipped } = await scanAssets(root, { exclude: args.exclude });
|
|
22137
22250
|
if (!assets.length) throw new Error(`No PNGs found under ${root}`);
|
|
22138
22251
|
const manifest = buildManifest(
|
|
22139
|
-
args.name ??
|
|
22252
|
+
args.name ?? path43.basename(path43.dirname(target)),
|
|
22140
22253
|
args.styles[0] ?? "base",
|
|
22141
22254
|
generator,
|
|
22142
|
-
|
|
22255
|
+
path43.relative(path43.dirname(target), root) || ".",
|
|
22143
22256
|
assets
|
|
22144
22257
|
);
|
|
22145
22258
|
await writeManifestFile(target, manifest);
|
|
22146
|
-
log(` scanned ${assets.length} PNG(s) under ${
|
|
22259
|
+
log(` scanned ${assets.length} PNG(s) under ${path43.relative(process.cwd(), root)}`);
|
|
22147
22260
|
if (skipped.length) log(` skipped ${skipped.length} unreadable file(s)`);
|
|
22148
|
-
log(` wrote ${
|
|
22261
|
+
log(` wrote ${path43.relative(process.cwd(), target)}`);
|
|
22149
22262
|
log(`
|
|
22150
22263
|
Prompts are intentionally empty. To recover the real ones from your`);
|
|
22151
22264
|
log(` PixelLab account instead of inventing them:`);
|
|
22152
22265
|
log(`
|
|
22153
|
-
pixelkiln adopt --manifest ${
|
|
22266
|
+
pixelkiln adopt --manifest ${path43.relative(process.cwd(), target)} --write-prompts
|
|
22154
22267
|
`);
|
|
22155
22268
|
}
|
|
22156
22269
|
|
|
22157
22270
|
// src/pipeline/doctor.ts
|
|
22158
22271
|
import { constants, existsSync as existsSync38 } from "fs";
|
|
22159
22272
|
import { access, stat as stat4 } from "fs/promises";
|
|
22160
|
-
import
|
|
22273
|
+
import path45 from "path";
|
|
22161
22274
|
|
|
22162
22275
|
// src/pipeline/install-check.ts
|
|
22163
22276
|
import { existsSync as existsSync37, readFileSync as readFileSync7 } from "fs";
|
|
22164
|
-
import
|
|
22277
|
+
import path44 from "path";
|
|
22165
22278
|
function readJson(file) {
|
|
22166
22279
|
try {
|
|
22167
22280
|
return JSON.parse(readFileSync7(file, "utf8"));
|
|
@@ -22170,18 +22283,18 @@ function readJson(file) {
|
|
|
22170
22283
|
}
|
|
22171
22284
|
}
|
|
22172
22285
|
function readInstallFacts(manifestDir, running) {
|
|
22173
|
-
let dir =
|
|
22286
|
+
let dir = path44.resolve(manifestDir);
|
|
22174
22287
|
for (let depth = 0; depth < 4; depth++) {
|
|
22175
|
-
const pkg = readJson(
|
|
22288
|
+
const pkg = readJson(path44.join(dir, "package.json"));
|
|
22176
22289
|
if (pkg) {
|
|
22177
22290
|
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
22178
22291
|
if (pinned) {
|
|
22179
|
-
const installedPkg = readJson(
|
|
22292
|
+
const installedPkg = readJson(path44.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
22180
22293
|
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
22181
22294
|
return { pinned, installed, running };
|
|
22182
22295
|
}
|
|
22183
22296
|
}
|
|
22184
|
-
const parent =
|
|
22297
|
+
const parent = path44.dirname(dir);
|
|
22185
22298
|
if (parent === dir || !existsSync37(parent)) break;
|
|
22186
22299
|
dir = parent;
|
|
22187
22300
|
}
|
|
@@ -22245,12 +22358,12 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
22245
22358
|
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
22246
22359
|
);
|
|
22247
22360
|
}
|
|
22248
|
-
const facts = readInstallFacts(
|
|
22361
|
+
const facts = readInstallFacts(path45.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
22249
22362
|
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
22250
22363
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
22251
22364
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
22252
|
-
|
|
22253
|
-
...spec.quality ? [
|
|
22365
|
+
path45.dirname(spec.outFile),
|
|
22366
|
+
...spec.quality ? [path45.dirname(spec.quality.outFile)] : []
|
|
22254
22367
|
]))];
|
|
22255
22368
|
const unwritable = [];
|
|
22256
22369
|
for (const dir of dirs) {
|
|
@@ -22273,7 +22386,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
22273
22386
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
22274
22387
|
const output = entry.outputs[index];
|
|
22275
22388
|
const spec = specByKey.get(key2);
|
|
22276
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
22389
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, path45.dirname(lockPath));
|
|
22277
22390
|
const owner = outputOwners.get(absolute);
|
|
22278
22391
|
if (owner && owner !== key2) duplicateOutputs.push(`${output.path} (${owner}, ${key2})`);
|
|
22279
22392
|
outputOwners.set(absolute, key2);
|
|
@@ -22288,7 +22401,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
22288
22401
|
} else {
|
|
22289
22402
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
22290
22403
|
}
|
|
22291
|
-
const cacheDir =
|
|
22404
|
+
const cacheDir = path45.join(path45.dirname(lockPath), ".pixelkiln", "cache");
|
|
22292
22405
|
const stranded = [];
|
|
22293
22406
|
const invalidState = [];
|
|
22294
22407
|
const staleMapUrls = [];
|
|
@@ -22304,7 +22417,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
22304
22417
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
22305
22418
|
let hasCache = false;
|
|
22306
22419
|
for (const output of entry.outputs) {
|
|
22307
|
-
const cached2 =
|
|
22420
|
+
const cached2 = path45.join(
|
|
22308
22421
|
cacheDir,
|
|
22309
22422
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
22310
22423
|
);
|
|
@@ -22404,7 +22517,7 @@ async function nearestExistingDirectory(start) {
|
|
|
22404
22517
|
if ((await stat4(current)).isDirectory()) return current;
|
|
22405
22518
|
} catch {
|
|
22406
22519
|
}
|
|
22407
|
-
const parent =
|
|
22520
|
+
const parent = path45.dirname(current);
|
|
22408
22521
|
if (parent === current) return current;
|
|
22409
22522
|
current = parent;
|
|
22410
22523
|
}
|
|
@@ -22413,7 +22526,7 @@ async function nearestExistingDirectory(start) {
|
|
|
22413
22526
|
// src/pipeline/audit.ts
|
|
22414
22527
|
import { readFile as readFile31 } from "fs/promises";
|
|
22415
22528
|
import { existsSync as existsSync39 } from "fs";
|
|
22416
|
-
import
|
|
22529
|
+
import path46 from "path";
|
|
22417
22530
|
function paletteDistance(asset, reference) {
|
|
22418
22531
|
if (!asset.length || !reference.length) return 0;
|
|
22419
22532
|
let total = 0;
|
|
@@ -22478,7 +22591,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
22478
22591
|
let referenceFromStyleImages = false;
|
|
22479
22592
|
const refPalettes = [];
|
|
22480
22593
|
for (const img of style.styleImages) {
|
|
22481
|
-
const abs =
|
|
22594
|
+
const abs = path46.resolve(loaded.root, img.path);
|
|
22482
22595
|
if (!existsSync39(abs)) continue;
|
|
22483
22596
|
try {
|
|
22484
22597
|
refPalettes.push(extractPalette(decodePng(await readFile31(abs)), 12));
|
|
@@ -22647,6 +22760,7 @@ async function runPlan(args) {
|
|
|
22647
22760
|
}
|
|
22648
22761
|
} : {},
|
|
22649
22762
|
...quality ? { quality: { state: quality.state, reason: quality.reason } } : {},
|
|
22763
|
+
...entry?.imported ? { imported: entry.imported, ...entry.origin ? { origin: entry.origin } : {} } : {},
|
|
22650
22764
|
// The estimate a wave budget spent against; present alongside the
|
|
22651
22765
|
// provider's actual charge only when `poll` has read one and it
|
|
22652
22766
|
// differs, since that is the only time the gap is worth a look.
|
|
@@ -22735,24 +22849,24 @@ async function runHash(args) {
|
|
|
22735
22849
|
}
|
|
22736
22850
|
|
|
22737
22851
|
// src/cli/commands/pack.ts
|
|
22738
|
-
import
|
|
22852
|
+
import path48 from "path";
|
|
22739
22853
|
import { readFile as readFile32 } from "fs/promises";
|
|
22740
22854
|
|
|
22741
22855
|
// src/pipeline/pack.ts
|
|
22742
22856
|
import { readFileSync as readFileSync8 } from "fs";
|
|
22743
|
-
import
|
|
22857
|
+
import path47 from "path";
|
|
22744
22858
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
22745
22859
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
22746
22860
|
if (!Array.isArray(raw) || !raw.length) {
|
|
22747
22861
|
throw new Error("--inputs must be a non-empty JSON array of { id, path }");
|
|
22748
22862
|
}
|
|
22749
|
-
const baseDir =
|
|
22863
|
+
const baseDir = path47.dirname(path47.resolve(inputsFilePath));
|
|
22750
22864
|
return raw.map((entry, i) => {
|
|
22751
22865
|
const e = entry;
|
|
22752
22866
|
if (typeof e.id !== "string" || typeof e.path !== "string") {
|
|
22753
22867
|
throw new Error(`--inputs[${i}] needs string "id" and "path"`);
|
|
22754
22868
|
}
|
|
22755
|
-
return { id: e.id, path:
|
|
22869
|
+
return { id: e.id, path: path47.resolve(baseDir, e.path) };
|
|
22756
22870
|
});
|
|
22757
22871
|
}
|
|
22758
22872
|
function packSprites(inputs, options = {}) {
|
|
@@ -22836,7 +22950,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
22836
22950
|
}
|
|
22837
22951
|
const inputs2 = Object.entries(options.sourceOverrides).map(([id, source]) => ({
|
|
22838
22952
|
id,
|
|
22839
|
-
path:
|
|
22953
|
+
path: path47.resolve(source)
|
|
22840
22954
|
}));
|
|
22841
22955
|
if (!inputs2.length) throw new Error(`No approved quality outputs for style "${styleId}".`);
|
|
22842
22956
|
const packed2 = packSprites(inputs2, options);
|
|
@@ -22860,7 +22974,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
22860
22974
|
let outputs = resolveEntryOutputs(entry, id, manifestDir);
|
|
22861
22975
|
const source = sources[id];
|
|
22862
22976
|
if (source && outputs.length <= 1) {
|
|
22863
|
-
inputs.push({ id, path:
|
|
22977
|
+
inputs.push({ id, path: path47.resolve(manifestDir, source) });
|
|
22864
22978
|
continue;
|
|
22865
22979
|
}
|
|
22866
22980
|
if (source && sourceIsStem(source, entry, manifestDir)) {
|
|
@@ -22895,7 +23009,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
22895
23009
|
}
|
|
22896
23010
|
}
|
|
22897
23011
|
for (const [id, source] of Object.entries(sources)) {
|
|
22898
|
-
if (!locked.has(id)) inputs.push({ id, path:
|
|
23012
|
+
if (!locked.has(id)) inputs.push({ id, path: path47.resolve(manifestDir, source) });
|
|
22899
23013
|
}
|
|
22900
23014
|
if (!inputs.length) {
|
|
22901
23015
|
throw new Error(`No readable sprites for style "${styleId}"; ${noOutput.length} skipped.`);
|
|
@@ -23003,7 +23117,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
23003
23117
|
const source = sources[id];
|
|
23004
23118
|
const entry = lock.entries[`${styleId}/${id}`];
|
|
23005
23119
|
if (source && !(entry && sourceIsStem(source, entry, manifestDir))) {
|
|
23006
|
-
placements.push({ id, path:
|
|
23120
|
+
placements.push({ id, path: path47.resolve(manifestDir, source), cell });
|
|
23007
23121
|
continue;
|
|
23008
23122
|
}
|
|
23009
23123
|
if (source && entry) {
|
|
@@ -23036,7 +23150,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
23036
23150
|
`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
23151
|
);
|
|
23038
23152
|
}
|
|
23039
|
-
const basePng = mount.base ? readFileSync8(
|
|
23153
|
+
const basePng = mount.base ? readFileSync8(path47.resolve(manifestDir, mount.base)) : void 0;
|
|
23040
23154
|
const mounted = mountSprites(placements, {
|
|
23041
23155
|
cellWidth: mount.cellWidth,
|
|
23042
23156
|
cellHeight: mount.cellHeight,
|
|
@@ -23046,7 +23160,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
23046
23160
|
...mounted,
|
|
23047
23161
|
sources: mount.base ? [{
|
|
23048
23162
|
id: "$base",
|
|
23049
|
-
path:
|
|
23163
|
+
path: path47.resolve(manifestDir, mount.base),
|
|
23050
23164
|
sha256: sha256(basePng),
|
|
23051
23165
|
included: true
|
|
23052
23166
|
}, ...mounted.sources] : mounted.sources,
|
|
@@ -23450,12 +23564,12 @@ async function runPack(args) {
|
|
|
23450
23564
|
if (args.primaryOnly || args.outputRoles.length) {
|
|
23451
23565
|
throw new Error("--primary-only and --output-role require manifest-driven pack");
|
|
23452
23566
|
}
|
|
23453
|
-
const raw = JSON.parse(await readFile32(
|
|
23567
|
+
const raw = JSON.parse(await readFile32(path48.resolve(args.inputs), "utf8"));
|
|
23454
23568
|
const inputs = resolvePackInputs(raw, args.inputs);
|
|
23455
23569
|
const { png, atlas, skipped, sources } = packSprites(inputs, { columns: args.columns });
|
|
23456
23570
|
const format = sheetFormat(args);
|
|
23457
|
-
const base =
|
|
23458
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
23571
|
+
const base = path48.resolve(args.out.replace(/\.(?:png|json|tres)$/i, ""));
|
|
23572
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path48.basename(`${base}.png`) });
|
|
23459
23573
|
const outputs = [
|
|
23460
23574
|
{ path: `${base}.png`, data: png },
|
|
23461
23575
|
{ path: `${base}${extension}`, data: document }
|
|
@@ -23468,7 +23582,7 @@ async function runPack(args) {
|
|
|
23468
23582
|
log(
|
|
23469
23583
|
` ${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
23584
|
);
|
|
23471
|
-
log(` ${
|
|
23585
|
+
log(` ${path48.relative(process.cwd(), base)}.png + ${extension} + .pixelkiln.json`);
|
|
23472
23586
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
23473
23587
|
return;
|
|
23474
23588
|
}
|
|
@@ -23476,7 +23590,7 @@ async function runPack(args) {
|
|
|
23476
23590
|
if (args.primaryOnly && args.outputRoles.length) {
|
|
23477
23591
|
throw new Error("pack accepts either --primary-only or --output-role, not both");
|
|
23478
23592
|
}
|
|
23479
|
-
const manifestDir =
|
|
23593
|
+
const manifestDir = path48.dirname(path48.resolve(args.manifest));
|
|
23480
23594
|
const styleIds = args.styles.length ? args.styles : Object.keys(loaded.manifest.styles);
|
|
23481
23595
|
for (const styleId of styleIds) {
|
|
23482
23596
|
const style = loaded.manifest.styles[styleId];
|
|
@@ -23491,9 +23605,9 @@ async function runPack(args) {
|
|
|
23491
23605
|
sourceOverrides: qualitySources,
|
|
23492
23606
|
sources: manifestSources(loaded.manifest, styleId)
|
|
23493
23607
|
});
|
|
23494
|
-
const base = args.out ?
|
|
23608
|
+
const base = args.out ? path48.resolve(args.out.replace(/\.(?:png|json|tres)$/i, "")) : path48.resolve(manifestDir, style.outDir, `${styleId}-sheet`);
|
|
23495
23609
|
const format = sheetFormat(args);
|
|
23496
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
23610
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path48.basename(`${base}.png`) });
|
|
23497
23611
|
const outputs = [
|
|
23498
23612
|
{ path: `${base}.png`, data: png },
|
|
23499
23613
|
{ path: `${base}${extension}`, data: document }
|
|
@@ -23525,13 +23639,13 @@ async function runPack(args) {
|
|
|
23525
23639
|
log(
|
|
23526
23640
|
` ${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
23641
|
);
|
|
23528
|
-
log(` ${
|
|
23642
|
+
log(` ${path48.relative(process.cwd(), base)}.png + ${extension} + .pixelkiln.json`);
|
|
23529
23643
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
23530
23644
|
}
|
|
23531
23645
|
}
|
|
23532
23646
|
async function runMount(args) {
|
|
23533
23647
|
const { loaded, lock } = await openProject2(args);
|
|
23534
|
-
const manifestDir =
|
|
23648
|
+
const manifestDir = path48.dirname(path48.resolve(args.manifest));
|
|
23535
23649
|
const styleIds = args.styles.length ? args.styles : Object.keys(loaded.manifest.styles);
|
|
23536
23650
|
for (const styleId of styleIds) {
|
|
23537
23651
|
const style = loaded.manifest.styles[styleId];
|
|
@@ -23570,9 +23684,9 @@ async function runMount(args) {
|
|
|
23570
23684
|
sources,
|
|
23571
23685
|
outputRoles
|
|
23572
23686
|
);
|
|
23573
|
-
const out =
|
|
23687
|
+
const out = path48.resolve(manifestDir, style.mount.out);
|
|
23574
23688
|
const format = sheetFormat(args);
|
|
23575
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
23689
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path48.basename(out) });
|
|
23576
23690
|
const metadata = out.replace(/\.png$/, "") + extension;
|
|
23577
23691
|
const companion = out.replace(/\.png$/, "") + ".pixelkiln.json";
|
|
23578
23692
|
const outputs = [
|
|
@@ -23592,7 +23706,7 @@ async function runMount(args) {
|
|
|
23592
23706
|
await provenanceFile("$lock", args.lock),
|
|
23593
23707
|
...qualityRecords,
|
|
23594
23708
|
...artifactSources.filter(
|
|
23595
|
-
(source) => source.id !== "$base" ||
|
|
23709
|
+
(source) => source.id !== "$base" || path48.resolve(source.path) !== out
|
|
23596
23710
|
)
|
|
23597
23711
|
],
|
|
23598
23712
|
options: {
|
|
@@ -23606,14 +23720,14 @@ async function runMount(args) {
|
|
|
23606
23720
|
log(
|
|
23607
23721
|
` ${styleId}: ${atlas.frames.length} cell(s) into ${atlas.sheet.width}x${atlas.sheet.height}` + (overBase ? ` over ${style.mount.base}` : " (new sheet)")
|
|
23608
23722
|
);
|
|
23609
|
-
log(` ${
|
|
23723
|
+
log(` ${path48.relative(process.cwd(), out)} + atlas/provenance JSON`);
|
|
23610
23724
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
23611
23725
|
}
|
|
23612
23726
|
}
|
|
23613
23727
|
async function runExport(args) {
|
|
23614
23728
|
const { loaded, specs, lock } = await openProject2(args);
|
|
23615
23729
|
const format = args.format ?? "generic";
|
|
23616
|
-
const manifestDir =
|
|
23730
|
+
const manifestDir = path48.dirname(path48.resolve(args.manifest));
|
|
23617
23731
|
const selected = specs.filter((spec) => {
|
|
23618
23732
|
if (spec.generator !== "tiles" && spec.generator !== "terrain") return false;
|
|
23619
23733
|
if (args.styles.length && !args.styles.includes(spec.styleId)) return false;
|
|
@@ -23629,12 +23743,12 @@ async function runExport(args) {
|
|
|
23629
23743
|
for (const spec of selected) {
|
|
23630
23744
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
23631
23745
|
const style = loaded.manifest.styles[spec.styleId];
|
|
23632
|
-
const defaultBase =
|
|
23633
|
-
const base = args.out ?
|
|
23746
|
+
const defaultBase = path48.resolve(manifestDir, style.outDir, `${spec.assetId}-tileset`);
|
|
23747
|
+
const base = args.out ? path48.resolve(args.out.replace(/\.(?:png|json|tsj|tres)$/i, "")) : defaultBase;
|
|
23634
23748
|
const result = exportTileset(entry, spec, {
|
|
23635
23749
|
format,
|
|
23636
23750
|
manifestDir,
|
|
23637
|
-
imageName:
|
|
23751
|
+
imageName: path48.basename(`${base}.png`),
|
|
23638
23752
|
columns: args.columns
|
|
23639
23753
|
});
|
|
23640
23754
|
const outputs = [
|
|
@@ -23652,7 +23766,7 @@ async function runExport(args) {
|
|
|
23652
23766
|
asset: spec.assetId,
|
|
23653
23767
|
columns: args.columns ?? null,
|
|
23654
23768
|
format,
|
|
23655
|
-
image:
|
|
23769
|
+
image: path48.basename(`${base}.png`),
|
|
23656
23770
|
providerRules: result.generic.providerRules,
|
|
23657
23771
|
style: spec.styleId,
|
|
23658
23772
|
tileType: spec.tileType ?? null
|
|
@@ -23662,7 +23776,7 @@ async function runExport(args) {
|
|
|
23662
23776
|
` ${spec.styleId}/${spec.assetId}: ${result.generic.tiles.length} tile(s), ${result.generic.sheet.width}x${result.generic.sheet.height} (${format})`
|
|
23663
23777
|
);
|
|
23664
23778
|
log(
|
|
23665
|
-
` ${
|
|
23779
|
+
` ${path48.relative(process.cwd(), base)}.png + ${path48.basename(base)}${result.extension} + .pixelkiln.json`
|
|
23666
23780
|
);
|
|
23667
23781
|
}
|
|
23668
23782
|
}
|
|
@@ -23676,9 +23790,9 @@ function sheetFormat(args) {
|
|
|
23676
23790
|
|
|
23677
23791
|
// src/cli/commands/pixellab-utils.ts
|
|
23678
23792
|
import { readFile as readFile33 } from "fs/promises";
|
|
23679
|
-
import
|
|
23793
|
+
import path49 from "path";
|
|
23680
23794
|
function loadKeys(args) {
|
|
23681
|
-
loadEnvFiles(
|
|
23795
|
+
loadEnvFiles(path49.dirname(path49.resolve(args.manifest)));
|
|
23682
23796
|
loadEnvFiles(process.cwd());
|
|
23683
23797
|
}
|
|
23684
23798
|
async function runUnzoom(args) {
|
|
@@ -23835,7 +23949,7 @@ async function runVfx(args) {
|
|
|
23835
23949
|
const fromRecipe = args.recipe ? await readVfxRecipe(args.recipe) : void 0;
|
|
23836
23950
|
const sprite = args.sprite ?? fromRecipe?.sprite;
|
|
23837
23951
|
const recipeName = typeof fromRecipe?.recipe.name === "string" ? fromRecipe.recipe.name : void 0;
|
|
23838
|
-
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ??
|
|
23952
|
+
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ?? path49.basename(paths.sheet, ".png"));
|
|
23839
23953
|
const from = args.preset ? `preset ${args.preset}` : args.recipe ? `recipe ${args.recipe}` : args.effect ? `saved effect ${args.effect}` : "nothing";
|
|
23840
23954
|
log(
|
|
23841
23955
|
` 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 +24016,7 @@ async function runVfxArtist(args, out) {
|
|
|
23902
24016
|
);
|
|
23903
24017
|
if (args.effect) {
|
|
23904
24018
|
log(
|
|
23905
|
-
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${
|
|
24019
|
+
` 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
24020
|
);
|
|
23907
24021
|
}
|
|
23908
24022
|
log(` cost: about ${quote} generations by PixelLab's table, billed on delivery; at most ${ceiling} if the effect runs long`);
|
|
@@ -23950,11 +24064,11 @@ async function runVfxArtist(args, out) {
|
|
|
23950
24064
|
}
|
|
23951
24065
|
|
|
23952
24066
|
// src/cli/commands/quality.ts
|
|
23953
|
-
import
|
|
24067
|
+
import path51 from "path";
|
|
23954
24068
|
import { readFile as readFile35 } from "fs/promises";
|
|
23955
24069
|
|
|
23956
24070
|
// src/pipeline/quality-regression.ts
|
|
23957
|
-
import
|
|
24071
|
+
import path50 from "path";
|
|
23958
24072
|
import { existsSync as existsSync40 } from "fs";
|
|
23959
24073
|
import { readFile as readFile34 } from "fs/promises";
|
|
23960
24074
|
import { z as z13 } from "zod";
|
|
@@ -23962,7 +24076,7 @@ var SHA256_RE = /^[0-9a-f]{64}$/;
|
|
|
23962
24076
|
var HEX_RE = /^#[0-9a-f]{6}$/;
|
|
23963
24077
|
var MAX_REDMEAN_DISTANCE = 765;
|
|
23964
24078
|
var QualityPathSchema = z13.string().min(1).refine(
|
|
23965
|
-
(value) => !
|
|
24079
|
+
(value) => !path50.posix.isAbsolute(value) && !value.includes("\\"),
|
|
23966
24080
|
"expected a portable relative path"
|
|
23967
24081
|
);
|
|
23968
24082
|
var DEFAULT_QUALITY_TOLERANCES = {
|
|
@@ -24109,7 +24223,7 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
24109
24223
|
};
|
|
24110
24224
|
}
|
|
24111
24225
|
async function measureImageQuality(file) {
|
|
24112
|
-
const absolute =
|
|
24226
|
+
const absolute = path50.resolve(file);
|
|
24113
24227
|
let bytes;
|
|
24114
24228
|
try {
|
|
24115
24229
|
bytes = await readFile34(absolute);
|
|
@@ -24131,11 +24245,11 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
24131
24245
|
}
|
|
24132
24246
|
const ids = parsed.data.map((entry) => entry.id);
|
|
24133
24247
|
if (new Set(ids).size !== ids.length) throw new Error("--inputs contains a duplicate quality case id.");
|
|
24134
|
-
const root =
|
|
24248
|
+
const root = path50.dirname(path50.resolve(inputsFilePath));
|
|
24135
24249
|
return parsed.data.map((entry) => ({
|
|
24136
24250
|
id: entry.id,
|
|
24137
|
-
file:
|
|
24138
|
-
...entry.record ? { record:
|
|
24251
|
+
file: path50.resolve(root, entry.path),
|
|
24252
|
+
...entry.record ? { record: path50.resolve(root, entry.record) } : {},
|
|
24139
24253
|
tolerances: QualityToleranceSchema.parse({
|
|
24140
24254
|
...DEFAULT_QUALITY_TOLERANCES,
|
|
24141
24255
|
...entry.tolerances
|
|
@@ -24143,7 +24257,7 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
24143
24257
|
}));
|
|
24144
24258
|
}
|
|
24145
24259
|
function portableRelative2(from, to) {
|
|
24146
|
-
return
|
|
24260
|
+
return path50.relative(from, path50.resolve(to)).split(path50.sep).join("/") || ".";
|
|
24147
24261
|
}
|
|
24148
24262
|
async function verifyRecordForImage(recordPath, imagePath) {
|
|
24149
24263
|
const verification = await verifyArtifactBundle(recordPath);
|
|
@@ -24158,20 +24272,20 @@ async function verifyRecordForImage(recordPath, imagePath) {
|
|
|
24158
24272
|
if (record.kind !== "refine" || options === null || typeof options !== "object" || options.schema !== "pixelkiln-quality") {
|
|
24159
24273
|
throw new Error(`Quality record ${recordPath} is not a PixelKiln refinement record.`);
|
|
24160
24274
|
}
|
|
24161
|
-
const outputs = record.outputs.map((output) =>
|
|
24162
|
-
if (!outputs.includes(
|
|
24275
|
+
const outputs = record.outputs.map((output) => path50.resolve(path50.dirname(recordPath), output.path));
|
|
24276
|
+
if (!outputs.includes(path50.resolve(imagePath))) {
|
|
24163
24277
|
throw new Error(`Quality record ${recordPath} does not own ${imagePath}.`);
|
|
24164
24278
|
}
|
|
24165
24279
|
}
|
|
24166
24280
|
async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
24167
24281
|
if (!inputs.length) throw new Error("Cannot snapshot an empty quality baseline.");
|
|
24168
|
-
const absolute =
|
|
24282
|
+
const absolute = path50.resolve(baselinePath);
|
|
24169
24283
|
for (const input of inputs) {
|
|
24170
|
-
if (
|
|
24284
|
+
if (path50.resolve(input.file) === absolute || input.record && path50.resolve(input.record) === absolute) {
|
|
24171
24285
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
24172
24286
|
}
|
|
24173
24287
|
}
|
|
24174
|
-
const root =
|
|
24288
|
+
const root = path50.dirname(absolute);
|
|
24175
24289
|
const cases = [];
|
|
24176
24290
|
for (const input of [...inputs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
24177
24291
|
const expected = await measureImageQuality(input.file);
|
|
@@ -24211,7 +24325,7 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
24211
24325
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
24212
24326
|
}
|
|
24213
24327
|
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
24214
|
-
const absolute =
|
|
24328
|
+
const absolute = path50.resolve(baselinePath);
|
|
24215
24329
|
if (!existsSync40(absolute)) {
|
|
24216
24330
|
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
24217
24331
|
}
|
|
@@ -24227,12 +24341,12 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
24227
24341
|
if (unknown.length) {
|
|
24228
24342
|
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
24229
24343
|
}
|
|
24230
|
-
const root =
|
|
24344
|
+
const root = path50.dirname(absolute);
|
|
24231
24345
|
const cases = [...raw.cases];
|
|
24232
24346
|
const report = [];
|
|
24233
24347
|
for (const id of only) {
|
|
24234
24348
|
const input = byId.get(id);
|
|
24235
|
-
if (
|
|
24349
|
+
if (path50.resolve(input.file) === absolute || input.record && path50.resolve(input.record) === absolute) {
|
|
24236
24350
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
24237
24351
|
}
|
|
24238
24352
|
const expected = await measureImageQuality(input.file);
|
|
@@ -24268,7 +24382,7 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
24268
24382
|
return { baseline, path: absolute, changed, cases: report };
|
|
24269
24383
|
}
|
|
24270
24384
|
async function readQualityBaseline(baselinePath) {
|
|
24271
|
-
const absolute =
|
|
24385
|
+
const absolute = path50.resolve(baselinePath);
|
|
24272
24386
|
let raw;
|
|
24273
24387
|
try {
|
|
24274
24388
|
raw = JSON.parse(await readFile34(absolute, "utf8"));
|
|
@@ -24293,7 +24407,7 @@ async function readQualityBaseline(baselinePath) {
|
|
|
24293
24407
|
throw new Error(
|
|
24294
24408
|
`Invalid quality baseline ${absolute}:
|
|
24295
24409
|
` + 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 ${
|
|
24410
|
+
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
24411
|
);
|
|
24298
24412
|
}
|
|
24299
24413
|
return parsed.data;
|
|
@@ -24355,12 +24469,12 @@ function regressionViolations(expected, actual, tolerances) {
|
|
|
24355
24469
|
return { violations, warnings };
|
|
24356
24470
|
}
|
|
24357
24471
|
async function checkQualityBaseline(baselinePath) {
|
|
24358
|
-
const absolute =
|
|
24472
|
+
const absolute = path50.resolve(baselinePath);
|
|
24359
24473
|
const baseline = await readQualityBaseline(absolute);
|
|
24360
|
-
const root =
|
|
24474
|
+
const root = path50.dirname(absolute);
|
|
24361
24475
|
const cases = [];
|
|
24362
24476
|
for (const entry of baseline.cases) {
|
|
24363
|
-
const file =
|
|
24477
|
+
const file = path50.resolve(root, entry.file);
|
|
24364
24478
|
let actual = null;
|
|
24365
24479
|
const violations = [];
|
|
24366
24480
|
const warnings = [];
|
|
@@ -24373,7 +24487,7 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
24373
24487
|
violations.push(message4(error));
|
|
24374
24488
|
}
|
|
24375
24489
|
if (entry.record) {
|
|
24376
|
-
const recordPath =
|
|
24490
|
+
const recordPath = path50.resolve(root, entry.record.path);
|
|
24377
24491
|
try {
|
|
24378
24492
|
const recordHash = await sha256File(recordPath);
|
|
24379
24493
|
if (recordHash !== entry.record.sha256) violations.push("quality record hash changed");
|
|
@@ -24415,15 +24529,15 @@ async function runQuality(args) {
|
|
|
24415
24529
|
if (!args.out) throw new Error("quality snapshot needs --out <pixelkiln.quality.json>.");
|
|
24416
24530
|
let raw;
|
|
24417
24531
|
try {
|
|
24418
|
-
raw = JSON.parse(await readFile35(
|
|
24532
|
+
raw = JSON.parse(await readFile35(path51.resolve(args.inputs), "utf8"));
|
|
24419
24533
|
} catch (error) {
|
|
24420
24534
|
throw new Error(
|
|
24421
|
-
`Could not read quality inputs ${
|
|
24535
|
+
`Could not read quality inputs ${path51.resolve(args.inputs)}: ${error instanceof Error ? error.message : String(error)}`,
|
|
24422
24536
|
{ cause: error }
|
|
24423
24537
|
);
|
|
24424
24538
|
}
|
|
24425
24539
|
const inputs = resolveQualityInputs(raw, args.inputs);
|
|
24426
|
-
if (
|
|
24540
|
+
if (path51.resolve(args.inputs) === path51.resolve(args.out)) {
|
|
24427
24541
|
throw new Error("quality snapshot --out must not overwrite its --inputs file.");
|
|
24428
24542
|
}
|
|
24429
24543
|
if (args.assets.length) {
|
|
@@ -24438,7 +24552,7 @@ async function runQuality(args) {
|
|
|
24438
24552
|
}
|
|
24439
24553
|
log(
|
|
24440
24554
|
`
|
|
24441
|
-
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${
|
|
24555
|
+
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${path51.relative(process.cwd(), result2.path)}; other cases left as they were.`
|
|
24442
24556
|
);
|
|
24443
24557
|
return;
|
|
24444
24558
|
}
|
|
@@ -24453,7 +24567,7 @@ async function runQuality(args) {
|
|
|
24453
24567
|
}, null, 2));
|
|
24454
24568
|
} else {
|
|
24455
24569
|
log(
|
|
24456
|
-
` ${result.changed ? "wrote" : "unchanged"} ${
|
|
24570
|
+
` ${result.changed ? "wrote" : "unchanged"} ${path51.relative(process.cwd(), result.path)} (${result.baseline.cases.length} case(s))`
|
|
24457
24571
|
);
|
|
24458
24572
|
log(` Review the tolerances, commit the baseline, then run quality check in CI.`);
|
|
24459
24573
|
}
|
|
@@ -24479,10 +24593,10 @@ async function runQuality(args) {
|
|
|
24479
24593
|
}
|
|
24480
24594
|
|
|
24481
24595
|
// src/cli/commands/recipe.ts
|
|
24482
|
-
import
|
|
24596
|
+
import path53 from "path";
|
|
24483
24597
|
|
|
24484
24598
|
// src/recipes.ts
|
|
24485
|
-
import
|
|
24599
|
+
import path52 from "path";
|
|
24486
24600
|
import { existsSync as existsSync41 } from "fs";
|
|
24487
24601
|
import { readdir as readdir3, readFile as readFile36 } from "fs/promises";
|
|
24488
24602
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
@@ -24493,7 +24607,7 @@ var VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
|
24493
24607
|
var RECIPE_FILE = "pixelkiln.recipe.json";
|
|
24494
24608
|
var RECIPE_DIR_TOKEN = "{{recipeDir}}";
|
|
24495
24609
|
var PortablePathSchema = z14.string().min(1).refine((value) => {
|
|
24496
|
-
if (value.includes("\\") ||
|
|
24610
|
+
if (value.includes("\\") || path52.posix.isAbsolute(value)) return false;
|
|
24497
24611
|
const parts = value.split("/");
|
|
24498
24612
|
return !parts.includes("") && !parts.includes(".") && !parts.includes("..");
|
|
24499
24613
|
}, "expected a portable relative path without '.', '..', or backslashes");
|
|
@@ -24669,7 +24783,7 @@ function message5(error) {
|
|
|
24669
24783
|
return error instanceof Error ? error.message : String(error);
|
|
24670
24784
|
}
|
|
24671
24785
|
async function readRecipeFile(recipePath, bundled) {
|
|
24672
|
-
const absolute =
|
|
24786
|
+
const absolute = path52.resolve(recipePath);
|
|
24673
24787
|
let raw;
|
|
24674
24788
|
try {
|
|
24675
24789
|
raw = JSON.parse(await readFile36(absolute, "utf8"));
|
|
@@ -24683,13 +24797,13 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
24683
24797
|
` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
|
|
24684
24798
|
);
|
|
24685
24799
|
}
|
|
24686
|
-
return { recipe: parsed.data, authored: raw, path: absolute, dir:
|
|
24800
|
+
return { recipe: parsed.data, authored: raw, path: absolute, dir: path52.dirname(absolute), bundled };
|
|
24687
24801
|
}
|
|
24688
24802
|
async function walkRecipeFiles(root) {
|
|
24689
24803
|
if (!existsSync41(root)) return [];
|
|
24690
24804
|
const out = [];
|
|
24691
24805
|
for (const entry of await readdir3(root, { withFileTypes: true })) {
|
|
24692
|
-
const resolved =
|
|
24806
|
+
const resolved = path52.join(root, entry.name);
|
|
24693
24807
|
if (entry.isDirectory()) out.push(...await walkRecipeFiles(resolved));
|
|
24694
24808
|
else if (entry.isFile() && entry.name === RECIPE_FILE) out.push(resolved);
|
|
24695
24809
|
}
|
|
@@ -24700,7 +24814,7 @@ function bundledRecipeRoot() {
|
|
|
24700
24814
|
}
|
|
24701
24815
|
async function listBundledRecipes(root = bundledRecipeRoot()) {
|
|
24702
24816
|
const recipes = await Promise.all(
|
|
24703
|
-
(await walkRecipeFiles(
|
|
24817
|
+
(await walkRecipeFiles(path52.resolve(root))).map((file) => readRecipeFile(file, true))
|
|
24704
24818
|
);
|
|
24705
24819
|
return recipes.sort(
|
|
24706
24820
|
(a, b) => a.recipe.id.localeCompare(b.recipe.id) || compareVersions(b.recipe.version, a.recipe.version)
|
|
@@ -24723,9 +24837,9 @@ function parseSelector(selector) {
|
|
|
24723
24837
|
return { id: match[1], version: match[2] };
|
|
24724
24838
|
}
|
|
24725
24839
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
24726
|
-
const local =
|
|
24840
|
+
const local = path52.resolve(target);
|
|
24727
24841
|
if (existsSync41(local)) {
|
|
24728
|
-
const recipePath =
|
|
24842
|
+
const recipePath = path52.basename(local) === RECIPE_FILE ? local : path52.join(local, RECIPE_FILE);
|
|
24729
24843
|
return readRecipeFile(recipePath, false);
|
|
24730
24844
|
}
|
|
24731
24845
|
if (target.startsWith(".") || target.startsWith("/") || target.includes("\\")) {
|
|
@@ -24739,7 +24853,7 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
24739
24853
|
return matches[0];
|
|
24740
24854
|
}
|
|
24741
24855
|
async function verifyFile(root, file) {
|
|
24742
|
-
const absolute =
|
|
24856
|
+
const absolute = path52.resolve(root, ...file.path.split("/"));
|
|
24743
24857
|
if (!existsSync41(absolute)) {
|
|
24744
24858
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
24745
24859
|
}
|
|
@@ -24755,7 +24869,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
24755
24869
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
24756
24870
|
const actualIntegrity = recipeDigest(loaded.authored);
|
|
24757
24871
|
const files = await Promise.all(loaded.recipe.files.map((file) => verifyFile(loaded.dir, file)));
|
|
24758
|
-
const modelRoot = options.modelRoot ?
|
|
24872
|
+
const modelRoot = options.modelRoot ? path52.resolve(options.modelRoot) : null;
|
|
24759
24873
|
const models = modelRoot ? await Promise.all(loaded.recipe.models.map(async (model) => ({
|
|
24760
24874
|
...await verifyFile(modelRoot, model),
|
|
24761
24875
|
source: model.source,
|
|
@@ -24789,7 +24903,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
24789
24903
|
};
|
|
24790
24904
|
}
|
|
24791
24905
|
function renderStyle(style, destination, cwd) {
|
|
24792
|
-
const portableDir =
|
|
24906
|
+
const portableDir = path52.relative(cwd, destination).split(path52.sep).join("/") || ".";
|
|
24793
24907
|
const replace = (value) => {
|
|
24794
24908
|
if (typeof value === "string") return value.replaceAll(RECIPE_DIR_TOKEN, portableDir);
|
|
24795
24909
|
if (Array.isArray(value)) return value.map(replace);
|
|
@@ -24801,19 +24915,19 @@ function renderStyle(style, destination, cwd) {
|
|
|
24801
24915
|
return replace(style);
|
|
24802
24916
|
}
|
|
24803
24917
|
async function installRecipe(target, options = {}) {
|
|
24804
|
-
const cwd =
|
|
24918
|
+
const cwd = path52.resolve(options.cwd ?? process.cwd());
|
|
24805
24919
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
24806
24920
|
const verification = await verifyRecipe(loaded.path);
|
|
24807
24921
|
if (!verification.ok) {
|
|
24808
24922
|
throw new Error(`Recipe ${loaded.recipe.id}@${loaded.recipe.version} failed integrity verification.`);
|
|
24809
24923
|
}
|
|
24810
|
-
const destination = options.out ?
|
|
24924
|
+
const destination = options.out ? path52.resolve(cwd, options.out) : path52.join(cwd, "pixelkiln-recipes", ...loaded.recipe.id.split("/"), loaded.recipe.version);
|
|
24811
24925
|
const sources = [
|
|
24812
24926
|
{ path: RECIPE_FILE, source: loaded.path },
|
|
24813
|
-
...loaded.recipe.files.map((file) => ({ path: file.path, source:
|
|
24927
|
+
...loaded.recipe.files.map((file) => ({ path: file.path, source: path52.join(loaded.dir, ...file.path.split("/")) }))
|
|
24814
24928
|
];
|
|
24815
24929
|
const files = await Promise.all(sources.map(async (file) => ({
|
|
24816
|
-
path:
|
|
24930
|
+
path: path52.join(destination, ...file.path.split("/")),
|
|
24817
24931
|
data: await readFile36(file.source)
|
|
24818
24932
|
})));
|
|
24819
24933
|
if (!options.force) {
|
|
@@ -24913,14 +25027,14 @@ async function runRecipe(args) {
|
|
|
24913
25027
|
}, null, 2));
|
|
24914
25028
|
} else {
|
|
24915
25029
|
log(` installed ${result.recipe.id}@${result.recipe.version}`);
|
|
24916
|
-
log(` ${
|
|
25030
|
+
log(` ${path53.relative(process.cwd(), result.destination) || "."}`);
|
|
24917
25031
|
log(`
|
|
24918
25032
|
Add this entry under your manifest's styles object:`);
|
|
24919
25033
|
log(JSON.stringify({ [result.styleId]: result.style }, null, 2));
|
|
24920
25034
|
if (result.recipe.models.length) {
|
|
24921
25035
|
log(`
|
|
24922
25036
|
Models are not downloaded automatically. Verify them with:`);
|
|
24923
|
-
log(` pixelkiln recipe verify ${
|
|
25037
|
+
log(` pixelkiln recipe verify ${path53.relative(process.cwd(), result.destination)} --model-root <ComfyUI/models>`);
|
|
24924
25038
|
}
|
|
24925
25039
|
}
|
|
24926
25040
|
return;
|
|
@@ -24928,7 +25042,7 @@ async function runRecipe(args) {
|
|
|
24928
25042
|
}
|
|
24929
25043
|
|
|
24930
25044
|
// src/cli/commands/refine.ts
|
|
24931
|
-
import
|
|
25045
|
+
import path54 from "path";
|
|
24932
25046
|
async function runRefine(args) {
|
|
24933
25047
|
if (args.from || args.subcommand === "approve") {
|
|
24934
25048
|
if (!args.from) {
|
|
@@ -24958,12 +25072,12 @@ async function runRefine(args) {
|
|
|
24958
25072
|
` recovered ${result3.detection.columns}x${result3.detection.rows} native grid (${result3.detection.confidence}: ${result3.detection.consensus})`
|
|
24959
25073
|
);
|
|
24960
25074
|
log(` enforced ${result3.palette.length}-color palette without dithering`);
|
|
24961
|
-
log(` wrote ${
|
|
24962
|
-
log(` quality record: ${
|
|
25075
|
+
log(` wrote ${path54.relative(process.cwd(), result3.output)}`);
|
|
25076
|
+
log(` quality record: ${path54.relative(process.cwd(), result3.record)}`);
|
|
24963
25077
|
log(`
|
|
24964
25078
|
Automated checks passed. Human 1\xD7 review is still required:`);
|
|
24965
25079
|
log(
|
|
24966
|
-
` pixelkiln refine approve --from ${
|
|
25080
|
+
` pixelkiln refine approve --from ${path54.relative(process.cwd(), result3.record)} --reviewer "Your Name"`
|
|
24967
25081
|
);
|
|
24968
25082
|
}
|
|
24969
25083
|
return;
|
|
@@ -24991,7 +25105,7 @@ async function runRefine(args) {
|
|
|
24991
25105
|
if (args.json) log(JSON.stringify(result3, null, 2));
|
|
24992
25106
|
else {
|
|
24993
25107
|
log(
|
|
24994
|
-
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${
|
|
25108
|
+
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
25109
|
);
|
|
24996
25110
|
}
|
|
24997
25111
|
return;
|
|
@@ -25000,7 +25114,7 @@ async function runRefine(args) {
|
|
|
25000
25114
|
if (args.json) {
|
|
25001
25115
|
log(JSON.stringify(result2, null, 2));
|
|
25002
25116
|
} else {
|
|
25003
|
-
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${
|
|
25117
|
+
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${path54.relative(process.cwd(), result2.output || result2.record)}`);
|
|
25004
25118
|
for (const reason of result2.reasons) log(` ${reason}`);
|
|
25005
25119
|
}
|
|
25006
25120
|
if (!result2.safe) process.exitCode = 1;
|
|
@@ -25046,7 +25160,7 @@ async function runRefine(args) {
|
|
|
25046
25160
|
log(` ${item.state.padEnd(16)} ${item.key} ${item.reason}`);
|
|
25047
25161
|
if (item.state === "needs-approval") {
|
|
25048
25162
|
log(
|
|
25049
|
-
` pixelkiln refine approve --from ${
|
|
25163
|
+
` pixelkiln refine approve --from ${path54.relative(process.cwd(), item.record)} --reviewer "Your Name"`
|
|
25050
25164
|
);
|
|
25051
25165
|
}
|
|
25052
25166
|
}
|
|
@@ -25057,7 +25171,7 @@ async function runRefine(args) {
|
|
|
25057
25171
|
}
|
|
25058
25172
|
|
|
25059
25173
|
// src/cli/commands/skeleton.ts
|
|
25060
|
-
import
|
|
25174
|
+
import path55 from "path";
|
|
25061
25175
|
import { existsSync as existsSync42 } from "fs";
|
|
25062
25176
|
import { readFile as readFile37, writeFile as writeFile21 } from "fs/promises";
|
|
25063
25177
|
|
|
@@ -25170,12 +25284,12 @@ var Canvas = class {
|
|
|
25170
25284
|
async function runEstimateSkeleton(args) {
|
|
25171
25285
|
const image = args.target;
|
|
25172
25286
|
if (!image) throw new UsageError("estimate-skeleton needs an image path: pixelkiln estimate-skeleton <image> [--out keypoints.json]");
|
|
25173
|
-
if (args.out && existsSync42(
|
|
25287
|
+
if (args.out && existsSync42(path55.resolve(args.out)) && !args.force) {
|
|
25174
25288
|
throw new UsageError(`${args.out} already exists; pass --force to replace it`);
|
|
25175
25289
|
}
|
|
25176
|
-
loadEnvFiles(
|
|
25290
|
+
loadEnvFiles(path55.dirname(path55.resolve(args.manifest)));
|
|
25177
25291
|
loadEnvFiles(process.cwd());
|
|
25178
|
-
const bytes = await readFile37(
|
|
25292
|
+
const bytes = await readFile37(path55.resolve(image));
|
|
25179
25293
|
const metadata = imageMetadata(bytes);
|
|
25180
25294
|
if (!metadata) throw new UsageError(`${image} is not a readable PNG or JPEG`);
|
|
25181
25295
|
const sizeProblem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
|
|
@@ -25187,7 +25301,7 @@ async function runEstimateSkeleton(args) {
|
|
|
25187
25301
|
const frames = args.frames ?? DEFAULT_SCAFFOLD_FRAMES;
|
|
25188
25302
|
const json = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames), null, 2);
|
|
25189
25303
|
if (args.out) {
|
|
25190
|
-
await writeFile21(
|
|
25304
|
+
await writeFile21(path55.resolve(args.out), json + "\n");
|
|
25191
25305
|
log(` wrote ${args.out}: the estimated pose and ${frames} frames to edit`);
|
|
25192
25306
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
25193
25307
|
} else {
|
|
@@ -25200,8 +25314,8 @@ async function runSkeletonPreview(args) {
|
|
|
25200
25314
|
let sourceFile2;
|
|
25201
25315
|
let label;
|
|
25202
25316
|
if (target.endsWith(".json")) {
|
|
25203
|
-
keypointsFile =
|
|
25204
|
-
sourceFile2 = args.from ?
|
|
25317
|
+
keypointsFile = path55.resolve(target);
|
|
25318
|
+
sourceFile2 = args.from ? path55.resolve(args.from) : void 0;
|
|
25205
25319
|
label = target;
|
|
25206
25320
|
} else {
|
|
25207
25321
|
const loaded = await loadManifest(args.manifest);
|
|
@@ -25213,7 +25327,7 @@ async function runSkeletonPreview(args) {
|
|
|
25213
25327
|
);
|
|
25214
25328
|
}
|
|
25215
25329
|
keypointsFile = spec.revision.keypointsFile;
|
|
25216
|
-
sourceFile2 = args.from ?
|
|
25330
|
+
sourceFile2 = args.from ? path55.resolve(args.from) : spec.revision.sourceFile;
|
|
25217
25331
|
label = `${spec.styleId}/${spec.assetId}`;
|
|
25218
25332
|
}
|
|
25219
25333
|
if (!existsSync42(keypointsFile)) throw new UsageError(`Keypoints file does not exist yet: ${keypointsFile}`);
|
|
@@ -25234,10 +25348,10 @@ async function runSkeletonPreview(args) {
|
|
|
25234
25348
|
source = decodePng(bytes);
|
|
25235
25349
|
}
|
|
25236
25350
|
}
|
|
25237
|
-
const out =
|
|
25351
|
+
const out = path55.resolve(args.out ?? keypointsFile.replace(/\.json$/, "") + ".preview.png");
|
|
25238
25352
|
await writeFile21(out, renderSkeletonSheet(set, { source }));
|
|
25239
25353
|
log(` ${label}: ${set.frames.length} frames after the starting pose`);
|
|
25240
|
-
const shown =
|
|
25354
|
+
const shown = path55.relative(process.cwd(), out);
|
|
25241
25355
|
log(` wrote ${shown.startsWith("..") ? out : shown}`);
|
|
25242
25356
|
}
|
|
25243
25357
|
|
|
@@ -25283,15 +25397,15 @@ async function runTools(args) {
|
|
|
25283
25397
|
}
|
|
25284
25398
|
|
|
25285
25399
|
// src/cli/commands/workspace.ts
|
|
25286
|
-
import
|
|
25400
|
+
import path56 from "path";
|
|
25287
25401
|
import { existsSync as existsSync43 } from "fs";
|
|
25288
25402
|
async function runWorkspace(args) {
|
|
25289
|
-
const workspacePath =
|
|
25290
|
-
const dir =
|
|
25403
|
+
const workspacePath = path56.resolve(args.workspace ?? "pixelkiln.workspace.json");
|
|
25404
|
+
const dir = path56.dirname(workspacePath);
|
|
25291
25405
|
if (args.subcommand === "add") {
|
|
25292
|
-
const manifestPath =
|
|
25406
|
+
const manifestPath = path56.resolve(args.target);
|
|
25293
25407
|
const loadedTarget = await loadManifest(manifestPath);
|
|
25294
|
-
const lockPath = args.explicitLock ?
|
|
25408
|
+
const lockPath = args.explicitLock ? path56.resolve(args.explicitLock) : path56.join(path56.dirname(manifestPath), "pixelkiln.lock.json");
|
|
25295
25409
|
const ws = await loadWorkspace(workspacePath);
|
|
25296
25410
|
const id = args.name ?? loadedTarget.manifest.name;
|
|
25297
25411
|
if (ws.projects.some((p) => p.id === id)) {
|
|
@@ -25311,7 +25425,7 @@ async function runWorkspace(args) {
|
|
|
25311
25425
|
...args.account ? { account: args.account } : {}
|
|
25312
25426
|
};
|
|
25313
25427
|
await saveWorkspace(workspacePath, { version: 1, projects: [...ws.projects, project] });
|
|
25314
|
-
log(` registered "${id}" in ${
|
|
25428
|
+
log(` registered "${id}" in ${path56.relative(process.cwd(), workspacePath)}`);
|
|
25315
25429
|
log(` manifest: ${project.manifest}`);
|
|
25316
25430
|
log(` lock: ${project.lock}`);
|
|
25317
25431
|
if (!existsSync43(lockPath)) {
|
|
@@ -25323,7 +25437,7 @@ async function runWorkspace(args) {
|
|
|
25323
25437
|
}
|
|
25324
25438
|
if (args.subcommand === "remove") {
|
|
25325
25439
|
const ws = await loadWorkspace(workspacePath);
|
|
25326
|
-
const resolvedTarget =
|
|
25440
|
+
const resolvedTarget = path56.resolve(args.target);
|
|
25327
25441
|
const match = ws.projects.find(
|
|
25328
25442
|
(p) => p.id === args.target || resolveProject(dir, p).manifestPath === resolvedTarget
|
|
25329
25443
|
);
|
|
@@ -25334,7 +25448,7 @@ async function runWorkspace(args) {
|
|
|
25334
25448
|
version: 1,
|
|
25335
25449
|
projects: ws.projects.filter((p) => p !== match)
|
|
25336
25450
|
});
|
|
25337
|
-
log(` removed "${match.id}" from ${
|
|
25451
|
+
log(` removed "${match.id}" from ${path56.relative(process.cwd(), workspacePath)}`);
|
|
25338
25452
|
return;
|
|
25339
25453
|
}
|
|
25340
25454
|
if (args.subcommand === "list") {
|
|
@@ -25346,9 +25460,9 @@ async function runWorkspace(args) {
|
|
|
25346
25460
|
if (args.json) {
|
|
25347
25461
|
log(JSON.stringify({ version: 1, workspace: workspacePath, projects: ws.projects, diagnostics }, null, 2));
|
|
25348
25462
|
} else if (!ws.projects.length) {
|
|
25349
|
-
log(` no projects registered in ${
|
|
25463
|
+
log(` no projects registered in ${path56.relative(process.cwd(), workspacePath)}`);
|
|
25350
25464
|
} else {
|
|
25351
|
-
log(` ${ws.projects.length} project(s) in ${
|
|
25465
|
+
log(` ${ws.projects.length} project(s) in ${path56.relative(process.cwd(), workspacePath)}:`);
|
|
25352
25466
|
for (const p of ws.projects) {
|
|
25353
25467
|
log(` ${p.id.padEnd(24)} ${p.manifest.padEnd(40)} (${p.provider}${p.account ? `, ${p.account}` : ""})`);
|
|
25354
25468
|
}
|
|
@@ -25366,7 +25480,7 @@ async function runWorkspace(args) {
|
|
|
25366
25480
|
if (args.json) {
|
|
25367
25481
|
log(JSON.stringify({ ...report, workspace: workspacePath }, null, 2));
|
|
25368
25482
|
} else {
|
|
25369
|
-
log(` workspace: ${
|
|
25483
|
+
log(` workspace: ${path56.relative(process.cwd(), workspacePath)}`);
|
|
25370
25484
|
for (const p of report.projects) {
|
|
25371
25485
|
if (p.error) {
|
|
25372
25486
|
log(`
|