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
@@ -2,7 +2,8 @@ import { Box, Text } from 'ink'
2
2
  import { observer } from 'mobx-react-lite'
3
3
  import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
4
4
 
5
- /** persistent left panel: workflows with their drafts nested; `t` (or ← from vars) focuses it */
5
+ /** persistent left panel: directory hierarchy + workflows with their drafts
6
+ * nested; `t` (or ← from vars) focuses it, `/` filters it */
6
7
  export const TreePanel = observer((p: { st: TuiSt }) => {
7
8
  const s = p.st
8
9
  const tree = s.tree
@@ -22,12 +23,20 @@ export const TreePanel = observer((p: { st: TuiSt }) => {
22
23
  (t)ree
23
24
  </Text>
24
25
  </Box>
26
+ {(tree.filtering || tree.filter !== '') && (
27
+ <Text color="yellow" wrap="truncate">
28
+ /{tree.filter}
29
+ {tree.filtering ? '▌' : ''}
30
+ </Text>
31
+ )}
25
32
  {tree.rows.map((row, ix) => {
26
33
  const sel = focused && ix === tree.ix
27
- if (row.kind === 'section') {
34
+ const indent = ' '.repeat(row.depth * 2)
35
+ if (row.kind === 'dir') {
28
36
  return (
29
- <Text key={`section·${row.label}`} color="gray" dimColor wrap="truncate">
30
- ─ {row.label}
37
+ <Text key={`dir·${row.path}`} inverse={sel} color="gray" bold wrap="truncate">
38
+ {indent}
39
+ {row.expanded ? '▾' : '▸'} {row.label}
31
40
  </Text>
32
41
  )
33
42
  }
@@ -38,9 +47,11 @@ export const TreePanel = observer((p: { st: TuiSt }) => {
38
47
  <Text
39
48
  key={row.file}
40
49
  inverse={sel}
41
- color={row.error != null ? 'red' : row.current ? 'green' : undefined}
50
+ bold={row.current}
51
+ color={row.error != null ? 'red' : row.color}
42
52
  wrap="truncate"
43
53
  >
54
+ {indent}
44
55
  {arrow}
45
56
  {marker} {row.name}
46
57
  </Text>
@@ -53,8 +64,7 @@ export const TreePanel = observer((p: { st: TuiSt }) => {
53
64
  color={row.active ? 'cyan' : 'gray'}
54
65
  wrap="truncate"
55
66
  >
56
- {' '}
57
- {row.active ? '●' : '·'} {row.draft}
67
+ {indent} {row.active ? '●' : '·'} {row.draft}
58
68
  </Text>
59
69
  )
60
70
  })}
@@ -1,14 +1,17 @@
1
1
  import { Box, Text, useApp, useInput, useStdin } from 'ink'
2
2
  import { observer } from 'mobx-react-lite'
3
3
  import { basename } from 'pathe'
4
+ import { CopyOverlay } from 'src/cli/tui/components/CopyOverlay.tsx'
4
5
  import { DraftsOverlay } from 'src/cli/tui/components/DraftsOverlay.tsx'
5
6
  import { Header } from 'src/cli/tui/components/Header.tsx'
6
7
  import { HostPanel } from 'src/cli/tui/components/HostPanel.tsx'
8
+ import { HostsOverlay } from 'src/cli/tui/components/HostsOverlay.tsx'
7
9
  import { LorasOverlay } from 'src/cli/tui/components/LorasOverlay.tsx'
8
10
  import { ChoiceOverlay, SizeOverlay } from 'src/cli/tui/components/PickerOverlays.tsx'
9
11
  import { PreviewPanel } from 'src/cli/tui/components/PreviewPanel.tsx'
10
12
  import { PromptOverlay } from 'src/cli/tui/components/PromptOverlay.tsx'
11
13
  import { KeyBar, ProgressLine } from 'src/cli/tui/components/StatusBar.tsx'
14
+ import { ImagePickerOverlay } from 'src/cli/tui/imagePicker/ImagePickerOverlay.tsx'
12
15
  import { LogsPanel } from 'src/cli/tui/components/LogsPanel.tsx'
13
16
  import { TextOverlay } from 'src/cli/tui/components/TextOverlay.tsx'
14
17
  import { TreePanel } from 'src/cli/tui/components/TreePanel.tsx'
@@ -97,9 +100,38 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
97
100
  if (input && !key.ctrl && !key.meta) return lo.filterInput(input)
98
101
  return
99
102
  }
103
+ if (s.mode === 'overlay-image') {
104
+ const ip = s.imagePicker
105
+ if (key.escape) return ip.cancel()
106
+ if (key.tab || input === '\t') return ip.cyclePane()
107
+ if (key.ctrl && input === 'f') return ip.toggleFavorite()
108
+ if (key.return) return ip.commit()
109
+ if (key.upArrow) return ip.move(-1)
110
+ if (key.downArrow) return ip.move(1)
111
+ if (key.leftArrow) return ip.goParent()
112
+ if (key.rightArrow) return ip.enter()
113
+ if ((key.meta && (key.backspace || key.delete)) || (key.ctrl && input === 'w')) return ip.filterDeleteWord()
114
+ if (key.backspace || key.delete) return ip.filterBackspace()
115
+ if (input && !key.ctrl && !key.meta) return ip.filterInput(input)
116
+ return
117
+ }
100
118
  if (s.mode === 'tree') {
101
119
  const tr = s.tree
102
- if (key.escape || input === 't') return tr.blur()
120
+ // the `/` filter owns plain keys while active (letters type into it)
121
+ if (tr.filtering) {
122
+ if (key.escape) return tr.clearFilter()
123
+ if (key.return) return void tr.commit()
124
+ if (key.upArrow) return tr.move(-1)
125
+ if (key.downArrow) return tr.move(1)
126
+ if (key.leftArrow) return tr.fold()
127
+ if (key.rightArrow) return tr.unfold()
128
+ if (key.backspace || key.delete) return tr.filterBackspace()
129
+ if (input && !key.ctrl && !key.meta) return tr.filterInput(input)
130
+ return
131
+ }
132
+ if (key.escape) return tr.filter !== '' ? tr.clearFilter() : tr.blur()
133
+ if (input === 't') return tr.blur()
134
+ if (input === '/') return tr.beginFilter()
103
135
  if (key.return || input === ' ') return void tr.commit()
104
136
  if (key.upArrow) return tr.move(-1)
105
137
  if (key.downArrow) return tr.move(1)
@@ -114,7 +146,8 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
114
146
  if (input === 'r') return void s.exec.run()
115
147
  if (input === 's') return s.exec.randomizeSeedAndRun()
116
148
  if (input === 'd') return s.drafts.begin()
117
- if (input === 'h') return s.host.begin()
149
+ if (input === 'h') return s.host.beginPicker()
150
+ if (input === 'a') return s.host.begin()
118
151
  if (input === 'p') return s.preview.beginMenu()
119
152
  if (input === 'o') return s.exec.openLastOutput()
120
153
  if (input === 'q') {
@@ -125,7 +158,8 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
125
158
  }
126
159
  if (s.mode === 'host') {
127
160
  const h = s.host
128
- if (key.escape || input === 'h' || input === 'v') return h.blur()
161
+ if (key.escape || input === 'a' || input === 'v') return h.blur()
162
+ if (input === 'h') return h.beginPicker()
129
163
  if (key.return || input === ' ') return void h.commit()
130
164
  if (key.upArrow) return h.move(-1)
131
165
  if (key.downArrow) return h.move(1)
@@ -135,6 +169,20 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
135
169
  }
136
170
  return
137
171
  }
172
+ if (s.mode === 'overlay-hosts') {
173
+ const h = s.host
174
+ if (key.escape || input === 'h') return h.cancelPicker()
175
+ if (key.return || input === ' ') return h.commitPicker()
176
+ if (key.upArrow) return h.pickerMove(-1)
177
+ if (key.downArrow) return h.pickerMove(1)
178
+ return
179
+ }
180
+ if (s.mode === 'overlay-copy') {
181
+ // any close-ish key ends it — a confirmation must never trap
182
+ if (key.escape || key.return || input === ' ' || input === 'c' || input === 'C' || input === 'q')
183
+ return s.exec.closeCopyPopup()
184
+ return
185
+ }
138
186
  if (s.mode === 'preview') {
139
187
  const pv = s.preview
140
188
  // ⏎ CONFIRMS (closes): ←→ already changed the value in place
@@ -147,7 +195,8 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
147
195
  if (input === 'r') return void s.exec.run()
148
196
  if (input === 's') return s.exec.randomizeSeedAndRun()
149
197
  if (input === 'd') return s.drafts.begin()
150
- if (input === 'h') return s.host.begin()
198
+ if (input === 'h') return s.host.beginPicker()
199
+ if (input === 'a') return s.host.begin()
151
200
  if (input === 'o') return s.exec.openLastOutput()
152
201
  if (input === 'q') {
153
202
  s.onExit()
@@ -182,11 +231,16 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
182
231
  if (key.leftArrow) return s.tree.focus()
183
232
  if (key.rightArrow || key.return || input === ' ') return s.activate()
184
233
  if (s.navKey(input)) return
234
+ if (input === '/') {
235
+ s.tree.focus()
236
+ return s.tree.beginFilter()
237
+ }
185
238
  if (input === 'e') return s.drafts.beginRename()
186
239
  if (input === 'r') return void s.exec.run()
187
240
  if (input === 's') return s.exec.randomizeSeedAndRun()
188
241
  if (input === 't' || input === 'w') return s.tree.focus()
189
- if (input === 'h') return s.host.begin()
242
+ if (input === 'h') return s.host.beginPicker()
243
+ if (input === 'a') return s.host.begin()
190
244
  if (input === 'd') return s.drafts.begin()
191
245
  if (input === 'p') return s.preview.beginMenu()
192
246
  if (input === 'o') return s.exec.openLastOutput()
@@ -218,8 +272,14 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
218
272
  <SizeOverlay st={s} />
219
273
  ) : s.mode === 'overlay-loras' ? (
220
274
  <LorasOverlay st={s} />
275
+ ) : s.mode === 'overlay-image' ? (
276
+ <ImagePickerOverlay st={s} />
221
277
  ) : s.mode === 'overlay-drafts' ? (
222
278
  <DraftsOverlay st={s} />
279
+ ) : s.mode === 'overlay-hosts' ? (
280
+ <HostsOverlay st={s} />
281
+ ) : s.mode === 'overlay-copy' ? (
282
+ <CopyOverlay st={s} />
223
283
  ) : (
224
284
  <VarsPanel st={s} />
225
285
  )}
@@ -1,14 +1,14 @@
1
- import { existsSync, readdirSync, readFileSync } from 'node:fs'
2
- import { fileURLToPath } from 'node:url'
3
- import { dirname, join } from 'pathe'
1
+ import { readdirSync } from 'node:fs'
2
+ import { join } from 'pathe'
4
3
 
5
4
  /**
6
5
  * recursive scan for the workflow-module naming convention. Entries BELOW a
7
6
  * node_modules segment are skipped: packaged examples arrive via
8
- * bundledExamplesDir (symlinked layouts like pnpm would otherwise list them
9
- * twice, un-deduped, as the user's own files), and third-party packages
10
- * shipping *.cflow.ts are not this project's workflows. A scan root that is
11
- * ITSELF inside node_modules still works (the filter is relative to the root).
7
+ * bundledExamplesDir (src/exampleAssets.ts — symlinked layouts like pnpm would
8
+ * otherwise list them twice, un-deduped, as the user's own files), and
9
+ * third-party packages shipping *.cflow.ts are not this project's workflows. A
10
+ * scan root that is ITSELF inside node_modules still works (the filter is
11
+ * relative to the root).
12
12
  */
13
13
  export function scanCflowFiles(dir: string): string[] {
14
14
  const hits = readdirSync(dir, { recursive: true })
@@ -19,40 +19,6 @@ export function scanCflowFiles(dir: string): string[] {
19
19
  return hits.sort()
20
20
  }
21
21
 
22
- /**
23
- * the examples/ folder shipped in the npm tarball, resolved from THIS module's
24
- * own location (NEVER cwd): walking up to the nearest NAMED package.json finds
25
- * <pkg>/examples both from a consumer's node_modules/comfy-ts/dist/cli.js and
26
- * from this repo's src/cli/tui/. Returns null when the examples are absent
27
- * (a consumer may prune the folder) or when the nearest named package is not
28
- * comfy-ts (the lib was inlined into someone else's bundle — its examples are
29
- * not on disk); no package.json all the way up is a broken install and throws.
30
- */
31
- export function bundledExamplesDir(moduleUrl: string = import.meta.url): string | null {
32
- let dir = dirname(fileURLToPath(moduleUrl))
33
- let prev = ''
34
- while (dir !== prev) {
35
- const pkgPath = join(dir, 'package.json')
36
- if (existsSync(pkgPath)) {
37
- let pkg: { name?: string } = {}
38
- try {
39
- pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
40
- } catch {
41
- // a malformed package.json on the walk (someone's broken fixture
42
- // dir) must not take the whole TUI down; treat as unnamed
43
- }
44
- if (pkg.name === 'comfy-ts') {
45
- const examples = join(dir, 'examples')
46
- return existsSync(examples) ? examples : null
47
- }
48
- if (pkg.name != null) return null
49
- }
50
- prev = dir
51
- dir = dirname(dir)
52
- }
53
- throw new Error(`[comfy-ts tui] no package.json found walking up from ${fileURLToPath(moduleUrl)}`)
54
- }
55
-
56
22
  export type WorkflowDiscovery = {
57
23
  /** every module the tree lists, user files first, bundled examples last */
58
24
  files: string[]
@@ -0,0 +1,72 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import { OverlayList } from 'src/cli/tui/components/OverlayList.tsx'
4
+ import { PICKER_PANES } from 'src/cli/tui/imagePicker/ImagePickerSt.ts'
5
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
6
+
7
+ /** modal image browser: three panes (tab), dirs enter, ⏎ picks, ★ = favorite folder */
8
+ export const ImagePickerOverlay = observer((p: { st: TuiSt }) => {
9
+ const s = p.st
10
+ const ip = s.imagePicker
11
+ const iv = ip.selectedVar
12
+ if (iv == null) return null
13
+ const rows = ip.rows
14
+ return (
15
+ <OverlayList
16
+ title={
17
+ <>
18
+ {s.selected?.[1].label ?? s.selected?.[0]} <Text color="gray">{iv.display()}</Text>
19
+ </>
20
+ }
21
+ extraHeader={
22
+ <Box flexDirection="column">
23
+ <Text>
24
+ {PICKER_PANES.map((pane, ix) => (
25
+ <Text key={pane}>
26
+ {ix > 0 ? <Text color="gray"> · </Text> : null}
27
+ <Text
28
+ color={pane === ip.pane ? 'cyan' : 'gray'}
29
+ bold={pane === ip.pane}
30
+ underline={pane === ip.pane}
31
+ >
32
+ {pane}
33
+ </Text>
34
+ </Text>
35
+ ))}
36
+ {ip.pane === 'browse' ? <Text color="gray"> {ip.folderDisplay}</Text> : null}
37
+ </Text>
38
+ <Text color="yellow">filter: {ip.filter}▌</Text>
39
+ </Box>
40
+ }
41
+ selectedIx={ip.ix}
42
+ lines={s.overlayLines}
43
+ rows={rows.map((row, ix) => {
44
+ const sel = ix === ip.ix
45
+ const fav = row.kind === 'dir' && ip.isFavorite(row.path)
46
+ const missing = row.kind === 'image' && row.missing
47
+ return {
48
+ key: `${row.kind}:${row.path}`,
49
+ node: (
50
+ <Text
51
+ key={`${row.kind}:${row.path}`}
52
+ inverse={sel}
53
+ color={row.kind === 'dir' ? 'blue' : missing ? 'gray' : undefined}
54
+ dimColor={missing}
55
+ >
56
+ {sel ? '▸ ' : ' '}
57
+ {fav ? '★ ' : ' '}
58
+ {row.name}
59
+ {row.kind === 'dir' ? '/' : ''}
60
+ {missing ? ' (missing)' : ''}
61
+ </Text>
62
+ ),
63
+ }
64
+ })}
65
+ footer={
66
+ rows.length === 0 ? (
67
+ <Text color="red">{ip.listingError ?? (ip.filter !== '' ? 'no match' : 'no images here')}</Text>
68
+ ) : undefined
69
+ }
70
+ />
71
+ )
72
+ })
@@ -0,0 +1,288 @@
1
+ import { existsSync, readFileSync, statSync } from 'node:fs'
2
+ import { homedir } from 'node:os'
3
+ import { makeAutoObservable, reaction } from 'mobx'
4
+ import { basename, dirname, resolve } from 'pathe'
5
+ import { listImageDir, parentDir } from 'src/cli/tui/imagePicker/fsListing.ts'
6
+ import { pickerPrefs } from 'src/cli/tui/imagePicker/pickerPrefs.ts'
7
+ import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
8
+ import { fuzzyMatch } from 'src/utils/fuzzyMatch.ts'
9
+ import { imageBufferToAnsi } from 'src/utils/ansiImage.ts'
10
+ import type { ImageVar } from 'src/vars/ComfyVars.ts'
11
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
12
+
13
+ export type PickerPane = 'browse' | 'favorites' | 'recents'
14
+ export const PICKER_PANES: readonly PickerPane[] = ['browse', 'favorites', 'recents']
15
+
16
+ export type PickerRow =
17
+ | { kind: 'dir'; name: string; path: string }
18
+ | { kind: 'image'; name: string; path: string; missing: boolean }
19
+
20
+ /** `~`-contract $HOME for display (ImageVar.display's convention) */
21
+ export function contractHome(path: string): string {
22
+ const home = homedir()
23
+ return path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path
24
+ }
25
+
26
+ /**
27
+ * image-picker overlay (mode 'overlay-image'): browse the disk for an image
28
+ * var, three panes (browse / favorites / recents), filter-as-you-type, the
29
+ * highlighted image previews into the panel via PreviewSt's overlay slot.
30
+ */
31
+ export class ImagePickerSt {
32
+ constructor(private st: TuiSt) {
33
+ makeAutoObservable<ImagePickerSt, 'st'>(this, { st: false })
34
+ // the highlighted image's preview follows the cursor (debounced so
35
+ // arrowing fast never thrashes sharp; renders into the preview panel)
36
+ this.st.disposers.push(
37
+ reaction(
38
+ () => (this.st.mode === 'overlay-image' ? this.highlightedImage : null),
39
+ () => void this.refreshPreview(),
40
+ { delay: 120 },
41
+ ),
42
+ )
43
+ }
44
+
45
+ pane: PickerPane = 'browse'
46
+ /** current browse folder, absolute */
47
+ folder: string = process.cwd()
48
+ ix: number = 0
49
+ filter: string = ''
50
+
51
+ /** kind-narrowing cast sanctioned (agent/coding.md), `kind` is the tag */
52
+ get selectedVar(): ImageVar | null {
53
+ const sel = this.st.selected?.[1]
54
+ return sel?.kind === 'image' ? (sel as ImageVar) : null
55
+ }
56
+
57
+ get folderDisplay(): string {
58
+ return contractHome(this.folder)
59
+ }
60
+
61
+ /** begin() open order: dirname(value) → persisted lastFolder → opts.folder → cwd */
62
+ private initialFolder(iv: ImageVar): string {
63
+ const candidates: (string | null)[] = [
64
+ iv.isSet() ? dirname(iv.absPath()) : null,
65
+ pickerPrefs().lastFolder,
66
+ iv.opts.folder != null ? resolve(iv.opts.folder) : null,
67
+ ]
68
+ for (const c of candidates) {
69
+ try {
70
+ if (c != null && statSync(c).isDirectory()) return c
71
+ } catch {
72
+ // vanished candidate: fall through to the next one
73
+ }
74
+ }
75
+ return process.cwd()
76
+ }
77
+
78
+ begin(): void {
79
+ const iv = this.selectedVar
80
+ if (iv == null) return
81
+ this.st.mode = 'overlay-image'
82
+ this.pane = 'browse'
83
+ this.filter = ''
84
+ this.ix = 0
85
+ this.folder = this.initialFolder(iv)
86
+ // fresh overlay starts on the placeholder, never a stale slot image
87
+ this.st.preview.clearOverlayImage()
88
+ }
89
+
90
+ cancel(): void {
91
+ this.st.mode = 'nav'
92
+ }
93
+
94
+ // ---- listing ----
95
+ /** every row of the active pane BEFORE the filter, plus the browse-pane
96
+ * read error (unreadable folder: shown IN the overlay, browsing elsewhere
97
+ * stays possible). Computed with NO side effects — mobx forbids them. */
98
+ private get paneListing(): { rows: PickerRow[]; error: string | null } {
99
+ if (this.pane === 'favorites')
100
+ return {
101
+ rows: pickerPrefs().favorites.map((dir) => ({ kind: 'dir', name: contractHome(dir), path: dir })),
102
+ error: null,
103
+ }
104
+ if (this.pane === 'recents')
105
+ return {
106
+ rows: pickerPrefs().recents.map((img) => ({
107
+ kind: 'image',
108
+ name: contractHome(img),
109
+ path: img,
110
+ missing: !existsSync(img),
111
+ })),
112
+ error: null,
113
+ }
114
+ const iv = this.selectedVar
115
+ if (iv == null) return { rows: [], error: null }
116
+ try {
117
+ const listing = listImageDir(this.folder, iv.extensions)
118
+ return {
119
+ rows: [
120
+ ...listing.dirs.map((d): PickerRow => ({ kind: 'dir', name: d, path: resolve(this.folder, d) })),
121
+ ...listing.images.map(
122
+ (f): PickerRow => ({ kind: 'image', name: f, path: resolve(this.folder, f), missing: false }),
123
+ ),
124
+ ],
125
+ error: null,
126
+ }
127
+ } catch (e) {
128
+ return { rows: [], error: extractErrorMessage(e) }
129
+ }
130
+ }
131
+
132
+ get listingError(): string | null {
133
+ return this.paneListing.error
134
+ }
135
+
136
+ /** what the overlay renders: pane rows surviving the filter */
137
+ get rows(): PickerRow[] {
138
+ const all = this.paneListing.rows
139
+ if (this.filter === '') return all
140
+ return all.filter((r) => fuzzyMatch(this.filter, r.name))
141
+ }
142
+
143
+ get current(): PickerRow | null {
144
+ return this.rows[this.ix] ?? null
145
+ }
146
+
147
+ /** feeds the preview reaction: only a real, present image highlights */
148
+ get highlightedImage(): string | null {
149
+ const row = this.current
150
+ return row?.kind === 'image' && !row.missing ? row.path : null
151
+ }
152
+
153
+ // ---- navigation ----
154
+ move(delta: number): void {
155
+ const len = this.rows.length
156
+ if (len === 0) return
157
+ this.ix = (this.ix + delta + len) % len
158
+ }
159
+
160
+ cyclePane(): void {
161
+ const ix = PICKER_PANES.indexOf(this.pane)
162
+ this.pane = PICKER_PANES[(ix + 1) % PICKER_PANES.length] ?? 'browse'
163
+ this.ix = 0
164
+ this.filter = ''
165
+ }
166
+
167
+ private goto(dir: string): void {
168
+ this.pane = 'browse'
169
+ this.folder = dir
170
+ this.ix = 0
171
+ this.filter = ''
172
+ }
173
+
174
+ /** `→`: enter the highlighted dir (browse pane; images select via ⏎ only) */
175
+ enter(): void {
176
+ const row = this.current
177
+ if (this.pane === 'browse' && row?.kind === 'dir') this.goto(row.path)
178
+ }
179
+
180
+ /** `←`: parent dir (browse pane; the fs root is its own parent) */
181
+ goParent(): void {
182
+ if (this.pane !== 'browse') return
183
+ const parent = parentDir(this.folder)
184
+ if (parent !== this.folder) this.goto(parent)
185
+ }
186
+
187
+ /** ⏎: enter a dir (a favorite jumps browse into it), select an image */
188
+ commit(): void {
189
+ const row = this.current
190
+ if (row == null) return
191
+ if (row.kind === 'dir') return this.goto(row.path)
192
+ if (row.missing) return // vanished recent: dim row, never a broken value
193
+ this.select(row.path)
194
+ }
195
+
196
+ /** the pick: absolute path into the var, recents + lastFolder recorded */
197
+ private select(absPath: string): void {
198
+ const iv = this.selectedVar
199
+ if (iv == null) return
200
+ iv.set(absPath)
201
+ pickerPrefs().recordPick(absPath)
202
+ this.st.mode = 'nav'
203
+ }
204
+
205
+ /** ⌃F: favorite FOLDERS only — a dir row favorites it, an image row favorites the current folder */
206
+ toggleFavorite(): void {
207
+ const row = this.current
208
+ const dir =
209
+ row == null
210
+ ? this.pane === 'browse'
211
+ ? this.folder
212
+ : null
213
+ : row.kind === 'dir'
214
+ ? row.path
215
+ : this.pane === 'browse'
216
+ ? this.folder
217
+ : dirname(row.path)
218
+ if (dir == null) return
219
+ pickerPrefs().toggleFavorite(dir)
220
+ // favorites pane: the row may vanish under the cursor — clamp
221
+ this.ix = Math.max(0, Math.min(this.ix, this.rows.length - 1))
222
+ }
223
+
224
+ isFavorite(dir: string): boolean {
225
+ return pickerPrefs().isFavorite(dir)
226
+ }
227
+
228
+ // ---- filter (plain chars ALWAYS filter, LorasSt precedent) ----
229
+ filterInput(chunk: string): void {
230
+ this.filter += chunk
231
+ this.ix = 0
232
+ }
233
+
234
+ filterBackspace(): void {
235
+ this.filter = this.filter.slice(0, -1)
236
+ this.ix = 0
237
+ }
238
+
239
+ /** ⌥⌫ / ⌃W: drop the last word of the filter */
240
+ filterDeleteWord(): void {
241
+ this.filter = this.filter.replace(/\s*\S+\s*$/, '')
242
+ this.ix = 0
243
+ }
244
+
245
+ // ---- preview into the shared overlay slot (debounced reaction above) ----
246
+ private _busy: boolean = false
247
+
248
+ async refreshPreview(): Promise<void> {
249
+ if (this.st.mode !== 'overlay-image') {
250
+ // debounced close: another overlay may ALREADY own the slot — never wipe its image
251
+ if (!this.st.preview.overlayActive) this.st.preview.clearOverlayImage()
252
+ return
253
+ }
254
+ const path = this.highlightedImage
255
+ if (path == null) {
256
+ // dir row / empty pane: clear so a stale image never lingers
257
+ this.st.preview.clearOverlayImage()
258
+ return
259
+ }
260
+ if (this._busy) return
261
+ this._busy = true
262
+ try {
263
+ // local file: bytes read directly, no host round-trip
264
+ const bytes = new Uint8Array(readFileSync(path))
265
+ if (this.st.preview.useNative) {
266
+ this.st.preview.setOverlayImage({ bytes, ansi: null, name: basename(path), note: null })
267
+ } else {
268
+ const ansi = await imageBufferToAnsi(bytes, {
269
+ width: this.st.preview.width,
270
+ height: this.st.preview.height,
271
+ })
272
+ this.st.preview.setOverlayImage({ bytes: null, ansi, name: basename(path), note: null })
273
+ }
274
+ } catch (e) {
275
+ // e.g. a file sharp can't decode — placeholder note, never a crash
276
+ this.st.preview.setOverlayImage({
277
+ bytes: null,
278
+ ansi: null,
279
+ name: basename(path),
280
+ note: extractErrorMessage(e),
281
+ })
282
+ } finally {
283
+ this._busy = false
284
+ // the cursor may have moved while we rendered: catch up once
285
+ if (this.st.mode === 'overlay-image' && this.highlightedImage !== path) void this.refreshPreview()
286
+ }
287
+ }
288
+ }
@@ -0,0 +1,48 @@
1
+ import { readdirSync, statSync } from 'node:fs'
2
+ import { dirname, join } from 'pathe'
3
+
4
+ export type DirListing = { dirs: string[]; images: string[] }
5
+
6
+ /** `name.PNG` matches extensions `['png']` — extensions are lowercase, no dots */
7
+ export function hasImageExtension(name: string, extensions: readonly string[]): boolean {
8
+ const dot = name.lastIndexOf('.')
9
+ if (dot <= 0) return false
10
+ return extensions.includes(name.slice(dot + 1).toLowerCase())
11
+ }
12
+
13
+ /**
14
+ * ONE folder for the picker: dirs first then images, both alphabetical,
15
+ * images filtered by extension. Dot FILES are junk (.DS_Store) and skipped;
16
+ * dot DIRS are listed — .comfy-ts/outputs must be browsable. Symlinks are
17
+ * followed (a dangling one is skipped). Pure over fs — an unreadable dir
18
+ * THROWS, the caller surfaces it (never a silent empty listing).
19
+ */
20
+ export function listImageDir(dir: string, extensions: readonly string[]): DirListing {
21
+ const dirs: string[] = []
22
+ const images: string[] = []
23
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
24
+ let isDir = entry.isDirectory()
25
+ let isFile = entry.isFile()
26
+ if (entry.isSymbolicLink()) {
27
+ try {
28
+ const target = statSync(join(dir, entry.name))
29
+ isDir = target.isDirectory()
30
+ isFile = target.isFile()
31
+ } catch {
32
+ continue // dangling symlink: neither dir nor image
33
+ }
34
+ }
35
+ // after symlink resolution, so a dot-named link to a real dir stays listed
36
+ if (entry.name.startsWith('.') && !isDir) continue
37
+ if (isDir) dirs.push(entry.name)
38
+ else if (isFile && hasImageExtension(entry.name, extensions)) images.push(entry.name)
39
+ }
40
+ dirs.sort((a, b) => a.localeCompare(b))
41
+ images.sort((a, b) => a.localeCompare(b))
42
+ return { dirs, images }
43
+ }
44
+
45
+ /** parent for `←` navigation — the fs root is its own parent (never ascends past it) */
46
+ export function parentDir(dir: string): string {
47
+ return dirname(dir)
48
+ }