comfy-ts 0.2.0 → 0.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.
Files changed (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +363 -0
  3. package/dist/cli.js +764 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/index.cjs +4128 -0
  6. package/dist/index.cjs.map +1 -0
  7. package/dist/index.d.cts +9862 -0
  8. package/dist/index.d.ts +9846 -58
  9. package/dist/index.js +4049 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/log-CdfgILde.js +10 -0
  12. package/dist/log-CdfgILde.js.map +1 -0
  13. package/dist/run-tui-Io8Xea0L.js +3340 -0
  14. package/dist/run-tui-Io8Xea0L.js.map +1 -0
  15. package/package.json +104 -75
  16. package/src/cli/comfy-ts-cli.ts +36 -0
  17. package/src/cli/gen.ts +47 -0
  18. package/src/cli/outline.ts +82 -0
  19. package/src/cli/tui/components/DraftsOverlay.tsx +44 -0
  20. package/src/cli/tui/components/EditField.tsx +27 -0
  21. package/src/cli/tui/components/Header.tsx +51 -0
  22. package/src/cli/tui/components/HostPanel.tsx +37 -0
  23. package/src/cli/tui/components/LorasOverlay.tsx +49 -0
  24. package/src/cli/tui/components/OverlayList.tsx +25 -0
  25. package/src/cli/tui/components/PickerOverlays.tsx +66 -0
  26. package/src/cli/tui/components/PreviewPanel.tsx +33 -0
  27. package/src/cli/tui/components/PromptOverlay.tsx +16 -0
  28. package/src/cli/tui/components/StatusBar.tsx +165 -0
  29. package/src/cli/tui/components/TextOverlay.tsx +72 -0
  30. package/src/cli/tui/components/TreePanel.tsx +51 -0
  31. package/src/cli/tui/components/TuiApp.tsx +223 -0
  32. package/src/cli/tui/components/VarsPanel.tsx +86 -0
  33. package/src/cli/tui/findDefinedWorkflow.ts +16 -0
  34. package/src/cli/tui/keys.ts +20 -0
  35. package/src/cli/tui/protocolImagePainter.ts +59 -0
  36. package/src/cli/tui/run-tui.tsx +73 -0
  37. package/src/cli/tui/state/DraftsSt.ts +273 -0
  38. package/src/cli/tui/state/EditorSt.ts +289 -0
  39. package/src/cli/tui/state/ExecSt.ts +170 -0
  40. package/src/cli/tui/state/HostSt.ts +107 -0
  41. package/src/cli/tui/state/LorasSt.ts +185 -0
  42. package/src/cli/tui/state/PickerSt.ts +112 -0
  43. package/src/cli/tui/state/PreviewSt.ts +138 -0
  44. package/src/cli/tui/state/QueueSt.ts +59 -0
  45. package/src/cli/tui/state/SettingsSt.ts +73 -0
  46. package/src/cli/tui/state/TreeSt.ts +122 -0
  47. package/src/cli/tui/state/TuiSt.ts +169 -0
  48. package/src/cli/tui/state/WorkflowsSt.ts +92 -0
  49. package/src/cli/tui-env.ts +8 -0
  50. package/src/errors/InvalidPromptError.ts +12 -0
  51. package/src/graph/ComfyNode.ts +403 -0
  52. package/src/graph/ComfyNodeID.ts +28 -0
  53. package/src/graph/ComfyNodeOutput.ts +16 -0
  54. package/src/graph/NodeSlotSize.ts +4 -0
  55. package/src/graph/autoValue.ts +17 -0
  56. package/src/host/ComfyHost.ts +646 -0
  57. package/src/host/ComfyInstallType.ts +15 -0
  58. package/src/host/ComfyManager.ts +232 -0
  59. package/src/host/ComfyUploader.ts +110 -0
  60. package/src/host/ComfyWorkflowBuilder.ts +60 -0
  61. package/src/host/Requirements.ts +55 -0
  62. package/src/host/ResilientWebsocket.ts +147 -0
  63. package/src/host/loraManagerApi.ts +98 -0
  64. package/src/image-utils/_getPngMetadata.ts +53 -0
  65. package/src/image-utils/_getWebpMetadata.ts +38 -0
  66. package/src/image-utils/_parseExifData.ts +53 -0
  67. package/src/index.ts +89 -0
  68. package/src/litegraph/LiteGraphGroup.ts +22 -0
  69. package/src/litegraph/LiteGraphJSON.ts +46 -0
  70. package/src/litegraph/LiteGraphLink.ts +23 -0
  71. package/src/litegraph/LiteGraphLinkID.ts +6 -0
  72. package/src/litegraph/LiteGraphNode.ts +69 -0
  73. package/src/litegraph/LiteGraphNodeInput.ts +27 -0
  74. package/src/litegraph/LiteGraphNodeOutput.ts +23 -0
  75. package/src/litegraph/LiteGraphSlotIndex.ts +6 -0
  76. package/src/litegraph/convertFlowToLiteGraphJSON.ts +114 -0
  77. package/src/manager/ComfyRegistry.ts +124 -0
  78. package/src/manager/generated/KnownComfyCustomNodeName.ts +19280 -0
  79. package/src/manager/generated/KnownComfyPluginTitle.ts +5130 -0
  80. package/src/manager/generated/KnownComfyPluginURL.ts +2589 -0
  81. package/src/manager/generated/KnownModel_Base.ts +126 -0
  82. package/src/manager/generated/KnownModel_FileName.ts +2287 -0
  83. package/src/manager/generated/KnownModel_Name.ts +2287 -0
  84. package/src/manager/generated/KnownModel_SavePath.ts +263 -0
  85. package/src/manager/generated/KnownModel_Type.ts +97 -0
  86. package/src/manager/json/alter-list.json +224 -0
  87. package/src/manager/json/custom-node-list.extra.ts +13 -0
  88. package/src/manager/json/custom-node-list.json +21948 -0
  89. package/src/manager/json/extension-node-map.json +31282 -0
  90. package/src/manager/json/github-stats.json +12602 -0
  91. package/src/manager/json/model-list.extra.ts +26 -0
  92. package/src/manager/json/model-list.json +5052 -0
  93. package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +56 -0
  94. package/src/manager/loaders/step2_custom-node-list-loader.ts +149 -0
  95. package/src/manager/loaders/step3_extension-node-map-loader.ts +189 -0
  96. package/src/manager/loaders/step4_model-list-loader.ts +159 -0
  97. package/src/manager/script-update-manager.bun.ts +18 -0
  98. package/src/manager/types/ComfyManagerAPIFetchPolicy.ts +9 -0
  99. package/src/manager/types/ComfyManagerAPIModelList.ts +10 -0
  100. package/src/manager/types/ComfyManagerAPIPluginList.ts +11 -0
  101. package/src/manager/types/ComfyManagerFileModelInfo.ts +5 -0
  102. package/src/manager/types/ComfyManagerFilePluginContent.ts +13 -0
  103. package/src/manager/types/ComfyManagerFilePluginList.ts +5 -0
  104. package/src/manager/types/ComfyManagerModelInfo.ts +18 -0
  105. package/src/manager/types/ComfyManagerPluginContentMetadata.ts +16 -0
  106. package/src/manager/types/ComfyManagerPluginEnums.ts +8 -0
  107. package/src/manager/types/ComfyManagerPluginInfo.ts +50 -0
  108. package/src/runner/ComfyExecution.ts +301 -0
  109. package/src/runner/ComfyExecutionStatus.ts +2 -0
  110. package/src/runner/ComfyWorkflow.ts +395 -0
  111. package/src/runner/ComfyWorkflowLayout.ts +96 -0
  112. package/src/runner/ComfyWsApi.ts +159 -0
  113. package/src/runner/MediaImage.ts +262 -0
  114. package/src/sdk-generator/ComfyNodeSchema.ts +79 -0
  115. package/src/sdk-generator/ComfySchema.ts +369 -0
  116. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +95 -0
  117. package/src/sdk-generator/Primitives.ts +76 -0
  118. package/src/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.ts +39 -0
  119. package/src/sdk-generator/_pythonModuleToNamespace.ts +27 -0
  120. package/src/sdk-generator/_toQualifiedNodeKey.ts +5 -0
  121. package/src/sdk-generator/comfy-api-json.ts +16 -0
  122. package/src/sdk-generator/comfyui-sdk-codegen.ts +287 -0
  123. package/src/sdk-generator/comfyui-types.ts +56 -0
  124. package/src/sdk-generator/litegraphToApiRequestPayload.ts +157 -0
  125. package/src/ssh-host-manager/ssh-config-manager.ts +89 -0
  126. package/src/ssh-host-manager/ssh-config.windows.md +32 -0
  127. package/src/ssh-host-manager/ssh-manager.ts +129 -0
  128. package/src/state.ts +136 -0
  129. package/src/types/comfy-sdk.ts +106 -0
  130. package/src/types/index.ts +55 -0
  131. package/src/utils/CodeBuffer.ts +61 -0
  132. package/src/utils/ComfyColors.ts +38 -0
  133. package/src/utils/ansi.ts +26 -0
  134. package/src/utils/ansiImage.ts +36 -0
  135. package/src/utils/bang.ts +39 -0
  136. package/src/utils/deepCopyNaive.ts +1 -0
  137. package/src/utils/downloadFile.ts +77 -0
  138. package/src/utils/escapeJSKey.ts +32 -0
  139. package/src/utils/exhaust.ts +4 -0
  140. package/src/utils/extractErrorMessage.ts +11 -0
  141. package/src/utils/fuzzyMatch.ts +8 -0
  142. package/src/utils/githubRegexes.ts +2 -0
  143. package/src/utils/hashArrayBuffer.ts +6 -0
  144. package/src/utils/log.ts +9 -0
  145. package/src/utils/loraTag.ts +10 -0
  146. package/src/utils/printArkResultInConsole.ts +16 -0
  147. package/src/utils/softValidate.ts +8 -0
  148. package/src/utils/stringifyReadable.ts +32 -0
  149. package/src/utils/toposort.ts +59 -0
  150. package/src/utils/tryExtracting.ts +41 -0
  151. package/src/utils/writeFile.ts +16 -0
  152. package/src/vars/ComfyVars.ts +531 -0
  153. package/src/vars/DefinedWorkflow.ts +112 -0
  154. package/src/vars/loraKeywords.ts +56 -0
  155. package/dist/index.d.mts +0 -74
  156. package/dist/index.mjs +0 -3
  157. package/dist/index.mjs.map +0 -1
  158. package/readme.md +0 -40
@@ -0,0 +1,33 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
4
+
5
+ /** right-side panel: selected-lora preview in the loras overlay, live latent while running, last output after.
6
+ * protocol terminals: the body is BLANK cells — useProtocolImage paints the real image over them */
7
+ export const PreviewPanel = observer((p: { st: TuiSt }) => {
8
+ const s = p.st
9
+ const pv = s.preview
10
+ const loraMode = s.mode === 'overlay-loras'
11
+ const showLatent = !loraMode && s.exec.running && (pv.latentAnsi != null || pv.latentBytes != null)
12
+ const label = loraMode ? `lora ${s.loras.previewName ?? 'lora'}` : showLatent ? 'latent' : 'output'
13
+ const placeholder = loraMode ? (s.loras.previewNote ?? '(pick a lora)') : '(no image yet)'
14
+ const content = pv.useNative ? null : loraMode ? s.loras.previewAnsi : showLatent ? pv.latentAnsi : pv.outputAnsi
15
+ const reserveRect = pv.useNative && pv.protocolImage != null
16
+ return (
17
+ <Box borderStyle="round" paddingX={1} flexDirection="column" flexShrink={0} width={pv.width + 4}>
18
+ {/* marginTop -1 lifts the label onto the border line: the panel key IS its title */}
19
+ <Box marginTop={-1}>
20
+ <Text color="gray" wrap="truncate">
21
+ (p)review · {label}
22
+ </Text>
23
+ </Box>
24
+ {reserveRect ? (
25
+ Array.from({ length: pv.height }, (_, ix) => <Text key={ix}> </Text>)
26
+ ) : content != null ? (
27
+ <Text>{content}</Text>
28
+ ) : (
29
+ <Text color="gray">{placeholder}</Text>
30
+ )}
31
+ </Box>
32
+ )
33
+ })
@@ -0,0 +1,16 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import { EditField } from 'src/cli/tui/components/EditField.tsx'
4
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
5
+
6
+ /** modal name prompt: renders any EditorSt CUSTOM session (new/rename/duplicate draft, …) */
7
+ export const PromptOverlay = observer((p: { st: TuiSt }) => {
8
+ const ed = p.st.editor
9
+ return (
10
+ <Box borderStyle="double" paddingX={1} flexDirection="column">
11
+ <Text bold>{ed.customTitle}</Text>
12
+ <EditField st={p.st} />
13
+ <Text color="gray">⏎ apply · esc cancel</Text>
14
+ </Box>
15
+ )
16
+ })
@@ -0,0 +1,165 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import type { ReactNode } from 'react'
4
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
5
+
6
+ export type Hint = [key: string, label: string]
7
+
8
+ /** keys cyan, labels gray — shared by the keybar and overlay footers */
9
+ export const KeyHints = (p: { hints: Hint[] }): ReactNode => (
10
+ <Text wrap="wrap">
11
+ {p.hints.map(([k, label], ix) => (
12
+ <Text key={`${k}·${label}`}>
13
+ {ix > 0 ? <Text color="gray"> · </Text> : null}
14
+ <Text color="cyan">{k}</Text>
15
+ <Text color="gray"> {label}</Text>
16
+ </Text>
17
+ ))}
18
+ </Text>
19
+ )
20
+
21
+ export const ProgressLine = observer((p: { st: TuiSt }) => {
22
+ const s = p.st
23
+ const e = s.exec
24
+ const queued = s.queue.remaining
25
+ if (s.mode === 'edit' || s.mode === 'overlay-text') return <Text color="gray">editing…</Text>
26
+ if (e.running) {
27
+ const prog = e.progress
28
+ const width = 16
29
+ const filled = prog ? Math.round((prog.percent / 100) * width) : 0
30
+ const bar = '█'.repeat(filled) + '░'.repeat(width - filled)
31
+ return (
32
+ <Text>
33
+ {'>> '}[{bar}] {prog ? `${prog.percent.toFixed(0)}%` : '…'}
34
+ {prog?.nodeName ? ` · ${prog.nodeName}` : ''}
35
+ {prog ? ` · ${(prog.elapsedMs / 1000).toFixed(0)}s` : ''}
36
+ {queued > 0 ? ` · queue ${queued}` : ''}
37
+ </Text>
38
+ )
39
+ }
40
+ if (e.error) return <Text color="red">{e.error}</Text>
41
+ if (e.notice) return <Text>{e.notice}</Text>
42
+ if (queued > 0) return <Text color="yellow">{queued} queued on the server</Text>
43
+ if (e.runCount > 0)
44
+ return (
45
+ <Text color={e.lastStatus === 'Success' ? 'green' : 'red'}>
46
+ run #{e.runCount} {e.lastStatus?.toLowerCase()}
47
+ </Text>
48
+ )
49
+ return <Text color="gray">ready — r to run</Text>
50
+ })
51
+
52
+ const KIND_KEYS: Record<string, Hint[]> = {
53
+ text: [['⏎/→', 'edit']],
54
+ int: [['⏎/→', 'edit']],
55
+ float: [['⏎/→', 'edit']],
56
+ seed: [
57
+ ['+', 'increment'],
58
+ ['-', 'decrement'],
59
+ ['?', 'random'],
60
+ ['=', 'fixed'],
61
+ ['⏎/→', 'type value'],
62
+ ['*', 'reroll'],
63
+ ],
64
+ toggle: [['⏎/→', 'flip']],
65
+ choice: [['⏎/→', 'pick']],
66
+ size: [['⏎/→', 'pick']],
67
+ loras: [['⏎/→', 'select']],
68
+ }
69
+
70
+ /** shown INSIDE the text editor box (TextOverlay footer), not in the keybar */
71
+ export const TEXT_EDIT_HINTS: Hint[] = [
72
+ ['⏎', 'save'],
73
+ ['⇧⏎/⌥⏎', 'newline'],
74
+ ['esc', 'cancel'],
75
+ ['⌥⌫', 'del word'],
76
+ ['⌥←→', 'jump'],
77
+ ['⌘←→/⌃A⌃E', 'line ends'],
78
+ ['⌥↑↓', 'move line'],
79
+ ['⌘/', 'comment'],
80
+ ['⌃U/⌃K', 'kill'],
81
+ ]
82
+
83
+ export const DRAFT_OP_HINTS: Hint[] = [
84
+ ['n', 'new'],
85
+ ['e', 'rename'],
86
+ ['c', 'duplicate'],
87
+ ['x', 'delete'],
88
+ ]
89
+
90
+ const MODE_KEYS: Partial<Record<string, Hint[]>> = {
91
+ edit: [
92
+ ['⏎', 'apply'],
93
+ ['esc', 'cancel'],
94
+ ['⌥⌫/⌃W', 'del word'],
95
+ ['⌥←→', 'jump'],
96
+ ['⌃A/⌃E', 'line ends'],
97
+ ['⌃U/⌃K', 'kill'],
98
+ ],
99
+ 'overlay-text': TEXT_EDIT_HINTS,
100
+ 'overlay-choice': [
101
+ ['⏎', 'pick'],
102
+ ['↑↓', 'move'],
103
+ ['type', 'filter'],
104
+ ['esc', 'cancel'],
105
+ ],
106
+ 'overlay-size': [
107
+ ['⏎', 'pick'],
108
+ ['↑↓', 'move'],
109
+ ['type', 'filter or WxH'],
110
+ ['esc', 'cancel'],
111
+ ],
112
+ 'overlay-loras': [
113
+ ['space/⏎', 'tick'],
114
+ ['←→', 'strength ±0.05'],
115
+ ['type', 'filter'],
116
+ ['⌃K', 'keyword'],
117
+ ['⌃A', 'all'],
118
+ ['⌃N', 'none'],
119
+ ['esc', 'done'],
120
+ ],
121
+ 'overlay-drafts': [['⏎', 'load / new'], ...DRAFT_OP_HINTS, ['↑↓', 'move'], ['esc', 'cancel']],
122
+ tree: [['⏎', 'load'], ['↑↓', 'move'], ['←', 'fold'], ['→', 'unfold / vars'], ...DRAFT_OP_HINTS, ['t/esc', 'back']],
123
+ host: [
124
+ ['⏎', 'run action'],
125
+ ['↑↓', 'move'],
126
+ ['h/esc', 'back'],
127
+ ],
128
+ }
129
+
130
+ /** persistent 2-line keybar: EVERYTHING available right now, always visible */
131
+ export const KeyBar = observer((p: { st: TuiSt }) => {
132
+ const s = p.st
133
+ const kind = s.selected?.[1].kind
134
+ const modeHints: Hint[] = MODE_KEYS[s.mode] ?? [
135
+ ['↑↓', 'select'],
136
+ ['←', 'tree'],
137
+ ...(kind ? (KIND_KEYS[kind] ?? []) : []),
138
+ ]
139
+ // keys already advertised by a panel title (t/v/p) or a header box (w/d/h)
140
+ // are NOT repeated here — one letter, one place
141
+ const globalHints: Hint[] =
142
+ s.mode === 'nav' || s.mode === 'tree' || s.mode === 'host'
143
+ ? [
144
+ ['r', 'run'],
145
+ ['s', 'reroll+run'],
146
+ ...(s.mode === 'nav' ? ([['e', 'rename draft']] as Hint[]) : []),
147
+ // the preview panel carries `p` in its title — unless it is hidden
148
+ ...(s.preview.show ? [] : ([['p', 'preview off']] as Hint[])),
149
+ ['o', 'open image'],
150
+ // c is duplicate inside the tree — don't advertise the copy pair there
151
+ ...(s.mode === 'tree' ? [] : ([['c/C', 'copy wf/api']] as Hint[])),
152
+ ['q', 'quit'],
153
+ ]
154
+ : [
155
+ ['⌃R', 'run'],
156
+ ['esc', 'back'],
157
+ ]
158
+ return (
159
+ <Box flexDirection="column" paddingX={1}>
160
+ {/* the text editor shows its keys under its own box */}
161
+ {s.mode !== 'overlay-text' && <KeyHints hints={modeHints} />}
162
+ <KeyHints hints={globalHints} />
163
+ </Box>
164
+ )
165
+ })
@@ -0,0 +1,72 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import { KeyHints, TEXT_EDIT_HINTS } from 'src/cli/tui/components/StatusBar.tsx'
4
+ import { PromptVar } from 'src/vars/ComfyVars.ts'
5
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
6
+
7
+ /** modal multiline editor: real newlines, caret rendered per code point.
8
+ * The cursor's LOGICAL line is background-highlighted (word wrap hides line
9
+ * bounds — the highlight shows exactly what ⌥↑↓ will move); on prompt vars,
10
+ * `//` comment lines render dim gray, `- ` negative lines red, and the
11
+ * injected lora keywords show as a magenta chrome line (not editable). */
12
+ export const TextOverlay = observer((p: { st: TuiSt }) => {
13
+ const s = p.st
14
+ const ed = s.editor
15
+ const winLines = s.overlayLines
16
+ const promptVar = s.selected?.[1]
17
+ const isPrompt = promptVar instanceof PromptVar
18
+ const injected = isPrompt ? promptVar.injectedKeywords() : []
19
+ // lines with their global code-point start offsets
20
+ const lines: { text: string; start: number }[] = []
21
+ let start = 0
22
+ for (const text of ed.buffer.split('\n')) {
23
+ lines.push({ text, start })
24
+ start += [...text].length + 1
25
+ }
26
+ let cursorLine = 0
27
+ for (let i = 0; i < lines.length; i++) if ((lines[i]?.start ?? 0) <= ed.cursor) cursorLine = i
28
+ const winStart = Math.max(0, Math.min(cursorLine - Math.floor(winLines / 2), lines.length - winLines))
29
+ const visible = lines.slice(winStart, winStart + winLines)
30
+ const color = ed.invalid ? 'red' : 'yellow'
31
+ return (
32
+ <Box borderStyle="double" paddingX={1} flexDirection="column">
33
+ <Text bold>{s.selected ? (s.selected[1].label ?? s.selected[0]) : ''}</Text>
34
+ {/* injected lora keywords: CHROME above the buffer — the cursor can never enter it */}
35
+ {injected.length > 0 && (
36
+ <Text color="magenta" wrap="wrap">
37
+ ↳ loras: {injected.join(', ')} <Text dimColor>(injected)</Text>
38
+ </Text>
39
+ )}
40
+ {winStart > 0 && <Text color="gray">… {winStart} more line(s)</Text>}
41
+ {visible.map((line, ix) => {
42
+ const globalIx = winStart + ix
43
+ const comment = isPrompt && PromptVar.isCommentLine(line.text)
44
+ const negative = isPrompt && !comment && PromptVar.isNegativeLine(line.text)
45
+ const lineColor = comment ? 'gray' : negative ? 'red' : color
46
+ if (globalIx !== cursorLine)
47
+ return (
48
+ <Text key={globalIx} color={lineColor} dimColor={comment}>
49
+ {line.text === '' ? ' ' : line.text}
50
+ </Text>
51
+ )
52
+ const cs = [...line.text]
53
+ const col = ed.cursor - line.start
54
+ const before = cs.slice(0, col).join('')
55
+ const at = cs[col] ?? ' '
56
+ const after = cs.slice(col + 1).join('')
57
+ return (
58
+ <Text key={globalIx} color={lineColor} dimColor={comment} backgroundColor="blackBright">
59
+ {before}
60
+ <Text inverse>{at}</Text>
61
+ {after}
62
+ </Text>
63
+ )
64
+ })}
65
+ {winStart + winLines < lines.length && (
66
+ <Text color="gray">… {lines.length - winStart - winLines} more line(s)</Text>
67
+ )}
68
+ {/* edit keys sit right under the text, not at the screen bottom */}
69
+ <KeyHints hints={TEXT_EDIT_HINTS} />
70
+ </Box>
71
+ )
72
+ })
@@ -0,0 +1,51 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
4
+
5
+ /** persistent left panel: workflows with their drafts nested; `t` (or ← from vars) focuses it */
6
+ export const TreePanel = observer((p: { st: TuiSt }) => {
7
+ const s = p.st
8
+ const tree = s.tree
9
+ const focused = s.mode === 'tree'
10
+ return (
11
+ <Box
12
+ borderStyle="round"
13
+ borderColor={focused ? 'cyan' : 'gray'}
14
+ flexDirection="column"
15
+ flexShrink={0}
16
+ width={s.treeWidth}
17
+ paddingX={1}
18
+ >
19
+ {/* marginTop -1 lifts the label onto the border line: the panel key IS its title */}
20
+ <Box marginTop={-1}>
21
+ <Text color={focused ? 'cyan' : 'gray'} bold={focused}>
22
+ (t)ree
23
+ </Text>
24
+ </Box>
25
+ {tree.rows.map((row, ix) => {
26
+ const sel = focused && ix === tree.ix
27
+ if (row.kind === 'workflow') {
28
+ const arrow = row.hasDrafts ? (row.expanded ? '▾' : '▸') : ' '
29
+ return (
30
+ <Text key={row.file} inverse={sel} color={row.current ? 'green' : undefined} wrap="truncate">
31
+ {arrow}
32
+ {row.current ? '●' : ' '} {row.name}
33
+ </Text>
34
+ )
35
+ }
36
+ return (
37
+ <Text
38
+ key={`${row.file}·${row.draft}`}
39
+ inverse={sel}
40
+ color={row.active ? 'cyan' : 'gray'}
41
+ wrap="truncate"
42
+ >
43
+ {' '}
44
+ {row.active ? '●' : '·'} {row.draft}
45
+ </Text>
46
+ )
47
+ })}
48
+ {s.workflows.loading ? <Text color="yellow">loading…</Text> : null}
49
+ </Box>
50
+ )
51
+ })
@@ -0,0 +1,223 @@
1
+ import { Box, Text, useApp, useInput, useStdin } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import { basename } from 'pathe'
4
+ import { DraftsOverlay } from 'src/cli/tui/components/DraftsOverlay.tsx'
5
+ import { Header } from 'src/cli/tui/components/Header.tsx'
6
+ import { HostPanel } from 'src/cli/tui/components/HostPanel.tsx'
7
+ import { LorasOverlay } from 'src/cli/tui/components/LorasOverlay.tsx'
8
+ import { ChoiceOverlay, SizeOverlay } from 'src/cli/tui/components/PickerOverlays.tsx'
9
+ import { PreviewPanel } from 'src/cli/tui/components/PreviewPanel.tsx'
10
+ import { PromptOverlay } from 'src/cli/tui/components/PromptOverlay.tsx'
11
+ import { KeyBar, ProgressLine } from 'src/cli/tui/components/StatusBar.tsx'
12
+ import { TextOverlay } from 'src/cli/tui/components/TextOverlay.tsx'
13
+ import { TreePanel } from 'src/cli/tui/components/TreePanel.tsx'
14
+ import { VarsPanel } from 'src/cli/tui/components/VarsPanel.tsx'
15
+ import { parseModifyOtherKeysEnter } from 'src/cli/tui/keys.ts'
16
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
17
+
18
+ export const TuiApp = observer((p: { st: TuiSt }) => {
19
+ const app = useApp()
20
+ const s = p.st
21
+ const stdin = useStdin()
22
+
23
+ useInput(
24
+ (input, key) => {
25
+ // modifyOtherKeys terminals (vscode/xterm.js) deliver modified ⏎ as
26
+ // the unparsed literal '[27;<mods>;13~' — fold it back into key flags
27
+ // so every branch below sees a normal (modified) return
28
+ const modEnter = parseModifyOtherKeysEnter(input)
29
+ if (modEnter != null) {
30
+ input = ''
31
+ key = { ...key, ...modEnter }
32
+ }
33
+ // ⌃R runs from ANY mode (plain letters type into filters/editors)
34
+ if (key.ctrl && input === 'r') return void s.exec.run()
35
+ if (s.mode === 'edit' || s.mode === 'overlay-text') {
36
+ const ed = s.editor
37
+ const multi = s.mode === 'overlay-text'
38
+ if (key.escape) return ed.cancel()
39
+ if (multi && key.ctrl && input === 's') return ed.commitMultiline()
40
+ // ⏎ SAVES; newline via ⇧⏎ (kitty/modifyOtherKeys terminals) or ⌥⏎ (everywhere)
41
+ if (multi && key.return && (key.shift || key.meta)) return ed.newline()
42
+ if (key.return) return multi ? ed.commitMultiline() : ed.commitInline()
43
+ // word ops: alt+backspace (ESC-DEL) or ctrl+w
44
+ if ((key.meta && (key.backspace || key.delete)) || (key.ctrl && input === 'w')) return ed.deleteWordBack()
45
+ // mac sends backspace as 'delete' in some terminals — treat both as backspace
46
+ if (key.backspace || key.delete) return ed.backspace()
47
+ // word jumps: alt+arrows (ESC[1;3C/D) or ESC-b / ESC-f (option-as-meta)
48
+ if (key.meta && key.leftArrow) return ed.wordLeft()
49
+ if (key.meta && key.rightArrow) return ed.wordRight()
50
+ if (key.meta && input === 'b') return ed.wordLeft()
51
+ if (key.meta && input === 'f') return ed.wordRight()
52
+ // line ops: ⌘←→ (kitty terminals report ⌘ as super), Home/End, and
53
+ // ⌃A/⌃E — 'natural text editing' terminals (iTerm2 preset, VSCode on
54
+ // macOS) rewrite ⌘←/⌘→ to ^A/^E, so those MUST be line-wise too
55
+ if ((key.super && key.leftArrow) || key.home || (key.ctrl && input === 'a')) return ed.lineHome()
56
+ if ((key.super && key.rightArrow) || key.end || (key.ctrl && input === 'e')) return ed.lineEnd()
57
+ // ⌥↑↓ move the logical line (before plain ↑↓ cursor moves)
58
+ if (multi && key.meta && key.upArrow) return ed.moveLine(-1)
59
+ if (multi && key.meta && key.downArrow) return ed.moveLine(1)
60
+ // comment toggle: ⌘/ (kitty) · ⌃/ (kitty, or legacy 0x1f byte) · ⌥/
61
+ if (multi && input === '/' && (key.super || key.ctrl || key.meta)) return ed.toggleComment()
62
+ if (multi && input.length === 1 && input.charCodeAt(0) === 0x1f) return ed.toggleComment()
63
+ if (key.leftArrow) return ed.cursorLeft()
64
+ if (key.rightArrow) return ed.cursorRight()
65
+ if (multi && key.upArrow) return ed.cursorUp()
66
+ if (multi && key.downArrow) return ed.cursorDown()
67
+ if (key.ctrl && input === 'u') return ed.killToStart()
68
+ if (key.ctrl && input === 'k') return ed.killToEnd()
69
+ if (input && !key.ctrl && !key.meta) return ed.input(input)
70
+ return
71
+ }
72
+ if (s.mode === 'overlay-choice' || s.mode === 'overlay-size') {
73
+ const pk = s.picker
74
+ if (key.escape) return s.editor.cancel()
75
+ if (key.return) return pk.commit()
76
+ if (key.upArrow) return pk.move(-1)
77
+ if (key.downArrow) return pk.move(1)
78
+ if ((key.meta && (key.backspace || key.delete)) || (key.ctrl && input === 'w')) return pk.filterDeleteWord()
79
+ if (key.backspace || key.delete) return pk.filterBackspace()
80
+ if (input && !key.ctrl && !key.meta) return pk.filterInput(input)
81
+ return
82
+ }
83
+ if (s.mode === 'overlay-loras') {
84
+ const lo = s.loras
85
+ if (key.escape) return s.editor.cancel()
86
+ if (key.ctrl && input === 'a') return lo.setAll(true)
87
+ if (key.ctrl && input === 'n') return lo.setAll(false)
88
+ if (key.ctrl && input === 'k') return lo.beginKeyword()
89
+ if (key.return || input === ' ') return lo.toggle()
90
+ if (key.upArrow) return lo.move(-1)
91
+ if (key.downArrow) return lo.move(1)
92
+ if (key.leftArrow) return lo.adjust(-0.05)
93
+ if (key.rightArrow) return lo.adjust(0.05)
94
+ if ((key.meta && (key.backspace || key.delete)) || (key.ctrl && input === 'w')) return lo.filterDeleteWord()
95
+ if (key.backspace || key.delete) return lo.filterBackspace()
96
+ if (input && !key.ctrl && !key.meta) return lo.filterInput(input)
97
+ return
98
+ }
99
+ if (s.mode === 'tree') {
100
+ const tr = s.tree
101
+ if (key.escape || input === 't') return tr.blur()
102
+ if (key.return || input === ' ') return void tr.commit()
103
+ if (key.upArrow) return tr.move(-1)
104
+ if (key.downArrow) return tr.move(1)
105
+ if (key.leftArrow) return tr.fold()
106
+ if (key.rightArrow) return tr.unfold()
107
+ if (input === 'v') return tr.blur()
108
+ if (input === 'n') return tr.promptNewDraft()
109
+ if (input === 'e') return tr.draftOp('rename')
110
+ if (input === 'c') return tr.draftOp('duplicate')
111
+ if (input === 'x') return tr.draftOp('delete')
112
+ // global keys keep working from the tree (c is taken by duplicate)
113
+ if (input === 'r') return void s.exec.run()
114
+ if (input === 's') return s.exec.randomizeSeedAndRun()
115
+ if (input === 'd') return s.drafts.begin()
116
+ if (input === 'h') return s.host.begin()
117
+ if (input === 'p') return s.settings.cyclePreviewMode()
118
+ if (input === 'o') return s.exec.openLastOutput()
119
+ if (input === 'q') {
120
+ s.onExit()
121
+ return app.exit()
122
+ }
123
+ return
124
+ }
125
+ if (s.mode === 'host') {
126
+ const h = s.host
127
+ if (key.escape || input === 'h' || input === 'v') return h.blur()
128
+ if (key.return || input === ' ') return void h.commit()
129
+ if (key.upArrow) return h.move(-1)
130
+ if (key.downArrow) return h.move(1)
131
+ if (input === 'q') {
132
+ s.onExit()
133
+ return app.exit()
134
+ }
135
+ return
136
+ }
137
+ if (s.mode === 'overlay-drafts') {
138
+ const d = s.drafts
139
+ if (key.escape) return s.editor.cancel()
140
+ if (key.return) return d.commit()
141
+ if (key.upArrow) return d.move(-1)
142
+ if (key.downArrow) return d.move(1)
143
+ if (input === 'n') return d.promptNew('overlay-drafts')
144
+ if (input === 'e' && d.selectedName != null)
145
+ return d.promptRename(d.selectedName, undefined, 'overlay-drafts')
146
+ if (input === 'c' && d.selectedName != null)
147
+ return d.promptDuplicate(d.selectedName, undefined, 'overlay-drafts')
148
+ if (input === 'x' && d.selectedName != null) {
149
+ d.deleteDraft(d.selectedName)
150
+ return d.begin()
151
+ }
152
+ return
153
+ }
154
+ if (input === 'q') {
155
+ s.onExit()
156
+ return app.exit()
157
+ }
158
+ if (key.upArrow) return s.moveSel(-1)
159
+ if (key.downArrow) return s.moveSel(1)
160
+ // spatial nav: the tree lives on the left, editing on the right
161
+ if (key.leftArrow) return s.tree.focus()
162
+ if (key.rightArrow || key.return || input === ' ') return s.activate()
163
+ if (s.navKey(input)) return
164
+ if (input === 'e') return s.drafts.beginRename()
165
+ if (input === 'r') return void s.exec.run()
166
+ if (input === 's') return s.exec.randomizeSeedAndRun()
167
+ if (input === 't' || input === 'w') return s.tree.focus()
168
+ if (input === 'h') return s.host.begin()
169
+ if (input === 'd') return s.drafts.begin()
170
+ if (input === 'p') return s.settings.cyclePreviewMode()
171
+ if (input === 'o') return s.exec.openLastOutput()
172
+ if (input === 'c') return void s.exec.copyWorkflowJson()
173
+ if (input === 'C') return void s.exec.copyApiJson()
174
+ },
175
+ // render-only when the terminal can't do raw input (pipes, CI).
176
+ // strict boolean: ink only skips on `isActive === false`, and bun pipes
177
+ // report isTTY as undefined
178
+ { isActive: stdin.isRawModeSupported === true },
179
+ )
180
+
181
+ return (
182
+ <Box flexDirection="column" minHeight={s.termRows - 1}>
183
+ <Header st={s} />
184
+ <Box flexDirection="row" flexGrow={1}>
185
+ <TreePanel st={s} />
186
+ <Box flexDirection="column" flexGrow={1}>
187
+ {/* ink has no z-order: the overlay replaces the vars panel while open */}
188
+ {s.mode === 'edit' && s.editor.isCustom ? (
189
+ <PromptOverlay st={s} />
190
+ ) : s.mode === 'host' ? (
191
+ <HostPanel st={s} />
192
+ ) : s.mode === 'overlay-text' ? (
193
+ <TextOverlay st={s} />
194
+ ) : s.mode === 'overlay-choice' ? (
195
+ <ChoiceOverlay st={s} />
196
+ ) : s.mode === 'overlay-size' ? (
197
+ <SizeOverlay st={s} />
198
+ ) : s.mode === 'overlay-loras' ? (
199
+ <LorasOverlay st={s} />
200
+ ) : s.mode === 'overlay-drafts' ? (
201
+ <DraftsOverlay st={s} />
202
+ ) : (
203
+ <VarsPanel st={s} />
204
+ )}
205
+ <Box paddingX={1}>
206
+ <ProgressLine st={s} />
207
+ </Box>
208
+ {s.exec.outputs.length > 0 && (
209
+ <Box borderStyle="round" paddingX={1} flexDirection="column">
210
+ {s.exec.outputs.map((o) => (
211
+ <Text key={o} color="green" wrap="truncate">
212
+ {basename(o)} <Text color="gray">{o}</Text>
213
+ </Text>
214
+ ))}
215
+ </Box>
216
+ )}
217
+ </Box>
218
+ {s.preview.show && <PreviewPanel st={s} />}
219
+ </Box>
220
+ <KeyBar st={s} />
221
+ </Box>
222
+ )
223
+ })
@@ -0,0 +1,86 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import { EditField } from 'src/cli/tui/components/EditField.tsx'
4
+ import { type AnyVar, PromptVar } from 'src/vars/ComfyVars.ts'
5
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
6
+
7
+ // long values wrap INSIDE the value column, so wrapped lines never read as a
8
+ // new var row (repro: a wrapped prompt showed as 'prompt [textdrawing…').
9
+ const VALUE_CAP = 300
10
+
11
+ /** prompt value cell: magenta injected-keywords chrome line (not part of the
12
+ * text), `//` comments dim gray, `- ` negative lines red */
13
+ const PromptCell = observer((p: { varDef: PromptVar; value: string }) => {
14
+ const injected = p.varDef.injectedKeywords()
15
+ return (
16
+ <Box flexDirection="column">
17
+ {injected.length > 0 && (
18
+ <Text color="magenta" wrap="wrap">
19
+ ↳ loras: {injected.join(', ')}
20
+ </Text>
21
+ )}
22
+ {p.value.split('\n').map((line, ix) => {
23
+ const comment = PromptVar.isCommentLine(line)
24
+ const negative = !comment && PromptVar.isNegativeLine(line)
25
+ return (
26
+ <Text key={ix} color={comment ? 'gray' : negative ? 'red' : 'cyan'} dimColor={comment} wrap="wrap">
27
+ {line === '' ? ' ' : line}
28
+ </Text>
29
+ )
30
+ })}
31
+ </Box>
32
+ )
33
+ })
34
+
35
+ const VarRow = observer((p: { name: string; varDef: AnyVar; selected: boolean; labelW: number; st: TuiSt }) => {
36
+ // a custom prompt session (draft naming) renders as PromptOverlay, not here
37
+ const editing = p.selected && p.st.mode === 'edit' && !p.st.editor.isCustom
38
+ const label = p.varDef.label ?? p.name
39
+ const raw = p.varDef.display()
40
+ const value = raw.length > VALUE_CAP ? `${raw.slice(0, VALUE_CAP)}…` : raw
41
+ return (
42
+ <Box flexDirection="row">
43
+ {/* fixed columns keep wrapped value lines aligned under the value column */}
44
+ <Box width={p.labelW} flexShrink={0}>
45
+ <Text inverse={p.selected}>
46
+ {p.selected ? '▸ ' : ' '}
47
+ {label}
48
+ </Text>
49
+ </Box>
50
+ <Box width={9} flexShrink={0}>
51
+ <Text color="gray">[{p.varDef.kind}]</Text>
52
+ </Box>
53
+ <Box flexGrow={1}>
54
+ {editing ? (
55
+ <EditField st={p.st} />
56
+ ) : p.varDef instanceof PromptVar ? (
57
+ <PromptCell varDef={p.varDef} value={value} />
58
+ ) : (
59
+ <Text color="cyan" wrap="wrap">
60
+ {value}
61
+ </Text>
62
+ )}
63
+ </Box>
64
+ </Box>
65
+ )
66
+ })
67
+
68
+ export const VarsPanel = observer((p: { st: TuiSt }) => {
69
+ const s = p.st
70
+ // label column = longest label + marker, so [kind] and values line up
71
+ const labelW = Math.max(6, ...s.entries.map(([name, v]) => (v.label ?? name).length)) + 3
72
+ const focused = s.mode === 'nav' || s.mode === 'edit'
73
+ return (
74
+ <Box borderStyle="round" borderColor={focused ? 'cyan' : 'gray'} paddingX={1} flexDirection="column">
75
+ {/* marginTop -1 lifts the label onto the border line: the panel key IS its title */}
76
+ <Box marginTop={-1}>
77
+ <Text color={focused ? 'cyan' : 'gray'} bold={focused}>
78
+ (v)ars
79
+ </Text>
80
+ </Box>
81
+ {s.entries.map(([name, varDef], ix) => (
82
+ <VarRow key={name} name={name} varDef={varDef} selected={ix === s.selIx} labelW={labelW} st={s} />
83
+ ))}
84
+ </Box>
85
+ )
86
+ })
@@ -0,0 +1,16 @@
1
+ import { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'
2
+
3
+ /**
4
+ * instanceof first; duck-type fallback covers a second copy of the library in
5
+ * the module graph (linked dev setups, npm dedupe misses)
6
+ */
7
+ export function findDefinedWorkflow(mod: Record<string, unknown>): DefinedWorkflow | null {
8
+ const isDefined = (x: unknown): x is DefinedWorkflow =>
9
+ x instanceof DefinedWorkflow ||
10
+ (typeof x === 'object' &&
11
+ x != null &&
12
+ 'spec' in x &&
13
+ typeof (x as DefinedWorkflow).run === 'function' &&
14
+ typeof (x as DefinedWorkflow).entries === 'function')
15
+ return [mod.default, ...Object.values(mod)].find(isDefined) ?? null
16
+ }