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.
Files changed (147) hide show
  1. package/README.md +60 -11
  2. package/dist/cli.js +4 -4439
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.cjs +445 -172
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +7439 -340
  7. package/dist/index.d.ts +7457 -358
  8. package/dist/index.js +444 -172
  9. package/dist/index.js.map +1 -1
  10. package/dist/{run-tui-BFhba_oG.js → run-tui-BAdizWsO.js} +1244 -201
  11. package/dist/run-tui-BAdizWsO.js.map +1 -0
  12. package/dist/state-BYbxDgfr.js +5258 -0
  13. package/dist/state-BYbxDgfr.js.map +1 -0
  14. package/examples/README.md +32 -0
  15. package/examples/comfy-cloud/ace-step-t2a.cflow.ts +79 -0
  16. package/examples/comfy-cloud/anima-t2i.cflow.ts +57 -0
  17. package/examples/comfy-cloud/boogu-i2i.cflow.ts +76 -0
  18. package/examples/comfy-cloud/capybara-i2i.cflow.ts +85 -0
  19. package/examples/comfy-cloud/capybara-i2v.cflow.ts +90 -0
  20. package/examples/comfy-cloud/capybara-t2i.cflow.ts +67 -0
  21. package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +79 -0
  22. package/examples/comfy-cloud/chroma-t2i.cflow.ts +62 -0
  23. package/examples/comfy-cloud/cloudHost.ts +41 -0
  24. package/examples/comfy-cloud/ernie-t2i.cflow.ts +59 -0
  25. package/examples/comfy-cloud/firered-i2i.cflow.ts +74 -0
  26. package/examples/comfy-cloud/flux1-i2i.cflow.ts +76 -0
  27. package/examples/comfy-cloud/flux1-t2i.cflow.ts +63 -0
  28. package/examples/comfy-cloud/flux2-i2i.cflow.ts +80 -0
  29. package/examples/comfy-cloud/flux2-t2i.cflow.ts +57 -0
  30. package/examples/comfy-cloud/hidream-i2i.cflow.ts +89 -0
  31. package/examples/comfy-cloud/hidream-t2i.cflow.ts +65 -0
  32. package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +93 -0
  33. package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +74 -0
  34. package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +80 -0
  35. package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +95 -0
  36. package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +60 -0
  37. package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +78 -0
  38. package/examples/comfy-cloud/krea2-t2i.cflow.ts +59 -0
  39. package/examples/comfy-cloud/lens-t2i.cflow.ts +62 -0
  40. package/examples/comfy-cloud/longcat-i2i.cflow.ts +74 -0
  41. package/examples/comfy-cloud/longcat-t2i.cflow.ts +65 -0
  42. package/examples/comfy-cloud/ltxv-i2v.cflow.ts +92 -0
  43. package/examples/comfy-cloud/ltxv-t2v.cflow.ts +78 -0
  44. package/examples/comfy-cloud/newbie-t2i.cflow.ts +67 -0
  45. package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +86 -0
  46. package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +62 -0
  47. package/examples/comfy-cloud/ovis-t2i.cflow.ts +56 -0
  48. package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +63 -0
  49. package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +69 -0
  50. package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +55 -0
  51. package/examples/comfy-cloud/sd35-t2i.cflow.ts +48 -0
  52. package/examples/comfy-cloud/sdk.d.ts +445 -57
  53. package/examples/comfy-cloud/sdxl-t2i.cflow.ts +69 -0
  54. package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +53 -0
  55. package/examples/comfy-cloud/svd-i2v.cflow.ts +75 -0
  56. package/examples/comfy-cloud/wan21-i2v.cflow.ts +83 -0
  57. package/examples/comfy-cloud/wan21-t2v.cflow.ts +64 -0
  58. package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +69 -0
  59. package/examples/comfy-cloud/wan22-i2v.cflow.ts +107 -0
  60. package/examples/comfy-cloud/wan22-t2v.cflow.ts +98 -0
  61. package/examples/comfy-cloud/z-image-t2i.cflow.ts +62 -0
  62. package/examples/images/README.md +18 -0
  63. package/examples/images/bear_1024x1024.jpg +0 -0
  64. package/examples/images/deer_768x1344.jpg +0 -0
  65. package/examples/images/dog_512x512.jpg +0 -0
  66. package/examples/images/lioness_768x768.jpg +0 -0
  67. package/examples/images/pug_200x300.jpg +0 -0
  68. package/examples/images/walrus_1344x768.jpg +0 -0
  69. package/examples/{01-txt2img.cflow.ts → rvion/01-txt2img.cflow.ts} +1 -1
  70. package/examples/{02-img2img-upload.cflow.ts → rvion/02-img2img-upload.cflow.ts} +7 -18
  71. package/examples/{03-export-workflow-json.cflow.ts → rvion/03-export-workflow-json.cflow.ts} +1 -1
  72. package/examples/{04-krea2-turbo-t2i.cflow.ts → rvion/04-krea2-turbo-t2i.cflow.ts} +2 -2
  73. package/examples/rvion/05-comfy-cloud.cflow.ts +51 -0
  74. package/examples/rvion/06-qwen-image-edit.cflow.ts +89 -0
  75. package/guide-for-agents.md +7 -1
  76. package/package.json +18 -4
  77. package/src/cli/tui/components/CopyOverlay.tsx +25 -0
  78. package/src/cli/tui/components/Header.tsx +9 -4
  79. package/src/cli/tui/components/HostPanel.tsx +3 -2
  80. package/src/cli/tui/components/HostsOverlay.tsx +33 -0
  81. package/src/cli/tui/components/PreviewPanel.tsx +9 -8
  82. package/src/cli/tui/components/StatusBar.tsx +39 -9
  83. package/src/cli/tui/components/TreePanel.tsx +17 -7
  84. package/src/cli/tui/components/TuiApp.tsx +65 -5
  85. package/src/cli/tui/discoverWorkflows.ts +7 -41
  86. package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +72 -0
  87. package/src/cli/tui/imagePicker/ImagePickerSt.ts +288 -0
  88. package/src/cli/tui/imagePicker/fsListing.ts +48 -0
  89. package/src/cli/tui/imagePicker/pickerPrefs.ts +78 -0
  90. package/src/cli/tui/run-tui.tsx +49 -8
  91. package/src/cli/tui/state/DraftsSt.ts +3 -2
  92. package/src/cli/tui/state/ExecSt.ts +108 -12
  93. package/src/cli/tui/state/HostSt.ts +94 -10
  94. package/src/cli/tui/state/LorasSt.ts +14 -36
  95. package/src/cli/tui/state/PickerSt.ts +8 -2
  96. package/src/cli/tui/state/PreviewSt.ts +28 -2
  97. package/src/cli/tui/state/QueueSt.ts +2 -2
  98. package/src/cli/tui/state/SettingsSt.ts +25 -7
  99. package/src/cli/tui/state/TreeSt.ts +139 -36
  100. package/src/cli/tui/state/TuiSt.ts +53 -6
  101. package/src/cli/tui/state/WorkflowsSt.ts +14 -2
  102. package/src/cli/tui/treeRows.ts +165 -0
  103. package/src/exampleAssets.ts +56 -0
  104. package/src/graph/ComfyNode.ts +4 -1
  105. package/src/host/ComfyHost.ts +7 -0
  106. package/src/index.ts +7 -0
  107. package/src/manager/ComfyRegistry.ts +37 -9
  108. package/src/manager/generated/KnownComfyCustomNodeName.ts +23852 -1926
  109. package/src/manager/generated/KnownComfyPluginTitle.ts +6854 -236
  110. package/src/manager/generated/KnownComfyPluginURL.ts +3425 -111
  111. package/src/manager/generated/KnownModel_Base.ts +23 -7
  112. package/src/manager/generated/KnownModel_FileName.ts +421 -0
  113. package/src/manager/generated/KnownModel_Name.ts +421 -0
  114. package/src/manager/generated/KnownModel_SavePath.ts +34 -8
  115. package/src/manager/generated/KnownModel_Type.ts +18 -14
  116. package/src/manager/json/alter-list.json +221 -221
  117. package/src/manager/json/custom-node-list.json +61020 -21946
  118. package/src/manager/json/extension-node-map.json +81077 -31176
  119. package/src/manager/json/github-stats.json +29321 -12601
  120. package/src/manager/json/model-list.json +5935 -4997
  121. package/src/manager/loaders/parseReport.ts +55 -0
  122. package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +15 -49
  123. package/src/manager/loaders/step2_custom-node-list-loader.ts +38 -83
  124. package/src/manager/loaders/step3_extension-node-map-loader.ts +36 -142
  125. package/src/manager/loaders/step4_model-list-loader.ts +25 -36
  126. package/src/manager/loaders/step5_alter-list-loader.ts +29 -0
  127. package/src/manager/loaders/step6_github-stats-loader.ts +23 -0
  128. package/src/manager/script-update-manager.bun.ts +9 -1
  129. package/src/manager/types/ComfyManagerAlterInfo.ts +13 -0
  130. package/src/manager/types/ComfyManagerFileModelInfo.ts +7 -3
  131. package/src/manager/types/ComfyManagerFilePluginContent.ts +6 -9
  132. package/src/manager/types/ComfyManagerFilePluginList.ts +3 -3
  133. package/src/manager/types/ComfyManagerGithubStats.ts +9 -0
  134. package/src/manager/types/ComfyManagerPluginContentMetadata.ts +2 -3
  135. package/src/manager/types/ComfyManagerPluginInfo.ts +48 -34
  136. package/src/runner/ComfyWorkflowLayout.ts +6 -4
  137. package/src/sdk-generator/ComfySchema.ts +14 -1
  138. package/src/sdk-generator/comfyui-sdk-codegen.ts +15 -0
  139. package/src/sdk-generator/inputWidgetKind.ts +17 -0
  140. package/src/state.ts +7 -1
  141. package/src/vars/ComfyVars.ts +106 -5
  142. package/src/vars/DefinedWorkflow.ts +28 -10
  143. package/dist/DefinedWorkflow-O3ynII3Y.js +0 -598
  144. package/dist/DefinedWorkflow-O3ynII3Y.js.map +0 -1
  145. package/dist/run-tui-BFhba_oG.js.map +0 -1
  146. package/examples/05-comfy-cloud.cflow.ts +0 -67
  147. package/src/utils/tryExtracting.ts +0 -41
@@ -16,6 +16,9 @@ export class PickerSt {
16
16
  ix: number = 0
17
17
  /** size overlay only: the filter failed to parse as WxH on commit */
18
18
  invalid: boolean = false
19
+ /** size overlay only: the linked image var's live dims, read ONCE per open
20
+ * (fs read — never inside the options computed, which runs per keystroke) */
21
+ imageSizeRow: string | null = null
19
22
 
20
23
  // kind-narrowing casts sanctioned (agent/coding.md), `kind` is the tag
21
24
  private get choiceVar(): ChoiceVar<string> | null {
@@ -37,6 +40,7 @@ export class PickerSt {
37
40
  const sv = this.sizeVar
38
41
  if (sv != null) {
39
42
  const labels = sv.presets.map((p) => `${p.width}×${p.height} ${p.label}`)
43
+ if (this.imageSizeRow != null) labels.unshift(this.imageSizeRow)
40
44
  if (this.filter === '') return labels
41
45
  return labels.filter((l) => fuzzyMatch(this.filter, l))
42
46
  }
@@ -58,8 +62,10 @@ export class PickerSt {
58
62
  this.st.mode = 'overlay-size'
59
63
  this.filter = ''
60
64
  this.invalid = false
61
- const ix = sv.presets.findIndex((p) => p.width === sv.value.width && p.height === sv.value.height)
62
- this.ix = ix === -1 ? 0 : ix
65
+ const img = sv.imageSize()
66
+ this.imageSizeRow = img == null ? null : `${img.width}×${img.height} size of image '${img.name}'`
67
+ const presetIx = sv.presets.findIndex((p) => p.width === sv.value.width && p.height === sv.value.height)
68
+ this.ix = presetIx === -1 ? 0 : presetIx + (this.imageSizeRow != null ? 1 : 0)
63
69
  }
64
70
 
65
71
  move(delta: number): void {
@@ -15,6 +15,15 @@ export function protocolCapable(): boolean {
15
15
 
16
16
  type MenuRow = { key: 'panel' | 'renderer' | 'during-run'; label: string; value: string }
17
17
 
18
+ /** what an overlay (loras / image picker) wants the panel to show: real bytes
19
+ * (native renderer), an ansi render (pixel), or a placeholder note */
20
+ export type OverlayImage = {
21
+ bytes: Uint8Array | null
22
+ ansi: string | null
23
+ name: string | null
24
+ note: string | null
25
+ }
26
+
18
27
  /** small-latent corner: fraction of the panel each dimension takes */
19
28
  const CORNER_FRACTION = 0.38
20
29
  /** pixel 'latent small': the sharp-composited thumb takes this fraction of the panel */
@@ -61,6 +70,23 @@ export class PreviewSt {
61
70
  get menuOpen(): boolean {
62
71
  return this.st.mode === 'preview'
63
72
  }
73
+
74
+ // ---- overlay slot: ONE code path for every overlay that previews into the
75
+ // panel (loras + image picker write it; the panel and the protocol painter
76
+ // read it whenever an overlay mode owns the vars area) ----
77
+ overlay: OverlayImage | null = null
78
+
79
+ get overlayActive(): boolean {
80
+ return this.st.mode === 'overlay-loras' || this.st.mode === 'overlay-image'
81
+ }
82
+
83
+ setOverlayImage(p: OverlayImage): void {
84
+ this.overlay = p
85
+ }
86
+
87
+ clearOverlayImage(): void {
88
+ this.overlay = null
89
+ }
64
90
  /** running + latents wanted + sampling well underway + none arrived = server
65
91
  * sends none. The ≥20% gate keeps healthy runs from red-flashing: the first
66
92
  * progress tick lands a beat before the first preview frame */
@@ -157,7 +183,7 @@ export class PreviewSt {
157
183
  /** what the painter should show RIGHT NOW (native renderer only; mirrors the panel's source) */
158
184
  get protocolImage(): Uint8Array | null {
159
185
  if (!this.useNative || !this.show || this.menuOpen) return null
160
- if (this.st.mode === 'overlay-loras') return this.st.loras.previewBytes
186
+ if (this.overlayActive) return this.overlay?.bytes ?? null
161
187
  if (this.st.exec.running) {
162
188
  if (this.duringRun === 'latent') return this.latentBytes ?? this.outputBytes
163
189
  // latent-small keeps the OUTPUT big (corner carries the latent) — last-output too
@@ -169,7 +195,7 @@ export class PreviewSt {
169
195
  /** small latent painted over the panel's top-right corner (native + 'latent small' only) */
170
196
  get protocolImageCorner(): Uint8Array | null {
171
197
  if (!this.useNative || !this.show || this.menuOpen) return null
172
- if (this.st.mode === 'overlay-loras') return null
198
+ if (this.overlayActive) return null
173
199
  if (this.st.exec.running && this.duringRun === 'latent-small') return this.latentBytes
174
200
  return null
175
201
  }
@@ -33,7 +33,7 @@ export class QueueSt {
33
33
 
34
34
  async clearPending(): Promise<void> {
35
35
  try {
36
- await this.st.wf.host.clearQueue()
36
+ await this.st.runHost.clearQueue()
37
37
  runInAction(() => {
38
38
  this.st.exec.notice = 'pending queue cleared'
39
39
  })
@@ -46,7 +46,7 @@ export class QueueSt {
46
46
 
47
47
  async interrupt(): Promise<void> {
48
48
  try {
49
- await this.st.wf.host.interrupt()
49
+ await this.st.runHost.interrupt()
50
50
  runInAction(() => {
51
51
  this.st.exec.notice = 'interrupt requested'
52
52
  })
@@ -41,17 +41,26 @@ export class SettingsSt {
41
41
  makeAutoObservable<SettingsSt, 'st'>(this, { st: false })
42
42
  this.st.disposers.push(
43
43
  reaction(
44
- () =>
45
- JSON.stringify({
46
- previewPanel: this.previewPanel,
47
- previewRenderer: this.previewRenderer,
48
- previewDuringRun: this.previewDuringRun,
49
- lastDraft: this.lastDraft,
50
- }),
44
+ () => this.snapshotJson(),
51
45
  (json) => this.write(json),
52
46
  { delay: 300 },
53
47
  ),
54
48
  )
49
+ // the delayed reaction can be cancelled by dispose with a write pending —
50
+ // and lastWorkflow's whole point is exit state: flush on the way out
51
+ this.st.disposers.push(() => this.write(this.snapshotJson()))
52
+ }
53
+
54
+ private snapshotJson(): string {
55
+ return JSON.stringify({
56
+ previewPanel: this.previewPanel,
57
+ previewRenderer: this.previewRenderer,
58
+ previewDuringRun: this.previewDuringRun,
59
+ lastDraft: this.lastDraft,
60
+ lastWorkflow: this.lastWorkflow,
61
+ hostOverrideId: this.hostOverrideId,
62
+ collapsedDirs: this.collapsedDirs,
63
+ })
55
64
  }
56
65
 
57
66
  previewPanel: boolean = true
@@ -59,6 +68,12 @@ export class SettingsSt {
59
68
  previewDuringRun: PreviewDuringRun = 'latent'
60
69
  /** module basename → the draft that was active last time (reopened on load) */
61
70
  lastDraft: Record<string, string> = {}
71
+ /** path of the last OPEN workflow module — a no-arg `tui` reopens it (his ask 2026-07-30) */
72
+ lastWorkflow: string | null = null
73
+ /** the `h` host override, by host id (re-resolved once that host registers) */
74
+ hostOverrideId: string | null = null
75
+ /** folded tree dirs (hand-tuned state persists, like every other surface) */
76
+ collapsedDirs: string[] = []
62
77
 
63
78
  rememberDraft(moduleKey: string, draft: string): void {
64
79
  this.lastDraft[moduleKey] = draft
@@ -81,6 +96,9 @@ export class SettingsSt {
81
96
  this.previewDuringRun = preview.previewDuringRun
82
97
  if (o.lastDraft != null && typeof o.lastDraft === 'object')
83
98
  this.lastDraft = { ...(o.lastDraft as Record<string, string>) }
99
+ if (typeof o.lastWorkflow === 'string') this.lastWorkflow = o.lastWorkflow
100
+ if (typeof o.hostOverrideId === 'string') this.hostOverrideId = o.hostOverrideId
101
+ if (Array.isArray(o.collapsedDirs)) this.collapsedDirs = o.collapsedDirs.filter((d) => typeof d === 'string')
84
102
  } catch {
85
103
  // corrupt settings must never block the TUI — start from defaults
86
104
  }
@@ -1,55 +1,87 @@
1
1
  import { makeAutoObservable } from 'mobx'
2
- import { draftKeyForFile, listDraftsForFile } from 'src/cli/tui/state/DraftsSt.ts'
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: 'section'; label: string } // dim group header (bundled examples), never selectable
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 under them */
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
- let sectionPushed = false
32
- for (const file of w.files) {
33
- // bundled examples come LAST in files: one section header before the first
34
- if (!sectionPushed && w.bundled.has(file)) {
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: draftKeyForFile(file),
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({ kind: 'draft', file, draft, active: current && draft === this.st.drafts.active })
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) this.expandedFiles.add(w.currentPath)
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 rows = this.rows
84
- const len = rows.length
129
+ const len = this.rows.length
85
130
  if (len === 0) return
86
- let ix = this.ix
87
- // hop over section headers (never selectable); bounded: wraps at most once
88
- for (let step = 0; step < len; step++) {
89
- ix = (ix + delta + len) % len
90
- if (rows[ix]?.kind !== 'section') break
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 nothing
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 || row.kind === 'section') return
100
- if (row.kind === 'workflow') this.expandedFiles.add(row.file)
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 the workflow under the cursor; on a draft row, jump to (and fold) its parent */
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 || row.kind === 'section') return
108
- this.expandedFiles.delete(row.file)
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 under the cursor */
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 || row.kind === 'section') return
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 === 'section') return
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
@@ -1,5 +1,6 @@
1
1
  import { makeAutoObservable, observable, runInAction } from 'mobx'
2
2
  import type { SeedVar, ToggleVar, AnyVar } from 'src/vars/ComfyVars.ts'
3
+ import { ImagePickerSt } from 'src/cli/tui/imagePicker/ImagePickerSt.ts'
3
4
  import { DraftsSt } from 'src/cli/tui/state/DraftsSt.ts'
4
5
  import { EditorSt } from 'src/cli/tui/state/EditorSt.ts'
5
6
  import { ExecSt } from 'src/cli/tui/state/ExecSt.ts'
@@ -12,11 +13,13 @@ import { QueueSt } from 'src/cli/tui/state/QueueSt.ts'
12
13
  import { SettingsSt } from 'src/cli/tui/state/SettingsSt.ts'
13
14
  import { TreeSt } from 'src/cli/tui/state/TreeSt.ts'
14
15
  import { WorkflowsSt } from 'src/cli/tui/state/WorkflowsSt.ts'
16
+ import type { ComfyHost } from 'src/host/ComfyHost.ts'
15
17
  import type { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'
16
18
 
17
- // nav = vars list · tree = left workflow panel · host = host stats/actions ·
19
+ // nav = vars list · tree = left workflow panel · host = host stats/actions (`a`) ·
18
20
  // preview = `p` settings menu in the preview panel ·
19
21
  // edit = inline single-line (numbers + custom prompts) · overlay-* = modal popups
22
+ // (overlay-hosts = the `h` host picker)
20
23
  export type TuiMode =
21
24
  | 'nav'
22
25
  | 'tree'
@@ -27,7 +30,10 @@ export type TuiMode =
27
30
  | 'overlay-choice'
28
31
  | 'overlay-size'
29
32
  | 'overlay-loras'
33
+ | 'overlay-image'
30
34
  | 'overlay-drafts'
35
+ | 'overlay-hosts'
36
+ | 'overlay-copy'
31
37
 
32
38
  /**
33
39
  * ROOT of the TUI state tree (one instance per run). Children are service
@@ -38,9 +44,36 @@ export class TuiSt {
38
44
  mode: TuiMode = 'nav'
39
45
  selIx: number = 0
40
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
+
41
73
  editor: EditorSt
42
74
  picker: PickerSt
43
75
  loras: LorasSt
76
+ imagePicker: ImagePickerSt
44
77
  workflows: WorkflowsSt
45
78
  tree: TreeSt
46
79
  drafts: DraftsSt
@@ -71,10 +104,12 @@ export class TuiSt {
71
104
  // the foreign object; children manage their own observability
72
105
  makeAutoObservable(this, {
73
106
  wf: observable.ref,
107
+ hostOverride: observable.ref,
74
108
  onExit: false,
75
109
  editor: false,
76
110
  picker: false,
77
111
  loras: false,
112
+ imagePicker: false,
78
113
  workflows: false,
79
114
  tree: false,
80
115
  drafts: false,
@@ -89,6 +124,7 @@ export class TuiSt {
89
124
  this.editor = new EditorSt(this)
90
125
  this.picker = new PickerSt(this)
91
126
  this.loras = new LorasSt(this)
127
+ this.imagePicker = new ImagePickerSt(this)
92
128
  this.workflows = new WorkflowsSt(
93
129
  this,
94
130
  opts.workflowFiles ?? [],
@@ -103,11 +139,19 @@ export class TuiSt {
103
139
  this.host = new HostSt(this)
104
140
  this.queue = new QueueSt(this)
105
141
  this.logs = new LogsSt(this)
142
+ // a remembered `h` override re-applies as soon as its host is registered
143
+ this.applyPersistedHostOverride()
106
144
  // the TUI is ALWAYS in a draft from the very first frame: the one this
107
145
  // workflow was last in (settings), else 'default'; the current workflow
108
146
  // starts unfolded so its drafts are visible in the tree
109
147
  this.drafts.activateRemembered()
110
- if (opts.currentFile != null) this.tree.expandedFiles.add(opts.currentFile)
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
+ }
111
155
  // full-terminal layout: track resizes (SIGWINCH surfaces as stdout resize)
112
156
  const onResize = (): void => {
113
157
  runInAction(() => {
@@ -134,15 +178,17 @@ export class TuiSt {
134
178
  return Math.max(8, this.termRows - 12)
135
179
  }
136
180
 
137
- /** left tree panel width: longest row (workflow or indented draft), clamped */
181
+ /** left tree panel width: longest row (depth-indented), clamped */
138
182
  get treeWidth(): number {
139
183
  const longest = Math.max(
140
184
  8,
141
- ...this.tree.rows.map((r) =>
142
- r.kind === 'workflow' ? r.name.length : r.kind === 'draft' ? r.draft.length + 3 : r.label.length,
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),
143
189
  ),
144
190
  )
145
- return Math.min(32, longest + 7)
191
+ return Math.min(34, longest + 7)
146
192
  }
147
193
 
148
194
  // ---- vars navigation ----
@@ -172,6 +218,7 @@ export class TuiSt {
172
218
  else if (sel.kind === 'choice') this.picker.beginChoice()
173
219
  else if (sel.kind === 'size') this.picker.beginSize()
174
220
  else if (sel.kind === 'loras') this.loras.begin()
221
+ else if (sel.kind === 'image') this.imagePicker.begin()
175
222
  else this.editor.beginInline() // int / float / seed: type the number
176
223
  }
177
224
 
@@ -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
- this.st.queue.attach(wf.host)
84
- this.st.logs.attach(wf.host)
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)}`)