@koda-sl/baker-cli 0.360.0 → 0.361.0-dev.0306d9ad9

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 CHANGED
@@ -69,7 +69,7 @@ import {
69
69
  validateCanvasDeep,
70
70
  withoutCastName,
71
71
  ytDlpBlockSignal
72
- } from "./chunk-AI4HWQVN.js";
72
+ } from "./chunk-K2IKLMCM.js";
73
73
  import {
74
74
  csvOrJson,
75
75
  daysAgoIso,
@@ -40880,6 +40880,7 @@ async function clearCreativeDirty(slug, base) {
40880
40880
  }
40881
40881
 
40882
40882
  // src/commands/canvas/run-resume.ts
40883
+ import { readFileSync as readFileSync14 } from "fs";
40883
40884
  import { mkdir as mkdir4, readFile as readFile9, rm as rm4, writeFile as writeFile6 } from "fs/promises";
40884
40885
  import path13 from "path";
40885
40886
  function markerKey(canvasPath) {
@@ -40902,9 +40903,12 @@ function classifyRemoteRun(run, now) {
40902
40903
  }
40903
40904
  async function resolveRunId(opts) {
40904
40905
  if (opts.explicitRunId) return { runId: opts.explicitRunId, resumed: false };
40906
+ const existing = await readMarker(opts.outputsDir, opts.canvasPath);
40907
+ if (existing?.pid !== void 0 && existing.pid !== process.pid && (opts.isRendering ?? isRenderProcess)(existing.pid)) {
40908
+ return { runId: existing.runId, resumed: false, rendering: { runId: existing.runId, pid: existing.pid } };
40909
+ }
40905
40910
  if (!opts.fresh) {
40906
- const existing = await readMarkerRunId(opts.outputsDir, opts.canvasPath);
40907
- if (existing) return { runId: existing, resumed: true, source: "local" };
40911
+ if (existing) return { runId: existing.runId, resumed: true, source: "local" };
40908
40912
  if (opts.remote) {
40909
40913
  try {
40910
40914
  const active = await opts.remote.getActiveRun(opts.remote.creativeSlug, opts.remote.canvasSha);
@@ -40924,22 +40928,31 @@ async function resolveRunId(opts) {
40924
40928
  }
40925
40929
  return { runId: `r_${ulid()}`, resumed: false };
40926
40930
  }
40927
- async function readMarkerRunId(outputsDir, canvasPath) {
40931
+ async function readMarker(outputsDir, canvasPath) {
40928
40932
  for (const key of [markerKey(canvasPath), legacyMarkerKey(canvasPath)]) {
40929
40933
  try {
40930
40934
  const raw = await readFile9(markerFile(outputsDir, key), "utf8");
40931
40935
  const parsed = JSON.parse(raw);
40932
- if (typeof parsed.runId === "string" && parsed.runId.length > 0) return parsed.runId;
40936
+ if (typeof parsed.runId === "string" && parsed.runId.length > 0) {
40937
+ return { runId: parsed.runId, ...Number.isInteger(parsed.pid) ? { pid: parsed.pid } : {} };
40938
+ }
40933
40939
  } catch {
40934
40940
  }
40935
40941
  }
40936
40942
  return null;
40937
40943
  }
40944
+ function isRenderProcess(pid) {
40945
+ try {
40946
+ return readFileSync14(`/proc/${pid}/cmdline`, "utf8").includes("canvas");
40947
+ } catch {
40948
+ return false;
40949
+ }
40950
+ }
40938
40951
  async function markRunInFlight(outputsDir, canvasPath, runId) {
40939
40952
  try {
40940
40953
  const file = markerFile(outputsDir, markerKey(canvasPath));
40941
40954
  await mkdir4(path13.dirname(file), { recursive: true });
40942
- await writeFile6(file, JSON.stringify({ runId, canvasPath: path13.resolve(canvasPath), startedAt: Date.now() }));
40955
+ await writeFile6(file, JSON.stringify({ runId, pid: process.pid, canvasPath: path13.resolve(canvasPath), startedAt: Date.now() }));
40943
40956
  } catch {
40944
40957
  }
40945
40958
  }
@@ -41897,13 +41910,31 @@ ${describeRewrites(healed.rewrites)}
41897
41910
  const creativeSlug = creativeSlugFromCanvasPath(filePath) ?? void 0;
41898
41911
  const client = opts.record === false ? null : buildBackendClient();
41899
41912
  const outputsDir = opts.outputsDir ? path16.resolve(opts.outputsDir) : path16.resolve("canvas");
41900
- const { runId, resumed, source, concurrentRunId } = await resolveRunId({
41913
+ const { runId, resumed, source, concurrentRunId, rendering } = await resolveRunId({
41901
41914
  explicitRunId: opts.runId,
41902
41915
  fresh: opts.fresh === true,
41903
41916
  outputsDir,
41904
41917
  canvasPath: filePath,
41905
41918
  remote: client && creativeSlug ? { creativeSlug, canvasSha, getActiveRun: (slug, sha) => client.getActiveRun(slug, sha) } : void 0
41906
41919
  });
41920
+ if (rendering) {
41921
+ process.stderr.write(
41922
+ `${JSON.stringify(
41923
+ {
41924
+ ok: false,
41925
+ error: {
41926
+ code: "CONFLICT",
41927
+ message: `This canvas is already rendering in another process (run ${rendering.runId}, pid ${rendering.pid}).`,
41928
+ fix: "Wait for that render to finish and use its result instead of starting a second one: two renders of one canvas share a run and overwrite each other. If you started it in the background, read its output when it completes."
41929
+ }
41930
+ },
41931
+ null,
41932
+ 2
41933
+ )}
41934
+ `
41935
+ );
41936
+ process.exit(2);
41937
+ }
41907
41938
  if (resumed) {
41908
41939
  process.stdout.write(
41909
41940
  `[resume] continuing interrupted run ${runId}${source === "remote" ? " (adopted from run history)" : ""} \u2014 in-flight jobs re-attach, cached nodes skip
@@ -48257,11 +48288,11 @@ var addSideEffectCommand = defineCommand125({
48257
48288
  });
48258
48289
 
48259
48290
  // src/commands/flows/map.ts
48260
- import { readFileSync as readFileSync15 } from "fs";
48291
+ import { readFileSync as readFileSync16 } from "fs";
48261
48292
  import { defineCommand as defineCommand126 } from "citty";
48262
48293
 
48263
48294
  // src/commands/flows/value-expression.ts
48264
- import { existsSync as existsSync6, readFileSync as readFileSync14 } from "fs";
48295
+ import { existsSync as existsSync6, readFileSync as readFileSync15 } from "fs";
48265
48296
  import { join as join4 } from "path";
48266
48297
  var PREFIXES2 = ["field", "tracking", "global", "code"];
48267
48298
  function splitParts(raw) {
@@ -48348,7 +48379,7 @@ function trackingFieldIds() {
48348
48379
  const path48 = join4(flowsDir(), "..", "tracking.ts");
48349
48380
  if (!existsSync6(path48)) return null;
48350
48381
  try {
48351
- const source = readFileSync14(path48, "utf-8");
48382
+ const source = readFileSync15(path48, "utf-8");
48352
48383
  const block2 = source.match(/TRACKING_FIELD_IDS\s*=\s*\[([\s\S]*?)\]\s*as const/)?.[1];
48353
48384
  if (!block2) return null;
48354
48385
  const ids = [...block2.matchAll(/"(tracking\.[a-z0-9_]+)"/g)].map((match) => match[1]);
@@ -48925,7 +48956,7 @@ function specsFromFile(parsed) {
48925
48956
  function readSpecFile(path48) {
48926
48957
  let raw;
48927
48958
  try {
48928
- raw = path48 === "-" ? readFileSync15(0, "utf-8") : readFileSync15(path48, "utf-8");
48959
+ raw = path48 === "-" ? readFileSync16(0, "utf-8") : readFileSync16(path48, "utf-8");
48929
48960
  } catch (error) {
48930
48961
  refuse(
48931
48962
  `Could not read ${path48 === "-" ? "the mapping from stdin" : `"${path48}"`}: ${error instanceof Error ? error.message : String(error)}`
@@ -49624,7 +49655,7 @@ Full guide: __tooling__/docs/tools/baker/flows.md`
49624
49655
  });
49625
49656
 
49626
49657
  // src/commands/funnel/index.ts
49627
- import { readFileSync as readFileSync16 } from "fs";
49658
+ import { readFileSync as readFileSync17 } from "fs";
49628
49659
  import { defineCommand as defineCommand130 } from "citty";
49629
49660
 
49630
49661
  // src/commands/funnel/formMoments.ts
@@ -50420,7 +50451,7 @@ function workspaceForms() {
50420
50451
  const forms = [];
50421
50452
  for (const slug of listFlowSlugs()) {
50422
50453
  try {
50423
- forms.push({ slug, tree: JSON.parse(readFileSync16(flowDataPath(slug), "utf-8")) });
50454
+ forms.push({ slug, tree: JSON.parse(readFileSync17(flowDataPath(slug), "utf-8")) });
50424
50455
  } catch {
50425
50456
  }
50426
50457
  }
@@ -50555,7 +50586,7 @@ Examples:
50555
50586
  import { defineCommand as defineCommand132 } from "citty";
50556
50587
 
50557
50588
  // src/commands/ga4/shared.ts
50558
- import { readFileSync as readFileSync17 } from "fs";
50589
+ import { readFileSync as readFileSync18 } from "fs";
50559
50590
  function failValidation3(message) {
50560
50591
  writeJsonEnvelope({ ok: false, error: { code: "VALIDATION_ERROR", message } });
50561
50592
  process.exit(1);
@@ -50571,7 +50602,7 @@ function requireTarget5(args5, entity) {
50571
50602
  function readJsonSource(args5, flag) {
50572
50603
  const inline = args5[flag];
50573
50604
  const file = args5.file;
50574
- const raw = typeof file === "string" && file.length > 0 ? readFileSync17(file, "utf8") : typeof inline === "string" && inline.length > 0 ? inline : void 0;
50605
+ const raw = typeof file === "string" && file.length > 0 ? readFileSync18(file, "utf8") : typeof inline === "string" && inline.length > 0 ? inline : void 0;
50575
50606
  if (raw === void 0) {
50576
50607
  failValidation3(`pass --${flag} with inline JSON or --file with a path to a JSON file`);
50577
50608
  }
@@ -50922,7 +50953,7 @@ Examples:
50922
50953
  });
50923
50954
 
50924
50955
  // src/commands/ga4/query.ts
50925
- import { appendFileSync as appendFileSync2, existsSync as existsSync7, readFileSync as readFileSync18, writeFileSync as writeFileSync4 } from "fs";
50956
+ import { appendFileSync as appendFileSync2, existsSync as existsSync7, readFileSync as readFileSync19, writeFileSync as writeFileSync4 } from "fs";
50926
50957
  import { resolve as resolve2 } from "path";
50927
50958
  import { defineCommand as defineCommand135 } from "citty";
50928
50959
 
@@ -51013,7 +51044,7 @@ function writeRowsToFile2(filePath, rows, append) {
51013
51044
  writeFileSync4(filePath, content, "utf-8");
51014
51045
  }
51015
51046
  } else if (append && existsSync7(filePath)) {
51016
- const existing = JSON.parse(readFileSync18(filePath, "utf-8"));
51047
+ const existing = JSON.parse(readFileSync19(filePath, "utf-8"));
51017
51048
  writeFileSync4(filePath, JSON.stringify([...existing, ...rows], null, 2), "utf-8");
51018
51049
  } else {
51019
51050
  writeFileSync4(filePath, JSON.stringify(rows, null, 2), "utf-8");
@@ -51865,7 +51896,7 @@ Full guide: __tooling__/docs/tools/baker/ga4.md`
51865
51896
  import { defineCommand as defineCommand141 } from "citty";
51866
51897
 
51867
51898
  // src/commands/gsc/query.ts
51868
- import { appendFileSync as appendFileSync3, existsSync as existsSync8, readFileSync as readFileSync19, writeFileSync as writeFileSync5 } from "fs";
51899
+ import { appendFileSync as appendFileSync3, existsSync as existsSync8, readFileSync as readFileSync20, writeFileSync as writeFileSync5 } from "fs";
51869
51900
  import { resolve as resolve3 } from "path";
51870
51901
  import { defineCommand as defineCommand138 } from "citty";
51871
51902
 
@@ -52013,7 +52044,7 @@ function writeRowsToFile3(filePath, rows, append) {
52013
52044
  writeFileSync5(filePath, content, "utf-8");
52014
52045
  }
52015
52046
  } else if (append && existsSync8(filePath)) {
52016
- const existing = JSON.parse(readFileSync19(filePath, "utf-8"));
52047
+ const existing = JSON.parse(readFileSync20(filePath, "utf-8"));
52017
52048
  writeFileSync5(filePath, JSON.stringify([...existing, ...rows], null, 2), "utf-8");
52018
52049
  } else {
52019
52050
  writeFileSync5(filePath, JSON.stringify(rows, null, 2), "utf-8");
@@ -65647,7 +65678,7 @@ import { defineCommand as defineCommand221 } from "citty";
65647
65678
  import { defineCommand as defineCommand218 } from "citty";
65648
65679
 
65649
65680
  // src/commands/tag-manager/shared.ts
65650
- import { readFileSync as readFileSync20 } from "fs";
65681
+ import { readFileSync as readFileSync21 } from "fs";
65651
65682
  function failValidation5(message) {
65652
65683
  writeJsonEnvelope({ ok: false, error: { code: "VALIDATION_ERROR", message } });
65653
65684
  process.exit(1);
@@ -65663,7 +65694,7 @@ function requireTarget6(args5, entity) {
65663
65694
  function loadJsonArg2(args5, flag = "json") {
65664
65695
  const inline = args5[flag];
65665
65696
  const file = args5.file;
65666
- const raw = typeof file === "string" && file.length > 0 ? readFileSync20(file, "utf8") : typeof inline === "string" && inline.length > 0 ? inline : void 0;
65697
+ const raw = typeof file === "string" && file.length > 0 ? readFileSync21(file, "utf8") : typeof inline === "string" && inline.length > 0 ? inline : void 0;
65667
65698
  if (raw === void 0) {
65668
65699
  failValidation5(`pass --${flag} with inline JSON or --file with a path to a JSON file`);
65669
65700
  }
@@ -69066,7 +69097,7 @@ function outputFlagForCommand(root, argv) {
69066
69097
  }
69067
69098
 
69068
69099
  // src/version.ts
69069
- import { readFileSync as readFileSync21 } from "fs";
69100
+ import { readFileSync as readFileSync22 } from "fs";
69070
69101
  function packageJsonUrl() {
69071
69102
  return new URL("../package.json", import.meta.url);
69072
69103
  }
@@ -69078,7 +69109,7 @@ function parsePackageVersion(raw) {
69078
69109
  throw new Error("Invalid CLI package.json: missing version");
69079
69110
  }
69080
69111
  function getCliVersion() {
69081
- return parsePackageVersion(readFileSync21(packageJsonUrl(), "utf8"));
69112
+ return parsePackageVersion(readFileSync22(packageJsonUrl(), "utf8"));
69082
69113
  }
69083
69114
 
69084
69115
  // src/cli.ts