You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A ComfyUI extension for managing and organizing prompt additions with support for individual prompts, prompt groups, and automatic trigger-word matching.
3
+
A ComfyUI extension for saving, organizing, and mixing up parts of prompts ("subprompts"). Supports nested subprompts, automatic loading of specific subprompts based on selected checkpoint, and more!
4
4
5
-
## 🚀 Features
5
+
## 🤔 Why use this?
6
6
7
-
### Core Functionality
8
-
-**Individual Prompt Management**: Create, edit, and organize individual prompt additions.
9
-
-**Prompt Groups**: Group related prompt additons together for batch operations.
10
-
-**Multiple Operation Modes**: Choose between applying an individual prompt addition, a specific group of prompt additions, or automatically apply groups of prompt additions based on the checkpoint name.
7
+
As I was learning ComfyUI, I found that keeping my prompts up to date with my experimental workflows was taking a lot of time. A few examples:
11
8
12
-
## 📦 Installation
9
+
* Manually switching between different embeddings (like `lazyneg`) when switching between checkpoints from different base models.
10
+
* Remembering which quality keywords worked well with which checkpoints, and manually switching between them.
11
+
* For advanced workflows involving multiple prompts, like rendering/combining multiple images, regional prompting, attention coupling, etc. - ensuring that you're using consistent style and quality keywords across all your prompts.
12
+
* Sharing consistent "base" prompts across characters. For example: if you have a set of unique prompts for specific fantasy characters, but all including the same style keywords, and you want to update the style keywords for all those characters at once.
13
13
14
-
### Quick Install (Recommended)
14
+
Prompt Companion aims to solve all of those.
15
+
16
+
## 😃 Neat! How do I get it?
15
17
16
-
This will be available once I'm happy enough with this node to publish it to the repository.
3. The Prompt Companion node will be available in the `jfc` category
31
-
32
-
## 🎯 Usage
33
-
34
-
### Basic Setup
35
-
36
-
1.**Add the Node**: Search for "PromptCompanion" in the node browser and add it to your workflow.
37
-
38
-
2.**Configure Inputs**:
39
-
-`ckpt_name`: Select your checkpoint.
40
-
-`addition_type`: Choose "Individual" mode to select an individual prompt addition, or "Group" mode to apply one or more groups of prompt additions.
41
-
-`prompt_group_mode`: Only available in "Group" mode. Choose "Manual" to select a single prompt addition, or "Automatic" to apply multiple groups based on the checkpoint name.
42
-
-`combine_mode`: Specify whether your prompt additions go in front of your prompts (prepend) or after them (append).
43
-
-`prompt_addition_name`: Only available in "Individual" mode. Select the prompt addition to apply.
44
-
-`prompt_addition_group`: Only available in "Group" addition mode when "Manual" group mode is selected. Select a prompt addition group to apply.
45
-
-`positive_addition`/`negative_addition`:
46
-
- In Individual mode, you can edit your prompt addition here directly.
47
-
- In Group mode, this will display the collected prompt additions that will be applied, which cannot be edited.
48
-
-`positive_prompt`/`negative_prompt`: Your base prompts. Can be input from another node, or entered directly.
49
-
50
-
51
-
52
-
### Managing Prompt Additions
53
-
54
-
Start by right-clicking the node, and selecting "Edit Prompt Additions."
55
-
56
-
#### Adding/Modifying Prompt Additions
57
-
58
-
Pretty self-explanatory. Create, delete, modify, rename, save with a new name.
59
36
60
-
#### Adding/Modifying Prompt Groups
37
+
2. The Prompt Companion node will be available in the `prompt-companion` category.
61
38
62
-
Click "Create New" to create a new one, or select one from the list to edit an exiting one.
39
+
## 😨 Okay, now how do I use it?
63
40
64
-
"Trigger words" are strings that Prompt Companion will look for in your checkpoint name/path. If they match any part of it, the prompt group will be included in the list of additions.
41
+
I've tried to make the nodes as intuitive as possible, so here's a quick example workflow to cover the basics:
65
42
66
-
While a prompt group is selected, select individual prompt additions to add/remove them from the prompt group.
43
+

67
44
68
-
Select "(none)" or click "Cancel" to exit.
45
+
First things first: the subprompts used here were created using the "Edit Subprompts" dialog, which can be accessed by right-clicking any Prompt Companion node.
69
46
70
-
**NOTE**: You can't edit prompt additions while editing a Prompt Group.
47
+
* The "Load Checkpoint With Subprompt" node loads the checkpoint. Note that the checkpoint file is in a subfolder, (`sd15/`). Any subprompts with the trigger word `sd15` will be merged together and exported from the `subprompt` output.
48
+
* You can see the output in the top flow: a negative subprompt that simply says `embedding: SD15\easynegative`.
49
+
* The subprompt is passed into the "Add Subprompt" node.
50
+
* This node now has three subprompts to merge:
51
+
*`input`: the input from the previous node.
52
+
*`subprompt`: the subprompt selected from the `subprompt_selection` drop-down.
53
+
*`textbox`: the contents of the textbox on the node itself.
54
+
* It merges them using the order specified in `merge_order`.
55
+
* The resulting output is seen on the right: positive and negative prompts made from combining the input, subprompt, and textbox (in that order, as specified in `merge_order`.)
56
+
* The text can then be used as input to CLIP Text Encode.
71
57
72
-
## 🔧 Architecture
58
+
In addition to the functional nodes, there are a couple conversion nodes for converting/deconverting between subprompts and positive/negative string pairs.
73
59
74
-
### Frontend Components
75
-
-**`extension.js`**: Main ComfyUI extension registration and node behavior
76
-
-**`promptAdditionManager.js`**: Dialog manager for CRUD operations
77
-
-**`api-operations.js`**: HTTP client for backend communication
78
-
-**`state-manager.js`**: Centralized state management with event system
60
+
## 😲 Pretty neat! How can I learn more?
79
61
80
-
### Backend Components
81
-
-**`nodes.py`**: ComfyUI node definition and API endpoints
82
-
-**`extension_config.py`**: Data models and configuration management
83
-
-**`config-schema.json`**: JSON schema for data validation
84
-
85
-
### Debug Mode
86
-
87
-
Enable debug logging by opening browser developer tools:
88
-
89
-
```javascript
90
-
// Check current state
91
-
console.log(window.promptState?.getState());
92
-
```
62
+
Give [USAGE.md](doc/USAGE.md) a read. It even has pictures!
93
63
94
64
## 🧪 Development
95
65
@@ -105,25 +75,65 @@ pre-commit install
105
75
106
76
### Project Structure
107
77
78
+
The architecture is organized into specialized modules for maintainability and scalability:
79
+
80
+
```text
81
+
custom_nodes/ComfyUI-Prompt-Companion/
82
+
├── __init__.py # Node package definition
83
+
├── pyproject.toml # Python project definition
84
+
├── api_routes.py # Definition of API routes
85
+
│
86
+
├── nodes/
87
+
│ ├── __init__.py # ComfyUI node definitions
88
+
│ ├── prompt_nodes.py # Subprompt-related notes
89
+
│ └── checkpoint_loader.py # Checkpoint loader with trigger-word support
90
+
│
91
+
├── core/ # Storage & Logic
92
+
│ ├── __init__.py # Core module exports
93
+
│ ├── storage.py # UUID-based storage with atomic operations
94
+
│ ├── subprompt.py # Subprompt class with circular reference detection
95
+
│ ├── folder.py # Hierarchical folder management
96
+
│ └── validation.py # Data validation
97
+
│
98
+
├── web/ # Frontend Components
99
+
│ ├── edit_dialog.js # Dialog for editing subprompts
100
+
│ ├── tree_view.js # Tree-view control for use in the dialog
│ ├── extension_config.py # Data models and config
118
-
│ └── config-schema.json # Data validation schema
119
-
├── __init__.py # Python module initialization
120
-
└── README.md # This file
121
-
```
108
+
109
+
### Key File Responsibilities
110
+
111
+
#### **Core Storage System**
112
+
113
+
***[`core/storage.py`](core/storage.py:1)**: UUID-based storage with thread-safe operations, atomic file writes, cascade deletion, and backup/restore capabilities
114
+
***[`core/subprompt.py`](core/subprompt.py:1)**: Subprompt class with nested resolution, circular reference detection, and validation
115
+
***[`core/folder.py`](core/folder.py:1)**: Hierarchical folder management with UUID-based identification
116
+
***[`core/validation.py`](core/validation.py:1)**: Validation rules for data integrity
117
+
118
+
#### **Node Integration**
119
+
120
+
***[`nodes/prompt_nodes.py`](nodes/prompt_nodes.py:1)**: ComfyUI nodes with dynamic combo boxes, IS_CHANGED method for cache invalidation, and six merge order permutations
121
+
***[`nodes/checkpoint_loader.py`](nodes/checkpoint_loader.py:1)**: Checkpoint loading with trigger word matching
122
+
123
+
#### **API Layer**
124
+
125
+
***[`api_routes.py`](api_routes.py:1)**: REST endpoints with CRUD operations, circular reference validation, and error handling
126
+
127
+
#### **Frontend Architecture**
128
+
129
+
***[`web/tree_view.js`](web/tree_view.js:1)**: Tree view with drag-and-drop, context menus, visual hierarchy indicators, and real-time updates
130
+
***[`web/edit_dialog.js`](web/edit_dialog.js:1)**: Simple editing interface with live preview, organization, drag-and-drop, etc.
131
+
***[`web/extensions.js`](web/extensions.js:1)**: ComfyUI integration layer for workflow integration
0 commit comments