Skip to content

Commit 2524f8d

Browse files
committed
Complete overhaul to final(ish) design
1 parent 4a99837 commit 2524f8d

40 files changed

+11357
-7702
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
prompt-companion-config.json
2-
31
# Byte-compiled / optimized / DLL files
42
__pycache__/
53
*.py[cod]

README.md

Lines changed: 96 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,65 @@
11
# ComfyUI Prompt Companion
22

3-
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!
44

5-
## 🚀 Features
5+
## 🤔 Why use this?
66

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:
118

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.
1313

14-
### Quick Install (Recommended)
14+
Prompt Companion aims to solve all of those.
15+
16+
## 😃 Neat! How do I get it?
1517

16-
This will be available once I'm happy enough with this node to publish it to the repository.
18+
Same as most ComfyUI custom nodes.
19+
20+
### Quick Install (Recommended)
1721

18-
1. Install [ComfyUI](https://docs.comfy.org/get_started)
19-
2. Install [ComfyUI-Manager](https://github.com/ltdrdata/ComfyUI-Manager)
20-
3. Look up "ComfyUI Prompt Companion" in ComfyUI-Manager and install
21-
4. Restart ComfyUI
22+
1. Install [ComfyUI](https://docs.comfy.org/get_started).
23+
2. Install [ComfyUI-Manager](https://github.com/ltdrdata/ComfyUI-Manager).
24+
3. Look up "ComfyUI Prompt Companion" in ComfyUI-Manager and install.
25+
4. Restart ComfyUI.
26+
5. The Prompt Companion node will be available in the `prompt-companion` category.
2227

2328
### Manual Install
29+
2430
1. Clone this repository to your ComfyUI custom nodes directory:
31+
2532
```bash
2633
cd ComfyUI/custom_nodes/
2734
git clone https://github.com/jfcantu/ComfyUI-Prompt-Companion.git
2835
```
29-
2. Restart ComfyUI
30-
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.
5936

60-
#### Adding/Modifying Prompt Groups
37+
2. The Prompt Companion node will be available in the `prompt-companion` category.
6138

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?
6340

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:
6542

66-
While a prompt group is selected, select individual prompt additions to add/remove them from the prompt group.
43+
![Example workflow](doc/quickstart-air-bud.png)
6744

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.
6946

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.
7157

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.
7359

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?
7961

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!
9363

9464
## 🧪 Development
9565

@@ -105,25 +75,65 @@ pre-commit install
10575

10676
### Project Structure
10777

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
101+
│ ├── extensions.js # ComfyUI integration extensions
102+
│ └── prompt_companion.css # Visual hierarchy styling
103+
104+
└── doc/ # Documentation & Assets
105+
├── USAGE.md # Usage documentation
106+
└── *.png # Screenshot assets
108107
```
109-
ComfyUI-Prompt-Companion/
110-
├── src/
111-
│ ├── web/ # Frontend JavaScript modules
112-
│ │ ├── extension.js # Main ComfyUI extension
113-
│ │ ├── promptAdditionManager.js # UI dialog manager
114-
│ │ ├── api-operations.js # HTTP client
115-
│ │ └── state-manager.js # State management
116-
│ ├── nodes.py # Backend node and API
117-
│ ├── 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
122132

123133
## 🤝 Contributing
124134

125-
1. Fork the repository
126-
2. Create a feature branch
127-
3. Make changes with proper documentation
128-
4. Add tests for new functionality
129-
5. Submit a pull request
135+
1. Fork the repository.
136+
2. Create a feature branch.
137+
3. Make changes with proper documentation.
138+
4. Add tests for new functionality.
139+
5. Submit a pull request.

0 commit comments

Comments
 (0)