comfy-ts 1.1.0 → 1.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 (66) hide show
  1. package/README.md +61 -8
  2. package/dist/{DefinedWorkflow-BYyu5dK9.js → DefinedWorkflow-gpknV-5f.js} +52 -35
  3. package/dist/DefinedWorkflow-gpknV-5f.js.map +1 -0
  4. package/dist/DraftsSt-DmA0jWGl.js +434 -0
  5. package/dist/DraftsSt-DmA0jWGl.js.map +1 -0
  6. package/dist/cli.js +17 -4555
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +184 -32
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +54 -23
  11. package/dist/index.d.ts +36 -5
  12. package/dist/index.js +184 -32
  13. package/dist/index.js.map +1 -1
  14. package/dist/run-serve-Bn6yIJB0.js +638 -0
  15. package/dist/run-serve-Bn6yIJB0.js.map +1 -0
  16. package/dist/{run-tui-DZ22HDHI.js → run-tui-BtjaOXRh.js} +791 -395
  17. package/dist/run-tui-BtjaOXRh.js.map +1 -0
  18. package/dist/state-DKCPy105.js +4690 -0
  19. package/dist/state-DKCPy105.js.map +1 -0
  20. package/examples/README.md +6 -4
  21. package/examples/{01-txt2img.cflow.ts → rvion/01-txt2img.cflow.ts} +1 -1
  22. package/examples/{02-img2img-upload.cflow.ts → rvion/02-img2img-upload.cflow.ts} +1 -1
  23. package/examples/{03-export-workflow-json.cflow.ts → rvion/03-export-workflow-json.cflow.ts} +1 -1
  24. package/examples/{04-krea2-turbo-t2i.cflow.ts → rvion/04-krea2-turbo-t2i.cflow.ts} +2 -2
  25. package/examples/{05-comfy-cloud.cflow.ts → rvion/05-comfy-cloud.cflow.ts} +2 -2
  26. package/examples/rvion/06-qwen-image-edit.cflow.ts +89 -0
  27. package/package.json +6 -2
  28. package/src/cli/comfy-ts-cli.ts +15 -5
  29. package/src/cli/serve/ServeApp.ts +378 -0
  30. package/src/cli/serve/applyVarPayload.ts +119 -0
  31. package/src/cli/serve/describeVar.ts +74 -0
  32. package/src/cli/serve/run-serve.ts +169 -0
  33. package/src/cli/tui/components/CopyOverlay.tsx +25 -0
  34. package/src/cli/tui/components/Header.tsx +9 -4
  35. package/src/cli/tui/components/HostPanel.tsx +3 -2
  36. package/src/cli/tui/components/HostsOverlay.tsx +33 -0
  37. package/src/cli/tui/components/StatusBar.tsx +29 -9
  38. package/src/cli/tui/components/TreePanel.tsx +33 -9
  39. package/src/cli/tui/components/TuiApp.tsx +54 -7
  40. package/src/cli/tui/components/VarsPanel.tsx +67 -34
  41. package/src/cli/tui/imageClipboard.ts +39 -0
  42. package/src/cli/tui/imagePicker/fsListing.ts +6 -4
  43. package/src/cli/tui/listWindow.ts +36 -0
  44. package/src/cli/tui/run-tui.tsx +47 -7
  45. package/src/cli/tui/state/DraftsSt.ts +3 -2
  46. package/src/cli/tui/state/ExecSt.ts +156 -12
  47. package/src/cli/tui/state/HostSt.ts +94 -10
  48. package/src/cli/tui/state/PickerSt.ts +8 -2
  49. package/src/cli/tui/state/QueueSt.ts +2 -2
  50. package/src/cli/tui/state/SettingsSt.ts +25 -7
  51. package/src/cli/tui/state/TreeSt.ts +164 -36
  52. package/src/cli/tui/state/TuiSt.ts +81 -6
  53. package/src/cli/tui/state/WorkflowsSt.ts +14 -2
  54. package/src/cli/tui/treeRows.ts +165 -0
  55. package/src/host/ComfyHost.ts +7 -0
  56. package/src/litegraph/convertFlowToLiteGraphJSON.ts +11 -7
  57. package/src/runner/ComfyExecution.ts +21 -4
  58. package/src/runner/ComfyWorkflowLayout.ts +6 -4
  59. package/src/runner/outputPath.ts +75 -0
  60. package/src/sdk-generator/inputWidgetKind.ts +50 -11
  61. package/src/sdk-generator/litegraphToApiRequestPayload.ts +14 -7
  62. package/src/state.ts +7 -1
  63. package/src/vars/ComfyVars.ts +33 -4
  64. package/src/vars/DefinedWorkflow.ts +21 -8
  65. package/dist/DefinedWorkflow-BYyu5dK9.js.map +0 -1
  66. package/dist/run-tui-DZ22HDHI.js.map +0 -1
@@ -1,11 +1,21 @@
1
1
  import { spawn } from 'node:child_process'
2
2
  import { makeAutoObservable, runInAction } from 'mobx'
3
3
  import { basename } from 'pathe'
4
+ import type { ComfyHost } from 'src/host/ComfyHost.ts'
4
5
  import type { ExecutionProgress } from 'src/runner/ComfyExecution.ts'
6
+ import { imageClipboardCommand } from 'src/cli/tui/imageClipboard.ts'
5
7
  import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
6
8
  import type { SeedVar } from 'src/vars/ComfyVars.ts'
7
9
  import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
8
10
 
11
+ /** popup body: summary + the head of the copied json (proof of WHAT is in the clipboard) */
12
+ export function jsonHead(text: string, maxLines: number): string[] {
13
+ const lines = text.split('\n')
14
+ const head = lines.slice(0, maxLines).map((l) => (l.length > 76 ? `${l.slice(0, 75)}…` : l))
15
+ if (lines.length > maxLines) head.push('…')
16
+ return head
17
+ }
18
+
9
19
  /** run lifecycle + outputs + status line + clipboard/open actions */
10
20
  export class ExecSt {
11
21
  constructor(private st: TuiSt) {
@@ -24,6 +34,11 @@ export class ExecSt {
24
34
  /** the prompt currently executing on the server (progress belongs to it) */
25
35
  private currentPromptId: string | null = null
26
36
 
37
+ /** every host a latent-preview handler is installed on — a queued run may
38
+ * target a DIFFERENT host after an `h` override switch, and clearing only
39
+ * the last run's host would leak the handler on the first one */
40
+ private latentHosts: Set<ComfyHost> = new Set()
41
+
27
42
  get running(): boolean {
28
43
  return this.inFlight > 0
29
44
  }
@@ -40,7 +55,7 @@ export class ExecSt {
40
55
  /** every run takes THIS path, queued ones included: same progress, outputs, previews */
41
56
  async run(): Promise<void> {
42
57
  const queued = this.running
43
- const host = this.st.wf.host
58
+ const host = this.st.runHost
44
59
  runInAction(() => {
45
60
  this.inFlight++
46
61
  this.error = null
@@ -54,12 +69,16 @@ export class ExecSt {
54
69
  // 'latent small' / 'last output' preview settings show it while
55
70
  // running (full reset belongs to workflow switches)
56
71
  this.st.preview.clearLatent()
57
- // installed while ANY run is in flight, so queued prompts keep painting latents
58
- host.onLatentPreview = (p) => void this.st.preview.renderLatent(p.bytes)
59
72
  }
73
+ // installed while ANY run is in flight (queued prompts keep painting
74
+ // latents), on THIS run's host — it may differ from the previous
75
+ // run's after an `h` override switch
76
+ host.onLatentPreview = (p) => void this.st.preview.renderLatent(p.bytes)
77
+ this.latentHosts.add(host)
60
78
  })
61
79
  try {
62
80
  const execution = await this.st.wf.run({
81
+ host: this.st.hostOverride ?? undefined,
63
82
  onProgress: (p) => runInAction(() => this.onProgress(p)),
64
83
  })
65
84
  runInAction(() => {
@@ -80,7 +99,10 @@ export class ExecSt {
80
99
  this.progress = null
81
100
  this.currentPromptId = null
82
101
  this.st.preview.clearLatent()
83
- if (this.inFlight === 0) host.onLatentPreview = null
102
+ if (this.inFlight === 0) {
103
+ for (const h of this.latentHosts) h.onLatentPreview = null
104
+ this.latentHosts.clear()
105
+ }
84
106
  })
85
107
  }
86
108
  }
@@ -123,6 +145,77 @@ export class ExecSt {
123
145
  }
124
146
 
125
147
  // ---- clipboard ----
148
+
149
+ /** `c`/`C` end HERE, success or failure — a copy must never be silent
150
+ * (his repro: 'c does nothing', the notice line was too quiet) */
151
+ copyPopup: { title: string; ok: boolean; lines: string[] } | null = null
152
+
153
+ /** a copy build can hang on a stalled-host upload: guard double-presses */
154
+ private copying = false
155
+
156
+ closeCopyPopup(): void {
157
+ this.copyPopup = null
158
+ this.st.mode = 'nav'
159
+ }
160
+
161
+ private showCopyPopup(title: string, ok: boolean, lines: string[]): void {
162
+ // the build is async: if the user moved into an editor meanwhile, never
163
+ // steal their keys — degrade to the notice line instead of a popup
164
+ const m = this.st.mode
165
+ if (m === 'edit' || m.startsWith('overlay-')) {
166
+ this.notice = `${ok ? '✓' : '✗'} ${title}`
167
+ return
168
+ }
169
+ this.copyPopup = { title, ok, lines }
170
+ this.st.mode = 'overlay-copy'
171
+ }
172
+ /** 'i': the LAST generated image's pixels → clipboard (paste anywhere) */
173
+ async copyLastImage(): Promise<void> {
174
+ const last = this.outputs[this.outputs.length - 1]
175
+ if (last == null) {
176
+ this.showCopyPopup('image → clipboard', false, ['no output image yet — r runs the workflow first'])
177
+ return
178
+ }
179
+ let file = last
180
+ let command = imageClipboardCommand(process.platform, file)
181
+ if (command == null && process.platform === 'darwin') {
182
+ // osascript only tags bytes — webp/etc must become real png first
183
+ try {
184
+ const { default: sharp } = await import('sharp')
185
+ const { tmpdir } = await import('node:os')
186
+ const { join } = await import('pathe')
187
+ file = join(tmpdir(), `comfy-ts-clip-${Date.now()}.png`)
188
+ await sharp(last).png().toFile(file)
189
+ command = imageClipboardCommand(process.platform, file)
190
+ } catch (e) {
191
+ this.showCopyPopup('image → clipboard', false, [
192
+ `COPY FAILED for ${basename(last)}`,
193
+ `png transcode failed: ${extractErrorMessage(e)}`,
194
+ ])
195
+ return
196
+ }
197
+ }
198
+ if (command == null) {
199
+ this.showCopyPopup('image → clipboard', false, [`no clipboard image tool for ${process.platform}`])
200
+ return
201
+ }
202
+ const cmd = command
203
+ const ok = await new Promise<boolean>((resolve) => {
204
+ const proc = spawn(cmd.cmd, cmd.args, { stdio: 'ignore' })
205
+ proc.on('error', () => resolve(false))
206
+ proc.on('close', (code) => resolve(code === 0))
207
+ })
208
+ runInAction(() => {
209
+ this.showCopyPopup(
210
+ 'image → clipboard',
211
+ ok,
212
+ ok
213
+ ? [`${basename(last)} — paste the pixels anywhere`, '', last]
214
+ : [`COPY FAILED for ${basename(last)}`, `could not run ${cmd.cmd} — is it installed and allowed ?`],
215
+ )
216
+ })
217
+ }
218
+
126
219
  private toClipboard(text: string): Promise<boolean> {
127
220
  const [cmd, ...args] =
128
221
  process.platform === 'darwin'
@@ -141,32 +234,83 @@ export class ExecSt {
141
234
 
142
235
  /** 'c': copy workflow.json (litegraph, drag into the ComfyUI editor) */
143
236
  async copyWorkflowJson(): Promise<void> {
237
+ if (this.copying) return
238
+ runInAction(() => {
239
+ this.copying = true
240
+ // instant feedback: the i2i upload inside build can hang for a tcp timeout
241
+ this.notice = 'building for copy… (i2i workflows upload their input image first)'
242
+ })
144
243
  try {
145
- const wf = await this.st.wf.build()
244
+ const wf = await this.st.wf.build({ host: this.st.hostOverride ?? undefined })
146
245
  const json = await wf.toWorkflowJson()
147
- const ok = await this.toClipboard(JSON.stringify(json, null, 2))
246
+ const text = JSON.stringify(json, null, 2)
247
+ const ok = await this.toClipboard(text)
148
248
  runInAction(() => {
149
- this.notice = ok ? `workflow.json copied (${json.nodes.length} nodes)` : 'clipboard copy failed'
249
+ this.showCopyPopup(
250
+ 'workflow.json → clipboard',
251
+ ok,
252
+ ok
253
+ ? [
254
+ `${json.nodes.length} nodes · ${text.length} chars — paste into the ComfyUI editor`,
255
+ '',
256
+ ...jsonHead(text, 10),
257
+ ]
258
+ : ['CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?'],
259
+ )
150
260
  })
151
261
  } catch (e) {
152
262
  runInAction(() => {
153
- this.notice = `${extractErrorMessage(e)}`
263
+ this.showCopyPopup('workflow.json copy FAILED', false, [
264
+ extractErrorMessage(e),
265
+ '',
266
+ 'nothing was copied. i2i/i2v builds upload their input image first —',
267
+ 'an unreachable host fails the build itself, not just the run.',
268
+ ])
269
+ })
270
+ } finally {
271
+ runInAction(() => {
272
+ this.copying = false
154
273
  })
155
274
  }
156
275
  }
157
276
 
158
277
  /** 'C': copy api.json (the POST /prompt payload) */
159
278
  async copyApiJson(): Promise<void> {
279
+ if (this.copying) return
280
+ runInAction(() => {
281
+ this.copying = true
282
+ this.notice = 'building for copy… (i2i workflows upload their input image first)'
283
+ })
160
284
  try {
161
- const wf = await this.st.wf.build()
285
+ const wf = await this.st.wf.build({ host: this.st.hostOverride ?? undefined })
162
286
  const json = wf.toApiJson('use_stringified_numbers_only')
163
- const ok = await this.toClipboard(JSON.stringify(json, null, 2))
287
+ const text = JSON.stringify(json, null, 2)
288
+ const ok = await this.toClipboard(text)
164
289
  runInAction(() => {
165
- this.notice = ok ? `api.json copied (${Object.keys(json).length} nodes)` : 'clipboard copy failed'
290
+ this.showCopyPopup(
291
+ 'api.json → clipboard',
292
+ ok,
293
+ ok
294
+ ? [
295
+ `${Object.keys(json).length} nodes · ${text.length} chars — the POST /prompt payload`,
296
+ '',
297
+ ...jsonHead(text, 10),
298
+ ]
299
+ : ['CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?'],
300
+ )
166
301
  })
167
302
  } catch (e) {
168
303
  runInAction(() => {
169
- this.notice = `${extractErrorMessage(e)}`
304
+ this.showCopyPopup('api.json copy FAILED', false, [
305
+ extractErrorMessage(e),
306
+ '',
307
+ 'nothing was copied. i2i/i2v builds upload their input image first —',
308
+ 'an unreachable host fails the build itself, not just the run.',
309
+ ])
310
+ })
311
+ } finally {
312
+ runInAction(() => {
313
+ this.copying = false
170
314
  })
171
315
  }
172
316
  }
@@ -9,9 +9,29 @@ export type HostStatus = 'unknown' | 'up' | 'down'
9
9
 
10
10
  const PROBE_EVERY_MS = 5000
11
11
  const PROBE_TIMEOUT_MS = 3000
12
+ /** ws message younger than this = the host is alive, whatever http says */
13
+ export const WS_ALIVE_MS = 10_000
12
14
 
13
15
  const SPIN_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
14
16
 
17
+ /**
18
+ * PURE probe verdict (headless-tested). http ok is proof enough; on http
19
+ * failure a RECENTLY TALKING open ws still means up — ComfyUI is
20
+ * single-threaded and stalls new connects mid-generation while established
21
+ * sockets stream (his repro 2026-07-30: 'windows-1 offline' in the header
22
+ * while the browser tab generated fine). A half-open socket receives
23
+ * nothing, so the recency window never revives one.
24
+ */
25
+ export function probeVerdict(p: { httpOk: boolean; wsOpen: boolean; lastWsMessageAt: number | null; now: number }): {
26
+ status: HostStatus
27
+ via: 'ws' | 'http' | null
28
+ } {
29
+ if (p.httpOk) return { status: 'up', via: p.wsOpen ? 'ws' : 'http' }
30
+ if (p.wsOpen && p.lastWsMessageAt != null && p.now - p.lastWsMessageAt < WS_ALIVE_MS)
31
+ return { status: 'up', via: 'ws' }
32
+ return { status: 'down', via: null }
33
+ }
34
+
15
35
  /** host panel (`h`): stats about the connected host + maintenance actions */
16
36
  export class HostSt {
17
37
  constructor(private st: TuiSt) {
@@ -23,16 +43,18 @@ export class HostSt {
23
43
  if (this.spinTimer != null) clearInterval(this.spinTimer)
24
44
  if (this.countdownTimer != null) clearInterval(this.countdownTimer)
25
45
  })
26
- // switching workflows can switch hosts: back to unknown, re-probe now.
27
- // probeGen++ kills a chain that is mid-await (its loopTimer isn't set yet,
28
- // clearing timers alone would leave it alive → duplicate chains forever)
46
+ // switching workflows (or the `h` override) can switch hosts: back to
47
+ // unknown, re-probe now. probeGen++ kills a chain that is mid-await (its
48
+ // loopTimer isn't set yet, clearing timers alone would leave it alive →
49
+ // duplicate chains forever)
29
50
  this.st.disposers.push(
30
51
  reaction(
31
- () => this.st.wf,
52
+ () => this.st.runHost,
32
53
  () => {
33
54
  runInAction(() => {
34
55
  this.status = 'unknown'
35
56
  this.statusVia = null
57
+ this.lastProbeError = null // the previous host's failure must not show under the new one
36
58
  })
37
59
  this.probeGen++
38
60
  if (this.loopTimer != null) clearTimeout(this.loopTimer)
@@ -47,6 +69,8 @@ export class HostSt {
47
69
  status: HostStatus = 'unknown'
48
70
  /** 'ws' when the live socket is open, 'http' when only the probe reaches the host */
49
71
  statusVia: 'ws' | 'http' | null = null
72
+ /** why the last http probe failed (timeout, dns, http status) — the stats panel shows it */
73
+ lastProbeError: string | null = null
50
74
  /** a probe is in flight (drives the spinner while down) */
51
75
  probing: boolean = false
52
76
  /** seconds until the next probe (shown while down) */
@@ -86,8 +110,9 @@ export class HostSt {
86
110
  this.loopTimer.unref?.()
87
111
  }
88
112
 
89
- /** http is the ground truth: a half-open ws keeps isOpen=true forever, and
90
- * trusting it would re-create the exact silent-death this dot exists to expose */
113
+ /** http first — a half-open ws keeps isOpen=true forever, so isOpen alone
114
+ * is never trusted. RECENT MESSAGES are: probeVerdict lets a talking ws
115
+ * beat a stalled http probe (busy single-threaded server) */
91
116
  private async probe(): Promise<void> {
92
117
  const host = this.host
93
118
  runInAction(() => {
@@ -103,13 +128,16 @@ export class HostSt {
103
128
  spin.unref?.()
104
129
  this.spinTimer = spin
105
130
  let ok = false
131
+ let probeError: string | null = null
106
132
  try {
107
133
  // host.fetch: /api preferred + auth header, so cloud hosts probe up too
108
134
  const res = await host.fetch('/prompt', { signal: AbortSignal.timeout(PROBE_TIMEOUT_MS) })
109
135
  void res.body?.cancel()
110
136
  ok = res.ok
111
- } catch {
137
+ if (!ok) probeError = `http ${res.status}`
138
+ } catch (e) {
112
139
  ok = false
140
+ probeError = extractErrorMessage(e)
113
141
  } finally {
114
142
  clearInterval(spin)
115
143
  if (this.spinTimer === spin) {
@@ -120,9 +148,16 @@ export class HostSt {
120
148
  }
121
149
  }
122
150
  if (this.host !== host) return // workflow switched mid-flight: stale verdict
151
+ const verdict = probeVerdict({
152
+ httpOk: ok,
153
+ wsOpen: host.isConnected,
154
+ lastWsMessageAt: host.lastWsMessageAt,
155
+ now: Date.now(),
156
+ })
123
157
  runInAction(() => {
124
- this.status = ok ? 'up' : 'down'
125
- this.statusVia = ok ? (host.isConnected ? 'ws' : 'http') : null
158
+ this.status = verdict.status
159
+ this.statusVia = verdict.via
160
+ this.lastProbeError = probeError
126
161
  })
127
162
  }
128
163
 
@@ -138,7 +173,7 @@ export class HostSt {
138
173
  ]
139
174
 
140
175
  get host(): ComfyHost {
141
- return this.st.wf.host
176
+ return this.st.runHost
142
177
  }
143
178
 
144
179
  get stats(): { label: string; value: string }[] {
@@ -151,6 +186,8 @@ export class HostSt {
151
186
  ? `down · ${this.probing ? `${this.spinner} probing…` : `retry in ${this.retryInS}s`}`
152
187
  : this.status + (this.statusVia != null ? ` (${this.statusVia})` : ''),
153
188
  },
189
+ // the WHY behind a down dot (or an up-via-ws with http stalling: busy server)
190
+ ...(this.lastProbeError != null ? [{ label: 'http probe', value: this.lastProbeError }] : []),
154
191
  { label: 'node types', value: String(schema.nodes.length) },
155
192
  { label: 'loras', value: String(schema.getLoras().length) },
156
193
  { label: 'embeddings', value: String(schema.data.embeddings.length) },
@@ -168,6 +205,53 @@ export class HostSt {
168
205
  this.st.mode = 'nav'
169
206
  }
170
207
 
208
+ // ---- `h` host picker: override the host the current workflow runs against ----
209
+
210
+ pickerIx: number = 0
211
+
212
+ get pickerRows(): { host: ComfyHost | null; label: string; active: boolean }[] {
213
+ const wfHost = this.st.wf.host
214
+ const rows: { host: ComfyHost | null; label: string; active: boolean }[] = [
215
+ { host: null, label: `workflow default (${wfHost.data.id})`, active: this.st.hostOverride == null },
216
+ ]
217
+ // the global registry: every host any imported module registered so far
218
+ for (const host of comfyts.hosts.values()) {
219
+ rows.push({
220
+ host,
221
+ label: `${host.data.id} (${host.base.host}:${host.base.port})`,
222
+ active: this.st.hostOverride === host,
223
+ })
224
+ }
225
+ return rows
226
+ }
227
+
228
+ beginPicker(): void {
229
+ this.st.mode = 'overlay-hosts'
230
+ const active = this.pickerRows.findIndex((r) => r.active)
231
+ this.pickerIx = active === -1 ? 0 : active
232
+ }
233
+
234
+ cancelPicker(): void {
235
+ this.st.mode = 'nav'
236
+ }
237
+
238
+ pickerMove(delta: number): void {
239
+ const len = this.pickerRows.length
240
+ if (len === 0) return
241
+ this.pickerIx = (this.pickerIx + delta + len) % len
242
+ }
243
+
244
+ commitPicker(): void {
245
+ const row = this.pickerRows[this.pickerIx]
246
+ if (row == null) return
247
+ this.st.setHostOverride(row.host)
248
+ this.st.mode = 'nav'
249
+ this.st.exec.notice =
250
+ row.host == null
251
+ ? `host override cleared — runs target the workflow's own host (${this.st.wf.host.data.id})`
252
+ : `runs now target ${row.host.data.id} (overrides ${this.st.wf.host.data.id})`
253
+ }
254
+
171
255
  move(delta: number): void {
172
256
  const len = this.actions.length
173
257
  this.ix = (this.ix + delta + len) % len
@@ -16,6 +16,9 @@ export class PickerSt {
16
16
  ix: number = 0
17
17
  /** size overlay only: the filter failed to parse as WxH on commit */
18
18
  invalid: boolean = false
19
+ /** size overlay only: the linked image var's live dims, read ONCE per open
20
+ * (fs read — never inside the options computed, which runs per keystroke) */
21
+ imageSizeRow: string | null = null
19
22
 
20
23
  // kind-narrowing casts sanctioned (agent/coding.md), `kind` is the tag
21
24
  private get choiceVar(): ChoiceVar<string> | null {
@@ -37,6 +40,7 @@ export class PickerSt {
37
40
  const sv = this.sizeVar
38
41
  if (sv != null) {
39
42
  const labels = sv.presets.map((p) => `${p.width}×${p.height} ${p.label}`)
43
+ if (this.imageSizeRow != null) labels.unshift(this.imageSizeRow)
40
44
  if (this.filter === '') return labels
41
45
  return labels.filter((l) => fuzzyMatch(this.filter, l))
42
46
  }
@@ -58,8 +62,10 @@ export class PickerSt {
58
62
  this.st.mode = 'overlay-size'
59
63
  this.filter = ''
60
64
  this.invalid = false
61
- const ix = sv.presets.findIndex((p) => p.width === sv.value.width && p.height === sv.value.height)
62
- this.ix = ix === -1 ? 0 : ix
65
+ const img = sv.imageSize()
66
+ this.imageSizeRow = img == null ? null : `${img.width}×${img.height} size of image '${img.name}'`
67
+ const presetIx = sv.presets.findIndex((p) => p.width === sv.value.width && p.height === sv.value.height)
68
+ this.ix = presetIx === -1 ? 0 : presetIx + (this.imageSizeRow != null ? 1 : 0)
63
69
  }
64
70
 
65
71
  move(delta: number): void {
@@ -33,7 +33,7 @@ export class QueueSt {
33
33
 
34
34
  async clearPending(): Promise<void> {
35
35
  try {
36
- await this.st.wf.host.clearQueue()
36
+ await this.st.runHost.clearQueue()
37
37
  runInAction(() => {
38
38
  this.st.exec.notice = 'pending queue cleared'
39
39
  })
@@ -46,7 +46,7 @@ export class QueueSt {
46
46
 
47
47
  async interrupt(): Promise<void> {
48
48
  try {
49
- await this.st.wf.host.interrupt()
49
+ await this.st.runHost.interrupt()
50
50
  runInAction(() => {
51
51
  this.st.exec.notice = 'interrupt requested'
52
52
  })
@@ -41,17 +41,26 @@ export class SettingsSt {
41
41
  makeAutoObservable<SettingsSt, 'st'>(this, { st: false })
42
42
  this.st.disposers.push(
43
43
  reaction(
44
- () =>
45
- JSON.stringify({
46
- previewPanel: this.previewPanel,
47
- previewRenderer: this.previewRenderer,
48
- previewDuringRun: this.previewDuringRun,
49
- lastDraft: this.lastDraft,
50
- }),
44
+ () => this.snapshotJson(),
51
45
  (json) => this.write(json),
52
46
  { delay: 300 },
53
47
  ),
54
48
  )
49
+ // the delayed reaction can be cancelled by dispose with a write pending —
50
+ // and lastWorkflow's whole point is exit state: flush on the way out
51
+ this.st.disposers.push(() => this.write(this.snapshotJson()))
52
+ }
53
+
54
+ private snapshotJson(): string {
55
+ return JSON.stringify({
56
+ previewPanel: this.previewPanel,
57
+ previewRenderer: this.previewRenderer,
58
+ previewDuringRun: this.previewDuringRun,
59
+ lastDraft: this.lastDraft,
60
+ lastWorkflow: this.lastWorkflow,
61
+ hostOverrideId: this.hostOverrideId,
62
+ collapsedDirs: this.collapsedDirs,
63
+ })
55
64
  }
56
65
 
57
66
  previewPanel: boolean = true
@@ -59,6 +68,12 @@ export class SettingsSt {
59
68
  previewDuringRun: PreviewDuringRun = 'latent'
60
69
  /** module basename → the draft that was active last time (reopened on load) */
61
70
  lastDraft: Record<string, string> = {}
71
+ /** path of the last OPEN workflow module — a no-arg `tui` reopens it (his ask 2026-07-30) */
72
+ lastWorkflow: string | null = null
73
+ /** the `h` host override, by host id (re-resolved once that host registers) */
74
+ hostOverrideId: string | null = null
75
+ /** folded tree dirs (hand-tuned state persists, like every other surface) */
76
+ collapsedDirs: string[] = []
62
77
 
63
78
  rememberDraft(moduleKey: string, draft: string): void {
64
79
  this.lastDraft[moduleKey] = draft
@@ -81,6 +96,9 @@ export class SettingsSt {
81
96
  this.previewDuringRun = preview.previewDuringRun
82
97
  if (o.lastDraft != null && typeof o.lastDraft === 'object')
83
98
  this.lastDraft = { ...(o.lastDraft as Record<string, string>) }
99
+ if (typeof o.lastWorkflow === 'string') this.lastWorkflow = o.lastWorkflow
100
+ if (typeof o.hostOverrideId === 'string') this.hostOverrideId = o.hostOverrideId
101
+ if (Array.isArray(o.collapsedDirs)) this.collapsedDirs = o.collapsedDirs.filter((d) => typeof d === 'string')
84
102
  } catch {
85
103
  // corrupt settings must never block the TUI — start from defaults
86
104
  }