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
@@ -0,0 +1,119 @@
1
+ // PURE payload → var application: one POST body value onto one var, per kind.
2
+ // Returns an error message (nothing applied) or null. No fs here — ImageVar
3
+ // url download + existence checks are ServeApp's job.
4
+ import {
5
+ type AnyVar,
6
+ ChoiceVar,
7
+ FloatVar,
8
+ ImageVar,
9
+ IntVar,
10
+ type LoraStrength,
11
+ LorasVar,
12
+ PromptVar,
13
+ SeedVar,
14
+ SizeVar,
15
+ TextVar,
16
+ ToggleVar,
17
+ } from 'src/vars/ComfyVars.ts'
18
+
19
+ function isFiniteNumber(x: unknown): x is number {
20
+ return typeof x === 'number' && Number.isFinite(x)
21
+ }
22
+
23
+ function isLoraStrength(x: unknown): x is LoraStrength {
24
+ if (typeof x === 'boolean') return true
25
+ if (isFiniteNumber(x)) return true
26
+ return Array.isArray(x) && x.length === 2 && isFiniteNumber(x[0]) && isFiniteNumber(x[1])
27
+ }
28
+
29
+ /** cap long option lists in error messages */
30
+ function listSome(items: readonly string[], cap: number = 20): string {
31
+ if (items.length <= cap) return items.join(', ')
32
+ return `${items.slice(0, cap).join(', ')} … +${items.length - cap} more`
33
+ }
34
+
35
+ export function applyVarPayload(varDef: AnyVar, raw: unknown): string | null {
36
+ const name = varDef.name ?? varDef.label ?? varDef.kind
37
+
38
+ if (varDef instanceof TextVar || varDef instanceof PromptVar) {
39
+ if (typeof raw !== 'string') return `var '${name}' expects a string`
40
+ varDef.set(raw)
41
+ return null
42
+ }
43
+
44
+ if (varDef instanceof IntVar || varDef instanceof FloatVar) {
45
+ if (isFiniteNumber(raw)) {
46
+ varDef.set(raw) // set() clamps to min/max
47
+ return null
48
+ }
49
+ if (typeof raw === 'string' && varDef.parse(raw)) return null
50
+ const o = varDef.opts
51
+ const range = o.min == null && o.max == null ? '' : ` (${o.min ?? '-∞'}..${o.max ?? '∞'})`
52
+ return `var '${name}' expects a number${range}`
53
+ }
54
+
55
+ if (varDef instanceof SeedVar) {
56
+ if (isFiniteNumber(raw)) {
57
+ // an explicit payload seed is FIXED for this request
58
+ varDef.setMode('=')
59
+ varDef.set(raw)
60
+ return null
61
+ }
62
+ if (raw != null && typeof raw === 'object' && !Array.isArray(raw)) {
63
+ const o = raw as { mode?: unknown; value?: unknown }
64
+ const mode = o.mode === '=' || o.mode === '+' || o.mode === '-' || o.mode === '?' ? o.mode : null
65
+ if (o.mode !== undefined && mode == null) return `var '${name}': mode must be one of = + - ?`
66
+ if (o.value !== undefined && !isFiniteNumber(o.value)) return `var '${name}': value must be a number`
67
+ if (mode == null && o.value === undefined) return `var '${name}': give "mode" and/or "value"`
68
+ if (mode != null) varDef.setMode(mode)
69
+ if (isFiniteNumber(o.value)) varDef.set(o.value)
70
+ return null
71
+ }
72
+ return `var '${name}' expects a number or {"mode":"=|+|-|?","value":number}`
73
+ }
74
+
75
+ if (varDef instanceof ToggleVar) {
76
+ if (typeof raw !== 'boolean') return `var '${name}' expects true or false`
77
+ varDef.set(raw)
78
+ return null
79
+ }
80
+
81
+ if (varDef instanceof ChoiceVar) {
82
+ if (typeof raw === 'string' && varDef.parse(raw)) return null
83
+ return `var '${name}' expects one of: ${listSome(varDef.choices)}`
84
+ }
85
+
86
+ if (varDef instanceof LorasVar) {
87
+ if (raw == null || typeof raw !== 'object' || Array.isArray(raw))
88
+ return `var '${name}' expects {"<lora name>": false | true | strength | [model, clip]}`
89
+ const record = raw as Record<string, unknown>
90
+ const known = new Set<string>(varDef.options)
91
+ const unknownNames = Object.keys(record).filter((k) => !known.has(k))
92
+ if (unknownNames.length > 0)
93
+ return `var '${name}': unknown lora(s) ${unknownNames.join(', ')} — available: ${listSome(varDef.options)}`
94
+ for (const [k, s] of Object.entries(record))
95
+ if (!isLoraStrength(s)) return `var '${name}': '${k}' must be false | true | number | [model, clip]`
96
+ varDef.set(record as Partial<Record<string, LoraStrength>>) // every entry validated just above
97
+ return null
98
+ }
99
+
100
+ if (varDef instanceof SizeVar) {
101
+ if (typeof raw === 'string' && varDef.parse(raw)) return null
102
+ if (raw != null && typeof raw === 'object' && !Array.isArray(raw)) {
103
+ const o = raw as { width?: unknown; height?: unknown }
104
+ if (isFiniteNumber(o.width) && isFiniteNumber(o.height)) {
105
+ varDef.set({ width: o.width, height: o.height })
106
+ return null
107
+ }
108
+ }
109
+ return `var '${name}' expects {"width":W,"height":H}, "WxH", or a preset label`
110
+ }
111
+
112
+ if (varDef instanceof ImageVar) {
113
+ if (typeof raw !== 'string') return `var '${name}' expects a file path or http(s) url string`
114
+ varDef.set(raw)
115
+ return null
116
+ }
117
+
118
+ return `var '${name}' has unsupported kind '${varDef.kind}'`
119
+ }
@@ -0,0 +1,74 @@
1
+ // PURE var → descriptor: ONE introspection pass feeds GET /drafts (json) AND
2
+ // the startup print (renderDescriptorLine)
3
+ import {
4
+ type AnyVar,
5
+ ChoiceVar,
6
+ FloatVar,
7
+ ImageVar,
8
+ IntVar,
9
+ LorasVar,
10
+ PromptVar,
11
+ SeedVar,
12
+ SizeVar,
13
+ type SizePreset,
14
+ type VarKind,
15
+ } from 'src/vars/ComfyVars.ts'
16
+
17
+ export type VarDescriptor = {
18
+ kind: VarKind
19
+ label?: string
20
+ /** what a POST payload accepts for this var, human-readable */
21
+ payload: string
22
+ default: unknown
23
+ choices?: readonly string[]
24
+ /** loras: the resolved option list */
25
+ options?: readonly string[]
26
+ min?: number
27
+ max?: number
28
+ presets?: SizePreset[]
29
+ extensions?: readonly string[]
30
+ }
31
+
32
+ function rangeText(opts: { min?: number; max?: number }): string {
33
+ if (opts.min == null && opts.max == null) return ''
34
+ return ` (${opts.min ?? '-∞'}..${opts.max ?? '∞'})`
35
+ }
36
+
37
+ export function describeVar(varDef: AnyVar): VarDescriptor {
38
+ const base = { kind: varDef.kind, label: varDef.label, default: varDef.defaultValue }
39
+ if (varDef instanceof PromptVar) return { ...base, payload: 'string ("//" lines = comments, "- " lines = negative)' }
40
+ if (varDef instanceof IntVar)
41
+ return { ...base, payload: `integer${rangeText(varDef.opts)}`, min: varDef.opts.min, max: varDef.opts.max }
42
+ if (varDef instanceof FloatVar)
43
+ return { ...base, payload: `number${rangeText(varDef.opts)}`, min: varDef.opts.min, max: varDef.opts.max }
44
+ if (varDef instanceof SeedVar)
45
+ return {
46
+ ...base,
47
+ default: { mode: varDef.mode, value: varDef.defaultValue },
48
+ payload: 'number (fixed) or {"mode":"=|+|-|?","value":number}',
49
+ }
50
+ if (varDef.kind === 'toggle') return { ...base, payload: 'true or false' }
51
+ if (varDef instanceof ChoiceVar)
52
+ return { ...base, payload: `one of: ${varDef.choices.join(' | ')}`, choices: varDef.choices }
53
+ if (varDef instanceof LorasVar)
54
+ return {
55
+ ...base,
56
+ payload: '{"<lora name>": false | true | strength | [model, clip]}',
57
+ options: varDef.options,
58
+ }
59
+ if (varDef instanceof SizeVar)
60
+ return { ...base, payload: '{"width":W,"height":H} or "WxH" or a preset label', presets: varDef.presets }
61
+ if (varDef instanceof ImageVar)
62
+ return { ...base, payload: 'local file path or http(s) url', extensions: varDef.extensions }
63
+ return { ...base, payload: 'string' } // TextVar and future plain kinds
64
+ }
65
+
66
+ /** one aligned console line per var (startup print) */
67
+ export function renderDescriptorLine(name: string, d: VarDescriptor, nameWidth: number): string {
68
+ const def = typeof d.default === 'string' ? JSON.stringify(truncate(d.default, 40)) : JSON.stringify(d.default)
69
+ return ` ${name.padEnd(nameWidth)} ${d.kind.padEnd(6)} ${d.payload} · default: ${truncate(def ?? 'null', 60)}`
70
+ }
71
+
72
+ function truncate(s: string, n: number): string {
73
+ return s.length <= n ? s : s.slice(0, n - 1) + '…'
74
+ }
@@ -0,0 +1,169 @@
1
+ // `comfy-ts serve [dir | module.cflow.ts] [--port N] [--bind ADDR]`
2
+ // drafts as a local HTTP generation API — agent/architecture.md item 12
3
+ import { statSync } from 'node:fs'
4
+ import { createServer, type IncomingMessage, type ServerResponse } from 'node:http'
5
+ import { pathToFileURL } from 'node:url'
6
+ import { resolve } from 'pathe'
7
+ import { scanCflowFiles } from 'src/cli/tui/discoverWorkflows.ts'
8
+ import { findDefinedWorkflow } from 'src/cli/tui/findDefinedWorkflow.ts'
9
+ import { draftKeyForFile } from 'src/cli/tui/state/DraftsSt.ts'
10
+ import { describeVar, renderDescriptorLine } from 'src/cli/serve/describeVar.ts'
11
+ import { ServeApp, type ServeModule } from 'src/cli/serve/ServeApp.ts'
12
+ import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
13
+
14
+ const DEFAULT_PORT = 8288
15
+ const BODY_CAP = 10_000_000
16
+
17
+ function parseArgs(args: string[]): { target?: string; port: number; bind: string } | { error: string } {
18
+ let target: string | undefined
19
+ let port = DEFAULT_PORT
20
+ let bind = '127.0.0.1'
21
+ for (let i = 0; i < args.length; i++) {
22
+ const a = args[i]
23
+ if (a === '--port') {
24
+ const n = Number(args[++i])
25
+ if (!Number.isInteger(n) || n <= 0 || n > 65535) return { error: `--port expects 1..65535, got '${args[i]}'` }
26
+ port = n
27
+ } else if (a === '--bind') {
28
+ const b = args[++i]
29
+ if (b == null) return { error: '--bind expects an address' }
30
+ bind = b
31
+ } else if (a != null && a.startsWith('--')) return { error: `unknown flag '${a}'` }
32
+ else if (a != null) {
33
+ if (target != null) return { error: `one target only (got '${target}' and '${a}')` }
34
+ target = a
35
+ }
36
+ }
37
+ return { target, port, bind }
38
+ }
39
+
40
+ /** node:http glue around ServeApp.handle — exported so tests can drive a real socket */
41
+ export function makeRequestListener(app: ServeApp): (req: IncomingMessage, res: ServerResponse) => void {
42
+ return (req, res) => {
43
+ // local bridge, no auth by design: open CORS so browser frontends can call it
44
+ const cors = {
45
+ 'access-control-allow-origin': '*',
46
+ 'access-control-allow-methods': 'GET, POST, OPTIONS',
47
+ 'access-control-allow-headers': 'content-type, accept',
48
+ }
49
+ const chunks: Buffer[] = []
50
+ let size = 0
51
+ let overflow = false
52
+ req.on('error', (e) => console.error(`[serve] request stream error: ${extractErrorMessage(e)}`))
53
+ req.on('data', (c: Buffer) => {
54
+ if (overflow) return
55
+ size += c.length
56
+ if (size > BODY_CAP) {
57
+ // answer NOW: a destroyed request never emits 'end'
58
+ overflow = true
59
+ res.writeHead(413, { 'content-type': 'application/json', ...cors })
60
+ res.end(JSON.stringify({ error: 'payload too large' }), () => req.destroy())
61
+ } else chunks.push(c)
62
+ })
63
+ req.on('end', () => {
64
+ if (overflow) return
65
+ if (req.method === 'OPTIONS') {
66
+ res.writeHead(204, cors)
67
+ res.end()
68
+ return
69
+ }
70
+ app.handle({
71
+ method: req.method ?? 'GET',
72
+ url: req.url ?? '/',
73
+ accept: req.headers.accept,
74
+ body: Buffer.concat(chunks).toString('utf8'),
75
+ })
76
+ .then((reply) => {
77
+ res.writeHead(reply.status, { 'content-type': reply.contentType, ...cors })
78
+ res.end(reply.body)
79
+ })
80
+ .catch((e: unknown) => {
81
+ // handle() catches internally; this guards the response write itself
82
+ console.error(`[serve] response write failed: ${extractErrorMessage(e)}`)
83
+ res.destroy()
84
+ })
85
+ })
86
+ }
87
+ }
88
+
89
+ export async function runServe(args: string[]): Promise<number> {
90
+ const parsed = parseArgs(args)
91
+ if ('error' in parsed) {
92
+ console.error(`[comfy-ts serve] ${parsed.error}`)
93
+ return 1
94
+ }
95
+
96
+ // discovery: explicit file → that module only; dir/no-arg → scan, WITHOUT
97
+ // the bundled examples (serve is for the user's tuned drafts)
98
+ const target = resolve(parsed.target ?? '.')
99
+ let files: string[]
100
+ try {
101
+ files = statSync(target).isDirectory() ? scanCflowFiles(target) : [target]
102
+ } catch {
103
+ console.error(`[comfy-ts serve] no such file or directory: ${target}`)
104
+ return 1
105
+ }
106
+ if (files.length === 0) {
107
+ console.error(`[comfy-ts serve] no *.cflow.ts modules under ${target}`)
108
+ return 1
109
+ }
110
+
111
+ const modules: ServeModule[] = []
112
+ const loadErrors: Record<string, string> = {}
113
+ for (const file of files) {
114
+ try {
115
+ const mod: Record<string, unknown> = await import(pathToFileURL(file).href)
116
+ const dw = findDefinedWorkflow(mod)
117
+ if (dw == null) throw new Error('exports no DefinedWorkflow')
118
+ const key = draftKeyForFile(file)
119
+ const clash = modules.find((m) => m.key === key)
120
+ if (clash != null) throw new Error(`module key '${key}' already taken by ${clash.file}`)
121
+ modules.push({ key, file, dw })
122
+ } catch (e) {
123
+ loadErrors[file] = extractErrorMessage(e)
124
+ console.error(`[comfy-ts serve] ✗ ${file}: ${loadErrors[file]}`)
125
+ }
126
+ }
127
+ if (modules.length === 0) {
128
+ console.error('[comfy-ts serve] every module failed to load — nothing to serve')
129
+ return 1
130
+ }
131
+
132
+ const app = new ServeApp(modules, { loadErrors })
133
+ printStartup(app, parsed.bind, parsed.port)
134
+
135
+ const server = createServer(makeRequestListener(app))
136
+
137
+ server.on('error', (e) => {
138
+ console.error(`[comfy-ts serve] server error: ${extractErrorMessage(e)}`)
139
+ process.exitCode = 1
140
+ server.close()
141
+ })
142
+ server.listen(parsed.port, parsed.bind)
143
+
144
+ // stays up until the process is interrupted or the server dies
145
+ return new Promise<number>((resolveExit) => {
146
+ server.on('close', () => resolveExit(typeof process.exitCode === 'number' ? process.exitCode : 0))
147
+ })
148
+ }
149
+
150
+ function printStartup(app: ServeApp, bind: string, port: number): void {
151
+ const base = `http://${bind}:${port}`
152
+ console.log(`comfy-ts serve · ${app.modules.length} workflow(s) · ${base}/`)
153
+ if (bind !== '127.0.0.1' && bind !== 'localhost')
154
+ console.log(`⚠️ bound to ${bind} — this API has NO AUTH and runs workflows on your ComfyUI host`)
155
+ for (const mod of app.modules) {
156
+ console.log(`\n${mod.key} (host: ${mod.dw.host.data.id})`)
157
+ for (const draft of app.draftsFor(mod))
158
+ console.log(` POST ${base}/generate/${encodeURIComponent(mod.key)}/${encodeURIComponent(draft)}`)
159
+ const entries = mod.dw.entries()
160
+ const nameWidth = Math.max(...entries.map(([n]) => n.length), 4)
161
+ for (const [name, varDef] of entries) console.log(renderDescriptorLine(name, describeVar(varDef), nameWidth))
162
+ }
163
+ const firstMod = app.modules[0]
164
+ if (firstMod != null)
165
+ console.log(
166
+ `\ntry: curl -X POST ${base}/generate/${encodeURIComponent(firstMod.key)}/default -H 'content-type: application/json' -d '{}'`,
167
+ )
168
+ console.log(`docs: GET ${base}/drafts (json index of everything above)`)
169
+ }
@@ -0,0 +1,25 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import { KeyHints } from 'src/cli/tui/components/StatusBar.tsx'
4
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
5
+
6
+ /** `c`/`C` confirmation popup: WHAT landed in the clipboard (or the loud
7
+ * failure) — a copy is never silent again. ⏎/esc closes. */
8
+ export const CopyOverlay = observer((p: { st: TuiSt }) => {
9
+ const popup = p.st.exec.copyPopup
10
+ if (popup == null) return null
11
+ return (
12
+ <Box borderStyle="double" borderColor={popup.ok ? 'green' : 'red'} paddingX={1} flexDirection="column">
13
+ <Text bold color={popup.ok ? 'green' : 'red'}>
14
+ {popup.ok ? '✓ ' : '✗ '}
15
+ {popup.title}
16
+ </Text>
17
+ {popup.lines.slice(0, p.st.overlayLines).map((line, ix) => (
18
+ <Text key={`${ix}·${line.slice(0, 12)}`} color={popup.ok ? undefined : 'red'} wrap="truncate">
19
+ {line}
20
+ </Text>
21
+ ))}
22
+ <KeyHints hints={[['⏎/esc', 'close']]} />
23
+ </Box>
24
+ )
25
+ })
@@ -15,9 +15,10 @@ const HeaderBox = (p: { title?: string; children: ReactNode }): ReactNode => (
15
15
  </Box>
16
16
  )
17
17
 
18
- /** labeled header boxes: brand · (w)orkflow · (d)raft · (h)ost — the keys open each surface */
18
+ /** labeled header boxes: brand · (w)orkflow · (d)raft · (h)ost·(a)ctions — the keys open each surface */
19
19
  export const Header = observer((p: { st: TuiSt }) => {
20
20
  const s = p.st
21
+ const runHost = s.runHost
21
22
  return (
22
23
  <Box flexDirection="row">
23
24
  <HeaderBox>
@@ -35,16 +36,20 @@ export const Header = observer((p: { st: TuiSt }) => {
35
36
  {s.drafts.active ?? 'default'}
36
37
  </Text>
37
38
  </HeaderBox>
38
- <HeaderBox title="(h)ost">
39
+ <HeaderBox title="(h)ost · (a)ctions">
39
40
  <Text>
40
41
  <Text color={s.host.status === 'up' ? 'green' : s.host.status === 'down' ? 'red' : 'gray'}>● </Text>
41
42
  <Text bold color="green">
42
- {s.wf.host.data.id}
43
+ {runHost.data.id}
43
44
  </Text>
44
45
  <Text color="gray">
45
46
  {' '}
46
- ({s.wf.host.data.host}:{s.wf.host.data.port})
47
+ ({runHost.base.host}:{runHost.base.port})
47
48
  </Text>
49
+ {/* the override must stay loud: every run bypasses the workflow's own host */}
50
+ {s.hostOverride != null && s.hostOverride !== s.wf.host && (
51
+ <Text color="yellow"> ⇄ overrides {s.wf.host.data.id}</Text>
52
+ )}
48
53
  {/* while down, show the probe loop living: spinner in flight, countdown between tries */}
49
54
  {s.host.status === 'down' && (
50
55
  <Text color="red"> {s.host.probing ? s.host.spinner : `↻ ${s.host.retryInS}s`}</Text>
@@ -9,10 +9,11 @@ export const HostPanel = observer((p: { st: TuiSt }) => {
9
9
  return (
10
10
  <Box borderStyle="double" paddingX={1} flexDirection="column">
11
11
  <Text bold>
12
- host · <Text color="green">{h.host.data.id}</Text>{' '}
12
+ host actions · <Text color="green">{h.host.data.id}</Text>{' '}
13
13
  <Text color="gray">
14
- ({h.host.data.host}:{h.host.data.port})
14
+ ({h.host.base.host}:{h.host.base.port})
15
15
  </Text>
16
+ {s.hostOverride != null && <Text color="yellow"> ⇄ override</Text>}
16
17
  </Text>
17
18
  {h.stats.map((row) => (
18
19
  <Text key={row.label}>
@@ -0,0 +1,33 @@
1
+ import { Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import { OverlayList } from 'src/cli/tui/components/OverlayList.tsx'
4
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
5
+
6
+ /** modal host picker (`h`): row 0 restores the workflow's own host, the rest
7
+ * override where runs are built and sent (every registered host is listed) */
8
+ export const HostsOverlay = observer((p: { st: TuiSt }) => {
9
+ const s = p.st
10
+ const h = s.host
11
+ const rows = h.pickerRows.map((row, ix) => ({
12
+ key: row.host?.data.id ?? '·default·',
13
+ node: (
14
+ <Text key={row.host?.data.id ?? '·default·'} inverse={ix === h.pickerIx}>
15
+ {ix === h.pickerIx ? '▸ ' : ' '}
16
+ {row.active ? '● ' : ' '}
17
+ {row.label}
18
+ </Text>
19
+ ),
20
+ }))
21
+ return (
22
+ <OverlayList
23
+ title={
24
+ <>
25
+ run host <Text color="gray">· overrides the workflow's configured host</Text>
26
+ </>
27
+ }
28
+ selectedIx={h.pickerIx}
29
+ lines={s.overlayLines}
30
+ rows={rows}
31
+ />
32
+ )
33
+ })
@@ -130,11 +130,26 @@ const MODE_KEYS: Partial<Record<string, Hint[]>> = {
130
130
  ['esc', 'cancel'],
131
131
  ],
132
132
  'overlay-drafts': [['⏎', 'load / new'], ...DRAFT_OP_HINTS, ['↑↓', 'move'], ['esc', 'cancel']],
133
- tree: [['⏎', 'load'], ['↑↓', 'move'], ['←', 'fold'], ['→', 'unfold / vars'], ...DRAFT_OP_HINTS, ['t/esc', 'back']],
133
+ 'overlay-hosts': [
134
+ ['⏎', 'pick run host'],
135
+ ['↑↓', 'move'],
136
+ ['esc', 'cancel'],
137
+ ],
138
+ 'overlay-copy': [['⏎/esc', 'close']],
139
+ tree: [
140
+ ['⏎', 'load'],
141
+ ['↑↓', 'move'],
142
+ ['←', 'fold'],
143
+ ['→', 'unfold / vars'],
144
+ ['/', 'filter'],
145
+ ...DRAFT_OP_HINTS,
146
+ ['t/esc', 'back'],
147
+ ],
134
148
  host: [
135
149
  ['⏎', 'run action'],
136
150
  ['↑↓', 'move'],
137
- ['h/esc', 'back'],
151
+ ['h', 'change host'],
152
+ ['a/esc', 'back'],
138
153
  ],
139
154
  preview: [
140
155
  ['←→', 'change'],
@@ -147,15 +162,19 @@ const MODE_KEYS: Partial<Record<string, Hint[]>> = {
147
162
  export const KeyBar = observer((p: { st: TuiSt }) => {
148
163
  const s = p.st
149
164
  const kind = s.selected?.[1].kind
150
- const modeHints: Hint[] = MODE_KEYS[s.mode] ?? [
151
- ['↑↓', 'select'],
152
- ['←', 'tree'],
153
- ...(kind ? (KIND_KEYS[kind] ?? []) : []),
154
- ]
155
- // keys already advertised by a panel title (t/v/p) or a header box (w/d/h)
165
+ const treeFiltering = s.mode === 'tree' && s.tree.filtering
166
+ const modeHints: Hint[] = treeFiltering
167
+ ? [
168
+ ['type', 'filter'],
169
+ ['⏎', 'load'],
170
+ ['↑↓', 'move'],
171
+ ['esc', 'clear'],
172
+ ]
173
+ : (MODE_KEYS[s.mode] ?? [['↑↓', 'select'], ['←', 'tree'], ...(kind ? (KIND_KEYS[kind] ?? []) : [])])
174
+ // keys already advertised by a panel title (t/v/p) or a header box (w/d/h/a)
156
175
  // are NOT repeated here — one letter, one place
157
176
  const globalHints: Hint[] =
158
- s.mode === 'nav' || s.mode === 'tree' || s.mode === 'host' || s.mode === 'preview'
177
+ !treeFiltering && (s.mode === 'nav' || s.mode === 'tree' || s.mode === 'host' || s.mode === 'preview')
159
178
  ? [
160
179
  ['r', 'run'],
161
180
  ['s', 'reroll+run'],
@@ -163,6 +182,7 @@ export const KeyBar = observer((p: { st: TuiSt }) => {
163
182
  // the preview panel carries `p` in its title — unless it is hidden
164
183
  ...(s.preview.show || s.mode === 'preview' ? [] : ([['p', 'preview (off)']] as Hint[])),
165
184
  ['o', 'open image'],
185
+ ['i', 'copy image'],
166
186
  // c is duplicate inside the tree — don't advertise the copy pair
167
187
  // there; the preview menu doesn't forward it either
168
188
  ...(s.mode === 'tree' || s.mode === 'preview' ? [] : ([['c/C', 'copy wf/api']] as Hint[])),
@@ -1,20 +1,32 @@
1
- import { Box, Text } from 'ink'
1
+ import { Box, measureElement, Text } from 'ink'
2
2
  import { observer } from 'mobx-react-lite'
3
+ import { useEffect, useRef } from 'react'
4
+ import type { DOMElement } from 'ink'
3
5
  import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
4
6
 
5
- /** persistent left panel: workflows with their drafts nested; `t` (or ← from vars) focuses it */
7
+ /** persistent left panel: directory hierarchy + workflows with their drafts
8
+ * nested; `t` (or ← from vars) focuses it, `/` filters it. The Box is
9
+ * measured (keybar wraps, chrome height is width-dependent — arithmetic
10
+ * lies) and the row list windows to the measured budget; overflow hidden
11
+ * is the backstop for the one pre-measure frame. */
6
12
  export const TreePanel = observer((p: { st: TuiSt }) => {
7
13
  const s = p.st
8
14
  const tree = s.tree
9
15
  const focused = s.mode === 'tree'
16
+ const boxRef = useRef<DOMElement>(null)
17
+ useEffect(() => {
18
+ if (boxRef.current != null) tree.setViewH(measureElement(boxRef.current).height)
19
+ })
10
20
  return (
11
21
  <Box
22
+ ref={boxRef}
12
23
  borderStyle="round"
13
24
  borderColor={focused ? 'cyan' : 'gray'}
14
25
  flexDirection="column"
15
26
  flexShrink={0}
16
27
  width={s.treeWidth}
17
28
  paddingX={1}
29
+ overflow="hidden"
18
30
  >
19
31
  {/* marginTop -1 lifts the label onto the border line: the panel key IS its title */}
20
32
  <Box marginTop={-1}>
@@ -22,12 +34,22 @@ export const TreePanel = observer((p: { st: TuiSt }) => {
22
34
  (t)ree
23
35
  </Text>
24
36
  </Box>
25
- {tree.rows.map((row, ix) => {
37
+ {(tree.filtering || tree.filter !== '') && (
38
+ <Text color="yellow" wrap="truncate">
39
+ /{tree.filter}
40
+ {tree.filtering ? '▌' : ''}
41
+ </Text>
42
+ )}
43
+ {tree.window.moreAbove && <Text color="gray">…</Text>}
44
+ {tree.rows.slice(tree.window.start, tree.window.end).map((row, sliceIx) => {
45
+ const ix = tree.window.start + sliceIx
26
46
  const sel = focused && ix === tree.ix
27
- if (row.kind === 'section') {
47
+ const indent = ' '.repeat(row.depth * 2)
48
+ if (row.kind === 'dir') {
28
49
  return (
29
- <Text key={`section·${row.label}`} color="gray" dimColor wrap="truncate">
30
- ─ {row.label}
50
+ <Text key={`dir·${row.path}`} inverse={sel} color="gray" bold wrap="truncate">
51
+ {indent}
52
+ {row.expanded ? '▾' : '▸'} {row.label}
31
53
  </Text>
32
54
  )
33
55
  }
@@ -38,9 +60,11 @@ export const TreePanel = observer((p: { st: TuiSt }) => {
38
60
  <Text
39
61
  key={row.file}
40
62
  inverse={sel}
41
- color={row.error != null ? 'red' : row.current ? 'green' : undefined}
63
+ bold={row.current}
64
+ color={row.error != null ? 'red' : row.color}
42
65
  wrap="truncate"
43
66
  >
67
+ {indent}
44
68
  {arrow}
45
69
  {marker} {row.name}
46
70
  </Text>
@@ -53,11 +77,11 @@ export const TreePanel = observer((p: { st: TuiSt }) => {
53
77
  color={row.active ? 'cyan' : 'gray'}
54
78
  wrap="truncate"
55
79
  >
56
- {' '}
57
- {row.active ? '●' : '·'} {row.draft}
80
+ {indent} {row.active ? '●' : '·'} {row.draft}
58
81
  </Text>
59
82
  )
60
83
  })}
84
+ {tree.window.moreBelow && <Text color="gray">…</Text>}
61
85
  {s.workflows.loading ? <Text color="yellow">loading…</Text> : null}
62
86
  </Box>
63
87
  )