comfy-ts 1.1.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 +21 -8
- package/dist/cli.js +4 -4552
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +53 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -23
- package/dist/index.d.ts +49 -23
- package/dist/index.js +53 -12
- package/dist/index.js.map +1 -1
- package/dist/{run-tui-DZ22HDHI.js → run-tui-BAdizWsO.js} +722 -130
- 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 +6 -4
- 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} +1 -1
- 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/{05-comfy-cloud.cflow.ts → rvion/05-comfy-cloud.cflow.ts} +2 -2
- package/examples/rvion/06-qwen-image-edit.cflow.ts +89 -0
- package/package.json +4 -1
- 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/StatusBar.tsx +28 -9
- package/src/cli/tui/components/TreePanel.tsx +17 -7
- package/src/cli/tui/components/TuiApp.tsx +47 -5
- package/src/cli/tui/imagePicker/fsListing.ts +6 -4
- package/src/cli/tui/run-tui.tsx +47 -7
- 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/PickerSt.ts +8 -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 +47 -6
- package/src/cli/tui/state/WorkflowsSt.ts +14 -2
- package/src/cli/tui/treeRows.ts +165 -0
- package/src/host/ComfyHost.ts +7 -0
- package/src/runner/ComfyWorkflowLayout.ts +6 -4
- package/src/state.ts +7 -1
- package/src/vars/ComfyVars.ts +25 -4
- package/src/vars/DefinedWorkflow.ts +21 -8
- package/dist/DefinedWorkflow-BYyu5dK9.js +0 -669
- package/dist/DefinedWorkflow-BYyu5dK9.js.map +0 -1
- package/dist/run-tui-DZ22HDHI.js.map +0 -1
|
@@ -1,55 +1,87 @@
|
|
|
1
1
|
import { makeAutoObservable } from 'mobx'
|
|
2
|
-
import {
|
|
2
|
+
import { listDraftsForFile } from 'src/cli/tui/state/DraftsSt.ts'
|
|
3
|
+
import { assignFamilyColors, buildFileRows, familyOf } from 'src/cli/tui/treeRows.ts'
|
|
3
4
|
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
4
5
|
|
|
5
6
|
export type TreeRow =
|
|
6
|
-
| { kind: '
|
|
7
|
+
| { kind: 'dir'; path: string; label: string; depth: number; expanded: boolean }
|
|
7
8
|
| {
|
|
8
9
|
kind: 'workflow'
|
|
9
10
|
file: string
|
|
10
11
|
name: string
|
|
12
|
+
depth: number
|
|
11
13
|
expanded: boolean
|
|
12
14
|
current: boolean
|
|
13
15
|
hasDrafts: boolean
|
|
14
16
|
error: string | null
|
|
17
|
+
/** spec.color of a LOADED module, else the per-family palette color */
|
|
18
|
+
color: string
|
|
15
19
|
}
|
|
16
|
-
| { kind: 'draft'; file: string; draft: string; active: boolean }
|
|
20
|
+
| { kind: 'draft'; file: string; draft: string; active: boolean; depth: number }
|
|
17
21
|
|
|
18
|
-
/** the left `(t)ree`: workflows with their drafts nested
|
|
22
|
+
/** the left `(t)ree`: directory hierarchy + workflows with their drafts nested */
|
|
19
23
|
export class TreeSt {
|
|
20
24
|
constructor(private st: TuiSt) {
|
|
25
|
+
this.collapsedDirs = new Set(st.settings.collapsedDirs)
|
|
21
26
|
makeAutoObservable<TreeSt, 'st'>(this, { st: false })
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
ix: number = 0
|
|
25
30
|
expandedFiles: Set<string> = new Set()
|
|
31
|
+
collapsedDirs: Set<string>
|
|
32
|
+
|
|
33
|
+
/** fold state is hand-tuned: mirror every change into the settings file */
|
|
34
|
+
private persistFolds(): void {
|
|
35
|
+
this.st.settings.collapsedDirs = [...this.collapsedDirs]
|
|
36
|
+
}
|
|
37
|
+
/** `/` filter: the text narrows the tree; `filtering` = keys type into it */
|
|
38
|
+
filter: string = ''
|
|
39
|
+
filtering: boolean = false
|
|
40
|
+
|
|
41
|
+
/** family → color over the FULL file list (stable under filter/fold) */
|
|
42
|
+
private get familyColors(): Map<string, string> {
|
|
43
|
+
return assignFamilyColors(this.st.workflows.files)
|
|
44
|
+
}
|
|
26
45
|
|
|
27
46
|
get rows(): TreeRow[] {
|
|
28
47
|
void this.st.drafts.version // fs-derived: recompute when drafts change
|
|
29
48
|
const w = this.st.workflows
|
|
49
|
+
const fileRows = buildFileRows({
|
|
50
|
+
userFiles: w.files.filter((f) => !w.bundled.has(f)),
|
|
51
|
+
bundledFiles: w.files.filter((f) => w.bundled.has(f)),
|
|
52
|
+
collapsedDirs: this.collapsedDirs,
|
|
53
|
+
filter: this.filter,
|
|
54
|
+
})
|
|
55
|
+
const colors = this.familyColors
|
|
30
56
|
const rows: TreeRow[] = []
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
rows.push({ kind: 'section', label: 'comfy-ts examples' })
|
|
36
|
-
sectionPushed = true
|
|
57
|
+
for (const row of fileRows) {
|
|
58
|
+
if (row.kind === 'dir') {
|
|
59
|
+
rows.push(row)
|
|
60
|
+
continue
|
|
37
61
|
}
|
|
38
|
-
const current = file === w.currentPath
|
|
39
|
-
const expanded = this.expandedFiles.has(file)
|
|
40
|
-
const drafts = listDraftsForFile(file)
|
|
62
|
+
const current = row.file === w.currentPath
|
|
63
|
+
const expanded = this.expandedFiles.has(row.file)
|
|
64
|
+
const drafts = listDraftsForFile(row.file)
|
|
41
65
|
rows.push({
|
|
42
66
|
kind: 'workflow',
|
|
43
|
-
file,
|
|
44
|
-
name:
|
|
67
|
+
file: row.file,
|
|
68
|
+
name: row.name,
|
|
69
|
+
depth: row.depth,
|
|
45
70
|
expanded,
|
|
46
71
|
current,
|
|
47
72
|
hasDrafts: drafts.length > 0,
|
|
48
|
-
error: w.loadErrors.get(file) ?? null,
|
|
73
|
+
error: w.loadErrors.get(row.file) ?? null,
|
|
74
|
+
color: w.specColors.get(row.file) ?? colors.get(familyOf(row.name)) ?? 'white',
|
|
49
75
|
})
|
|
50
76
|
if (!expanded) continue
|
|
51
77
|
for (const draft of drafts) {
|
|
52
|
-
rows.push({
|
|
78
|
+
rows.push({
|
|
79
|
+
kind: 'draft',
|
|
80
|
+
file: row.file,
|
|
81
|
+
draft,
|
|
82
|
+
active: current && draft === this.st.drafts.active,
|
|
83
|
+
depth: row.depth + 1,
|
|
84
|
+
})
|
|
53
85
|
}
|
|
54
86
|
}
|
|
55
87
|
return rows
|
|
@@ -66,7 +98,20 @@ export class TreeSt {
|
|
|
66
98
|
this.st.exec.notice = 'no workflow tree — start the tui in a folder containing **/*.cflow.ts'
|
|
67
99
|
return
|
|
68
100
|
}
|
|
69
|
-
if (w.currentPath != null)
|
|
101
|
+
if (w.currentPath != null) {
|
|
102
|
+
this.expandedFiles.add(w.currentPath)
|
|
103
|
+
// the cursor must land ON the current row: unfold any ancestor dir
|
|
104
|
+
// hiding it (snapshot: the loop deletes while iterating)
|
|
105
|
+
let changed = false
|
|
106
|
+
const collapsed = [...this.collapsedDirs]
|
|
107
|
+
for (const dir of collapsed) {
|
|
108
|
+
if (w.currentPath.startsWith(`${dir}/`)) {
|
|
109
|
+
this.collapsedDirs.delete(dir)
|
|
110
|
+
changed = true
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (changed) this.persistFolds()
|
|
114
|
+
}
|
|
70
115
|
this.st.mode = 'tree'
|
|
71
116
|
const rows = this.rows
|
|
72
117
|
const draftIx = rows.findIndex((r) => r.kind === 'draft' && r.active)
|
|
@@ -76,46 +121,104 @@ export class TreeSt {
|
|
|
76
121
|
|
|
77
122
|
/** esc/t inside the tree, → on a draft row, `v` anywhere: back to the vars list */
|
|
78
123
|
blur(): void {
|
|
124
|
+
this.filtering = false
|
|
79
125
|
this.st.mode = 'nav'
|
|
80
126
|
}
|
|
81
127
|
|
|
82
128
|
move(delta: number): void {
|
|
83
|
-
const
|
|
84
|
-
const len = rows.length
|
|
129
|
+
const len = this.rows.length
|
|
85
130
|
if (len === 0) return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
131
|
+
this.ix = (this.ix + delta + len) % len
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ---- `/` filter ----
|
|
135
|
+
|
|
136
|
+
beginFilter(): void {
|
|
137
|
+
this.filtering = true
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
filterInput(ch: string): void {
|
|
141
|
+
this.filter += ch
|
|
142
|
+
this.clampToSelectable()
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
filterBackspace(): void {
|
|
146
|
+
this.filter = this.filter.slice(0, -1)
|
|
147
|
+
this.clampToSelectable()
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** esc while the filter owns the keys: drop it, stay in the tree */
|
|
151
|
+
clearFilter(): void {
|
|
152
|
+
this.filter = ''
|
|
153
|
+
this.filtering = false
|
|
154
|
+
this.clampToSelectable()
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** filter edits reshape rows: keep the cursor on a workflow row when one exists */
|
|
158
|
+
private clampToSelectable(): void {
|
|
159
|
+
const rows = this.rows
|
|
160
|
+
this.ix = Math.min(this.ix, Math.max(0, rows.length - 1))
|
|
161
|
+
if (rows[this.ix]?.kind !== 'workflow') {
|
|
162
|
+
const first = rows.findIndex((r) => r.kind === 'workflow')
|
|
163
|
+
if (first !== -1) this.ix = first
|
|
91
164
|
}
|
|
92
|
-
this.ix = ix
|
|
93
165
|
}
|
|
94
166
|
|
|
95
|
-
/** →: unfold the workflow under the cursor; on a draft row there is
|
|
96
|
-
* left to unfold, so → continues rightwards into the vars panel */
|
|
167
|
+
/** →: unfold the dir/workflow under the cursor; on a draft row there is
|
|
168
|
+
* nothing left to unfold, so → continues rightwards into the vars panel */
|
|
97
169
|
unfold(): void {
|
|
98
170
|
const row = this.selected
|
|
99
|
-
if (row == null
|
|
100
|
-
if (row.kind === '
|
|
171
|
+
if (row == null) return
|
|
172
|
+
if (row.kind === 'dir') {
|
|
173
|
+
this.collapsedDirs.delete(row.path)
|
|
174
|
+
this.persistFolds()
|
|
175
|
+
} else if (row.kind === 'workflow') this.expandedFiles.add(row.file)
|
|
101
176
|
else this.blur()
|
|
102
177
|
}
|
|
103
178
|
|
|
104
|
-
/** ←: fold
|
|
179
|
+
/** ←: fold under the cursor; on an already-folded row, jump to the parent */
|
|
105
180
|
fold(): void {
|
|
106
181
|
const row = this.selected
|
|
107
|
-
if (row == null
|
|
108
|
-
|
|
182
|
+
if (row == null) return
|
|
183
|
+
if (row.kind === 'dir') {
|
|
184
|
+
this.collapsedDirs.add(row.path)
|
|
185
|
+
this.persistFolds()
|
|
186
|
+
return
|
|
187
|
+
}
|
|
109
188
|
if (row.kind === 'draft') {
|
|
110
189
|
const ix = this.rows.findIndex((r) => r.kind === 'workflow' && r.file === row.file)
|
|
111
190
|
if (ix !== -1) this.ix = ix
|
|
191
|
+
this.expandedFiles.delete(row.file)
|
|
192
|
+
return
|
|
193
|
+
}
|
|
194
|
+
if (row.expanded) {
|
|
195
|
+
this.expandedFiles.delete(row.file)
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
// nothing to fold on the workflow itself: climb to its parent dir row
|
|
199
|
+
for (let ix = this.ix - 1; ix >= 0; ix--) {
|
|
200
|
+
const r = this.rows[ix]
|
|
201
|
+
if (r?.kind === 'dir' && r.depth < row.depth) {
|
|
202
|
+
this.ix = ix
|
|
203
|
+
return
|
|
204
|
+
}
|
|
112
205
|
}
|
|
113
206
|
}
|
|
114
207
|
|
|
115
|
-
/** ⏎: load the workflow (into 'default'), or the exact draft
|
|
208
|
+
/** ⏎: toggle a dir, load the workflow (into 'default'), or load the exact draft */
|
|
116
209
|
async commit(): Promise<void> {
|
|
117
210
|
const row = this.selected
|
|
118
|
-
if (row == null
|
|
211
|
+
if (row == null) return
|
|
212
|
+
if (row.kind === 'dir') {
|
|
213
|
+
if (this.filter !== '') return // folds are ignored under a filter: toggling would be a silent no-op
|
|
214
|
+
if (row.expanded) this.collapsedDirs.add(row.path)
|
|
215
|
+
else this.collapsedDirs.delete(row.path)
|
|
216
|
+
this.persistFolds()
|
|
217
|
+
return
|
|
218
|
+
}
|
|
219
|
+
// picking a result ends the filter session (the narrowed tree did its job)
|
|
220
|
+
this.filter = ''
|
|
221
|
+
this.filtering = false
|
|
119
222
|
if (row.kind === 'workflow') return this.st.workflows.commit(row.file)
|
|
120
223
|
return this.st.workflows.commit(row.file, row.draft)
|
|
121
224
|
}
|
|
@@ -123,7 +226,7 @@ export class TreeSt {
|
|
|
123
226
|
/** n: new draft — current workflow only (a draft snapshots its LIVE var values) */
|
|
124
227
|
promptNewDraft(): void {
|
|
125
228
|
const row = this.selected
|
|
126
|
-
if (row?.kind === '
|
|
229
|
+
if (row?.kind === 'dir') return
|
|
127
230
|
if (row != null && row.file !== this.st.workflows.currentPath) {
|
|
128
231
|
this.st.exec.notice = 'load that workflow first (⏎) — a new draft snapshots its live vars'
|
|
129
232
|
return
|
|
@@ -13,11 +13,13 @@ import { QueueSt } from 'src/cli/tui/state/QueueSt.ts'
|
|
|
13
13
|
import { SettingsSt } from 'src/cli/tui/state/SettingsSt.ts'
|
|
14
14
|
import { TreeSt } from 'src/cli/tui/state/TreeSt.ts'
|
|
15
15
|
import { WorkflowsSt } from 'src/cli/tui/state/WorkflowsSt.ts'
|
|
16
|
+
import type { ComfyHost } from 'src/host/ComfyHost.ts'
|
|
16
17
|
import type { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'
|
|
17
18
|
|
|
18
|
-
// nav = vars list · tree = left workflow panel · host = host stats/actions ·
|
|
19
|
+
// nav = vars list · tree = left workflow panel · host = host stats/actions (`a`) ·
|
|
19
20
|
// preview = `p` settings menu in the preview panel ·
|
|
20
21
|
// edit = inline single-line (numbers + custom prompts) · overlay-* = modal popups
|
|
22
|
+
// (overlay-hosts = the `h` host picker)
|
|
21
23
|
export type TuiMode =
|
|
22
24
|
| 'nav'
|
|
23
25
|
| 'tree'
|
|
@@ -30,6 +32,8 @@ export type TuiMode =
|
|
|
30
32
|
| 'overlay-loras'
|
|
31
33
|
| 'overlay-image'
|
|
32
34
|
| 'overlay-drafts'
|
|
35
|
+
| 'overlay-hosts'
|
|
36
|
+
| 'overlay-copy'
|
|
33
37
|
|
|
34
38
|
/**
|
|
35
39
|
* ROOT of the TUI state tree (one instance per run). Children are service
|
|
@@ -40,6 +44,32 @@ export class TuiSt {
|
|
|
40
44
|
mode: TuiMode = 'nav'
|
|
41
45
|
selIx: number = 0
|
|
42
46
|
|
|
47
|
+
/** `h` host override: when set, EVERY workflow runs/probes against it
|
|
48
|
+
* instead of its defining host (cleared by picking 'workflow default') */
|
|
49
|
+
hostOverride: ComfyHost | null = null
|
|
50
|
+
|
|
51
|
+
/** the host runs actually target right now */
|
|
52
|
+
get runHost(): ComfyHost {
|
|
53
|
+
return this.hostOverride ?? this.wf.host
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setHostOverride(host: ComfyHost | null): void {
|
|
57
|
+
this.hostOverride = host
|
|
58
|
+
// the override host must be disconnected on exit like any loaded one
|
|
59
|
+
if (host != null) this.workflows.loadedHosts.add(host)
|
|
60
|
+
this.queue.attach(this.runHost)
|
|
61
|
+
this.logs.attach(this.runHost)
|
|
62
|
+
this.settings.hostOverrideId = host?.data.id ?? null
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** re-resolve a persisted override id — hosts register as modules import */
|
|
66
|
+
applyPersistedHostOverride(): void {
|
|
67
|
+
const id = this.settings.hostOverrideId
|
|
68
|
+
if (id == null || this.hostOverride != null) return
|
|
69
|
+
const host = comfyts.hosts.get(id)
|
|
70
|
+
if (host != null) this.setHostOverride(host)
|
|
71
|
+
}
|
|
72
|
+
|
|
43
73
|
editor: EditorSt
|
|
44
74
|
picker: PickerSt
|
|
45
75
|
loras: LorasSt
|
|
@@ -74,6 +104,7 @@ export class TuiSt {
|
|
|
74
104
|
// the foreign object; children manage their own observability
|
|
75
105
|
makeAutoObservable(this, {
|
|
76
106
|
wf: observable.ref,
|
|
107
|
+
hostOverride: observable.ref,
|
|
77
108
|
onExit: false,
|
|
78
109
|
editor: false,
|
|
79
110
|
picker: false,
|
|
@@ -108,11 +139,19 @@ export class TuiSt {
|
|
|
108
139
|
this.host = new HostSt(this)
|
|
109
140
|
this.queue = new QueueSt(this)
|
|
110
141
|
this.logs = new LogsSt(this)
|
|
142
|
+
// a remembered `h` override re-applies as soon as its host is registered
|
|
143
|
+
this.applyPersistedHostOverride()
|
|
111
144
|
// the TUI is ALWAYS in a draft from the very first frame: the one this
|
|
112
145
|
// workflow was last in (settings), else 'default'; the current workflow
|
|
113
146
|
// starts unfolded so its drafts are visible in the tree
|
|
114
147
|
this.drafts.activateRemembered()
|
|
115
|
-
if (opts.currentFile != null)
|
|
148
|
+
if (opts.currentFile != null) {
|
|
149
|
+
this.tree.expandedFiles.add(opts.currentFile)
|
|
150
|
+
// the first module loads in run-tui, BEFORE WorkflowsSt.load can record it
|
|
151
|
+
this.workflows.recordSpecColor(opts.currentFile, wf)
|
|
152
|
+
// whatever is on screen is what a no-arg reopen returns to
|
|
153
|
+
this.settings.lastWorkflow = opts.currentFile
|
|
154
|
+
}
|
|
116
155
|
// full-terminal layout: track resizes (SIGWINCH surfaces as stdout resize)
|
|
117
156
|
const onResize = (): void => {
|
|
118
157
|
runInAction(() => {
|
|
@@ -139,15 +178,17 @@ export class TuiSt {
|
|
|
139
178
|
return Math.max(8, this.termRows - 12)
|
|
140
179
|
}
|
|
141
180
|
|
|
142
|
-
/** left tree panel width: longest row (
|
|
181
|
+
/** left tree panel width: longest row (depth-indented), clamped */
|
|
143
182
|
get treeWidth(): number {
|
|
144
183
|
const longest = Math.max(
|
|
145
184
|
8,
|
|
146
|
-
...this.tree.rows.map(
|
|
147
|
-
r
|
|
185
|
+
...this.tree.rows.map(
|
|
186
|
+
(r) =>
|
|
187
|
+
r.depth * 2 +
|
|
188
|
+
(r.kind === 'workflow' ? r.name.length : r.kind === 'draft' ? r.draft.length + 3 : r.label.length + 2),
|
|
148
189
|
),
|
|
149
190
|
)
|
|
150
|
-
return Math.min(
|
|
191
|
+
return Math.min(34, longest + 7)
|
|
151
192
|
}
|
|
152
193
|
|
|
153
194
|
// ---- vars navigation ----
|
|
@@ -4,6 +4,7 @@ import { basename, resolve } from 'pathe'
|
|
|
4
4
|
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
5
5
|
import { findDefinedWorkflow } from 'src/cli/tui/findDefinedWorkflow.ts'
|
|
6
6
|
import type { ComfyHost } from 'src/host/ComfyHost.ts'
|
|
7
|
+
import type { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'
|
|
7
8
|
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
8
9
|
|
|
9
10
|
/** workflow-module data layer: scanned files, module loading, opened-host set (TreeSt is the UI over it) */
|
|
@@ -32,6 +33,13 @@ export class WorkflowsSt {
|
|
|
32
33
|
* cleared by a later successful load; ⏎ on the row retries */
|
|
33
34
|
loadErrors: Map<string, string>
|
|
34
35
|
|
|
36
|
+
/** spec.color of every module seen loading — overrides the tree's family palette */
|
|
37
|
+
specColors: Map<string, string> = new Map()
|
|
38
|
+
|
|
39
|
+
recordSpecColor(path: string, wf: DefinedWorkflow): void {
|
|
40
|
+
if (wf.spec.color != null) this.specColors.set(path, wf.spec.color)
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
/**
|
|
36
44
|
* every host seen across switches. Modules are import-cached, so a
|
|
37
45
|
* switched-away host must stay connected (switching back reuses it) — exit
|
|
@@ -79,10 +87,14 @@ export class WorkflowsSt {
|
|
|
79
87
|
this.loadErrors.delete(path)
|
|
80
88
|
this.loadedHosts.add(this.st.wf.host)
|
|
81
89
|
this.loadedHosts.add(wf.host)
|
|
90
|
+
this.recordSpecColor(path, wf)
|
|
82
91
|
this.st.wf = wf
|
|
83
|
-
|
|
84
|
-
this.st.
|
|
92
|
+
// a module import may have registered the host a persisted override names
|
|
93
|
+
this.st.applyPersistedHostOverride()
|
|
94
|
+
this.st.queue.attach(this.st.runHost)
|
|
95
|
+
this.st.logs.attach(this.st.runHost)
|
|
85
96
|
this.currentPath = path
|
|
97
|
+
this.st.settings.lastWorkflow = path
|
|
86
98
|
this.st.selIx = 0
|
|
87
99
|
this.st.mode = 'nav'
|
|
88
100
|
this.st.exec.resetForWorkflow(`${basename(path)}`)
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { basename, dirname } from 'pathe'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PURE tree-shaping layer under TreeSt (headless-tested): turns the flat
|
|
5
|
+
* discovered file list into hierarchy rows (directory nodes + files), applies
|
|
6
|
+
* the `/` substring filter, and owns the per-family color assignment.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type FileTreeRow =
|
|
10
|
+
| { kind: 'dir'; path: string; label: string; depth: number; expanded: boolean }
|
|
11
|
+
| { kind: 'file'; file: string; name: string; depth: number }
|
|
12
|
+
|
|
13
|
+
/** module display name — also the drafts folder key (DraftsSt delegates here) */
|
|
14
|
+
export function moduleName(file: string): string {
|
|
15
|
+
return basename(file).replace(/\.cflow\.tsx?$/, '')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** the color word: everything before the first `-` (`flux1-i2i` → `flux1`) */
|
|
19
|
+
export function familyOf(name: string): string {
|
|
20
|
+
const dash = name.indexOf('-')
|
|
21
|
+
return dash === -1 ? name : name.slice(0, dash)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** hue-spread so CONSECUTIVE families land on clearly distinct colors */
|
|
25
|
+
export const FAMILY_PALETTE: string[] = [
|
|
26
|
+
'#61afef', // blue
|
|
27
|
+
'#e5c07b', // amber
|
|
28
|
+
'#c678dd', // magenta
|
|
29
|
+
'#98c379', // green
|
|
30
|
+
'#e06c75', // rose
|
|
31
|
+
'#56b6c2', // teal
|
|
32
|
+
'#d19a66', // orange
|
|
33
|
+
'#a5b4fc', // lavender
|
|
34
|
+
'#a5e075', // lime
|
|
35
|
+
'#f28fad', // pink
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
/** family → color, palette cycled in first-appearance order over the FULL
|
|
39
|
+
* (unfiltered) file list — stable while filtering/folding */
|
|
40
|
+
export function assignFamilyColors(files: string[]): Map<string, string> {
|
|
41
|
+
const colors = new Map<string, string>()
|
|
42
|
+
for (const file of files) {
|
|
43
|
+
const family = familyOf(moduleName(file))
|
|
44
|
+
if (colors.has(family)) continue
|
|
45
|
+
colors.set(family, FAMILY_PALETTE[colors.size % FAMILY_PALETTE.length] ?? '#61afef')
|
|
46
|
+
}
|
|
47
|
+
return colors
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type DirNode = {
|
|
51
|
+
/** deepest real directory path of this node (unique row key) */
|
|
52
|
+
path: string
|
|
53
|
+
label: string
|
|
54
|
+
files: string[]
|
|
55
|
+
dirs: Map<string, DirNode>
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function commonDir(files: string[]): string {
|
|
59
|
+
const first = files[0]
|
|
60
|
+
if (first == null) return ''
|
|
61
|
+
let prefix = dirname(first).split('/')
|
|
62
|
+
for (const f of files.slice(1)) {
|
|
63
|
+
const segs = dirname(f).split('/')
|
|
64
|
+
let i = 0
|
|
65
|
+
while (i < prefix.length && i < segs.length && prefix[i] === segs[i]) i++
|
|
66
|
+
prefix = prefix.slice(0, i)
|
|
67
|
+
}
|
|
68
|
+
return prefix.join('/')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function insert(root: DirNode, rootDir: string, file: string): void {
|
|
72
|
+
const rel = dirname(file).slice(rootDir.length).replace(/^\//, '')
|
|
73
|
+
const segs = rel === '' ? [] : rel.split('/')
|
|
74
|
+
let node = root
|
|
75
|
+
for (const seg of segs) {
|
|
76
|
+
let child = node.dirs.get(seg)
|
|
77
|
+
if (child == null) {
|
|
78
|
+
child = { path: `${node.path}/${seg}`, label: seg, files: [], dirs: new Map() }
|
|
79
|
+
node.dirs.set(seg, child)
|
|
80
|
+
}
|
|
81
|
+
node = child
|
|
82
|
+
}
|
|
83
|
+
node.files.push(file)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** a dir holding NOTHING but one subdir shows as one `a/b` row */
|
|
87
|
+
function mergeChains(node: DirNode): void {
|
|
88
|
+
// snapshot: the loop rewrites node.dirs entries while iterating
|
|
89
|
+
const entries = [...node.dirs]
|
|
90
|
+
for (const [key, child] of entries) {
|
|
91
|
+
mergeChains(child)
|
|
92
|
+
if (child.files.length === 0 && child.dirs.size === 1) {
|
|
93
|
+
const only = [...child.dirs.values()][0]!
|
|
94
|
+
const label = `${child.label}/${only.label}`
|
|
95
|
+
node.dirs.delete(key)
|
|
96
|
+
// re-key by the MERGED label: keying by only.label could clobber a
|
|
97
|
+
// real sibling dir of the same name (segments never contain '/')
|
|
98
|
+
node.dirs.set(label, { ...only, label })
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function matches(file: string, rootDir: string, filter: string): boolean {
|
|
104
|
+
if (filter === '') return true
|
|
105
|
+
// dir path + module name, NOT the raw filename: '.cflow.ts' matching
|
|
106
|
+
// everything would make the filter useless for 'ts', 'flow', '.'
|
|
107
|
+
const haystack = `${dirname(file).slice(rootDir.length)}/${moduleName(file)}`.toLowerCase()
|
|
108
|
+
return haystack.includes(filter.toLowerCase())
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function emit(p: {
|
|
112
|
+
node: DirNode
|
|
113
|
+
depth: number
|
|
114
|
+
rootDir: string
|
|
115
|
+
collapsedDirs: Set<string>
|
|
116
|
+
filter: string
|
|
117
|
+
out: FileTreeRow[]
|
|
118
|
+
}): void {
|
|
119
|
+
for (const file of p.node.files) {
|
|
120
|
+
if (!matches(file, p.rootDir, p.filter)) continue
|
|
121
|
+
p.out.push({ kind: 'file', file, name: moduleName(file), depth: p.depth })
|
|
122
|
+
}
|
|
123
|
+
for (const dir of [...p.node.dirs.values()].sort((a, b) => a.label.localeCompare(b.label))) {
|
|
124
|
+
const kept: FileTreeRow[] = []
|
|
125
|
+
// a collapsed dir still ignores its fold while a filter narrows the tree
|
|
126
|
+
const expanded = p.filter !== '' || !p.collapsedDirs.has(dir.path)
|
|
127
|
+
emit({ ...p, node: dir, depth: p.depth + 1, out: kept })
|
|
128
|
+
if (p.filter !== '' && kept.length === 0) continue // prune filtered-empty dirs
|
|
129
|
+
p.out.push({ kind: 'dir', path: dir.path, label: dir.label, depth: p.depth, expanded })
|
|
130
|
+
if (expanded) p.out.push(...kept)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* hierarchy rows over the discovered files: user files under their common
|
|
136
|
+
* root, packaged examples LAST under one foldable 'comfy-ts examples' node.
|
|
137
|
+
*/
|
|
138
|
+
export function buildFileRows(p: {
|
|
139
|
+
userFiles: string[]
|
|
140
|
+
bundledFiles: string[]
|
|
141
|
+
collapsedDirs: Set<string>
|
|
142
|
+
filter: string
|
|
143
|
+
}): FileTreeRow[] {
|
|
144
|
+
const out: FileTreeRow[] = []
|
|
145
|
+
if (p.userFiles.length > 0) {
|
|
146
|
+
const rootDir = commonDir(p.userFiles)
|
|
147
|
+
const root: DirNode = { path: rootDir, label: '', files: [], dirs: new Map() }
|
|
148
|
+
for (const f of p.userFiles) insert(root, rootDir, f)
|
|
149
|
+
mergeChains(root)
|
|
150
|
+
emit({ node: root, depth: 0, rootDir, collapsedDirs: p.collapsedDirs, filter: p.filter, out })
|
|
151
|
+
}
|
|
152
|
+
if (p.bundledFiles.length > 0) {
|
|
153
|
+
const rootDir = commonDir(p.bundledFiles)
|
|
154
|
+
const root: DirNode = { path: rootDir, label: 'comfy-ts examples', files: [], dirs: new Map() }
|
|
155
|
+
for (const f of p.bundledFiles) insert(root, rootDir, f)
|
|
156
|
+
mergeChains(root)
|
|
157
|
+
const kept: FileTreeRow[] = []
|
|
158
|
+
const expanded = p.filter !== '' || !p.collapsedDirs.has(rootDir)
|
|
159
|
+
emit({ node: root, depth: 1, rootDir, collapsedDirs: p.collapsedDirs, filter: p.filter, out: kept })
|
|
160
|
+
if (p.filter !== '' && kept.length === 0) return out
|
|
161
|
+
out.push({ kind: 'dir', path: rootDir, label: root.label, depth: 0, expanded })
|
|
162
|
+
if (expanded) out.push(...kept)
|
|
163
|
+
}
|
|
164
|
+
return out
|
|
165
|
+
}
|
package/src/host/ComfyHost.ts
CHANGED
|
@@ -720,7 +720,14 @@ export class ComfyHost<ID extends string = string> {
|
|
|
720
720
|
/** handy to keep around */
|
|
721
721
|
status: ComfyStatusData['status'] | null = null
|
|
722
722
|
|
|
723
|
+
/** last time ANY ws message arrived — proof-of-life for the TUI probe: a
|
|
724
|
+
* busy single-threaded ComfyUI stalls NEW connects while established
|
|
725
|
+
* sockets keep streaming (a half-open socket receives nothing, so this
|
|
726
|
+
* never revives one) */
|
|
727
|
+
lastWsMessageAt: number | null = null
|
|
728
|
+
|
|
723
729
|
onMessage(e: MessageEvent): void {
|
|
730
|
+
this.lastWsMessageAt = Date.now()
|
|
724
731
|
if (this.data.onWsMessageAny) this.data.onWsMessageAny(e)
|
|
725
732
|
if (e.data instanceof ArrayBuffer) {
|
|
726
733
|
const frame = parseBinaryWsFrame(e.data)
|
|
@@ -15,9 +15,9 @@ import type { ComfyWorkflow } from 'src/runner/ComfyWorkflow.ts'
|
|
|
15
15
|
export function comfyWorkflowAutoLayout(
|
|
16
16
|
this: ComfyWorkflow,
|
|
17
17
|
p?: {
|
|
18
|
-
/** @default:
|
|
18
|
+
/** @default: 40 */
|
|
19
19
|
node_vsep?: number
|
|
20
|
-
/** @default:
|
|
20
|
+
/** @default: 100 */
|
|
21
21
|
node_hsep?: number
|
|
22
22
|
/** @default false */
|
|
23
23
|
forceLeft?: boolean
|
|
@@ -70,8 +70,10 @@ export function comfyWorkflowAutoLayout(
|
|
|
70
70
|
else cols[at] = [node]
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
// real ComfyUI nodes render wider than the 200px layout estimate, so the
|
|
74
|
+
// horizontal gap is generous to keep pasted graphs readable
|
|
75
|
+
const HSEP = p?.node_hsep ?? 100
|
|
76
|
+
const VSEP = p?.node_vsep ?? 40
|
|
75
77
|
// cols.reverse()
|
|
76
78
|
let colX = 0
|
|
77
79
|
let maxY = 0
|
package/src/state.ts
CHANGED
|
@@ -6,6 +6,12 @@ import { parseHostBase, renderHttpBase } from 'src/host/hostUrl.ts'
|
|
|
6
6
|
import { ComfyRegistry } from 'src/manager/ComfyRegistry.ts'
|
|
7
7
|
import { type AbsolutePath, asAbsolutePath, type RelativePath } from 'src/types/index.ts'
|
|
8
8
|
|
|
9
|
+
/** the ONE settings-file location rule — run-tui reads it BEFORE any module
|
|
10
|
+
* import creates the comfyts global, so the path logic cannot live on the instance only */
|
|
11
|
+
export function settingsPathFor(root: string): AbsolutePath {
|
|
12
|
+
return asAbsolutePath(join(root, '.comfy-ts', 'settings.json'))
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
/** singleton */
|
|
10
16
|
export class ComfyTS {
|
|
11
17
|
version = pkgJson.version
|
|
@@ -99,7 +105,7 @@ export class ComfyTS {
|
|
|
99
105
|
|
|
100
106
|
/** local TUI settings (preview mode, last draft per workflow) — gitignored */
|
|
101
107
|
get settingsPath(): AbsolutePath {
|
|
102
|
-
return
|
|
108
|
+
return settingsPathFor(this.rootPath)
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
resolveFromHosts(relativePath: string): AbsolutePath {
|