comfy-ts 2.15.0 → 2.17.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 (76) hide show
  1. package/README.md +23 -0
  2. package/dist/{run-serve-B5PfIuhK.js → ServeApp-BSA5yzxZ.js} +28 -446
  3. package/dist/ServeApp-BSA5yzxZ.js.map +1 -0
  4. package/dist/cli.js +18 -5
  5. package/dist/cli.js.map +1 -1
  6. package/dist/exampleAssets-BfWzygoM.js +38 -0
  7. package/dist/exampleAssets-BfWzygoM.js.map +1 -0
  8. package/dist/{LogsSt-C3UIWR-o.js → findDefinedWorkflow-0lG-VTEd.js} +201 -201
  9. package/dist/findDefinedWorkflow-0lG-VTEd.js.map +1 -0
  10. package/dist/index.cjs +202 -62
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +115 -14
  13. package/dist/index.d.ts +115 -14
  14. package/dist/index.js +202 -62
  15. package/dist/index.js.map +1 -1
  16. package/dist/run-run-DnaMLCFn.js +450 -0
  17. package/dist/run-run-DnaMLCFn.js.map +1 -0
  18. package/dist/run-serve-CbKxIu6i.js +418 -0
  19. package/dist/run-serve-CbKxIu6i.js.map +1 -0
  20. package/dist/{run-tui-D-N4_yyX.js → run-tui-B0AQWbad.js} +6 -37
  21. package/dist/run-tui-B0AQWbad.js.map +1 -0
  22. package/dist/{schemaDrift-BkN8rLiZ.js → schemaDrift-CbsABBuk.js} +59 -5
  23. package/dist/schemaDrift-CbsABBuk.js.map +1 -0
  24. package/dist/serve-web.js +48 -48
  25. package/dist/{state-CZsYJqB6.js → state-C2oDiQ26.js} +146 -60
  26. package/dist/state-C2oDiQ26.js.map +1 -0
  27. package/dist/web.d.ts +115 -14
  28. package/dist/web.js +202 -62
  29. package/dist/web.js.map +1 -1
  30. package/examples/README.md +2 -0
  31. package/examples/media/README.md +6 -5
  32. package/examples/media/voice_en_6s.flac +0 -0
  33. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +9 -1
  34. package/examples/rvion/10-anima-t2i.cflow.ts +8 -1
  35. package/examples/rvion/15-tts-voice-clone.cflow.ts +111 -0
  36. package/examples/rvion/16-tts-voice-design.cflow.ts +71 -0
  37. package/guide-for-agents.md +5 -1
  38. package/package.json +2 -2
  39. package/src/cli/comfy-ts-cli.ts +14 -1
  40. package/src/cli/run/findModules.ts +36 -0
  41. package/src/cli/run/flagValue.ts +61 -0
  42. package/src/cli/run/outputPaths.ts +41 -0
  43. package/src/cli/run/pickModule.ts +41 -0
  44. package/src/cli/run/run-run.ts +250 -0
  45. package/src/cli/run/runArgs.ts +61 -0
  46. package/src/cli/run/sidecar.ts +27 -0
  47. package/src/cli/serve/ServeApp.ts +28 -42
  48. package/src/cli/serve/web/components/DraftTabs.tsx +10 -3
  49. package/src/cli/serve/web/components/Gallery.tsx +2 -1
  50. package/src/cli/serve/web/components/HistoryPicker.tsx +5 -3
  51. package/src/cli/serve/web/components/MenuButton.tsx +2 -4
  52. package/src/cli/serve/web/components/Omnibox.tsx +2 -1
  53. package/src/cli/serve/web/components/PromptEnhancer.tsx +4 -3
  54. package/src/cli/serve/web/components/ShortcutsModal.tsx +2 -1
  55. package/src/cli/serve/web/components/SideMenu.tsx +2 -1
  56. package/src/cli/serve/web/components/controls/LorasControl.tsx +4 -3
  57. package/src/cli/serve/web/components/controls/PresetPicker.tsx +2 -1
  58. package/src/cli/serve/web/components/controls/PromptControl.tsx +2 -1
  59. package/src/cli/serve/web/components/controls/SizeControl.tsx +2 -1
  60. package/src/cli/serve/web/state/draftTabs.ts +12 -0
  61. package/src/cli/serve/web/state/escape.ts +16 -0
  62. package/src/cli/serve/web/state/shortcutCatalog.ts +1 -0
  63. package/src/coreExports.ts +12 -1
  64. package/src/host/ComfyHost.ts +73 -40
  65. package/src/host/previewMethod.ts +29 -0
  66. package/src/runner/ComfyExecution.ts +45 -1
  67. package/src/runner/ComfyWorkflow.ts +6 -1
  68. package/src/runner/ComfyWsApi.ts +1 -1
  69. package/src/runner/wsBinaryFrame.ts +48 -25
  70. package/src/vars/ComfyVars.ts +86 -13
  71. package/src/vars/DefinedWorkflow.ts +36 -2
  72. package/dist/LogsSt-C3UIWR-o.js.map +0 -1
  73. package/dist/run-serve-B5PfIuhK.js.map +0 -1
  74. package/dist/run-tui-D-N4_yyX.js.map +0 -1
  75. package/dist/schemaDrift-BkN8rLiZ.js.map +0 -1
  76. package/dist/state-CZsYJqB6.js.map +0 -1
@@ -9,6 +9,8 @@ Every `*.cflow.ts` file here is a runnable workflow module: run it directly with
9
9
  - `rvion/06-qwen-image-edit.cflow.ts` — image editing (qwen image edit 2511) against the same local host.
10
10
  - `rvion/07-local-llm-text-gen.cflow.ts` — a local LLM, no image: core's `TextGenerate` runs a chat model loaded through `CLIPLoader`, and the text comes back in `execution.text`. `--sweep` reports which text encoders on your host actually generate.
11
11
  - `rvion/08-qwen-image-21-t2i.cflow.ts` / `rvion/09-qwen-image-21-edit.cflow.ts` — Qwen Image 2.1 (ComfyUI ≥ 0.37) against the same local host: text to image, and instruction editing of one reference image (its `remove background` preset is the official background-removal template).
12
+ - `rvion/16-tts-voice-design.cflow.ts`: a new voice from a written description (needs TTS-Audio-Suite, Qwen3-TTS VoiceDesign): it speaks one sample line in that voice, and the clip plus that line are what `15-tts-voice-clone` takes as `voice` and `transcript`. From the command line the flow is two runs: `comfy-ts run tts-voice-design --description "…" --line "…" --out voices/sailor.flac` writes the clip and `voices/sailor.txt`, then `comfy-ts run tts-voice-clone --voice voices/sailor.flac --prompt "…" --out lines/001.flac` speaks any line in it.
13
+ - `rvion/15-tts-voice-clone.cflow.ts` — text to speech in a cloned voice (needs the [TTS-Audio-Suite](https://github.com/diodiogod/TTS-Audio-Suite) custom node pack on the host): pick an engine (Chatterbox Multilingual v3 by default, Qwen3-TTS, Fish Audio S2 Pro, CosyVoice3, OmniVoice) and a language, drop a voice clip and write its transcript, and the text comes back as audio in `execution.audios`.
12
14
  - `comfy-cloud/<family>-<mode>.cflow.ts` — the model zoo: one clean example per model family × mode (`t2i`, `i2i`, `t2v`, `i2v`, `t2a`), each mirroring an official ComfyUI template (flux, qwen-image, z-image, wan, hidream, ace-step, …). All share `comfy-cloud/cloudHost.ts`.
13
15
 
14
16
  ## Cloud API key
@@ -1,8 +1,9 @@
1
1
  # Bundled example media
2
2
 
3
- Default inputs for the examples that take an audio or a video file. They ship in the npm tarball, so these examples run out of the box. Both are synthetic (ffmpeg test sources), so no license question applies.
3
+ Default inputs for the examples that take an audio or a video file. They ship in the npm tarball, so these examples run out of the box. All are synthetic (ffmpeg test sources, or a voice invented by a TTS model), so no license question applies.
4
4
 
5
- | file | what | made with |
6
- | ------------------------ | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
7
- | `testsrc_256x256_3s.mp4` | 3 s, 256×256, 12 fps, h264, no audio track | `ffmpeg -f lavfi -i "testsrc2=size=256x256:rate=12:duration=3" -c:v libx264 -pix_fmt yuv420p -crf 30 -movflags +faststart` |
8
- | `sine_440hz_3s.flac` | 3 s, 440 Hz sine at 30% volume, 22.05 kHz | `ffmpeg -f lavfi -i "sine=frequency=440:duration=3:sample_rate=22050" -af "volume=0.3" -c:a flac` |
5
+ | file | what | made with |
6
+ | ------------------------ | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
7
+ | `testsrc_256x256_3s.mp4` | 3 s, 256×256, 12 fps, h264, no audio track | `ffmpeg -f lavfi -i "testsrc2=size=256x256:rate=12:duration=3" -c:v libx264 -pix_fmt yuv420p -crf 30 -movflags +faststart` |
8
+ | `sine_440hz_3s.flac` | 3 s, 440 Hz sine at 30% volume, 22.05 kHz | `ffmpeg -f lavfi -i "sine=frequency=440:duration=3:sample_rate=22050" -af "volume=0.3" -c:a flac` |
9
+ | `voice_en_6s.flac` | 6.4 s of English speech, 24 kHz mono, the default voice of example 15 | Qwen3-TTS 1.7B VoiceDesign (Apache 2.0), instruction « a calm, warm adult narrator in his thirties, clear diction, neutral American English accent, steady medium pace », text « This is a short sample of my voice. Clone it, and I can read any text you give me, in many languages. », seed 7 |
Binary file
@@ -45,6 +45,14 @@ export const t2i = host.defineWorkflow({
45
45
  // number still says exactly which one you are on
46
46
  seed: v.seed(517, { mode: '+' }),
47
47
  steps: v.int(8, { min: 1, max: 40 }),
48
+ // the base model: every krea file the box has, read live from the host (serve's
49
+ // "refresh schema" picks up a new download). A finetune is chosen in the draft,
50
+ // so its file name never has to be written here
51
+ checkpoint: v.model('UNETLoader.unet_name', {
52
+ filter: /krea/i,
53
+ default: 'krea2_turbo_fp8_scaled.safetensors',
54
+ label: 'checkpoint',
55
+ }),
48
56
  size: v.size({ width: 1024, height: 1024 }),
49
57
  removeBg: v.toggle(true, 'remove bg'),
50
58
  loras,
@@ -52,7 +60,7 @@ export const t2i = host.defineWorkflow({
52
60
  },
53
61
  build: (b, vars) => {
54
62
  // models
55
- const unet = b.UNETLoader({ unet_name: 'krea2_turbo_fp8_scaled.safetensors', weight_dtype: 'default' })
63
+ const unet = b.UNETLoader({ unet_name: vars.checkpoint, weight_dtype: 'default' })
56
64
  const clipLoader = b.CLIPLoader({
57
65
  clip_name: 'qwen3vl_4b_fp8_scaled.safetensors',
58
66
  type: 'krea2',
@@ -151,6 +151,13 @@ export const animaT2i = host.defineWorkflow({
151
151
  groupColor: 'rgba(122, 162, 247, 0.08)',
152
152
  description: 'turbo and base+turbo: 8 steps at turbo cfg. aesthetic and base: the steps and cfg below',
153
153
  }),
154
+ // a finetune in place of the model's own file, read live from the host. The model
155
+ // choice above still decides the sampling (turbo or not), so pick the one it matches
156
+ checkpoint: v.model('UNETLoader.unet_name', { filter: /anima/i, default: null, label: 'checkpoint' }).ui({
157
+ group: 'sampling',
158
+ description:
159
+ "none = the model choice's own file. Any other file replaces it and keeps that choice's sampling",
160
+ }),
154
161
  // auto = er_sde on aesthetic and base, euler on the distilled ones
155
162
  sampler: v.choice(['auto', 'er_sde', 'euler', 'euler_ancestral'], 'auto', 'sampler').ui({ group: 'sampling' }),
156
163
  // the distilled models ignore these: 8 steps at cfg 1 is what they were distilled for
@@ -187,7 +194,7 @@ export const animaT2i = host.defineWorkflow({
187
194
  device: 'default',
188
195
  })
189
196
  const spec = MODELS[vars.model]
190
- let model = b.UNETLoader({ unet_name: spec.unet, weight_dtype: 'default' })._MODEL
197
+ let model = b.UNETLoader({ unet_name: vars.checkpoint ?? spec.unet, weight_dtype: 'default' })._MODEL
191
198
  let clip = clipLoader._CLIP
192
199
  if (spec.turboLora) model = b.LoraLoaderModelOnly({ model, lora_name: TURBO_LORA, strength_model: 1 })._MODEL
193
200
  for (const l of activeLoras(vars.loras)) {
@@ -0,0 +1,111 @@
1
+ // text to speech in a cloned voice, on windows-1: one reference clip and its transcript become the
2
+ // voice, and the engine you pick reads your text with it, in the language you pick
3
+ // engines: chatterbox (Chatterbox Multilingual v3, 0.5B, fast), qwen3 (Qwen3-TTS 1.7B Base),
4
+ // fishs2 (Fish Audio S2 Pro, fp8), cosyvoice3 (Fun-CosyVoice3 0.5B), omnivoice (OmniVoice)
5
+ // box inventory: custom node pack TTS-Audio-Suite (github.com/diodiogod/TTS-Audio-Suite); every
6
+ // engine downloads its weights on first use, which takes minutes. The bundled voice is synthetic
7
+ // (examples/media/README.md); drop your own clip on `voice` and write what it says in `transcript`
8
+ // run directly: bun examples/rvion/15-tts-voice-clone.cflow.ts ["text"] [engine] [language]
9
+ import { ComfyTS, exampleMediaPath, v } from 'comfy-ts'
10
+
11
+ const comfy = ComfyTS.create()
12
+ const host = comfy.host({ id: 'windows-1', host: 'desktop-im18794', port: 8085 })
13
+ await host.loadSchemaFromCache() // offline import; run() connects lazily
14
+
15
+ const ENGINES = ['chatterbox', 'qwen3', 'fishs2', 'cosyvoice3', 'omnivoice'] as const
16
+ // the languages every engine here names the same way
17
+ const LANGUAGES = [
18
+ 'English',
19
+ 'French',
20
+ 'German',
21
+ 'Spanish',
22
+ 'Italian',
23
+ 'Portuguese',
24
+ 'Russian',
25
+ 'Japanese',
26
+ 'Korean',
27
+ 'Chinese',
28
+ ] as const
29
+
30
+ const transcript = v.text(
31
+ 'This is a short sample of my voice. Clone it, and I can read any text you give me, in many languages.',
32
+ { label: 'transcript of the voice clip' },
33
+ )
34
+ // bundled default (examples/media/, ships in the tarball). A clip's `<clip>.txt` is its
35
+ // transcript when `comfy-ts run` sets the clip and leaves the transcript alone
36
+ const voice = v.audio(exampleMediaPath('voice_en_6s.flac'), { sidecarText: transcript })
37
+
38
+ export const ttsVoiceClone = host.defineWorkflow({
39
+ id: 'tts-voice-clone',
40
+ tags: ['tts', 'voice'],
41
+ vars: {
42
+ prompt: v.prompt(
43
+ 'Welcome back, traveler. The road ahead is long, but the view from the top is worth every step.',
44
+ ),
45
+ seed: v.seed(1),
46
+ engine: v.choice(ENGINES, 'chatterbox', 'engine'),
47
+ language: v.choice(LANGUAGES, 'English', 'language'),
48
+ voice,
49
+ transcript,
50
+ },
51
+ // async build: the voice clip is uploaded (hash-named, deduped) per run
52
+ build: async (b, vars, wf) => {
53
+ const S = 'TTS-Audio-Suite'
54
+ const engine = (() => {
55
+ switch (vars.engine) {
56
+ case 'chatterbox':
57
+ return b[`${S}.ChatterBoxOfficial23LangEngineNode`]({
58
+ model_version: 'v3',
59
+ language: vars.language,
60
+ device: 'auto',
61
+ })
62
+ case 'qwen3':
63
+ return b[`${S}.Qwen3TTSEngineNode`]({
64
+ model_variant: 'TTS - Base 1.7B (Voice Clone)',
65
+ device: 'auto',
66
+ voice_preset: 'None (Zero-shot / Custom)',
67
+ language: vars.language,
68
+ instruct: '',
69
+ })
70
+ case 'fishs2':
71
+ return b[`${S}.FishAudioS2EngineNode`]({ model: 's2-pro-fp8', device: 'auto' })
72
+ case 'cosyvoice3':
73
+ return b[`${S}.CosyVoiceEngineNode`]({ model_path: 'Fun-CosyVoice3-0.5B-RL', device: 'auto' })
74
+ case 'omnivoice':
75
+ return b[`${S}.OmniVoiceEngineNode`]({
76
+ model_variant: 'OmniVoice',
77
+ device: 'auto',
78
+ language: vars.language,
79
+ })
80
+ }
81
+ })()
82
+ const narrator = b[`${S}.CharacterVoicesNode`]({
83
+ voice_name: 'none',
84
+ reference_text: vars.transcript,
85
+ opt_audio_input: await voice.loadInWorkflow(wf),
86
+ })
87
+ const speech = b[`${S}.UnifiedTTSTextNode`]({
88
+ TTS_engine: engine.outputs.TTS_engine,
89
+ text: vars.prompt.positive,
90
+ narrator_voice: 'none',
91
+ opt_narrator: narrator.outputs.opt_narrator,
92
+ seed: vars.seed,
93
+ enable_chunking: false,
94
+ enable_audio_cache: false,
95
+ })
96
+ b.PreviewAudio({ audio: speech.outputs.audio })
97
+ },
98
+ })
99
+
100
+ export default ttsVoiceClone
101
+
102
+ // standalone run (skipped when another driver — e.g. the TUI — imports this module)
103
+ if (import.meta.main) {
104
+ if (process.argv[2]) ttsVoiceClone.vars.prompt.set(process.argv[2])
105
+ if (process.argv[3]) ttsVoiceClone.vars.engine.set(process.argv[3] as (typeof ENGINES)[number])
106
+ if (process.argv[4]) ttsVoiceClone.vars.language.set(process.argv[4] as (typeof LANGUAGES)[number])
107
+
108
+ const execution = await ttsVoiceClone.run({ log: true, save: { prefix: 'comfy-ts-example/tts-voice-clone' } })
109
+ for (const clip of execution.audios) console.log(`🟢 ${clip.absPath}`)
110
+ host.disconnect()
111
+ }
@@ -0,0 +1,71 @@
1
+ // a new voice from a written description, on windows-1: Qwen3-TTS VoiceDesign speaks one sample
2
+ // line in the voice you describe. The clip and that line are the pair 15-tts-voice-clone takes
3
+ // as `voice` and `transcript`, so every later line keeps the same voice. The line comes back
4
+ // as a text output too: `comfy-ts run` writes it beside the clip as its transcript
5
+ // box inventory: custom node pack TTS-Audio-Suite (github.com/diodiogod/TTS-Audio-Suite); the
6
+ // VoiceDesign checkpoint downloads on first use, which takes minutes
7
+ // run directly: bun examples/rvion/16-tts-voice-design.cflow.ts ["description"] ["line"]
8
+ import { ComfyTS, v } from 'comfy-ts'
9
+
10
+ const comfy = ComfyTS.create()
11
+ const host = comfy.host({ id: 'windows-1', host: 'desktop-im18794', port: 8085 })
12
+ await host.loadSchemaFromCache() // offline import; run() connects lazily
13
+
14
+ const LANGUAGES = [
15
+ 'English',
16
+ 'French',
17
+ 'German',
18
+ 'Spanish',
19
+ 'Italian',
20
+ 'Portuguese',
21
+ 'Russian',
22
+ 'Japanese',
23
+ 'Korean',
24
+ 'Chinese',
25
+ ] as const
26
+
27
+ export const ttsVoiceDesign = host.defineWorkflow({
28
+ id: 'tts-voice-design',
29
+ tags: ['tts', 'voice'],
30
+ vars: {
31
+ description: v.text('An old sailor, gravelly and warm, slow pace, a smile in the voice.', {
32
+ label: 'the voice: age, gender, pitch, texture, accent, pace, mood',
33
+ }),
34
+ line: v.text('Ahoy, and welcome aboard. The sea is calm tonight, so sit down and listen to my story.', {
35
+ label: 'what the sample says (8 to 12 s of speech clones best)',
36
+ }),
37
+ language: v.choice(LANGUAGES, 'English', 'language'),
38
+ seed: v.seed(7),
39
+ },
40
+ build: (b, vars) => {
41
+ const S = 'TTS-Audio-Suite'
42
+ const engine = b[`${S}.Qwen3TTSEngineNode`]({
43
+ model_variant: 'Voice Design - 1.7B VoiceDesign',
44
+ device: 'auto',
45
+ voice_preset: 'None (Zero-shot / Custom)',
46
+ language: vars.language,
47
+ instruct: '',
48
+ })
49
+ const designed = b[`${S}.UnifiedVoiceDesignerNode`]({
50
+ TTS_engine: engine.outputs.TTS_engine,
51
+ reference_text: vars.line,
52
+ voice_instruction: vars.description,
53
+ seed: vars.seed,
54
+ })
55
+ b.PreviewAudio({ audio: designed.outputs.preview_audio })
56
+ // the transcript of the clip: the line itself, as a text output
57
+ b.PreviewAny({ source: vars.line })
58
+ },
59
+ })
60
+
61
+ export default ttsVoiceDesign
62
+
63
+ // standalone run (skipped when another driver, like the TUI, imports this module)
64
+ if (import.meta.main) {
65
+ if (process.argv[2]) ttsVoiceDesign.vars.description.set(process.argv[2])
66
+ if (process.argv[3]) ttsVoiceDesign.vars.line.set(process.argv[3])
67
+
68
+ const execution = await ttsVoiceDesign.run({ log: true, save: { prefix: 'comfy-ts-example/tts-voice-design' } })
69
+ for (const clip of execution.audios) console.log(`🟢 ${clip.absPath}`)
70
+ host.disconnect()
71
+ }
@@ -71,11 +71,12 @@ if (import.meta.main) {
71
71
  }
72
72
  ```
73
73
 
74
- Var kinds: `v.text`, `v.int`, `v.float`, `v.seed`, `v.toggle`, `v.choice`, `v.size`, `v.loras`, `v.prompt`, `v.image`, `v.audio`, `v.video`. Notes:
74
+ Var kinds: `v.text`, `v.int`, `v.float`, `v.seed`, `v.toggle`, `v.choice`, `v.size`, `v.loras`, `v.prompt`, `v.model`, `v.image`, `v.audio`, `v.video`. Notes:
75
75
 
76
76
  - `v.loras(/regex/)` resolves against the host's real lora list; `activeLoras(vars.loras)` returns `{ lora_name, strength_model, strength_clip }[]` for a standard `LoraLoader` chain.
77
77
  - `v.prompt` is structured: `//` lines are comments (stripped), `- ` lines go to the negative prompt, `{ loraKeywordsFrom: lorasVar }` prefixes lora trigger keywords. The value is `{ positive, negative }`.
78
78
  - `v.image` holds a local image path as a plain string; an empty value throws at build time instead of running a silent placeholder. Capture the var in a const and call `image.absPath()` in `build`. Default it to a bundled sample with `exampleImagePath('bear_1024x1024.jpg')` (ships in the package). In the TUI it opens an image picker (browse, favorite folders, recents, preview).
79
+ - `v.model('UNETLoader.unet_name', { default, filter })` (in a `vars: (v) => …` lambda) is a choice over the host's file list for that loader input; use it instead of writing a model file name into the workflow.
79
80
  - `v.audio` and `v.video` work the same way for audio and video files. In `build`, `await myVar.loadInWorkflow(wf)` uploads the file and returns the loader node (`LoadImage`, `LoadAudio`, `LoadVideo`). Default them with `exampleMediaPath('sine_440hz_3s.flac')` or `exampleMediaPath('testsrc_256x256_3s.mp4')`. Video results land in `execution.videos`.
80
81
  - `vars` may be a lambda `(v) => ({ ... })` so vars can reference each other.
81
82
  - `build` may be async, for uploads: the third param `wf` feeds `MediaImage` helpers (`new MediaImage({ path }).loadInWorkflow_viaLoadImageNode(wf)`). Uploads are hash-named and deduped, nothing is re-sent.
@@ -95,8 +96,11 @@ bunx comfy-ts gen --id <host-id> [--host http://127.0.0.1:8188] # codegen
95
96
  bunx comfy-ts outline [file] [--section Name] [--lines N] # inspect a sdk.d.ts
96
97
  bunx comfy-ts loras [--id <host-id>] [--host http://…] # mirror lora metadata (optional ComfyUI-Lora-Manager extension)
97
98
  bunx comfy-ts tui [dir | module.cflow.ts] # interactive tweak & re-run
99
+ bunx comfy-ts run <name | module.cflow.ts> [--draft <name>] [--<var> <value>…] [--out <path>] [--json] # one generation, headless
98
100
  ```
99
101
 
102
+ `comfy-ts run` is how an agent generates: the module is found in the cwd, then in the bundled examples, by key or a unique part of it (`folder/name` narrows, like `rvion/anima`). Every var is a flag (`--prompt "…" --seed 7 --image in.png`, `--<var>-file` reads a text var from a file), `--out` says where the output goes, and `--json` prints one line with every output path. `comfy-ts run <name> --help` lists the vars. Every flag is a var name the module declares. A media var declared with `sidecarText: someTextVar` fills that text var from `<file>.txt` beside the file it is given (a voice clip's transcript, example 15).
103
+
100
104
  `comfy-ts loras` writes `.comfy-ts/hosts/<id>/loras.json`: per lora, the model's real name, its civitai trigger words, tags, base model and preview url, stored raw. It is what makes `v.prompt(text, { loraKeywordsFrom: lorasVar })` inject a lora's trigger words with nothing typed by hand, and what lets the TUI find a lora by its human name. Read it yourself (`getLoraInfo`, `getLoraTriggerWords`, `getLoraDisplayName`) when a user asks which lora to pick. Absent extension or no sync yet: every getter answers empty, nothing breaks.
101
105
 
102
106
  The TUI scans `**/*.cflow.ts` (no arg: cwd PLUS the examples bundled with the package, grouped apart in the tree; an explicit dir or file limits to that scope), shows vars as editable knobs, runs with live progress and previews, and saves named drafts under `.comfy-ts/drafts/`. It re-execs through bun when launched under node (workflow modules are TypeScript, and node cannot import .ts from node_modules). Point users at it; as an agent you run modules with `bun path/to/module.cflow.ts`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comfy-ts",
3
- "version": "2.15.0",
3
+ "version": "2.17.0",
4
4
  "description": "The complete TypeScript toolkit for ComfyUI and generative AI. Fully type-safe SDK with autocomplete on every node, companion CLI, TUI, agentic docs, and 50+ examples. Design, run and deploy creative pipelines for image, video, audio, 3d and text on any ComfyUI, local, cloud or hosted.",
5
5
  "keywords": [
6
6
  "comfyui",
@@ -140,7 +140,7 @@
140
140
  "oxfmt": "^0.60.0",
141
141
  "oxlint": "^1.75.0",
142
142
  "oxlint-tsgolint": "^7.0.2001",
143
- "rvlib-shipkit": "^1.6.0",
143
+ "rvlib-shipkit": "^1.7.0",
144
144
  "rvlib-ts-tools": "^0.3.3",
145
145
  "tsdown": "^0.22.14",
146
146
  "typescript": "^7.0.2"
@@ -39,6 +39,15 @@ Usage:
39
39
  panel. No bundled examples, no auth, and any origin may call it: use
40
40
  --host beyond localhost only on a network you trust.
41
41
 
42
+ comfy-ts run <name | module.cflow.ts> [--draft <name>] [--<var> <value>…] [--out <path>] [--json]
43
+ ONE generation, headless, with live progress: the module is found in cwd,
44
+ then in the examples bundled with comfy-ts, by its key (10-anima-t2i), its
45
+ key without the number (anima-t2i) or a unique part (anima). Each var is a
46
+ flag (--prompt "…" --seed 7 --image in.png), --<var>-file reads a text var
47
+ from a file, --out writes the output there (several: a-1.png, a-2.png; a
48
+ dir keeps the server's names). \`comfy-ts run <name> --help\` lists the vars,
49
+ \`comfy-ts run\` lists the modules. --json prints one line with the paths
50
+
42
51
  comfy-ts help
43
52
  `
44
53
 
@@ -47,7 +56,7 @@ async function main(): Promise<number> {
47
56
  if (cmd === 'gen') return runGen(rest)
48
57
  if (cmd === 'outline') return runOutline(rest)
49
58
  if (cmd === 'loras') return runLoras(rest)
50
- if (cmd === 'tui' || cmd === 'serve') {
59
+ if (cmd === 'tui' || cmd === 'serve' || cmd === 'run') {
51
60
  // .cflow.ts workflow modules need bun: node refuses to strip types under
52
61
  // node_modules, exactly where the packaged examples live — and the bin's
53
62
  // node shebang means `bunx comfy-ts tui|serve` lands here under NODE. Hop
@@ -60,6 +69,10 @@ async function main(): Promise<number> {
60
69
  `[comfy-ts ${cmd}] bun not found (${res.error.message}) — continuing under node: the examples packaged in node_modules cannot load here, and your own .cflow.ts modules rely on node's type stripping`,
61
70
  )
62
71
  }
72
+ if (cmd === 'run') {
73
+ const { runRun } = await import('src/cli/run/run-run.ts')
74
+ return runRun(rest)
75
+ }
63
76
  if (cmd === 'serve') {
64
77
  const { runServe } = await import('src/cli/serve/run-serve.ts')
65
78
  return runServe(rest)
@@ -0,0 +1,36 @@
1
+ // the `*.cflow.ts` modules under the cwd for `comfy-ts run`, walked with bounds: node_modules
2
+ // and dot dirs are never entered (a recursive readdir reads all of them before any filter,
3
+ // which stalls a run started in a big repo or a temp dir), and the walk stops MAX_DEPTH deep
4
+ import { existsSync, readdirSync } from 'node:fs'
5
+ import { dirname, join } from 'pathe'
6
+
7
+ export const MAX_DEPTH = 5
8
+
9
+ export function findModules(dir: string, depth = 0): string[] {
10
+ let entries: import('node:fs').Dirent[]
11
+ try {
12
+ entries = readdirSync(dir, { withFileTypes: true })
13
+ } catch {
14
+ return []
15
+ }
16
+ const out: string[] = []
17
+ for (const e of entries.sort((a, b) => a.name.localeCompare(b.name))) {
18
+ if (e.isFile() && /\.cflow\.tsx?$/.test(e.name)) out.push(join(dir, e.name))
19
+ else if (e.isDirectory() && depth < MAX_DEPTH && e.name !== 'node_modules' && !e.name.startsWith('.'))
20
+ out.push(...findModules(join(dir, e.name), depth + 1))
21
+ }
22
+ return out
23
+ }
24
+
25
+ /** the workspace a module belongs to: the nearest folder above it holding `.comfy-ts/` (its
26
+ * schema cache and its tuned drafts), or null. A run roots comfy-ts there, so it never writes a
27
+ * `.comfy-ts/` into whatever folder it was started from */
28
+ export function workspaceOf(file: string): string | null {
29
+ let dir = dirname(file)
30
+ while (true) {
31
+ if (existsSync(join(dir, '.comfy-ts'))) return dir
32
+ const up = dirname(dir)
33
+ if (up === dir) return null
34
+ dir = up
35
+ }
36
+ }
@@ -0,0 +1,61 @@
1
+ // one `--<var> <value>` flag, a string on the command line, as the value serve's payload takes
2
+ // for that var kind (applyVarPayload validates it after, so this only shapes, never judges)
3
+ import { isAbsolute, resolve } from 'pathe'
4
+ import type { ChoiceSelect, VarKind } from 'src/vars/ComfyVars.ts'
5
+
6
+ export type FlagSpec = { kind: VarKind; select?: ChoiceSelect }
7
+
8
+ const TRUE = new Set(['true', 'yes', '1', 'on'])
9
+ const FALSE = new Set(['false', 'no', '0', 'off'])
10
+
11
+ /** `raw` is `true` for a bare flag (`--upscale`) */
12
+ export function flagValue(p: {
13
+ name: string
14
+ spec: FlagSpec
15
+ raw: string | true
16
+ cwd: string
17
+ }): { value: unknown } | { error: string } {
18
+ const raw = p.raw
19
+ if (p.spec.kind === 'toggle') {
20
+ if (raw === true) return { value: true }
21
+ const v = raw.toLowerCase()
22
+ if (TRUE.has(v)) return { value: true }
23
+ if (FALSE.has(v)) return { value: false }
24
+ return { error: `--${p.name} is a toggle: true or false` }
25
+ }
26
+ if (raw === true) return { error: `--${p.name} needs a value` }
27
+ switch (p.spec.kind) {
28
+ case 'int':
29
+ case 'float':
30
+ return { value: raw }
31
+ case 'seed': {
32
+ // a random seed as a number: serve rerolls a '?' mode only when the payload leaves the seed out
33
+ if (raw === '?') return { value: Math.floor(Math.random() * 2 ** 32) }
34
+ const n = Number(raw)
35
+ return Number.isFinite(n) ? { value: n } : { error: `--${p.name} is a seed: a number, or ? for a random one` }
36
+ }
37
+ case 'choice':
38
+ if (p.spec.select === 'many')
39
+ return {
40
+ value: raw
41
+ .split(',')
42
+ .map((x) => x.trim())
43
+ .filter((x) => x !== ''),
44
+ }
45
+ if (p.spec.select === 'zero-or-one' && raw === 'none') return { value: null }
46
+ return { value: raw }
47
+ case 'loras':
48
+ try {
49
+ return { value: JSON.parse(raw) }
50
+ } catch {
51
+ return { error: `--${p.name} takes the loras as json, like '{"name.safetensors": 0.8}'` }
52
+ }
53
+ case 'image':
54
+ case 'audio':
55
+ case 'video':
56
+ // a url goes through as is: serve downloads it
57
+ return { value: /^https?:\/\//.test(raw) || isAbsolute(raw) ? raw : resolve(p.cwd, raw) }
58
+ default:
59
+ return { value: raw }
60
+ }
61
+ }
@@ -0,0 +1,41 @@
1
+ // where `comfy-ts run` writes each output. `--out a.png` and one output: exactly there, its
2
+ // extension swapped for the output's own when they differ (said on the line); several outputs
3
+ // are numbered (`a-1.png`); a dir keeps the server's filenames; no --out names them after the
4
+ // module and the prompt in the cwd. Pure: the caller says whether --out is a dir
5
+ import { basename, extname, join, resolve } from 'pathe'
6
+
7
+ export type Produced = { filename: string }
8
+ export type Destination = { path: string; note: string | null }
9
+
10
+ export function outputPaths(p: {
11
+ out: string | null
12
+ outIsDir: boolean
13
+ module: string
14
+ promptId: string
15
+ items: readonly Produced[]
16
+ cwd: string
17
+ }): Destination[] {
18
+ const n = p.items.length
19
+ if (p.out != null && p.outIsDir) {
20
+ const dir = resolve(p.cwd, p.out)
21
+ return p.items.map((it) => ({ path: join(dir, basename(it.filename)), note: null }))
22
+ }
23
+ const base = p.out == null ? join(p.cwd, `${p.module}-${p.promptId.slice(0, 8)}`) : resolve(p.cwd, p.out)
24
+ const asked = p.out == null ? '' : extname(base)
25
+ const stem = asked === '' ? base : base.slice(0, -asked.length)
26
+ return p.items.map((it, ix) => {
27
+ const own = extname(it.filename)
28
+ const path = `${stem}${n > 1 ? `-${ix + 1}` : ''}${own}`
29
+ const note =
30
+ asked !== '' && own !== '' && asked.toLowerCase() !== own.toLowerCase()
31
+ ? `the output is ${own}, not ${asked}`
32
+ : null
33
+ return { path, note }
34
+ })
35
+ }
36
+
37
+ /** the transcript or text beside the first media output: same stem, `.txt` */
38
+ export function sidecarPath(mediaPath: string): string {
39
+ const ext = extname(mediaPath)
40
+ return `${ext === '' ? mediaPath : mediaPath.slice(0, -ext.length)}.txt`
41
+ }
@@ -0,0 +1,41 @@
1
+ // `comfy-ts run <name>`: which module a name means, over the discovered files in their order
2
+ // (cwd first, then the bundled examples). A name may carry its folder (`rvion/anima`,
3
+ // `comfy-cloud/anima`), which narrows to modules in a folder of that name. Tiers, first hit
4
+ // wins: the exact module key, the key without its number (`anima-t2i` → `10-anima-t2i`), a
5
+ // prefix of that, a substring. Two modules on the first tier that hits is ambiguous, and the
6
+ // error names them with their folder
7
+ import { basename, dirname } from 'pathe'
8
+ import { moduleName } from 'src/cli/tui/treeRows.ts'
9
+
10
+ export type Picked = { file: string; key: string } | { error: string }
11
+
12
+ const bare = (key: string): string => key.replace(/^\d+-/, '')
13
+ const qualified = (file: string): string => `${basename(dirname(file))}/${moduleName(file)}`
14
+
15
+ export function pickModule(files: readonly string[], name: string): Picked {
16
+ const cut = name.lastIndexOf('/')
17
+ const folder = cut < 0 ? null : name.slice(0, cut).toLowerCase()
18
+ const n = name.slice(cut + 1).toLowerCase()
19
+ // one file per qualified name, the first one found: a cwd module shadows a bundled one
20
+ const byName = new Map<string, string>()
21
+ for (const f of files) {
22
+ if (folder != null && !qualified(f).toLowerCase().startsWith(`${folder}/`)) continue
23
+ if (!byName.has(qualified(f))) byName.set(qualified(f), f)
24
+ }
25
+ const all = [...byName.values()]
26
+ const tiers: ((k: string) => boolean)[] = [
27
+ (k) => k === n,
28
+ (k) => bare(k) === n,
29
+ (k) => bare(k).startsWith(n),
30
+ (k) => k.includes(n),
31
+ ]
32
+ for (const hit of tiers) {
33
+ const found = all.filter((f) => hit(moduleName(f).toLowerCase()))
34
+ if (found.length === 1) return { file: found[0]!, key: moduleName(found[0]!) }
35
+ if (found.length > 1)
36
+ return {
37
+ error: `'${name}' matches ${found.length} modules: ${found.map(qualified).join(', ')}. Name one, folder included`,
38
+ }
39
+ }
40
+ return { error: `no module matches '${name}'. Modules: ${all.map(qualified).join(', ')}` }
41
+ }