comfy-ts 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +363 -0
- package/dist/cli.js +764 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +4171 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9910 -0
- package/dist/index.d.ts +9894 -58
- package/dist/index.js +4092 -2
- package/dist/index.js.map +1 -1
- package/dist/log-CdfgILde.js +10 -0
- package/dist/log-CdfgILde.js.map +1 -0
- package/dist/run-tui-SDSJo1Qf.js +3896 -0
- package/dist/run-tui-SDSJo1Qf.js.map +1 -0
- package/package.json +103 -75
- package/src/cli/comfy-ts-cli.ts +36 -0
- package/src/cli/gen.ts +47 -0
- package/src/cli/outline.ts +82 -0
- package/src/cli/tui/components/DraftsOverlay.tsx +44 -0
- package/src/cli/tui/components/EditField.tsx +27 -0
- package/src/cli/tui/components/Header.tsx +56 -0
- package/src/cli/tui/components/HostPanel.tsx +37 -0
- package/src/cli/tui/components/LogsPanel.tsx +23 -0
- package/src/cli/tui/components/LorasOverlay.tsx +49 -0
- package/src/cli/tui/components/OverlayList.tsx +25 -0
- package/src/cli/tui/components/PickerOverlays.tsx +66 -0
- package/src/cli/tui/components/PreviewPanel.tsx +78 -0
- package/src/cli/tui/components/PromptOverlay.tsx +16 -0
- package/src/cli/tui/components/StatusBar.tsx +171 -0
- package/src/cli/tui/components/TextOverlay.tsx +72 -0
- package/src/cli/tui/components/TreePanel.tsx +51 -0
- package/src/cli/tui/components/TuiApp.tsx +246 -0
- package/src/cli/tui/components/VarsPanel.tsx +86 -0
- package/src/cli/tui/findDefinedWorkflow.ts +16 -0
- package/src/cli/tui/keys.ts +20 -0
- package/src/cli/tui/protocolImagePainter.ts +95 -0
- package/src/cli/tui/run-tui.tsx +76 -0
- package/src/cli/tui/state/DraftsSt.ts +273 -0
- package/src/cli/tui/state/EditorSt.ts +289 -0
- package/src/cli/tui/state/ExecSt.ts +173 -0
- package/src/cli/tui/state/HostSt.ts +230 -0
- package/src/cli/tui/state/LogsSt.ts +107 -0
- package/src/cli/tui/state/LorasSt.ts +185 -0
- package/src/cli/tui/state/PickerSt.ts +112 -0
- package/src/cli/tui/state/PreviewSt.ts +288 -0
- package/src/cli/tui/state/QueueSt.ts +59 -0
- package/src/cli/tui/state/SettingsSt.ts +100 -0
- package/src/cli/tui/state/TreeSt.ts +122 -0
- package/src/cli/tui/state/TuiSt.ts +175 -0
- package/src/cli/tui/state/WorkflowsSt.ts +93 -0
- package/src/cli/tui-env.ts +8 -0
- package/src/errors/InvalidPromptError.ts +12 -0
- package/src/graph/ComfyNode.ts +403 -0
- package/src/graph/ComfyNodeID.ts +28 -0
- package/src/graph/ComfyNodeOutput.ts +16 -0
- package/src/graph/NodeSlotSize.ts +4 -0
- package/src/graph/autoValue.ts +17 -0
- package/src/host/ComfyHost.ts +690 -0
- package/src/host/ComfyInstallType.ts +15 -0
- package/src/host/ComfyManager.ts +232 -0
- package/src/host/ComfyUploader.ts +110 -0
- package/src/host/ComfyWorkflowBuilder.ts +60 -0
- package/src/host/Requirements.ts +55 -0
- package/src/host/ResilientWebsocket.ts +147 -0
- package/src/host/loraManagerApi.ts +98 -0
- package/src/image-utils/_getPngMetadata.ts +53 -0
- package/src/image-utils/_getWebpMetadata.ts +38 -0
- package/src/image-utils/_parseExifData.ts +53 -0
- package/src/index.ts +89 -0
- package/src/litegraph/LiteGraphGroup.ts +22 -0
- package/src/litegraph/LiteGraphJSON.ts +46 -0
- package/src/litegraph/LiteGraphLink.ts +23 -0
- package/src/litegraph/LiteGraphLinkID.ts +6 -0
- package/src/litegraph/LiteGraphNode.ts +69 -0
- package/src/litegraph/LiteGraphNodeInput.ts +27 -0
- package/src/litegraph/LiteGraphNodeOutput.ts +23 -0
- package/src/litegraph/LiteGraphSlotIndex.ts +6 -0
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +114 -0
- package/src/manager/ComfyRegistry.ts +124 -0
- package/src/manager/generated/KnownComfyCustomNodeName.ts +19280 -0
- package/src/manager/generated/KnownComfyPluginTitle.ts +5130 -0
- package/src/manager/generated/KnownComfyPluginURL.ts +2589 -0
- package/src/manager/generated/KnownModel_Base.ts +126 -0
- package/src/manager/generated/KnownModel_FileName.ts +2287 -0
- package/src/manager/generated/KnownModel_Name.ts +2287 -0
- package/src/manager/generated/KnownModel_SavePath.ts +263 -0
- package/src/manager/generated/KnownModel_Type.ts +97 -0
- package/src/manager/json/alter-list.json +224 -0
- package/src/manager/json/custom-node-list.extra.ts +13 -0
- package/src/manager/json/custom-node-list.json +21948 -0
- package/src/manager/json/extension-node-map.json +31282 -0
- package/src/manager/json/github-stats.json +12602 -0
- package/src/manager/json/model-list.extra.ts +26 -0
- package/src/manager/json/model-list.json +5052 -0
- package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +56 -0
- package/src/manager/loaders/step2_custom-node-list-loader.ts +149 -0
- package/src/manager/loaders/step3_extension-node-map-loader.ts +189 -0
- package/src/manager/loaders/step4_model-list-loader.ts +159 -0
- package/src/manager/script-update-manager.bun.ts +18 -0
- package/src/manager/types/ComfyManagerAPIFetchPolicy.ts +9 -0
- package/src/manager/types/ComfyManagerAPIModelList.ts +10 -0
- package/src/manager/types/ComfyManagerAPIPluginList.ts +11 -0
- package/src/manager/types/ComfyManagerFileModelInfo.ts +5 -0
- package/src/manager/types/ComfyManagerFilePluginContent.ts +13 -0
- package/src/manager/types/ComfyManagerFilePluginList.ts +5 -0
- package/src/manager/types/ComfyManagerModelInfo.ts +18 -0
- package/src/manager/types/ComfyManagerPluginContentMetadata.ts +16 -0
- package/src/manager/types/ComfyManagerPluginEnums.ts +8 -0
- package/src/manager/types/ComfyManagerPluginInfo.ts +50 -0
- package/src/runner/ComfyExecution.ts +301 -0
- package/src/runner/ComfyExecutionStatus.ts +2 -0
- package/src/runner/ComfyWorkflow.ts +395 -0
- package/src/runner/ComfyWorkflowLayout.ts +96 -0
- package/src/runner/ComfyWsApi.ts +170 -0
- package/src/runner/MediaImage.ts +262 -0
- package/src/sdk-generator/ComfyNodeSchema.ts +79 -0
- package/src/sdk-generator/ComfySchema.ts +369 -0
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +95 -0
- package/src/sdk-generator/Primitives.ts +76 -0
- package/src/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.ts +39 -0
- package/src/sdk-generator/_pythonModuleToNamespace.ts +27 -0
- package/src/sdk-generator/_toQualifiedNodeKey.ts +5 -0
- package/src/sdk-generator/comfy-api-json.ts +16 -0
- package/src/sdk-generator/comfyui-sdk-codegen.ts +287 -0
- package/src/sdk-generator/comfyui-types.ts +56 -0
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +157 -0
- package/src/ssh-host-manager/ssh-config-manager.ts +89 -0
- package/src/ssh-host-manager/ssh-config.windows.md +32 -0
- package/src/ssh-host-manager/ssh-manager.ts +114 -0
- package/src/state.ts +136 -0
- package/src/types/comfy-sdk.ts +106 -0
- package/src/types/index.ts +55 -0
- package/src/utils/CodeBuffer.ts +61 -0
- package/src/utils/ComfyColors.ts +38 -0
- package/src/utils/ansi.ts +33 -0
- package/src/utils/ansiImage.ts +36 -0
- package/src/utils/bang.ts +39 -0
- package/src/utils/deepCopyNaive.ts +1 -0
- package/src/utils/downloadFile.ts +77 -0
- package/src/utils/escapeJSKey.ts +32 -0
- package/src/utils/exhaust.ts +4 -0
- package/src/utils/extractErrorMessage.ts +11 -0
- package/src/utils/fuzzyMatch.ts +8 -0
- package/src/utils/githubRegexes.ts +2 -0
- package/src/utils/hashArrayBuffer.ts +6 -0
- package/src/utils/log.ts +9 -0
- package/src/utils/loraTag.ts +10 -0
- package/src/utils/mojibake.ts +60 -0
- package/src/utils/printArkResultInConsole.ts +16 -0
- package/src/utils/softValidate.ts +8 -0
- package/src/utils/stringifyReadable.ts +32 -0
- package/src/utils/toposort.ts +59 -0
- package/src/utils/tryExtracting.ts +41 -0
- package/src/utils/writeFile.ts +16 -0
- package/src/vars/ComfyVars.ts +531 -0
- package/src/vars/DefinedWorkflow.ts +112 -0
- package/src/vars/loraKeywords.ts +56 -0
- package/dist/index.d.mts +0 -74
- package/dist/index.mjs +0 -3
- package/dist/index.mjs.map +0 -1
- package/readme.md +0 -40
|
@@ -0,0 +1,246 @@
|
|
|
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 { LogsPanel } from 'src/cli/tui/components/LogsPanel.tsx'
|
|
13
|
+
import { TextOverlay } from 'src/cli/tui/components/TextOverlay.tsx'
|
|
14
|
+
import { TreePanel } from 'src/cli/tui/components/TreePanel.tsx'
|
|
15
|
+
import { VarsPanel } from 'src/cli/tui/components/VarsPanel.tsx'
|
|
16
|
+
import { parseModifyOtherKeysEnter } from 'src/cli/tui/keys.ts'
|
|
17
|
+
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
18
|
+
|
|
19
|
+
export const TuiApp = observer((p: { st: TuiSt }) => {
|
|
20
|
+
const app = useApp()
|
|
21
|
+
const s = p.st
|
|
22
|
+
const stdin = useStdin()
|
|
23
|
+
|
|
24
|
+
useInput(
|
|
25
|
+
(input, key) => {
|
|
26
|
+
// modifyOtherKeys terminals (vscode/xterm.js) deliver modified ⏎ as
|
|
27
|
+
// the unparsed literal '[27;<mods>;13~' — fold it back into key flags
|
|
28
|
+
// so every branch below sees a normal (modified) return
|
|
29
|
+
const modEnter = parseModifyOtherKeysEnter(input)
|
|
30
|
+
if (modEnter != null) {
|
|
31
|
+
input = ''
|
|
32
|
+
key = { ...key, ...modEnter }
|
|
33
|
+
}
|
|
34
|
+
// ⌃R runs from ANY mode (plain letters type into filters/editors)
|
|
35
|
+
if (key.ctrl && input === 'r') return void s.exec.run()
|
|
36
|
+
if (s.mode === 'edit' || s.mode === 'overlay-text') {
|
|
37
|
+
const ed = s.editor
|
|
38
|
+
const multi = s.mode === 'overlay-text'
|
|
39
|
+
if (key.escape) return ed.cancel()
|
|
40
|
+
if (multi && key.ctrl && input === 's') return ed.commitMultiline()
|
|
41
|
+
// ⏎ SAVES; newline via ⇧⏎ (kitty/modifyOtherKeys terminals) or ⌥⏎ (everywhere)
|
|
42
|
+
if (multi && key.return && (key.shift || key.meta)) return ed.newline()
|
|
43
|
+
if (key.return) return multi ? ed.commitMultiline() : ed.commitInline()
|
|
44
|
+
// word ops: alt+backspace (ESC-DEL) or ctrl+w
|
|
45
|
+
if ((key.meta && (key.backspace || key.delete)) || (key.ctrl && input === 'w')) return ed.deleteWordBack()
|
|
46
|
+
// mac sends backspace as 'delete' in some terminals — treat both as backspace
|
|
47
|
+
if (key.backspace || key.delete) return ed.backspace()
|
|
48
|
+
// word jumps: alt+arrows (ESC[1;3C/D) or ESC-b / ESC-f (option-as-meta)
|
|
49
|
+
if (key.meta && key.leftArrow) return ed.wordLeft()
|
|
50
|
+
if (key.meta && key.rightArrow) return ed.wordRight()
|
|
51
|
+
if (key.meta && input === 'b') return ed.wordLeft()
|
|
52
|
+
if (key.meta && input === 'f') return ed.wordRight()
|
|
53
|
+
// line ops: ⌘←→ (kitty terminals report ⌘ as super), Home/End, and
|
|
54
|
+
// ⌃A/⌃E — 'natural text editing' terminals (iTerm2 preset, VSCode on
|
|
55
|
+
// macOS) rewrite ⌘←/⌘→ to ^A/^E, so those MUST be line-wise too
|
|
56
|
+
if ((key.super && key.leftArrow) || key.home || (key.ctrl && input === 'a')) return ed.lineHome()
|
|
57
|
+
if ((key.super && key.rightArrow) || key.end || (key.ctrl && input === 'e')) return ed.lineEnd()
|
|
58
|
+
// ⌥↑↓ move the logical line (before plain ↑↓ cursor moves)
|
|
59
|
+
if (multi && key.meta && key.upArrow) return ed.moveLine(-1)
|
|
60
|
+
if (multi && key.meta && key.downArrow) return ed.moveLine(1)
|
|
61
|
+
// comment toggle: ⌘/ (kitty) · ⌃/ (kitty, or legacy 0x1f byte) · ⌥/
|
|
62
|
+
if (multi && input === '/' && (key.super || key.ctrl || key.meta)) return ed.toggleComment()
|
|
63
|
+
if (multi && input.length === 1 && input.charCodeAt(0) === 0x1f) return ed.toggleComment()
|
|
64
|
+
if (key.leftArrow) return ed.cursorLeft()
|
|
65
|
+
if (key.rightArrow) return ed.cursorRight()
|
|
66
|
+
if (multi && key.upArrow) return ed.cursorUp()
|
|
67
|
+
if (multi && key.downArrow) return ed.cursorDown()
|
|
68
|
+
if (key.ctrl && input === 'u') return ed.killToStart()
|
|
69
|
+
if (key.ctrl && input === 'k') return ed.killToEnd()
|
|
70
|
+
if (input && !key.ctrl && !key.meta) return ed.input(input)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
if (s.mode === 'overlay-choice' || s.mode === 'overlay-size') {
|
|
74
|
+
const pk = s.picker
|
|
75
|
+
if (key.escape) return s.editor.cancel()
|
|
76
|
+
if (key.return) return pk.commit()
|
|
77
|
+
if (key.upArrow) return pk.move(-1)
|
|
78
|
+
if (key.downArrow) return pk.move(1)
|
|
79
|
+
if ((key.meta && (key.backspace || key.delete)) || (key.ctrl && input === 'w')) return pk.filterDeleteWord()
|
|
80
|
+
if (key.backspace || key.delete) return pk.filterBackspace()
|
|
81
|
+
if (input && !key.ctrl && !key.meta) return pk.filterInput(input)
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
if (s.mode === 'overlay-loras') {
|
|
85
|
+
const lo = s.loras
|
|
86
|
+
if (key.escape) return s.editor.cancel()
|
|
87
|
+
if (key.ctrl && input === 'a') return lo.setAll(true)
|
|
88
|
+
if (key.ctrl && input === 'n') return lo.setAll(false)
|
|
89
|
+
if (key.ctrl && input === 'k') return lo.beginKeyword()
|
|
90
|
+
if (key.return || input === ' ') return lo.toggle()
|
|
91
|
+
if (key.upArrow) return lo.move(-1)
|
|
92
|
+
if (key.downArrow) return lo.move(1)
|
|
93
|
+
if (key.leftArrow) return lo.adjust(-0.05)
|
|
94
|
+
if (key.rightArrow) return lo.adjust(0.05)
|
|
95
|
+
if ((key.meta && (key.backspace || key.delete)) || (key.ctrl && input === 'w')) return lo.filterDeleteWord()
|
|
96
|
+
if (key.backspace || key.delete) return lo.filterBackspace()
|
|
97
|
+
if (input && !key.ctrl && !key.meta) return lo.filterInput(input)
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
if (s.mode === 'tree') {
|
|
101
|
+
const tr = s.tree
|
|
102
|
+
if (key.escape || input === 't') return tr.blur()
|
|
103
|
+
if (key.return || input === ' ') return void tr.commit()
|
|
104
|
+
if (key.upArrow) return tr.move(-1)
|
|
105
|
+
if (key.downArrow) return tr.move(1)
|
|
106
|
+
if (key.leftArrow) return tr.fold()
|
|
107
|
+
if (key.rightArrow) return tr.unfold()
|
|
108
|
+
if (input === 'v') return tr.blur()
|
|
109
|
+
if (input === 'n') return tr.promptNewDraft()
|
|
110
|
+
if (input === 'e') return tr.draftOp('rename')
|
|
111
|
+
if (input === 'c') return tr.draftOp('duplicate')
|
|
112
|
+
if (input === 'x') return tr.draftOp('delete')
|
|
113
|
+
// global keys keep working from the tree (c is taken by duplicate)
|
|
114
|
+
if (input === 'r') return void s.exec.run()
|
|
115
|
+
if (input === 's') return s.exec.randomizeSeedAndRun()
|
|
116
|
+
if (input === 'd') return s.drafts.begin()
|
|
117
|
+
if (input === 'h') return s.host.begin()
|
|
118
|
+
if (input === 'p') return s.preview.beginMenu()
|
|
119
|
+
if (input === 'o') return s.exec.openLastOutput()
|
|
120
|
+
if (input === 'q') {
|
|
121
|
+
s.onExit()
|
|
122
|
+
return app.exit()
|
|
123
|
+
}
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
if (s.mode === 'host') {
|
|
127
|
+
const h = s.host
|
|
128
|
+
if (key.escape || input === 'h' || input === 'v') return h.blur()
|
|
129
|
+
if (key.return || input === ' ') return void h.commit()
|
|
130
|
+
if (key.upArrow) return h.move(-1)
|
|
131
|
+
if (key.downArrow) return h.move(1)
|
|
132
|
+
if (input === 'q') {
|
|
133
|
+
s.onExit()
|
|
134
|
+
return app.exit()
|
|
135
|
+
}
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
if (s.mode === 'preview') {
|
|
139
|
+
const pv = s.preview
|
|
140
|
+
// ⏎ CONFIRMS (closes): ←→ already changed the value in place
|
|
141
|
+
if (key.escape || key.return || input === 'p' || input === 'v') return pv.blurMenu()
|
|
142
|
+
if (key.upArrow) return pv.menuMove(-1)
|
|
143
|
+
if (key.downArrow) return pv.menuMove(1)
|
|
144
|
+
if (key.leftArrow) return pv.menuCycle(-1)
|
|
145
|
+
if (key.rightArrow || input === ' ') return pv.menuCycle(1)
|
|
146
|
+
// global keys keep working from the menu (mirrors the tree)
|
|
147
|
+
if (input === 'r') return void s.exec.run()
|
|
148
|
+
if (input === 's') return s.exec.randomizeSeedAndRun()
|
|
149
|
+
if (input === 'd') return s.drafts.begin()
|
|
150
|
+
if (input === 'h') return s.host.begin()
|
|
151
|
+
if (input === 'o') return s.exec.openLastOutput()
|
|
152
|
+
if (input === 'q') {
|
|
153
|
+
s.onExit()
|
|
154
|
+
return app.exit()
|
|
155
|
+
}
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
if (s.mode === 'overlay-drafts') {
|
|
159
|
+
const d = s.drafts
|
|
160
|
+
if (key.escape) return s.editor.cancel()
|
|
161
|
+
if (key.return) return d.commit()
|
|
162
|
+
if (key.upArrow) return d.move(-1)
|
|
163
|
+
if (key.downArrow) return d.move(1)
|
|
164
|
+
if (input === 'n') return d.promptNew('overlay-drafts')
|
|
165
|
+
if (input === 'e' && d.selectedName != null)
|
|
166
|
+
return d.promptRename(d.selectedName, undefined, 'overlay-drafts')
|
|
167
|
+
if (input === 'c' && d.selectedName != null)
|
|
168
|
+
return d.promptDuplicate(d.selectedName, undefined, 'overlay-drafts')
|
|
169
|
+
if (input === 'x' && d.selectedName != null) {
|
|
170
|
+
d.deleteDraft(d.selectedName)
|
|
171
|
+
return d.begin()
|
|
172
|
+
}
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
if (input === 'q') {
|
|
176
|
+
s.onExit()
|
|
177
|
+
return app.exit()
|
|
178
|
+
}
|
|
179
|
+
if (key.upArrow) return s.moveSel(-1)
|
|
180
|
+
if (key.downArrow) return s.moveSel(1)
|
|
181
|
+
// spatial nav: the tree lives on the left, editing on the right
|
|
182
|
+
if (key.leftArrow) return s.tree.focus()
|
|
183
|
+
if (key.rightArrow || key.return || input === ' ') return s.activate()
|
|
184
|
+
if (s.navKey(input)) return
|
|
185
|
+
if (input === 'e') return s.drafts.beginRename()
|
|
186
|
+
if (input === 'r') return void s.exec.run()
|
|
187
|
+
if (input === 's') return s.exec.randomizeSeedAndRun()
|
|
188
|
+
if (input === 't' || input === 'w') return s.tree.focus()
|
|
189
|
+
if (input === 'h') return s.host.begin()
|
|
190
|
+
if (input === 'd') return s.drafts.begin()
|
|
191
|
+
if (input === 'p') return s.preview.beginMenu()
|
|
192
|
+
if (input === 'o') return s.exec.openLastOutput()
|
|
193
|
+
if (input === 'c') return void s.exec.copyWorkflowJson()
|
|
194
|
+
if (input === 'C') return void s.exec.copyApiJson()
|
|
195
|
+
},
|
|
196
|
+
// render-only when the terminal can't do raw input (pipes, CI).
|
|
197
|
+
// strict boolean: ink only skips on `isActive === false`, and bun pipes
|
|
198
|
+
// report isTTY as undefined
|
|
199
|
+
{ isActive: stdin.isRawModeSupported === true },
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<Box flexDirection="column" minHeight={s.termRows - 1}>
|
|
204
|
+
<Header st={s} />
|
|
205
|
+
<Box flexDirection="row" flexGrow={1}>
|
|
206
|
+
<TreePanel st={s} />
|
|
207
|
+
<Box flexDirection="column" flexGrow={1}>
|
|
208
|
+
{/* ink has no z-order: the overlay replaces the vars panel while open */}
|
|
209
|
+
{s.mode === 'edit' && s.editor.isCustom ? (
|
|
210
|
+
<PromptOverlay st={s} />
|
|
211
|
+
) : s.mode === 'host' ? (
|
|
212
|
+
<HostPanel st={s} />
|
|
213
|
+
) : s.mode === 'overlay-text' ? (
|
|
214
|
+
<TextOverlay st={s} />
|
|
215
|
+
) : s.mode === 'overlay-choice' ? (
|
|
216
|
+
<ChoiceOverlay st={s} />
|
|
217
|
+
) : s.mode === 'overlay-size' ? (
|
|
218
|
+
<SizeOverlay st={s} />
|
|
219
|
+
) : s.mode === 'overlay-loras' ? (
|
|
220
|
+
<LorasOverlay st={s} />
|
|
221
|
+
) : s.mode === 'overlay-drafts' ? (
|
|
222
|
+
<DraftsOverlay st={s} />
|
|
223
|
+
) : (
|
|
224
|
+
<VarsPanel st={s} />
|
|
225
|
+
)}
|
|
226
|
+
<Box paddingX={1}>
|
|
227
|
+
<ProgressLine st={s} />
|
|
228
|
+
</Box>
|
|
229
|
+
{s.exec.outputs.length > 0 && (
|
|
230
|
+
<Box borderStyle="round" paddingX={1} flexDirection="column">
|
|
231
|
+
{s.exec.outputs.map((o) => (
|
|
232
|
+
<Text key={o} color="green" wrap="truncate">
|
|
233
|
+
{basename(o)} <Text color="gray">{o}</Text>
|
|
234
|
+
</Text>
|
|
235
|
+
))}
|
|
236
|
+
</Box>
|
|
237
|
+
)}
|
|
238
|
+
{/* hidden while an overlay owns the vars area: typing space > logs */}
|
|
239
|
+
{!s.mode.startsWith('overlay-') && !(s.mode === 'edit' && s.editor.isCustom) && <LogsPanel st={s} />}
|
|
240
|
+
</Box>
|
|
241
|
+
{(s.preview.show || s.preview.menuOpen) && <PreviewPanel st={s} />}
|
|
242
|
+
</Box>
|
|
243
|
+
<KeyBar st={s} />
|
|
244
|
+
</Box>
|
|
245
|
+
)
|
|
246
|
+
})
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** the key flags a modified-⏎ translation produces (subset of ink's Key) */
|
|
2
|
+
export type EnterKeyBits = { return: boolean; shift: boolean; meta: boolean; ctrl: boolean }
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* xterm modifyOtherKeys (vscode/xterm.js — enabled by run-tui via `CSI > 4;1 m`)
|
|
6
|
+
* encodes modified ⏎ as `CSI 27;<mods>;13~`. ink 7 leaves that sequence
|
|
7
|
+
* unparsed: it reaches useInput as the LITERAL input `[27;<mods>;13~` with no
|
|
8
|
+
* key flags, which would otherwise be typed into editors/filters. Translate it
|
|
9
|
+
* back into return + modifier bits (mods is xterm's modifier-1 bitfield:
|
|
10
|
+
* 1 shift · 2 alt · 4 ctrl · 8 meta — alt|meta fold into ink's `meta`, same
|
|
11
|
+
* mask ink uses for legacy fn-keys). Kitty-protocol terminals never hit this:
|
|
12
|
+
* their `CSI 13;2u` is parsed natively by ink. Returns null when `input` is
|
|
13
|
+
* not a modified enter.
|
|
14
|
+
*/
|
|
15
|
+
export function parseModifyOtherKeysEnter(input: string): EnterKeyBits | null {
|
|
16
|
+
const m = /^\[27;(\d+);13~$/.exec(input)
|
|
17
|
+
if (m == null) return null
|
|
18
|
+
const mods = Number(m[1]) - 1
|
|
19
|
+
return { return: true, shift: (mods & 1) !== 0, meta: (mods & 10) !== 0, ctrl: (mods & 4) !== 0 }
|
|
20
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { reaction } from 'mobx'
|
|
2
|
+
import { protocolCapable } from 'src/cli/tui/state/PreviewSt.ts'
|
|
3
|
+
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
4
|
+
|
|
5
|
+
type WriteCb = (err?: Error | null) => void
|
|
6
|
+
|
|
7
|
+
const SYNC_BEGIN = '\u001b[?2026h'
|
|
8
|
+
const SYNC_END = '\u001b[?2026l'
|
|
9
|
+
/** below this a write is a terminal query/reply, not a frame — no cells damaged */
|
|
10
|
+
const MIN_FRAME_BYTES = 64
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* paints the REAL image (OSC 1337) over the preview panel's cell rect.
|
|
14
|
+
* Protocol images cannot go THROUGH ink (layout shreds the escape) and every
|
|
15
|
+
* ink frame write ERASES the image's cells — so this hooks stdout.write and
|
|
16
|
+
* re-paints SYNCHRONOUSLY within the same flush, the whole batch wrapped in
|
|
17
|
+
* DEC 2026 synchronized-update markers: the terminal never presents the
|
|
18
|
+
* erased-frame intermediate state. (The previous deferred setImmediate
|
|
19
|
+
* repaint WAS the native-mode flicker — his repro.) A mobx reaction covers
|
|
20
|
+
* byte-only changes (fresh latent/output/lora bytes with no frame write).
|
|
21
|
+
* NOT React: effects only fire for the component that re-rendered, which is
|
|
22
|
+
* why a useEffect painter missed frames (his report: image waited for input).
|
|
23
|
+
*/
|
|
24
|
+
export function installProtocolImagePainter(st: TuiSt): () => void {
|
|
25
|
+
// capability, not current setting: the menu can switch to native at any
|
|
26
|
+
// time — imageEscapes() is empty while pixel/hidden, so painting no-ops
|
|
27
|
+
if (!protocolCapable() || process.stdout.isTTY !== true) return () => {}
|
|
28
|
+
const original = process.stdout.write.bind(process.stdout)
|
|
29
|
+
|
|
30
|
+
const imageEscape = (bytes: Uint8Array, row: number, col: number, w: number, h: number): string => {
|
|
31
|
+
const b64 = Buffer.from(bytes).toString('base64')
|
|
32
|
+
// cursor save → CUP → image sized in CELLS → cursor restore
|
|
33
|
+
return `\u001b7\u001b[${row};${col}H\u001b]1337;File=inline=1;size=${bytes.byteLength};width=${w};height=${h};preserveAspectRatio=1:${b64}\u0007\u001b8`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// first image row: header(3) + panel border(1) + 1 content row — row 6,
|
|
37
|
+
// calibrated by playtest on iTerm2 (2026-07-27: row 5 painted one line too high)
|
|
38
|
+
const CONTENT_ROW = 6
|
|
39
|
+
|
|
40
|
+
/** both images as ONE escape string ('' when nothing to paint) */
|
|
41
|
+
const imageEscapes = (): string => {
|
|
42
|
+
const pv = st.preview
|
|
43
|
+
const main = pv.protocolImage
|
|
44
|
+
const corner = pv.protocolImageCorner
|
|
45
|
+
if (main == null && corner == null) return ''
|
|
46
|
+
// panel outer left edge +1 border +1 padding
|
|
47
|
+
const col = Math.max(1, st.termCols - (pv.width + 4) + 3)
|
|
48
|
+
let out = ''
|
|
49
|
+
if (main != null) out += imageEscape(main, CONTENT_ROW, col, pv.width, pv.height)
|
|
50
|
+
// small latent AFTER the big image so it stays on top; its cell box
|
|
51
|
+
// matches the latent's aspect (cornerBox) — a mismatched rect letterboxes
|
|
52
|
+
if (corner != null) {
|
|
53
|
+
const box = pv.cornerBox
|
|
54
|
+
out += imageEscape(corner, CONTENT_ROW, col + pv.width - box.w, box.w, box.h)
|
|
55
|
+
}
|
|
56
|
+
return out
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// disposed kills PENDING paints too: a repaint queued around ink's final
|
|
60
|
+
// frame must never fire after the alt-screen restore (ghost image after q)
|
|
61
|
+
let disposed = false
|
|
62
|
+
|
|
63
|
+
/** byte-only changes (no frame write erased anything): paint alone, atomically */
|
|
64
|
+
let scheduled = false
|
|
65
|
+
const schedule = (): void => {
|
|
66
|
+
if (scheduled || disposed) return
|
|
67
|
+
scheduled = true
|
|
68
|
+
setImmediate(() => {
|
|
69
|
+
scheduled = false
|
|
70
|
+
if (disposed) return
|
|
71
|
+
const images = imageEscapes()
|
|
72
|
+
if (images !== '') original(SYNC_BEGIN + images + SYNC_END)
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// cast: whitelist item 8 (agent/coding.md) — reimplements the exact overload set
|
|
77
|
+
const patched = ((chunk: Uint8Array | string, encodingOrCb?: BufferEncoding | WriteCb, cb?: WriteCb): boolean => {
|
|
78
|
+
// frame writes damage the image cells: repaint in the SAME flush, the
|
|
79
|
+
// whole batch synchronized so no intermediate state is ever presented
|
|
80
|
+
const isFrame = !disposed && (typeof chunk === 'string' ? chunk.length : chunk.byteLength) >= MIN_FRAME_BYTES
|
|
81
|
+
const images = isFrame ? imageEscapes() : ''
|
|
82
|
+
if (images !== '') original(SYNC_BEGIN)
|
|
83
|
+
const res = typeof encodingOrCb === 'function' ? original(chunk, encodingOrCb) : original(chunk, encodingOrCb, cb)
|
|
84
|
+
if (images !== '') original(images + SYNC_END)
|
|
85
|
+
return res
|
|
86
|
+
}) as typeof process.stdout.write
|
|
87
|
+
|
|
88
|
+
process.stdout.write = patched
|
|
89
|
+
const disposeReaction = reaction(() => [st.preview.protocolImage, st.preview.protocolImageCorner], schedule)
|
|
90
|
+
return () => {
|
|
91
|
+
disposed = true
|
|
92
|
+
process.stdout.write = original
|
|
93
|
+
disposeReaction()
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readdirSync, statSync } from 'node:fs'
|
|
2
|
+
import { pathToFileURL } from 'node:url'
|
|
3
|
+
import { render } from 'ink'
|
|
4
|
+
import { dirname, join, resolve } from 'pathe'
|
|
5
|
+
import { COMFY_TS_TUI_ENV } from 'src/cli/tui-env.ts'
|
|
6
|
+
import { findDefinedWorkflow } from 'src/cli/tui/findDefinedWorkflow.ts'
|
|
7
|
+
import { installProtocolImagePainter } from 'src/cli/tui/protocolImagePainter.ts'
|
|
8
|
+
import { TuiApp } from 'src/cli/tui/components/TuiApp.tsx'
|
|
9
|
+
import { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
10
|
+
|
|
11
|
+
/** recursive scan for the workflow-module naming convention */
|
|
12
|
+
function scanCflowFiles(dir: string): string[] {
|
|
13
|
+
const hits = readdirSync(dir, { recursive: true })
|
|
14
|
+
.map((f) => join(dir, String(f)))
|
|
15
|
+
.filter((f) => f.endsWith('.cflow.ts') || f.endsWith('.cflow.tsx'))
|
|
16
|
+
return hits.sort()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function runTui(args: string[]): Promise<number> {
|
|
20
|
+
// no arg = scan cwd; a file arg ALSO scans its folder (file preselected)
|
|
21
|
+
const target = args.find((a) => !a.startsWith('--')) ?? '.'
|
|
22
|
+
|
|
23
|
+
// the module contract: files check `import.meta.main` (false here) so their
|
|
24
|
+
// standalone run block is skipped; this env var covers in-run tweaks
|
|
25
|
+
process.env[COMFY_TS_TUI_ENV] = '1'
|
|
26
|
+
process.env.COMFY_TS_QUIET = '1' // info chatter off; the TUI owns the screen
|
|
27
|
+
|
|
28
|
+
const abs = resolve(target)
|
|
29
|
+
const isDir = statSync(abs).isDirectory()
|
|
30
|
+
const scanned = scanCflowFiles(isDir ? abs : dirname(abs))
|
|
31
|
+
const workflowFiles = isDir || scanned.includes(abs) ? scanned : [abs, ...scanned]
|
|
32
|
+
const first = isDir ? workflowFiles[0] : abs
|
|
33
|
+
if (first == null) {
|
|
34
|
+
console.error(`[comfy-ts tui] no **/*.cflow.ts found under ${abs}`)
|
|
35
|
+
return 1
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const mod: Record<string, unknown> = await import(pathToFileURL(first).href)
|
|
39
|
+
const wf = findDefinedWorkflow(mod)
|
|
40
|
+
if (wf == null) {
|
|
41
|
+
console.error(
|
|
42
|
+
`[comfy-ts tui] ${first} exports no DefinedWorkflow — export the result of host.defineWorkflow(...)`,
|
|
43
|
+
)
|
|
44
|
+
return 1
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const st = new TuiSt(wf, { workflowFiles, currentFile: first })
|
|
48
|
+
// ALT SCREEN (TTY only): deterministic absolute coordinates for the protocol
|
|
49
|
+
// image painter + no scrollback pollution / clipped first row.
|
|
50
|
+
// modifyOtherKeys mode 1 rides along: vscode/xterm.js then ENCODES modified ⏎
|
|
51
|
+
// (so ⇧⏎ stops arriving as a plain-`\r` commit) as `CSI 27;mods;13~` —
|
|
52
|
+
// translated in TuiApp via keys.ts. Mode 1 only touches keys without
|
|
53
|
+
// well-known sequences (mode 2 would re-encode ctrl+letters and break the
|
|
54
|
+
// editor keys); unsupporting terminals ignore it.
|
|
55
|
+
const altScreen = process.stdout.isTTY === true
|
|
56
|
+
if (altScreen) process.stdout.write('\u001b[?1049h\u001b[H\u001b[>4;1m')
|
|
57
|
+
// REAL images over the preview panel rect on OSC-1337 terminals (repaints
|
|
58
|
+
// after every stdout flush + on image change — NOT a React effect)
|
|
59
|
+
const uninstallPainter = installProtocolImagePainter(st)
|
|
60
|
+
try {
|
|
61
|
+
// kittyKeyboard auto: ink queries `CSI ? u` and enables CSI-u encoding
|
|
62
|
+
// where supported (iTerm2 3.5+/WezTerm/kitty/ghostty) — ⇧⏎ parsed natively
|
|
63
|
+
const app = render(<TuiApp st={st} />, { kittyKeyboard: { mode: 'auto' } })
|
|
64
|
+
// dispose: flush reactions/listeners + close every ws opened by loaded modules
|
|
65
|
+
st.onExit = () => st.dispose()
|
|
66
|
+
await app.waitUntilExit()
|
|
67
|
+
st.dispose()
|
|
68
|
+
} finally {
|
|
69
|
+
uninstallPainter()
|
|
70
|
+
// reset colors + erase WHILE STILL in the alt screen: ED deletes iTerm
|
|
71
|
+
// inline images too — without this the last protocol image and stray
|
|
72
|
+
// background colors survive into the shell (his repro)
|
|
73
|
+
if (altScreen) process.stdout.write('\u001b[0m\u001b[2J\u001b[H\u001b[>4;0m\u001b[?1049l')
|
|
74
|
+
}
|
|
75
|
+
return 0
|
|
76
|
+
}
|