comfy-ts 2.0.0 → 2.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.
- package/README.md +65 -225
- package/dist/{DefinedWorkflow-CqNE_kgR.js → DefinedWorkflow-CwHInZgn.js} +4 -3
- package/dist/DefinedWorkflow-CwHInZgn.js.map +1 -0
- package/dist/{DraftsSt-Da4DZUP7.js → DraftsSt-omWuBSej.js} +3 -4
- package/dist/DraftsSt-omWuBSej.js.map +1 -0
- package/dist/cli.js +3 -3
- package/dist/index.cjs +22 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +22 -5
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-BqeXtf8P.js → run-serve-C1oo5ilG.js} +170 -126
- package/dist/run-serve-C1oo5ilG.js.map +1 -0
- package/dist/{run-tui-CiB7TbYv.js → run-tui-CuVst-nc.js} +298 -103
- package/dist/run-tui-CuVst-nc.js.map +1 -0
- package/dist/{state-C1g_B8zR.js → state-CvMt0W1-.js} +23 -7
- package/dist/state-CvMt0W1-.js.map +1 -0
- package/dist/web.d.ts +12 -2
- package/dist/web.js +22 -5
- package/dist/web.js.map +1 -1
- package/examples/README.md +6 -18
- package/examples/images/README.md +2 -6
- package/guide-for-agents.md +25 -84
- package/package.json +1 -1
- package/src/cli/serve/ServeApp.ts +17 -11
- package/src/cli/serve/applyVarPayload.ts +91 -71
- package/src/cli/serve/describeVar.ts +57 -28
- package/src/cli/tui/components/StatusBar.tsx +1 -0
- package/src/cli/tui/components/TextOverlay.tsx +7 -3
- package/src/cli/tui/components/TuiApp.tsx +4 -5
- package/src/cli/tui/components/VarsPanel.tsx +42 -4
- package/src/cli/tui/imageClipboard.ts +40 -0
- package/src/cli/tui/state/DraftsSt.ts +1 -2
- package/src/cli/tui/state/ExecSt.ts +146 -98
- package/src/cli/tui/state/PreviewSt.ts +12 -11
- package/src/cli/tui/state/SettingsSt.ts +13 -0
- package/src/cli/tui/state/TuiSt.ts +65 -11
- package/src/host/ComfyHost.ts +5 -1
- package/src/runner/ComfyExecution.ts +15 -7
- package/src/runner/outputPath.ts +11 -0
- package/src/vars/ComfyVars.ts +12 -2
- package/dist/DefinedWorkflow-CqNE_kgR.js.map +0 -1
- package/dist/DraftsSt-Da4DZUP7.js.map +0 -1
- package/dist/run-serve-BqeXtf8P.js.map +0 -1
- package/dist/run-tui-CiB7TbYv.js.map +0 -1
- package/dist/state-C1g_B8zR.js.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Box, Text, useApp, useInput, useStdin } from 'ink'
|
|
2
2
|
import { observer } from 'mobx-react-lite'
|
|
3
|
-
import { basename } from 'pathe'
|
|
4
3
|
import { CopyOverlay } from 'src/cli/tui/components/CopyOverlay.tsx'
|
|
5
4
|
import { DraftsOverlay } from 'src/cli/tui/components/DraftsOverlay.tsx'
|
|
6
5
|
import { Header } from 'src/cli/tui/components/Header.tsx'
|
|
@@ -291,11 +290,11 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
|
|
|
291
290
|
<Box paddingX={1}>
|
|
292
291
|
<ProgressLine st={s} />
|
|
293
292
|
</Box>
|
|
294
|
-
{s.exec.
|
|
293
|
+
{s.exec.outputLabels.length > 0 && (
|
|
295
294
|
<Box borderStyle="round" paddingX={1} flexDirection="column">
|
|
296
|
-
{s.exec.
|
|
297
|
-
<Text key={o} color=
|
|
298
|
-
{
|
|
295
|
+
{s.exec.outputLabels.map((o, ix) => (
|
|
296
|
+
<Text key={`${ix}-${o.name}`} color={o.memory ? 'yellow' : 'green'} wrap="truncate">
|
|
297
|
+
{o.name} <Text color="gray">{o.detail}</Text>
|
|
299
298
|
</Text>
|
|
300
299
|
))}
|
|
301
300
|
</Box>
|
|
@@ -63,8 +63,8 @@ const VarRow = observer(
|
|
|
63
63
|
<Text color="cyan" wrap="truncate">
|
|
64
64
|
{value.replaceAll('\n', ' ')}
|
|
65
65
|
</Text>
|
|
66
|
-
) : p.varDef
|
|
67
|
-
<PromptCell varDef={p.varDef} value={value} />
|
|
66
|
+
) : p.varDef.kind === 'prompt' ? (
|
|
67
|
+
<PromptCell varDef={p.varDef as PromptVar} value={value} />
|
|
68
68
|
) : (
|
|
69
69
|
<Text color="cyan" wrap="wrap">
|
|
70
70
|
{value}
|
|
@@ -79,7 +79,8 @@ const VarRow = observer(
|
|
|
79
79
|
export const VarsPanel = observer((p: { st: TuiSt }) => {
|
|
80
80
|
const s = p.st
|
|
81
81
|
// label column = longest label + marker, so [kind] and values line up
|
|
82
|
-
|
|
82
|
+
// ('save to disk'.length covers the TUI-owned last row)
|
|
83
|
+
const labelW = Math.max(12, ...s.entries.map(([name, v]) => (v.label ?? name).length)) + 3
|
|
83
84
|
const focused = s.mode === 'nav' || s.mode === 'edit'
|
|
84
85
|
const boxRef = useRef<DOMElement>(null)
|
|
85
86
|
useEffect(() => {
|
|
@@ -102,7 +103,7 @@ export const VarsPanel = observer((p: { st: TuiSt }) => {
|
|
|
102
103
|
</Text>
|
|
103
104
|
</Box>
|
|
104
105
|
{w.moreAbove && <Text color="gray">…</Text>}
|
|
105
|
-
{s.entries.slice(w.start, w.end).map(([name, varDef], sliceIx) => (
|
|
106
|
+
{s.entries.slice(w.start, Math.min(w.end, s.entries.length)).map(([name, varDef], sliceIx) => (
|
|
106
107
|
<VarRow
|
|
107
108
|
key={name}
|
|
108
109
|
name={name}
|
|
@@ -113,6 +114,43 @@ export const VarsPanel = observer((p: { st: TuiSt }) => {
|
|
|
113
114
|
compact={s.varsCompact}
|
|
114
115
|
/>
|
|
115
116
|
))}
|
|
117
|
+
{/* the TUI-owned save rows ride the vars list as its last rows (item 14) */}
|
|
118
|
+
{w.end > s.entries.length && (
|
|
119
|
+
<Box flexDirection="row">
|
|
120
|
+
<Box width={labelW} flexShrink={0}>
|
|
121
|
+
<Text inverse={s.onSaveRow}>
|
|
122
|
+
{s.onSaveRow ? '▸ ' : ' '}
|
|
123
|
+
save to disk
|
|
124
|
+
</Text>
|
|
125
|
+
</Box>
|
|
126
|
+
<Box width={9} flexShrink={0}>
|
|
127
|
+
<Text color="gray">[tui]</Text>
|
|
128
|
+
</Box>
|
|
129
|
+
<Box flexGrow={1}>
|
|
130
|
+
<Text color={s.settings.saveToDisk ? 'cyan' : 'yellow'} wrap="truncate">
|
|
131
|
+
{s.settings.saveToDisk ? 'on' : 'off — outputs stay in memory'}
|
|
132
|
+
</Text>
|
|
133
|
+
</Box>
|
|
134
|
+
</Box>
|
|
135
|
+
)}
|
|
136
|
+
{s.settings.saveToDisk && w.end > s.entries.length + 1 && (
|
|
137
|
+
<Box flexDirection="row">
|
|
138
|
+
<Box width={labelW} flexShrink={0}>
|
|
139
|
+
<Text inverse={s.onPrefixRow}>
|
|
140
|
+
{s.onPrefixRow ? '▸ ' : ' '}
|
|
141
|
+
save prefix
|
|
142
|
+
</Text>
|
|
143
|
+
</Box>
|
|
144
|
+
<Box width={9} flexShrink={0}>
|
|
145
|
+
<Text color="gray">[tui]</Text>
|
|
146
|
+
</Box>
|
|
147
|
+
<Box flexGrow={1}>
|
|
148
|
+
<Text color="cyan" wrap="truncate">
|
|
149
|
+
.comfy-ts/outputs/{s.savePrefix}/
|
|
150
|
+
</Text>
|
|
151
|
+
</Box>
|
|
152
|
+
</Box>
|
|
153
|
+
)}
|
|
116
154
|
{w.moreBelow && <Text color="gray">…</Text>}
|
|
117
155
|
</Box>
|
|
118
156
|
)
|
|
@@ -7,6 +7,46 @@ const extOf = (path: string): string => {
|
|
|
7
7
|
return dot === -1 ? '' : path.slice(dot + 1).toLowerCase()
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/** platform command that puts PNG bytes on the clipboard from STDIN — no
|
|
11
|
+
* file ever touches disk (his ask 2026-07-31). The caller pipes `stdin`
|
|
12
|
+
* into the spawned process and closes it. */
|
|
13
|
+
export type ImageClipboardStdinCommand = { cmd: string; args: string[]; stdin: Uint8Array }
|
|
14
|
+
|
|
15
|
+
export const imageClipboardStdinCommand = (
|
|
16
|
+
platform: NodeJS.Platform,
|
|
17
|
+
pngBytes: Uint8Array,
|
|
18
|
+
): ImageClipboardStdinCommand => {
|
|
19
|
+
if (platform === 'darwin') {
|
|
20
|
+
// osascript reads the SCRIPT itself from stdin (`-`): a «data PNGf<hex>»
|
|
21
|
+
// literal carries the pixels inside the script — hex doubles the size,
|
|
22
|
+
// so multi-MB images take a beat; the caller falls back to the file
|
|
23
|
+
// command when this exits non-zero
|
|
24
|
+
const hex = Buffer.from(pngBytes).toString('hex').toUpperCase()
|
|
25
|
+
return {
|
|
26
|
+
cmd: 'osascript',
|
|
27
|
+
args: ['-'],
|
|
28
|
+
stdin: new TextEncoder().encode(`set the clipboard to «data PNGf${hex}»`),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (platform === 'win32') {
|
|
32
|
+
// base64 rides stdin; PS rebuilds the image from a MemoryStream — no
|
|
33
|
+
// user-controlled string ever lands in the script (quoting stays trivial)
|
|
34
|
+
const script =
|
|
35
|
+
'$b=[Convert]::FromBase64String([Console]::In.ReadToEnd()); ' +
|
|
36
|
+
'$ms=New-Object System.IO.MemoryStream(,$b); ' +
|
|
37
|
+
'Add-Type -AssemblyName System.Windows.Forms,System.Drawing; ' +
|
|
38
|
+
'$img=[System.Drawing.Image]::FromStream($ms); ' +
|
|
39
|
+
'[System.Windows.Forms.Clipboard]::SetImage($img); $img.Dispose()'
|
|
40
|
+
return {
|
|
41
|
+
cmd: 'powershell',
|
|
42
|
+
args: ['-NoProfile', '-Sta', '-Command', script],
|
|
43
|
+
stdin: new TextEncoder().encode(Buffer.from(pngBytes).toString('base64')),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// xclip reads the image bytes from stdin natively
|
|
47
|
+
return { cmd: 'xclip', args: ['-selection', 'clipboard', '-t', 'image/png'], stdin: pngBytes }
|
|
48
|
+
}
|
|
49
|
+
|
|
10
50
|
export const imageClipboardCommand = (platform: NodeJS.Platform, path: string): ImageClipboardCommand | null => {
|
|
11
51
|
const ext = extOf(path)
|
|
12
52
|
if (platform === 'darwin') {
|
|
@@ -82,8 +82,7 @@ export class DraftsSt {
|
|
|
82
82
|
|
|
83
83
|
/** module key of the currently loaded workflow (settings.lastDraft is keyed by it) */
|
|
84
84
|
private get moduleKey(): string {
|
|
85
|
-
|
|
86
|
-
return cur != null ? draftKeyForFile(cur) : (this.st.wf.spec.id ?? 'workflow')
|
|
85
|
+
return this.st.moduleKey
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
/** switch to a draft: load its stored values when the file exists, else it starts from current values */
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process'
|
|
2
|
+
import { existsSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
2
4
|
import { makeAutoObservable, runInAction } from 'mobx'
|
|
3
|
-
import { basename } from 'pathe'
|
|
5
|
+
import { basename, join } from 'pathe'
|
|
4
6
|
import type { ComfyHost } from 'src/host/ComfyHost.ts'
|
|
5
7
|
import type { ExecutionProgress } from 'src/runner/ComfyExecution.ts'
|
|
6
|
-
import { imageClipboardCommand } from 'src/cli/tui/imageClipboard.ts'
|
|
8
|
+
import { imageClipboardCommand, imageClipboardStdinCommand } from 'src/cli/tui/imageClipboard.ts'
|
|
7
9
|
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
10
|
+
import { importSharp } from 'src/utils/lazySharp.ts'
|
|
8
11
|
import type { SeedVar } from 'src/vars/ComfyVars.ts'
|
|
9
12
|
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
10
|
-
import {
|
|
11
|
-
import type { AbsolutePath } from 'src/types/index.ts'
|
|
13
|
+
import type { MediaImage } from 'src/runner/MediaImage.ts'
|
|
12
14
|
|
|
13
15
|
/** popup body: summary + the head of the copied json (proof of WHAT is in the clipboard) */
|
|
14
16
|
export function jsonHead(text: string, maxLines: number): string[] {
|
|
@@ -27,7 +29,8 @@ export class ExecSt {
|
|
|
27
29
|
/** runs we launched that have not finished (the server executes them FIFO) */
|
|
28
30
|
inFlight: number = 0
|
|
29
31
|
progress: ExecutionProgress | null = null
|
|
30
|
-
outputs
|
|
32
|
+
/** last run's outputs — MediaImages, so memory-only runs (save toggle off) stay first-class */
|
|
33
|
+
outputImages: MediaImage[] = []
|
|
31
34
|
runCount: number = 0
|
|
32
35
|
lastStatus: string | null = null
|
|
33
36
|
error: string | null = null
|
|
@@ -45,21 +48,35 @@ export class ExecSt {
|
|
|
45
48
|
return this.inFlight > 0
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
/** local save dir for this module's outputs (same key the drafts use) */
|
|
49
|
-
private get saveDirPrefix(): string {
|
|
50
|
-
const cur = this.st.workflows.currentPath
|
|
51
|
-
return cur != null ? draftKeyForFile(cur) : (this.st.wf.spec.id ?? 'workflow')
|
|
52
|
-
}
|
|
53
|
-
|
|
54
51
|
/** workflow switch: wipe run artifacts, keep a hello notice */
|
|
55
52
|
resetForWorkflow(notice: string): void {
|
|
56
|
-
this.
|
|
53
|
+
this.outputImages = []
|
|
57
54
|
this.error = null
|
|
58
55
|
this.notice = notice
|
|
59
56
|
this.runCount = 0
|
|
60
57
|
this.lastStatus = null
|
|
61
58
|
}
|
|
62
59
|
|
|
60
|
+
/** outputs box rows: path when saved, honest memory label otherwise */
|
|
61
|
+
get outputLabels(): { name: string; detail: string; memory: boolean }[] {
|
|
62
|
+
return this.outputImages.map((img) => {
|
|
63
|
+
if (img.absPath != null) return { name: basename(img.absPath), detail: img.absPath, memory: false }
|
|
64
|
+
const dims = img.width != null && img.height != null ? `${img.width}x${img.height}, ` : ''
|
|
65
|
+
return { name: img.filename, detail: `(${dims}in memory — i copies, o opens)`, memory: true }
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** a file path for viewer/clipboard: the saved file, or the bytes
|
|
70
|
+
* materialized into os tmpdir (deliberate user action, never a silent
|
|
71
|
+
* save — architecture item 14). The path derives from the content hash,
|
|
72
|
+
* so re-materializing is a cheap existsSync, no retention needed. */
|
|
73
|
+
private materialize(img: MediaImage): string {
|
|
74
|
+
if (img.absPath != null) return img.absPath
|
|
75
|
+
const path = join(tmpdir(), `comfy-ts-mem-${img.hash.slice(0, 8)}${img.extension}`)
|
|
76
|
+
if (!existsSync(path)) writeFileSync(path, img.buffer)
|
|
77
|
+
return path
|
|
78
|
+
}
|
|
79
|
+
|
|
63
80
|
/** every run takes THIS path, queued ones included: same progress, outputs, previews */
|
|
64
81
|
async run(): Promise<void> {
|
|
65
82
|
const queued = this.running
|
|
@@ -87,19 +104,18 @@ export class ExecSt {
|
|
|
87
104
|
try {
|
|
88
105
|
const execution = await this.st.wf.run({
|
|
89
106
|
host: this.st.hostOverride ?? undefined,
|
|
90
|
-
// the
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
save: { prefix: this.saveDirPrefix },
|
|
107
|
+
// the save rows (vars panel, item 14): on = files under
|
|
108
|
+
// .comfy-ts/outputs/<savePrefix>/, off = outputs stay in memory
|
|
109
|
+
save: this.st.settings.saveToDisk ? { prefix: this.st.savePrefix } : false,
|
|
94
110
|
onProgress: (p) => runInAction(() => this.onProgress(p)),
|
|
95
111
|
})
|
|
96
112
|
runInAction(() => {
|
|
97
|
-
this.
|
|
113
|
+
this.outputImages = execution.images.slice()
|
|
98
114
|
this.lastStatus = execution.status
|
|
99
115
|
this.runCount++
|
|
100
116
|
})
|
|
101
117
|
const lastImage = execution.images[execution.images.length - 1]
|
|
102
|
-
if (lastImage
|
|
118
|
+
if (lastImage != null) void this.st.preview.renderOutput(lastImage.absPath ?? lastImage.buffer)
|
|
103
119
|
} catch (e) {
|
|
104
120
|
runInAction(() => {
|
|
105
121
|
this.error = extractErrorMessage(e)
|
|
@@ -140,11 +156,18 @@ export class ExecSt {
|
|
|
140
156
|
|
|
141
157
|
/** 'o': real pixels in the OS viewer — the in-terminal ceiling is half-blocks */
|
|
142
158
|
openLastOutput(): void {
|
|
143
|
-
const
|
|
144
|
-
if (
|
|
159
|
+
const lastImg = this.outputImages[this.outputImages.length - 1]
|
|
160
|
+
if (lastImg == null) {
|
|
145
161
|
this.notice = 'no output image yet'
|
|
146
162
|
return
|
|
147
163
|
}
|
|
164
|
+
let last: string
|
|
165
|
+
try {
|
|
166
|
+
last = this.materialize(lastImg)
|
|
167
|
+
} catch (e) {
|
|
168
|
+
this.notice = `open failed: ${extractErrorMessage(e)}`
|
|
169
|
+
return
|
|
170
|
+
}
|
|
148
171
|
const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open'
|
|
149
172
|
const proc = spawn(cmd, [last], { stdio: 'ignore', detached: true })
|
|
150
173
|
proc.on('error', () => {
|
|
@@ -153,7 +176,7 @@ export class ExecSt {
|
|
|
153
176
|
})
|
|
154
177
|
})
|
|
155
178
|
proc.unref()
|
|
156
|
-
this.notice = `opened ${basename(last)}`
|
|
179
|
+
this.notice = `opened ${basename(last)}${lastImg.absPath == null ? ` (memory image via ${last})` : ''}`
|
|
157
180
|
}
|
|
158
181
|
|
|
159
182
|
// ---- clipboard ----
|
|
@@ -170,6 +193,10 @@ export class ExecSt {
|
|
|
170
193
|
this.st.mode = 'nav'
|
|
171
194
|
}
|
|
172
195
|
|
|
196
|
+
/** makeAutoObservable already annotates this method as an action, so the
|
|
197
|
+
* post-await callers below need no runInAction of their own (verified
|
|
198
|
+
* against mobx: a TS-private prototype method called after an `await`
|
|
199
|
+
* opens its own action context; only a CONSTRUCTOR body does not) */
|
|
173
200
|
private showCopyPopup(title: string, ok: boolean, lines: string[]): void {
|
|
174
201
|
// the build is async: if the user moved into an editor meanwhile, never
|
|
175
202
|
// steal their keys — degrade to the notice line instead of a popup
|
|
@@ -181,50 +208,79 @@ export class ExecSt {
|
|
|
181
208
|
this.copyPopup = { title, ok, lines }
|
|
182
209
|
this.st.mode = 'overlay-copy'
|
|
183
210
|
}
|
|
184
|
-
/** 'i': the LAST generated image's pixels → clipboard (paste anywhere)
|
|
211
|
+
/** 'i': the LAST generated image's pixels → clipboard (paste anywhere).
|
|
212
|
+
* The primary route pipes png bytes over stdin — no disk write at all
|
|
213
|
+
* (his ask 2026-07-31); only when that tool fails does it fall back to
|
|
214
|
+
* the materialized-file command, and the popup says which route ran. */
|
|
185
215
|
async copyLastImage(): Promise<void> {
|
|
186
|
-
const
|
|
187
|
-
if (
|
|
216
|
+
const lastImg = this.outputImages[this.outputImages.length - 1]
|
|
217
|
+
if (lastImg == null) {
|
|
188
218
|
this.showCopyPopup('image → clipboard', false, ['no output image yet — r runs the workflow first'])
|
|
189
219
|
return
|
|
190
220
|
}
|
|
191
|
-
|
|
192
|
-
let
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
command = imageClipboardCommand(process.platform, file)
|
|
202
|
-
} catch (e) {
|
|
203
|
-
this.showCopyPopup('image → clipboard', false, [
|
|
204
|
-
`COPY FAILED for ${basename(last)}`,
|
|
205
|
-
`png transcode failed: ${extractErrorMessage(e)}`,
|
|
206
|
-
])
|
|
207
|
-
return
|
|
208
|
-
}
|
|
221
|
+
// normalize to png IN MEMORY: osascript/PS tag bytes, they never transcode
|
|
222
|
+
let pngBytes: Uint8Array
|
|
223
|
+
try {
|
|
224
|
+
pngBytes = lastImg.metadata.type === 'png' ? lastImg.buffer : await this.toPngBytes(lastImg.buffer)
|
|
225
|
+
} catch (e) {
|
|
226
|
+
this.showCopyPopup('image → clipboard', false, [
|
|
227
|
+
`COPY FAILED for ${lastImg.filename}`,
|
|
228
|
+
`png transcode failed: ${extractErrorMessage(e)}`,
|
|
229
|
+
])
|
|
230
|
+
return
|
|
209
231
|
}
|
|
210
|
-
|
|
211
|
-
|
|
232
|
+
const piped = imageClipboardStdinCommand(process.platform, pngBytes)
|
|
233
|
+
const pipedOk = await this.runWithStdin(piped)
|
|
234
|
+
if (pipedOk) {
|
|
235
|
+
this.showCopyPopup('image → clipboard', true, [
|
|
236
|
+
`${lastImg.filename} — paste the pixels anywhere`,
|
|
237
|
+
'',
|
|
238
|
+
'nothing written to disk',
|
|
239
|
+
])
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
// fallback: the piped tool failed (missing/blocked) — try the file route
|
|
243
|
+
let file: string
|
|
244
|
+
try {
|
|
245
|
+
file = this.materialize(lastImg)
|
|
246
|
+
} catch (e) {
|
|
247
|
+
this.showCopyPopup('image → clipboard', false, [
|
|
248
|
+
`COPY FAILED for ${lastImg.filename}`,
|
|
249
|
+
`piped ${piped.cmd} failed, and the tmp-file fallback could not write: ${extractErrorMessage(e)}`,
|
|
250
|
+
])
|
|
212
251
|
return
|
|
213
252
|
}
|
|
214
|
-
const
|
|
215
|
-
const ok =
|
|
216
|
-
|
|
253
|
+
const command = imageClipboardCommand(process.platform, file)
|
|
254
|
+
const ok =
|
|
255
|
+
command != null &&
|
|
256
|
+
(await new Promise<boolean>((resolve) => {
|
|
257
|
+
const proc = spawn(command.cmd, command.args, { stdio: 'ignore' })
|
|
258
|
+
proc.on('error', () => resolve(false))
|
|
259
|
+
proc.on('close', (code) => resolve(code === 0))
|
|
260
|
+
}))
|
|
261
|
+
this.showCopyPopup(
|
|
262
|
+
'image → clipboard',
|
|
263
|
+
ok,
|
|
264
|
+
ok
|
|
265
|
+
? [`${basename(file)} — paste the pixels anywhere`, '', `via fallback file ${file}`]
|
|
266
|
+
: [`COPY FAILED for ${lastImg.filename}`, `could not run ${piped.cmd} — is it installed and allowed ?`],
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private async toPngBytes(bytes: Uint8Array): Promise<Uint8Array> {
|
|
271
|
+
const sharp = await importSharp('the clipboard png normalize')
|
|
272
|
+
return new Uint8Array(await sharp(bytes).png().toBuffer())
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
private runWithStdin(p: { cmd: string; args: string[]; stdin: Uint8Array }): Promise<boolean> {
|
|
276
|
+
return new Promise((resolve) => {
|
|
277
|
+
const proc = spawn(p.cmd, p.args, { stdio: ['pipe', 'ignore', 'ignore'] })
|
|
217
278
|
proc.on('error', () => resolve(false))
|
|
218
279
|
proc.on('close', (code) => resolve(code === 0))
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
ok,
|
|
224
|
-
ok
|
|
225
|
-
? [`${basename(last)} — paste the pixels anywhere`, '', last]
|
|
226
|
-
: [`COPY FAILED for ${basename(last)}`, `could not run ${cmd.cmd} — is it installed and allowed ?`],
|
|
227
|
-
)
|
|
280
|
+
// EPIPE when the tool is missing/dies early: the close handler decides
|
|
281
|
+
proc.stdin.on('error', () => {})
|
|
282
|
+
proc.stdin.write(p.stdin)
|
|
283
|
+
proc.stdin.end()
|
|
228
284
|
})
|
|
229
285
|
}
|
|
230
286
|
|
|
@@ -257,28 +313,24 @@ export class ExecSt {
|
|
|
257
313
|
const json = await wf.toWorkflowJson()
|
|
258
314
|
const text = JSON.stringify(json, null, 2)
|
|
259
315
|
const ok = await this.toClipboard(text)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
)
|
|
272
|
-
})
|
|
316
|
+
this.showCopyPopup(
|
|
317
|
+
'workflow.json → clipboard',
|
|
318
|
+
ok,
|
|
319
|
+
ok
|
|
320
|
+
? [
|
|
321
|
+
`${json.nodes.length} nodes · ${text.length} chars — paste into the ComfyUI editor`,
|
|
322
|
+
'',
|
|
323
|
+
...jsonHead(text, 10),
|
|
324
|
+
]
|
|
325
|
+
: ['CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?'],
|
|
326
|
+
)
|
|
273
327
|
} catch (e) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
])
|
|
281
|
-
})
|
|
328
|
+
this.showCopyPopup('workflow.json copy FAILED', false, [
|
|
329
|
+
extractErrorMessage(e),
|
|
330
|
+
'',
|
|
331
|
+
'nothing was copied. i2i/i2v builds upload their input image first —',
|
|
332
|
+
'an unreachable host fails the build itself, not just the run.',
|
|
333
|
+
])
|
|
282
334
|
} finally {
|
|
283
335
|
runInAction(() => {
|
|
284
336
|
this.copying = false
|
|
@@ -298,28 +350,24 @@ export class ExecSt {
|
|
|
298
350
|
const json = wf.toApiJson('use_stringified_numbers_only')
|
|
299
351
|
const text = JSON.stringify(json, null, 2)
|
|
300
352
|
const ok = await this.toClipboard(text)
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
)
|
|
313
|
-
})
|
|
353
|
+
this.showCopyPopup(
|
|
354
|
+
'api.json → clipboard',
|
|
355
|
+
ok,
|
|
356
|
+
ok
|
|
357
|
+
? [
|
|
358
|
+
`${Object.keys(json).length} nodes · ${text.length} chars — the POST /prompt payload`,
|
|
359
|
+
'',
|
|
360
|
+
...jsonHead(text, 10),
|
|
361
|
+
]
|
|
362
|
+
: ['CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?'],
|
|
363
|
+
)
|
|
314
364
|
} catch (e) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
])
|
|
322
|
-
})
|
|
365
|
+
this.showCopyPopup('api.json copy FAILED', false, [
|
|
366
|
+
extractErrorMessage(e),
|
|
367
|
+
'',
|
|
368
|
+
'nothing was copied. i2i/i2v builds upload their input image first —',
|
|
369
|
+
'an unreachable host fails the build itself, not just the run.',
|
|
370
|
+
])
|
|
323
371
|
} finally {
|
|
324
372
|
runInAction(() => {
|
|
325
373
|
this.copying = false
|
|
@@ -52,8 +52,9 @@ export class PreviewSt {
|
|
|
52
52
|
latentDims: { width: number; height: number } | null = null
|
|
53
53
|
/** at least one latent frame arrived this run — false + progress = server sends none */
|
|
54
54
|
latentSeenThisRun: boolean = false
|
|
55
|
-
/** last output
|
|
56
|
-
|
|
55
|
+
/** last output, kept so a settings change can re-render it: a path when
|
|
56
|
+
* the run saved, raw bytes for memory-only runs (item 14) */
|
|
57
|
+
private lastOutput: string | Uint8Array | null = null
|
|
57
58
|
|
|
58
59
|
get show(): boolean {
|
|
59
60
|
return this.st.settings.previewPanel
|
|
@@ -162,7 +163,7 @@ export class PreviewSt {
|
|
|
162
163
|
this.latentBytes = null
|
|
163
164
|
this.latentDims = null
|
|
164
165
|
this.latentSeenThisRun = false
|
|
165
|
-
this.
|
|
166
|
+
this.lastOutput = null
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
/** run boundary: drop the latents so the next run never shows the previous one's */
|
|
@@ -177,7 +178,7 @@ export class PreviewSt {
|
|
|
177
178
|
onSettingsChanged(): void {
|
|
178
179
|
this.outputAnsi = null
|
|
179
180
|
this.outputBytes = null
|
|
180
|
-
if (this.show && this.
|
|
181
|
+
if (this.show && this.lastOutput != null) void this.renderOutput(this.lastOutput)
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
/** what the painter should show RIGHT NOW (native renderer only; mirrors the panel's source) */
|
|
@@ -227,13 +228,13 @@ export class PreviewSt {
|
|
|
227
228
|
return Math.max(10, this.st.termRows - 12)
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
async renderOutput(
|
|
231
|
-
this.
|
|
231
|
+
async renderOutput(src: string | Uint8Array): Promise<void> {
|
|
232
|
+
this.lastOutput = src
|
|
232
233
|
if (!this.show) return
|
|
233
234
|
try {
|
|
234
235
|
if (this.useNative) {
|
|
235
236
|
// pre-shrink ONCE: the painter re-uploads on every repaint, so ~100KB beats ~2MB
|
|
236
|
-
const shrunk = await sharp(
|
|
237
|
+
const shrunk = await sharp(src)
|
|
237
238
|
.resize(896, 896, { fit: 'inside', withoutEnlargement: true })
|
|
238
239
|
.png()
|
|
239
240
|
.toBuffer()
|
|
@@ -242,7 +243,7 @@ export class PreviewSt {
|
|
|
242
243
|
})
|
|
243
244
|
return
|
|
244
245
|
}
|
|
245
|
-
const rendered = await imageBufferToAnsi(
|
|
246
|
+
const rendered = await imageBufferToAnsi(src, { width: this.width, height: this.height })
|
|
246
247
|
runInAction(() => {
|
|
247
248
|
this.outputAnsi = rendered
|
|
248
249
|
})
|
|
@@ -302,9 +303,9 @@ export class PreviewSt {
|
|
|
302
303
|
)
|
|
303
304
|
.png()
|
|
304
305
|
.toBuffer()
|
|
305
|
-
const
|
|
306
|
-
if (
|
|
307
|
-
const base = await sharp(
|
|
306
|
+
const out = this.lastOutput
|
|
307
|
+
if (out == null) return imageBufferToAnsi(thumb, { width: this.width, height: this.height })
|
|
308
|
+
const base = await sharp(out).resize(pxW, pxH, { fit: 'inside' }).png().toBuffer()
|
|
308
309
|
const composed = await sharp(base)
|
|
309
310
|
.composite([{ input: thumb, gravity: 'northeast' }])
|
|
310
311
|
.png()
|
|
@@ -60,6 +60,8 @@ export class SettingsSt {
|
|
|
60
60
|
lastWorkflow: this.lastWorkflow,
|
|
61
61
|
hostOverrideId: this.hostOverrideId,
|
|
62
62
|
collapsedDirs: this.collapsedDirs,
|
|
63
|
+
saveToDisk: this.saveToDisk,
|
|
64
|
+
savePrefix: this.savePrefix,
|
|
63
65
|
})
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -74,6 +76,10 @@ export class SettingsSt {
|
|
|
74
76
|
hostOverrideId: string | null = null
|
|
75
77
|
/** folded tree dirs (hand-tuned state persists, like every other surface) */
|
|
76
78
|
collapsedDirs: string[] = []
|
|
79
|
+
/** the vars-panel save toggle (architecture item 14): off = outputs stay in memory */
|
|
80
|
+
saveToDisk: boolean = true
|
|
81
|
+
/** per-module override of the local save dir under .comfy-ts/outputs/ (item 14) */
|
|
82
|
+
savePrefix: Record<string, string> = {}
|
|
77
83
|
|
|
78
84
|
rememberDraft(moduleKey: string, draft: string): void {
|
|
79
85
|
this.lastDraft[moduleKey] = draft
|
|
@@ -99,6 +105,13 @@ export class SettingsSt {
|
|
|
99
105
|
if (typeof o.lastWorkflow === 'string') this.lastWorkflow = o.lastWorkflow
|
|
100
106
|
if (typeof o.hostOverrideId === 'string') this.hostOverrideId = o.hostOverrideId
|
|
101
107
|
if (Array.isArray(o.collapsedDirs)) this.collapsedDirs = o.collapsedDirs.filter((d) => typeof d === 'string')
|
|
108
|
+
if (typeof o.saveToDisk === 'boolean') this.saveToDisk = o.saveToDisk
|
|
109
|
+
if (o.savePrefix != null && typeof o.savePrefix === 'object')
|
|
110
|
+
this.savePrefix = Object.fromEntries(
|
|
111
|
+
Object.entries(o.savePrefix as Record<string, unknown>).filter(
|
|
112
|
+
(kv): kv is [string, string] => typeof kv[1] === 'string',
|
|
113
|
+
),
|
|
114
|
+
)
|
|
102
115
|
} catch {
|
|
103
116
|
// corrupt settings must never block the TUI — start from defaults
|
|
104
117
|
}
|