CLI 图片输入转临时文件
Turn a ComfyUI Image Into a CLI-Ready Prompt + Paths
- image
- reference_image
- reference
- command
- output_path
- prompt_path
- image_path
- reference_path
A CLI agent can't see your ComfyUI tensors. It can only see files. KSCLIImageInputFiles is the bridge: it writes your prompt to a temp .txt, your product image to a temp .png, your reference image to another temp .png, then builds a ready-to-run command with real filesystem paths substituted in. Feed its command output to KSAntigravityCLIExecute, and its output_path to KSCLIImageOutputFile to get the result back. It's the "format the inputs for an outside agent" node.
How it works
You give it a command_template containing placeholders, and it replaces them:
{prompt_path}- temp file where yourprompttext lands (UTF-8, so Chinese prompts survive).{image_path}- temp PNG written from yourimagetensor.{reference_path}- temp PNG fromreference_image, or a path from thereferenceobject; empty string if no reference.{output_dir}and{output_path}- where you expect the agent to save its result.
The default template is a complete Antigravity-style instruction: "Create exactly one final e-commerce product image. Use product image: {image_path}. Read the detailed design prompt from: {prompt_path}. Save the final image as a PNG file exactly at: {output_path}." That's the whole trick - the agent is told exactly which files to read and where to write, so a fallible model still hits the right contract.
The inputs that matter
command_template- the big one. Keep the placeholders, and the node handles the paths. This is where you define what the CLI is supposed to do.prompt- the full text written to{prompt_path}. In the intended pipeline this isKSDesignStrategy'sfinal_prompt.image- the product photo tensor.output_directory- defaultimage_pipeline/antigravity_cli. Relative paths land under ComfyUI'soutput/dir; absolute paths are used as-is. The 1688-flavored gotcha: leave it blank and connectsource_image_path, and it derives a folder named1688_mainnext to your source image'swhite_backgroundfolder - pure Alibaba-marketplace workflow logic that only makes sense inside the author's original pipeline.output_filename- defaultantigravity_result.png. When filled, the node keeps the extension and appends a timestamp, so every run writes a fresh file. When blank +source_image_path, it reuses the source filename withwhite_backgroundswapped for1688_main.
Optional: reference_image (direct IMAGE, wins over the object), reference (a KS_REFERENCE), and source_image_path (drives the auto-derivation above).
Outputs: command (the fully-substituted command line), output_path (where the result is expected), plus prompt_path, image_path, reference_path if you want the temp files themselves.
Installing
With the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/kongshan4219/ComfyUI-Kongshan-Nodes
restart ComfyUI. No API key needed - this node only touches local temp files and strings.
Gotchas
- Temp files accumulate. It writes
ks_cli_prompt_<timestamp>.txtetc. into ComfyUI'stemp/dir with no cleanup. Fine for light use; a busy pipeline will litter the temp folder. - The output filename changes every run. The timestamp is the point (no clobbering), but it means
expected_output_pathin the output node is unique per run - which is exactly howKSCLIImageOutputFileknows which file to load, so don't "fix" it. - It's built for one specific pipeline. The
1688_main/white_backgroundauto-naming is a clear tell that this is one author's private marketplace workflow open-sourced. It works fine with your own names - just type them intooutput_directoryinstead of relying on the blank-path magic.
Young pack, zero impressions everywhere as of now, but the placeholder-substitution pattern here is clean and easy to reuse for any CLI agent, not just Antigravity.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| command_template | STRING | agy --print "Create exactly one final e-commerce product image. Use product image: {image_path}. Use reference image if provided: {reference_path}. Read the detailed design prompt from: {prompt_path}. Save the final image as a PNG file exactly at: {output_path}. After saving, print only the saved image path." | 命令模板。可使用 {prompt_path}、{image_path}、{reference_path}、{output_dir}、{output_path} 占位符,节点会替换成实际路径。 |
| prompt | STRING | 写入临时 txt 的完整提示词。外部 CLI 可通过 {prompt_path} 读取。 | |
| image | IMAGE | 写入临时 PNG 的商品图。外部 CLI 可通过 {image_path} 读取。 | |
| output_directory | STRING | image_pipeline/antigravity_cli | 期望输出目录。相对路径会放在 ComfyUI output 目录下;绝对路径会直接使用。留空且连接 source_image_path 时,保存到 white_background 同级的 1688_main。 |
| output_filename | STRING | antigravity_result.png | 期望输出文件名。填写时节点会保留扩展名并追加时间戳;留空且连接 source_image_path 时,使用源图片名并把 white_background 替换为 1688_main。 |
| reference_imageopt | IMAGE | 直接连接的参考图,会写入临时 PNG 并作为 {reference_path}。优先级高于 reference。 | |
| referenceopt | KS_REFERENCE | 参考对象。若包含 image 会写入临时 PNG;否则使用其中 path 作为 {reference_path}。 | |
| source_image_pathopt | STRING | 源图片路径。output_directory 留空时用它推导输出目录;output_filename 留空时用源图片名派生输出文件名。 |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| command | STRING | — |
| output_path | STRING | — |
| prompt_path | STRING | — |
| image_path | STRING | — |
| reference_path | STRING | — |