comfy-ts 1.1.0 → 1.3.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 +61 -8
- package/dist/{DefinedWorkflow-BYyu5dK9.js → DefinedWorkflow-gpknV-5f.js} +52 -35
- package/dist/DefinedWorkflow-gpknV-5f.js.map +1 -0
- package/dist/DraftsSt-DmA0jWGl.js +434 -0
- package/dist/DraftsSt-DmA0jWGl.js.map +1 -0
- package/dist/cli.js +17 -4555
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +184 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +54 -23
- package/dist/index.d.ts +36 -5
- package/dist/index.js +184 -32
- package/dist/index.js.map +1 -1
- package/dist/run-serve-Bn6yIJB0.js +638 -0
- package/dist/run-serve-Bn6yIJB0.js.map +1 -0
- package/dist/{run-tui-DZ22HDHI.js → run-tui-BtjaOXRh.js} +791 -395
- package/dist/run-tui-BtjaOXRh.js.map +1 -0
- package/dist/state-DKCPy105.js +4690 -0
- package/dist/state-DKCPy105.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 +6 -2
- package/src/cli/comfy-ts-cli.ts +15 -5
- package/src/cli/serve/ServeApp.ts +378 -0
- package/src/cli/serve/applyVarPayload.ts +119 -0
- package/src/cli/serve/describeVar.ts +74 -0
- package/src/cli/serve/run-serve.ts +169 -0
- 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 +29 -9
- package/src/cli/tui/components/TreePanel.tsx +33 -9
- package/src/cli/tui/components/TuiApp.tsx +54 -7
- package/src/cli/tui/components/VarsPanel.tsx +67 -34
- package/src/cli/tui/imageClipboard.ts +39 -0
- package/src/cli/tui/imagePicker/fsListing.ts +6 -4
- package/src/cli/tui/listWindow.ts +36 -0
- 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 +156 -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 +164 -36
- package/src/cli/tui/state/TuiSt.ts +81 -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/litegraph/convertFlowToLiteGraphJSON.ts +11 -7
- package/src/runner/ComfyExecution.ts +21 -4
- package/src/runner/ComfyWorkflowLayout.ts +6 -4
- package/src/runner/outputPath.ts +75 -0
- package/src/sdk-generator/inputWidgetKind.ts +50 -11
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +14 -7
- package/src/state.ts +7 -1
- package/src/vars/ComfyVars.ts +33 -4
- package/src/vars/DefinedWorkflow.ts +21 -8
- package/dist/DefinedWorkflow-BYyu5dK9.js.map +0 -1
- package/dist/run-tui-DZ22HDHI.js.map +0 -1
|
@@ -1,55 +1,88 @@
|
|
|
1
1
|
import { makeAutoObservable } from 'mobx'
|
|
2
|
-
import {
|
|
2
|
+
import { listDraftsForFile } from 'src/cli/tui/state/DraftsSt.ts'
|
|
3
|
+
import { listWindow, type ListWindow } from 'src/cli/tui/listWindow.ts'
|
|
4
|
+
import { assignFamilyColors, buildFileRows, familyOf } from 'src/cli/tui/treeRows.ts'
|
|
3
5
|
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
4
6
|
|
|
5
7
|
export type TreeRow =
|
|
6
|
-
| { kind: '
|
|
8
|
+
| { kind: 'dir'; path: string; label: string; depth: number; expanded: boolean }
|
|
7
9
|
| {
|
|
8
10
|
kind: 'workflow'
|
|
9
11
|
file: string
|
|
10
12
|
name: string
|
|
13
|
+
depth: number
|
|
11
14
|
expanded: boolean
|
|
12
15
|
current: boolean
|
|
13
16
|
hasDrafts: boolean
|
|
14
17
|
error: string | null
|
|
18
|
+
/** spec.color of a LOADED module, else the per-family palette color */
|
|
19
|
+
color: string
|
|
15
20
|
}
|
|
16
|
-
| { kind: 'draft'; file: string; draft: string; active: boolean }
|
|
21
|
+
| { kind: 'draft'; file: string; draft: string; active: boolean; depth: number }
|
|
17
22
|
|
|
18
|
-
/** the left `(t)ree`: workflows with their drafts nested
|
|
23
|
+
/** the left `(t)ree`: directory hierarchy + workflows with their drafts nested */
|
|
19
24
|
export class TreeSt {
|
|
20
25
|
constructor(private st: TuiSt) {
|
|
26
|
+
this.collapsedDirs = new Set(st.settings.collapsedDirs)
|
|
21
27
|
makeAutoObservable<TreeSt, 'st'>(this, { st: false })
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
ix: number = 0
|
|
25
31
|
expandedFiles: Set<string> = new Set()
|
|
32
|
+
collapsedDirs: Set<string>
|
|
33
|
+
|
|
34
|
+
/** fold state is hand-tuned: mirror every change into the settings file */
|
|
35
|
+
private persistFolds(): void {
|
|
36
|
+
this.st.settings.collapsedDirs = [...this.collapsedDirs]
|
|
37
|
+
}
|
|
38
|
+
/** `/` filter: the text narrows the tree; `filtering` = keys type into it */
|
|
39
|
+
filter: string = ''
|
|
40
|
+
filtering: boolean = false
|
|
41
|
+
|
|
42
|
+
/** family → color over the FULL file list (stable under filter/fold) */
|
|
43
|
+
private get familyColors(): Map<string, string> {
|
|
44
|
+
return assignFamilyColors(this.st.workflows.files)
|
|
45
|
+
}
|
|
26
46
|
|
|
27
47
|
get rows(): TreeRow[] {
|
|
28
48
|
void this.st.drafts.version // fs-derived: recompute when drafts change
|
|
29
49
|
const w = this.st.workflows
|
|
50
|
+
const fileRows = buildFileRows({
|
|
51
|
+
userFiles: w.files.filter((f) => !w.bundled.has(f)),
|
|
52
|
+
bundledFiles: w.files.filter((f) => w.bundled.has(f)),
|
|
53
|
+
collapsedDirs: this.collapsedDirs,
|
|
54
|
+
filter: this.filter,
|
|
55
|
+
})
|
|
56
|
+
const colors = this.familyColors
|
|
30
57
|
const rows: TreeRow[] = []
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
rows.push({ kind: 'section', label: 'comfy-ts examples' })
|
|
36
|
-
sectionPushed = true
|
|
58
|
+
for (const row of fileRows) {
|
|
59
|
+
if (row.kind === 'dir') {
|
|
60
|
+
rows.push(row)
|
|
61
|
+
continue
|
|
37
62
|
}
|
|
38
|
-
const current = file === w.currentPath
|
|
39
|
-
const expanded = this.expandedFiles.has(file)
|
|
40
|
-
const drafts = listDraftsForFile(file)
|
|
63
|
+
const current = row.file === w.currentPath
|
|
64
|
+
const expanded = this.expandedFiles.has(row.file)
|
|
65
|
+
const drafts = listDraftsForFile(row.file)
|
|
41
66
|
rows.push({
|
|
42
67
|
kind: 'workflow',
|
|
43
|
-
file,
|
|
44
|
-
name:
|
|
68
|
+
file: row.file,
|
|
69
|
+
name: row.name,
|
|
70
|
+
depth: row.depth,
|
|
45
71
|
expanded,
|
|
46
72
|
current,
|
|
47
73
|
hasDrafts: drafts.length > 0,
|
|
48
|
-
error: w.loadErrors.get(file) ?? null,
|
|
74
|
+
error: w.loadErrors.get(row.file) ?? null,
|
|
75
|
+
color: w.specColors.get(row.file) ?? colors.get(familyOf(row.name)) ?? 'white',
|
|
49
76
|
})
|
|
50
77
|
if (!expanded) continue
|
|
51
78
|
for (const draft of drafts) {
|
|
52
|
-
rows.push({
|
|
79
|
+
rows.push({
|
|
80
|
+
kind: 'draft',
|
|
81
|
+
file: row.file,
|
|
82
|
+
draft,
|
|
83
|
+
active: current && draft === this.st.drafts.active,
|
|
84
|
+
depth: row.depth + 1,
|
|
85
|
+
})
|
|
53
86
|
}
|
|
54
87
|
}
|
|
55
88
|
return rows
|
|
@@ -66,7 +99,20 @@ export class TreeSt {
|
|
|
66
99
|
this.st.exec.notice = 'no workflow tree — start the tui in a folder containing **/*.cflow.ts'
|
|
67
100
|
return
|
|
68
101
|
}
|
|
69
|
-
if (w.currentPath != null)
|
|
102
|
+
if (w.currentPath != null) {
|
|
103
|
+
this.expandedFiles.add(w.currentPath)
|
|
104
|
+
// the cursor must land ON the current row: unfold any ancestor dir
|
|
105
|
+
// hiding it (snapshot: the loop deletes while iterating)
|
|
106
|
+
let changed = false
|
|
107
|
+
const collapsed = [...this.collapsedDirs]
|
|
108
|
+
for (const dir of collapsed) {
|
|
109
|
+
if (w.currentPath.startsWith(`${dir}/`)) {
|
|
110
|
+
this.collapsedDirs.delete(dir)
|
|
111
|
+
changed = true
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (changed) this.persistFolds()
|
|
115
|
+
}
|
|
70
116
|
this.st.mode = 'tree'
|
|
71
117
|
const rows = this.rows
|
|
72
118
|
const draftIx = rows.findIndex((r) => r.kind === 'draft' && r.active)
|
|
@@ -74,48 +120,130 @@ export class TreeSt {
|
|
|
74
120
|
this.ix = ix === -1 ? 0 : ix
|
|
75
121
|
}
|
|
76
122
|
|
|
123
|
+
// ---- viewport (his small-terminal overflow repro 2026-07-31) ----
|
|
124
|
+
|
|
125
|
+
/** measured height of the tree panel Box (TreePanel measureElement); 0 = not measured yet */
|
|
126
|
+
viewH: number = 0
|
|
127
|
+
setViewH(h: number): void {
|
|
128
|
+
this.viewH = h
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** rows available for tree content: measured panel height minus the panel's
|
|
132
|
+
* own chrome (2 border rows, the filter line when visible, the loading
|
|
133
|
+
* line). Pre-measure fallback: termRows minus the header+keybar estimate —
|
|
134
|
+
* one frame only, the measurement replaces it. */
|
|
135
|
+
get viewBudget(): number {
|
|
136
|
+
const h = this.viewH > 0 ? this.viewH : Math.max(5, this.st.termRows - 5)
|
|
137
|
+
const filterLine = this.filtering || this.filter !== '' ? 1 : 0
|
|
138
|
+
const loadingLine = this.st.workflows.loading ? 1 : 0
|
|
139
|
+
return Math.max(1, h - 2 - filterLine - loadingLine)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** the visible slice, selection always inside, markers within the budget */
|
|
143
|
+
get window(): ListWindow {
|
|
144
|
+
return listWindow({ count: this.rows.length, selected: this.ix, budget: this.viewBudget })
|
|
145
|
+
}
|
|
146
|
+
|
|
77
147
|
/** esc/t inside the tree, → on a draft row, `v` anywhere: back to the vars list */
|
|
78
148
|
blur(): void {
|
|
149
|
+
this.filtering = false
|
|
79
150
|
this.st.mode = 'nav'
|
|
80
151
|
}
|
|
81
152
|
|
|
82
153
|
move(delta: number): void {
|
|
83
|
-
const
|
|
84
|
-
const len = rows.length
|
|
154
|
+
const len = this.rows.length
|
|
85
155
|
if (len === 0) return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
156
|
+
this.ix = (this.ix + delta + len) % len
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ---- `/` filter ----
|
|
160
|
+
|
|
161
|
+
beginFilter(): void {
|
|
162
|
+
this.filtering = true
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
filterInput(ch: string): void {
|
|
166
|
+
this.filter += ch
|
|
167
|
+
this.clampToSelectable()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
filterBackspace(): void {
|
|
171
|
+
this.filter = this.filter.slice(0, -1)
|
|
172
|
+
this.clampToSelectable()
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** esc while the filter owns the keys: drop it, stay in the tree */
|
|
176
|
+
clearFilter(): void {
|
|
177
|
+
this.filter = ''
|
|
178
|
+
this.filtering = false
|
|
179
|
+
this.clampToSelectable()
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** filter edits reshape rows: keep the cursor on a workflow row when one exists */
|
|
183
|
+
private clampToSelectable(): void {
|
|
184
|
+
const rows = this.rows
|
|
185
|
+
this.ix = Math.min(this.ix, Math.max(0, rows.length - 1))
|
|
186
|
+
if (rows[this.ix]?.kind !== 'workflow') {
|
|
187
|
+
const first = rows.findIndex((r) => r.kind === 'workflow')
|
|
188
|
+
if (first !== -1) this.ix = first
|
|
91
189
|
}
|
|
92
|
-
this.ix = ix
|
|
93
190
|
}
|
|
94
191
|
|
|
95
|
-
/** →: unfold the workflow under the cursor; on a draft row there is
|
|
96
|
-
* left to unfold, so → continues rightwards into the vars panel */
|
|
192
|
+
/** →: unfold the dir/workflow under the cursor; on a draft row there is
|
|
193
|
+
* nothing left to unfold, so → continues rightwards into the vars panel */
|
|
97
194
|
unfold(): void {
|
|
98
195
|
const row = this.selected
|
|
99
|
-
if (row == null
|
|
100
|
-
if (row.kind === '
|
|
196
|
+
if (row == null) return
|
|
197
|
+
if (row.kind === 'dir') {
|
|
198
|
+
this.collapsedDirs.delete(row.path)
|
|
199
|
+
this.persistFolds()
|
|
200
|
+
} else if (row.kind === 'workflow') this.expandedFiles.add(row.file)
|
|
101
201
|
else this.blur()
|
|
102
202
|
}
|
|
103
203
|
|
|
104
|
-
/** ←: fold
|
|
204
|
+
/** ←: fold under the cursor; on an already-folded row, jump to the parent */
|
|
105
205
|
fold(): void {
|
|
106
206
|
const row = this.selected
|
|
107
|
-
if (row == null
|
|
108
|
-
|
|
207
|
+
if (row == null) return
|
|
208
|
+
if (row.kind === 'dir') {
|
|
209
|
+
this.collapsedDirs.add(row.path)
|
|
210
|
+
this.persistFolds()
|
|
211
|
+
return
|
|
212
|
+
}
|
|
109
213
|
if (row.kind === 'draft') {
|
|
110
214
|
const ix = this.rows.findIndex((r) => r.kind === 'workflow' && r.file === row.file)
|
|
111
215
|
if (ix !== -1) this.ix = ix
|
|
216
|
+
this.expandedFiles.delete(row.file)
|
|
217
|
+
return
|
|
218
|
+
}
|
|
219
|
+
if (row.expanded) {
|
|
220
|
+
this.expandedFiles.delete(row.file)
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
// nothing to fold on the workflow itself: climb to its parent dir row
|
|
224
|
+
for (let ix = this.ix - 1; ix >= 0; ix--) {
|
|
225
|
+
const r = this.rows[ix]
|
|
226
|
+
if (r?.kind === 'dir' && r.depth < row.depth) {
|
|
227
|
+
this.ix = ix
|
|
228
|
+
return
|
|
229
|
+
}
|
|
112
230
|
}
|
|
113
231
|
}
|
|
114
232
|
|
|
115
|
-
/** ⏎: load the workflow (into 'default'), or the exact draft
|
|
233
|
+
/** ⏎: toggle a dir, load the workflow (into 'default'), or load the exact draft */
|
|
116
234
|
async commit(): Promise<void> {
|
|
117
235
|
const row = this.selected
|
|
118
|
-
if (row == null
|
|
236
|
+
if (row == null) return
|
|
237
|
+
if (row.kind === 'dir') {
|
|
238
|
+
if (this.filter !== '') return // folds are ignored under a filter: toggling would be a silent no-op
|
|
239
|
+
if (row.expanded) this.collapsedDirs.add(row.path)
|
|
240
|
+
else this.collapsedDirs.delete(row.path)
|
|
241
|
+
this.persistFolds()
|
|
242
|
+
return
|
|
243
|
+
}
|
|
244
|
+
// picking a result ends the filter session (the narrowed tree did its job)
|
|
245
|
+
this.filter = ''
|
|
246
|
+
this.filtering = false
|
|
119
247
|
if (row.kind === 'workflow') return this.st.workflows.commit(row.file)
|
|
120
248
|
return this.st.workflows.commit(row.file, row.draft)
|
|
121
249
|
}
|
|
@@ -123,7 +251,7 @@ export class TreeSt {
|
|
|
123
251
|
/** n: new draft — current workflow only (a draft snapshots its LIVE var values) */
|
|
124
252
|
promptNewDraft(): void {
|
|
125
253
|
const row = this.selected
|
|
126
|
-
if (row?.kind === '
|
|
254
|
+
if (row?.kind === 'dir') return
|
|
127
255
|
if (row != null && row.file !== this.st.workflows.currentPath) {
|
|
128
256
|
this.st.exec.notice = 'load that workflow first (⏎) — a new draft snapshots its live vars'
|
|
129
257
|
return
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { makeAutoObservable, observable, runInAction } from 'mobx'
|
|
2
|
+
import { listWindow, type ListWindow } from 'src/cli/tui/listWindow.ts'
|
|
2
3
|
import type { SeedVar, ToggleVar, AnyVar } from 'src/vars/ComfyVars.ts'
|
|
3
4
|
import { ImagePickerSt } from 'src/cli/tui/imagePicker/ImagePickerSt.ts'
|
|
4
5
|
import { DraftsSt } from 'src/cli/tui/state/DraftsSt.ts'
|
|
@@ -13,11 +14,13 @@ import { QueueSt } from 'src/cli/tui/state/QueueSt.ts'
|
|
|
13
14
|
import { SettingsSt } from 'src/cli/tui/state/SettingsSt.ts'
|
|
14
15
|
import { TreeSt } from 'src/cli/tui/state/TreeSt.ts'
|
|
15
16
|
import { WorkflowsSt } from 'src/cli/tui/state/WorkflowsSt.ts'
|
|
17
|
+
import type { ComfyHost } from 'src/host/ComfyHost.ts'
|
|
16
18
|
import type { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'
|
|
17
19
|
|
|
18
|
-
// nav = vars list · tree = left workflow panel · host = host stats/actions ·
|
|
20
|
+
// nav = vars list · tree = left workflow panel · host = host stats/actions (`a`) ·
|
|
19
21
|
// preview = `p` settings menu in the preview panel ·
|
|
20
22
|
// edit = inline single-line (numbers + custom prompts) · overlay-* = modal popups
|
|
23
|
+
// (overlay-hosts = the `h` host picker)
|
|
21
24
|
export type TuiMode =
|
|
22
25
|
| 'nav'
|
|
23
26
|
| 'tree'
|
|
@@ -30,6 +33,8 @@ export type TuiMode =
|
|
|
30
33
|
| 'overlay-loras'
|
|
31
34
|
| 'overlay-image'
|
|
32
35
|
| 'overlay-drafts'
|
|
36
|
+
| 'overlay-hosts'
|
|
37
|
+
| 'overlay-copy'
|
|
33
38
|
|
|
34
39
|
/**
|
|
35
40
|
* ROOT of the TUI state tree (one instance per run). Children are service
|
|
@@ -40,6 +45,32 @@ export class TuiSt {
|
|
|
40
45
|
mode: TuiMode = 'nav'
|
|
41
46
|
selIx: number = 0
|
|
42
47
|
|
|
48
|
+
/** `h` host override: when set, EVERY workflow runs/probes against it
|
|
49
|
+
* instead of its defining host (cleared by picking 'workflow default') */
|
|
50
|
+
hostOverride: ComfyHost | null = null
|
|
51
|
+
|
|
52
|
+
/** the host runs actually target right now */
|
|
53
|
+
get runHost(): ComfyHost {
|
|
54
|
+
return this.hostOverride ?? this.wf.host
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
setHostOverride(host: ComfyHost | null): void {
|
|
58
|
+
this.hostOverride = host
|
|
59
|
+
// the override host must be disconnected on exit like any loaded one
|
|
60
|
+
if (host != null) this.workflows.loadedHosts.add(host)
|
|
61
|
+
this.queue.attach(this.runHost)
|
|
62
|
+
this.logs.attach(this.runHost)
|
|
63
|
+
this.settings.hostOverrideId = host?.data.id ?? null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** re-resolve a persisted override id — hosts register as modules import */
|
|
67
|
+
applyPersistedHostOverride(): void {
|
|
68
|
+
const id = this.settings.hostOverrideId
|
|
69
|
+
if (id == null || this.hostOverride != null) return
|
|
70
|
+
const host = comfyts.hosts.get(id)
|
|
71
|
+
if (host != null) this.setHostOverride(host)
|
|
72
|
+
}
|
|
73
|
+
|
|
43
74
|
editor: EditorSt
|
|
44
75
|
picker: PickerSt
|
|
45
76
|
loras: LorasSt
|
|
@@ -74,6 +105,7 @@ export class TuiSt {
|
|
|
74
105
|
// the foreign object; children manage their own observability
|
|
75
106
|
makeAutoObservable(this, {
|
|
76
107
|
wf: observable.ref,
|
|
108
|
+
hostOverride: observable.ref,
|
|
77
109
|
onExit: false,
|
|
78
110
|
editor: false,
|
|
79
111
|
picker: false,
|
|
@@ -108,11 +140,19 @@ export class TuiSt {
|
|
|
108
140
|
this.host = new HostSt(this)
|
|
109
141
|
this.queue = new QueueSt(this)
|
|
110
142
|
this.logs = new LogsSt(this)
|
|
143
|
+
// a remembered `h` override re-applies as soon as its host is registered
|
|
144
|
+
this.applyPersistedHostOverride()
|
|
111
145
|
// the TUI is ALWAYS in a draft from the very first frame: the one this
|
|
112
146
|
// workflow was last in (settings), else 'default'; the current workflow
|
|
113
147
|
// starts unfolded so its drafts are visible in the tree
|
|
114
148
|
this.drafts.activateRemembered()
|
|
115
|
-
if (opts.currentFile != null)
|
|
149
|
+
if (opts.currentFile != null) {
|
|
150
|
+
this.tree.expandedFiles.add(opts.currentFile)
|
|
151
|
+
// the first module loads in run-tui, BEFORE WorkflowsSt.load can record it
|
|
152
|
+
this.workflows.recordSpecColor(opts.currentFile, wf)
|
|
153
|
+
// whatever is on screen is what a no-arg reopen returns to
|
|
154
|
+
this.settings.lastWorkflow = opts.currentFile
|
|
155
|
+
}
|
|
116
156
|
// full-terminal layout: track resizes (SIGWINCH surfaces as stdout resize)
|
|
117
157
|
const onResize = (): void => {
|
|
118
158
|
runInAction(() => {
|
|
@@ -139,15 +179,17 @@ export class TuiSt {
|
|
|
139
179
|
return Math.max(8, this.termRows - 12)
|
|
140
180
|
}
|
|
141
181
|
|
|
142
|
-
/** left tree panel width: longest row (
|
|
182
|
+
/** left tree panel width: longest row (depth-indented), clamped */
|
|
143
183
|
get treeWidth(): number {
|
|
144
184
|
const longest = Math.max(
|
|
145
185
|
8,
|
|
146
|
-
...this.tree.rows.map(
|
|
147
|
-
r
|
|
186
|
+
...this.tree.rows.map(
|
|
187
|
+
(r) =>
|
|
188
|
+
r.depth * 2 +
|
|
189
|
+
(r.kind === 'workflow' ? r.name.length : r.kind === 'draft' ? r.draft.length + 3 : r.label.length + 2),
|
|
148
190
|
),
|
|
149
191
|
)
|
|
150
|
-
return Math.min(
|
|
192
|
+
return Math.min(34, longest + 7)
|
|
151
193
|
}
|
|
152
194
|
|
|
153
195
|
// ---- vars navigation ----
|
|
@@ -165,6 +207,39 @@ export class TuiSt {
|
|
|
165
207
|
this.selIx = (this.selIx + delta + len) % len
|
|
166
208
|
}
|
|
167
209
|
|
|
210
|
+
// ---- vars viewport (reviewer follow-up 2026-07-31: the fixed-height
|
|
211
|
+
// frame clips instead of overflowing, so the vars list must window like
|
|
212
|
+
// the tree — measured height, never chrome arithmetic) ----
|
|
213
|
+
|
|
214
|
+
/** measured height of the vars panel Box (VarsPanel measureElement); 0 = not measured yet */
|
|
215
|
+
varsViewH: number = 0
|
|
216
|
+
setVarsViewH(h: number): void {
|
|
217
|
+
this.varsViewH = h
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** row budget: measured height minus the 2 border rows; pre-measure fallback estimate */
|
|
221
|
+
get varsBudget(): number {
|
|
222
|
+
const h = this.varsViewH > 0 ? this.varsViewH : Math.max(5, this.termRows - 5)
|
|
223
|
+
return Math.max(1, h - 2)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
get varsWindow(): ListWindow {
|
|
227
|
+
return listWindow({ count: this.entries.length, selected: this.selIx, budget: this.varsBudget })
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* while the list cannot fit, NON-selected rows collapse to one truncated
|
|
232
|
+
* line (prompt values wrap tall) — rows above the selection then cost one
|
|
233
|
+
* line each, so the selection can never be pushed off-screen. Reads only
|
|
234
|
+
* entry count + measured height, never its own rendering: no oscillation.
|
|
235
|
+
*/
|
|
236
|
+
get varsCompact(): boolean {
|
|
237
|
+
const w = this.varsWindow
|
|
238
|
+
if (w.moreAbove || w.moreBelow) return true
|
|
239
|
+
const h = this.varsViewH > 0 ? this.varsViewH : Math.max(5, this.termRows - 5)
|
|
240
|
+
return this.entries.length + 2 > h
|
|
241
|
+
}
|
|
242
|
+
|
|
168
243
|
// kind-discriminated narrowing casts below are sanctioned (agent/coding.md):
|
|
169
244
|
// ComfyVar<T> value-invariance blocks a clean union, `kind` is the tag.
|
|
170
245
|
|
|
@@ -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)
|