comfy-ts 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +65 -225
  2. package/dist/{DefinedWorkflow-CqNE_kgR.js → DefinedWorkflow-CwHInZgn.js} +4 -3
  3. package/dist/DefinedWorkflow-CwHInZgn.js.map +1 -0
  4. package/dist/{DraftsSt-Da4DZUP7.js → DraftsSt-omWuBSej.js} +3 -4
  5. package/dist/DraftsSt-omWuBSej.js.map +1 -0
  6. package/dist/cli.js +3 -3
  7. package/dist/index.cjs +22 -5
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +12 -2
  10. package/dist/index.d.ts +12 -2
  11. package/dist/index.js +22 -5
  12. package/dist/index.js.map +1 -1
  13. package/dist/{run-serve-BqeXtf8P.js → run-serve-C1oo5ilG.js} +170 -126
  14. package/dist/run-serve-C1oo5ilG.js.map +1 -0
  15. package/dist/{run-tui-CiB7TbYv.js → run-tui-CuVst-nc.js} +298 -103
  16. package/dist/run-tui-CuVst-nc.js.map +1 -0
  17. package/dist/{state-C1g_B8zR.js → state-CvMt0W1-.js} +23 -7
  18. package/dist/state-CvMt0W1-.js.map +1 -0
  19. package/dist/web.d.ts +12 -2
  20. package/dist/web.js +22 -5
  21. package/dist/web.js.map +1 -1
  22. package/examples/README.md +6 -18
  23. package/examples/images/README.md +2 -6
  24. package/guide-for-agents.md +25 -84
  25. package/package.json +1 -1
  26. package/src/cli/serve/ServeApp.ts +17 -11
  27. package/src/cli/serve/applyVarPayload.ts +91 -71
  28. package/src/cli/serve/describeVar.ts +57 -28
  29. package/src/cli/tui/components/StatusBar.tsx +1 -0
  30. package/src/cli/tui/components/TextOverlay.tsx +7 -3
  31. package/src/cli/tui/components/TuiApp.tsx +4 -5
  32. package/src/cli/tui/components/VarsPanel.tsx +42 -4
  33. package/src/cli/tui/imageClipboard.ts +40 -0
  34. package/src/cli/tui/state/DraftsSt.ts +1 -2
  35. package/src/cli/tui/state/ExecSt.ts +146 -98
  36. package/src/cli/tui/state/PreviewSt.ts +12 -11
  37. package/src/cli/tui/state/SettingsSt.ts +13 -0
  38. package/src/cli/tui/state/TuiSt.ts +65 -11
  39. package/src/host/ComfyHost.ts +5 -1
  40. package/src/runner/ComfyExecution.ts +15 -7
  41. package/src/runner/outputPath.ts +11 -0
  42. package/src/vars/ComfyVars.ts +12 -2
  43. package/dist/DefinedWorkflow-CqNE_kgR.js.map +0 -1
  44. package/dist/DraftsSt-Da4DZUP7.js.map +0 -1
  45. package/dist/run-serve-BqeXtf8P.js.map +0 -1
  46. package/dist/run-tui-CiB7TbYv.js.map +0 -1
  47. package/dist/state-C1g_B8zR.js.map +0 -1
@@ -1,6 +1,6 @@
1
- import { i as stripAnsi, n as settingsPathFor, o as sha1HexOfString } from "./state-C1g_B8zR.js";
2
- import { c as PromptVar, g as getComfyStorage, h as extractErrorMessage, m as setLoraKeyword, p as getLoraKeyword, s as LorasVar, y as logError } from "./DefinedWorkflow-CqNE_kgR.js";
3
- import { a as assignFamilyColors, c as findDefinedWorkflow, i as listDraftsForFile, l as mergeWorkflowSources, n as draftKeyForFile, o as buildFileRows, s as familyOf, t as DraftsSt, u as scanCflowFiles } from "./DraftsSt-Da4DZUP7.js";
1
+ import { a as importSharp, i as stripAnsi, n as settingsPathFor, s as sha1HexOfString } from "./state-CvMt0W1-.js";
2
+ import { a as setLoraKeyword, i as getLoraKeyword, n as LorasVar, o as extractErrorMessage, r as PromptVar, s as getComfyStorage, u as logError } from "./DefinedWorkflow-CwHInZgn.js";
3
+ import { a as assignFamilyColors, c as findDefinedWorkflow, i as listDraftsForFile, l as mergeWorkflowSources, n as draftKeyForFile, o as buildFileRows, s as familyOf, t as DraftsSt, u as scanCflowFiles } from "./DraftsSt-omWuBSej.js";
4
4
  import { spawn } from "node:child_process";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
6
6
  import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
@@ -12,7 +12,7 @@ import { Box, Text, measureElement, render, useApp, useInput, useStdin } from "i
12
12
  import sharp from "sharp";
13
13
  import { observer } from "mobx-react-lite";
14
14
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
- import { homedir } from "node:os";
15
+ import { homedir, tmpdir } from "node:os";
16
16
  import { useEffect, useRef } from "react";
17
17
  //#region src/cli/tui-env.ts
18
18
  const COMFY_TS_TUI_ENV = "COMFY_TS_TUI";
@@ -109,7 +109,7 @@ var PreviewSt = class {
109
109
  this.latentBytes = null;
110
110
  this.latentDims = null;
111
111
  this.latentSeenThisRun = false;
112
- this.lastOutputPath = null;
112
+ this.lastOutput = null;
113
113
  this.overlay = null;
114
114
  this.menuIx = 0;
115
115
  this._busy = false;
@@ -200,7 +200,7 @@ var PreviewSt = class {
200
200
  this.latentBytes = null;
201
201
  this.latentDims = null;
202
202
  this.latentSeenThisRun = false;
203
- this.lastOutputPath = null;
203
+ this.lastOutput = null;
204
204
  }
205
205
  /** run boundary: drop the latents so the next run never shows the previous one's */
206
206
  clearLatent() {
@@ -213,7 +213,7 @@ var PreviewSt = class {
213
213
  onSettingsChanged() {
214
214
  this.outputAnsi = null;
215
215
  this.outputBytes = null;
216
- if (this.show && this.lastOutputPath != null) this.renderOutput(this.lastOutputPath);
216
+ if (this.show && this.lastOutput != null) this.renderOutput(this.lastOutput);
217
217
  }
218
218
  /** what the painter should show RIGHT NOW (native renderer only; mirrors the panel's source) */
219
219
  get protocolImage() {
@@ -260,12 +260,12 @@ var PreviewSt = class {
260
260
  get height() {
261
261
  return Math.max(10, this.st.termRows - 12);
262
262
  }
263
- async renderOutput(path) {
264
- this.lastOutputPath = path;
263
+ async renderOutput(src) {
264
+ this.lastOutput = src;
265
265
  if (!this.show) return;
266
266
  try {
267
267
  if (this.useNative) {
268
- const shrunk = await sharp(path).resize(896, 896, {
268
+ const shrunk = await sharp(src).resize(896, 896, {
269
269
  fit: "inside",
270
270
  withoutEnlargement: true
271
271
  }).png().toBuffer();
@@ -274,7 +274,7 @@ var PreviewSt = class {
274
274
  });
275
275
  return;
276
276
  }
277
- const rendered = await imageBufferToAnsi(path, {
277
+ const rendered = await imageBufferToAnsi(src, {
278
278
  width: this.width,
279
279
  height: this.height
280
280
  });
@@ -326,12 +326,12 @@ var PreviewSt = class {
326
326
  const pxW = this.width;
327
327
  const pxH = this.height * 2;
328
328
  const thumb = await sharp(bytes).resize(Math.max(8, Math.floor(pxW * PIXEL_SMALL_FRACTION)), Math.max(8, Math.floor(pxH * PIXEL_SMALL_FRACTION)), { fit: "inside" }).png().toBuffer();
329
- const outPath = this.lastOutputPath;
330
- if (outPath == null) return imageBufferToAnsi(thumb, {
329
+ const out = this.lastOutput;
330
+ if (out == null) return imageBufferToAnsi(thumb, {
331
331
  width: this.width,
332
332
  height: this.height
333
333
  });
334
- return imageBufferToAnsi(await sharp(await sharp(outPath).resize(pxW, pxH, { fit: "inside" }).png().toBuffer()).composite([{
334
+ return imageBufferToAnsi(await sharp(await sharp(out).resize(pxW, pxH, { fit: "inside" }).png().toBuffer()).composite([{
335
335
  input: thumb,
336
336
  gravity: "northeast"
337
337
  }]).png().toBuffer(), {
@@ -477,6 +477,7 @@ const ProgressLine = observer((p) => {
477
477
  });
478
478
  const KIND_KEYS = {
479
479
  text: [["⏎/→", "edit"]],
480
+ prompt: [["⏎/→", "edit"]],
480
481
  int: [["⏎/→", "edit"]],
481
482
  float: [["⏎/→", "edit"]],
482
483
  seed: [
@@ -1607,9 +1608,10 @@ const TextOverlay = observer((p) => {
1607
1608
  const s = p.st;
1608
1609
  const ed = s.editor;
1609
1610
  const winLines = s.overlayLines;
1610
- const promptVar = s.selected?.[1];
1611
- const isPrompt = promptVar instanceof PromptVar;
1612
- const injected = isPrompt ? promptVar.injectedKeywords() : [];
1611
+ const selectedVar = s.selected?.[1];
1612
+ const promptVar = selectedVar?.kind === "prompt" ? selectedVar : null;
1613
+ const isPrompt = promptVar != null;
1614
+ const injected = promptVar?.injectedKeywords() ?? [];
1613
1615
  const lines = [];
1614
1616
  let start = 0;
1615
1617
  for (const text of ed.buffer.split("\n")) {
@@ -1858,7 +1860,7 @@ const VarRow = observer((p) => {
1858
1860
  color: "cyan",
1859
1861
  wrap: "truncate",
1860
1862
  children: value.replaceAll("\n", " ")
1861
- }) : p.varDef instanceof PromptVar ? /* @__PURE__ */ jsx(PromptCell, {
1863
+ }) : p.varDef.kind === "prompt" ? /* @__PURE__ */ jsx(PromptCell, {
1862
1864
  varDef: p.varDef,
1863
1865
  value
1864
1866
  }) : /* @__PURE__ */ jsx(Text, {
@@ -1872,7 +1874,7 @@ const VarRow = observer((p) => {
1872
1874
  });
1873
1875
  const VarsPanel = observer((p) => {
1874
1876
  const s = p.st;
1875
- const labelW = Math.max(6, ...s.entries.map(([name, v]) => (v.label ?? name).length)) + 3;
1877
+ const labelW = Math.max(12, ...s.entries.map(([name, v]) => (v.label ?? name).length)) + 3;
1876
1878
  const focused = s.mode === "nav" || s.mode === "edit";
1877
1879
  const boxRef = useRef(null);
1878
1880
  useEffect(() => {
@@ -1899,7 +1901,7 @@ const VarsPanel = observer((p) => {
1899
1901
  color: "gray",
1900
1902
  children: "…"
1901
1903
  }),
1902
- s.entries.slice(w.start, w.end).map(([name, varDef], sliceIx) => /* @__PURE__ */ jsx(VarRow, {
1904
+ s.entries.slice(w.start, Math.min(w.end, s.entries.length)).map(([name, varDef], sliceIx) => /* @__PURE__ */ jsx(VarRow, {
1903
1905
  name,
1904
1906
  varDef,
1905
1907
  selected: w.start + sliceIx === s.selIx,
@@ -1907,6 +1909,68 @@ const VarsPanel = observer((p) => {
1907
1909
  st: s,
1908
1910
  compact: s.varsCompact
1909
1911
  }, name)),
1912
+ w.end > s.entries.length && /* @__PURE__ */ jsxs(Box, {
1913
+ flexDirection: "row",
1914
+ children: [
1915
+ /* @__PURE__ */ jsx(Box, {
1916
+ width: labelW,
1917
+ flexShrink: 0,
1918
+ children: /* @__PURE__ */ jsxs(Text, {
1919
+ inverse: s.onSaveRow,
1920
+ children: [s.onSaveRow ? "▸ " : " ", "save to disk"]
1921
+ })
1922
+ }),
1923
+ /* @__PURE__ */ jsx(Box, {
1924
+ width: 9,
1925
+ flexShrink: 0,
1926
+ children: /* @__PURE__ */ jsx(Text, {
1927
+ color: "gray",
1928
+ children: "[tui]"
1929
+ })
1930
+ }),
1931
+ /* @__PURE__ */ jsx(Box, {
1932
+ flexGrow: 1,
1933
+ children: /* @__PURE__ */ jsx(Text, {
1934
+ color: s.settings.saveToDisk ? "cyan" : "yellow",
1935
+ wrap: "truncate",
1936
+ children: s.settings.saveToDisk ? "on" : "off — outputs stay in memory"
1937
+ })
1938
+ })
1939
+ ]
1940
+ }),
1941
+ s.settings.saveToDisk && w.end > s.entries.length + 1 && /* @__PURE__ */ jsxs(Box, {
1942
+ flexDirection: "row",
1943
+ children: [
1944
+ /* @__PURE__ */ jsx(Box, {
1945
+ width: labelW,
1946
+ flexShrink: 0,
1947
+ children: /* @__PURE__ */ jsxs(Text, {
1948
+ inverse: s.onPrefixRow,
1949
+ children: [s.onPrefixRow ? "▸ " : " ", "save prefix"]
1950
+ })
1951
+ }),
1952
+ /* @__PURE__ */ jsx(Box, {
1953
+ width: 9,
1954
+ flexShrink: 0,
1955
+ children: /* @__PURE__ */ jsx(Text, {
1956
+ color: "gray",
1957
+ children: "[tui]"
1958
+ })
1959
+ }),
1960
+ /* @__PURE__ */ jsx(Box, {
1961
+ flexGrow: 1,
1962
+ children: /* @__PURE__ */ jsxs(Text, {
1963
+ color: "cyan",
1964
+ wrap: "truncate",
1965
+ children: [
1966
+ ".comfy-ts/outputs/",
1967
+ s.savePrefix,
1968
+ "/"
1969
+ ]
1970
+ })
1971
+ })
1972
+ ]
1973
+ }),
1910
1974
  w.moreBelow && /* @__PURE__ */ jsx(Text, {
1911
1975
  color: "gray",
1912
1976
  children: "…"
@@ -2170,22 +2234,22 @@ const TuiApp = observer((p) => {
2170
2234
  paddingX: 1,
2171
2235
  children: /* @__PURE__ */ jsx(ProgressLine, { st: s })
2172
2236
  }),
2173
- s.exec.outputs.length > 0 && /* @__PURE__ */ jsx(Box, {
2237
+ s.exec.outputLabels.length > 0 && /* @__PURE__ */ jsx(Box, {
2174
2238
  borderStyle: "round",
2175
2239
  paddingX: 1,
2176
2240
  flexDirection: "column",
2177
- children: s.exec.outputs.map((o) => /* @__PURE__ */ jsxs(Text, {
2178
- color: "green",
2241
+ children: s.exec.outputLabels.map((o, ix) => /* @__PURE__ */ jsxs(Text, {
2242
+ color: o.memory ? "yellow" : "green",
2179
2243
  wrap: "truncate",
2180
2244
  children: [
2181
- basename(o),
2245
+ o.name,
2182
2246
  " ",
2183
2247
  /* @__PURE__ */ jsx(Text, {
2184
2248
  color: "gray",
2185
- children: o
2249
+ children: o.detail
2186
2250
  })
2187
2251
  ]
2188
- }, o))
2252
+ }, `${ix}-${o.name}`))
2189
2253
  }),
2190
2254
  !s.mode.startsWith("overlay-") && !(s.mode === "edit" && s.editor.isCustom) && /* @__PURE__ */ jsx(LogsPanel, { st: s })
2191
2255
  ]
@@ -2512,6 +2576,36 @@ const extOf = (path) => {
2512
2576
  const dot = path.lastIndexOf(".");
2513
2577
  return dot === -1 ? "" : path.slice(dot + 1).toLowerCase();
2514
2578
  };
2579
+ const imageClipboardStdinCommand = (platform, pngBytes) => {
2580
+ if (platform === "darwin") {
2581
+ const hex = Buffer.from(pngBytes).toString("hex").toUpperCase();
2582
+ return {
2583
+ cmd: "osascript",
2584
+ args: ["-"],
2585
+ stdin: new TextEncoder().encode(`set the clipboard to «data PNGf${hex}»`)
2586
+ };
2587
+ }
2588
+ if (platform === "win32") return {
2589
+ cmd: "powershell",
2590
+ args: [
2591
+ "-NoProfile",
2592
+ "-Sta",
2593
+ "-Command",
2594
+ "$b=[Convert]::FromBase64String([Console]::In.ReadToEnd()); $ms=New-Object System.IO.MemoryStream(,$b); Add-Type -AssemblyName System.Windows.Forms,System.Drawing; $img=[System.Drawing.Image]::FromStream($ms); [System.Windows.Forms.Clipboard]::SetImage($img); $img.Dispose()"
2595
+ ],
2596
+ stdin: new TextEncoder().encode(Buffer.from(pngBytes).toString("base64"))
2597
+ };
2598
+ return {
2599
+ cmd: "xclip",
2600
+ args: [
2601
+ "-selection",
2602
+ "clipboard",
2603
+ "-t",
2604
+ "image/png"
2605
+ ],
2606
+ stdin: pngBytes
2607
+ };
2608
+ };
2515
2609
  const imageClipboardCommand = (platform, path) => {
2516
2610
  const ext = extOf(path);
2517
2611
  if (platform === "darwin") {
@@ -2558,7 +2652,7 @@ var ExecSt = class {
2558
2652
  this.st = st;
2559
2653
  this.inFlight = 0;
2560
2654
  this.progress = null;
2561
- this.outputs = [];
2655
+ this.outputImages = [];
2562
2656
  this.runCount = 0;
2563
2657
  this.lastStatus = null;
2564
2658
  this.error = null;
@@ -2572,19 +2666,40 @@ var ExecSt = class {
2572
2666
  get running() {
2573
2667
  return this.inFlight > 0;
2574
2668
  }
2575
- /** local save dir for this module's outputs (same key the drafts use) */
2576
- get saveDirPrefix() {
2577
- const cur = this.st.workflows.currentPath;
2578
- return cur != null ? draftKeyForFile(cur) : this.st.wf.spec.id ?? "workflow";
2579
- }
2580
2669
  /** workflow switch: wipe run artifacts, keep a hello notice */
2581
2670
  resetForWorkflow(notice) {
2582
- this.outputs = [];
2671
+ this.outputImages = [];
2583
2672
  this.error = null;
2584
2673
  this.notice = notice;
2585
2674
  this.runCount = 0;
2586
2675
  this.lastStatus = null;
2587
2676
  }
2677
+ /** outputs box rows: path when saved, honest memory label otherwise */
2678
+ get outputLabels() {
2679
+ return this.outputImages.map((img) => {
2680
+ if (img.absPath != null) return {
2681
+ name: basename(img.absPath),
2682
+ detail: img.absPath,
2683
+ memory: false
2684
+ };
2685
+ const dims = img.width != null && img.height != null ? `${img.width}x${img.height}, ` : "";
2686
+ return {
2687
+ name: img.filename,
2688
+ detail: `(${dims}in memory — i copies, o opens)`,
2689
+ memory: true
2690
+ };
2691
+ });
2692
+ }
2693
+ /** a file path for viewer/clipboard: the saved file, or the bytes
2694
+ * materialized into os tmpdir (deliberate user action, never a silent
2695
+ * save — architecture item 14). The path derives from the content hash,
2696
+ * so re-materializing is a cheap existsSync, no retention needed. */
2697
+ materialize(img) {
2698
+ if (img.absPath != null) return img.absPath;
2699
+ const path = join(tmpdir(), `comfy-ts-mem-${img.hash.slice(0, 8)}${img.extension}`);
2700
+ if (!existsSync(path)) writeFileSync(path, img.buffer);
2701
+ return path;
2702
+ }
2588
2703
  /** every run takes THIS path, queued ones included: same progress, outputs, previews */
2589
2704
  async run() {
2590
2705
  const queued = this.running;
@@ -2605,16 +2720,16 @@ var ExecSt = class {
2605
2720
  try {
2606
2721
  const execution = await this.st.wf.run({
2607
2722
  host: this.st.hostOverride ?? void 0,
2608
- save: { prefix: this.saveDirPrefix },
2723
+ save: this.st.settings.saveToDisk ? { prefix: this.st.savePrefix } : false,
2609
2724
  onProgress: (p) => runInAction(() => this.onProgress(p))
2610
2725
  });
2611
2726
  runInAction(() => {
2612
- this.outputs = execution.images.map((i) => i.absPath).filter((p) => p != null);
2727
+ this.outputImages = execution.images.slice();
2613
2728
  this.lastStatus = execution.status;
2614
2729
  this.runCount++;
2615
2730
  });
2616
2731
  const lastImage = execution.images[execution.images.length - 1];
2617
- if (lastImage?.absPath != null) this.st.preview.renderOutput(lastImage.absPath);
2732
+ if (lastImage != null) this.st.preview.renderOutput(lastImage.absPath ?? lastImage.buffer);
2618
2733
  } catch (e) {
2619
2734
  runInAction(() => {
2620
2735
  this.error = extractErrorMessage(e);
@@ -2647,11 +2762,18 @@ var ExecSt = class {
2647
2762
  }
2648
2763
  /** 'o': real pixels in the OS viewer — the in-terminal ceiling is half-blocks */
2649
2764
  openLastOutput() {
2650
- const last = this.outputs[this.outputs.length - 1];
2651
- if (last == null) {
2765
+ const lastImg = this.outputImages[this.outputImages.length - 1];
2766
+ if (lastImg == null) {
2652
2767
  this.notice = "no output image yet";
2653
2768
  return;
2654
2769
  }
2770
+ let last;
2771
+ try {
2772
+ last = this.materialize(lastImg);
2773
+ } catch (e) {
2774
+ this.notice = `open failed: ${extractErrorMessage(e)}`;
2775
+ return;
2776
+ }
2655
2777
  const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
2656
2778
  const proc = spawn(cmd, [last], {
2657
2779
  stdio: "ignore",
@@ -2663,12 +2785,16 @@ var ExecSt = class {
2663
2785
  });
2664
2786
  });
2665
2787
  proc.unref();
2666
- this.notice = `opened ${basename(last)}`;
2788
+ this.notice = `opened ${basename(last)}${lastImg.absPath == null ? ` (memory image via ${last})` : ""}`;
2667
2789
  }
2668
2790
  closeCopyPopup() {
2669
2791
  this.copyPopup = null;
2670
2792
  this.st.mode = "nav";
2671
2793
  }
2794
+ /** makeAutoObservable already annotates this method as an action, so the
2795
+ * post-await callers below need no runInAction of their own (verified
2796
+ * against mobx: a TS-private prototype method called after an `await`
2797
+ * opens its own action context; only a CONSTRUCTOR body does not) */
2672
2798
  showCopyPopup(title, ok, lines) {
2673
2799
  const m = this.st.mode;
2674
2800
  if (m === "edit" || m.startsWith("overlay-")) {
@@ -2682,42 +2808,67 @@ var ExecSt = class {
2682
2808
  };
2683
2809
  this.st.mode = "overlay-copy";
2684
2810
  }
2685
- /** 'i': the LAST generated image's pixels → clipboard (paste anywhere) */
2811
+ /** 'i': the LAST generated image's pixels → clipboard (paste anywhere).
2812
+ * The primary route pipes png bytes over stdin — no disk write at all
2813
+ * (his ask 2026-07-31); only when that tool fails does it fall back to
2814
+ * the materialized-file command, and the popup says which route ran. */
2686
2815
  async copyLastImage() {
2687
- const last = this.outputs[this.outputs.length - 1];
2688
- if (last == null) {
2816
+ const lastImg = this.outputImages[this.outputImages.length - 1];
2817
+ if (lastImg == null) {
2689
2818
  this.showCopyPopup("image → clipboard", false, ["no output image yet — r runs the workflow first"]);
2690
2819
  return;
2691
2820
  }
2692
- let file = last;
2693
- let command = imageClipboardCommand(process.platform, file);
2694
- if (command == null && process.platform === "darwin") try {
2695
- const { default: sharp } = await import("sharp");
2696
- const { tmpdir } = await import("node:os");
2697
- const { join } = await import("pathe");
2698
- file = join(tmpdir(), `comfy-ts-clip-${Date.now()}.png`);
2699
- await sharp(last).png().toFile(file);
2700
- command = imageClipboardCommand(process.platform, file);
2821
+ let pngBytes;
2822
+ try {
2823
+ pngBytes = lastImg.metadata.type === "png" ? lastImg.buffer : await this.toPngBytes(lastImg.buffer);
2701
2824
  } catch (e) {
2702
- this.showCopyPopup("image → clipboard", false, [`COPY FAILED for ${basename(last)}`, `png transcode failed: ${extractErrorMessage(e)}`]);
2825
+ this.showCopyPopup("image → clipboard", false, [`COPY FAILED for ${lastImg.filename}`, `png transcode failed: ${extractErrorMessage(e)}`]);
2703
2826
  return;
2704
2827
  }
2705
- if (command == null) {
2706
- this.showCopyPopup("image → clipboard", false, [`no clipboard image tool for ${process.platform}`]);
2828
+ const piped = imageClipboardStdinCommand(process.platform, pngBytes);
2829
+ if (await this.runWithStdin(piped)) {
2830
+ this.showCopyPopup("image → clipboard", true, [
2831
+ `${lastImg.filename} — paste the pixels anywhere`,
2832
+ "",
2833
+ "nothing written to disk"
2834
+ ]);
2707
2835
  return;
2708
2836
  }
2709
- const cmd = command;
2710
- const ok = await new Promise((resolve) => {
2711
- const proc = spawn(cmd.cmd, cmd.args, { stdio: "ignore" });
2837
+ let file;
2838
+ try {
2839
+ file = this.materialize(lastImg);
2840
+ } catch (e) {
2841
+ this.showCopyPopup("image → clipboard", false, [`COPY FAILED for ${lastImg.filename}`, `piped ${piped.cmd} failed, and the tmp-file fallback could not write: ${extractErrorMessage(e)}`]);
2842
+ return;
2843
+ }
2844
+ const command = imageClipboardCommand(process.platform, file);
2845
+ const ok = command != null && await new Promise((resolve) => {
2846
+ const proc = spawn(command.cmd, command.args, { stdio: "ignore" });
2712
2847
  proc.on("error", () => resolve(false));
2713
2848
  proc.on("close", (code) => resolve(code === 0));
2714
2849
  });
2715
- runInAction(() => {
2716
- this.showCopyPopup("image → clipboard", ok, ok ? [
2717
- `${basename(last)} — paste the pixels anywhere`,
2718
- "",
2719
- last
2720
- ] : [`COPY FAILED for ${basename(last)}`, `could not run ${cmd.cmd} — is it installed and allowed ?`]);
2850
+ this.showCopyPopup("image → clipboard", ok, ok ? [
2851
+ `${basename(file)} — paste the pixels anywhere`,
2852
+ "",
2853
+ `via fallback file ${file}`
2854
+ ] : [`COPY FAILED for ${lastImg.filename}`, `could not run ${piped.cmd} — is it installed and allowed ?`]);
2855
+ }
2856
+ async toPngBytes(bytes) {
2857
+ const sharp = await importSharp("the clipboard png normalize");
2858
+ return new Uint8Array(await sharp(bytes).png().toBuffer());
2859
+ }
2860
+ runWithStdin(p) {
2861
+ return new Promise((resolve) => {
2862
+ const proc = spawn(p.cmd, p.args, { stdio: [
2863
+ "pipe",
2864
+ "ignore",
2865
+ "ignore"
2866
+ ] });
2867
+ proc.on("error", () => resolve(false));
2868
+ proc.on("close", (code) => resolve(code === 0));
2869
+ proc.stdin.on("error", () => {});
2870
+ proc.stdin.write(p.stdin);
2871
+ proc.stdin.end();
2721
2872
  });
2722
2873
  }
2723
2874
  toClipboard(text) {
@@ -2749,22 +2900,18 @@ var ExecSt = class {
2749
2900
  const json = await (await this.st.wf.build({ host: this.st.hostOverride ?? void 0 })).toWorkflowJson();
2750
2901
  const text = JSON.stringify(json, null, 2);
2751
2902
  const ok = await this.toClipboard(text);
2752
- runInAction(() => {
2753
- this.showCopyPopup("workflow.json → clipboard", ok, ok ? [
2754
- `${json.nodes.length} nodes · ${text.length} chars — paste into the ComfyUI editor`,
2755
- "",
2756
- ...jsonHead(text, 10)
2757
- ] : ["CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?"]);
2758
- });
2903
+ this.showCopyPopup("workflow.json → clipboard", ok, ok ? [
2904
+ `${json.nodes.length} nodes · ${text.length} chars — paste into the ComfyUI editor`,
2905
+ "",
2906
+ ...jsonHead(text, 10)
2907
+ ] : ["CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?"]);
2759
2908
  } catch (e) {
2760
- runInAction(() => {
2761
- this.showCopyPopup("workflow.json copy FAILED", false, [
2762
- extractErrorMessage(e),
2763
- "",
2764
- "nothing was copied. i2i/i2v builds upload their input image first —",
2765
- "an unreachable host fails the build itself, not just the run."
2766
- ]);
2767
- });
2909
+ this.showCopyPopup("workflow.json copy FAILED", false, [
2910
+ extractErrorMessage(e),
2911
+ "",
2912
+ "nothing was copied. i2i/i2v builds upload their input image first —",
2913
+ "an unreachable host fails the build itself, not just the run."
2914
+ ]);
2768
2915
  } finally {
2769
2916
  runInAction(() => {
2770
2917
  this.copying = false;
@@ -2782,22 +2929,18 @@ var ExecSt = class {
2782
2929
  const json = (await this.st.wf.build({ host: this.st.hostOverride ?? void 0 })).toApiJson("use_stringified_numbers_only");
2783
2930
  const text = JSON.stringify(json, null, 2);
2784
2931
  const ok = await this.toClipboard(text);
2785
- runInAction(() => {
2786
- this.showCopyPopup("api.json → clipboard", ok, ok ? [
2787
- `${Object.keys(json).length} nodes · ${text.length} chars — the POST /prompt payload`,
2788
- "",
2789
- ...jsonHead(text, 10)
2790
- ] : ["CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?"]);
2791
- });
2932
+ this.showCopyPopup("api.json → clipboard", ok, ok ? [
2933
+ `${Object.keys(json).length} nodes · ${text.length} chars — the POST /prompt payload`,
2934
+ "",
2935
+ ...jsonHead(text, 10)
2936
+ ] : ["CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?"]);
2792
2937
  } catch (e) {
2793
- runInAction(() => {
2794
- this.showCopyPopup("api.json copy FAILED", false, [
2795
- extractErrorMessage(e),
2796
- "",
2797
- "nothing was copied. i2i/i2v builds upload their input image first —",
2798
- "an unreachable host fails the build itself, not just the run."
2799
- ]);
2800
- });
2938
+ this.showCopyPopup("api.json copy FAILED", false, [
2939
+ extractErrorMessage(e),
2940
+ "",
2941
+ "nothing was copied. i2i/i2v builds upload their input image first —",
2942
+ "an unreachable host fails the build itself, not just the run."
2943
+ ]);
2801
2944
  } finally {
2802
2945
  runInAction(() => {
2803
2946
  this.copying = false;
@@ -3671,6 +3814,8 @@ var SettingsSt = class {
3671
3814
  this.lastWorkflow = null;
3672
3815
  this.hostOverrideId = null;
3673
3816
  this.collapsedDirs = [];
3817
+ this.saveToDisk = true;
3818
+ this.savePrefix = {};
3674
3819
  this.load();
3675
3820
  if (this.previewRenderer === "native" && !protocolCapable()) this.previewRenderer = "pixel";
3676
3821
  makeAutoObservable(this, { st: false });
@@ -3685,7 +3830,9 @@ var SettingsSt = class {
3685
3830
  lastDraft: this.lastDraft,
3686
3831
  lastWorkflow: this.lastWorkflow,
3687
3832
  hostOverrideId: this.hostOverrideId,
3688
- collapsedDirs: this.collapsedDirs
3833
+ collapsedDirs: this.collapsedDirs,
3834
+ saveToDisk: this.saveToDisk,
3835
+ savePrefix: this.savePrefix
3689
3836
  });
3690
3837
  }
3691
3838
  rememberDraft(moduleKey, draft) {
@@ -3710,6 +3857,8 @@ var SettingsSt = class {
3710
3857
  if (typeof o.lastWorkflow === "string") this.lastWorkflow = o.lastWorkflow;
3711
3858
  if (typeof o.hostOverrideId === "string") this.hostOverrideId = o.hostOverrideId;
3712
3859
  if (Array.isArray(o.collapsedDirs)) this.collapsedDirs = o.collapsedDirs.filter((d) => typeof d === "string");
3860
+ if (typeof o.saveToDisk === "boolean") this.saveToDisk = o.saveToDisk;
3861
+ if (o.savePrefix != null && typeof o.savePrefix === "object") this.savePrefix = Object.fromEntries(Object.entries(o.savePrefix).filter((kv) => typeof kv[1] === "string"));
3713
3862
  } catch {}
3714
3863
  }
3715
3864
  write(json) {
@@ -4096,9 +4245,12 @@ var TuiSt = class {
4096
4245
  this.applyPersistedHostOverride();
4097
4246
  this.drafts.activateRemembered();
4098
4247
  if (opts.currentFile != null) {
4099
- this.tree.expandedFiles.add(opts.currentFile);
4100
- this.workflows.recordSpecColor(opts.currentFile, wf);
4101
- this.settings.lastWorkflow = opts.currentFile;
4248
+ const currentFile = opts.currentFile;
4249
+ runInAction(() => {
4250
+ this.tree.expandedFiles.add(currentFile);
4251
+ this.workflows.recordSpecColor(currentFile, wf);
4252
+ this.settings.lastWorkflow = currentFile;
4253
+ });
4102
4254
  }
4103
4255
  const onResize = () => {
4104
4256
  runInAction(() => {
@@ -4128,9 +4280,37 @@ var TuiSt = class {
4128
4280
  get selected() {
4129
4281
  return this.entries[this.selIx];
4130
4282
  }
4283
+ /** module key of the loaded workflow (drafts + savePrefix are keyed by it) */
4284
+ get moduleKey() {
4285
+ const cur = this.workflows.currentPath;
4286
+ return cur != null ? draftKeyForFile(cur) : this.wf.spec.id ?? "workflow";
4287
+ }
4288
+ /** the local save dir under .comfy-ts/outputs/ — per-module override, else the module key */
4289
+ get savePrefix() {
4290
+ return this.settings.savePrefix[this.moduleKey] ?? this.moduleKey;
4291
+ }
4292
+ /** empty input resets to the module-key default */
4293
+ setSavePrefix(raw) {
4294
+ const trimmed = raw.trim().replace(/^\/+|\/+$/g, "");
4295
+ if (trimmed === "" || trimmed === this.moduleKey) delete this.settings.savePrefix[this.moduleKey];
4296
+ else this.settings.savePrefix[this.moduleKey] = trimmed;
4297
+ }
4298
+ /** the vars list carries the TUI-owned rows after the workflow vars: the
4299
+ * save-to-disk toggle, plus the save-prefix row while saving is on
4300
+ * (architecture item 14) */
4301
+ get varRowCount() {
4302
+ return this.entries.length + (this.settings.saveToDisk ? 2 : 1);
4303
+ }
4304
+ /** true while the selection sits on the save-to-disk pseudo-row */
4305
+ get onSaveRow() {
4306
+ return this.selIx === this.entries.length;
4307
+ }
4308
+ /** true while the selection sits on the save-prefix pseudo-row */
4309
+ get onPrefixRow() {
4310
+ return this.settings.saveToDisk && this.selIx === this.entries.length + 1;
4311
+ }
4131
4312
  moveSel(delta) {
4132
- const len = this.entries.length;
4133
- if (len === 0) return;
4313
+ const len = this.varRowCount;
4134
4314
  this.selIx = (this.selIx + delta + len) % len;
4135
4315
  }
4136
4316
  setVarsViewH(h) {
@@ -4143,7 +4323,7 @@ var TuiSt = class {
4143
4323
  }
4144
4324
  get varsWindow() {
4145
4325
  return listWindow({
4146
- count: this.entries.length,
4326
+ count: this.varRowCount,
4147
4327
  selected: this.selIx,
4148
4328
  budget: this.varsBudget
4149
4329
  });
@@ -4158,14 +4338,29 @@ var TuiSt = class {
4158
4338
  const w = this.varsWindow;
4159
4339
  if (w.moreAbove || w.moreBelow) return true;
4160
4340
  const h = this.varsViewH > 0 ? this.varsViewH : Math.max(5, this.termRows - 5);
4161
- return this.entries.length + 2 > h;
4341
+ return this.varRowCount + 2 > h;
4162
4342
  }
4163
4343
  /** enter/space on a var: toggle, open an overlay, or inline-edit */
4164
4344
  activate() {
4345
+ if (this.onSaveRow) {
4346
+ this.settings.saveToDisk = !this.settings.saveToDisk;
4347
+ return;
4348
+ }
4349
+ if (this.onPrefixRow) {
4350
+ this.editor.beginCustom({
4351
+ title: `save prefix — dir under .comfy-ts/outputs/ (empty = ${this.moduleKey})`,
4352
+ initial: this.savePrefix,
4353
+ onCommit: (raw) => {
4354
+ this.setSavePrefix(raw);
4355
+ return true;
4356
+ }
4357
+ });
4358
+ return;
4359
+ }
4165
4360
  const sel = this.selected?.[1];
4166
4361
  if (sel == null) return;
4167
4362
  if (sel.kind === "toggle") sel.toggle();
4168
- else if (sel.kind === "text") this.editor.beginMultiline();
4363
+ else if (sel.kind === "text" || sel.kind === "prompt") this.editor.beginMultiline();
4169
4364
  else if (sel.kind === "choice") this.picker.beginChoice();
4170
4365
  else if (sel.kind === "size") this.picker.beginSize();
4171
4366
  else if (sel.kind === "loras") this.loras.begin();
@@ -4268,4 +4463,4 @@ async function runTui(args) {
4268
4463
  //#endregion
4269
4464
  export { runTui };
4270
4465
 
4271
- //# sourceMappingURL=run-tui-CiB7TbYv.js.map
4466
+ //# sourceMappingURL=run-tui-CuVst-nc.js.map