comfy-ts 1.0.0 → 1.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.
- package/README.md +60 -11
- package/dist/cli.js +4 -4439
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +445 -172
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7439 -340
- package/dist/index.d.ts +7457 -358
- package/dist/index.js +444 -172
- package/dist/index.js.map +1 -1
- package/dist/{run-tui-BFhba_oG.js → run-tui-BAdizWsO.js} +1244 -201
- package/dist/run-tui-BAdizWsO.js.map +1 -0
- package/dist/state-BYbxDgfr.js +5258 -0
- package/dist/state-BYbxDgfr.js.map +1 -0
- package/examples/README.md +32 -0
- package/examples/comfy-cloud/ace-step-t2a.cflow.ts +79 -0
- package/examples/comfy-cloud/anima-t2i.cflow.ts +57 -0
- package/examples/comfy-cloud/boogu-i2i.cflow.ts +76 -0
- package/examples/comfy-cloud/capybara-i2i.cflow.ts +85 -0
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +90 -0
- package/examples/comfy-cloud/capybara-t2i.cflow.ts +67 -0
- package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +79 -0
- package/examples/comfy-cloud/chroma-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/cloudHost.ts +41 -0
- package/examples/comfy-cloud/ernie-t2i.cflow.ts +59 -0
- package/examples/comfy-cloud/firered-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/flux1-i2i.cflow.ts +76 -0
- package/examples/comfy-cloud/flux1-t2i.cflow.ts +63 -0
- package/examples/comfy-cloud/flux2-i2i.cflow.ts +80 -0
- package/examples/comfy-cloud/flux2-t2i.cflow.ts +57 -0
- package/examples/comfy-cloud/hidream-i2i.cflow.ts +89 -0
- package/examples/comfy-cloud/hidream-t2i.cflow.ts +65 -0
- package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +93 -0
- package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +74 -0
- package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +80 -0
- package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +95 -0
- package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +60 -0
- package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +78 -0
- package/examples/comfy-cloud/krea2-t2i.cflow.ts +59 -0
- package/examples/comfy-cloud/lens-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/longcat-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/longcat-t2i.cflow.ts +65 -0
- package/examples/comfy-cloud/ltxv-i2v.cflow.ts +92 -0
- package/examples/comfy-cloud/ltxv-t2v.cflow.ts +78 -0
- package/examples/comfy-cloud/newbie-t2i.cflow.ts +67 -0
- package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +86 -0
- package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/ovis-t2i.cflow.ts +56 -0
- package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +63 -0
- package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +69 -0
- package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +55 -0
- package/examples/comfy-cloud/sd35-t2i.cflow.ts +48 -0
- package/examples/comfy-cloud/sdk.d.ts +445 -57
- package/examples/comfy-cloud/sdxl-t2i.cflow.ts +69 -0
- package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +53 -0
- package/examples/comfy-cloud/svd-i2v.cflow.ts +75 -0
- package/examples/comfy-cloud/wan21-i2v.cflow.ts +83 -0
- package/examples/comfy-cloud/wan21-t2v.cflow.ts +64 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +69 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +107 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +98 -0
- package/examples/comfy-cloud/z-image-t2i.cflow.ts +62 -0
- package/examples/images/README.md +18 -0
- package/examples/images/bear_1024x1024.jpg +0 -0
- package/examples/images/deer_768x1344.jpg +0 -0
- package/examples/images/dog_512x512.jpg +0 -0
- package/examples/images/lioness_768x768.jpg +0 -0
- package/examples/images/pug_200x300.jpg +0 -0
- package/examples/images/walrus_1344x768.jpg +0 -0
- package/examples/{01-txt2img.cflow.ts → rvion/01-txt2img.cflow.ts} +1 -1
- package/examples/{02-img2img-upload.cflow.ts → rvion/02-img2img-upload.cflow.ts} +7 -18
- package/examples/{03-export-workflow-json.cflow.ts → rvion/03-export-workflow-json.cflow.ts} +1 -1
- package/examples/{04-krea2-turbo-t2i.cflow.ts → rvion/04-krea2-turbo-t2i.cflow.ts} +2 -2
- package/examples/rvion/05-comfy-cloud.cflow.ts +51 -0
- package/examples/rvion/06-qwen-image-edit.cflow.ts +89 -0
- package/guide-for-agents.md +7 -1
- package/package.json +18 -4
- package/src/cli/tui/components/CopyOverlay.tsx +25 -0
- package/src/cli/tui/components/Header.tsx +9 -4
- package/src/cli/tui/components/HostPanel.tsx +3 -2
- package/src/cli/tui/components/HostsOverlay.tsx +33 -0
- package/src/cli/tui/components/PreviewPanel.tsx +9 -8
- package/src/cli/tui/components/StatusBar.tsx +39 -9
- package/src/cli/tui/components/TreePanel.tsx +17 -7
- package/src/cli/tui/components/TuiApp.tsx +65 -5
- package/src/cli/tui/discoverWorkflows.ts +7 -41
- package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +72 -0
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +288 -0
- package/src/cli/tui/imagePicker/fsListing.ts +48 -0
- package/src/cli/tui/imagePicker/pickerPrefs.ts +78 -0
- package/src/cli/tui/run-tui.tsx +49 -8
- package/src/cli/tui/state/DraftsSt.ts +3 -2
- package/src/cli/tui/state/ExecSt.ts +108 -12
- package/src/cli/tui/state/HostSt.ts +94 -10
- package/src/cli/tui/state/LorasSt.ts +14 -36
- package/src/cli/tui/state/PickerSt.ts +8 -2
- package/src/cli/tui/state/PreviewSt.ts +28 -2
- package/src/cli/tui/state/QueueSt.ts +2 -2
- package/src/cli/tui/state/SettingsSt.ts +25 -7
- package/src/cli/tui/state/TreeSt.ts +139 -36
- package/src/cli/tui/state/TuiSt.ts +53 -6
- package/src/cli/tui/state/WorkflowsSt.ts +14 -2
- package/src/cli/tui/treeRows.ts +165 -0
- package/src/exampleAssets.ts +56 -0
- package/src/graph/ComfyNode.ts +4 -1
- package/src/host/ComfyHost.ts +7 -0
- package/src/index.ts +7 -0
- package/src/manager/ComfyRegistry.ts +37 -9
- package/src/manager/generated/KnownComfyCustomNodeName.ts +23852 -1926
- package/src/manager/generated/KnownComfyPluginTitle.ts +6854 -236
- package/src/manager/generated/KnownComfyPluginURL.ts +3425 -111
- package/src/manager/generated/KnownModel_Base.ts +23 -7
- package/src/manager/generated/KnownModel_FileName.ts +421 -0
- package/src/manager/generated/KnownModel_Name.ts +421 -0
- package/src/manager/generated/KnownModel_SavePath.ts +34 -8
- package/src/manager/generated/KnownModel_Type.ts +18 -14
- package/src/manager/json/alter-list.json +221 -221
- package/src/manager/json/custom-node-list.json +61020 -21946
- package/src/manager/json/extension-node-map.json +81077 -31176
- package/src/manager/json/github-stats.json +29321 -12601
- package/src/manager/json/model-list.json +5935 -4997
- package/src/manager/loaders/parseReport.ts +55 -0
- package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +15 -49
- package/src/manager/loaders/step2_custom-node-list-loader.ts +38 -83
- package/src/manager/loaders/step3_extension-node-map-loader.ts +36 -142
- package/src/manager/loaders/step4_model-list-loader.ts +25 -36
- package/src/manager/loaders/step5_alter-list-loader.ts +29 -0
- package/src/manager/loaders/step6_github-stats-loader.ts +23 -0
- package/src/manager/script-update-manager.bun.ts +9 -1
- package/src/manager/types/ComfyManagerAlterInfo.ts +13 -0
- package/src/manager/types/ComfyManagerFileModelInfo.ts +7 -3
- package/src/manager/types/ComfyManagerFilePluginContent.ts +6 -9
- package/src/manager/types/ComfyManagerFilePluginList.ts +3 -3
- package/src/manager/types/ComfyManagerGithubStats.ts +9 -0
- package/src/manager/types/ComfyManagerPluginContentMetadata.ts +2 -3
- package/src/manager/types/ComfyManagerPluginInfo.ts +48 -34
- package/src/runner/ComfyWorkflowLayout.ts +6 -4
- package/src/sdk-generator/ComfySchema.ts +14 -1
- package/src/sdk-generator/comfyui-sdk-codegen.ts +15 -0
- package/src/sdk-generator/inputWidgetKind.ts +17 -0
- package/src/state.ts +7 -1
- package/src/vars/ComfyVars.ts +106 -5
- package/src/vars/DefinedWorkflow.ts +28 -10
- package/dist/DefinedWorkflow-O3ynII3Y.js +0 -598
- package/dist/DefinedWorkflow-O3ynII3Y.js.map +0 -1
- package/dist/run-tui-BFhba_oG.js.map +0 -1
- package/examples/05-comfy-cloud.cflow.ts +0 -67
- package/src/utils/tryExtracting.ts +0 -41
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as PromptVar, f as logError, i as LorasVar, l as extractErrorMessage, n as settingsPathFor, o as getLoraKeyword, r as DefinedWorkflow, s as setLoraKeyword, u as stripAnsi } from "./state-BYbxDgfr.js";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -7,6 +7,7 @@ import { createHash } from "node:crypto";
|
|
|
7
7
|
import { type } from "arktype";
|
|
8
8
|
import sharp from "sharp";
|
|
9
9
|
import { imageMeta } from "image-meta";
|
|
10
|
+
import { homedir } from "node:os";
|
|
10
11
|
import { makeAutoObservable, observable, reaction, runInAction } from "mobx";
|
|
11
12
|
import { Box, Text, render, useApp, useInput, useStdin } from "ink";
|
|
12
13
|
import { observer } from "mobx-react-lite";
|
|
@@ -18,22 +19,43 @@ const COMFY_TS_TUI_ENV = "COMFY_TS_TUI";
|
|
|
18
19
|
/**
|
|
19
20
|
* recursive scan for the workflow-module naming convention. Entries BELOW a
|
|
20
21
|
* node_modules segment are skipped: packaged examples arrive via
|
|
21
|
-
* bundledExamplesDir (symlinked layouts like pnpm would
|
|
22
|
-
* twice, un-deduped, as the user's own files), and
|
|
23
|
-
* shipping *.cflow.ts are not this project's workflows. A
|
|
24
|
-
* ITSELF inside node_modules still works (the filter is
|
|
22
|
+
* bundledExamplesDir (src/exampleAssets.ts — symlinked layouts like pnpm would
|
|
23
|
+
* otherwise list them twice, un-deduped, as the user's own files), and
|
|
24
|
+
* third-party packages shipping *.cflow.ts are not this project's workflows. A
|
|
25
|
+
* scan root that is ITSELF inside node_modules still works (the filter is
|
|
26
|
+
* relative to the root).
|
|
25
27
|
*/
|
|
26
28
|
function scanCflowFiles(dir) {
|
|
27
29
|
return readdirSync(dir, { recursive: true }).map((f) => String(f)).filter((f) => !f.split("/").includes("node_modules")).map((f) => join(dir, f)).filter((f) => f.endsWith(".cflow.ts") || f.endsWith(".cflow.tsx")).sort();
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
32
|
+
* PURE merge of the scan with the packaged examples (headless-tested). An
|
|
33
|
+
* explicit target keeps its scope only. Bundled files ALWAYS group under the
|
|
34
|
+
* bundled section, also when the scan already found them (repo dev: ./examples
|
|
35
|
+
* is under cwd) — dedupe relies on the caller passing realpath-normalized
|
|
36
|
+
* strings on both sides.
|
|
37
|
+
*/
|
|
38
|
+
function mergeWorkflowSources(p) {
|
|
39
|
+
if (p.explicitTarget) return {
|
|
40
|
+
files: p.scanned,
|
|
41
|
+
bundled: /* @__PURE__ */ new Set()
|
|
42
|
+
};
|
|
43
|
+
const bundled = new Set(p.bundledFiles);
|
|
44
|
+
return {
|
|
45
|
+
files: [...p.scanned.filter((f) => !bundled.has(f)), ...p.bundledFiles],
|
|
46
|
+
bundled
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/exampleAssets.ts
|
|
51
|
+
/**
|
|
30
52
|
* the examples/ folder shipped in the npm tarball, resolved from THIS module's
|
|
31
53
|
* own location (NEVER cwd): walking up to the nearest NAMED package.json finds
|
|
32
|
-
* <pkg>/examples both from a consumer's node_modules/comfy-ts/dist/
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
54
|
+
* <pkg>/examples both from a consumer's node_modules/comfy-ts/dist/ and from
|
|
55
|
+
* this repo's src/. Returns null when the examples are absent (a consumer may
|
|
56
|
+
* prune the folder) or when the nearest named package is not comfy-ts (the lib
|
|
57
|
+
* was inlined into someone else's bundle — its examples are not on disk); no
|
|
58
|
+
* package.json all the way up is a broken install and throws.
|
|
37
59
|
*/
|
|
38
60
|
function bundledExamplesDir(moduleUrl = import.meta.url) {
|
|
39
61
|
let dir = dirname(fileURLToPath(moduleUrl));
|
|
@@ -54,25 +76,7 @@ function bundledExamplesDir(moduleUrl = import.meta.url) {
|
|
|
54
76
|
prev = dir;
|
|
55
77
|
dir = dirname(dir);
|
|
56
78
|
}
|
|
57
|
-
throw new Error(`[comfy-ts
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* PURE merge of the scan with the packaged examples (headless-tested). An
|
|
61
|
-
* explicit target keeps its scope only. Bundled files ALWAYS group under the
|
|
62
|
-
* bundled section, also when the scan already found them (repo dev: ./examples
|
|
63
|
-
* is under cwd) — dedupe relies on the caller passing realpath-normalized
|
|
64
|
-
* strings on both sides.
|
|
65
|
-
*/
|
|
66
|
-
function mergeWorkflowSources(p) {
|
|
67
|
-
if (p.explicitTarget) return {
|
|
68
|
-
files: p.scanned,
|
|
69
|
-
bundled: /* @__PURE__ */ new Set()
|
|
70
|
-
};
|
|
71
|
-
const bundled = new Set(p.bundledFiles);
|
|
72
|
-
return {
|
|
73
|
-
files: [...p.scanned.filter((f) => !bundled.has(f)), ...p.bundledFiles],
|
|
74
|
-
bundled
|
|
75
|
-
};
|
|
79
|
+
throw new Error(`[comfy-ts] no package.json found walking up from ${fileURLToPath(moduleUrl)}`);
|
|
76
80
|
}
|
|
77
81
|
//#endregion
|
|
78
82
|
//#region src/cli/tui/findDefinedWorkflow.ts
|
|
@@ -146,6 +150,7 @@ var PreviewSt = class {
|
|
|
146
150
|
this.latentDims = null;
|
|
147
151
|
this.latentSeenThisRun = false;
|
|
148
152
|
this.lastOutputPath = null;
|
|
153
|
+
this.overlay = null;
|
|
149
154
|
this.menuIx = 0;
|
|
150
155
|
this._busy = false;
|
|
151
156
|
makeAutoObservable(this, { st: false });
|
|
@@ -165,6 +170,15 @@ var PreviewSt = class {
|
|
|
165
170
|
get menuOpen() {
|
|
166
171
|
return this.st.mode === "preview";
|
|
167
172
|
}
|
|
173
|
+
get overlayActive() {
|
|
174
|
+
return this.st.mode === "overlay-loras" || this.st.mode === "overlay-image";
|
|
175
|
+
}
|
|
176
|
+
setOverlayImage(p) {
|
|
177
|
+
this.overlay = p;
|
|
178
|
+
}
|
|
179
|
+
clearOverlayImage() {
|
|
180
|
+
this.overlay = null;
|
|
181
|
+
}
|
|
168
182
|
/** running + latents wanted + sampling well underway + none arrived = server
|
|
169
183
|
* sends none. The ≥20% gate keeps healthy runs from red-flashing: the first
|
|
170
184
|
* progress tick lands a beat before the first preview frame */
|
|
@@ -244,7 +258,7 @@ var PreviewSt = class {
|
|
|
244
258
|
/** what the painter should show RIGHT NOW (native renderer only; mirrors the panel's source) */
|
|
245
259
|
get protocolImage() {
|
|
246
260
|
if (!this.useNative || !this.show || this.menuOpen) return null;
|
|
247
|
-
if (this.
|
|
261
|
+
if (this.overlayActive) return this.overlay?.bytes ?? null;
|
|
248
262
|
if (this.st.exec.running) {
|
|
249
263
|
if (this.duringRun === "latent") return this.latentBytes ?? this.outputBytes;
|
|
250
264
|
return this.outputBytes;
|
|
@@ -254,7 +268,7 @@ var PreviewSt = class {
|
|
|
254
268
|
/** small latent painted over the panel's top-right corner (native + 'latent small' only) */
|
|
255
269
|
get protocolImageCorner() {
|
|
256
270
|
if (!this.useNative || !this.show || this.menuOpen) return null;
|
|
257
|
-
if (this.
|
|
271
|
+
if (this.overlayActive) return null;
|
|
258
272
|
if (this.st.exec.running && this.duringRun === "latent-small") return this.latentBytes;
|
|
259
273
|
return null;
|
|
260
274
|
}
|
|
@@ -436,35 +450,6 @@ function installProtocolImagePainter(st) {
|
|
|
436
450
|
};
|
|
437
451
|
}
|
|
438
452
|
//#endregion
|
|
439
|
-
//#region src/cli/tui/components/OverlayList.tsx
|
|
440
|
-
/** generic modal list: title + rows windowed around the selected index */
|
|
441
|
-
const OverlayList = (p) => {
|
|
442
|
-
const winStart = Math.max(0, Math.min(p.selectedIx - Math.floor(p.lines / 2), p.rows.length - p.lines));
|
|
443
|
-
const visible = p.rows.slice(winStart, winStart + p.lines);
|
|
444
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
445
|
-
borderStyle: "double",
|
|
446
|
-
paddingX: 1,
|
|
447
|
-
flexDirection: "column",
|
|
448
|
-
children: [
|
|
449
|
-
/* @__PURE__ */ jsx(Text, {
|
|
450
|
-
bold: true,
|
|
451
|
-
children: p.title
|
|
452
|
-
}),
|
|
453
|
-
p.extraHeader,
|
|
454
|
-
winStart > 0 && /* @__PURE__ */ jsx(Text, {
|
|
455
|
-
color: "gray",
|
|
456
|
-
children: "…"
|
|
457
|
-
}),
|
|
458
|
-
visible.map((r) => r.node),
|
|
459
|
-
winStart + p.lines < p.rows.length && /* @__PURE__ */ jsx(Text, {
|
|
460
|
-
color: "gray",
|
|
461
|
-
children: "…"
|
|
462
|
-
}),
|
|
463
|
-
p.footer
|
|
464
|
-
]
|
|
465
|
-
});
|
|
466
|
-
};
|
|
467
|
-
//#endregion
|
|
468
453
|
//#region src/cli/tui/components/StatusBar.tsx
|
|
469
454
|
/** keys cyan, labels gray — shared by the keybar and overlay footers */
|
|
470
455
|
const KeyHints = (p) => /* @__PURE__ */ jsx(Text, {
|
|
@@ -545,7 +530,8 @@ const KIND_KEYS = {
|
|
|
545
530
|
toggle: [["⏎/→", "flip"]],
|
|
546
531
|
choice: [["⏎/→", "pick"]],
|
|
547
532
|
size: [["⏎/→", "pick"]],
|
|
548
|
-
loras: [["⏎/→", "select"]]
|
|
533
|
+
loras: [["⏎/→", "select"]],
|
|
534
|
+
image: [["⏎/→", "browse"]]
|
|
549
535
|
};
|
|
550
536
|
/** shown INSIDE the text editor box (TextOverlay footer), not in the keybar */
|
|
551
537
|
const TEXT_EDIT_HINTS = [
|
|
@@ -596,24 +582,42 @@ const MODE_KEYS = {
|
|
|
596
582
|
["⌃N", "none"],
|
|
597
583
|
["esc", "done"]
|
|
598
584
|
],
|
|
585
|
+
"overlay-image": [
|
|
586
|
+
["⏎", "pick / enter dir"],
|
|
587
|
+
["←", "parent"],
|
|
588
|
+
["→", "enter dir"],
|
|
589
|
+
["tab", "pane"],
|
|
590
|
+
["↑↓", "move"],
|
|
591
|
+
["type", "filter"],
|
|
592
|
+
["⌃F", "fav folder"],
|
|
593
|
+
["esc", "cancel"]
|
|
594
|
+
],
|
|
599
595
|
"overlay-drafts": [
|
|
600
596
|
["⏎", "load / new"],
|
|
601
597
|
...DRAFT_OP_HINTS,
|
|
602
598
|
["↑↓", "move"],
|
|
603
599
|
["esc", "cancel"]
|
|
604
600
|
],
|
|
601
|
+
"overlay-hosts": [
|
|
602
|
+
["⏎", "pick run host"],
|
|
603
|
+
["↑↓", "move"],
|
|
604
|
+
["esc", "cancel"]
|
|
605
|
+
],
|
|
606
|
+
"overlay-copy": [["⏎/esc", "close"]],
|
|
605
607
|
tree: [
|
|
606
608
|
["⏎", "load"],
|
|
607
609
|
["↑↓", "move"],
|
|
608
610
|
["←", "fold"],
|
|
609
611
|
["→", "unfold / vars"],
|
|
612
|
+
["/", "filter"],
|
|
610
613
|
...DRAFT_OP_HINTS,
|
|
611
614
|
["t/esc", "back"]
|
|
612
615
|
],
|
|
613
616
|
host: [
|
|
614
617
|
["⏎", "run action"],
|
|
615
618
|
["↑↓", "move"],
|
|
616
|
-
["h
|
|
619
|
+
["h", "change host"],
|
|
620
|
+
["a/esc", "back"]
|
|
617
621
|
],
|
|
618
622
|
preview: [
|
|
619
623
|
["←→", "change"],
|
|
@@ -625,12 +629,18 @@ const MODE_KEYS = {
|
|
|
625
629
|
const KeyBar = observer((p) => {
|
|
626
630
|
const s = p.st;
|
|
627
631
|
const kind = s.selected?.[1].kind;
|
|
628
|
-
const
|
|
632
|
+
const treeFiltering = s.mode === "tree" && s.tree.filtering;
|
|
633
|
+
const modeHints = treeFiltering ? [
|
|
634
|
+
["type", "filter"],
|
|
635
|
+
["⏎", "load"],
|
|
636
|
+
["↑↓", "move"],
|
|
637
|
+
["esc", "clear"]
|
|
638
|
+
] : MODE_KEYS[s.mode] ?? [
|
|
629
639
|
["↑↓", "select"],
|
|
630
640
|
["←", "tree"],
|
|
631
641
|
...kind ? KIND_KEYS[kind] ?? [] : []
|
|
632
642
|
];
|
|
633
|
-
const globalHints = s.mode === "nav" || s.mode === "tree" || s.mode === "host" || s.mode === "preview" ? [
|
|
643
|
+
const globalHints = !treeFiltering && (s.mode === "nav" || s.mode === "tree" || s.mode === "host" || s.mode === "preview") ? [
|
|
634
644
|
["r", "run"],
|
|
635
645
|
["s", "reroll+run"],
|
|
636
646
|
...s.mode === "nav" ? [["e", "rename draft"]] : [],
|
|
@@ -646,6 +656,62 @@ const KeyBar = observer((p) => {
|
|
|
646
656
|
});
|
|
647
657
|
});
|
|
648
658
|
//#endregion
|
|
659
|
+
//#region src/cli/tui/components/CopyOverlay.tsx
|
|
660
|
+
/** `c`/`C` confirmation popup: WHAT landed in the clipboard (or the loud
|
|
661
|
+
* failure) — a copy is never silent again. ⏎/esc closes. */
|
|
662
|
+
const CopyOverlay = observer((p) => {
|
|
663
|
+
const popup = p.st.exec.copyPopup;
|
|
664
|
+
if (popup == null) return null;
|
|
665
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
666
|
+
borderStyle: "double",
|
|
667
|
+
borderColor: popup.ok ? "green" : "red",
|
|
668
|
+
paddingX: 1,
|
|
669
|
+
flexDirection: "column",
|
|
670
|
+
children: [
|
|
671
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
672
|
+
bold: true,
|
|
673
|
+
color: popup.ok ? "green" : "red",
|
|
674
|
+
children: [popup.ok ? "✓ " : "✗ ", popup.title]
|
|
675
|
+
}),
|
|
676
|
+
popup.lines.slice(0, p.st.overlayLines).map((line, ix) => /* @__PURE__ */ jsx(Text, {
|
|
677
|
+
color: popup.ok ? void 0 : "red",
|
|
678
|
+
wrap: "truncate",
|
|
679
|
+
children: line
|
|
680
|
+
}, `${ix}·${line.slice(0, 12)}`)),
|
|
681
|
+
/* @__PURE__ */ jsx(KeyHints, { hints: [["⏎/esc", "close"]] })
|
|
682
|
+
]
|
|
683
|
+
});
|
|
684
|
+
});
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region src/cli/tui/components/OverlayList.tsx
|
|
687
|
+
/** generic modal list: title + rows windowed around the selected index */
|
|
688
|
+
const OverlayList = (p) => {
|
|
689
|
+
const winStart = Math.max(0, Math.min(p.selectedIx - Math.floor(p.lines / 2), p.rows.length - p.lines));
|
|
690
|
+
const visible = p.rows.slice(winStart, winStart + p.lines);
|
|
691
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
692
|
+
borderStyle: "double",
|
|
693
|
+
paddingX: 1,
|
|
694
|
+
flexDirection: "column",
|
|
695
|
+
children: [
|
|
696
|
+
/* @__PURE__ */ jsx(Text, {
|
|
697
|
+
bold: true,
|
|
698
|
+
children: p.title
|
|
699
|
+
}),
|
|
700
|
+
p.extraHeader,
|
|
701
|
+
winStart > 0 && /* @__PURE__ */ jsx(Text, {
|
|
702
|
+
color: "gray",
|
|
703
|
+
children: "…"
|
|
704
|
+
}),
|
|
705
|
+
visible.map((r) => r.node),
|
|
706
|
+
winStart + p.lines < p.rows.length && /* @__PURE__ */ jsx(Text, {
|
|
707
|
+
color: "gray",
|
|
708
|
+
children: "…"
|
|
709
|
+
}),
|
|
710
|
+
p.footer
|
|
711
|
+
]
|
|
712
|
+
});
|
|
713
|
+
};
|
|
714
|
+
//#endregion
|
|
649
715
|
//#region src/cli/tui/components/DraftsOverlay.tsx
|
|
650
716
|
/** modal draft picker: row 0 creates a new draft, the rest load existing ones */
|
|
651
717
|
const DraftsOverlay = observer((p) => {
|
|
@@ -695,9 +761,10 @@ const HeaderBox = (p) => /* @__PURE__ */ jsxs(Box, {
|
|
|
695
761
|
})
|
|
696
762
|
}), /* @__PURE__ */ jsx(Box, { children: p.children })]
|
|
697
763
|
});
|
|
698
|
-
/** labeled header boxes: brand · (w)orkflow · (d)raft · (h)ost — the keys open each surface */
|
|
764
|
+
/** labeled header boxes: brand · (w)orkflow · (d)raft · (h)ost·(a)ctions — the keys open each surface */
|
|
699
765
|
const Header = observer((p) => {
|
|
700
766
|
const s = p.st;
|
|
767
|
+
const runHost = s.runHost;
|
|
701
768
|
return /* @__PURE__ */ jsxs(Box, {
|
|
702
769
|
flexDirection: "row",
|
|
703
770
|
children: [
|
|
@@ -723,7 +790,7 @@ const Header = observer((p) => {
|
|
|
723
790
|
})
|
|
724
791
|
}),
|
|
725
792
|
/* @__PURE__ */ jsx(HeaderBox, {
|
|
726
|
-
title: "(h)ost",
|
|
793
|
+
title: "(h)ost · (a)ctions",
|
|
727
794
|
children: /* @__PURE__ */ jsxs(Text, { children: [
|
|
728
795
|
/* @__PURE__ */ jsx(Text, {
|
|
729
796
|
color: s.host.status === "up" ? "green" : s.host.status === "down" ? "red" : "gray",
|
|
@@ -732,19 +799,23 @@ const Header = observer((p) => {
|
|
|
732
799
|
/* @__PURE__ */ jsx(Text, {
|
|
733
800
|
bold: true,
|
|
734
801
|
color: "green",
|
|
735
|
-
children:
|
|
802
|
+
children: runHost.data.id
|
|
736
803
|
}),
|
|
737
804
|
/* @__PURE__ */ jsxs(Text, {
|
|
738
805
|
color: "gray",
|
|
739
806
|
children: [
|
|
740
807
|
" ",
|
|
741
808
|
"(",
|
|
742
|
-
|
|
809
|
+
runHost.base.host,
|
|
743
810
|
":",
|
|
744
|
-
|
|
811
|
+
runHost.base.port,
|
|
745
812
|
")"
|
|
746
813
|
]
|
|
747
814
|
}),
|
|
815
|
+
s.hostOverride != null && s.hostOverride !== s.wf.host && /* @__PURE__ */ jsxs(Text, {
|
|
816
|
+
color: "yellow",
|
|
817
|
+
children: [" ⇄ overrides ", s.wf.host.data.id]
|
|
818
|
+
}),
|
|
748
819
|
s.host.status === "down" && /* @__PURE__ */ jsxs(Text, {
|
|
749
820
|
color: "red",
|
|
750
821
|
children: [" ", s.host.probing ? s.host.spinner : `↻ ${s.host.retryInS}s`]
|
|
@@ -758,7 +829,8 @@ const Header = observer((p) => {
|
|
|
758
829
|
//#region src/cli/tui/components/HostPanel.tsx
|
|
759
830
|
/** host stats + maintenance actions (mode 'host', key `h`) */
|
|
760
831
|
const HostPanel = observer((p) => {
|
|
761
|
-
const
|
|
832
|
+
const s = p.st;
|
|
833
|
+
const h = s.host;
|
|
762
834
|
return /* @__PURE__ */ jsxs(Box, {
|
|
763
835
|
borderStyle: "double",
|
|
764
836
|
paddingX: 1,
|
|
@@ -767,7 +839,7 @@ const HostPanel = observer((p) => {
|
|
|
767
839
|
/* @__PURE__ */ jsxs(Text, {
|
|
768
840
|
bold: true,
|
|
769
841
|
children: [
|
|
770
|
-
"host · ",
|
|
842
|
+
"host actions · ",
|
|
771
843
|
/* @__PURE__ */ jsx(Text, {
|
|
772
844
|
color: "green",
|
|
773
845
|
children: h.host.data.id
|
|
@@ -777,11 +849,15 @@ const HostPanel = observer((p) => {
|
|
|
777
849
|
color: "gray",
|
|
778
850
|
children: [
|
|
779
851
|
"(",
|
|
780
|
-
h.host.
|
|
852
|
+
h.host.base.host,
|
|
781
853
|
":",
|
|
782
|
-
h.host.
|
|
854
|
+
h.host.base.port,
|
|
783
855
|
")"
|
|
784
856
|
]
|
|
857
|
+
}),
|
|
858
|
+
s.hostOverride != null && /* @__PURE__ */ jsx(Text, {
|
|
859
|
+
color: "yellow",
|
|
860
|
+
children: " ⇄ override"
|
|
785
861
|
})
|
|
786
862
|
]
|
|
787
863
|
}),
|
|
@@ -807,6 +883,34 @@ const HostPanel = observer((p) => {
|
|
|
807
883
|
});
|
|
808
884
|
});
|
|
809
885
|
//#endregion
|
|
886
|
+
//#region src/cli/tui/components/HostsOverlay.tsx
|
|
887
|
+
/** modal host picker (`h`): row 0 restores the workflow's own host, the rest
|
|
888
|
+
* override where runs are built and sent (every registered host is listed) */
|
|
889
|
+
const HostsOverlay = observer((p) => {
|
|
890
|
+
const s = p.st;
|
|
891
|
+
const h = s.host;
|
|
892
|
+
const rows = h.pickerRows.map((row, ix) => ({
|
|
893
|
+
key: row.host?.data.id ?? "·default·",
|
|
894
|
+
node: /* @__PURE__ */ jsxs(Text, {
|
|
895
|
+
inverse: ix === h.pickerIx,
|
|
896
|
+
children: [
|
|
897
|
+
ix === h.pickerIx ? "▸ " : " ",
|
|
898
|
+
row.active ? "● " : " ",
|
|
899
|
+
row.label
|
|
900
|
+
]
|
|
901
|
+
}, row.host?.data.id ?? "·default·")
|
|
902
|
+
}));
|
|
903
|
+
return /* @__PURE__ */ jsx(OverlayList, {
|
|
904
|
+
title: /* @__PURE__ */ jsxs(Fragment, { children: ["run host ", /* @__PURE__ */ jsx(Text, {
|
|
905
|
+
color: "gray",
|
|
906
|
+
children: "· overrides the workflow's configured host"
|
|
907
|
+
})] }),
|
|
908
|
+
selectedIx: h.pickerIx,
|
|
909
|
+
lines: s.overlayLines,
|
|
910
|
+
rows
|
|
911
|
+
});
|
|
912
|
+
});
|
|
913
|
+
//#endregion
|
|
810
914
|
//#region src/cli/tui/components/LorasOverlay.tsx
|
|
811
915
|
/** modal multi-select: tick/untick loras, filter, bulk ops, step strengths */
|
|
812
916
|
const LorasOverlay = observer((p) => {
|
|
@@ -998,12 +1102,12 @@ const PreviewPanel = observer((p) => {
|
|
|
998
1102
|
})
|
|
999
1103
|
]
|
|
1000
1104
|
});
|
|
1001
|
-
const
|
|
1105
|
+
const overlayMode = pv.overlayActive;
|
|
1002
1106
|
const wantLatent = s.exec.running && pv.duringRun !== "last-output";
|
|
1003
|
-
const showLatent = !
|
|
1004
|
-
const label =
|
|
1005
|
-
const placeholder =
|
|
1006
|
-
const content = pv.useNative ? null :
|
|
1107
|
+
const showLatent = !overlayMode && wantLatent && (pv.latentAnsi != null || pv.latentBytes != null);
|
|
1108
|
+
const label = overlayMode ? pv.overlay?.name ?? (s.mode === "overlay-loras" ? "lora" : "image") : showLatent ? pv.duringRun === "latent-small" ? "latent small" : "latent" : "output";
|
|
1109
|
+
const placeholder = overlayMode ? pv.overlay?.note ?? (s.mode === "overlay-loras" ? "(pick a lora)" : "(pick an image)") : pv.latentsMissing ? "(no latents from the server — launch comfy with --preview-method auto)" : "(no image yet)";
|
|
1110
|
+
const content = pv.useNative ? null : overlayMode ? pv.overlay?.ansi ?? null : showLatent ? pv.latentAnsi ?? pv.outputAnsi : pv.outputAnsi;
|
|
1007
1111
|
const reserveRect = pv.useNative && (pv.protocolImage != null || pv.protocolImageCorner != null);
|
|
1008
1112
|
return /* @__PURE__ */ jsxs(Box, {
|
|
1009
1113
|
borderStyle: "round",
|
|
@@ -1081,6 +1185,431 @@ const PromptOverlay = observer((p) => {
|
|
|
1081
1185
|
});
|
|
1082
1186
|
});
|
|
1083
1187
|
//#endregion
|
|
1188
|
+
//#region src/cli/tui/imagePicker/fsListing.ts
|
|
1189
|
+
/** `name.PNG` matches extensions `['png']` — extensions are lowercase, no dots */
|
|
1190
|
+
function hasImageExtension(name, extensions) {
|
|
1191
|
+
const dot = name.lastIndexOf(".");
|
|
1192
|
+
if (dot <= 0) return false;
|
|
1193
|
+
return extensions.includes(name.slice(dot + 1).toLowerCase());
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* ONE folder for the picker: dirs first then images, both alphabetical,
|
|
1197
|
+
* images filtered by extension. Dot FILES are junk (.DS_Store) and skipped;
|
|
1198
|
+
* dot DIRS are listed — .comfy-ts/outputs must be browsable. Symlinks are
|
|
1199
|
+
* followed (a dangling one is skipped). Pure over fs — an unreadable dir
|
|
1200
|
+
* THROWS, the caller surfaces it (never a silent empty listing).
|
|
1201
|
+
*/
|
|
1202
|
+
function listImageDir(dir, extensions) {
|
|
1203
|
+
const dirs = [];
|
|
1204
|
+
const images = [];
|
|
1205
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1206
|
+
let isDir = entry.isDirectory();
|
|
1207
|
+
let isFile = entry.isFile();
|
|
1208
|
+
if (entry.isSymbolicLink()) try {
|
|
1209
|
+
const target = statSync(join(dir, entry.name));
|
|
1210
|
+
isDir = target.isDirectory();
|
|
1211
|
+
isFile = target.isFile();
|
|
1212
|
+
} catch {
|
|
1213
|
+
continue;
|
|
1214
|
+
}
|
|
1215
|
+
if (entry.name.startsWith(".") && !isDir) continue;
|
|
1216
|
+
if (isDir) dirs.push(entry.name);
|
|
1217
|
+
else if (isFile && hasImageExtension(entry.name, extensions)) images.push(entry.name);
|
|
1218
|
+
}
|
|
1219
|
+
dirs.sort((a, b) => a.localeCompare(b));
|
|
1220
|
+
images.sort((a, b) => a.localeCompare(b));
|
|
1221
|
+
return {
|
|
1222
|
+
dirs,
|
|
1223
|
+
images
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
/** parent for `←` navigation — the fs root is its own parent (never ascends past it) */
|
|
1227
|
+
function parentDir(dir) {
|
|
1228
|
+
return dirname(dir);
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* image-picker favorites + recents + lastFolder — loraKeywords pattern:
|
|
1232
|
+
* observable, loaded once, written through on every mutation. Human-editable
|
|
1233
|
+
* json at `.comfy-ts/image-picker.json` (hand-tuned data, NOT under cache/ —
|
|
1234
|
+
* survives a cache wipe):
|
|
1235
|
+
* { "favorites": ["/abs/dir"], "recents": ["/abs/img.png"], "lastFolder": "/abs/dir" }
|
|
1236
|
+
* A corrupt file logs loud and starts fresh, never blocks the TUI. The class
|
|
1237
|
+
* takes its file path explicitly so tests round-trip it headless; the TUI
|
|
1238
|
+
* uses the ONE lazy module singleton below.
|
|
1239
|
+
*/
|
|
1240
|
+
var PickerPrefs = class {
|
|
1241
|
+
constructor(path) {
|
|
1242
|
+
this.path = path;
|
|
1243
|
+
this.favorites = [];
|
|
1244
|
+
this.recents = [];
|
|
1245
|
+
this.lastFolder = null;
|
|
1246
|
+
this.load();
|
|
1247
|
+
makeAutoObservable(this);
|
|
1248
|
+
}
|
|
1249
|
+
load() {
|
|
1250
|
+
if (!existsSync(this.path)) return;
|
|
1251
|
+
try {
|
|
1252
|
+
const raw = JSON.parse(readFileSync(this.path, "utf8"));
|
|
1253
|
+
if (raw == null || typeof raw !== "object") throw new Error("not a json object");
|
|
1254
|
+
const o = raw;
|
|
1255
|
+
if (Array.isArray(o.favorites)) this.favorites = o.favorites.filter((f) => typeof f === "string");
|
|
1256
|
+
if (Array.isArray(o.recents)) this.recents = o.recents.filter((r) => typeof r === "string").slice(0, 20);
|
|
1257
|
+
if (typeof o.lastFolder === "string") this.lastFolder = o.lastFolder;
|
|
1258
|
+
} catch (e) {
|
|
1259
|
+
logError(`[imagePicker] unreadable ${this.path} — starting fresh: ${String(e)}`);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
write() {
|
|
1263
|
+
try {
|
|
1264
|
+
mkdirSync(dirname(this.path), { recursive: true });
|
|
1265
|
+
const json = {
|
|
1266
|
+
favorites: this.favorites,
|
|
1267
|
+
recents: this.recents,
|
|
1268
|
+
lastFolder: this.lastFolder
|
|
1269
|
+
};
|
|
1270
|
+
writeFileSync(this.path, `${JSON.stringify(json, null, 2)}\n`);
|
|
1271
|
+
} catch (e) {
|
|
1272
|
+
logError(`[imagePicker] write failed ${this.path}: ${String(e)}`);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
isFavorite(dir) {
|
|
1276
|
+
return this.favorites.includes(dir);
|
|
1277
|
+
}
|
|
1278
|
+
toggleFavorite(dir) {
|
|
1279
|
+
this.favorites = this.favorites.includes(dir) ? this.favorites.filter((f) => f !== dir) : [...this.favorites, dir];
|
|
1280
|
+
this.write();
|
|
1281
|
+
}
|
|
1282
|
+
/** a pick records the image (newest first, deduped, capped) AND remembers its folder */
|
|
1283
|
+
recordPick(imagePath) {
|
|
1284
|
+
this.recents = [imagePath, ...this.recents.filter((r) => r !== imagePath)].slice(0, 20);
|
|
1285
|
+
this.lastFolder = dirname(imagePath);
|
|
1286
|
+
this.write();
|
|
1287
|
+
}
|
|
1288
|
+
};
|
|
1289
|
+
let _prefs = null;
|
|
1290
|
+
/** the TUI's store, bound lazily to `.comfy-ts/image-picker.json` (gitignored) */
|
|
1291
|
+
function pickerPrefs() {
|
|
1292
|
+
if (_prefs == null) _prefs = new PickerPrefs(join(comfyts.baseFolder, "image-picker.json"));
|
|
1293
|
+
return _prefs;
|
|
1294
|
+
}
|
|
1295
|
+
//#endregion
|
|
1296
|
+
//#region src/utils/fuzzyMatch.ts
|
|
1297
|
+
/** case-insensitive subsequence match: 'wide' hits '16:9 (Widescreen)' */
|
|
1298
|
+
function fuzzyMatch(needle, hay) {
|
|
1299
|
+
const n = needle.toLowerCase();
|
|
1300
|
+
const h = hay.toLowerCase();
|
|
1301
|
+
let i = 0;
|
|
1302
|
+
for (const ch of h) if (ch === n[i]) i++;
|
|
1303
|
+
return i >= n.length;
|
|
1304
|
+
}
|
|
1305
|
+
//#endregion
|
|
1306
|
+
//#region src/cli/tui/imagePicker/ImagePickerSt.ts
|
|
1307
|
+
const PICKER_PANES = [
|
|
1308
|
+
"browse",
|
|
1309
|
+
"favorites",
|
|
1310
|
+
"recents"
|
|
1311
|
+
];
|
|
1312
|
+
/** `~`-contract $HOME for display (ImageVar.display's convention) */
|
|
1313
|
+
function contractHome(path) {
|
|
1314
|
+
const home = homedir();
|
|
1315
|
+
return path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* image-picker overlay (mode 'overlay-image'): browse the disk for an image
|
|
1319
|
+
* var, three panes (browse / favorites / recents), filter-as-you-type, the
|
|
1320
|
+
* highlighted image previews into the panel via PreviewSt's overlay slot.
|
|
1321
|
+
*/
|
|
1322
|
+
var ImagePickerSt = class {
|
|
1323
|
+
constructor(st) {
|
|
1324
|
+
this.st = st;
|
|
1325
|
+
this.pane = "browse";
|
|
1326
|
+
this.folder = process.cwd();
|
|
1327
|
+
this.ix = 0;
|
|
1328
|
+
this.filter = "";
|
|
1329
|
+
this._busy = false;
|
|
1330
|
+
makeAutoObservable(this, { st: false });
|
|
1331
|
+
this.st.disposers.push(reaction(() => this.st.mode === "overlay-image" ? this.highlightedImage : null, () => void this.refreshPreview(), { delay: 120 }));
|
|
1332
|
+
}
|
|
1333
|
+
/** kind-narrowing cast sanctioned (agent/coding.md), `kind` is the tag */
|
|
1334
|
+
get selectedVar() {
|
|
1335
|
+
const sel = this.st.selected?.[1];
|
|
1336
|
+
return sel?.kind === "image" ? sel : null;
|
|
1337
|
+
}
|
|
1338
|
+
get folderDisplay() {
|
|
1339
|
+
return contractHome(this.folder);
|
|
1340
|
+
}
|
|
1341
|
+
/** begin() open order: dirname(value) → persisted lastFolder → opts.folder → cwd */
|
|
1342
|
+
initialFolder(iv) {
|
|
1343
|
+
const candidates = [
|
|
1344
|
+
iv.isSet() ? dirname(iv.absPath()) : null,
|
|
1345
|
+
pickerPrefs().lastFolder,
|
|
1346
|
+
iv.opts.folder != null ? resolve(iv.opts.folder) : null
|
|
1347
|
+
];
|
|
1348
|
+
for (const c of candidates) try {
|
|
1349
|
+
if (c != null && statSync(c).isDirectory()) return c;
|
|
1350
|
+
} catch {}
|
|
1351
|
+
return process.cwd();
|
|
1352
|
+
}
|
|
1353
|
+
begin() {
|
|
1354
|
+
const iv = this.selectedVar;
|
|
1355
|
+
if (iv == null) return;
|
|
1356
|
+
this.st.mode = "overlay-image";
|
|
1357
|
+
this.pane = "browse";
|
|
1358
|
+
this.filter = "";
|
|
1359
|
+
this.ix = 0;
|
|
1360
|
+
this.folder = this.initialFolder(iv);
|
|
1361
|
+
this.st.preview.clearOverlayImage();
|
|
1362
|
+
}
|
|
1363
|
+
cancel() {
|
|
1364
|
+
this.st.mode = "nav";
|
|
1365
|
+
}
|
|
1366
|
+
/** every row of the active pane BEFORE the filter, plus the browse-pane
|
|
1367
|
+
* read error (unreadable folder: shown IN the overlay, browsing elsewhere
|
|
1368
|
+
* stays possible). Computed with NO side effects — mobx forbids them. */
|
|
1369
|
+
get paneListing() {
|
|
1370
|
+
if (this.pane === "favorites") return {
|
|
1371
|
+
rows: pickerPrefs().favorites.map((dir) => ({
|
|
1372
|
+
kind: "dir",
|
|
1373
|
+
name: contractHome(dir),
|
|
1374
|
+
path: dir
|
|
1375
|
+
})),
|
|
1376
|
+
error: null
|
|
1377
|
+
};
|
|
1378
|
+
if (this.pane === "recents") return {
|
|
1379
|
+
rows: pickerPrefs().recents.map((img) => ({
|
|
1380
|
+
kind: "image",
|
|
1381
|
+
name: contractHome(img),
|
|
1382
|
+
path: img,
|
|
1383
|
+
missing: !existsSync(img)
|
|
1384
|
+
})),
|
|
1385
|
+
error: null
|
|
1386
|
+
};
|
|
1387
|
+
const iv = this.selectedVar;
|
|
1388
|
+
if (iv == null) return {
|
|
1389
|
+
rows: [],
|
|
1390
|
+
error: null
|
|
1391
|
+
};
|
|
1392
|
+
try {
|
|
1393
|
+
const listing = listImageDir(this.folder, iv.extensions);
|
|
1394
|
+
return {
|
|
1395
|
+
rows: [...listing.dirs.map((d) => ({
|
|
1396
|
+
kind: "dir",
|
|
1397
|
+
name: d,
|
|
1398
|
+
path: resolve(this.folder, d)
|
|
1399
|
+
})), ...listing.images.map((f) => ({
|
|
1400
|
+
kind: "image",
|
|
1401
|
+
name: f,
|
|
1402
|
+
path: resolve(this.folder, f),
|
|
1403
|
+
missing: false
|
|
1404
|
+
}))],
|
|
1405
|
+
error: null
|
|
1406
|
+
};
|
|
1407
|
+
} catch (e) {
|
|
1408
|
+
return {
|
|
1409
|
+
rows: [],
|
|
1410
|
+
error: extractErrorMessage(e)
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
get listingError() {
|
|
1415
|
+
return this.paneListing.error;
|
|
1416
|
+
}
|
|
1417
|
+
/** what the overlay renders: pane rows surviving the filter */
|
|
1418
|
+
get rows() {
|
|
1419
|
+
const all = this.paneListing.rows;
|
|
1420
|
+
if (this.filter === "") return all;
|
|
1421
|
+
return all.filter((r) => fuzzyMatch(this.filter, r.name));
|
|
1422
|
+
}
|
|
1423
|
+
get current() {
|
|
1424
|
+
return this.rows[this.ix] ?? null;
|
|
1425
|
+
}
|
|
1426
|
+
/** feeds the preview reaction: only a real, present image highlights */
|
|
1427
|
+
get highlightedImage() {
|
|
1428
|
+
const row = this.current;
|
|
1429
|
+
return row?.kind === "image" && !row.missing ? row.path : null;
|
|
1430
|
+
}
|
|
1431
|
+
move(delta) {
|
|
1432
|
+
const len = this.rows.length;
|
|
1433
|
+
if (len === 0) return;
|
|
1434
|
+
this.ix = (this.ix + delta + len) % len;
|
|
1435
|
+
}
|
|
1436
|
+
cyclePane() {
|
|
1437
|
+
const ix = PICKER_PANES.indexOf(this.pane);
|
|
1438
|
+
this.pane = PICKER_PANES[(ix + 1) % PICKER_PANES.length] ?? "browse";
|
|
1439
|
+
this.ix = 0;
|
|
1440
|
+
this.filter = "";
|
|
1441
|
+
}
|
|
1442
|
+
goto(dir) {
|
|
1443
|
+
this.pane = "browse";
|
|
1444
|
+
this.folder = dir;
|
|
1445
|
+
this.ix = 0;
|
|
1446
|
+
this.filter = "";
|
|
1447
|
+
}
|
|
1448
|
+
/** `→`: enter the highlighted dir (browse pane; images select via ⏎ only) */
|
|
1449
|
+
enter() {
|
|
1450
|
+
const row = this.current;
|
|
1451
|
+
if (this.pane === "browse" && row?.kind === "dir") this.goto(row.path);
|
|
1452
|
+
}
|
|
1453
|
+
/** `←`: parent dir (browse pane; the fs root is its own parent) */
|
|
1454
|
+
goParent() {
|
|
1455
|
+
if (this.pane !== "browse") return;
|
|
1456
|
+
const parent = parentDir(this.folder);
|
|
1457
|
+
if (parent !== this.folder) this.goto(parent);
|
|
1458
|
+
}
|
|
1459
|
+
/** ⏎: enter a dir (a favorite jumps browse into it), select an image */
|
|
1460
|
+
commit() {
|
|
1461
|
+
const row = this.current;
|
|
1462
|
+
if (row == null) return;
|
|
1463
|
+
if (row.kind === "dir") return this.goto(row.path);
|
|
1464
|
+
if (row.missing) return;
|
|
1465
|
+
this.select(row.path);
|
|
1466
|
+
}
|
|
1467
|
+
/** the pick: absolute path into the var, recents + lastFolder recorded */
|
|
1468
|
+
select(absPath) {
|
|
1469
|
+
const iv = this.selectedVar;
|
|
1470
|
+
if (iv == null) return;
|
|
1471
|
+
iv.set(absPath);
|
|
1472
|
+
pickerPrefs().recordPick(absPath);
|
|
1473
|
+
this.st.mode = "nav";
|
|
1474
|
+
}
|
|
1475
|
+
/** ⌃F: favorite FOLDERS only — a dir row favorites it, an image row favorites the current folder */
|
|
1476
|
+
toggleFavorite() {
|
|
1477
|
+
const row = this.current;
|
|
1478
|
+
const dir = row == null ? this.pane === "browse" ? this.folder : null : row.kind === "dir" ? row.path : this.pane === "browse" ? this.folder : dirname(row.path);
|
|
1479
|
+
if (dir == null) return;
|
|
1480
|
+
pickerPrefs().toggleFavorite(dir);
|
|
1481
|
+
this.ix = Math.max(0, Math.min(this.ix, this.rows.length - 1));
|
|
1482
|
+
}
|
|
1483
|
+
isFavorite(dir) {
|
|
1484
|
+
return pickerPrefs().isFavorite(dir);
|
|
1485
|
+
}
|
|
1486
|
+
filterInput(chunk) {
|
|
1487
|
+
this.filter += chunk;
|
|
1488
|
+
this.ix = 0;
|
|
1489
|
+
}
|
|
1490
|
+
filterBackspace() {
|
|
1491
|
+
this.filter = this.filter.slice(0, -1);
|
|
1492
|
+
this.ix = 0;
|
|
1493
|
+
}
|
|
1494
|
+
/** ⌥⌫ / ⌃W: drop the last word of the filter */
|
|
1495
|
+
filterDeleteWord() {
|
|
1496
|
+
this.filter = this.filter.replace(/\s*\S+\s*$/, "");
|
|
1497
|
+
this.ix = 0;
|
|
1498
|
+
}
|
|
1499
|
+
async refreshPreview() {
|
|
1500
|
+
if (this.st.mode !== "overlay-image") {
|
|
1501
|
+
if (!this.st.preview.overlayActive) this.st.preview.clearOverlayImage();
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1504
|
+
const path = this.highlightedImage;
|
|
1505
|
+
if (path == null) {
|
|
1506
|
+
this.st.preview.clearOverlayImage();
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
if (this._busy) return;
|
|
1510
|
+
this._busy = true;
|
|
1511
|
+
try {
|
|
1512
|
+
const bytes = new Uint8Array(readFileSync(path));
|
|
1513
|
+
if (this.st.preview.useNative) this.st.preview.setOverlayImage({
|
|
1514
|
+
bytes,
|
|
1515
|
+
ansi: null,
|
|
1516
|
+
name: basename(path),
|
|
1517
|
+
note: null
|
|
1518
|
+
});
|
|
1519
|
+
else {
|
|
1520
|
+
const ansi = await imageBufferToAnsi(bytes, {
|
|
1521
|
+
width: this.st.preview.width,
|
|
1522
|
+
height: this.st.preview.height
|
|
1523
|
+
});
|
|
1524
|
+
this.st.preview.setOverlayImage({
|
|
1525
|
+
bytes: null,
|
|
1526
|
+
ansi,
|
|
1527
|
+
name: basename(path),
|
|
1528
|
+
note: null
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
} catch (e) {
|
|
1532
|
+
this.st.preview.setOverlayImage({
|
|
1533
|
+
bytes: null,
|
|
1534
|
+
ansi: null,
|
|
1535
|
+
name: basename(path),
|
|
1536
|
+
note: extractErrorMessage(e)
|
|
1537
|
+
});
|
|
1538
|
+
} finally {
|
|
1539
|
+
this._busy = false;
|
|
1540
|
+
if (this.st.mode === "overlay-image" && this.highlightedImage !== path) this.refreshPreview();
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
//#endregion
|
|
1545
|
+
//#region src/cli/tui/imagePicker/ImagePickerOverlay.tsx
|
|
1546
|
+
/** modal image browser: three panes (tab), dirs enter, ⏎ picks, ★ = favorite folder */
|
|
1547
|
+
const ImagePickerOverlay = observer((p) => {
|
|
1548
|
+
const s = p.st;
|
|
1549
|
+
const ip = s.imagePicker;
|
|
1550
|
+
const iv = ip.selectedVar;
|
|
1551
|
+
if (iv == null) return null;
|
|
1552
|
+
const rows = ip.rows;
|
|
1553
|
+
return /* @__PURE__ */ jsx(OverlayList, {
|
|
1554
|
+
title: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1555
|
+
s.selected?.[1].label ?? s.selected?.[0],
|
|
1556
|
+
" ",
|
|
1557
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1558
|
+
color: "gray",
|
|
1559
|
+
children: iv.display()
|
|
1560
|
+
})
|
|
1561
|
+
] }),
|
|
1562
|
+
extraHeader: /* @__PURE__ */ jsxs(Box, {
|
|
1563
|
+
flexDirection: "column",
|
|
1564
|
+
children: [/* @__PURE__ */ jsxs(Text, { children: [PICKER_PANES.map((pane, ix) => /* @__PURE__ */ jsxs(Text, { children: [ix > 0 ? /* @__PURE__ */ jsx(Text, {
|
|
1565
|
+
color: "gray",
|
|
1566
|
+
children: " · "
|
|
1567
|
+
}) : null, /* @__PURE__ */ jsx(Text, {
|
|
1568
|
+
color: pane === ip.pane ? "cyan" : "gray",
|
|
1569
|
+
bold: pane === ip.pane,
|
|
1570
|
+
underline: pane === ip.pane,
|
|
1571
|
+
children: pane
|
|
1572
|
+
})] }, pane)), ip.pane === "browse" ? /* @__PURE__ */ jsxs(Text, {
|
|
1573
|
+
color: "gray",
|
|
1574
|
+
children: [" ", ip.folderDisplay]
|
|
1575
|
+
}) : null] }), /* @__PURE__ */ jsxs(Text, {
|
|
1576
|
+
color: "yellow",
|
|
1577
|
+
children: [
|
|
1578
|
+
"filter: ",
|
|
1579
|
+
ip.filter,
|
|
1580
|
+
"▌"
|
|
1581
|
+
]
|
|
1582
|
+
})]
|
|
1583
|
+
}),
|
|
1584
|
+
selectedIx: ip.ix,
|
|
1585
|
+
lines: s.overlayLines,
|
|
1586
|
+
rows: rows.map((row, ix) => {
|
|
1587
|
+
const sel = ix === ip.ix;
|
|
1588
|
+
const fav = row.kind === "dir" && ip.isFavorite(row.path);
|
|
1589
|
+
const missing = row.kind === "image" && row.missing;
|
|
1590
|
+
return {
|
|
1591
|
+
key: `${row.kind}:${row.path}`,
|
|
1592
|
+
node: /* @__PURE__ */ jsxs(Text, {
|
|
1593
|
+
inverse: sel,
|
|
1594
|
+
color: row.kind === "dir" ? "blue" : missing ? "gray" : void 0,
|
|
1595
|
+
dimColor: missing,
|
|
1596
|
+
children: [
|
|
1597
|
+
sel ? "▸ " : " ",
|
|
1598
|
+
fav ? "★ " : " ",
|
|
1599
|
+
row.name,
|
|
1600
|
+
row.kind === "dir" ? "/" : "",
|
|
1601
|
+
missing ? " (missing)" : ""
|
|
1602
|
+
]
|
|
1603
|
+
}, `${row.kind}:${row.path}`)
|
|
1604
|
+
};
|
|
1605
|
+
}),
|
|
1606
|
+
footer: rows.length === 0 ? /* @__PURE__ */ jsx(Text, {
|
|
1607
|
+
color: "red",
|
|
1608
|
+
children: ip.listingError ?? (ip.filter !== "" ? "no match" : "no images here")
|
|
1609
|
+
}) : void 0
|
|
1610
|
+
});
|
|
1611
|
+
});
|
|
1612
|
+
//#endregion
|
|
1084
1613
|
//#region src/cli/tui/components/LogsPanel.tsx
|
|
1085
1614
|
const ERROR_RE = /error|exception|traceback|failed/i;
|
|
1086
1615
|
/** last server console lines (LogsSt), below the vars panel */
|
|
@@ -1207,7 +1736,8 @@ const TextOverlay = observer((p) => {
|
|
|
1207
1736
|
});
|
|
1208
1737
|
//#endregion
|
|
1209
1738
|
//#region src/cli/tui/components/TreePanel.tsx
|
|
1210
|
-
/** persistent left panel: workflows with their drafts
|
|
1739
|
+
/** persistent left panel: directory hierarchy + workflows with their drafts
|
|
1740
|
+
* nested; `t` (or ← from vars) focuses it, `/` filters it */
|
|
1211
1741
|
const TreePanel = observer((p) => {
|
|
1212
1742
|
const s = p.st;
|
|
1213
1743
|
const tree = s.tree;
|
|
@@ -1228,22 +1758,40 @@ const TreePanel = observer((p) => {
|
|
|
1228
1758
|
children: "(t)ree"
|
|
1229
1759
|
})
|
|
1230
1760
|
}),
|
|
1761
|
+
(tree.filtering || tree.filter !== "") && /* @__PURE__ */ jsxs(Text, {
|
|
1762
|
+
color: "yellow",
|
|
1763
|
+
wrap: "truncate",
|
|
1764
|
+
children: [
|
|
1765
|
+
"/",
|
|
1766
|
+
tree.filter,
|
|
1767
|
+
tree.filtering ? "▌" : ""
|
|
1768
|
+
]
|
|
1769
|
+
}),
|
|
1231
1770
|
tree.rows.map((row, ix) => {
|
|
1232
1771
|
const sel = focused && ix === tree.ix;
|
|
1233
|
-
|
|
1772
|
+
const indent = " ".repeat(row.depth * 2);
|
|
1773
|
+
if (row.kind === "dir") return /* @__PURE__ */ jsxs(Text, {
|
|
1774
|
+
inverse: sel,
|
|
1234
1775
|
color: "gray",
|
|
1235
|
-
|
|
1776
|
+
bold: true,
|
|
1236
1777
|
wrap: "truncate",
|
|
1237
|
-
children: [
|
|
1238
|
-
|
|
1778
|
+
children: [
|
|
1779
|
+
indent,
|
|
1780
|
+
row.expanded ? "▾" : "▸",
|
|
1781
|
+
" ",
|
|
1782
|
+
row.label
|
|
1783
|
+
]
|
|
1784
|
+
}, `dir·${row.path}`);
|
|
1239
1785
|
if (row.kind === "workflow") {
|
|
1240
1786
|
const arrow = row.hasDrafts ? row.expanded ? "▾" : "▸" : " ";
|
|
1241
1787
|
const marker = row.error != null ? "✗" : row.current ? "●" : " ";
|
|
1242
1788
|
return /* @__PURE__ */ jsxs(Text, {
|
|
1243
1789
|
inverse: sel,
|
|
1244
|
-
|
|
1790
|
+
bold: row.current,
|
|
1791
|
+
color: row.error != null ? "red" : row.color,
|
|
1245
1792
|
wrap: "truncate",
|
|
1246
1793
|
children: [
|
|
1794
|
+
indent,
|
|
1247
1795
|
arrow,
|
|
1248
1796
|
marker,
|
|
1249
1797
|
" ",
|
|
@@ -1256,7 +1804,8 @@ const TreePanel = observer((p) => {
|
|
|
1256
1804
|
color: row.active ? "cyan" : "gray",
|
|
1257
1805
|
wrap: "truncate",
|
|
1258
1806
|
children: [
|
|
1259
|
-
|
|
1807
|
+
indent,
|
|
1808
|
+
" ",
|
|
1260
1809
|
row.active ? "●" : "·",
|
|
1261
1810
|
" ",
|
|
1262
1811
|
row.draft
|
|
@@ -1456,9 +2005,37 @@ const TuiApp = observer((p) => {
|
|
|
1456
2005
|
if (input && !key.ctrl && !key.meta) return lo.filterInput(input);
|
|
1457
2006
|
return;
|
|
1458
2007
|
}
|
|
2008
|
+
if (s.mode === "overlay-image") {
|
|
2009
|
+
const ip = s.imagePicker;
|
|
2010
|
+
if (key.escape) return ip.cancel();
|
|
2011
|
+
if (key.tab || input === " ") return ip.cyclePane();
|
|
2012
|
+
if (key.ctrl && input === "f") return ip.toggleFavorite();
|
|
2013
|
+
if (key.return) return ip.commit();
|
|
2014
|
+
if (key.upArrow) return ip.move(-1);
|
|
2015
|
+
if (key.downArrow) return ip.move(1);
|
|
2016
|
+
if (key.leftArrow) return ip.goParent();
|
|
2017
|
+
if (key.rightArrow) return ip.enter();
|
|
2018
|
+
if (key.meta && (key.backspace || key.delete) || key.ctrl && input === "w") return ip.filterDeleteWord();
|
|
2019
|
+
if (key.backspace || key.delete) return ip.filterBackspace();
|
|
2020
|
+
if (input && !key.ctrl && !key.meta) return ip.filterInput(input);
|
|
2021
|
+
return;
|
|
2022
|
+
}
|
|
1459
2023
|
if (s.mode === "tree") {
|
|
1460
2024
|
const tr = s.tree;
|
|
1461
|
-
if (
|
|
2025
|
+
if (tr.filtering) {
|
|
2026
|
+
if (key.escape) return tr.clearFilter();
|
|
2027
|
+
if (key.return) return void tr.commit();
|
|
2028
|
+
if (key.upArrow) return tr.move(-1);
|
|
2029
|
+
if (key.downArrow) return tr.move(1);
|
|
2030
|
+
if (key.leftArrow) return tr.fold();
|
|
2031
|
+
if (key.rightArrow) return tr.unfold();
|
|
2032
|
+
if (key.backspace || key.delete) return tr.filterBackspace();
|
|
2033
|
+
if (input && !key.ctrl && !key.meta) return tr.filterInput(input);
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
if (key.escape) return tr.filter !== "" ? tr.clearFilter() : tr.blur();
|
|
2037
|
+
if (input === "t") return tr.blur();
|
|
2038
|
+
if (input === "/") return tr.beginFilter();
|
|
1462
2039
|
if (key.return || input === " ") return void tr.commit();
|
|
1463
2040
|
if (key.upArrow) return tr.move(-1);
|
|
1464
2041
|
if (key.downArrow) return tr.move(1);
|
|
@@ -1472,7 +2049,8 @@ const TuiApp = observer((p) => {
|
|
|
1472
2049
|
if (input === "r") return void s.exec.run();
|
|
1473
2050
|
if (input === "s") return s.exec.randomizeSeedAndRun();
|
|
1474
2051
|
if (input === "d") return s.drafts.begin();
|
|
1475
|
-
if (input === "h") return s.host.
|
|
2052
|
+
if (input === "h") return s.host.beginPicker();
|
|
2053
|
+
if (input === "a") return s.host.begin();
|
|
1476
2054
|
if (input === "p") return s.preview.beginMenu();
|
|
1477
2055
|
if (input === "o") return s.exec.openLastOutput();
|
|
1478
2056
|
if (input === "q") {
|
|
@@ -1483,7 +2061,8 @@ const TuiApp = observer((p) => {
|
|
|
1483
2061
|
}
|
|
1484
2062
|
if (s.mode === "host") {
|
|
1485
2063
|
const h = s.host;
|
|
1486
|
-
if (key.escape || input === "
|
|
2064
|
+
if (key.escape || input === "a" || input === "v") return h.blur();
|
|
2065
|
+
if (input === "h") return h.beginPicker();
|
|
1487
2066
|
if (key.return || input === " ") return void h.commit();
|
|
1488
2067
|
if (key.upArrow) return h.move(-1);
|
|
1489
2068
|
if (key.downArrow) return h.move(1);
|
|
@@ -1493,6 +2072,18 @@ const TuiApp = observer((p) => {
|
|
|
1493
2072
|
}
|
|
1494
2073
|
return;
|
|
1495
2074
|
}
|
|
2075
|
+
if (s.mode === "overlay-hosts") {
|
|
2076
|
+
const h = s.host;
|
|
2077
|
+
if (key.escape || input === "h") return h.cancelPicker();
|
|
2078
|
+
if (key.return || input === " ") return h.commitPicker();
|
|
2079
|
+
if (key.upArrow) return h.pickerMove(-1);
|
|
2080
|
+
if (key.downArrow) return h.pickerMove(1);
|
|
2081
|
+
return;
|
|
2082
|
+
}
|
|
2083
|
+
if (s.mode === "overlay-copy") {
|
|
2084
|
+
if (key.escape || key.return || input === " " || input === "c" || input === "C" || input === "q") return s.exec.closeCopyPopup();
|
|
2085
|
+
return;
|
|
2086
|
+
}
|
|
1496
2087
|
if (s.mode === "preview") {
|
|
1497
2088
|
const pv = s.preview;
|
|
1498
2089
|
if (key.escape || key.return || input === "p" || input === "v") return pv.blurMenu();
|
|
@@ -1503,7 +2094,8 @@ const TuiApp = observer((p) => {
|
|
|
1503
2094
|
if (input === "r") return void s.exec.run();
|
|
1504
2095
|
if (input === "s") return s.exec.randomizeSeedAndRun();
|
|
1505
2096
|
if (input === "d") return s.drafts.begin();
|
|
1506
|
-
if (input === "h") return s.host.
|
|
2097
|
+
if (input === "h") return s.host.beginPicker();
|
|
2098
|
+
if (input === "a") return s.host.begin();
|
|
1507
2099
|
if (input === "o") return s.exec.openLastOutput();
|
|
1508
2100
|
if (input === "q") {
|
|
1509
2101
|
s.onExit();
|
|
@@ -1535,11 +2127,16 @@ const TuiApp = observer((p) => {
|
|
|
1535
2127
|
if (key.leftArrow) return s.tree.focus();
|
|
1536
2128
|
if (key.rightArrow || key.return || input === " ") return s.activate();
|
|
1537
2129
|
if (s.navKey(input)) return;
|
|
2130
|
+
if (input === "/") {
|
|
2131
|
+
s.tree.focus();
|
|
2132
|
+
return s.tree.beginFilter();
|
|
2133
|
+
}
|
|
1538
2134
|
if (input === "e") return s.drafts.beginRename();
|
|
1539
2135
|
if (input === "r") return void s.exec.run();
|
|
1540
2136
|
if (input === "s") return s.exec.randomizeSeedAndRun();
|
|
1541
2137
|
if (input === "t" || input === "w") return s.tree.focus();
|
|
1542
|
-
if (input === "h") return s.host.
|
|
2138
|
+
if (input === "h") return s.host.beginPicker();
|
|
2139
|
+
if (input === "a") return s.host.begin();
|
|
1543
2140
|
if (input === "d") return s.drafts.begin();
|
|
1544
2141
|
if (input === "p") return s.preview.beginMenu();
|
|
1545
2142
|
if (input === "o") return s.exec.openLastOutput();
|
|
@@ -1560,7 +2157,7 @@ const TuiApp = observer((p) => {
|
|
|
1560
2157
|
flexDirection: "column",
|
|
1561
2158
|
flexGrow: 1,
|
|
1562
2159
|
children: [
|
|
1563
|
-
s.mode === "edit" && s.editor.isCustom ? /* @__PURE__ */ jsx(PromptOverlay, { st: s }) : s.mode === "host" ? /* @__PURE__ */ jsx(HostPanel, { st: s }) : s.mode === "overlay-text" ? /* @__PURE__ */ jsx(TextOverlay, { st: s }) : s.mode === "overlay-choice" ? /* @__PURE__ */ jsx(ChoiceOverlay, { st: s }) : s.mode === "overlay-size" ? /* @__PURE__ */ jsx(SizeOverlay, { st: s }) : s.mode === "overlay-loras" ? /* @__PURE__ */ jsx(LorasOverlay, { st: s }) : s.mode === "overlay-drafts" ? /* @__PURE__ */ jsx(DraftsOverlay, { st: s }) : /* @__PURE__ */ jsx(VarsPanel, { st: s }),
|
|
2160
|
+
s.mode === "edit" && s.editor.isCustom ? /* @__PURE__ */ jsx(PromptOverlay, { st: s }) : s.mode === "host" ? /* @__PURE__ */ jsx(HostPanel, { st: s }) : s.mode === "overlay-text" ? /* @__PURE__ */ jsx(TextOverlay, { st: s }) : s.mode === "overlay-choice" ? /* @__PURE__ */ jsx(ChoiceOverlay, { st: s }) : s.mode === "overlay-size" ? /* @__PURE__ */ jsx(SizeOverlay, { st: s }) : s.mode === "overlay-loras" ? /* @__PURE__ */ jsx(LorasOverlay, { st: s }) : s.mode === "overlay-image" ? /* @__PURE__ */ jsx(ImagePickerOverlay, { st: s }) : s.mode === "overlay-drafts" ? /* @__PURE__ */ jsx(DraftsOverlay, { st: s }) : s.mode === "overlay-hosts" ? /* @__PURE__ */ jsx(HostsOverlay, { st: s }) : s.mode === "overlay-copy" ? /* @__PURE__ */ jsx(CopyOverlay, { st: s }) : /* @__PURE__ */ jsx(VarsPanel, { st: s }),
|
|
1564
2161
|
/* @__PURE__ */ jsx(Box, {
|
|
1565
2162
|
paddingX: 1,
|
|
1566
2163
|
children: /* @__PURE__ */ jsx(ProgressLine, { st: s })
|
|
@@ -1593,10 +2190,183 @@ const TuiApp = observer((p) => {
|
|
|
1593
2190
|
});
|
|
1594
2191
|
});
|
|
1595
2192
|
//#endregion
|
|
2193
|
+
//#region src/cli/tui/treeRows.ts
|
|
2194
|
+
/** module display name — also the drafts folder key (DraftsSt delegates here) */
|
|
2195
|
+
function moduleName(file) {
|
|
2196
|
+
return basename(file).replace(/\.cflow\.tsx?$/, "");
|
|
2197
|
+
}
|
|
2198
|
+
/** the color word: everything before the first `-` (`flux1-i2i` → `flux1`) */
|
|
2199
|
+
function familyOf(name) {
|
|
2200
|
+
const dash = name.indexOf("-");
|
|
2201
|
+
return dash === -1 ? name : name.slice(0, dash);
|
|
2202
|
+
}
|
|
2203
|
+
/** hue-spread so CONSECUTIVE families land on clearly distinct colors */
|
|
2204
|
+
const FAMILY_PALETTE = [
|
|
2205
|
+
"#61afef",
|
|
2206
|
+
"#e5c07b",
|
|
2207
|
+
"#c678dd",
|
|
2208
|
+
"#98c379",
|
|
2209
|
+
"#e06c75",
|
|
2210
|
+
"#56b6c2",
|
|
2211
|
+
"#d19a66",
|
|
2212
|
+
"#a5b4fc",
|
|
2213
|
+
"#a5e075",
|
|
2214
|
+
"#f28fad"
|
|
2215
|
+
];
|
|
2216
|
+
/** family → color, palette cycled in first-appearance order over the FULL
|
|
2217
|
+
* (unfiltered) file list — stable while filtering/folding */
|
|
2218
|
+
function assignFamilyColors(files) {
|
|
2219
|
+
const colors = /* @__PURE__ */ new Map();
|
|
2220
|
+
for (const file of files) {
|
|
2221
|
+
const family = familyOf(moduleName(file));
|
|
2222
|
+
if (colors.has(family)) continue;
|
|
2223
|
+
colors.set(family, FAMILY_PALETTE[colors.size % FAMILY_PALETTE.length] ?? "#61afef");
|
|
2224
|
+
}
|
|
2225
|
+
return colors;
|
|
2226
|
+
}
|
|
2227
|
+
function commonDir(files) {
|
|
2228
|
+
const first = files[0];
|
|
2229
|
+
if (first == null) return "";
|
|
2230
|
+
let prefix = dirname(first).split("/");
|
|
2231
|
+
for (const f of files.slice(1)) {
|
|
2232
|
+
const segs = dirname(f).split("/");
|
|
2233
|
+
let i = 0;
|
|
2234
|
+
while (i < prefix.length && i < segs.length && prefix[i] === segs[i]) i++;
|
|
2235
|
+
prefix = prefix.slice(0, i);
|
|
2236
|
+
}
|
|
2237
|
+
return prefix.join("/");
|
|
2238
|
+
}
|
|
2239
|
+
function insert(root, rootDir, file) {
|
|
2240
|
+
const rel = dirname(file).slice(rootDir.length).replace(/^\//, "");
|
|
2241
|
+
const segs = rel === "" ? [] : rel.split("/");
|
|
2242
|
+
let node = root;
|
|
2243
|
+
for (const seg of segs) {
|
|
2244
|
+
let child = node.dirs.get(seg);
|
|
2245
|
+
if (child == null) {
|
|
2246
|
+
child = {
|
|
2247
|
+
path: `${node.path}/${seg}`,
|
|
2248
|
+
label: seg,
|
|
2249
|
+
files: [],
|
|
2250
|
+
dirs: /* @__PURE__ */ new Map()
|
|
2251
|
+
};
|
|
2252
|
+
node.dirs.set(seg, child);
|
|
2253
|
+
}
|
|
2254
|
+
node = child;
|
|
2255
|
+
}
|
|
2256
|
+
node.files.push(file);
|
|
2257
|
+
}
|
|
2258
|
+
/** a dir holding NOTHING but one subdir shows as one `a/b` row */
|
|
2259
|
+
function mergeChains(node) {
|
|
2260
|
+
const entries = [...node.dirs];
|
|
2261
|
+
for (const [key, child] of entries) {
|
|
2262
|
+
mergeChains(child);
|
|
2263
|
+
if (child.files.length === 0 && child.dirs.size === 1) {
|
|
2264
|
+
const only = [...child.dirs.values()][0];
|
|
2265
|
+
const label = `${child.label}/${only.label}`;
|
|
2266
|
+
node.dirs.delete(key);
|
|
2267
|
+
node.dirs.set(label, {
|
|
2268
|
+
...only,
|
|
2269
|
+
label
|
|
2270
|
+
});
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
function matches(file, rootDir, filter) {
|
|
2275
|
+
if (filter === "") return true;
|
|
2276
|
+
return `${dirname(file).slice(rootDir.length)}/${moduleName(file)}`.toLowerCase().includes(filter.toLowerCase());
|
|
2277
|
+
}
|
|
2278
|
+
function emit(p) {
|
|
2279
|
+
for (const file of p.node.files) {
|
|
2280
|
+
if (!matches(file, p.rootDir, p.filter)) continue;
|
|
2281
|
+
p.out.push({
|
|
2282
|
+
kind: "file",
|
|
2283
|
+
file,
|
|
2284
|
+
name: moduleName(file),
|
|
2285
|
+
depth: p.depth
|
|
2286
|
+
});
|
|
2287
|
+
}
|
|
2288
|
+
for (const dir of [...p.node.dirs.values()].sort((a, b) => a.label.localeCompare(b.label))) {
|
|
2289
|
+
const kept = [];
|
|
2290
|
+
const expanded = p.filter !== "" || !p.collapsedDirs.has(dir.path);
|
|
2291
|
+
emit({
|
|
2292
|
+
...p,
|
|
2293
|
+
node: dir,
|
|
2294
|
+
depth: p.depth + 1,
|
|
2295
|
+
out: kept
|
|
2296
|
+
});
|
|
2297
|
+
if (p.filter !== "" && kept.length === 0) continue;
|
|
2298
|
+
p.out.push({
|
|
2299
|
+
kind: "dir",
|
|
2300
|
+
path: dir.path,
|
|
2301
|
+
label: dir.label,
|
|
2302
|
+
depth: p.depth,
|
|
2303
|
+
expanded
|
|
2304
|
+
});
|
|
2305
|
+
if (expanded) p.out.push(...kept);
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
/**
|
|
2309
|
+
* hierarchy rows over the discovered files: user files under their common
|
|
2310
|
+
* root, packaged examples LAST under one foldable 'comfy-ts examples' node.
|
|
2311
|
+
*/
|
|
2312
|
+
function buildFileRows(p) {
|
|
2313
|
+
const out = [];
|
|
2314
|
+
if (p.userFiles.length > 0) {
|
|
2315
|
+
const rootDir = commonDir(p.userFiles);
|
|
2316
|
+
const root = {
|
|
2317
|
+
path: rootDir,
|
|
2318
|
+
label: "",
|
|
2319
|
+
files: [],
|
|
2320
|
+
dirs: /* @__PURE__ */ new Map()
|
|
2321
|
+
};
|
|
2322
|
+
for (const f of p.userFiles) insert(root, rootDir, f);
|
|
2323
|
+
mergeChains(root);
|
|
2324
|
+
emit({
|
|
2325
|
+
node: root,
|
|
2326
|
+
depth: 0,
|
|
2327
|
+
rootDir,
|
|
2328
|
+
collapsedDirs: p.collapsedDirs,
|
|
2329
|
+
filter: p.filter,
|
|
2330
|
+
out
|
|
2331
|
+
});
|
|
2332
|
+
}
|
|
2333
|
+
if (p.bundledFiles.length > 0) {
|
|
2334
|
+
const rootDir = commonDir(p.bundledFiles);
|
|
2335
|
+
const root = {
|
|
2336
|
+
path: rootDir,
|
|
2337
|
+
label: "comfy-ts examples",
|
|
2338
|
+
files: [],
|
|
2339
|
+
dirs: /* @__PURE__ */ new Map()
|
|
2340
|
+
};
|
|
2341
|
+
for (const f of p.bundledFiles) insert(root, rootDir, f);
|
|
2342
|
+
mergeChains(root);
|
|
2343
|
+
const kept = [];
|
|
2344
|
+
const expanded = p.filter !== "" || !p.collapsedDirs.has(rootDir);
|
|
2345
|
+
emit({
|
|
2346
|
+
node: root,
|
|
2347
|
+
depth: 1,
|
|
2348
|
+
rootDir,
|
|
2349
|
+
collapsedDirs: p.collapsedDirs,
|
|
2350
|
+
filter: p.filter,
|
|
2351
|
+
out: kept
|
|
2352
|
+
});
|
|
2353
|
+
if (p.filter !== "" && kept.length === 0) return out;
|
|
2354
|
+
out.push({
|
|
2355
|
+
kind: "dir",
|
|
2356
|
+
path: rootDir,
|
|
2357
|
+
label: root.label,
|
|
2358
|
+
depth: 0,
|
|
2359
|
+
expanded
|
|
2360
|
+
});
|
|
2361
|
+
if (expanded) out.push(...kept);
|
|
2362
|
+
}
|
|
2363
|
+
return out;
|
|
2364
|
+
}
|
|
2365
|
+
//#endregion
|
|
1596
2366
|
//#region src/cli/tui/state/DraftsSt.ts
|
|
1597
2367
|
/** module basename (`01-txt2img`) keys the draft folder — knowable for EVERY tree file without importing it */
|
|
1598
2368
|
function draftKeyForFile(file) {
|
|
1599
|
-
return
|
|
2369
|
+
return moduleName(file);
|
|
1600
2370
|
}
|
|
1601
2371
|
function draftsDirForFile(file) {
|
|
1602
2372
|
return comfyts.resolveFromDrafts(draftKeyForFile(file));
|
|
@@ -2060,6 +2830,13 @@ var EditorSt = class EditorSt {
|
|
|
2060
2830
|
};
|
|
2061
2831
|
//#endregion
|
|
2062
2832
|
//#region src/cli/tui/state/ExecSt.ts
|
|
2833
|
+
/** popup body: summary + the head of the copied json (proof of WHAT is in the clipboard) */
|
|
2834
|
+
function jsonHead(text, maxLines) {
|
|
2835
|
+
const lines = text.split("\n");
|
|
2836
|
+
const head = lines.slice(0, maxLines).map((l) => l.length > 76 ? `${l.slice(0, 75)}…` : l);
|
|
2837
|
+
if (lines.length > maxLines) head.push("…");
|
|
2838
|
+
return head;
|
|
2839
|
+
}
|
|
2063
2840
|
/** run lifecycle + outputs + status line + clipboard/open actions */
|
|
2064
2841
|
var ExecSt = class {
|
|
2065
2842
|
constructor(st) {
|
|
@@ -2072,6 +2849,9 @@ var ExecSt = class {
|
|
|
2072
2849
|
this.error = null;
|
|
2073
2850
|
this.notice = null;
|
|
2074
2851
|
this.currentPromptId = null;
|
|
2852
|
+
this.latentHosts = /* @__PURE__ */ new Set();
|
|
2853
|
+
this.copyPopup = null;
|
|
2854
|
+
this.copying = false;
|
|
2075
2855
|
makeAutoObservable(this, { st: false });
|
|
2076
2856
|
}
|
|
2077
2857
|
get running() {
|
|
@@ -2088,7 +2868,7 @@ var ExecSt = class {
|
|
|
2088
2868
|
/** every run takes THIS path, queued ones included: same progress, outputs, previews */
|
|
2089
2869
|
async run() {
|
|
2090
2870
|
const queued = this.running;
|
|
2091
|
-
const host = this.st.
|
|
2871
|
+
const host = this.st.runHost;
|
|
2092
2872
|
runInAction(() => {
|
|
2093
2873
|
this.inFlight++;
|
|
2094
2874
|
this.error = null;
|
|
@@ -2098,11 +2878,15 @@ var ExecSt = class {
|
|
|
2098
2878
|
this.notice = null;
|
|
2099
2879
|
this.currentPromptId = null;
|
|
2100
2880
|
this.st.preview.clearLatent();
|
|
2101
|
-
host.onLatentPreview = (p) => void this.st.preview.renderLatent(p.bytes);
|
|
2102
2881
|
}
|
|
2882
|
+
host.onLatentPreview = (p) => void this.st.preview.renderLatent(p.bytes);
|
|
2883
|
+
this.latentHosts.add(host);
|
|
2103
2884
|
});
|
|
2104
2885
|
try {
|
|
2105
|
-
const execution = await this.st.wf.run({
|
|
2886
|
+
const execution = await this.st.wf.run({
|
|
2887
|
+
host: this.st.hostOverride ?? void 0,
|
|
2888
|
+
onProgress: (p) => runInAction(() => this.onProgress(p))
|
|
2889
|
+
});
|
|
2106
2890
|
runInAction(() => {
|
|
2107
2891
|
this.outputs = execution.images.map((i) => i.absPath);
|
|
2108
2892
|
this.lastStatus = execution.status;
|
|
@@ -2120,7 +2904,10 @@ var ExecSt = class {
|
|
|
2120
2904
|
this.progress = null;
|
|
2121
2905
|
this.currentPromptId = null;
|
|
2122
2906
|
this.st.preview.clearLatent();
|
|
2123
|
-
if (this.inFlight === 0)
|
|
2907
|
+
if (this.inFlight === 0) {
|
|
2908
|
+
for (const h of this.latentHosts) h.onLatentPreview = null;
|
|
2909
|
+
this.latentHosts.clear();
|
|
2910
|
+
}
|
|
2124
2911
|
});
|
|
2125
2912
|
}
|
|
2126
2913
|
}
|
|
@@ -2157,6 +2944,23 @@ var ExecSt = class {
|
|
|
2157
2944
|
proc.unref();
|
|
2158
2945
|
this.notice = `opened ${basename(last)}`;
|
|
2159
2946
|
}
|
|
2947
|
+
closeCopyPopup() {
|
|
2948
|
+
this.copyPopup = null;
|
|
2949
|
+
this.st.mode = "nav";
|
|
2950
|
+
}
|
|
2951
|
+
showCopyPopup(title, ok, lines) {
|
|
2952
|
+
const m = this.st.mode;
|
|
2953
|
+
if (m === "edit" || m.startsWith("overlay-")) {
|
|
2954
|
+
this.notice = `${ok ? "✓" : "✗"} ${title}`;
|
|
2955
|
+
return;
|
|
2956
|
+
}
|
|
2957
|
+
this.copyPopup = {
|
|
2958
|
+
title,
|
|
2959
|
+
ok,
|
|
2960
|
+
lines
|
|
2961
|
+
};
|
|
2962
|
+
this.st.mode = "overlay-copy";
|
|
2963
|
+
}
|
|
2160
2964
|
toClipboard(text) {
|
|
2161
2965
|
const [cmd, ...args] = process.platform === "darwin" ? ["pbcopy"] : process.platform === "win32" ? ["clip"] : [
|
|
2162
2966
|
"xclip",
|
|
@@ -2177,29 +2981,67 @@ var ExecSt = class {
|
|
|
2177
2981
|
}
|
|
2178
2982
|
/** 'c': copy workflow.json (litegraph, drag into the ComfyUI editor) */
|
|
2179
2983
|
async copyWorkflowJson() {
|
|
2984
|
+
if (this.copying) return;
|
|
2985
|
+
runInAction(() => {
|
|
2986
|
+
this.copying = true;
|
|
2987
|
+
this.notice = "building for copy… (i2i workflows upload their input image first)";
|
|
2988
|
+
});
|
|
2180
2989
|
try {
|
|
2181
|
-
const json = await (await this.st.wf.build()).toWorkflowJson();
|
|
2182
|
-
const
|
|
2990
|
+
const json = await (await this.st.wf.build({ host: this.st.hostOverride ?? void 0 })).toWorkflowJson();
|
|
2991
|
+
const text = JSON.stringify(json, null, 2);
|
|
2992
|
+
const ok = await this.toClipboard(text);
|
|
2183
2993
|
runInAction(() => {
|
|
2184
|
-
this.
|
|
2994
|
+
this.showCopyPopup("workflow.json → clipboard", ok, ok ? [
|
|
2995
|
+
`${json.nodes.length} nodes · ${text.length} chars — paste into the ComfyUI editor`,
|
|
2996
|
+
"",
|
|
2997
|
+
...jsonHead(text, 10)
|
|
2998
|
+
] : ["CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?"]);
|
|
2185
2999
|
});
|
|
2186
3000
|
} catch (e) {
|
|
2187
3001
|
runInAction(() => {
|
|
2188
|
-
this.
|
|
3002
|
+
this.showCopyPopup("workflow.json copy FAILED", false, [
|
|
3003
|
+
extractErrorMessage(e),
|
|
3004
|
+
"",
|
|
3005
|
+
"nothing was copied. i2i/i2v builds upload their input image first —",
|
|
3006
|
+
"an unreachable host fails the build itself, not just the run."
|
|
3007
|
+
]);
|
|
3008
|
+
});
|
|
3009
|
+
} finally {
|
|
3010
|
+
runInAction(() => {
|
|
3011
|
+
this.copying = false;
|
|
2189
3012
|
});
|
|
2190
3013
|
}
|
|
2191
3014
|
}
|
|
2192
3015
|
/** 'C': copy api.json (the POST /prompt payload) */
|
|
2193
3016
|
async copyApiJson() {
|
|
3017
|
+
if (this.copying) return;
|
|
3018
|
+
runInAction(() => {
|
|
3019
|
+
this.copying = true;
|
|
3020
|
+
this.notice = "building for copy… (i2i workflows upload their input image first)";
|
|
3021
|
+
});
|
|
2194
3022
|
try {
|
|
2195
|
-
const json = (await this.st.wf.build()).toApiJson("use_stringified_numbers_only");
|
|
2196
|
-
const
|
|
3023
|
+
const json = (await this.st.wf.build({ host: this.st.hostOverride ?? void 0 })).toApiJson("use_stringified_numbers_only");
|
|
3024
|
+
const text = JSON.stringify(json, null, 2);
|
|
3025
|
+
const ok = await this.toClipboard(text);
|
|
2197
3026
|
runInAction(() => {
|
|
2198
|
-
this.
|
|
3027
|
+
this.showCopyPopup("api.json → clipboard", ok, ok ? [
|
|
3028
|
+
`${Object.keys(json).length} nodes · ${text.length} chars — the POST /prompt payload`,
|
|
3029
|
+
"",
|
|
3030
|
+
...jsonHead(text, 10)
|
|
3031
|
+
] : ["CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?"]);
|
|
2199
3032
|
});
|
|
2200
3033
|
} catch (e) {
|
|
2201
3034
|
runInAction(() => {
|
|
2202
|
-
this.
|
|
3035
|
+
this.showCopyPopup("api.json copy FAILED", false, [
|
|
3036
|
+
extractErrorMessage(e),
|
|
3037
|
+
"",
|
|
3038
|
+
"nothing was copied. i2i/i2v builds upload their input image first —",
|
|
3039
|
+
"an unreachable host fails the build itself, not just the run."
|
|
3040
|
+
]);
|
|
3041
|
+
});
|
|
3042
|
+
} finally {
|
|
3043
|
+
runInAction(() => {
|
|
3044
|
+
this.copying = false;
|
|
2203
3045
|
});
|
|
2204
3046
|
}
|
|
2205
3047
|
}
|
|
@@ -2220,12 +3062,35 @@ const SPIN_FRAMES = [
|
|
|
2220
3062
|
"⠇",
|
|
2221
3063
|
"⠏"
|
|
2222
3064
|
];
|
|
3065
|
+
/**
|
|
3066
|
+
* PURE probe verdict (headless-tested). http ok is proof enough; on http
|
|
3067
|
+
* failure a RECENTLY TALKING open ws still means up — ComfyUI is
|
|
3068
|
+
* single-threaded and stalls new connects mid-generation while established
|
|
3069
|
+
* sockets stream (his repro 2026-07-30: 'windows-1 offline' in the header
|
|
3070
|
+
* while the browser tab generated fine). A half-open socket receives
|
|
3071
|
+
* nothing, so the recency window never revives one.
|
|
3072
|
+
*/
|
|
3073
|
+
function probeVerdict(p) {
|
|
3074
|
+
if (p.httpOk) return {
|
|
3075
|
+
status: "up",
|
|
3076
|
+
via: p.wsOpen ? "ws" : "http"
|
|
3077
|
+
};
|
|
3078
|
+
if (p.wsOpen && p.lastWsMessageAt != null && p.now - p.lastWsMessageAt < 1e4) return {
|
|
3079
|
+
status: "up",
|
|
3080
|
+
via: "ws"
|
|
3081
|
+
};
|
|
3082
|
+
return {
|
|
3083
|
+
status: "down",
|
|
3084
|
+
via: null
|
|
3085
|
+
};
|
|
3086
|
+
}
|
|
2223
3087
|
/** host panel (`h`): stats about the connected host + maintenance actions */
|
|
2224
3088
|
var HostSt = class {
|
|
2225
3089
|
constructor(st) {
|
|
2226
3090
|
this.st = st;
|
|
2227
3091
|
this.status = "unknown";
|
|
2228
3092
|
this.statusVia = null;
|
|
3093
|
+
this.lastProbeError = null;
|
|
2229
3094
|
this.probing = false;
|
|
2230
3095
|
this.retryInS = 0;
|
|
2231
3096
|
this.spinFrame = 0;
|
|
@@ -2254,6 +3119,7 @@ var HostSt = class {
|
|
|
2254
3119
|
label: "interrupt current run"
|
|
2255
3120
|
}
|
|
2256
3121
|
];
|
|
3122
|
+
this.pickerIx = 0;
|
|
2257
3123
|
makeAutoObservable(this, { st: false });
|
|
2258
3124
|
this.probeLoop();
|
|
2259
3125
|
this.st.disposers.push(() => {
|
|
@@ -2262,10 +3128,11 @@ var HostSt = class {
|
|
|
2262
3128
|
if (this.spinTimer != null) clearInterval(this.spinTimer);
|
|
2263
3129
|
if (this.countdownTimer != null) clearInterval(this.countdownTimer);
|
|
2264
3130
|
});
|
|
2265
|
-
this.st.disposers.push(reaction(() => this.st.
|
|
3131
|
+
this.st.disposers.push(reaction(() => this.st.runHost, () => {
|
|
2266
3132
|
runInAction(() => {
|
|
2267
3133
|
this.status = "unknown";
|
|
2268
3134
|
this.statusVia = null;
|
|
3135
|
+
this.lastProbeError = null;
|
|
2269
3136
|
});
|
|
2270
3137
|
this.probeGen++;
|
|
2271
3138
|
if (this.loopTimer != null) clearTimeout(this.loopTimer);
|
|
@@ -2298,8 +3165,9 @@ var HostSt = class {
|
|
|
2298
3165
|
}, PROBE_EVERY_MS);
|
|
2299
3166
|
this.loopTimer.unref?.();
|
|
2300
3167
|
}
|
|
2301
|
-
/** http
|
|
2302
|
-
*
|
|
3168
|
+
/** http first — a half-open ws keeps isOpen=true forever, so isOpen alone
|
|
3169
|
+
* is never trusted. RECENT MESSAGES are: probeVerdict lets a talking ws
|
|
3170
|
+
* beat a stalled http probe (busy single-threaded server) */
|
|
2303
3171
|
async probe() {
|
|
2304
3172
|
const host = this.host;
|
|
2305
3173
|
runInAction(() => {
|
|
@@ -2313,12 +3181,15 @@ var HostSt = class {
|
|
|
2313
3181
|
spin.unref?.();
|
|
2314
3182
|
this.spinTimer = spin;
|
|
2315
3183
|
let ok = false;
|
|
3184
|
+
let probeError = null;
|
|
2316
3185
|
try {
|
|
2317
3186
|
const res = await host.fetch("/prompt", { signal: AbortSignal.timeout(PROBE_TIMEOUT_MS) });
|
|
2318
3187
|
res.body?.cancel();
|
|
2319
3188
|
ok = res.ok;
|
|
2320
|
-
|
|
3189
|
+
if (!ok) probeError = `http ${res.status}`;
|
|
3190
|
+
} catch (e) {
|
|
2321
3191
|
ok = false;
|
|
3192
|
+
probeError = extractErrorMessage(e);
|
|
2322
3193
|
} finally {
|
|
2323
3194
|
clearInterval(spin);
|
|
2324
3195
|
if (this.spinTimer === spin) {
|
|
@@ -2329,13 +3200,20 @@ var HostSt = class {
|
|
|
2329
3200
|
}
|
|
2330
3201
|
}
|
|
2331
3202
|
if (this.host !== host) return;
|
|
3203
|
+
const verdict = probeVerdict({
|
|
3204
|
+
httpOk: ok,
|
|
3205
|
+
wsOpen: host.isConnected,
|
|
3206
|
+
lastWsMessageAt: host.lastWsMessageAt,
|
|
3207
|
+
now: Date.now()
|
|
3208
|
+
});
|
|
2332
3209
|
runInAction(() => {
|
|
2333
|
-
this.status =
|
|
2334
|
-
this.statusVia =
|
|
3210
|
+
this.status = verdict.status;
|
|
3211
|
+
this.statusVia = verdict.via;
|
|
3212
|
+
this.lastProbeError = probeError;
|
|
2335
3213
|
});
|
|
2336
3214
|
}
|
|
2337
3215
|
get host() {
|
|
2338
|
-
return this.st.
|
|
3216
|
+
return this.st.runHost;
|
|
2339
3217
|
}
|
|
2340
3218
|
get stats() {
|
|
2341
3219
|
const schema = this.host.schema;
|
|
@@ -2344,6 +3222,10 @@ var HostSt = class {
|
|
|
2344
3222
|
label: "status",
|
|
2345
3223
|
value: this.status === "down" ? `down · ${this.probing ? `${this.spinner} probing…` : `retry in ${this.retryInS}s`}` : this.status + (this.statusVia != null ? ` (${this.statusVia})` : "")
|
|
2346
3224
|
},
|
|
3225
|
+
...this.lastProbeError != null ? [{
|
|
3226
|
+
label: "http probe",
|
|
3227
|
+
value: this.lastProbeError
|
|
3228
|
+
}] : [],
|
|
2347
3229
|
{
|
|
2348
3230
|
label: "node types",
|
|
2349
3231
|
value: String(schema.nodes.length)
|
|
@@ -2373,6 +3255,39 @@ var HostSt = class {
|
|
|
2373
3255
|
blur() {
|
|
2374
3256
|
this.st.mode = "nav";
|
|
2375
3257
|
}
|
|
3258
|
+
get pickerRows() {
|
|
3259
|
+
const rows = [{
|
|
3260
|
+
host: null,
|
|
3261
|
+
label: `workflow default (${this.st.wf.host.data.id})`,
|
|
3262
|
+
active: this.st.hostOverride == null
|
|
3263
|
+
}];
|
|
3264
|
+
for (const host of comfyts.hosts.values()) rows.push({
|
|
3265
|
+
host,
|
|
3266
|
+
label: `${host.data.id} (${host.base.host}:${host.base.port})`,
|
|
3267
|
+
active: this.st.hostOverride === host
|
|
3268
|
+
});
|
|
3269
|
+
return rows;
|
|
3270
|
+
}
|
|
3271
|
+
beginPicker() {
|
|
3272
|
+
this.st.mode = "overlay-hosts";
|
|
3273
|
+
const active = this.pickerRows.findIndex((r) => r.active);
|
|
3274
|
+
this.pickerIx = active === -1 ? 0 : active;
|
|
3275
|
+
}
|
|
3276
|
+
cancelPicker() {
|
|
3277
|
+
this.st.mode = "nav";
|
|
3278
|
+
}
|
|
3279
|
+
pickerMove(delta) {
|
|
3280
|
+
const len = this.pickerRows.length;
|
|
3281
|
+
if (len === 0) return;
|
|
3282
|
+
this.pickerIx = (this.pickerIx + delta + len) % len;
|
|
3283
|
+
}
|
|
3284
|
+
commitPicker() {
|
|
3285
|
+
const row = this.pickerRows[this.pickerIx];
|
|
3286
|
+
if (row == null) return;
|
|
3287
|
+
this.st.setHostOverride(row.host);
|
|
3288
|
+
this.st.mode = "nav";
|
|
3289
|
+
this.st.exec.notice = row.host == null ? `host override cleared — runs target the workflow's own host (${this.st.wf.host.data.id})` : `runs now target ${row.host.data.id} (overrides ${this.st.wf.host.data.id})`;
|
|
3290
|
+
}
|
|
2376
3291
|
move(delta) {
|
|
2377
3292
|
const len = this.actions.length;
|
|
2378
3293
|
this.ix = (this.ix + delta + len) % len;
|
|
@@ -2673,16 +3588,6 @@ async function fetchLoraPreviewBytes(host, previewUrl) {
|
|
|
2673
3588
|
}
|
|
2674
3589
|
}
|
|
2675
3590
|
//#endregion
|
|
2676
|
-
//#region src/utils/fuzzyMatch.ts
|
|
2677
|
-
/** case-insensitive subsequence match: 'wide' hits '16:9 (Widescreen)' */
|
|
2678
|
-
function fuzzyMatch(needle, hay) {
|
|
2679
|
-
const n = needle.toLowerCase();
|
|
2680
|
-
const h = hay.toLowerCase();
|
|
2681
|
-
let i = 0;
|
|
2682
|
-
for (const ch of h) if (ch === n[i]) i++;
|
|
2683
|
-
return i >= n.length;
|
|
2684
|
-
}
|
|
2685
|
-
//#endregion
|
|
2686
3591
|
//#region src/cli/tui/state/LorasSt.ts
|
|
2687
3592
|
/** loras overlay: fuzzy filter + tick/untick + strengths + bulk ops + lora-manager preview */
|
|
2688
3593
|
var LorasSt = class {
|
|
@@ -2690,10 +3595,6 @@ var LorasSt = class {
|
|
|
2690
3595
|
this.st = st;
|
|
2691
3596
|
this.ix = 0;
|
|
2692
3597
|
this.filter = "";
|
|
2693
|
-
this.previewAnsi = null;
|
|
2694
|
-
this.previewBytes = null;
|
|
2695
|
-
this.previewName = null;
|
|
2696
|
-
this.previewNote = null;
|
|
2697
3598
|
this.previewMap = void 0;
|
|
2698
3599
|
this.previewMapHostId = null;
|
|
2699
3600
|
this._busy = false;
|
|
@@ -2717,6 +3618,7 @@ var LorasSt = class {
|
|
|
2717
3618
|
this.st.mode = "overlay-loras";
|
|
2718
3619
|
this.ix = 0;
|
|
2719
3620
|
this.filter = "";
|
|
3621
|
+
this.st.preview.clearOverlayImage();
|
|
2720
3622
|
}
|
|
2721
3623
|
move(delta) {
|
|
2722
3624
|
const len = this.filteredNames.length;
|
|
@@ -2769,14 +3671,10 @@ var LorasSt = class {
|
|
|
2769
3671
|
get selectedName() {
|
|
2770
3672
|
return this.filteredNames[this.ix] ?? null;
|
|
2771
3673
|
}
|
|
3674
|
+
/** preview goes through PreviewSt's shared overlay slot (one code path with the image picker) */
|
|
2772
3675
|
async refreshPreview() {
|
|
2773
3676
|
if (this.st.mode !== "overlay-loras") {
|
|
2774
|
-
|
|
2775
|
-
this.previewAnsi = null;
|
|
2776
|
-
this.previewBytes = null;
|
|
2777
|
-
this.previewName = null;
|
|
2778
|
-
this.previewNote = null;
|
|
2779
|
-
});
|
|
3677
|
+
if (!this.st.preview.overlayActive) this.st.preview.clearOverlayImage();
|
|
2780
3678
|
return;
|
|
2781
3679
|
}
|
|
2782
3680
|
const name = this.selectedName;
|
|
@@ -2792,22 +3690,22 @@ var LorasSt = class {
|
|
|
2792
3690
|
const url = map?.get(loraPreviewKey(name));
|
|
2793
3691
|
const note = map == null ? "lora-manager extension not detected" : url == null ? "no preview available" : null;
|
|
2794
3692
|
if (url == null) {
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
3693
|
+
this.st.preview.setOverlayImage({
|
|
3694
|
+
bytes: null,
|
|
3695
|
+
ansi: null,
|
|
3696
|
+
name: `lora ${name}`,
|
|
3697
|
+
note
|
|
2800
3698
|
});
|
|
2801
3699
|
return;
|
|
2802
3700
|
}
|
|
2803
3701
|
const bytes = await fetchLoraPreviewBytes(host, url);
|
|
2804
3702
|
if (bytes == null) throw new Error("no image preview on the server");
|
|
2805
3703
|
if (this.st.preview.useNative) {
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
3704
|
+
this.st.preview.setOverlayImage({
|
|
3705
|
+
bytes,
|
|
3706
|
+
ansi: null,
|
|
3707
|
+
name: `lora ${name}`,
|
|
3708
|
+
note: null
|
|
2811
3709
|
});
|
|
2812
3710
|
return;
|
|
2813
3711
|
}
|
|
@@ -2815,17 +3713,18 @@ var LorasSt = class {
|
|
|
2815
3713
|
width: this.st.preview.width,
|
|
2816
3714
|
height: this.st.preview.height
|
|
2817
3715
|
});
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
3716
|
+
this.st.preview.setOverlayImage({
|
|
3717
|
+
bytes: null,
|
|
3718
|
+
ansi,
|
|
3719
|
+
name: `lora ${name}`,
|
|
3720
|
+
note: null
|
|
2822
3721
|
});
|
|
2823
3722
|
} catch (e) {
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
3723
|
+
this.st.preview.setOverlayImage({
|
|
3724
|
+
bytes: null,
|
|
3725
|
+
ansi: null,
|
|
3726
|
+
name: `lora ${name}`,
|
|
3727
|
+
note: extractErrorMessage(e)
|
|
2829
3728
|
});
|
|
2830
3729
|
} finally {
|
|
2831
3730
|
this._busy = false;
|
|
@@ -2845,6 +3744,7 @@ var PickerSt = class {
|
|
|
2845
3744
|
this.filter = "";
|
|
2846
3745
|
this.ix = 0;
|
|
2847
3746
|
this.invalid = false;
|
|
3747
|
+
this.imageSizeRow = null;
|
|
2848
3748
|
makeAutoObservable(this, { st: false });
|
|
2849
3749
|
}
|
|
2850
3750
|
get choiceVar() {
|
|
@@ -2864,6 +3764,7 @@ var PickerSt = class {
|
|
|
2864
3764
|
const sv = this.sizeVar;
|
|
2865
3765
|
if (sv != null) {
|
|
2866
3766
|
const labels = sv.presets.map((p) => `${p.width}×${p.height} ${p.label}`);
|
|
3767
|
+
if (this.imageSizeRow != null) labels.unshift(this.imageSizeRow);
|
|
2867
3768
|
if (this.filter === "") return labels;
|
|
2868
3769
|
return labels.filter((l) => fuzzyMatch(this.filter, l));
|
|
2869
3770
|
}
|
|
@@ -2883,8 +3784,10 @@ var PickerSt = class {
|
|
|
2883
3784
|
this.st.mode = "overlay-size";
|
|
2884
3785
|
this.filter = "";
|
|
2885
3786
|
this.invalid = false;
|
|
2886
|
-
const
|
|
2887
|
-
this.
|
|
3787
|
+
const img = sv.imageSize();
|
|
3788
|
+
this.imageSizeRow = img == null ? null : `${img.width}×${img.height} size of image '${img.name}'`;
|
|
3789
|
+
const presetIx = sv.presets.findIndex((p) => p.width === sv.value.width && p.height === sv.value.height);
|
|
3790
|
+
this.ix = presetIx === -1 ? 0 : presetIx + (this.imageSizeRow != null ? 1 : 0);
|
|
2888
3791
|
}
|
|
2889
3792
|
move(delta) {
|
|
2890
3793
|
const len = this.options.length;
|
|
@@ -2960,7 +3863,7 @@ var QueueSt = class {
|
|
|
2960
3863
|
}
|
|
2961
3864
|
async clearPending() {
|
|
2962
3865
|
try {
|
|
2963
|
-
await this.st.
|
|
3866
|
+
await this.st.runHost.clearQueue();
|
|
2964
3867
|
runInAction(() => {
|
|
2965
3868
|
this.st.exec.notice = "pending queue cleared";
|
|
2966
3869
|
});
|
|
@@ -2972,7 +3875,7 @@ var QueueSt = class {
|
|
|
2972
3875
|
}
|
|
2973
3876
|
async interrupt() {
|
|
2974
3877
|
try {
|
|
2975
|
-
await this.st.
|
|
3878
|
+
await this.st.runHost.interrupt();
|
|
2976
3879
|
runInAction(() => {
|
|
2977
3880
|
this.st.exec.notice = "interrupt requested";
|
|
2978
3881
|
});
|
|
@@ -3006,15 +3909,25 @@ var SettingsSt = class {
|
|
|
3006
3909
|
this.previewRenderer = protocolCapable() ? "native" : "pixel";
|
|
3007
3910
|
this.previewDuringRun = "latent";
|
|
3008
3911
|
this.lastDraft = {};
|
|
3912
|
+
this.lastWorkflow = null;
|
|
3913
|
+
this.hostOverrideId = null;
|
|
3914
|
+
this.collapsedDirs = [];
|
|
3009
3915
|
this.load();
|
|
3010
3916
|
if (this.previewRenderer === "native" && !protocolCapable()) this.previewRenderer = "pixel";
|
|
3011
3917
|
makeAutoObservable(this, { st: false });
|
|
3012
|
-
this.st.disposers.push(reaction(() =>
|
|
3918
|
+
this.st.disposers.push(reaction(() => this.snapshotJson(), (json) => this.write(json), { delay: 300 }));
|
|
3919
|
+
this.st.disposers.push(() => this.write(this.snapshotJson()));
|
|
3920
|
+
}
|
|
3921
|
+
snapshotJson() {
|
|
3922
|
+
return JSON.stringify({
|
|
3013
3923
|
previewPanel: this.previewPanel,
|
|
3014
3924
|
previewRenderer: this.previewRenderer,
|
|
3015
3925
|
previewDuringRun: this.previewDuringRun,
|
|
3016
|
-
lastDraft: this.lastDraft
|
|
3017
|
-
|
|
3926
|
+
lastDraft: this.lastDraft,
|
|
3927
|
+
lastWorkflow: this.lastWorkflow,
|
|
3928
|
+
hostOverrideId: this.hostOverrideId,
|
|
3929
|
+
collapsedDirs: this.collapsedDirs
|
|
3930
|
+
});
|
|
3018
3931
|
}
|
|
3019
3932
|
rememberDraft(moduleKey, draft) {
|
|
3020
3933
|
this.lastDraft[moduleKey] = draft;
|
|
@@ -3035,6 +3948,9 @@ var SettingsSt = class {
|
|
|
3035
3948
|
this.previewRenderer = preview.previewRenderer;
|
|
3036
3949
|
this.previewDuringRun = preview.previewDuringRun;
|
|
3037
3950
|
if (o.lastDraft != null && typeof o.lastDraft === "object") this.lastDraft = { ...o.lastDraft };
|
|
3951
|
+
if (typeof o.lastWorkflow === "string") this.lastWorkflow = o.lastWorkflow;
|
|
3952
|
+
if (typeof o.hostOverrideId === "string") this.hostOverrideId = o.hostOverrideId;
|
|
3953
|
+
if (Array.isArray(o.collapsedDirs)) this.collapsedDirs = o.collapsedDirs.filter((d) => typeof d === "string");
|
|
3038
3954
|
} catch {}
|
|
3039
3955
|
}
|
|
3040
3956
|
write(json) {
|
|
@@ -3051,45 +3967,62 @@ var SettingsSt = class {
|
|
|
3051
3967
|
};
|
|
3052
3968
|
//#endregion
|
|
3053
3969
|
//#region src/cli/tui/state/TreeSt.ts
|
|
3054
|
-
/** the left `(t)ree`: workflows with their drafts nested
|
|
3970
|
+
/** the left `(t)ree`: directory hierarchy + workflows with their drafts nested */
|
|
3055
3971
|
var TreeSt = class {
|
|
3056
3972
|
constructor(st) {
|
|
3057
3973
|
this.st = st;
|
|
3058
3974
|
this.ix = 0;
|
|
3059
3975
|
this.expandedFiles = /* @__PURE__ */ new Set();
|
|
3976
|
+
this.filter = "";
|
|
3977
|
+
this.filtering = false;
|
|
3978
|
+
this.collapsedDirs = new Set(st.settings.collapsedDirs);
|
|
3060
3979
|
makeAutoObservable(this, { st: false });
|
|
3061
3980
|
}
|
|
3981
|
+
/** fold state is hand-tuned: mirror every change into the settings file */
|
|
3982
|
+
persistFolds() {
|
|
3983
|
+
this.st.settings.collapsedDirs = [...this.collapsedDirs];
|
|
3984
|
+
}
|
|
3985
|
+
/** family → color over the FULL file list (stable under filter/fold) */
|
|
3986
|
+
get familyColors() {
|
|
3987
|
+
return assignFamilyColors(this.st.workflows.files);
|
|
3988
|
+
}
|
|
3062
3989
|
get rows() {
|
|
3063
3990
|
this.st.drafts.version;
|
|
3064
3991
|
const w = this.st.workflows;
|
|
3992
|
+
const fileRows = buildFileRows({
|
|
3993
|
+
userFiles: w.files.filter((f) => !w.bundled.has(f)),
|
|
3994
|
+
bundledFiles: w.files.filter((f) => w.bundled.has(f)),
|
|
3995
|
+
collapsedDirs: this.collapsedDirs,
|
|
3996
|
+
filter: this.filter
|
|
3997
|
+
});
|
|
3998
|
+
const colors = this.familyColors;
|
|
3065
3999
|
const rows = [];
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
kind: "section",
|
|
3071
|
-
label: "comfy-ts examples"
|
|
3072
|
-
});
|
|
3073
|
-
sectionPushed = true;
|
|
4000
|
+
for (const row of fileRows) {
|
|
4001
|
+
if (row.kind === "dir") {
|
|
4002
|
+
rows.push(row);
|
|
4003
|
+
continue;
|
|
3074
4004
|
}
|
|
3075
|
-
const current = file === w.currentPath;
|
|
3076
|
-
const expanded = this.expandedFiles.has(file);
|
|
3077
|
-
const drafts = listDraftsForFile(file);
|
|
4005
|
+
const current = row.file === w.currentPath;
|
|
4006
|
+
const expanded = this.expandedFiles.has(row.file);
|
|
4007
|
+
const drafts = listDraftsForFile(row.file);
|
|
3078
4008
|
rows.push({
|
|
3079
4009
|
kind: "workflow",
|
|
3080
|
-
file,
|
|
3081
|
-
name:
|
|
4010
|
+
file: row.file,
|
|
4011
|
+
name: row.name,
|
|
4012
|
+
depth: row.depth,
|
|
3082
4013
|
expanded,
|
|
3083
4014
|
current,
|
|
3084
4015
|
hasDrafts: drafts.length > 0,
|
|
3085
|
-
error: w.loadErrors.get(file) ?? null
|
|
4016
|
+
error: w.loadErrors.get(row.file) ?? null,
|
|
4017
|
+
color: w.specColors.get(row.file) ?? colors.get(familyOf(row.name)) ?? "white"
|
|
3086
4018
|
});
|
|
3087
4019
|
if (!expanded) continue;
|
|
3088
4020
|
for (const draft of drafts) rows.push({
|
|
3089
4021
|
kind: "draft",
|
|
3090
|
-
file,
|
|
4022
|
+
file: row.file,
|
|
3091
4023
|
draft,
|
|
3092
|
-
active: current && draft === this.st.drafts.active
|
|
4024
|
+
active: current && draft === this.st.drafts.active,
|
|
4025
|
+
depth: row.depth + 1
|
|
3093
4026
|
});
|
|
3094
4027
|
}
|
|
3095
4028
|
return rows;
|
|
@@ -3104,7 +4037,16 @@ var TreeSt = class {
|
|
|
3104
4037
|
this.st.exec.notice = "no workflow tree — start the tui in a folder containing **/*.cflow.ts";
|
|
3105
4038
|
return;
|
|
3106
4039
|
}
|
|
3107
|
-
if (w.currentPath != null)
|
|
4040
|
+
if (w.currentPath != null) {
|
|
4041
|
+
this.expandedFiles.add(w.currentPath);
|
|
4042
|
+
let changed = false;
|
|
4043
|
+
const collapsed = [...this.collapsedDirs];
|
|
4044
|
+
for (const dir of collapsed) if (w.currentPath.startsWith(`${dir}/`)) {
|
|
4045
|
+
this.collapsedDirs.delete(dir);
|
|
4046
|
+
changed = true;
|
|
4047
|
+
}
|
|
4048
|
+
if (changed) this.persistFolds();
|
|
4049
|
+
}
|
|
3108
4050
|
this.st.mode = "tree";
|
|
3109
4051
|
const rows = this.rows;
|
|
3110
4052
|
const draftIx = rows.findIndex((r) => r.kind === "draft" && r.active);
|
|
@@ -3113,48 +4055,98 @@ var TreeSt = class {
|
|
|
3113
4055
|
}
|
|
3114
4056
|
/** esc/t inside the tree, → on a draft row, `v` anywhere: back to the vars list */
|
|
3115
4057
|
blur() {
|
|
4058
|
+
this.filtering = false;
|
|
3116
4059
|
this.st.mode = "nav";
|
|
3117
4060
|
}
|
|
3118
4061
|
move(delta) {
|
|
3119
|
-
const
|
|
3120
|
-
const len = rows.length;
|
|
4062
|
+
const len = this.rows.length;
|
|
3121
4063
|
if (len === 0) return;
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
4064
|
+
this.ix = (this.ix + delta + len) % len;
|
|
4065
|
+
}
|
|
4066
|
+
beginFilter() {
|
|
4067
|
+
this.filtering = true;
|
|
4068
|
+
}
|
|
4069
|
+
filterInput(ch) {
|
|
4070
|
+
this.filter += ch;
|
|
4071
|
+
this.clampToSelectable();
|
|
4072
|
+
}
|
|
4073
|
+
filterBackspace() {
|
|
4074
|
+
this.filter = this.filter.slice(0, -1);
|
|
4075
|
+
this.clampToSelectable();
|
|
4076
|
+
}
|
|
4077
|
+
/** esc while the filter owns the keys: drop it, stay in the tree */
|
|
4078
|
+
clearFilter() {
|
|
4079
|
+
this.filter = "";
|
|
4080
|
+
this.filtering = false;
|
|
4081
|
+
this.clampToSelectable();
|
|
4082
|
+
}
|
|
4083
|
+
/** filter edits reshape rows: keep the cursor on a workflow row when one exists */
|
|
4084
|
+
clampToSelectable() {
|
|
4085
|
+
const rows = this.rows;
|
|
4086
|
+
this.ix = Math.min(this.ix, Math.max(0, rows.length - 1));
|
|
4087
|
+
if (rows[this.ix]?.kind !== "workflow") {
|
|
4088
|
+
const first = rows.findIndex((r) => r.kind === "workflow");
|
|
4089
|
+
if (first !== -1) this.ix = first;
|
|
3126
4090
|
}
|
|
3127
|
-
this.ix = ix;
|
|
3128
4091
|
}
|
|
3129
|
-
/** →: unfold the workflow under the cursor; on a draft row there is
|
|
3130
|
-
* left to unfold, so → continues rightwards into the vars panel */
|
|
4092
|
+
/** →: unfold the dir/workflow under the cursor; on a draft row there is
|
|
4093
|
+
* nothing left to unfold, so → continues rightwards into the vars panel */
|
|
3131
4094
|
unfold() {
|
|
3132
4095
|
const row = this.selected;
|
|
3133
|
-
if (row == null
|
|
3134
|
-
if (row.kind === "
|
|
4096
|
+
if (row == null) return;
|
|
4097
|
+
if (row.kind === "dir") {
|
|
4098
|
+
this.collapsedDirs.delete(row.path);
|
|
4099
|
+
this.persistFolds();
|
|
4100
|
+
} else if (row.kind === "workflow") this.expandedFiles.add(row.file);
|
|
3135
4101
|
else this.blur();
|
|
3136
4102
|
}
|
|
3137
|
-
/** ←: fold
|
|
4103
|
+
/** ←: fold under the cursor; on an already-folded row, jump to the parent */
|
|
3138
4104
|
fold() {
|
|
3139
4105
|
const row = this.selected;
|
|
3140
|
-
if (row == null
|
|
3141
|
-
|
|
4106
|
+
if (row == null) return;
|
|
4107
|
+
if (row.kind === "dir") {
|
|
4108
|
+
this.collapsedDirs.add(row.path);
|
|
4109
|
+
this.persistFolds();
|
|
4110
|
+
return;
|
|
4111
|
+
}
|
|
3142
4112
|
if (row.kind === "draft") {
|
|
3143
4113
|
const ix = this.rows.findIndex((r) => r.kind === "workflow" && r.file === row.file);
|
|
3144
4114
|
if (ix !== -1) this.ix = ix;
|
|
4115
|
+
this.expandedFiles.delete(row.file);
|
|
4116
|
+
return;
|
|
4117
|
+
}
|
|
4118
|
+
if (row.expanded) {
|
|
4119
|
+
this.expandedFiles.delete(row.file);
|
|
4120
|
+
return;
|
|
4121
|
+
}
|
|
4122
|
+
for (let ix = this.ix - 1; ix >= 0; ix--) {
|
|
4123
|
+
const r = this.rows[ix];
|
|
4124
|
+
if (r?.kind === "dir" && r.depth < row.depth) {
|
|
4125
|
+
this.ix = ix;
|
|
4126
|
+
return;
|
|
4127
|
+
}
|
|
3145
4128
|
}
|
|
3146
4129
|
}
|
|
3147
|
-
/** ⏎: load the workflow (into 'default'), or the exact draft
|
|
4130
|
+
/** ⏎: toggle a dir, load the workflow (into 'default'), or load the exact draft */
|
|
3148
4131
|
async commit() {
|
|
3149
4132
|
const row = this.selected;
|
|
3150
|
-
if (row == null
|
|
4133
|
+
if (row == null) return;
|
|
4134
|
+
if (row.kind === "dir") {
|
|
4135
|
+
if (this.filter !== "") return;
|
|
4136
|
+
if (row.expanded) this.collapsedDirs.add(row.path);
|
|
4137
|
+
else this.collapsedDirs.delete(row.path);
|
|
4138
|
+
this.persistFolds();
|
|
4139
|
+
return;
|
|
4140
|
+
}
|
|
4141
|
+
this.filter = "";
|
|
4142
|
+
this.filtering = false;
|
|
3151
4143
|
if (row.kind === "workflow") return this.st.workflows.commit(row.file);
|
|
3152
4144
|
return this.st.workflows.commit(row.file, row.draft);
|
|
3153
4145
|
}
|
|
3154
4146
|
/** n: new draft — current workflow only (a draft snapshots its LIVE var values) */
|
|
3155
4147
|
promptNewDraft() {
|
|
3156
4148
|
const row = this.selected;
|
|
3157
|
-
if (row?.kind === "
|
|
4149
|
+
if (row?.kind === "dir") return;
|
|
3158
4150
|
if (row != null && row.file !== this.st.workflows.currentPath) {
|
|
3159
4151
|
this.st.exec.notice = "load that workflow first (⏎) — a new draft snapshots its live vars";
|
|
3160
4152
|
return;
|
|
@@ -3182,12 +4174,16 @@ var WorkflowsSt = class {
|
|
|
3182
4174
|
this.st = st;
|
|
3183
4175
|
this.files = files;
|
|
3184
4176
|
this.loading = false;
|
|
4177
|
+
this.specColors = /* @__PURE__ */ new Map();
|
|
3185
4178
|
this.loadedHosts = /* @__PURE__ */ new Set();
|
|
3186
4179
|
this.currentPath = currentPath;
|
|
3187
4180
|
this.bundled = bundled;
|
|
3188
4181
|
this.loadErrors = loadErrors;
|
|
3189
4182
|
makeAutoObservable(this, { st: false });
|
|
3190
4183
|
}
|
|
4184
|
+
recordSpecColor(path, wf) {
|
|
4185
|
+
if (wf.spec.color != null) this.specColors.set(path, wf.spec.color);
|
|
4186
|
+
}
|
|
3191
4187
|
disconnectAllHosts() {
|
|
3192
4188
|
this.loadedHosts.add(this.st.wf.host);
|
|
3193
4189
|
for (const host of this.loadedHosts) host.disconnect();
|
|
@@ -3222,10 +4218,13 @@ var WorkflowsSt = class {
|
|
|
3222
4218
|
this.loadErrors.delete(path);
|
|
3223
4219
|
this.loadedHosts.add(this.st.wf.host);
|
|
3224
4220
|
this.loadedHosts.add(wf.host);
|
|
4221
|
+
this.recordSpecColor(path, wf);
|
|
3225
4222
|
this.st.wf = wf;
|
|
3226
|
-
this.st.
|
|
3227
|
-
this.st.
|
|
4223
|
+
this.st.applyPersistedHostOverride();
|
|
4224
|
+
this.st.queue.attach(this.st.runHost);
|
|
4225
|
+
this.st.logs.attach(this.st.runHost);
|
|
3228
4226
|
this.currentPath = path;
|
|
4227
|
+
this.st.settings.lastWorkflow = path;
|
|
3229
4228
|
this.st.selIx = 0;
|
|
3230
4229
|
this.st.mode = "nav";
|
|
3231
4230
|
this.st.exec.resetForWorkflow(`${basename(path)}`);
|
|
@@ -3254,9 +4253,28 @@ var WorkflowsSt = class {
|
|
|
3254
4253
|
* classes with an `st` backref; components are stateless views over this.
|
|
3255
4254
|
*/
|
|
3256
4255
|
var TuiSt = class {
|
|
4256
|
+
/** the host runs actually target right now */
|
|
4257
|
+
get runHost() {
|
|
4258
|
+
return this.hostOverride ?? this.wf.host;
|
|
4259
|
+
}
|
|
4260
|
+
setHostOverride(host) {
|
|
4261
|
+
this.hostOverride = host;
|
|
4262
|
+
if (host != null) this.workflows.loadedHosts.add(host);
|
|
4263
|
+
this.queue.attach(this.runHost);
|
|
4264
|
+
this.logs.attach(this.runHost);
|
|
4265
|
+
this.settings.hostOverrideId = host?.data.id ?? null;
|
|
4266
|
+
}
|
|
4267
|
+
/** re-resolve a persisted override id — hosts register as modules import */
|
|
4268
|
+
applyPersistedHostOverride() {
|
|
4269
|
+
const id = this.settings.hostOverrideId;
|
|
4270
|
+
if (id == null || this.hostOverride != null) return;
|
|
4271
|
+
const host = comfyts.hosts.get(id);
|
|
4272
|
+
if (host != null) this.setHostOverride(host);
|
|
4273
|
+
}
|
|
3257
4274
|
constructor(wf, opts = {}) {
|
|
3258
4275
|
this.mode = "nav";
|
|
3259
4276
|
this.selIx = 0;
|
|
4277
|
+
this.hostOverride = null;
|
|
3260
4278
|
this.disposers = [];
|
|
3261
4279
|
this.onExit = () => {};
|
|
3262
4280
|
this.termCols = process.stdout.columns ?? 80;
|
|
@@ -3264,10 +4282,12 @@ var TuiSt = class {
|
|
|
3264
4282
|
this.wf = wf;
|
|
3265
4283
|
makeAutoObservable(this, {
|
|
3266
4284
|
wf: observable.ref,
|
|
4285
|
+
hostOverride: observable.ref,
|
|
3267
4286
|
onExit: false,
|
|
3268
4287
|
editor: false,
|
|
3269
4288
|
picker: false,
|
|
3270
4289
|
loras: false,
|
|
4290
|
+
imagePicker: false,
|
|
3271
4291
|
workflows: false,
|
|
3272
4292
|
tree: false,
|
|
3273
4293
|
drafts: false,
|
|
@@ -3282,6 +4302,7 @@ var TuiSt = class {
|
|
|
3282
4302
|
this.editor = new EditorSt(this);
|
|
3283
4303
|
this.picker = new PickerSt(this);
|
|
3284
4304
|
this.loras = new LorasSt(this);
|
|
4305
|
+
this.imagePicker = new ImagePickerSt(this);
|
|
3285
4306
|
this.workflows = new WorkflowsSt(this, opts.workflowFiles ?? [], opts.currentFile ?? null, opts.bundledFiles, opts.loadErrors);
|
|
3286
4307
|
this.tree = new TreeSt(this);
|
|
3287
4308
|
this.drafts = new DraftsSt(this);
|
|
@@ -3290,8 +4311,13 @@ var TuiSt = class {
|
|
|
3290
4311
|
this.host = new HostSt(this);
|
|
3291
4312
|
this.queue = new QueueSt(this);
|
|
3292
4313
|
this.logs = new LogsSt(this);
|
|
4314
|
+
this.applyPersistedHostOverride();
|
|
3293
4315
|
this.drafts.activateRemembered();
|
|
3294
|
-
if (opts.currentFile != null)
|
|
4316
|
+
if (opts.currentFile != null) {
|
|
4317
|
+
this.tree.expandedFiles.add(opts.currentFile);
|
|
4318
|
+
this.workflows.recordSpecColor(opts.currentFile, wf);
|
|
4319
|
+
this.settings.lastWorkflow = opts.currentFile;
|
|
4320
|
+
}
|
|
3295
4321
|
const onResize = () => {
|
|
3296
4322
|
runInAction(() => {
|
|
3297
4323
|
this.termCols = process.stdout.columns ?? 80;
|
|
@@ -3309,10 +4335,10 @@ var TuiSt = class {
|
|
|
3309
4335
|
get overlayLines() {
|
|
3310
4336
|
return Math.max(8, this.termRows - 12);
|
|
3311
4337
|
}
|
|
3312
|
-
/** left tree panel width: longest row (
|
|
4338
|
+
/** left tree panel width: longest row (depth-indented), clamped */
|
|
3313
4339
|
get treeWidth() {
|
|
3314
|
-
const longest = Math.max(8, ...this.tree.rows.map((r) => r.kind === "workflow" ? r.name.length : r.kind === "draft" ? r.draft.length + 3 : r.label.length));
|
|
3315
|
-
return Math.min(
|
|
4340
|
+
const longest = Math.max(8, ...this.tree.rows.map((r) => r.depth * 2 + (r.kind === "workflow" ? r.name.length : r.kind === "draft" ? r.draft.length + 3 : r.label.length + 2)));
|
|
4341
|
+
return Math.min(34, longest + 7);
|
|
3316
4342
|
}
|
|
3317
4343
|
get entries() {
|
|
3318
4344
|
return this.wf.entries();
|
|
@@ -3334,6 +4360,7 @@ var TuiSt = class {
|
|
|
3334
4360
|
else if (sel.kind === "choice") this.picker.beginChoice();
|
|
3335
4361
|
else if (sel.kind === "size") this.picker.beginSize();
|
|
3336
4362
|
else if (sel.kind === "loras") this.loras.begin();
|
|
4363
|
+
else if (sel.kind === "image") this.imagePicker.begin();
|
|
3337
4364
|
else this.editor.beginInline();
|
|
3338
4365
|
}
|
|
3339
4366
|
/** kind-specific nav keys (documented in the keybar): seed `+`/`-`/`=`/`?` mode, `*` reroll */
|
|
@@ -3354,6 +4381,18 @@ var TuiSt = class {
|
|
|
3354
4381
|
};
|
|
3355
4382
|
//#endregion
|
|
3356
4383
|
//#region src/cli/tui/run-tui.tsx
|
|
4384
|
+
/** the module the last session was on, IF it is still in this run's tree
|
|
4385
|
+
* (settings write: SettingsSt; exported for the headless test) */
|
|
4386
|
+
function rememberedWorkflow(workflowFiles, settingsPath = settingsPathFor(process.cwd())) {
|
|
4387
|
+
try {
|
|
4388
|
+
const raw = JSON.parse(readFileSync(settingsPath, "utf8"));
|
|
4389
|
+
if (raw == null || typeof raw !== "object") return null;
|
|
4390
|
+
const last = raw.lastWorkflow;
|
|
4391
|
+
return typeof last === "string" && workflowFiles.includes(last) ? last : null;
|
|
4392
|
+
} catch {
|
|
4393
|
+
return null;
|
|
4394
|
+
}
|
|
4395
|
+
}
|
|
3357
4396
|
async function runTui(args) {
|
|
3358
4397
|
const target = args.find((a) => !a.startsWith("--"));
|
|
3359
4398
|
process.env[COMFY_TS_TUI_ENV] = "1";
|
|
@@ -3365,17 +4404,19 @@ async function runTui(args) {
|
|
|
3365
4404
|
const canImportBundled = process.versions.bun != null;
|
|
3366
4405
|
const examplesDir = canImportBundled ? bundledExamplesDir() : null;
|
|
3367
4406
|
if (!canImportBundled && target == null) logError("packaged examples skipped: importing .cflow.ts from node_modules needs bun (bunx --bun comfy-ts tui)");
|
|
4407
|
+
const bundledFiles = examplesDir == null ? [] : scanCflowFiles(realpathSync(examplesDir)).sort((a, b) => Number(!a.includes("/rvion/")) - Number(!b.includes("/rvion/")) || a.localeCompare(b));
|
|
3368
4408
|
const discovery = mergeWorkflowSources({
|
|
3369
4409
|
explicitTarget: target != null,
|
|
3370
4410
|
scanned: scannedPlusArg,
|
|
3371
|
-
bundledFiles
|
|
4411
|
+
bundledFiles
|
|
3372
4412
|
});
|
|
3373
4413
|
const workflowFiles = discovery.files;
|
|
3374
4414
|
if (workflowFiles.length === 0) {
|
|
3375
4415
|
console.error(`[comfy-ts tui] no **/*.cflow.ts found under ${abs}`);
|
|
3376
4416
|
return 1;
|
|
3377
4417
|
}
|
|
3378
|
-
const
|
|
4418
|
+
const preferred = !isDir && workflowFiles.includes(abs) ? abs : target == null ? rememberedWorkflow(workflowFiles) : null;
|
|
4419
|
+
const candidates = preferred != null ? [preferred, ...workflowFiles.filter((f) => f !== preferred)] : workflowFiles;
|
|
3379
4420
|
const loadErrors = /* @__PURE__ */ new Map();
|
|
3380
4421
|
let first = null;
|
|
3381
4422
|
let wf = null;
|
|
@@ -3403,11 +4444,13 @@ async function runTui(args) {
|
|
|
3403
4444
|
if (altScreen) process.stdout.write("\x1B[?1049h\x1B[H\x1B[>4;1m");
|
|
3404
4445
|
const uninstallPainter = installProtocolImagePainter(st);
|
|
3405
4446
|
try {
|
|
4447
|
+
if (process.stdin.isTTY === true) process.stdin.setRawMode(true);
|
|
3406
4448
|
const app = render(/* @__PURE__ */ jsx(TuiApp, { st }), { kittyKeyboard: { mode: "auto" } });
|
|
3407
4449
|
st.onExit = () => st.dispose();
|
|
3408
4450
|
await app.waitUntilExit();
|
|
3409
4451
|
st.dispose();
|
|
3410
4452
|
} finally {
|
|
4453
|
+
if (process.stdin.isTTY === true) process.stdin.setRawMode(false);
|
|
3411
4454
|
uninstallPainter();
|
|
3412
4455
|
if (altScreen) process.stdout.write("\x1B[0m\x1B[2J\x1B[H\x1B[>4;0m\x1B[?1049l");
|
|
3413
4456
|
}
|
|
@@ -3416,4 +4459,4 @@ async function runTui(args) {
|
|
|
3416
4459
|
//#endregion
|
|
3417
4460
|
export { runTui };
|
|
3418
4461
|
|
|
3419
|
-
//# sourceMappingURL=run-tui-
|
|
4462
|
+
//# sourceMappingURL=run-tui-BAdizWsO.js.map
|