Compare commits

..
35 Commits
Author SHA1 Message Date
KOFiblto b37d90882b Fix: start dock resize from current on-screen size (no jump to saved settings box)
Grabbing the resize handle now baselines from the dock's actual rendered size (e.g. 500x250 for a 2:1 latent) instead of the possibly larger Floating Dock Max Width/Height box (500x500). Nothing moves until the pointer moves; on release the dragged free-form box is clamped (100-2000px) and written to the settings, and the dock snaps to the exact latent fit.
2026-10-17 20:12:20 +02:00
KOFiblto 71608332ab Docs: document resize overhaul and LoRA loader maintenance resets 2026-10-17 01:06:05 +02:00
KOFiblto 48e452dd67 Feat: Visual LoRA Loader maintenance resets and iterator reset confirmation
Adds confirmed Reset buttons on the Visual LoRA Loader: cycle counter (sequential/random position + prompt->LoRA assignments), usage counters, and thumbnail cache. Adds authenticated backend routes for each. The Prompt Queue Iterator's Reset Counter button now confirms and explains that it does not wipe queue state.
2026-10-17 01:06:05 +02:00
KOFiblto 377b95681c Fix: free-form dock resize, drag reliability, and queue overlay resize performance
Dock dragging now resizes width/height independently (100-2000px bounds) with CSS-only live previews instead of per-move canvas rebuilds; drags reliably end via pointer capture, pointercancel and window-blur guards. Queue overlay heights apply as scoped inline styles (rAF-throttled) instead of rewriting a stylesheet every pointermove. Sliders are 1px-stepped; footer observer and power sidebar mutation handling were scoped to eliminate per-frame callback churn.
2026-10-17 01:06:05 +02:00
KOFiblto b4f388f378 Fix: floating latent dock resize crash from undefined renderImage calls
- Route the dock drag-resize and screen-profile-change re-renders through the real onNewPreview routine
- Resolves the repeated 'this.renderImage is not a function' console errors
- Changelog: add fixed entry
2026-10-17 00:30:27 +02:00
KOFiblto de815c5c63 Refactor: remove all legacy node aliases and alias machinery
- Drop the six superseded node class-name aliases from NODE_CLASS_MAPPINGS and NODE_DISPLAY_NAME_MAPPINGS
- Remove module-level alias exports and frontend alias checks (decision, visual LoRA loader, image loader, aspect ratio preview, color registry)
- Remove the LEGACY_ALIAS_MAP / canonical-key machinery from __init__.py
- Update SOP, changelog and README to reflect zero compatibility surface
2026-10-17 00:27:33 +02:00
KOFiblto 88e73b81c3 Docs: scrub remaining pre-rename references from documentation
README alias notes, CSRF claims and environment notes now describe only the current state. CHANGELOG 2.6.1 entries updated and historical entries scrubbed of legacy-name strings. AGENTS/SECURITY compatibility policy updated to reflect the single remaining compatibility surface (node class-name aliases).
2026-10-16 23:36:02 +02:00
KOFiblto 4145f247b7 Refactor: purge all pre-rename compatibility layers
Legacy HTTP route aliases removed: all routes now live exclusively under /saturnnodes/*. Frontend settings migration and legacy settings-ID lookups removed (direct SaturnNodes.* keys only). Legacy localStorage keys removed from the batch queue. Legacy CSRF header fallback removed (only X-SaturnNodes-CSRF-Token is accepted). Legacy user-directory auto-migration and the deprecated user-dir helper alias removed. _LeafFlowAuth window alias removed and the restore UUID namespace renamed. Node class-name aliases remain the only compatibility surface so old workflow files keep loading.
2026-10-16 23:36:02 +02:00
KOFiblto 1e3999e32f Docs: rebrand documentation, complete settings reference and fill v2.6.1 changelog
- WALKTHROUGH.md fully rebranded and corrected against real setting labels, widget names and node display names; linked from README.
- README: settings reference now covers Live Preview, Node Management and all missing toggles; fixed the false /leafflow/* alias claim; added Manager/registry install options.
- AGENTS.md, SECURITY.md and .env.example updated to the current architecture (registry publishing, no install.py, SaturnNodes user data paths).
- CHANGELOG: [2.6.1] section filled in; empty [2.6.0] dev placeholder folded into it (2.6.0 was never tagged or released).
2026-10-16 23:23:40 +02:00
KOFiblto 5cdd808bd8 Fix: unify extension names, CSS prefixes, log tags and user-facing strings
- Frontend extensions now uniformly register as ComfyUI.SaturnNodes.*; unified saturnnodes-* CSS class/style prefixes and [SaturnNodes ...] console tags.
- Rebrand remaining user-visible strings (copy-prompt toast/alert, settings footer version badge, assets-restore client id, backend docstrings).
- Drop unused get_leafflow_user_dir imports (the alias itself stays in nodes/utils.py for third-party compatibility).
- Rename test helper root constant to SATURNNODES_ROOT.
2026-10-16 23:23:35 +02:00
KOFiblto aa63fffb36 Refactor: scope HTTP routes under /saturnnodes/* with legacy aliases
- Move image_loader, folder_lora_loader, pause_queue and persistent_queue endpoints under the /saturnnodes/* namespace; the pre-2.6 paths remain registered as permanent legacy aliases so nothing breaks.
- Update all frontend callers to the namespaced paths.
- Unify queue log tags ([SaturnNodes PauseQueue], [SaturnNodes PersistentQueue]) and fix leftover 'LeafFlow settings' messages in power-control errors.
2026-10-16 23:23:31 +02:00
KOFiblto 8727eab44e Feat: ComfyUI Registry publishing infrastructure and v2.6.1 metadata
- Add registry metadata: name 'saturnnodes', license file, requires-python, classifiers, Bug Tracker/Documentation URLs, requires-comfyui, optional extras.
- Add 400x400 Saturn icon (web/logo.png) replacing the previous 404 Icon URL.
- Add .comfyignore manifest and publish_action.yml workflow (needs REGISTRY_ACCESS_TOKEN secret).
- release.yml now publishes curated CHANGELOG notes instead of raw auto-generated compare links.
- lint.yml now runs on all branches like the test suite.
- Remove install.py: dependencies are declared in pyproject.toml / requirements.txt only.
- Bump version to 2.6.1 (registry versions are immutable once published).
2026-10-16 23:23:26 +02:00
KOFiblto 19c6084216 fix(audit): comprehensive v2.6.0 audit remediation and hardening
- C1 & C2: resolve pause queue deadlock risk, instant broadcast stalls, and graceful process restart verification
- M1 & M2: atomic .env persistence with fsync, return 500 on failure, guard debug endpoint with local auth
- M3 & M4: recursive subgraph node lookup in decision/iterator, guard snapshot seed restoration
- M5 & M6: async pipe streaming with timeouts for local runner, migrate user paths from LeafFlow to SaturnNodes
- N1 - N4: correct VisualLoraLoader legacy alias class, label legacy menu entries, match AspectRatioFinder in frontend, and harden restart child exit checks
- Stereogram: switch generate() decorator to @torch.no_grad() to avoid downstream in-place tensor mutation errors; add soft_empty_cache() and FIFO depth cache
- Frontend: support setSettingValue API, deep legacy setting inheritance across modern/classic ComfyUI frontends
- Reliability: sanitize cp1252 stdout logs, ensure atomic writes across JSON caches, add root install.py
2026-10-16 22:31:24 +02:00
KOFiblto 63747d9c9c feat(ui): add per-resolution display memory and direct drag resize handles for Floating Latent Dock and Queue Overlay 2026-10-16 19:42:37 +02:00
KOFiblto f7ec8e5073 fix(frontend): allow Visual LoRA and Image Loaders to dynamically scale to any height without empty gaps 2026-10-16 16:19:28 +02:00
KOFiblto 0e635cd37f chore: initialize v2.6.0 development track 2026-10-10 16:02:10 +02:00
KOFiblto e596c6de5a docs(changelog): finalize v2.5.0 release notes with dock, lora caching, and settings improvements 2026-10-10 15:57:33 +02:00
KOFiblto 387b5ceb0b perf(lora_loader): non-blocking async thumbnailing, bicubic fast-webp encoding, viewport lazy-loading, and bypass setting 2026-10-08 22:58:41 +02:00
KOFiblto 5369980d57 feat(dock): open live latent in core lightbox inspecting view with real-time sampling updates 2026-10-07 22:29:45 +02:00
KOFiblto 61011eea96 feat(settings): convert dock dimensions and queue height to continuous sliders and optimize layout observer 2026-10-05 21:56:46 +02:00
KOFiblto d706f0eb00 Fix bottom toolbar alignment, default dock size 280px, queue visible height setting, footer injection, and banner spacing 2026-10-05 18:41:54 +02:00
KOFiblto 77637e0626 Remove Sampling badge and text from live latent preview dock 2026-10-05 18:21:18 +02:00
KOFiblto 9c9917961c perf(lora_loader): add disk-cached WebP thumbnail generation and lazy loading for visual lora tiles 2026-10-05 17:56:39 +02:00
KOFiblto a32bb7f913 fix(settings,cli,colors): node management class grouping, footer isolation, startup total format, and beforeRegisterNodeDef error 2026-10-05 17:14:36 +02:00
KOFiblto 4c6493fe63 fix(queue): export persistent_queue_manager alias for startup banner 2026-10-05 17:00:21 +02:00
KOFiblto c12beff2d2 feat(cli): add system status lines to startup banner 2026-10-05 16:59:04 +02:00
KOFiblto 5e2872d5f8 feat(cli): clean unified startup banner in Saturn colors and remove noisy internal debug prints 2026-10-05 16:52:00 +02:00
KOFiblto 5a8f23ea2b feat(dock,settings): exact aspect contain sizing and flush alignment, remove Stereo3DLive, and detect disabled workflow nodes 2026-10-05 16:43:29 +02:00
KOFiblto 12492185d2 feat(pause,preview,nodes): pause before queue pop, flush-right portrait dock, and selective node disabling in settings 2026-10-05 16:19:43 +02:00
KOFiblto c99af98e09 feat(preview): add floating island live latent dock with dynamic minimap tracking and aspect ratio shape 2026-10-05 16:10:32 +02:00
KOFiblto a8a8946edc fix(ci): replace cv2 with PIL and add graceful fallback when onnxruntime is unavailable 2026-10-01 18:13:52 +02:00
KOFiblto 16d2ed916d fix(stereo,queue): add 1s live countdown with mid-render interrupt, fix slider NaN bug, and update restored queue create_time 2026-10-01 18:07:03 +02:00
KOFiblto 31047dc9da feat(stereo): implement SaturnStereo3D and SaturnStereo3DLive with 500ms debounced live view and native lightbox modal, fix menubar dropdown injection 2026-09-30 22:41:01 +02:00
KOFiblto e15f716563 feat(3d): implement Stereonix-inspired Stereoscopic 3D & Cross-Eye Generator node 2026-09-30 21:16:27 +02:00
KOFiblto a6fbfe06e0 docs: establish strict version-named branching workflow and initialize v2.5.0 development track 2026-09-29 20:42:04 +02:00
59 changed files with 4196 additions and 817 deletions
+17
View File
@@ -0,0 +1,17 @@
# Files and folders excluded from the ComfyUI Registry package archive.
# Everything listed here stays in the GitHub repository but is not bundled
# when publishing via .github/workflows/publish_action.yml.
# Development, tests & CI
.github/
tests/
# Contributor & agent documentation (not needed at runtime)
AGENTS.md
CLAUDE.md
GEMINI.md
CONTRIBUTING.md
# Python bytecode caches
__pycache__/
*.pyc
+9 -1
View File
@@ -1,5 +1,6 @@
# ComfyUI-LeafFlow Environment Configuration Example
# ComfyUI-SaturnNodes Environment Configuration Example
# Copy or rename this file to .env to configure custom API keys and default behaviors.
# Runtime location: ComfyUI/user/default/SaturnNodes/.env
# Optional Civitai API Key for auto-downloading LoRA preview thumbnails
CIVITAI_API_KEY=
@@ -20,3 +21,10 @@ RESTORE_ASSETS_COUNT=64
DEFAULT_PAUSE_STATE=Paused
DEFAULT_PAUSE_MODE=after_finish
PERSISTENT_QUEUE_RESTORED_STATE=Match Default
# Prompt iterator privacy
CLEAR_PROMPT_ITERATOR_ON_LAUNCH=false
# Security gates (opt-in, both disabled by default)
ALLOW_PROCESS_MANAGEMENT=false
ENABLE_LOCAL_FILE_EXECUTION=false
+1 -1
View File
@@ -1,6 +1,6 @@
---
name: Feature request
about: Suggest an idea for ComfyUI-LeafFlow
about: Suggest an idea for ComfyUI-SaturnNodes
title: '[FEAT] '
labels: 'enhancement'
assignees: ''
+2 -2
View File
@@ -2,9 +2,9 @@ name: Lint and Syntax Check
on:
push:
branches: [ main ]
branches: [ "**" ]
pull_request:
branches: [ main ]
branches: [ "**" ]
jobs:
lint:
+19
View File
@@ -0,0 +1,19 @@
name: Publish to ComfyUI Registry
on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'pyproject.toml'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Publish Custom Node
uses: Comfy-Org/publish-node-action@main
with:
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
+15 -1
View File
@@ -12,9 +12,23 @@ jobs:
contents: write
steps:
- uses: actions/checkout@v4
- name: Extract release notes from CHANGELOG.md
run: |
python - <<'PY'
import os, re, pathlib
tag = os.environ["GITHUB_REF_NAME"].lstrip("v")
changelog = pathlib.Path("CHANGELOG.md").read_text(encoding="utf-8")
pattern = re.compile(rf"^## \[{re.escape(tag)}\][^\n]*\n(.*?)(?=^## \[|\Z)", re.M | re.S)
match = pattern.search(changelog)
body = match.group(1).strip() if match else ""
if not body:
body = f"See CHANGELOG.md for the full list of changes in v{tag}."
pathlib.Path("release_notes.md").write_text(body + "\n", encoding="utf-8")
PY
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
body_path: release_notes.md
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+5
View File
@@ -23,3 +23,8 @@ user/
.vscode/
.DS_Store
Thumbs.db
# Downloaded models and checkpoints
models/
*.onnx
*.onnx.tmp
+89 -64
View File
@@ -1,7 +1,7 @@
# 🤖 Agent & Developer Standard Operating Procedure (SOP)
## `ComfyUI-LeafFlow` Contributor & Automation Guide
## `ComfyUI-SaturnNodes` Contributor & Automation Guide
This guide defines the engineering checklist and architecture standards for all AI agents (Antigravity, Claude, Gemini, Cursor, Copilot) and human developers contributing to **`ComfyUI-LeafFlow`**.
This guide defines the engineering checklist and architecture standards for all AI agents (Antigravity, Claude, Gemini, Cursor, Copilot) and human developers contributing to **`ComfyUI-SaturnNodes`**.
For Git workflow, branch protection, and Pull Request guidelines, see **[`CONTRIBUTING.md`](./CONTRIBUTING.md)**.
@@ -17,9 +17,9 @@ For Git workflow, branch protection, and Pull Request guidelines, see **[`CONTRI
| **`WALKTHROUGH.md`** | Step-by-step user tutorials, example workflows, visual load guides, and batch prompting patterns. | [WALKTHROUGH.md](./WALKTHROUGH.md) |
| **`CHANGELOG.md`** | Strict Keep-A-Changelog semantic version release history across all updates. | [CHANGELOG.md](./CHANGELOG.md) |
| **`SECURITY.md`** | Security policies, supported versions, and private vulnerability disclosure instructions. | [SECURITY.md](./SECURITY.md) |
| **`SECURITY_AUDIT_PLAYBOOK.md`** | Authoritative ComfyUI custom node security rulebook, PR #3200 review precedents, threat model, and coding standards. | [SECURITY_AUDIT_PLAYBOOK.md](./SECURITY_AUDIT_PLAYBOOK.md) |
| **`CLAUDE.md`** | AI agent instruction pointer. | [CLAUDE.md](./CLAUDE.md) |
| **`GEMINI.md`** | AI agent instruction pointer. | [GEMINI.md](./GEMINI.md) |
| **`AGENTS.md`** | AI agent instruction pointer. | [AGENTS.md](./AGENTS.md) |
| **`bug_report.md`** | GitHub issue template for reporting reproducible defects. | [bug_report.md](./.github/ISSUE_TEMPLATE/bug_report.md) |
| **`feature_request.md`** | GitHub issue template for proposing new nodes or UI features. | [feature_request.md](./.github/ISSUE_TEMPLATE/feature_request.md) |
@@ -31,7 +31,7 @@ For Git workflow, branch protection, and Pull Request guidelines, see **[`CONTRI
3. [Checklist: Adding a New Setting / Feature Flag](#3-checklist-adding-a-new-setting--feature-flag)
4. [Checklist: Updating Dependencies](#4-checklist-updating-dependencies)
5. [Cross-Platform & Safe Coding Standards](#5-cross-platform--safe-coding-standards)
6. [User Data & Storage Architecture (`ComfyUI/user/default/LeafFlow/`)](#7-user-data--storage-architecture-comfyuiuserdefaultleafflow)
6. [User Data & Storage Architecture (`ComfyUI/user/default/SaturnNodes/`)](#7-user-data--storage-architecture-comfyuiuserdefaultsaturnnodes)
7. [Git, Branching & Commit Conventions](#6-git-branching--commit-conventions)
---
@@ -39,42 +39,55 @@ For Git workflow, branch protection, and Pull Request guidelines, see **[`CONTRI
## 1. Architecture & Directory Layout
```
ComfyUI-LeafFlow/
├── __init__.py # Node registration (NODE_CLASS_MAPPINGS), web endpoints (/leafflow/settings)
├── install.py # Dependency installer script for ComfyUI Manager
├── pyproject.toml # Package metadata and pip dependencies
ComfyUI-SaturnNodes/
├── __init__.py # Node registration (NODE_CLASS_MAPPINGS), settings routes (/saturnnodes/*)
├── pyproject.toml # Package metadata, dependencies & ComfyUI Registry configuration
├── requirements.txt # Pip dependencies (auto-installed by ComfyUI Manager)
├── .env.example # Template of all supported environment variables
├── .gitignore # Exclusion rules for caches, states, and credentials
├── .comfyignore # Files excluded from the ComfyUI Registry package archive
├── nodes/ # Python backend node implementations
│ ├── aspect_ratio.py # Text & preview aspect ratio calculation nodes
│ ├── assets_restore.py # Startup output-folder history restoration
│ ├── auto_watcher.py # Automated folder watch image loaders
│ ├── decision_node.py # Inline pause/gate decision node & notifications
│ ├── text_split.py # Forward/backward & regex text splitter node
│ ├── image_loader.py # Visual image browser & EXIF/PNG metadata parser
│ ├── load_recent.py # Recent outputs loader node
│ ├── local_runner.py # Confined local script execution node & authorization routes
│ ├── lora_finder.py # Text-based prompt LoRA scanner & patcher
│ ├── lora_loader.py # Folder & visual LoRA loaders + Civitai/TMDB scrapers
│ ├── preview_latent.py # Live latent WebSocket preview node
│ ├── prompt_counter.py # Multiline prompt counter node
│ ├── prompt_iterator.py # Multiline prompt queue batch popper
│ ├── queue_control.py # Pause Queue, Persistent Queue hooks, and server routes
│ ├── stereogram.py # Stereoscopic 3D / cross-eye generator nodes
│ ├── text_replacer.py # Multiline regex & list text replacer node
│ ├── text_split.py # Forward/backward & regex text splitter node
│ ├── tray_icon.py # OS system tray icon manager & status indicator
│ └── utils.py # Shared path sanitization, string parsing, and formatting helpers
├── web/ # Frontend extensions & static assets
│ ├── leafflow_colors.js # Node theme colors (LiteGraph canvas & Vue V2)
│ ├── leafflow_settings.js# Native ComfyUI Settings panel registrations
│ ├── saturnnodes_colors.js # Node theme colors (LiteGraph canvas & Vue V2)
│ ├── saturnnodes_settings.js# Native ComfyUI Settings panel registrations
│ ├── pause_queue.js # Top toolbar Pause/Continue button group & dropdown
│ ├── pause_queue.css # Toolbar styling
│ ├── persistent_queue.js # Queue crash-recovery client ownership claimer
│ ├── batch_queue.js # 1D git-graph batch queue visualizer
│ ├── floating_latent_dock.js# Floating live latent preview dock
│ ├── preview_node.js # Live latent canvas preview widget
│ ├── logo.png # Registry icon (400x400)
│ └── js/ # Node-specific UI widgets (visual pickers, buttons, aspect preview)
│ ├── decision_node.js
│ ├── auth_helper.js # CSRF token helper shared by all frontend extensions
│ ├── copy_prompt.js
│ ├── decision_node.js
│ ├── folder_lora_loader.js
│ ├── image_loader.js
│ ├── local_runner.js
│ ├── power_sidebar.js
│ ├── preview_aspect_ratio.js
│ ├── preview_manager.js
│ └── prompt_iterator.js
│ ├── prompt_counter.js
│ ├── prompt_iterator.js
│ └── stereogram.js
├── README.md # Main documentation & complete node reference
├── WALKTHROUGH.md # End-user guide for workflows and features
└── CHANGELOG.md # Version release history
@@ -92,7 +105,7 @@ When implementing a new custom node, you **must complete all 5 steps**:
- `RETURN_TYPES`: Tuple of output types (e.g. `("IMAGE", "STRING")`).
- `RETURN_NAMES`: Tuple of human-readable output labels.
- `FUNCTION`: Exact method name to execute.
- `CATEGORY`: Categorized under `"🍃 LeafFlow/Loaders"`, `"🍃 LeafFlow/Utils"`, `"🍃 LeafFlow/Automation"`, or `"🍃 LeafFlow/Previews"`.
- `CATEGORY`: Categorized under `"🪐 SaturnNodes/Loaders"`, `"🪐 SaturnNodes/Utils"`, `"🪐 SaturnNodes/Automation"`, `"🪐 SaturnNodes/Previews"`, or `"🪐 SaturnNodes/3D & Previews"`.
- `DESCRIPTION`: Clear multi-line string explaining node functionality and parameters.
- [ ] Use `sanitize_folder_path(folder_input, default_dir)` from `nodes.utils` for any path/directory arguments (handles Windows/Linux slashes, wildcards `*`, and relative paths cleanly).
- [ ] Ensure dummy tensors are valid 4D float32 batches `torch.zeros((1, 64, 64, 3), dtype=torch.float32)` for empty image states.
@@ -107,26 +120,25 @@ When implementing a new custom node, you **must complete all 5 steps**:
# ...
}
```
- [ ] Register in `NODE_DISPLAY_NAME_MAPPINGS` with leaf prefix and emoji:
- [ ] Register in `NODE_DISPLAY_NAME_MAPPINGS` with the Saturn prefix and emoji:
```python
NODE_DISPLAY_NAME_MAPPINGS = {
"YourNewNodeName": "🍃 🏷️ Your Display Name",
"YourNewNodeName": "🪐 🏷️ Your Display Name",
# ...
}
```
- [ ] If renaming or replacing an existing node, **always preserve the old name in `NODE_CLASS_MAPPINGS` as an alias** to avoid breaking user workflows!
- [ ] Avoid renaming or replacing existing node class names; if unavoidable, migrate known workflow files to the new class name instead of keeping permanent legacy aliases (see §7).
### Step 2.3: Frontend Extensions & Colors (`web/`)
- [ ] If the node needs custom canvas/DOM widgets, implement the extension under `web/js/<feature>.js`.
- [ ] In `nodeCreated(node)` or `beforeRegisterNodeDef(nodeType, nodeData)`, **always check both `node.comfyClass` and `node.type`**, and support aliases:
- [ ] In `nodeCreated(node)` or `beforeRegisterNodeDef(nodeType, nodeData)`, **always check both `node.comfyClass` and `node.type`**:
```javascript
const isTargetNode = ["YourNodeName", "YourOldAlias"].includes(node.comfyClass) ||
["YourNodeName", "YourOldAlias"].includes(node.type);
const isTargetNode = node.comfyClass === "YourNodeName" ||
node.type === "YourNodeName";
```
- [ ] Register node theme colors in [`web/leafflow_colors.js`](./web/leafflow_colors.js):
- Loaders: Emerald Green (`color: "#059669"`, `bgcolor: "#047857"`)
- Automation & Utils: Amber (`color: "#d97706"`, `bgcolor: "#b45309"`)
- Previews & Decisions: Violet (`color: "#7c3aed"`, `bgcolor: "#6d28d9"`)
- [ ] Register node theme colors in [`web/saturnnodes_colors.js`](./web/saturnnodes_colors.js):
- The suite uses a single unified Saturn amber theme (`DEFAULT_HEADER_COLOR = "#6a3f20"`, `DEFAULT_BG_COLOR = "#472a15"`), user-overridable via the Custom Node Title/Body Color settings.
- Add the new node class key to `SATURN_NODE_TYPES` so the custom colors apply to it.
### Step 2.4: Documentation (`README.md` & `WALKTHROUGH.md`)
- [ ] Add a clean heading section in [`README.md`](./README.md) under `## 📦 Individual Nodes Reference`:
@@ -156,17 +168,17 @@ When introducing a configurable option or feature toggle:
- [ ] In `get_settings()` route: parse and return the setting.
- [ ] In `save_settings()` route: read value from incoming JSON, persist to `.env` file via `new_lines`, update `os.environ`, and trigger any dynamic runtime manager updates.
### Step 3.3: Frontend Settings Registration (`web/leafflow_settings.js`)
### Step 3.3: Frontend Settings Registration (`web/saturnnodes_settings.js`)
- [ ] Register via `app.ui.settings.addSetting({...})`:
```javascript
app.ui.settings.addSetting({
id: "LeafFlow.YourSettingName",
name: "🍃 LeafFlow: Your Setting Display Name",
id: "SaturnNodes.YourSettingName",
name: "🪐 SaturnNodes: Your Setting Display Name",
type: "boolean" /* or "text", "combo" */,
defaultValue: false,
tooltip: "Descriptive tooltip explaining user impact.",
onChange(value) {
api.fetchApi("/leafflow/settings", {
api.fetchApi("/saturnnodes/settings", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ your_setting_key: value })
@@ -184,16 +196,17 @@ When introducing a configurable option or feature toggle:
## 4. Checklist: Updating Dependencies
If a feature requires a new Python package:
- [ ] Add package to `dependencies` in [`pyproject.toml`](./pyproject.toml).
- [ ] Add package to `dependencies` list in [`install.py`](./install.py).
- [ ] Add the package to `dependencies` in [`pyproject.toml`](./pyproject.toml) (ComfyUI Registry packaging).
- [ ] Keep [`requirements.txt`](./requirements.txt) in sync for ComfyUI Manager auto-install.
- [ ] Check imports gracefully handle missing optional libraries (e.g. `try... except ImportError`).
- [ ] **Never** add an `install.py` or any runtime `pip`/`subprocess` installation — the suite is ComfyUI Registry compliant and installs nothing dynamically.
---
## 5. Cross-Platform & Safe Coding Standards
1. **Terminal Console Safety (Windows `cp1252` encoding)**:
- **Never include raw unicode emojis in backend `print()` calls** (e.g. write `print("[LeafFlow] Started")` instead of `print("[LeafFlow] 🍃 ...")`).
- **Never include raw unicode emojis in backend `print()` calls** (e.g. write `print("[SaturnNodes] Started")` instead of `print("[SaturnNodes] 🪐 ...")`).
- Windows consoles running on default codepages will raise fatal `UnicodeEncodeError: 'charmap' codec can't encode character` if raw emoji bytes hit standard output.
2. **Path Sanitization**:
- Never assume `/` or `\` separators; always use `os.path.join()`, `os.path.normpath()`, or `sanitize_folder_path()`.
@@ -210,59 +223,71 @@ If a feature requires a new Python package:
---
## 7. User Data & Storage Architecture (`ComfyUI/user/default/LeafFlow/`)
## 7. User Data & Storage Architecture (`ComfyUI/user/default/SaturnNodes/`)
All user-specific runtime states, API credentials, usage counters, and temporary caches **MUST** be stored centrally in `ComfyUI/user/default/LeafFlow/` using the helper `get_leafflow_user_dir()` in `nodes/utils.py`:
All user-specific runtime states, API credentials, usage counters, and temporary caches **MUST** be stored centrally in `ComfyUI/user/default/SaturnNodes/` using the helper `get_saturnnodes_user_dir()` in `nodes/utils.py`:
```python
from .utils import get_leafflow_user_dir
from .utils import get_saturnnodes_user_dir
USER_DIR = get_leafflow_user_dir()
USER_DIR = get_saturnnodes_user_dir()
STATE_FILE = os.path.join(USER_DIR, "your_state.json")
```
### Stored User Files:
- `ComfyUI/user/default/LeafFlow/.env` — API keys and persistent settings
- `ComfyUI/user/default/LeafFlow/lora_usage.json` — LoRA selection counts and usage badges
- `ComfyUI/user/default/LeafFlow/image_prompts_cache.json` — Cached positive prompts extracted from images
- `ComfyUI/user/default/LeafFlow/failed_scrapes.json` — Failed Civitai/TMDB scraping attempts cache
- `ComfyUI/user/default/LeafFlow/prompt_iterator_state.json` — Current iteration pointers and popped prompt queues
- `ComfyUI/user/default/LeafFlow/persistent_queue.json` — Real-time queue crash recovery state
- `ComfyUI/user/default/SaturnNodes/.env` — API keys and persistent settings
- `ComfyUI/user/default/SaturnNodes/lora_usage.json` — LoRA selection counts and usage badges
- `ComfyUI/user/default/SaturnNodes/image_prompts_cache.json` — Cached positive prompts extracted from images
- `ComfyUI/user/default/SaturnNodes/failed_scrapes.json` — Failed Civitai/TMDB scraping attempts cache
- `ComfyUI/user/default/SaturnNodes/prompt_iterator_state.json` — Current iteration pointers and popped prompt queues
- `ComfyUI/user/default/SaturnNodes/persistent_queue.json` — Real-time queue crash recovery state
### Future Migration Hooks SOP:
If legacy files need to be migrated in future multi-user releases or version upgrades:
1. In `nodes/utils.py`, define a startup check `migrate_legacy_user_data()`.
2. Inspect `custom_nodes/ComfyUI-LeafFlow/` for legacy files (`.env`, `lora_usage.json`, etc.).
3. Atomically move them to `get_leafflow_user_dir()` using `shutil.move()` or copy + delete.
4. Log a single clean notification `[LeafFlow] 🍃 Migrated legacy user data to ComfyUI/user/default/LeafFlow/`.
### Directory Rules & Compatibility Policy:
- All state, caches, and credentials live in `ComfyUI/user/default/SaturnNodes/` only. No legacy directories are read, migrated, or referenced.
- No pre-rename compatibility shims exist or may be reintroduced (old HTTP routes, old setting keys/IDs, old localStorage keys, old headers, old user directories, old node class-name aliases). Old workflow files are migrated to the current node names instead.
---
## 6. Git, Branching & Commit Conventions
## 6. Git, Branching, Versioning & Release Strategy (MANDATORY)
### 6.1 Strict Branch Naming Classification
Never create misleading or overly narrow branch names when multiple components, fixes, and features are bundled together!
- **Atomic Feature Branches** (`feature/<feature-name>`):
- Used **ONLY** when implementing a single, isolated new feature or node.
- Examples: `feature/prompt-iterator-privacy`, `feature/visual-loaders-pathing`
- **Atomic Bug Fix Branches** (`fix/<bug-name>`):
- Used **ONLY** for targeted bug fixes.
- Examples: `fix/preview-latent-insets`, `fix/tray-icon-persistence`
- **Comprehensive Integration & Release Branches** (`release/vX.Y.Z-<summary>` or `dev/<summary>`):
- **MANDATORY**: Whenever bundling multiple features, fixes, rebrands, or architectural updates into a combined testing or release candidate, use a `release/...` or `dev/...` branch name.
- **STRICTLY PROHIBITED**: Never disguise a multi-feature/fix release bundle under a single isolated `feature/<narrow-name>`.
- Examples: `release/v2.2.0-leafflow-update`, `dev/v2.2.0-full-integration`
### 6.1 Version-Named Branching Workflow
From version `v2.5.0` onward, all development work in this repository strictly adheres to a version-scoped branching model:
1. **Active Work Occurs ONLY in the Current Version Branch**:
- All active development, bug fixes, UI improvements, and code changes **MUST** occur on a dedicated branch named directly after the target version prefixed with `v` (e.g. `v2.5.0`).
- Git and GitHub fully support dots in branch names (`v2.5.0`, `v2.6.0`, `v3.0.0`).
- **STRICTLY PROHIBITED**: Never commit or push directly to `main` during active development.
2. **Strict User-Approval Gate for Merges & Releases**:
- Merging to `main` is **STRICTLY GATED** by explicit user approval.
- **NEVER** merge a version branch into `main` unless the user explicitly commands: *"merge to main"* or *"make a release"*.
3. **Release & Tagging Execution Steps (Upon User Command)**:
When explicit permission to release is granted:
- **Merge**: Merge the version branch (e.g. `v2.5.0`) into `main`.
- **Tag**: Create an annotated Git tag prefixed with `v` (e.g. `git tag -a v2.5.0 -m "v2.5.0 ..."`).
- *Rule*: **ALWAYS** use the `v` prefix (`v2.5.0`, `v2.6.0`). **NEVER** create bare tags without `v` (like `2.5.0`).
- **GitHub Release**: Publish or update the GitHub Release attached to that `vX.Y.Z` tag.
- *Rule*: Every release **MUST** include a clear, descriptive title (e.g. `v2.5.0 - <Feature/Theme Summary> 🪐`) and a concise markdown bullet-point explanation of what changed and what was fixed (matching the standard of `v2.3.2` and `v2.4.0`), never just bare automated compare links.
- **Next Version Transition**:
- Immediately checkout a new branch from `main` named after the next target version (e.g. `git checkout -b v2.6.0` or `git checkout -b v3.0.0`).
- Update version identifiers in `pyproject.toml`, `__init__.py`, `CHANGELOG.md`, and frontend info to the new development version.
- Continue all subsequent work exclusively on the new version branch.
### 6.2 Excluded Files & Privacy
Never commit sensitive keys, runtime states, or caches:
Never commit sensitive keys, personal paths, runtime states, or caches:
- `.env`, `.env.local`
- `persistent_queue.json`, `lora_usage.json`, `failed_scrapes.json`, `image_prompts_cache.json`
- `user/` directory
- Personal user names, machine paths (`C:\Users\...`), or private model names.
### 6.3 Commit Messages
Use atomic, descriptive English commit headers:
- `Feat: ...` (New features or nodes)
- `Fix: ...` (Bug fixes, UI sync repairs)
- `Fix: ...` (Bug fixes, UI repairs)
- `Docs: ...` (Documentation, README, Walkthrough updates)
- `Refactor: ...` (Code restructuring or rebrands)
- `Release: ...` (Consolidated version releases)
- `Refactor: ...` (Code restructuring or cleanup)
- `Release: ...` (Consolidated version release merge)
### 6.4 Registry Publishing (ComfyUI Registry)
- Registry node name: `saturnnodes` (Publisher `KOFiblto`, `DisplayName = ComfyUI-SaturnNodes`). **Published versions are immutable** — always bump the version before publishing a change.
- `.github/workflows/publish_action.yml` publishes automatically when `pyproject.toml` changes on `main` (and can also be triggered manually via workflow dispatch). It requires the `REGISTRY_ACCESS_TOKEN` repository secret.
- `.comfyignore` excludes development files (tests, CI, contributor docs) from the published package archive.
- Icon (`web/logo.png`) must be square, 400x400 or smaller.
+91 -23
View File
@@ -5,10 +5,78 @@ All notable changes to `ComfyUI-SaturnNodes` will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.4.1] - Latest (Development)
## [2.6.1] - In Development
### Added
- **Per-Resolution Dock Memory & Drag Resize Handles**: The Floating Latent Dock and the queue overlay now remember their size per resolution/monitor and expose on-screen drag resize handles.
- **Visual LoRA Loader Maintenance Controls**: New `↺ Counter`, `🧹 Usage` and `🗑 Cache` reset buttons on the Visual LoRA Loader node (each with a confirmation prompt) to reset the per-node Sequential/Random LoRA cycle and prompt→LoRA assignments, clear usage badges, or delete cached thumbnails.
- **ComfyUI Registry Packaging**: Complete registry metadata (`pyproject.toml` with `requires-comfyui`, classifiers and optional extras), a Saturn icon (`web/logo.png`), a `.comfyignore` manifest, and an automated `publish_action.yml` workflow.
- **Curated GitHub Releases**: `release.yml` now publishes the matching `CHANGELOG.md` section as the GitHub Release body instead of raw auto-generated compare links.
### Changed
- Active development track for subsequent patches and visual LoRA loader V1 enhancements.
- **Free-Form Dock Resize**: Dragging the Floating Latent Dock's corner now resizes width and height independently (no longer locked to the latent's aspect ratio) within sane 100–2000px bounds. The drag starts from the dock's current on-screen size (no jump to the larger saved settings box), shows the free-form box live, writes the dragged dimensions back into the `Floating Dock Max Width/Height` settings (now 1px-stepped sliders), and snaps the dock to the exact latent fit on release.
- **Route Namespacing**: All HTTP routes live exclusively under `/saturnnodes/*`; the transitional pre-2.6 route aliases (`/pause_queue/*`, `/persistent_queue/*`, `/image_loader/*`, `/folder_lora_loader/*`) were removed entirely.
- **Compatibility Surface Reduction**: All remaining pre-rename compatibility layers were purged — duplicate legacy route handlers, frontend settings migration and legacy settings-ID lookups, legacy localStorage/storage keys, the legacy CSRF header fallback, the legacy user-directory auto-migration, and all superseded node class-name aliases. No backward-compatibility surface remains.
- **Naming Consistency**: Unified `ComfyUI.SaturnNodes.*` frontend extension names, `saturnnodes-*` CSS prefixes, and `[SaturnNodes ...]` console log tags.
- **Documentation Rebrand**: `WALKTHROUGH.md`, the README settings reference, `.env.example`, `AGENTS.md` and `SECURITY.md` were fully rebranded and reconciled with the real setting labels, widget names and environment variables.
- **Registry Identity**: Package name set to `saturnnodes` (per registry naming best practices); version bumped to `2.6.1`.
### Fixed
- **Publishing Compliance**: Removed `install.py` (no runtime `pip` execution, matching the documented "Zero Runtime Package Installs" claim) and corrected a stale README claim about legacy route aliases.
- **Audit Remediation Hardening**: Full audit remediation pass — pause queue stall/deadlock fixes, restart verification hardening, atomic `.env` writes with proper error responses, debug endpoint guards, subgraph-safe lookups, runner pipe streaming, IPv4-mapped loopback handling and more (119 unit tests passing).
- **Floating Latent Dock Resize Crash**: Fixed a `this.renderImage is not a function` error thrown while dragging the dock's resize handles or when the screen profile changed; the resize paths now invoke the dock's actual render routine.
- **Queue Overlay Resize Lag**: Resizing the queue overlay no longer rewrites a stylesheet on every pointermove (which forced a full-document style recalculation, layout and paint churn on every frame); heights are now applied as scoped, rAF-throttled inline styles.
- **Dock Drag Performance & Stuck Drags**: Dragging the dock no longer rebuilds the full-resolution canvas backing store (GPU texture/layer churn, ~74% GPU load during drags) on every pointermove — only CSS sizes change while dragging, with one full-quality redraw on release. Pointer capture plus `pointercancel`/window-blur guards fix drags that "never stopped" when the pointer was released outside the window.
- **Prompt Iterator Reset Clarity**: The Prompt Queue Iterator's `Reset Counter (0)` button now confirms before resetting and explains that it resets the run pointer to the first prompt without wiping the queue state file (use Settings → `Reset All Queues` for a full wipe).
### Removed
- `install.py` — dependencies are declared in `pyproject.toml` / `requirements.txt` only, and ComfyUI Manager handles installation.
---
## [2.5.0] - 2026-10-10 [Stable]
### Added
- **Floating Latent Live Preview Dock & Core Lightbox Live Inspection**:
- Floating live latent preview dock with dynamic aspect ratio preservation and contain-scaling, eliminating letterbox bars and layout jitter.
- Minimap tracking and alignment alongside canvas navigation controls.
- **Native Core Lightbox Live Inspecting View**: Clicking the floating latent dock opens the live generation directly in ComfyUI's native inspecting lightbox view, updating live in real time as each diffusion sampling step arrives.
- Minimalist design: removed redundant "Sampling..." badge overlays for distraction-free monitoring.
- **High-Performance LoRA Loader Engine & Viewport WebP Lazy-Loading**:
- **Disk-Cached WebP Generation**: High-resolution preview images are downscaled via bicubic fast-WebP encoding and cached in `ComfyUI/user/default/SaturnNodes/cache/lora_thumbs/` (~35KB per card).
- **Non-Blocking Background Worker**: Thumbnail processing runs asynchronously on worker threads with `threading.Event`, eliminating canvas UI thread lockups during heavy directory indexing.
- **Viewport IntersectionObserver**: Implemented native `IntersectionObserver` on visual LoRA cards so thumbnails only load as they scroll into view.
- Added an explicit settings toggle to bypass thumbnail generation if desired.
- **Stereoscopic 3D / Cross-Eye Generator (`SaturnStereo3D`)**:
- Transform 2D images into stereoscopic 3D pairs for cross-eye viewing, parallel 3D viewers, VR displays, and red-cyan anaglyphs.
- Hybrid depth execution: accepts any input `depth_map` (zero downloads, 1ms execution) or automatically falls back to built-in Depth Anything V2 Small ONNX model cached locally, with mathematical gradient fallback when ONNX is absent.
- Stereonix-inspired controls: `depth_intensity`, `depth_gamma`, `invert_depth`, `convergence_plane`, `image_zoom`, `pan_horizontal`, `pan_vertical`.
- Framing and focus controls: adjustable `gap_spacing`, `outer_border` padding, and high-contrast `alignment_dots`.
- **Stereoscopic 3D Live Viewer (`SaturnStereo3DLive`)**:
- Interactive live viewer node featuring a real-time **1s countdown timer** on parameter adjustment.
- **Mid-Render Interruption**: Modifying sliders during generation immediately sends `/interrupt` to abort obsolete rendering and restarts the 1s countdown.
- **In-Memory Depth Map Caching**: Cached depth predictions allow near-instant (~5ms) re-rendering when tweaking intensity, gamma, zoom, pan, and spacing on the same input image.
- **Queue Execution Controls & Mid-Generation Pause**:
- Added execution interception hook allowing the queue to pause before popping the next item from the queue.
- Restored queue prompt `create_time` timestamps are refreshed upon restart to prevent deprioritization in history.
- **Modernized Continuous Sliders Settings UI**:
- Converted `Visible Queue Items (Height)` and `Live Latent Dock Size` from rigid dropdowns into smooth continuous sliders.
- Cleaned settings categories and isolated context menus to prevent bleeding into top PrimeVue application menubars.
- **CLI Terminal Branding & Clean Telemetry**:
- Clean unified startup banner styled in Saturn amber theme.
- Cleaned noisy internal debug logging, displaying concise status lines for node count, persistence status, and storage paths.
### Fixed
- **Persistent Queue Restored Creation Timestamp**:
- Fixed an issue where unfinished prompts resumed after a server restart sorted to the bottom of the history and assets list by updating `create_time` to the current timestamp on recovery.
- **Live Viewer Widget Value Corruption**:
- Fixed an issue where sliding widgets on `SaturnStereo3DLive` set them to `NaN` or `0` due to arrow-function callback scoping, preventing "wrong type" and "missing connection" validation errors.
- **Top Application Menubar Injection**:
- Fixed an issue where "Copy prompt" appeared in the main application menu (between File and Edit) on PrimeVue Frontend V2 by strictly excluding `.comfy-command-menu`, `.comfy-menu`, `.p-menubar`, and top-level menuitems.
- **CI & Environment Resilience**:
- Replaced OpenCV dependency with PIL and ensured graceful fallback when `onnxruntime` is not installed.
- **Security & Path Confinement**:
- Hardened directory traversal guards against UNC paths and relative escapes, passing 119 unit tests.
---
@@ -21,7 +89,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Core Stability & Logic**:
- Implemented true cycle permutation for `Random (Cycle)` in `PromptQueueIterator`.
- Upgraded comma parsing in `MultiTextReplacer` with `csv.reader` to preserve quoted phrases.
- Removed legacy node mappings (`LeafFlowDecision`, `LeafFlowTextSplit`).
- Removed legacy pre-rebrand node class mappings.
- Added robust exception handling for unterminated regex in text splitting.
- Optimized 60fps canvas draw loops by decoupling badge geometry enforcement from `onDrawForeground`.
@@ -31,14 +99,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed & Rebranded
- **Full Suite Rebrand to SaturnNodes (`🪐`)**:
- Rebranded the entire suite from `ComfyUI-LeafFlow` to **`ComfyUI-SaturnNodes`** with signature emoji `🪐`.
- Renamed the entire suite to **`ComfyUI-SaturnNodes`** with signature emoji `🪐`.
- Node display names updated with the `🪐` prefix across all 16 custom nodes.
- Node category updated to `🪐 SaturnNodes/*` (`Loaders`, `Utils`, `Previews`, `Queue`, `Automation`).
- Full backward compatibility: all legacy class names (`LeafFlowDecision`, `LeafFlowTextSplit`) preserved and aliased alongside new class names in `NODE_CLASS_MAPPINGS`.
- Dual HTTP route registration: both `/saturnnodes/*` and `/leafflow/*` routes are active, guaranteeing compatibility with existing scripts, extensions, and bookmarks.
- Dual WebSocket event emission: both `saturnnodes_*` and `leafflow_*` events are broadcast to the frontend.
- Seamless settings migration: frontend settings and local storage automatically migrate from `LeafFlow.*` to `SaturnNodes.*` with instant fallback.
- Automatic user directory migration: `.env` and `prompt_iterator_state.json` migrate smoothly from `user/default/LeafFlow/` to `user/default/SaturnNodes/`.
- Full backward compatibility: all legacy pre-rebrand class names preserved and aliased alongside the new class names in `NODE_CLASS_MAPPINGS`.
- Dual HTTP route registration for full compatibility with existing scripts, extensions, and bookmarks.
- Dual WebSocket event emission for full frontend compatibility.
- Seamless settings migration: frontend settings and local storage automatically migrated to `SaturnNodes.*` keys with instant fallback.
- Automatic user directory migration: `.env` and `prompt_iterator_state.json` migrated smoothly into `user/default/SaturnNodes/`.
- Removed third-party PromptBookmarks coupling: cleaned UI bookmarks button from copy prompt node for modularity.
---
@@ -47,10 +115,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security & Hardening
- **Universal CSRF Protection Across All Mutation Routes**:
- Protected `POST /leafflow/prompt_iterator/reset_node`, `POST /leafflow/prompt_iterator/clear`, and `POST /leafflow/prompt_iterator/open_file` with `is_authenticated_local_request`.
- Protected `POST /leafflow/decision` with `is_authenticated_local_request`.
- Protected queue-mutating endpoints (`POST /pause_queue/toggle`, `POST /pause_queue/mode`, `POST /pause_queue/continue`, `POST /persistent_queue/claim`, `POST /leafflow/batch_queue/sync`, `POST /leafflow/assets/restore`) with `is_authenticated_local_request`.
- Updated all frontend callers in `web/` to send the `X-LeafFlow-CSRF-Token` session header via `authenticatedFetch`.
- Protected the prompt iterator reset, clear, and open-file endpoints with `is_authenticated_local_request`.
- Protected the decision node endpoint with `is_authenticated_local_request`.
- Protected all queue-mutating endpoints (pause controls, persistent queue claim, batch queue sync, assets restore) with `is_authenticated_local_request`.
- Updated all frontend callers in `web/` to send the session CSRF header via `authenticatedFetch`.
- **SSRF Protection & Scheme Filtering for Preview Scrapers**:
- Added `is_safe_external_image_url` validating that downloaded image URLs use standard `https` or `http` schemes.
- Strictly blocked internal loopback (`127.0.0.1`, `localhost`), private networks (`10.*`, `172.16.*`, `192.168.*`), and link-local cloud metadata endpoints (`169.254.*`).
@@ -83,18 +151,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Recursive process tree termination on timeout or cancellation (uses `taskkill /F /T` on Windows to prevent orphaned background processes).
- **In-Memory Operator Authorization Gate**: Removed `security_consent` from `INPUT_TYPES` so consent never serializes into workflow JSON or dropped image metadata. Requires active canvas button click `[⚡ Authorize Run]` with 5-minute single-use memory token.
- Visual node status indicator (`[ARMED]` in emerald green vs `[DISARMED]` in red).
- Global toggle setting (`LeafFlow.9 - 🛡️ Security.01_AllowLocalFileExecution`, default `false`).
- Global `Allow Local File Execution` toggle setting (default `false`).
- **🛡️ CSRF Defense & Request Authentication**:
- Added `is_authenticated_local_request` validating loopback origin, `Sec-Fetch-Site` header (blocking `cross-site` calls from visited web pages), and `Origin`/`Referer` headers.
- Cryptographically secure per-session CSRF token (`X-LeafFlow-CSRF-Token`) generated via `secrets.token_hex(32)` and validated with `secrets.compare_digest`.
- Cryptographically secure per-session CSRF token generated via `secrets.token_hex(32)` and validated with `secrets.compare_digest`.
- Added frontend auth helper (`web/js/auth_helper.js`) automatically fetching and attaching CSRF tokens to administrative fetch requests.
- **⚡ Two-Step Power Action Handshake**:
- Server restart and shutdown endpoints require `ALLOW_PROCESS_MANAGEMENT=true` plus a two-step confirmation handshake (`POST /leafflow/power/request_token` to issue a 30s single-use ticket, followed by `POST /leafflow/power/confirm_action` to consume and execute).
- Server restart and shutdown endpoints require `ALLOW_PROCESS_MANAGEMENT=true` plus a two-step confirmation handshake (requesting a 30-second single-use ticket, then confirming the action to consume and execute it).
### Fixed & Compliance
- **Complete Removal of `ALLOW_ANY_SCRIPT_PATH`**: Eliminated all path escape settings to guarantee execution confinement to `ComfyUI/scripts/`.
- **Dynamic Node Count**: Replaced hardcoded node count in startup banner with dynamic `len(NODE_CLASS_MAPPINGS)` (now reporting all 16 registered nodes).
- **Universal Synchronized Versioning**: Version `2.3.0` synchronized across `__init__.py`, `pyproject.toml`, `/leafflow/debug/export`, `README.md`, and `CHANGELOG.md`.
- **Universal Synchronized Versioning**: Version `2.3.0` synchronized across `__init__.py`, `pyproject.toml`, the debug export endpoint, `README.md`, and `CHANGELOG.md`.
- **Process Management Security Toggle**: Server restart and shutdown controls are disabled by default (`ALLOW_PROCESS_MANAGEMENT=false`). If disabled, attempts to trigger restart/shutdown via the UI or API return HTTP 403 with clear instructions.
- **Optional `pystray` Dependency**: Made `pystray` an optional extra (`[project.optional-dependencies] tray = ["pystray"]`) and removed all runtime `pip install` subprocess calls, ensuring zero crashes on headless cloud servers, Docker, or Google Colab.
- **Universal Loopback Protection**: Added `is_local_request(request)` validation to all legacy queue endpoints (`/pause_queue/*` and `/persistent_queue/claim`).
@@ -121,7 +189,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Restores the direct "Inspect asset" (zoom in) button directly onto image cards in the Assets pane hover action bar, placed seamlessly alongside Download, Copy Prompt, and Bookmarks (restoring access since newer ComfyUI versions tucked it away behind the 3-dots submenu). Default is `false` (opt-in).
- **🔖 Robust Inline SVG Icons for "Save to Prompt Bookmarks"**:
- Replaced runtime Tailwind icon class references with crisp inline SVG ribbons, fixing an issue in modern `comfyui_frontend_package` where the bookmark icon rendered with 0 dimensions (empty space).
- **🎨 1D Git-Graph Batch Queue Visualizer (`ComfyUI.LeafFlow.BatchQueue`)**:
- **🎨 1D Git-Graph Batch Queue Visualizer**:
- Automatically identifies workflows queued together as batches in both ComfyUI Frontend V2 (`JobAssetsList`) and Classic V1 queue list.
- Purely graphical 1D colored line along the left edge of queue items without any text or number clutter.
- **36 Curated Cycling Colors**: Sequential assignment ensures adjacent batches have distinct, high-contrast colors.
@@ -132,7 +200,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Single-item batches curve inward at both top and bottom (`(`).
- **In-between Infiltration Handling**: When another prompt or batch is queued in-between items of an existing batch, the interrupted batch retains its open straight ends (no false start/end curves), while the inserted item is cleanly enclosed in its own bracket.
- **PersistentQueue Interoperability**: Operates client-side via `localStorage` when standalone, and synchronizes with `PersistentQueueManager` so batch relationships restore automatically upon server restart.
- **Settings Toggle**: Added `LeafFlow.BatchQueue.Enabled` setting in ComfyUI Settings menu.
- **Settings Toggle**: Added an enable/disable batch queue setting in the ComfyUI Settings menu.
### Fixed
- **📐 Independent Per-Node `tile_size` in Visual Loaders**:
@@ -142,7 +210,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Hardened image card button injection guards to avoid injecting into queue item elements or small icon previews in modern virtual grids.
### Security & Registry Compliance
- **Local-Only Route Enforcement**: All server control endpoints (`/leafflow/power/*`), settings updates (`/leafflow/settings`), and queue sync routes now strictly verify loopback origin (`127.0.0.1` / `::1`), rejecting remote calls with `403 Forbidden`.
- **Local-Only Route Enforcement**: All server control endpoints (power actions, settings updates, queue sync) now strictly verify loopback origin (`127.0.0.1` / `::1`), rejecting remote calls with `403 Forbidden`.
- **Directory Traversal Protection**: Image loading (`VisualImageLoader`) and thumbnail endpoints are strictly confined to ComfyUI `input`, `output`, and `temp` directories.
- **Packaging & Installation Standards**: Removed runtime `install.py` in favor of standard `requirements.txt` (`Pillow`, `piexif`, `numpy`, `pystray`), and removed `"torch"` from `pyproject.toml` to prevent host CUDA environment corruption.
- **Opt-In Preview Scraping**: Civitai and TMDB network scraping defaulted to disabled (`ENABLE_CIVITAI_SCRAPING=false`, `ENABLE_TMDB_SCRAPING=false`).
@@ -157,7 +225,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.1.0] - 2026-08-24
### Added
- **Centralized ComfyUI User Directory (`ComfyUI/user/default/LeafFlow/`)**:
- **Centralized ComfyUI User Directory (`ComfyUI/user/default/SaturnNodes/`)**:
- All runtime JSON state (`lora_usage.json`, `lora_loader_state.json`, `image_prompts_cache.json`, `failed_scrapes.json`, `prompt_iterator_state.json`, `persistent_queue.json`, `.env`) now strictly lives inside the ComfyUI user folder rather than polluting the node directory.
- **Structured ComfyUI V2 Settings Menu**:
- Restructured settings into 6 explicit subcategories with clear titles, info tooltips, and real styled action buttons (`🗑️ Reset Scrapes Cache`, `🔄 Reset All Queues`).
@@ -168,7 +236,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed empty folder matching edge case in `BackToPlaceholder` (`undo_placeholder.py`).
- Fixed XML entity escaping for native Windows Toast Notifications in `LeafFlowDecision`.
- Fixed XML entity escaping for native Windows Toast Notifications in the decision node.
- Removed accidental scrape cache reset during minor settings updates in `__init__.py`.
- Removed obsolete `playwright` dependency from `pyproject.toml` and `install.py`.
@@ -183,7 +251,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **🍃 🔄 Prompt Queue Iterator**: Multiline batch prompt queue iterator with Pop, Cycle, and Random modes.
- **🍃 🔤 Multi Text Replacer**: High-performance multi-target find & replace node with protection against recursive replacement loops.
- **🍃 ✂️ Text Split**: Split strings into two outputs using literal delimiters or regex patterns (forward/backward).
- **🍃 ⏸️ LeafFlow Decision**: Interactive mid-workflow pause node with UI buttons (Continue / Cancel / Stop) and desktop notifications.
- **🍃 ⏸️ Decision**: Interactive mid-workflow pause node with UI buttons (Continue / Cancel / Stop) and desktop notifications.
- **🍃 🔔 System Tray Integration**: OS notification area tray icon with real-time queue status colors and outside-browser queue controls.
- **🍃 🖼️ Assets & History Restore**: Automatic restoration of recent generations into the ComfyUI Assets / History pane on startup.
+9 -7
View File
@@ -22,12 +22,14 @@ Before opening a new issue:
## 🛠️ Contribution Workflow (Feature Branches & PRs)
### Branch and Pull Request Policy
Direct pushes to the `main` branch are restricted. All changes, bug fixes, and new features must be developed on a dedicated feature or fix branch and merged via Pull Request.
Direct pushes to the `main` branch are strictly prohibited. Active development is organized into dedicated version branches (e.g. `v2.5.0`, `v2.6.0`). Community features or fixes should branch off the active version branch or submit Pull Requests targeting it.
All development follows a **Feature Branch $\rightarrow$ Pull Request** workflow:
Merging into `main` and creating releases is strictly gated by repository maintainer explicit authorization. Every release is tagged with `v` prefix (`vX.Y.Z`) and accompanied by release notes detailing all changes.
All development follows a **Branch $\rightarrow$ Pull Request** workflow:
```
1. Fork/Branch Repository --> 2. Create Feature Branch --> 3. Commit Changes --> 4. Open Pull Request
1. Fork/Branch Repository --> 2. Create Working Branch --> 3. Commit Changes --> 4. Open Pull Request
```
### Step 1: Fork and Clone
@@ -37,7 +39,7 @@ git clone https://github.com/YOUR_USERNAME/ComfyUI-SaturnNodes.git
cd ComfyUI-SaturnNodes
```
### Step 2: Create a Feature Branch
### Step 2: Create a Working Branch
Create a descriptive branch for your change:
```bash
git checkout -b feature/short-description
@@ -67,8 +69,8 @@ Push your branch to your fork on GitHub and open a Pull Request:
```bash
git push origin feature/short-description
```
1. Open [Pull Requests](https://github.com/KOFiblto/ComfyUI-LeafFlow/pulls) $\rightarrow$ Click **New pull request**.
2. Select `base: main` $\leftarrow$ `compare: feature/short-description`.
1. Open [Pull Requests](https://github.com/KOFiblto/ComfyUI-SaturnNodes/pulls) $\rightarrow$ Click **New pull request**.
2. Select the active version branch (e.g. `v2.5.0`) or `main` as base $\leftarrow$ `compare: feature/short-description`.
3. Provide a brief summary of what changed and how you verified your fix.
4. Wait for code review approval and automated status check validation!
@@ -79,4 +81,4 @@ git push origin feature/short-description
- Be respectful and constructive when commenting on issues and reviewing pull requests.
- The official mascot of ComfyUI is a very cute anime girl with massive fennec ears, a big fluffy tail, long blonde wavy hair, and blue eyes. Treat her with respect!
Thank you for helping make `ComfyUI-LeafFlow` better for everyone!
Thank you for helping make `ComfyUI-SaturnNodes` better for everyone!
+80 -11
View File
@@ -2,11 +2,14 @@
A unified workflow control and productivity suite for **ComfyUI**. Both **Frontend V1 (LiteGraph)** and **Frontend V2 (Vue UI)** are supported, though `VisualLoraLoader` breaks on V1 for now (will be fixed).
> 📖 **New here?** Follow the step-by-step [Complete Walkthrough](WALKTHROUGH.md) for setup, node recipes, and batch-prompting patterns.
---
## 🚀 Key Capabilities & Overview
- **Live Latent Preview**: Watch generations materialize step-by-step directly inside your graph canvas nodes in real time.
- **Stereoscopic 3D & Cross-Eye Generator**: Convert 2D artwork and renders into 3D stereograms, parallel views, and red-cyan anaglyphs with automatic Depth Anything V2 fallback.
- **Batch Prompting & Iteration**: Queue multiple prompts automatically with delimiter splits, regex blocks, and persistent queue state tracking.
- **Visual Thumbnail Browsing**: Browse LoRAs and image folders with auto-scraped Civitai & TMDB previews, ranking badges, and multi-selection.
- **Real-Time Queue & Pause Controls**: Pause, resume, or cleanly cancel execution mid-generation, with automatic crash recovery for interrupted queues.
@@ -62,11 +65,17 @@ Loads a LoRA using formatted pretty names (e.g. `Cyberpunk Character V1` instead
</details>
<details>
<summary><b>🪐 🖼️ Visual LoRA Loader</b> (<code>VisualLoraLoader</code> / alias <code>FolderLoraLoaderVisualPrettyV2</code>)</summary>
<summary><b>🪐 🖼️ Visual LoRA Loader</b> (<code>VisualLoraLoader</code>)</summary>
#### Overview
Visual thumbnail browser for LoRAs with Civitai SHA256 search & TMDB auto-scraping, popularity rank badges (🔥), multi-selection support, and independent per-node thumbnail zoom sizing.
#### Maintenance Reset Buttons
The node's control bar exposes three maintenance buttons — each asks for confirmation before acting:
- **`↺ Counter`**: Resets this node's `Sequential`/`Random` cycle position and clears its prompt→LoRA assignments (stored in `user/default/SaturnNodes/lora_loader_state.json`). ⚠️ Only use between batches: running/queued workflows will restart the cycle from the first selected LoRA and can mismatch their prompts.
- **`🧹 Usage`**: Clears all LoRA usage counters and badges (`lora_usage.json`). Cosmetic only — affects badges and `Usage` sortings, not LoRA loading.
- **`🗑 Cache`**: Deletes cached thumbnail images. They regenerate automatically when you view the grid.
#### Inputs & Widgets
- **`model`** (`MODEL`): Input model.
- **`clip`** (`CLIP`): Input CLIP.
@@ -87,7 +96,7 @@ Visual thumbnail browser for LoRAs with Civitai SHA256 search & TMDB auto-scrapi
</details>
<details>
<summary><b>🪐 📷 Visual Image Loader</b> (<code>VisualImageLoader</code> / alias <code>ImageLoaderVisualPrettyV2</code>)</summary>
<summary><b>🪐 📷 Visual Image Loader</b> (<code>VisualImageLoader</code>)</summary>
#### Overview
Visual thumbnail browser for image folders with instant preview selection, independent per-node thumbnail zoom sizing, and EXIF positive prompt metadata extraction. Path access is strictly confined to ComfyUI `input`, `output`, and `temp` directories for safe operation.
@@ -151,10 +160,10 @@ Canvas rendering node that listens to sampler WebSocket latent binary streams an
</details>
<details>
<summary><b>🪐 ⏸️ Saturn Decision</b> (<code>SaturnDecision</code> / alias <code>LeafFlowDecision</code>)</summary>
<summary><b>🪐 ⏸️ Saturn Decision</b> (<code>SaturnDecision</code>)</summary>
#### Overview
Pauses workflow execution at a specific step and displays an inline UI popup with Continue, Cancel, or Stop Workflow actions, plus optional native OS desktop notifications. Fully backward compatible with workflows containing `LeafFlowDecision`.
Pauses workflow execution at a specific step and displays an inline UI popup with Continue, Cancel, or Stop Workflow actions, plus optional native OS desktop notifications.
#### Inputs & Widgets
- **`disable`** (`BOOLEAN`): Bypass decision gate.
@@ -166,7 +175,7 @@ Pauses workflow execution at a specific step and displays an inline UI popup wit
</details>
<details>
<summary><b>🪐 📐 Text Aspect Ratio Finder</b> (<code>TextAspectRatioFinder</code> / alias <code>AspectRatioFinder</code>)</summary>
<summary><b>🪐 📐 Text Aspect Ratio Finder</b> (<code>TextAspectRatioFinder</code>)</summary>
#### Overview
Parses input text for aspect ratios (e.g. `16:9`, `2.35:1`), syntax-checks them, and calculates pixel resolution for a target megapixel target.
@@ -204,7 +213,7 @@ Computes image dimensions and aspect ratio from an input image tensor and format
</details>
<details>
<summary><b>🪐 🔎 Text LoRA Finder & Loader</b> (<code>TextLoraFinder</code> / alias <code>LoraTextFinder</code>)</summary>
<summary><b>🪐 🔎 Text LoRA Finder & Loader</b> (<code>TextLoraFinder</code>)</summary>
#### Overview
Scans input prompt text for `<lora:name:strength>` tags or names matching a folder on disk, dynamically applies them, and returns patched models along with sanitized prompt text.
@@ -278,7 +287,7 @@ Performs multiple text replacements in a single step using comma-separated or ne
</details>
<details>
<summary><b>🪐 ✂️ Text Split</b> (<code>SaturnTextSplit</code> / alias <code>LeafFlowTextSplit</code>)</summary>
<summary><b>🪐 ✂️ Text Split</b> (<code>SaturnTextSplit</code>)</summary>
#### Overview
Splits text into two parts at a specified delimiter. Supports forward (from start) and backward (from end) search, as well as regular expressions.
@@ -321,6 +330,36 @@ Safely executes a local script or executable (`.bat`, `.cmd`, `.ps1`, `.exe` on
- **`passthrough`** (`*`): Passes input `trigger` data through untouched to downstream nodes.
</details>
<details>
<summary><b>🪐 👓 Stereoscopic 3D / Cross-Eye Generator</b> (<code>SaturnStereo3D</code>)</summary>
#### Overview
Inspired by Stereonix, this node transforms any 2D image into stereoscopic 3D pairs for cross-eye viewing, parallel 3D viewers, VR/3D displays, and red-cyan anaglyph 3D glasses using depth-based horizontal disparity mapping (DIBR). Features automatic on-demand Depth Anything V2 Small fallback, crop/zoom/pan controls, outer border framing, empty gap spacing, and focus alignment guide dots.
#### Inputs & Widgets
- **`image`** (`IMAGE`): The source 2D image.
- **`mode`** (`COMBO`): 3D viewing format (`Cross-Eye`, `Parallel (Wall-Eyed)`, `Red-Cyan Anaglyph`, `Side-by-Side (Parallel)`, `Top-Bottom (Over-Under)`, `Left Eye Only`, `Right Eye Only`).
- **`depth_intensity`** (`FLOAT` slider, `0.0` - `100.0`, default `25.0`): Controls how much the left and right eye perspectives shift apart horizontally.
- **`depth_gamma`** (`FLOAT` slider, `0.1` - `3.0`, default `0.50`): Adjusts the depth curve for realistic falloff.
- **`invert_depth`** (`BOOLEAN`, default `False`): Flips near and far depth planes.
- **`convergence_plane`** (`FLOAT` slider, `0.0` - `1.0`, default `0.50`): Focal depth plane where horizontal shift is zero (the screen surface). Depths closer pop out; depths farther sink in.
- **`image_zoom`** (`FLOAT` slider, `10.0` - `300.0`, default `100.0`): Zoom into areas of interest before generating 3D disparity.
- **`pan_horizontal`** (`FLOAT` slider, `-100.0` - `100.0`, default `0.0`): Horizontal pan offset.
- **`pan_vertical`** (`FLOAT` slider, `-100.0` - `100.0`, default `0.0`): Vertical pan offset.
- **`gap_spacing`** (`INT`, default `20`): Empty black space between the left and right eye panels.
- **`outer_border`** (`INT`, default `0`): Black border padding around the canvas (allows shrinking images for easier cross-eye viewing on large monitors).
- **`alignment_dots`** (`BOOLEAN`, default `True`): Renders focus guide dots centered above each eye view to easily lock into 3D cross-eye view.
- **`fill_method`** (`COMBO`): Hole-filling method (`Smooth (Bilinear Grid)` vs `Nearest Neighbor (Stereonix)`).
- **`preview_zoom`** (`COMBO`): Scale preview for comfortable canvas cross-eye viewing (`Fit`, `25%`, `33%`, `50%`, `75%`, `100%`).
- **`depth_map`** (`IMAGE`, *Optional Input*): Optional depth map from any node. If not connected, automatically downloads and runs Depth Anything V2 Small ONNX model internally.
#### Outputs
- **`stereogram`** (`IMAGE`): The composited 3D stereogram image.
- **`left_eye`** (`IMAGE`): The warped left eye viewpoint.
- **`right_eye`** (`IMAGE`): The warped right eye viewpoint.
- **`depth_map`** (`IMAGE`): The normalized depth map used for disparity calculation.
</details>
---
<a id="comfyui-settings-menu-reference"></a>
@@ -340,6 +379,16 @@ Configure options directly under ComfyUI Settings (⚙ gear icon):
- **`Enable TMDB Auto-Scraping`** (`boolean`, *Default: false*): Automatically download media preview images from TMDB.
- **`Enable LoRA Usage Tracking`** (`boolean`, *Default: true*): Toggle LoRA usage counting and visual rank badges (🔥, Gold, Silver, Bronze) in the picker.
- **`Reset Failed Scrapes Cache`** (*Button: `🗑️ Clear Scrapes Cache`*): Clears failed scrape history so Civitai/TMDB can retry downloading missing preview images.
- **`Disable Thumbnail Downscaling (Serve Raw)`** (`boolean`, *Default: false*): Serves full-resolution original preview images instead of generating downscaled WebP thumbnails (downscaled WebP thumbnails render faster in the picker and are recommended).
</details>
<details>
<summary><b>👁️ Live Preview (Floating Latent Dock)</b></summary>
- **`Enable Floating Latent Dock`** (`boolean`, *Default: true*): Adds the floating picture-in-picture Live Latent preview dock (bottom-right corner) plus a canvas toolbar toggle button.
- **`Floating Dock Max Width`** (`slider`, *Default: 280*, 1px steps): Maximum dock width box in pixels (100–2000). Drag the dock's top-left corner to set a free-form width×height box; the dragged dimensions are saved back into this setting, and the dock then snaps to the exact latent aspect ratio without distortion.
- **`Floating Dock Max Height`** (`slider`, *Default: 280*, 1px steps): Maximum dock height box in pixels (100–2000). Drag the dock's top-left corner to set a free-form width×height box; the dragged dimensions are saved back into this setting, and the dock then snaps to the exact latent aspect ratio without distortion.
- **`Auto-Hide Dock When Idle`** (`boolean`, *Default: false*): Hides the dock while idle and reveals it automatically when sampling begins.
</details>
<details>
@@ -367,12 +416,13 @@ Configure options directly under ComfyUI Settings (⚙ gear icon):
- **`Toolbar Button Paused Color`** (`text`, *Default: `#ea580c`*): Hex color for the toolbar paused state.
- **`Enable System Tray Icon`** (`boolean`, *Default: false*): Displays an OS system tray icon with real-time queue status colors and outside-browser controls.
- **`Allow Process Management (Restart / Shutdown)`** (`boolean`, *Default: false*): Opt-in authorization allowing server restart and shutdown actions from the SaturnNodes power controls. Disabled by default for maximum security.
- **`Visible Queue Items (Height)`** (`slider`, *Default: automatic per-monitor*, 1px steps, 0–1200): Limits the visible height of the queue overlay panel in pixels (`0` = native). The overlay's bottom edge can also be dragged directly on screen; sizes are remembered per monitor.
</details>
<details>
<summary><b>💾 Persistent Queue</b></summary>
- **`Persistent Queue (Auto-Recovery)`** (`boolean`, *Default: true*): Automatically saves unfinished queue items and restores them after restart/crash.
- **`Enable Persistent Queue (Auto-Recovery)`** (`boolean`, *Default: true*): Automatically saves unfinished queue items and restores them after restart/crash.
- **`Recovery Launch State`** (`combo`, *Default: `Match Default`*): Override launch state when restored queue items are recovered on startup (`Match Default`, `Force Paused`, `Force Running`).
</details>
@@ -407,32 +457,51 @@ Configure options directly under ComfyUI Settings (⚙ gear icon):
- **Strict Confinement**: Execution is strictly limited to the `ComfyUI/scripts/` directory. Absolute paths and directory traversal (`..`) are permanently blocked.
</details>
<details>
<summary><b>🧩 Node Management</b></summary>
- One enable/disable toggle per SaturnNodes node (e.g. `Loaders / LoRA Loader (Folder)`, `Utils / Prompt Counter`): hides individual nodes from the node search menu. Disabled nodes remain registered, so existing workflows keep loading unchanged — they are only hidden from the Add Node menu (requires a server restart to take effect).
</details>
---
## 🔒 Security & Privacy
For the comprehensive engineering standard, threat model, and review precedents enforced by the ComfyUI-Manager maintainers, see the full **[ComfyUI Custom Node Security & Compliance Rulebook](SECURITY_AUDIT_PLAYBOOK.md)**.
- **Local Runner Sandbox & Operator Authorization Gate:** The `Run Local File` node enforces single-use interactive operator authorization (`⚡ Authorize Run (5 min)`), strictly confines execution to `ComfyUI/scripts/`, never uses `shell=True`, terminates whole process trees on timeout or cancellation, and **never persists authorization inside workflow JSON or image metadata**.
- **CSRF Defense & Fetch Metadata Validation:** All administrative endpoints (`/saturnnodes/settings`, `/saturnnodes/power/*`, `/saturnnodes/local_runner/*`, `/saturnnodes/scrapes/clear` and backward-compatible `/leafflow/*` aliases) enforce loopback checks, `Sec-Fetch-Site` header checks (blocking cross-site requests from visited web pages), and cryptographic per-session `X-SaturnNodes-CSRF-Token` headers.
- **CSRF Defense & Fetch Metadata Validation:** All administrative endpoints (`/saturnnodes/settings`, `/saturnnodes/power/*`, `/saturnnodes/local_runner/*`, `/saturnnodes/scrapes/clear`, `/saturnnodes/pause_queue/*`, `/saturnnodes/persistent_queue/*`, `/saturnnodes/image_loader/*`, `/saturnnodes/folder_lora_loader/*`) enforce loopback checks, `Sec-Fetch-Site` header checks (blocking cross-site requests from visited web pages), and cryptographic per-session `X-SaturnNodes-CSRF-Token` headers.
- **Two-Step Ephemeral Ticket Handshake for Power Actions:** Process restart and shutdown controls are disabled by default (`ALLOW_PROCESS_MANAGEMENT=false`), require CSRF authentication, and execute only after a single-use 30-second ephemeral ticket confirmation handshake.
- **Universal Loopback Protection:** All administrative and queue endpoints strictly verify loopback origin (`127.0.0.1` / `::1`), rejecting external network requests with `403 Forbidden`.
- **Directory Traversal Protection:** Image loading and thumbnail routes are strictly confined to ComfyUI `input`, `output`, and `temp` directories with traversal guards.
- **Optional Headless Dependencies:** System tray desktop integration (`pystray`) is an optional dependency, ensuring cloud containers (Docker, Colab, RunPod) run with zero dependency errors.
- **Opt-In Scraping:** Civitai and TMDB network scraping are opt-in and disabled by default.
- **Zero Runtime Package Installs:** No `install.py` or dynamic `pip` execution; all standard dependencies are cleanly declared in `requirements.txt`.
- **Local Environment:** All API keys and settings are stored locally in `.env` inside `user/default/SaturnNodes/` (auto-migrated from legacy `LeafFlow/` folder if present).
- **Local Environment:** All API keys and settings are stored locally in `.env` inside `user/default/SaturnNodes/`.
- **Atomic File Writes:** Safe atomic writes (`.tmp` + `os.replace`) prevent JSON corruption during sudden crashes.
---
## 🚀 Installation & Setup
**Option A — ComfyUI Manager / Registry (recommended):**
1. Open ComfyUI Manager → **Install Custom Nodes** and search for `SaturnNodes`, or run:
```bash
comfy node install saturnnodes
```
2. Restart ComfyUI.
**Option B — Manual (git clone):**
1. Open your terminal and navigate to your ComfyUI `custom_nodes` directory:
```bash
cd ComfyUI/custom_nodes
git clone https://github.com/KOFiblto/ComfyUI-SaturnNodes.git
```
2. Restart ComfyUI.
3. Open ComfyUI Settings (⚙ gear menu) to configure API keys or feature toggles if desired.
**After install (either option):** open ComfyUI Settings (⚙ gear menu) to configure API keys or feature toggles if desired, and see the [Complete Walkthrough](WALKTHROUGH.md) for usage recipes.
---
+2 -2
View File
@@ -15,11 +15,11 @@ Instead, please report security vulnerabilities directly to the maintainer via G
## Security Architecture & Best Practices
- **CSRF Defense & Fetch Metadata Validation**: All administrative endpoints (`/saturnnodes/*`, `/leafflow/*`) enforce multi-layer CSRF protection via `is_authenticated_local_request(request)`.
- **CSRF Defense & Fetch Metadata Validation**: All administrative endpoints under `/saturnnodes/*` enforce multi-layer CSRF protection via `is_authenticated_local_request(request)`.
- Enforces loopback origin checks (`127.0.0.1` / `::1`), rejecting remote calls with `403 Forbidden`.
- Rejects `cross-site` requests via `Sec-Fetch-Site` header checks, preventing external malicious web pages visited by the operator from triggering actions.
- Verifies `Origin` and `Referer` headers against loopback hostnames.
- Requires cryptographically random session tokens in the `X-SaturnNodes-CSRF-Token` / `X-LeafFlow-CSRF-Token` header (`secrets.compare_digest`), prompting CORS preflight rejection if an external origin attempts unauthorized requests.
- Requires cryptographically random session tokens in the `X-SaturnNodes-CSRF-Token` header (`secrets.compare_digest`), prompting CORS preflight rejection if an external origin attempts unauthorized requests.
- **Two-Step Ephemeral Ticket Handshake for Power Actions**:
- Server restart and shutdown endpoints require `ALLOW_PROCESS_MANAGEMENT=true` in settings.
- Execution requires a two-step handshake: the client requests a single-use ephemeral ticket (`POST /saturnnodes/power/request_token`) valid for 30 seconds.
+394 -128
View File
@@ -1,169 +1,435 @@
# 🛡️ ComfyUI Node Security Audit Playbook
*A Repeatable, Step-by-Step Security Review & Conformance Framework for ComfyUI Custom Node Developers and Auditors.*
# 🛡️ ComfyUI Custom Node Security, Compliance & Architecture Rulebook
*The Authoritative Engineering Standard & Audit Playbook Derived from ComfyUI-Manager PR #3200 Review Precedents*
---
## 🎯 The Core Philosophy & Threat Model
> **The Golden Rule (by @ltdrdata, ComfyUI-Manager maintainer):**
> *"Treat every input, widget values included, as attacker-controlled, because it can come from a shared workflow or a direct `/prompt` call."*
### Why ComfyUI Nodes Require a Hostile Threat Model
1. **Shared Workflow Vectors:** ComfyUI workflows are routinely shared across the internet as `.json` files or embedded inside `.png` image metadata (on Civitai, Reddit, Discord, GitHub).
2. **Zero-Interaction Poisoning:** When a user drags and drops a contaminated image or loads a workflow JSON, widget values are immediately populated with whatever data the author specified.
3. **Headless & API Execution:** Malicious payloads can be sent directly to the local server via `POST /prompt` without any UI interaction.
4. **Local Host Privileges:** ComfyUI runs with the full local privileges of the host user account. Any vulnerability can lead to Remote Code Execution (RCE), arbitrary file deletion, or sensitive data theft.
## 📑 Table of Contents
1. [Core Threat Model & The Golden Rule](#1-core-threat-model--the-golden-rule)
2. [Case Study: ComfyUI-Manager PR #3200 Review Precedents](#2-case-study-comfyui-manager-pr-3200-review-precedents)
3. [The 8 Core Security Rules (With Code Examples)](#3-the-8-core-security-rules)
- [Rule 1: Filesystem Confinement & Traversal Prevention](#rule-1-filesystem-confinement--traversal-prevention)
- [Rule 2: Destructive File Actions & Deletion Guards](#rule-2-destructive-file-actions--deletion-guards)
- [Rule 3: Process Execution & The Workflow Serialization Trap](#rule-3-process-execution--the-workflow-serialization-trap)
- [Rule 4: Dynamic Code Evaluation & Deserialization](#rule-4-dynamic-code-evaluation--deserialization)
- [Rule 5: Web Endpoints & The Same-Machine Browser Fallacy (CSRF)](#rule-5-web-endpoints--the-same-machine-browser-fallacy-csrf)
- [Rule 6: Two-Step Ephemeral Ticket Handshakes for Power Actions](#rule-6-two-step-ephemeral-ticket-handshakes-for-power-actions)
- [Rule 7: Outbound Network Requests & SSRF Prevention](#rule-7-outbound-network-requests--ssrf-prevention)
- [Rule 8: Configuration Storage, Isolation & Injection Defense](#rule-8-configuration-storage-isolation--injection-defense)
4. [Ecosystem & Registry Packaging Compliance](#4-ecosystem--registry-packaging-compliance)
- [Rule 9: Zero Runtime Package Installations (`install.py` Prohibition)](#rule-9-zero-runtime-package-installations-installpy-prohibition)
- [Rule 10: PyTorch Exclusion from Dependencies](#rule-10-pytorch-exclusion-from-dependencies)
- [Rule 11: Headless & Cloud Container Resilience](#rule-11-headless--cloud-container-resilience)
- [Rule 12: Core Monkey-Patching Isolation](#rule-12-core-monkey-patching-isolation)
5. [Frontend Hygiene & Canvas Safety](#5-frontend-hygiene--canvas-safety)
- [Rule 13: Dual Frontend Architecture (V1 LiteGraph & V2 Vue UI)](#rule-13-dual-frontend-architecture-v1-litegraph--v2-vue-ui)
- [Rule 14: Canvas Resize Loops (`computeSize` & `node.size`)](#rule-14-canvas-resize-loops-computesize--nodesize)
- [Rule 15: Non-Serialized UI Widgets (`{ serialize: false }`)](#rule-15-non-serialized-ui-widgets--serialize-false-)
6. [Auditor & Maintainer Quick Conformance Matrix](#6-auditor--maintainer-quick-conformance-matrix)
---
## 📋 The 4-Phase Security Audit Checklist
## 1. Core Threat Model & The Golden Rule
When auditing a new or existing custom node pack, execute the following four phases step by step.
### 1.1 The Golden Rule
> **"Treat every input, widget values included, as attacker-controlled, because it can come from a shared workflow or a direct `/prompt` call."**
> — *ltdrdata (ComfyUI-Manager Lead Maintainer, Comfy-Org)*
### 1.2 The 4 Attack Vectors Unique to ComfyUI
1. **Shared Workflow Vectors (.json & PNG Metadata):**
ComfyUI workflows are freely shared across community hubs (Civitai, Reddit, Discord, GitHub) as raw JSON files or embedded inside PNG image generation metadata. Loading a poisoned image instantly sets all node widgets on the canvas.
2. **The Same-Machine Browser Exploit (Drive-by Localhost CSRF):**
Any website an operator visits in their regular browser can execute background JavaScript (`fetch('http://localhost:8188/...')`). Because this request originates from the operator's local computer, primitive IP loopback checks (`127.0.0.1`) pass automatically unless strict fetch metadata and CSRF headers are validated.
3. **Direct Headless API Injection (`POST /prompt`):**
Attackers or automated scripts can bypass the graphical interface completely by sending malicious graph specifications directly to the server's `/prompt` endpoint.
4. **Host User Privileges:**
ComfyUI processes run with the full security privileges of the logged-in operating system user. Any sandbox breakout, unchecked script runner, or arbitrary file deletion results in immediate compromise of personal files or host systems.
---
### Phase 1: Node-by-Node Audit Matrix (The 7 Vector Checklist)
## 2. Case Study: ComfyUI-Manager PR #3200 Review Precedents
Repeat this checklist for **every single custom node** in `NODE_CLASS_MAPPINGS`.
During the official registration of **`ComfyUI-SaturnNodes`** in [Comfy-Org/ComfyUI-Manager#3200](https://github.com/Comfy-Org/ComfyUI-Manager/pull/3200), lead maintainer `@ltdrdata` conducted a three-phase security review. This exchange set definitive precedents for all modern custom nodes:
#### 1.1 Filesystem Paths & Directory Traversal
* [ ] **No Unchecked Absolute Paths:** Does the node accept file or folder paths as input strings?
- Absolute paths (e.g. `C:\`, `/etc/`, `\\server\share`) must be strictly rejected unless explicitly intended and approved.
- Windows drive letter patterns (`^[A-Za-z]:`) and UNC paths (`^//`, `^\\\\`) must be blocked.
* [ ] **No Directory Traversal (`..`):** Does the node reject any path segment containing `..`?
* [ ] **Canonical Path Confinement via `commonpath`:**
- Are paths resolved to canonical real paths using `os.path.realpath`?
- Are resolved paths checked against an authorized base directory using `os.path.commonpath`?
```python
real_base = os.path.realpath(allowed_base)
real_target = os.path.realpath(target_path)
if os.path.commonpath([real_base, real_target]) != real_base:
raise ValueError("Directory traversal attempt detected.")
```
* [ ] **Confined Base Directories:** Are file reads and writes confined strictly to approved ComfyUI folders (`input/`, `output/`, `temp/`, or `models/`)?
### Round 1: Unauthenticated Power Routes & Arbitrary File Reads
* **Maintainer Finding:** Exposing network routes that restart/shutdown the server, stream files by absolute path, or write to `.env` without access controls is strictly forbidden.
* **Precedent:** File reads must be confined to fixed base directories. Power management and settings routes must be local-only and strictly constrained.
#### 1.2 Destructive Actions (Deletions, Writes, Overwrites)
* [ ] **Safe Deletion Guards:** If the node contains `os.remove`, `os.unlink`, or `shutil.rmtree`:
- Is file deletion strictly confined to `input/` or `output/`?
- Does the node refuse to delete files outside the confined sandbox, even if a manipulated path is provided?
- Does the deletion toggle default to `False`?
* [ ] **Atomic File Writes:** When writing JSON, cache, or state files, are writes executed atomically via temporary files (`.tmp` + `os.replace`) to prevent corruption during unexpected shutdowns?
* [ ] **Read-Only Filesystem Defense:** Are disk writes wrapped in `try / except (PermissionError, OSError)` with graceful logging to prevent server crashes on read-only Docker/network mounts?
### Round 2: The Same-Machine Fallacy & The Workflow Serialization Trap
* **Maintainer Finding:**
1. *Same-Machine Check Failure:* A basic IP loopback check (`request.remote == "127.0.0.1"`) is insufficient. Any open browser tab makes requests from `localhost`, allowing malicious web pages to trigger restarts, shutdowns, or settings changes.
2. *Escape Hatches Forbidden:* Settings toggles such as `ALLOW_ANY_SCRIPT_PATH` that bypass folder confinement must be completely removed.
3. *In-Workflow Consent Fallacy:* A `security_consent` boolean widget in `INPUT_TYPES` defaults to `False` in code, but a shared malicious workflow arrives with `security_consent: True` already serialized. Execution consent must never travel with the graph.
* **Precedent:**
- Routes must validate `Sec-Fetch-Site` (blocking `cross-site`) and verify cryptographic CSRF tokens.
- Process execution must require interactive, in-memory human authorization on the canvas node via an ephemeral RAM token.
#### 1.3 Command & Process Execution
* [ ] **Never Use `shell=True`:** Are all subprocess calls executed with `shell=False` and tokenized argument lists (`shlex.split` or list of strings)?
* [ ] **Strict Executable Confinement:** Are scripts or binaries restricted strictly to a dedicated directory (e.g., `ComfyUI/scripts/`)?
* [ ] **In-Memory Operator Authorization Gate:**
- Can script execution consent travel inside workflow JSON or image metadata? (Answer must be **NO**).
- Does execution require an interactive, in-memory user action on the canvas node (e.g. `[⚡ Authorize Run]` with an ephemeral RAM token) before queueing?
* [ ] **Master Safety Switch:** Is local script/process execution disabled by default in settings (`ENABLE_LOCAL_FILE_EXECUTION = False`)?
* [ ] **Process Tree Termination & Timeouts:** Do subprocesses enforce strict execution timeouts and clean process-tree termination on user cancellation?
#### 1.4 Dynamic Code Evaluation
* [ ] **Zero `eval()` or `exec()` on Inputs:** Does the node evaluate mathematical expressions, conditions, or strings using Python's `eval()` or `exec()`?
- `eval()` and `exec()` on widget inputs represent instantaneous Remote Code Execution (RCE).
- Use safe AST parsers (such as `ast.literal_eval` or custom math parsers) instead.
* [ ] **No Dynamic Imports from Input Strings:** Does the node invoke `__import__` or `importlib.import_module` using user-supplied module names?
#### 1.5 Outbound Network Requests & SSRF
* [ ] **Strict Protocol Validation:** Do web requests (e.g. preview scrapers, API fetchers) strictly require `https://` or `http://`? (`file://`, `ftp://`, `gopher://` must be rejected).
* [ ] **Internal Network & Loopback Blocking:**
- Are requests to `127.0.0.1`, `localhost`, `::1`, and `0.0.0.0` blocked?
- Are private IPv4/IPv6 ranges blocked (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`)?
- Are cloud metadata services blocked (`169.254.169.254` on AWS/GCP/Azure)?
* [ ] **Opt-In Network Activity:** Are external web scraping or API features disabled by default, requiring explicit user activation?
#### 1.6 Regular Expression DoS (ReDoS) & Input Validation
* [ ] **Regex Error Handling:** Are user-provided regular expressions wrapped in `try / except re.error` with a safe fallback to prevent unhandled crashes?
* [ ] **Catastrophic Backtracking Defense:** Are regex patterns inspected for exponential backtracking vulnerability (e.g. `(a+)+$`)?
* [ ] **String Splitting Delimiters:** When parsing delimited inputs (e.g. CSV find/replace targets), does the parser handle quoted strings containing delimiters without fragmentation?
#### 1.7 Resource Exhaustion & Memory Allocation
* [ ] **Bounded Iteration:** Do loop nodes (e.g. batch iterators, queue steppers) enforce sane upper bounds to prevent infinite loops?
* [ ] **Image Dimension Clamping:** Are image dimensions, aspect ratio scalers, and tensor buffers validated to prevent out-of-memory (OOM) allocation bombs?
### Round 3: Folder Deletion Sandbox Bypass
* **Maintainer Finding:** `sanitize_folder_path` allowed relative paths (`..`) and absolute paths. In a folder watcher node with an optional `delete_image` flag, an attacker could supply `folder: "C:/Windows"` or `../../` and delete arbitrary user files.
* **Precedent:** All path-handling functions must reject absolute paths, reject `..`, and verify canonical containment against approved ComfyUI directories using `os.path.commonpath`.
---
### Phase 2: Administrative Endpoints & Web Routes Review
## 3. The 8 Core Security Rules
Examine all routes registered via `PromptServer.instance.app.routes` in `__init__.py` or route handlers.
### Rule 1: Filesystem Confinement & Traversal Prevention
#### 2.1 Loopback Origin Enforcement (`is_local_request`)
* [ ] **Local-Only Verification:** Do sensitive endpoints check the client's peer IP address and reject non-loopback connections (`127.0.0.1` / `::1`) with `403 Forbidden`?
Nodes must never read, write, or list files outside designated ComfyUI directories (`input/`, `output/`, `temp/`, and `models/`).
#### 2.2 Cross-Site Request Forgery (CSRF) & Fetch Metadata
* [ ] **Same-Machine Browser Exploit Defense:** A local-only IP check is insufficient on its own because any malicious website visited by the user in another browser tab makes requests from `localhost`!
* [ ] **`Sec-Fetch-Site` Validation:** Does the route inspect the browser-enforced `Sec-Fetch-Site` header and reject `cross-site` calls?
* [ ] **Origin / Referer Validation:** Does the route verify that `Origin` or `Referer` matches the ComfyUI host?
* [ ] **Cryptographic Session CSRF Token:** Do state-mutating `POST` endpoints require a session token header (e.g. `X-CSRF-Token`) generated on server startup?
#### ❌ Non-Compliant Patterns
```python
# VULNERABLE: Accepts arbitrary absolute paths or directory traversal
def load_image(self, folder, filename):
filepath = os.path.join(folder, filename)
with open(filepath, "rb") as f: # Attacker loads C:\Users\user\.ssh\id_rsa
return f.read()
```
#### 2.3 Two-Step Ephemeral Ticket Handshakes for High-Impact Actions
* [ ] **Destructive Action Isolation:** Are high-impact administrative actions (server restart, shutdown, mass cache wipe) separated into a two-step handshake?
1. `POST /request_token`: Client requests a single-use token stored in server RAM with a short TTL (30 seconds).
2. `POST /confirm_action`: Client presents the single-use token to execute the action.
* [ ] **Default Disabled:** Are server management features disabled by default in settings (`ALLOW_PROCESS_MANAGEMENT = False`)?
#### ✅ Compliant Pattern
```python
import os
import re
def sanitize_folder_path(folder_input: str, allowed_base_dir: str) -> str:
"""
Strictly confines a folder to an allowed base directory.
Rejects absolute paths, drive letters, UNC shares, and parent traversal.
"""
if not folder_input or not folder_input.strip():
return allowed_base_dir
raw_path = folder_input.strip()
# Reject Windows drive letters (C:) and UNC network paths (// or \\)
if re.match(r'^[A-Za-z]:', raw_path) or raw_path.startswith(("\\\\", "//")):
raise ValueError(f"Absolute or network paths are forbidden: {raw_path}")
# Reject root slashes and directory traversal
if raw_path.startswith(("/", "\\")) or ".." in raw_path.replace("\\", "/").split("/"):
raise ValueError(f"Directory traversal sequences are forbidden: {raw_path}")
# Canonicalize and verify commonpath boundary
canonical_base = os.path.realpath(allowed_base_dir)
target_path = os.path.realpath(os.path.join(canonical_base, raw_path))
if os.path.commonpath([canonical_base, target_path]) != canonical_base:
raise ValueError(f"Path escapes allowed sandbox: {target_path}")
return target_path
```
---
### Phase 3: Settings & Persistent Configuration Review
### Rule 2: Destructive File Actions & Deletion Guards
Inspect how preferences, credentials, and states are stored.
Any node that deletes or overwrites files (`os.remove`, `os.unlink`, `shutil.rmtree`) must verify containment immediately prior to invocation.
#### 3.1 Safe Directory Isolation
* [ ] **Centralized Data Directory:** Are user data and settings stored in `ComfyUI/user/default/<PackName>/` rather than cluttering root or writing to random system paths?
* [ ] **No Secret Tracking in Git:** Are `.env` files, API keys, and local state files strictly added to `.gitignore`?
* [ ] **Log Masking:** Are secret keys (e.g. Civitai API keys, TMDB tokens) masked (`***` or truncated) when output to server logs?
#### ❌ Non-Compliant Patterns
```python
# VULNERABLE: Trusting earlier sanitization or allowing unverified deletion
def cleanup_cache(self, user_supplied_path):
if os.path.exists(user_supplied_path):
os.remove(user_supplied_path) # Arbitrary file deletion
```
#### 3.2 Configuration File Injection Defense
* [ ] **Newline Injection Defense:** When writing `.env` or configuration key-value pairs, are keys and values sanitized against `\r` and `\n` to prevent config poisoning?
#### ✅ Compliant Pattern
```python
def safe_delete_image(target_file_path: str, allowed_folders: list[str]) -> bool:
"""
Verifies target file is strictly inside input/output before deletion.
"""
real_target = os.path.realpath(target_file_path)
if not os.path.isfile(real_target):
return False
is_confined = any(
os.path.commonpath([os.path.realpath(base), real_target]) == os.path.realpath(base)
for base in allowed_folders
)
if not is_confined:
raise PermissionError(f"Security Violation: Refusing to delete file outside sandbox: {real_target}")
os.remove(real_target)
return True
```
---
### Phase 4: ComfyUI Ecosystem & Registry Compliance
### Rule 3: Process Execution & The Workflow Serialization Trap
Review package structure against the official Comfy-Org registry and ComfyUI-Manager requirements.
Executing external binaries or scripts is high risk. You must adhere to the following principles:
#### 4.1 Packaging & Dependency Standards
* [ ] **No `install.py`:** Is `install.py` completely eliminated? (Comfy-Org prohibits `install.py` executing `pip install` subprocesses on startup).
* [ ] **Transparent `requirements.txt` & `pyproject.toml`:** Are dependencies clearly declared with standard version constraints?
* [ ] **No PyTorch in Dependencies:** Is `"torch"` omitted from `requirements.txt` / `pyproject.toml` dependencies? (ComfyUI manages its own PyTorch/CUDA environment).
* [ ] **Optional Headless Dependencies:** Are GUI-dependent packages (like system tray `pystray`) made optional or headless-tolerant so cloud containers (Docker, RunPod, Colab) boot cleanly?
1. **The Workflow Serialization Trap:** Never include an authorization checkbox (e.g. `"security_consent": ("BOOLEAN", {"default": False})`) in `INPUT_TYPES`. Attackers distribute workflows with `"security_consent": True` already serialized.
2. **Ephemeral RAM Authorization:** Authorization must occur via an in-memory session token generated when the user physically clicks a canvas UI button (e.g. `[⚡ Authorize Run]`).
3. **Execution Confinement:** Scripts must reside strictly within a dedicated directory (e.g., `ComfyUI/scripts/`).
4. **Never Use `shell=True`:** Always tokenize arguments (`shlex.split` or list) and execute with `shell=False`.
#### 4.2 Frontend Compatibility & Widget Serialization
* [ ] **Dual Frontend Support:** Does the node suite function cleanly on both **Frontend V1 (LiteGraph)** and **Frontend V2 (Vue UI)**?
* [ ] **No Canvas Runaway Loops:** Do custom DOM widgets avoid overriding `computeSize()` with formulas tied to `node.size[1]`, which triggers infinite downward expansion in LiteGraph?
* [ ] **Serialization Hygiene:** Are UI-only preview badges and widgets explicitly marked `{ serialize: false }` to avoid polluting saved workflow JSON?
#### ❌ Non-Compliant Patterns
```python
# VULNERABLE: shell=True, arbitrary paths, and consent stored in workflow JSON
class VulnerableRunner:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"command": ("STRING", {"default": "python script.py"}),
"user_consent": ("BOOLEAN", {"default": False}), # Poisoned via JSON!
}
}
def run(self, command, user_consent):
if user_consent:
subprocess.Popen(command, shell=True) # Remote Code Execution
```
#### 4.3 Core Monkey-Patching Isolation
* [ ] **Conditional Patching:** If the node pack overrides any core ComfyUI server or queue functions (e.g. `PromptQueue`), is the patch completely bypassed when the feature toggle is disabled?
#### ✅ Compliant Pattern
```python
import subprocess
import shlex
import time
import os
# Stored strictly in volatile Python memory (RAM), never serialized to disk
ACTIVE_RUN_AUTHORIZATIONS: dict[str, float] = {}
def authorize_node_execution(node_id: str, ttl_seconds: int = 300) -> str:
"""Invoked only by interactive UI button via authenticated CSRF route."""
token = os.urandom(16).hex()
ACTIVE_RUN_AUTHORIZATIONS[node_id] = time.time() + ttl_seconds
return token
def execute_confined_script(script_name: str, args_list: list[str], node_id: str, scripts_dir: str):
# 1. Verify in-memory authorization
expiry = ACTIVE_RUN_AUTHORIZATIONS.pop(node_id, 0)
if time.time() > expiry:
raise PermissionError("Execution denied: Interactive operator authorization required on canvas.")
# 2. Confine target executable to scripts/ directory
real_scripts_base = os.path.realpath(scripts_dir)
target_script = os.path.realpath(os.path.join(real_scripts_base, script_name))
if os.path.commonpath([real_scripts_base, target_script]) != real_scripts_base:
raise ValueError("Script escape detected.")
if not os.path.isfile(target_script):
raise FileNotFoundError(f"Script not found: {script_name}")
# 3. Safe execution with shell=False
cmd = ["python", target_script] + args_list
proc = subprocess.Popen(
cmd,
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
return proc.communicate(timeout=60)
```
---
## 🔍 Rapid Audit Checklist Matrix
### Rule 4: Dynamic Code Evaluation & Deserialization
Use this quick scorecard when reviewing a custom node pack:
Never pass widget string inputs into `eval()`, `exec()`, or dynamic `importlib` calls.
| Category | Check | Status |
| :--- | :--- | :---: |
| **Inputs** | Absolute paths rejected | [ ] |
| **Inputs** | Directory traversal (`..`) rejected | [ ] |
| **Inputs** | Path confinement verified with `commonpath` | [ ] |
| **Inputs** | Regex errors caught and handled | [ ] |
| **Execution** | `shell=False` enforced on all subprocesses | [ ] |
| **Execution** | Scripts confined to dedicated directory | [ ] |
| **Execution** | Consent cannot travel in workflow JSON | [ ] |
| **Execution** | In-memory interactive operator authorization | [ ] |
| **Network** | SSRF protection: loopback & private LAN blocked | [ ] |
| **Network** | Protocol restricted to HTTP/HTTPS | [ ] |
| **Network** | Scrapers & network features opt-in | [ ] |
| **Endpoints** | Loopback origin checks on admin routes | [ ] |
| **Endpoints** | `Sec-Fetch-Site` CSRF defense | [ ] |
| **Endpoints** | Ephemeral ticket handshake for power actions | [ ] |
| **Settings** | Dangerous features default to `False` | [ ] |
| **Settings** | Data stored in `user/default/<pack>/` | [ ] |
| **Packaging** | No `install.py` / import-time `pip` | [ ] |
| **Packaging** | Dependencies in `requirements.txt` | [ ] |
| **Frontend** | Clean V1 and V2 compatibility without resize loops | [ ] |
#### ❌ Non-Compliant Patterns
```python
# VULNERABLE: Direct eval allows __import__('os').system('...')
def calculate_aspect(self, formula_string):
return eval(formula_string)
```
#### ✅ Compliant Pattern
```python
import ast
import operator
SAFE_OPERATORS = {
ast.Add: operator.add,
ast.Sub: operator.sub,
ast.Mult: operator.mul,
ast.Div: operator.truediv,
}
def safe_eval_math(expression: str) -> float:
"""Parses mathematical expression using an Abstract Syntax Tree (AST)."""
node = ast.parse(expression, mode='eval').body
def _eval(node):
if isinstance(node, ast.Constant) and isinstance(node.value, (int, float)):
return node.value
if isinstance(node, ast.BinOp) and type(node.op) in SAFE_OPERATORS:
return SAFE_OPERATORS[type(node.op)](_eval(node.left), _eval(node.right))
raise ValueError(f"Unsafe expression: {expression}")
return float(_eval(node))
```
---
*Created for ComfyUI-SaturnNodes to maintain institutional security compliance.*
### Rule 5: Web Endpoints & The Same-Machine Browser Fallacy (CSRF)
Because any malicious web page the operator visits in another tab can target `http://127.0.0.1:8188`, endpoints that mutate state or trigger actions must defend against cross-site requests.
#### Required Multi-Layer Defense:
1. **Loopback IP Verification:** Peer address must be `127.0.0.1`, `::1`, or `localhost`.
2. **Fetch Metadata Inspection:** `Sec-Fetch-Site` header must **not** be `cross-site`.
3. **Cryptographic CSRF Header:** Require a per-session secret token in a custom header (e.g. `X-SaturnNodes-CSRF-Token`). Browsers forbid cross-origin pages from sending custom headers without CORS preflight approval.
#### ✅ Compliant Pattern
```python
import secrets
from aiohttp import web
SESSION_CSRF_TOKEN = secrets.token_hex(32)
def is_authenticated_local_request(request: web.Request) -> bool:
"""
Blocks remote network callers AND malicious cross-site browser requests.
"""
# 1. IP Loopback Check
peername = request.transport.get_extra_info('peername')
client_ip = peername[0] if peername else ""
if client_ip not in ("127.0.0.1", "::1", "localhost"):
return False
# 2. Browser Fetch Metadata Defense (blocks drive-by background fetches)
sec_fetch_site = request.headers.get("Sec-Fetch-Site", "")
if sec_fetch_site in ("cross-site",):
return False
# 3. Custom Header & Secret Verification (triggers CORS preflight rejection)
token = request.headers.get("X-SaturnNodes-CSRF-Token", "")
if not token or not secrets.compare_digest(token, SESSION_CSRF_TOKEN):
return False
return True
```
---
### Rule 6: Two-Step Ephemeral Ticket Handshakes for Power Actions
High-impact administrative actions (restarting ComfyUI, shutting down the host, mass cache purges) must **never** trigger from a single `POST` endpoint.
#### Handshake Protocol:
1. **Disabled by Default:** Master setting `ALLOW_PROCESS_MANAGEMENT = False`.
2. **Step 1 (`POST /power/request_token`):** Server validates local CSRF session, generates a single-use token in RAM with a 30-second TTL, and returns it to the client.
3. **Step 2 (`POST /power/confirm_action`):** Client provides the single-use token. Server validates, burns the token, and schedules the action.
---
### Rule 7: Outbound Network Requests & SSRF Prevention
If your custom node scrapes images, models, or metadata from the internet (Civitai, HuggingFace, TMDB):
1. **Opt-In Only:** Background scraping must be disabled by default in settings.
2. **Protocol Confinement:** Allow only `http://` and `https://`. Reject `file://`, `ftp://`, and `gopher://`.
3. **Private IP & Cloud Metadata Blocking (SSRF):** Reject requests resolving to:
- Loopback: `127.0.0.0/8`, `::1`
- Private LAN: `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`
- Link-Local / Cloud Metadata: `169.254.169.254`
#### ✅ Compliant Pattern
```python
import ipaddress
import socket
from urllib.parse import urlparse
def is_safe_external_url(url: str) -> bool:
try:
parsed = urlparse(url)
if parsed.scheme not in ("http", "https"):
return False
hostname = parsed.hostname
if not hostname:
return False
# Resolve IP and check for private / loopback / metadata ranges
ip_addr = socket.gethostbyname(hostname)
ip = ipaddress.ip_address(ip_addr)
if ip.is_private or ip.is_loopback or ip.is_link_local or ip.is_reserved:
return False
return True
except Exception:
return False
```
---
### Rule 8: Configuration Storage, Isolation & Injection Defense
All user runtime state, custom settings, and caches must be stored cleanly inside ComfyUI's user directory:
`ComfyUI/user/default/<YourCustomNodeName>/`
- **Newline Injection Defense:** When writing to `.env` or config files, strip `\r` and `\n` from both keys and values to prevent setting forgery.
- **Atomic Disk Writes:** Write data to a temporary file (`.tmp`) first, then commit via `os.replace` to prevent corrupted files on unexpected shutdowns.
- **Log Masking:** Strip or mask API keys (`sk-***`, token hashes) in console output.
---
## 4. Ecosystem & Registry Packaging Compliance
To pass automated and manual review in the official ComfyUI Registry and ComfyUI-Manager:
### Rule 9: Zero Runtime Package Installations (`install.py` Prohibition)
- **Prohibited:** Creating an `install.py` script that invokes `subprocess.run(["pip", "install", ...])` during ComfyUI startup.
- **Mandated:** Declare all dependencies cleanly in `requirements.txt` and `pyproject.toml`.
### Rule 10: PyTorch Exclusion from Dependencies
- **Prohibited:** Listing `torch` or `torchvision` in your custom node's `requirements.txt` or `pyproject.toml`.
- **Reason:** ComfyUI manages its own PyTorch/CUDA environment. Specifying `torch` causes pip to downgrade or corrupt the user's CUDA acceleration binaries.
### Rule 11: Headless & Cloud Container Resilience
- If using desktop GUI dependencies (e.g. `pystray` system tray icons, Tkinter windows), wrap imports in `try/except ImportError` and provide silent headless fallbacks so cloud instances (RunPod, Colab, Docker) do not crash on launch.
### Rule 12: Core Monkey-Patching Isolation
- If overriding core ComfyUI objects (such as `PromptQueue`), the monkey-patch must be conditionally executed **only** if the corresponding feature flag is enabled in settings. If the user disables the feature, core classes must remain untouched.
---
## 5. Frontend Hygiene & Canvas Safety
### Rule 13: Dual Frontend Architecture (V1 LiteGraph & V2 Vue UI)
- All custom UI extensions must verify compatibility with both the classic LiteGraph canvas and the modern ComfyUI Vue V2 interface.
- In hooks (`nodeCreated`, `beforeRegisterNodeDef`), verify both `node.comfyClass` and `node.type`.
### Rule 14: Canvas Resize Loops (`computeSize` & `node.size`)
- Never compute widget heights dynamically based on `this.size[1]` inside `computeSize()`. In LiteGraph, this creates an infinite resize loop where the node expands downwards continuously on every draw frame.
### Rule 15: Non-Serialized UI Widgets (`{ serialize: false }`)
- Dynamic preview widgets, action buttons, ranking badges, and status labels must be configured with:
```javascript
widget.serialize = false;
// or widget.options = { serialize: false };
```
This prevents transient UI states from cluttering the user's saved workflow JSON.
---
## 6. Auditor & Maintainer Quick Conformance Matrix
Use this matrix when auditing your own or third-party ComfyUI custom nodes:
| Domain | Mandatory Security Requirement | Verification Method |
| :--- | :--- | :--- |
| **Filesystem** | Absolute paths (`C:`, `/`, `\\`) rejected | Test with `C:\Windows\System32` & `/etc/passwd` |
| **Filesystem** | Directory traversal (`..`) rejected | Test with `../../` |
| **Filesystem** | Canonical path confinement via `commonpath` | Verify `commonpath([base, target]) == base` |
| **Deletion** | Deletions strictly confined to `input/` and `output/` | Verify boundary check immediately before `os.remove` |
| **Execution** | `shell=False` enforced on all subprocesses | Inspect all `subprocess.Popen` / `subprocess.run` calls |
| **Execution** | Scripts confined strictly to `ComfyUI/scripts/` | Verify realpath check against scripts directory |
| **Execution** | Execution consent **absent** from `INPUT_TYPES` | Verify no authorization widgets in workflow JSON |
| **Execution** | In-memory interactive operator authorization | Confirm single-use RAM token generated via UI button |
| **Network** | Loopback checks on administrative routes | Test request from non-local IP (expects 403) |
| **Network** | CSRF defense: `Sec-Fetch-Site` + custom token header | Test request with `Sec-Fetch-Site: cross-site` |
| **Network** | Two-step ephemeral ticket for restart/shutdown | Verify token generation + confirmation handshake |
| **Network** | SSRF: Private IPs & cloud metadata blocked | Test with `127.0.0.1`, `192.168.1.1`, `169.254.169.254` |
| **Network** | Scraping features opt-in (disabled by default) | Verify settings default to `false` |
| **Packaging** | No `install.py` / dynamic pip execution | Verify absence of `install.py` |
| **Packaging** | `torch` excluded from `requirements.txt` | Verify dependencies list |
| **Data** | Data stored in `user/default/<pack>/` | Inspect state and cache file paths |
| **Frontend** | UI widgets marked `{ serialize: false }` | Inspect exported workflow JSON for UI clutter |
---
*Maintained under the ComfyUI-SaturnNodes security framework. Conforms strictly to Comfy-Org registry audit policies.*
+32 -30
View File
@@ -1,6 +1,6 @@
# 🍃 ComfyUI-LeafFlow Complete Walkthrough
# 🪐 ComfyUI-SaturnNodes Complete Walkthrough
Welcome to the full guide for ComfyUI-LeafFlow! This custom node suite is designed to give you unprecedented control over your generations, visual asset management, and queue resilience.
Welcome to the full guide for ComfyUI-SaturnNodes! This custom node suite is designed to give you unprecedented control over your generations, visual asset management, and queue resilience.
This walkthrough covers everything from basic setup to advanced workflows across both the new ComfyUI V2 (Vue) and the classic ComfyUI (LiteGraph).
@@ -9,7 +9,7 @@ This walkthrough covers everything from basic setup to advanced workflows across
## 1. Global Features
### The Pause Queue Toolbar
Upon installing the extension, you will notice a new **Green/Orange Pause Button** nestled next to your standard "Queue Prompt" button.
Upon installing the extension, you will notice a new **Green/Orange Pause Button** nestled next to your standard "Queue Prompt" button.
- **Green (Running)**: ComfyUI operates normally.
- **Orange (Pausing/Paused)**: ComfyUI is holding the queue.
@@ -19,8 +19,8 @@ You have two pause modes, accessible by clicking the small dropdown arrow next t
### The System Tray Icon (Outside-Browser Queue Control)
Want to check your queue status or pause/resume generations while working in other apps (Photoshop, Blender, games) without opening ComfyUI in your browser?
1. Open ComfyUI Settings (⚙️ gear icon) and enable **🍃 LeafFlow: Enable System Tray Icon** (or set `ENABLE_TRAY_ICON=true` in `.env`).
2. LeafFlow will spawn an OS system tray icon in your Windows/macOS/Linux taskbar notification area:
1. Open ComfyUI Settings (⚙️ gear icon) and enable **`Enable System Tray Icon`** (search for `SaturnNodes` in the settings search box, or set `ENABLE_TRAY_ICON=true` in `ComfyUI/user/default/SaturnNodes/.env`).
2. SaturnNodes will spawn an OS system tray icon in your Windows/macOS/Linux taskbar notification area:
- **Green Icon (❚❚)**: Indicates ComfyUI queue is actively running.
- **Orange Icon (▶)**: Indicates ComfyUI queue is paused and waiting for you to continue.
- **Orange Icon (❚❚)**: Indicates ComfyUI is in the middle of a generation and will pause as soon as the active workflow/node finishes.
@@ -28,72 +28,73 @@ Want to check your queue status or pause/resume generations while working in oth
4. Right-click the tray icon to choose explicit actions: **Pause (Finish)**, **Pause (Instant)**, **Continue / Resume**, switch default pause modes, or quickly **Open ComfyUI in Browser**.
### The 1D Git-Graph Batch Queue Visualizer
LeafFlow automatically tracks which workflows are submitted together as a batch (whether through "Batch count" or sequential submission) and renders a clean, purely graphical 1D git-graph line directly to the left of your queued items in the queue list:
SaturnNodes automatically tracks which workflows are submitted together as a batch (whether through "Batch count" or sequential submission) and renders a clean, purely graphical 1D git-graph line directly to the left of your queued items in the queue list:
- **36 High-Contrast Cycling Colors**: Every new batch gets a distinct color from an accessible 36-color sequence so adjacent batches are visually distinguishable at a glance.
- **Purely Graphical (No Clutter)**: No numbers or text labels.
- **Purely Graphical (No Clutter)**: No numbers or text labels.
- **Batch Start (`┌`)**: The top of the line curves inward towards the card and runs straight down.
- **Batch Middle (`│`)**: Seamless, continuous straight vertical line.
- **Batch End (`└`)**: Runs straight from above and curves inward towards the card at the bottom.
- **Single Item (`(`)**: A standalone 1-item batch curves inward at both top and bottom like a bracket.
- **In-between Infiltration**: If you use "Queue Front" or insert another prompt between items of an active batch, the original batch maintains its open ends (no false start/end curves), while the inserted prompt is enclosed in its own bracket.
- **Works Standalone or with PersistentQueue**: Runs locally via `localStorage`, and synchronizes with `PersistentQueue` so batch groupings survive server restarts.
- **Works Standalone or with Persistent Queue**: Runs locally via `localStorage`, and synchronizes with the Persistent Queue so batch groupings survive server restarts.
- **V1 & V2 Frontend Compatible**: Works in the modern V2 queue sidebar (`JobAssetsList`) and classic V1 queue dialog.
### The Persistent Queue (Crash Recovery)
You don't need to interact with this—it runs silently in the background!
Every time you queue a prompt, LeafFlow saves the entire queue state to your hard drive in real time. If your computer crashes, power goes out, or you accidentally close the terminal, ComfyUI will automatically restore your unfinished queue upon next boot (in a paused state, so it doesn't overwhelm your GPU before you're ready).
You don't need to interact with this—it runs silently in the background!
Every time you queue a prompt, SaturnNodes saves the entire queue state to your hard drive in real time. If your computer crashes, power goes out, or you accidentally close the terminal, ComfyUI will automatically restore your unfinished queue upon next boot (in a paused state, so it doesn't overwhelm your GPU before you're ready).
### Automatic Assets Pane & History Restore
In standard ComfyUI, restarting your server wipes the in-memory execution history, leaving your sidebar Assets Pane / History tab completely blank on launch.
- LeafFlow automatically scans your `output` folder (read-only) on server startup and pre-populates the history with your latest **64 images** (or custom count).
- SaturnNodes automatically scans your `output` folder (read-only) on server startup and pre-populates the history with your latest **64 images** (or custom count).
- All images are loaded in strict chronological order with embedded workflow and prompt graphs intact.
- Features like **Copy Prompt** and **Copy Workflow** immediately work with restored images as if they were generated in your current session!
- You can adjust the restored image count or toggle this feature in **ComfyUI Settings (⚙️)** under **`🍃 LeafFlow: Restore Assets on Launch`** and **`🍃 LeafFlow: Restored Assets Count`**.
- You can adjust the restored image count or toggle this feature in **ComfyUI Settings (⚙️)** under **`Restore Assets on Launch`** and **`Restored Assets Count`** (search for `SaturnNodes`).
### Image Overlay Actions & Prompt Bookmarks
Hovering over any image in the ComfyUI Assets / History pane or preview nodes provides powerful quick actions directly on the card:
- **📋 Copy Prompt**: Instantly copies the positive prompt text/graph to your clipboard.
- **🔖 Save to Prompt Bookmarks**: One-click saves prompt text straight into your Prompt Bookmarks list with robust SVG bookmark iconography.
- **🔍 Inspect Asset (Zoom)**: When enabled in settings (`04_EnableInspectAssetButton`), restores the direct full-size zoom inspect button right on the card hover pill bar alongside Download and Copy Prompt (bringing back quick one-click access that newer ComfyUI frontend versions moved into the 3-dots submenu).
- **🔍 Inspect Asset (Zoom)**: When enabled via the **Show "Inspect Asset" (Zoom) Button on Images** setting, restores the direct full-size zoom inspect button right on the card hover pill bar alongside Download and Copy Prompt (bringing back quick one-click access that newer ComfyUI frontend versions moved into the 3-dots submenu).
- **Dynamic Button Pill Styling**: The action button bar dynamically calculates borders and corner rounding (`rounded-l-lg`, `rounded-r-lg`) depending on which actions are enabled in settings, maintaining a seamless native appearance.
---
## 2. Advanced Nodes
### 🍃 ⏸️ LeafFlow Decision
### 🪐 ⏸️ Saturn Decision
Sometimes you run a complex workflow that takes hours (e.g., upscaling), but you want to check a low-res preview first to ensure it's worth the compute time.
1. Drop the **`🍃 ⏸️ LeafFlow Decision`** node into your workflow between the low-res and high-res stages.
1. Drop the **`🪐 ⏸️ Saturn Decision`** node into your workflow between the low-res and high-res stages.
2. When the execution reaches this node, your workflow will pause, and a native desktop notification (Windows/macOS/Linux) will alert you!
3. You will see a popup UI on your ComfyUI canvas giving you three choices:
- **Continue**: Proceeds with the workflow normally.
- **Cancel**: Outputs a `True` signal. You can route this into a Switch node to bypass the high-res stage entirely.
- **Stop Workflow**: Instantly aborts the generation queue, exactly like clicking the red X in ComfyUI.
### 🍃 📂 Load Image From Folder
### 🪐 📂 Load Image From Folder
An absolute powerhouse for automation. Point this node at any folder on your hard drive, and it will automatically ingest incoming images, convert them into tensors, and delete the original files to keep the folder clean.
- **wait_if_folder_is_empty**: If set to `True`, the workflow will patiently pause and poll the folder at your `rescan_interval` until an image arrives. Perfect for linking ComfyUI to external tools like Photoshop or Blender auto-exports!
- **Regex Filtering**: Only want it to grab images that start with `render_`? Just use standard regex like `^render_.*\.png$`.
### 🍃 🖼️ Visual LoRA & Image Loaders
### 🪐 🖼️ Visual LoRA & Image Loaders
Tired of guessing what a LoRA does based on its filename?
1. Use the **`🍃 🖼️ Visual LoRA Loader`**. It natively extracts preview images if you place an identically named `.png`/`.jpg` next to your `.safetensors` file.
2. If you enable the **Civitai Auto-Scraper** in your ComfyUI Settings, the node will calculate the SHA256 hash of your LoRA and automatically download the official preview thumbnail directly from Civitai!
3. **Pretty Name String Output**: The node outputs the parsed, human-readable name of the loaded LoRA (e.g. "Addison Rae V1") by default, allowing you to route it into a text prompt or watermark node. You can easily switch this via the `output_name` toggle on the node to output the raw filename without extension instead.
4. **Independent Per-Node Zoom**: Use the `tile_size` slider to adjust preview card sizes to your preference. Zoom levels are saved per node directly inside your workflow JSON, so different visual loaders maintain independent tile sizes across browser reloads.
1. Use the **`🪐 🖼️ Visual LoRA Loader`**. It natively extracts preview images if you place an identically named `.png`/`.jpg` next to your `.safetensors` file.
2. If you enable the **Civitai Auto-Scraper** in your ComfyUI Settings, the node will calculate the SHA256 hash of your LoRA and automatically download the official preview thumbnail directly from Civitai!
3. **Pretty Name String Output**: The node outputs the parsed, human-readable name of the loaded LoRA (e.g. "Addison Rae V1") by default, allowing you to route it into a text prompt or watermark node. You can easily switch this via the `output_name` toggle on the node to output the raw filename without extension instead.
4. **Independent Per-Node Zoom**: Use the `tile_size` slider to adjust preview card sizes to your preference. Zoom levels are saved per node directly inside your workflow JSON, so different visual loaders maintain independent tile sizes across browser reloads.
5. **Maintenance Reset Buttons**: The control bar offers `↺ Counter` (reset this node's Sequential/Random LoRA cycle + prompt→LoRA assignments), `🧹 Usage` (clear usage badges), and `🗑 Cache` (delete cached thumbnails). Each asks for confirmation. ⚠️ Only use `↺ Counter` when the queue is empty — resetting mid-batch restarts the LoRA cycle from the first selected LoRA and can mismatch prompts against LoRAs.
### 🍃 ⏱️ Recent Outputs
Want to quickly reference your recent generations without digging through Windows Explorer? The **`🍃 ⏱️ Recent Outputs`** node cycles chronologically through your `output/` directory, pulling your freshest creations right back into the workflow canvas.
### 🪐 ⏱️ Recent Outputs
Want to quickly reference your recent generations without digging through Windows Explorer? The **`🪐 ⏱️ Recent Outputs`** node cycles chronologically through your `output/` directory, pulling your freshest creations right back into the workflow canvas.
### 🍃 📝 Prompt Counter & 🔄 Prompt Queue Iterator
### 🪐 📝 Prompt Counter & 🪐 🔄 Prompt Queue Iterator
Managing multi-prompt queues and setting the exact ComfyUI batch size has never been easier:
1. **`🍃 📝 Prompt Counter`**: Place this multiline text node in your workflow and paste all your prompts.
- As you type or paste, the live badge instantly updates (e.g. `🍃 24 Prompts`), so you know exactly what batch size to set before clicking Queue!
1. **`🪐 📝 Prompt Counter`**: Place this multiline text node in your workflow and paste all your prompts.
- As you type or paste, the live badge instantly updates (e.g. `24 Prompts`), so you know exactly what batch size to set before clicking Queue!
- Under Advanced Options, select your delimiter (`>1 Empty Line`, `Newline`, `>2 Empty Lines`, or `Custom Regex`).
- If `Custom Regex` is selected, enter any custom delimiter pattern (such as `\n---\n`). The regex field is dynamically enabled only when Custom Regex is active.
2. **`🍃 🔄 Prompt Queue Iterator`**: Connect the `STRING` output of the Prompt Counter into the Prompt Queue Iterator to sequentially pop and execute each prompt run-by-run.
2. **`🪐 🔄 Prompt Queue Iterator`**: Connect the `STRING` output of the Prompt Counter into the Prompt Queue Iterator to sequentially pop and execute each prompt run-by-run.
- Now supports `Custom Regex` in addition to empty line and newline separators.
- Includes live progress counter widget (`🍃 Run X / Y`), instant index reset button (`🔄 Reset Counter (0)`), and direct state file access (`📂 Open Queue File`).
- Includes live progress counter widget (`Run X / Y`), an index reset button (`Reset Counter (0)`, now with a confirmation explaining that it only restarts the run pointer — it does **not** empty the queue state file; use Settings → `🔄 Reset All Queues` for a full wipe), and direct state file access (`Open Queue File`).
---
@@ -103,7 +104,7 @@ Several nodes across this suite (e.g. *Load Image From Folder*, *Recent Outputs*
- **Empty String**: Leaving a field completely empty (or spaces) will default to the sensible native directory for that node (e.g., leaving it empty on *Recent Outputs* will automatically target ComfyUI's root `output/` directory).
- **Safe Directory Containment**: For security, image loading and visual thumbnail nodes are confined to ComfyUI `input`, `output`, and `temp` directories with path traversal protection.
- **Subfolder Paths**: You can specify subdirectories like `batch_01` or `renders/portraits` within the allowed ComfyUI directories.
- **Wildcard Filters (`*`)**:
- **Wildcard Filters (`*`)**:
- **For the LoRA Loader**: Ending a path with `*` acts as a wildcard directory filter. For example, if you input `style/*`, the loader will recursively display all LoRAs located inside any subfolder that begins with `style/`.
- **For File Loaders**: If you accidentally copy a path from Windows Explorer that ends in `\*` or `*`, these nodes are smart enough to automatically strip the trailing asterisk so the folder path still resolves cleanly without throwing an OS Error.
@@ -111,9 +112,10 @@ Several nodes across this suite (e.g. *Load Image From Folder*, *Recent Outputs*
## 4. Settings & Configuration
Click the standard ComfyUI Settings gear ⚙️ to access LeafFlow's configurations. Here you can:
Click the standard ComfyUI Settings gear ⚙️ and search for `SaturnNodes` to access the suite's configurations. Here you can:
- Safely enter and mask API Keys for Civitai and TMDB scraping.
- Change the colors of the Pause Queue buttons via built-in color pickers.
- Adjust the default boot behavior for the Persistent Queue (e.g., forcing ComfyUI to always boot in a Paused state).
- Enable the floating Live Latent dock, drag-resize the queue overlay, and hide entire nodes from the Add Node menu under **Node Management**.
> **Cross-Platform Note**: All of the visual nodes, pause features, and OS notifications are fully compatible with Windows, macOS, and Linux, and seamlessly adapt to both the modern ComfyUI V2 interface and the classic LiteGraph UI!
+205 -26
View File
@@ -4,30 +4,39 @@ import subprocess
from aiohttp import web
from server import PromptServer
__version__ = "2.4.1"
__version__ = "2.6.1"
from .nodes.queue_control import setup_queue_control_routes, tray_manager
from .nodes.queue_control import (
setup_queue_control_routes,
tray_manager,
persistent_queue_manager,
is_persistent_queue_enabled
)
from .nodes.tray_icon import is_tray_icon_enabled
from .nodes.assets_restore import (
assets_restore_manager,
is_assets_restore_enabled
)
from .nodes.lora_loader import (
FolderLoraLoader,
FolderLoraLoaderPretty,
VisualLoraLoader,
FolderLoraLoaderVisualPrettyV2
VisualLoraLoader
)
from .nodes.image_loader import VisualImageLoader, ImageLoaderVisualPrettyV2
from .nodes.image_loader import VisualImageLoader
from .nodes.auto_watcher import LoadImageFromFolder
from .nodes.load_recent import LoadRecentOutputs
from .nodes.preview_latent import PreviewLatentLiveNode
from .nodes.decision_node import SaturnDecision
from .nodes.aspect_ratio import TextAspectRatioFinder, AspectRatioFinder, PreviewImageSizeAspectRatio
from .nodes.lora_finder import TextLoraFinder, LoraTextFinder
from .nodes.aspect_ratio import TextAspectRatioFinder, PreviewImageSizeAspectRatio
from .nodes.lora_finder import TextLoraFinder
from .nodes.prompt_iterator import PromptQueueIterator
from .nodes.prompt_counter import PromptCounter
from .nodes.text_replacer import MultiTextReplacer
from .nodes.text_split import SaturnTextSplit
from .nodes.local_runner import RunLocalFileNode, setup_local_runner_routes
from .nodes.stereogram import SaturnStereo3D
from .nodes.utils import (
get_saturnnodes_user_dir,
get_leafflow_user_dir,
get_env_setting,
is_local_request,
is_safe_path,
@@ -52,6 +61,7 @@ NODE_CLASS_MAPPINGS = {
"MultiTextReplacer": MultiTextReplacer,
"SaturnTextSplit": SaturnTextSplit,
"RunLocalFileNode": RunLocalFileNode,
"SaturnStereo3D": SaturnStereo3D,
}
NODE_DISPLAY_NAME_MAPPINGS = {
@@ -70,32 +80,166 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"PromptCounter": "🪐 📝 Prompt Counter",
"MultiTextReplacer": "🪐 🔤 Multi Text Replacer",
"SaturnTextSplit": "🪐 ✂️ Text Split",
"RunLocalFileNode": "🪐 ⚡ Run Local File"
"RunLocalFileNode": "🪐 ⚡ Run Local File",
"SaturnStereo3D": "🪐 👓 Stereoscopic 3D Generator",
}
ALL_SATURN_NODE_CLASSES = dict(NODE_CLASS_MAPPINGS)
ALL_SATURN_NODE_DISPLAY_NAMES = dict(NODE_DISPLAY_NAME_MAPPINGS)
ALL_SATURN_NODE_KEYS = list(NODE_CLASS_MAPPINGS)
def get_saturn_nodes_info():
"""Returns sorted node metadata auto-generated from NODE_CLASS_MAPPINGS and NODE_DISPLAY_NAME_MAPPINGS."""
import re
info_list = []
category_order = ["Loaders", "Automation", "Previews", "3D & Previews", "Utils"]
for key in ALL_SATURN_NODE_KEYS:
cls = ALL_SATURN_NODE_CLASSES.get(key)
cat = getattr(cls, "CATEGORY", "🪐 SaturnNodes/Utils") if cls else "🪐 SaturnNodes/Utils"
subcat = cat.split("/")[-1].strip() if "/" in cat else "Utils"
disp = ALL_SATURN_NODE_DISPLAY_NAMES.get(key, key)
clean_name = re.sub(r'^[^a-zA-Z0-9\(]+', '', disp).strip()
if not clean_name:
clean_name = key
info_list.append({
"key": key,
"category": subcat,
"clean_name": clean_name,
"name": f"{subcat} / {clean_name}",
"desc": disp
})
def sort_key(item):
cat = item["category"]
cat_idx = category_order.index(cat) if cat in category_order else 999
return (cat_idx, item["name"])
info_list.sort(key=sort_key)
return info_list
def load_disabled_nodes():
"""Loads set of user-disabled SaturnNodes from user settings directory."""
try:
import json
user_dir = get_saturnnodes_user_dir()
path = os.path.join(user_dir, "disabled_nodes.json")
if os.path.isfile(path):
with open(path, "r", encoding="utf-8") as f:
data = json.load(f)
if isinstance(data, list):
return set(data)
except Exception as e:
print(f"[SaturnNodes] Notice: Unable to load disabled_nodes.json: {e}")
return set()
def save_disabled_nodes(disabled_set):
"""Saves set of user-disabled SaturnNodes atomically."""
import json
user_dir = get_saturnnodes_user_dir()
os.makedirs(user_dir, exist_ok=True)
path = os.path.join(user_dir, "disabled_nodes.json")
temp_path = path + ".tmp"
with open(temp_path, "w", encoding="utf-8") as f:
json.dump(sorted(list(disabled_set)), f, indent=2)
os.replace(temp_path, path)
# Filter disabled nodes (all enabled by default when disabled_nodes.json is empty)
_active_disabled_nodes = load_disabled_nodes()
if _active_disabled_nodes:
for _node_name in _active_disabled_nodes:
NODE_CLASS_MAPPINGS.pop(_node_name, None)
NODE_DISPLAY_NAME_MAPPINGS.pop(_node_name, None)
WEB_DIRECTORY = "./web"
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
server = PromptServer.instance
setup_queue_control_routes(server)
setup_local_runner_routes(server)
server = getattr(PromptServer, "instance", None)
if server is not None and hasattr(server, "routes"):
setup_queue_control_routes(server)
setup_local_runner_routes(server)
routes = server.routes
else:
routes = web.RouteTableDef()
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
USER_DIR = get_saturnnodes_user_dir()
ENV_FILE = os.path.join(USER_DIR, ".env")
routes = server.routes
def print_startup_banner():
# Enable ANSI escape sequences on Windows console if available
if os.name == "nt":
try:
import ctypes
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)
except Exception:
pass
# Saturn Brand Colors (Amber, Gold, Warm Sand, White)
AMBER = "\033[1;38;2;245;158;11m"
GOLD = "\033[38;2;251;191;36m"
SAND = "\033[38;2;222;203;178m"
WHITE = "\033[97m"
RESET = "\033[0m"
active_count = len(NODE_DISPLAY_NAME_MAPPINGS)
total_count = len(ALL_SATURN_NODE_KEYS)
disabled_count = len(_active_disabled_nodes) if _active_disabled_nodes else 0
total_str = f"{active_count}/{total_count} nodes loaded"
if disabled_count > 0:
total_str += f" ({disabled_count} disabled in settings)"
print()
print(f"{AMBER}[ComfyUI-SaturnNodes]{RESET} {SAND}Version:{RESET} {WHITE}{__version__}{RESET}")
print(f" {GOLD}*{RESET} {SAND}Loaded:{RESET} {WHITE}Visual LoRA & Image Loaders, LoRA Folder Loader{RESET}")
print(f" {GOLD}*{RESET} {SAND}Loaded:{RESET} {WHITE}Live Latent Preview & Floating Dock{RESET}")
print(f" {GOLD}*{RESET} {SAND}Loaded:{RESET} {WHITE}Stereoscopic 3D Generator{RESET}")
print(f" {GOLD}*{RESET} {SAND}Loaded:{RESET} {WHITE}Prompt Queue Iterator, Prompt Counter, Text Tools{RESET}")
print(f" {GOLD}*{RESET} {SAND}Loaded:{RESET} {WHITE}Queue Pause, Persistent Queue, Local Runner{RESET}")
print()
# System status lines
try:
if is_tray_icon_enabled() and getattr(tray_manager, "_is_running", False):
tray_str = "System tray icon started."
elif not is_tray_icon_enabled():
tray_str = "System tray icon disabled in settings."
else:
tray_str = "System tray icon not started."
except Exception:
tray_str = "System tray icon disabled in settings."
try:
if is_assets_restore_enabled():
r_count = getattr(assets_restore_manager, "restored_count", 0)
assets_str = f"Restored {r_count} recent image(s) into Assets pane."
else:
assets_str = "No images restored into Assets pane (disabled in settings)."
except Exception:
assets_str = "Assets pane restore ready."
try:
if is_persistent_queue_enabled():
p_items = getattr(persistent_queue_manager, "persistent_items", [])
q_count = len(p_items) if p_items else 0
queue_str = f"Loaded {q_count} saved queue item(s)."
else:
queue_str = "No saved queue items loaded (disabled in settings)."
except Exception:
queue_str = "Persistent queue manager ready."
print(f" {GOLD}*{RESET} {WHITE}{tray_str}{RESET}")
print(f" {GOLD}*{RESET} {WHITE}{assets_str}{RESET}")
print(f" {GOLD}*{RESET} {WHITE}{queue_str}{RESET}")
print(f"{AMBER}Total: {total_str}{RESET}")
print()
try:
can_encode_saturn = True
try:
"🪐".encode(sys.stdout.encoding or "ascii")
except Exception:
can_encode_saturn = False
saturn_symbol = "🪐 " if can_encode_saturn else ""
print(f"[ComfyUI-SaturnNodes] {saturn_symbol}Loaded {len(NODE_CLASS_MAPPINGS)} nodes & visual endpoints successfully (v{__version__}).")
print_startup_banner()
except Exception:
print(f"[ComfyUI-SaturnNodes] Loaded {len(NODE_CLASS_MAPPINGS)} nodes & visual endpoints successfully (v{__version__}).")
print(f"\n[ComfyUI-SaturnNodes] Version: {__version__} - Total: {len(NODE_DISPLAY_NAME_MAPPINGS)}/{len(ALL_SATURN_NODE_KEYS)} nodes loaded\n")
@routes.get("/saturnnodes/auth/token")
async def get_csrf_token_endpoint(request):
@@ -326,8 +470,12 @@ async def save_settings(request):
if not has_local_file_exec and enable_local_file_execution is not None:
new_lines.append(f"ENABLE_LOCAL_FILE_EXECUTION={enable_local_file_execution}\n")
with open(ENV_FILE, "w", encoding="utf-8") as f:
temp_env = ENV_FILE + ".tmp"
with open(temp_env, "w", encoding="utf-8") as f:
f.writelines(new_lines)
f.flush()
os.fsync(f.fileno())
os.replace(temp_env, ENV_FILE)
if civitai_key is not None:
os.environ["CIVITAI_API_KEY"] = civitai_key
@@ -351,25 +499,56 @@ async def save_settings(request):
os.environ["CLEAR_PROMPT_ITERATOR_ON_LAUNCH"] = str(clear_prompt_iterator_on_launch)
except Exception as e:
print(f"[SaturnNodes] 🪐 Error saving settings to .env: {e}")
print(f"[SaturnNodes] Error saving settings to .env: {e}")
return web.json_response({"status": "error", "message": str(e)}, status=500)
return web.json_response({"status": "ok"})
@routes.get("/saturnnodes/disabled_nodes")
async def get_disabled_nodes_endpoint(request):
if not is_local_request(request):
return web.json_response({"error": "Forbidden: Local access only"}, status=403)
return web.json_response({
"disabled_nodes": sorted(list(load_disabled_nodes())),
"all_nodes": ALL_SATURN_NODE_KEYS,
"nodes_info": get_saturn_nodes_info()
})
@routes.post("/saturnnodes/disabled_nodes")
async def save_disabled_nodes_endpoint(request):
if not is_authenticated_local_request(request):
return web.json_response({"error": "Forbidden: Local authenticated access only"}, status=403)
try:
data = await request.json()
disabled_list = data.get("disabled_nodes", [])
if isinstance(disabled_list, list):
valid_keys = set(ALL_SATURN_NODE_KEYS)
cleaned = {str(k) for k in disabled_list if str(k) in valid_keys}
save_disabled_nodes(cleaned)
return web.json_response({"status": "ok", "disabled_nodes": sorted(list(cleaned))})
return web.json_response({"error": "Invalid format"}, status=400)
except Exception as e:
return web.json_response({"error": str(e)}, status=500)
@routes.post("/saturnnodes/scrapes/clear")
async def clear_scrapes_endpoint(request):
if not is_authenticated_local_request(request):
return web.json_response({"error": "Forbidden: Local authenticated access only"}, status=403)
try:
failed_file = os.path.join(USER_DIR, "failed_scrapes.json")
with open(failed_file, "w", encoding="utf-8") as f:
temp_failed = failed_file + ".tmp"
with open(temp_failed, "w", encoding="utf-8") as f:
f.write("{}")
os.replace(temp_failed, failed_file)
return web.json_response({"status": "ok"})
except Exception as e:
print(f"[SaturnNodes] 🪐 Error clearing scrapes cache: {e}")
print(f"[SaturnNodes] Error clearing scrapes cache: {e}")
return web.json_response({"status": "error", "message": str(e)}, status=500)
@routes.get("/saturnnodes/debug/export")
async def export_debug_profile(request):
if not is_local_request(request):
return web.json_response({"error": "Forbidden: Local access only"}, status=403)
try:
import platform
import json
@@ -389,7 +568,7 @@ async def export_debug_profile(request):
for line in f:
if line.strip().startswith("CIVITAI_API_KEY=") and not civitai_key:
civitai_key = line.split("=", 1)[1].strip()
elif line.startswith("TMDB_API_KEY=") and not tmdb_key:
elif line.strip().startswith("TMDB_API_KEY=") and not tmdb_key:
tmdb_key = line.split("=", 1)[1].strip()
except Exception:
pass
-2
View File
@@ -251,5 +251,3 @@ class PreviewImageSizeAspectRatio:
return {}
# Alias for backward compatibility
AspectRatioFinder = TextAspectRatioFinder
+10 -6
View File
@@ -9,9 +9,9 @@ import logging
from PIL import Image
import folder_paths
from .utils import get_leafflow_user_dir
from .utils import get_saturnnodes_user_dir
USER_DIR = get_leafflow_user_dir()
USER_DIR = get_saturnnodes_user_dir()
ENV_FILE = os.path.join(USER_DIR, ".env")
def get_env_setting(key, default_val):
@@ -137,15 +137,19 @@ class AssetsRestoreManager:
subfolder = item["subfolder"]
rel_key = f"{subfolder}/{filename}" if subfolder else filename
prompt_id = str(uuid.uuid5(uuid.NAMESPACE_URL, f"leafflow:{rel_key}"))
prompt_id = str(uuid.uuid5(uuid.NAMESPACE_URL, f"saturnnodes:{rel_key}"))
prompt_dict, workflow_dict, positive_prompt = self.extract_image_metadata(filepath)
output_node_id = "9"
output_node_id = None
if prompt_dict:
for nid, nval in prompt_dict.items():
if isinstance(nval, dict) and "SaveImage" in nval.get("class_type", ""):
output_node_id = str(nid)
break
if not output_node_id:
output_node_id = str(next(iter(prompt_dict.keys())))
if not output_node_id:
output_node_id = "0"
extra_pnginfo = {}
if workflow_dict:
@@ -162,7 +166,7 @@ class AssetsRestoreManager:
{
"create_time": mtime_ms,
"extra_pnginfo": extra_pnginfo,
"client_id": "leafflow_restored"
"client_id": "saturnnodes_restored"
},
[output_node_id]
],
@@ -229,9 +233,9 @@ class AssetsRestoreManager:
"total_scanned_images": len(images),
"restored_count": restored_count
}
self.restored_count = restored_count
if restored_count > 0:
print(f"[SaturnNodes] Restored {restored_count} recent image(s) into Assets / History pane.")
if server:
try:
server.queue_updated()
+13 -5
View File
@@ -10,11 +10,19 @@ from .utils import sanitize_folder_path, is_safe_path, get_allowed_folder_watch_
def get_current_prompt_id():
try:
from server import PromptServer
server = PromptServer.instance
if hasattr(server, "prompt_queue") and server.prompt_queue.currently_running:
for item in server.prompt_queue.currently_running.values():
if isinstance(item, (tuple, list)) and len(item) > 1:
return str(item[1])
server = getattr(PromptServer, "instance", None)
if server and hasattr(server, "prompt_queue"):
queue = server.prompt_queue
if hasattr(queue, "currently_running") and queue.currently_running:
mutex = getattr(queue, "mutex", None)
if mutex:
with mutex:
items = list(queue.currently_running.values())
else:
items = list(queue.currently_running.values())
for item in items:
if isinstance(item, (tuple, list)) and len(item) > 1:
return str(item[1])
except Exception:
pass
return None
+21 -9
View File
@@ -149,20 +149,35 @@ $toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
return (True,)
elif action == "stop":
print(f"[SaturnNodes] Node {unique_id} stopped workflow.")
stop_dispatched = False
try:
# Attempt to cancel current execution queue
PromptServer.instance.prompt_queue.cancel_current_execution()
except Exception:
pass
if hasattr(PromptServer, "instance") and hasattr(PromptServer.instance, "prompt_queue"):
PromptServer.instance.prompt_queue.cancel_current_execution()
stop_dispatched = True
except Exception as e:
print(f"[SaturnNodes] Notice: cancel_current_execution: {e}")
try:
import nodes
if hasattr(nodes, "interrupt_processing"):
nodes.interrupt_processing()
stop_dispatched = True
except Exception as e:
print(f"[SaturnNodes] Notice: nodes.interrupt_processing: {e}")
try:
comfy.model_management.interrupt_current_processing()
except Exception:
pass
stop_dispatched = True
except Exception as e:
print(f"[SaturnNodes] Notice: interrupt_current_processing: {e}")
if not stop_dispatched:
print(f"[SaturnNodes] Notice: Core cancellation hooks bypassed; halting via InterruptProcessingException.")
# Raise exception to halt this thread instantly
try:
raise comfy.model_management.InterruptProcessingException("Workflow stopped by SaturnNodes Decision Node.")
except AttributeError:
raise Exception("Workflow stopped by SaturnNodes Decision Node.")
raise RuntimeError("Workflow stopped by SaturnNodes Decision Node.")
print(f"[SaturnNodes] Node {unique_id} continuing.")
return (False,)
@@ -184,6 +199,3 @@ async def handle_decision(request):
return web.json_response({"status": "error", "message": "Node is not waiting."}, status=400)
except Exception as e:
return web.json_response({"status": "error", "message": str(e)}, status=500)
LeafFlowDecision = SaturnDecision
SaturnDecision = SaturnDecision
+21 -17
View File
@@ -11,7 +11,6 @@ from server import PromptServer
import folder_paths
from .utils import (
sanitize_folder_path,
get_leafflow_user_dir,
is_local_request,
is_safe_path,
sanitize_image_loader_folder,
@@ -163,14 +162,20 @@ def load_prompts_cache():
def save_prompts_cache(cache):
try:
with open(CACHE_FILE, "w", encoding="utf-8") as f:
temp_file = CACHE_FILE + ".tmp"
with open(temp_file, "w", encoding="utf-8") as f:
json.dump(cache, f, indent=4, ensure_ascii=False)
os.replace(temp_file, CACHE_FILE)
except Exception as e:
print(f"[SaturnNodes] Failed to save prompts cache: {e}")
routes = PromptServer.instance.routes if hasattr(PromptServer, "instance") and PromptServer.instance is not None else web.RouteTableDef()
if hasattr(PromptServer, "instance") and PromptServer.instance is not None:
routes = PromptServer.instance.routes
else:
routes = web.RouteTableDef()
print("[SaturnNodes] Notice: PromptServer instance not available during image_loader import; using standalone route table.")
@routes.get("/image_loader/get_images")
@routes.get("/saturnnodes/image_loader/get_images")
async def get_images_endpoint(request):
if not is_local_request(request):
return web.json_response({"error": "Forbidden: Local access only"}, status=403)
@@ -223,6 +228,7 @@ async def get_images_endpoint(request):
cached_entry = cache.get(full_path)
if cached_entry and cached_entry.get("mtime") == mtime:
prompt_text = cached_entry.get("prompt", "")
cache[full_path] = cache.pop(full_path)
else:
prompt_text, _, _ = extract_metadata_from_image(full_path)
cache[full_path] = {
@@ -251,7 +257,7 @@ async def get_images_endpoint(request):
"prompts": prompts
})
@routes.get("/image_loader/get_thumbnail")
@routes.get("/saturnnodes/image_loader/get_thumbnail")
async def get_thumbnail_endpoint(request):
if not is_local_request(request):
return web.Response(status=403)
@@ -282,7 +288,7 @@ async def get_thumbnail_endpoint(request):
except Exception:
return web.FileResponse(full_path)
@routes.get("/image_loader/get_full_image")
@routes.get("/saturnnodes/image_loader/get_full_image")
async def get_full_image_endpoint(request):
if not is_local_request(request):
return web.Response(status=403)
@@ -343,18 +349,16 @@ class VisualImageLoader:
empty_image = torch.zeros((1, 512, 512, 3), dtype=torch.float32)
return (empty_image, "", 0, 0)
i = Image.open(full_path)
i = ImageOps.exif_transpose(i)
positive_prompt, width, height = extract_metadata_from_image(full_path)
if width == 0 or height == 0:
width, height = i.size
with Image.open(full_path) as i:
i = ImageOps.exif_transpose(i)
positive_prompt, width, height = extract_metadata_from_image(full_path)
if width == 0 or height == 0:
width, height = i.size
image = i.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
image = i.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
return (image, positive_prompt, width, height)
# Alias for backward compatibility
ImageLoaderVisualPrettyV2 = VisualImageLoader
+1 -1
View File
@@ -57,7 +57,7 @@ class LoadRecentOutputs:
except OSError:
continue
except Exception as e:
print(f"[SaturnNodes] 🍃 Error scanning output folder '{output_dir}': {e}")
print(f"[SaturnNodes] Error scanning output folder '{output_dir}': {e}")
dummy = torch.zeros((1, 512, 512, 3), dtype=torch.float32)
return (dummy,)
+11 -4
View File
@@ -390,6 +390,8 @@ class RunLocalFileNode:
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
encoding="utf-8",
errors="replace",
creationflags=creationflags
)
@@ -411,9 +413,11 @@ class RunLocalFileNode:
pass
effective_timeout = timeout if timeout > 0 else None
stdout_data = ""
stderr_data = ""
# Poll for completion while honoring ComfyUI cancellation
while proc.poll() is None:
# Continuously drain pipes to prevent OS buffer deadlocks while honoring cancellation
while True:
try:
comfy.model_management.throw_exception_if_processing_interrupted()
except Exception:
@@ -427,9 +431,12 @@ class RunLocalFileNode:
_safe_print(f"[SaturnNodes LocalRunner] {err}")
return ("", err, -1, False, passthrough_out)
time.sleep(0.1)
try:
stdout_data, stderr_data = proc.communicate(timeout=0.1)
break
except subprocess.TimeoutExpired:
continue
stdout_data, stderr_data = proc.communicate()
exit_code = proc.returncode
success = (exit_code == 0)
+2 -4
View File
@@ -99,7 +99,7 @@ class TextLoraFinder:
matches.append((m.start(), display_name, sys_path))
seen_paths.add(sys_path)
except Exception as e:
print(f"[SaturnNodes] 🍃 Invalid custom regex pattern '{custom_regex}': {e}")
print(f"[SaturnNodes] Invalid custom regex pattern '{custom_regex}': {e}")
else:
for display_name, sys_path in mapping.items():
if display_name in ["[ NONE ]", "[ RANDOM ]"] or not sys_path or sys_path == "[ NONE ]":
@@ -150,7 +150,7 @@ class TextLoraFinder:
)
increment_lora_usage(sys_path)
except Exception as e:
print(f"[SaturnNodes] 🍃 Error loading LoRA '{sys_path}': {e}")
print(f"[SaturnNodes] Error loading LoRA '{sys_path}': {e}")
continue
else:
increment_lora_usage(sys_path)
@@ -161,5 +161,3 @@ class TextLoraFinder:
return (current_model, current_clip, ", ".join(formatted_names))
# Alias for backward compatibility
LoraTextFinder = TextLoraFinder
+142 -13
View File
@@ -4,6 +4,7 @@ import fnmatch
import json
import time
import hashlib
import asyncio
import folder_paths
import urllib.request
import urllib.parse
@@ -19,8 +20,8 @@ from .utils import (
format_lora_output_name,
sanitize_folder_path,
get_saturnnodes_user_dir,
get_leafflow_user_dir,
is_local_request,
is_authenticated_local_request,
is_safe_path
)
@@ -60,8 +61,10 @@ def save_lora_cycle_state(state):
excess_keys = list(state.keys())[:-100]
for k in excess_keys:
del state[k]
with open(LORA_STATE_FILE, "w", encoding="utf-8") as f:
temp_file = LORA_STATE_FILE + ".tmp"
with open(temp_file, "w", encoding="utf-8") as f:
json.dump(state, f, indent=4, ensure_ascii=False)
os.replace(temp_file, LORA_STATE_FILE)
except Exception as e:
print(f"[SaturnNodes] Error saving lora loader cycle state: {e}")
@@ -112,8 +115,10 @@ def increment_lora_usage(lora_path):
usage_data = load_usage_data()
pretty_key = parse_pretty_name(lora_path)
usage_data[pretty_key] = usage_data.get(pretty_key, 0) + 1
with open(usage_file, "w", encoding="utf-8") as f:
temp_file = usage_file + ".tmp"
with open(temp_file, "w", encoding="utf-8") as f:
json.dump(usage_data, f, indent=4, ensure_ascii=False)
os.replace(temp_file, usage_file)
except Exception as e:
print(f"[SaturnNodes] Error updating lora usage: {e}")
@@ -237,6 +242,9 @@ def scrape_missing_images_sync():
success = True
except (PermissionError, OSError) as write_err:
print(f"[SaturnNodes] Warning: Could not save preview image to '{dest_path}': {write_err}")
except urllib.error.HTTPError as http_err:
if http_err.code in (401, 403):
print(f"[SaturnNodes] Notice: Civitai API authentication failed (HTTP {http_err.code}). Check your CIVITAI_API_KEY in settings.")
except Exception:
pass
@@ -283,7 +291,10 @@ def scrape_missing_images_sync():
break
except (PermissionError, OSError) as write_err:
print(f"[SaturnNodes] Warning: Could not save preview image to '{dest_path}': {write_err}")
except Exception as tmdb_err:
except urllib.error.HTTPError as http_err:
if http_err.code in (401, 403):
print(f"[SaturnNodes] Notice: TMDB API authentication failed (HTTP {http_err.code}). Check your TMDB_API_KEY in settings.")
except Exception:
pass
if not success:
@@ -292,8 +303,10 @@ def scrape_missing_images_sync():
if modified:
try:
with open(failed_scrapes_file, "w", encoding="utf-8") as f:
temp_file = failed_scrapes_file + ".tmp"
with open(temp_file, "w", encoding="utf-8") as f:
json.dump(failed_scrapes, f, indent=4, ensure_ascii=False)
os.replace(temp_file, failed_scrapes_file)
except Exception:
pass
except Exception as e:
@@ -352,7 +365,7 @@ def get_filtered_loras_mapping(folder_filter, pretty=False):
server = PromptServer.instance
routes = server.routes
@routes.get("/folder_lora_loader/get_loras")
@routes.get("/saturnnodes/folder_lora_loader/get_loras")
async def get_loras_endpoint(request):
if not is_local_request(request):
return web.json_response({"error": "Forbidden: Local access only"}, status=403)
@@ -390,7 +403,46 @@ async def get_loras_endpoint(request):
"mtime": mtime_by_path
})
@routes.get("/folder_lora_loader/get_preview")
THUMBNAILS_DIR = os.path.join(USER_DIR, "thumbnails")
def get_or_create_thumbnail(img_path, max_size=256):
"""
Returns path to a high-speed cached WebP thumbnail of img_path with max dimension max_size.
Cached on disk and invalidated if source file mtime changes.
"""
try:
from PIL import Image
mtime = os.path.getmtime(img_path)
hash_src = f"{img_path}_{mtime}_{max_size}".encode("utf-8")
cache_key = hashlib.md5(hash_src).hexdigest()
os.makedirs(THUMBNAILS_DIR, exist_ok=True)
thumb_path = os.path.join(THUMBNAILS_DIR, f"thumb_{cache_key}.webp")
if os.path.exists(thumb_path) and os.path.getsize(thumb_path) > 0:
return thumb_path
with Image.open(img_path) as img:
w, h = img.size
if w <= max_size and h <= max_size:
return img_path
if img.mode in ("RGBA", "LA") or (img.mode == "P" and "transparency" in img.info):
img = img.convert("RGBA")
else:
img = img.convert("RGB")
# BICUBIC produces crisp, smooth, high-quality thumbnails from 4K/6MP sources
# while executing significantly faster than LANCZOS to avoid CPU contention.
img.thumbnail((max_size, max_size), Image.Resampling.BICUBIC)
temp_path = thumb_path + ".tmp"
# method=1 gives high quality WebP at ~10x the speed of method=4, eliminating CPU spikes
img.save(temp_path, format="WEBP", quality=85, method=1)
os.replace(temp_path, thumb_path)
return thumb_path
except Exception:
return img_path
@routes.get("/saturnnodes/folder_lora_loader/get_preview")
async def get_preview_endpoint(request):
if not is_local_request(request):
return web.Response(status=403)
@@ -398,18 +450,97 @@ async def get_preview_endpoint(request):
lora_name = request.query.get("lora", "")
folder = request.query.get("folder", "")
pretty = request.query.get("pretty", "true").lower() == "true"
full = request.query.get("full", "false").lower() == "true"
if not system_path and lora_name:
mapping = get_filtered_loras_mapping(folder, pretty=pretty)
system_path = mapping.get(lora_name, lora_name)
if system_path and system_path != "[ NONE ]":
img_path = find_preview_image(system_path)
if img_path and os.path.exists(img_path) and os.path.isfile(img_path):
return web.FileResponse(img_path)
if full:
return web.FileResponse(img_path)
try:
thumb_size = int(request.query.get("size", 256))
thumb_size = max(64, min(1024, thumb_size))
except Exception:
thumb_size = 256
serve_path = await asyncio.to_thread(get_or_create_thumbnail, img_path, max_size=thumb_size)
return web.FileResponse(serve_path)
return web.Response(status=404)
@routes.post("/saturnnodes/folder_lora_loader/reset_cycle")
async def reset_lora_cycle_endpoint(request):
"""Clears Sequential/Random cycle counters + prompt->LoRA assignments for one node (or all)."""
if not is_authenticated_local_request(request):
return web.json_response({"error": "Forbidden: Local authenticated access only"}, status=403)
try:
data = await request.json()
except Exception:
data = {}
node_id = str(data.get("node_id", "")).strip()
try:
state = load_lora_cycle_state()
removed = 0
if node_id and node_id != "all":
prefixes = (f"seq_{node_id}_", f"rand_{node_id}_", f"noreplace_{node_id}_")
for k in list(state.keys()):
if k.startswith(prefixes):
del state[k]
removed += 1
else:
removed = len(state)
state = {}
save_lora_cycle_state(state)
return web.json_response({"status": "ok", "removed": removed})
except Exception as e:
return web.json_response({"status": "error", "message": str(e)}, status=500)
@routes.post("/saturnnodes/folder_lora_loader/reset_usage")
async def reset_lora_usage_endpoint(request):
"""Empties lora_usage.json (usage badges + usage-based sortings)."""
if not is_authenticated_local_request(request):
return web.json_response({"error": "Forbidden: Local authenticated access only"}, status=403)
try:
ensure_user_dir()
usage_file = os.path.join(USER_DIR, "lora_usage.json")
tmp_file = usage_file + ".tmp"
with open(tmp_file, "w", encoding="utf-8") as f:
json.dump({}, f, indent=4)
os.replace(tmp_file, usage_file)
return web.json_response({"status": "ok"})
except Exception as e:
return web.json_response({"status": "error", "message": str(e)}, status=500)
@routes.post("/saturnnodes/folder_lora_loader/clear_cache")
async def clear_lora_cache_endpoint(request):
"""Deletes cached WebP thumbnails (regenerated on demand)."""
if not is_authenticated_local_request(request):
return web.json_response({"error": "Forbidden: Local authenticated access only"}, status=403)
removed = 0
try:
cache_dir = os.path.realpath(THUMBNAILS_DIR)
canonical_user = os.path.realpath(USER_DIR)
try:
if os.path.commonpath([canonical_user, cache_dir]) != canonical_user:
return web.json_response({"status": "error", "message": "Security: cache path escapes user directory"}, status=403)
except Exception:
return web.json_response({"status": "error", "message": "Security path validation error"}, status=403)
if os.path.isdir(cache_dir):
for name in os.listdir(cache_dir):
entry = os.path.join(cache_dir, name)
if os.path.isfile(entry):
try:
os.remove(entry)
removed += 1
except Exception:
pass
return web.json_response({"status": "ok", "removed": removed})
except Exception as e:
return web.json_response({"status": "error", "message": str(e)}, status=500)
class FolderLoraLoader:
@classmethod
def INPUT_TYPES(s):
@@ -747,5 +878,3 @@ class VisualLoraLoader(FolderLoraLoaderPretty):
pretty_name_str = ", ".join(loaded_names) if loaded_names else ""
return (current_model, current_clip, pretty_name_str)
# Alias for backward compatibility
FolderLoraLoaderVisualPrettyV2 = VisualLoraLoader
+1 -1
View File
@@ -2,7 +2,7 @@ from .prompt_iterator import parse_prompt_blocks
class PromptCounter:
"""
LeafFlow Prompt Counter:
SaturnNodes Prompt Counter:
Multiline text prompt input node with real-time prompt counting according to
selectable separator ("Newline", ">1 Empty Line", ">2 Empty Lines", "Custom Regex").
Outputs STRING (unmodified text) and count (integer count of prompts).
+25 -18
View File
@@ -9,7 +9,7 @@ import subprocess
from aiohttp import web
from server import PromptServer
import folder_paths
from .utils import get_saturnnodes_user_dir, get_leafflow_user_dir, is_authenticated_local_request
from .utils import get_saturnnodes_user_dir, is_authenticated_local_request
CURRENT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
USER_DIR = get_saturnnodes_user_dir()
@@ -43,7 +43,7 @@ def load_state():
if isinstance(data, dict):
return data
except Exception as e:
print(f"[SaturnNodes] 🍃 Warning reading prompt iterator state: {e}")
print(f"[SaturnNodes] Warning reading prompt iterator state: {e}")
return {}
def save_state(state):
@@ -57,22 +57,21 @@ def save_state(state):
tmp_file = STATE_FILE + ".tmp"
with open(tmp_file, "w", encoding="utf-8") as f:
json.dump(state, f, indent=4, ensure_ascii=False)
if os.path.exists(STATE_FILE):
os.replace(tmp_file, STATE_FILE)
else:
os.rename(tmp_file, STATE_FILE)
os.replace(tmp_file, STATE_FILE)
except Exception as e:
print(f"[SaturnNodes] 🍃 Error saving prompt iterator state: {e}")
print(f"[SaturnNodes] Error saving prompt iterator state: {e}")
def clear_state():
ensure_user_dir()
try:
with open(STATE_FILE, "w", encoding="utf-8") as f:
tmp_file = STATE_FILE + ".tmp"
with open(tmp_file, "w", encoding="utf-8") as f:
json.dump({}, f, indent=4)
print("[SaturnNodes] 🍃 Prompt iterator state cleared.")
os.replace(tmp_file, STATE_FILE)
print("[SaturnNodes] Prompt iterator state cleared.")
return True
except Exception as e:
print(f"[SaturnNodes] 🍃 Error clearing prompt iterator state: {e}")
print(f"[SaturnNodes] Error clearing prompt iterator state: {e}")
return False
# Clear state on startup if privacy setting enabled
@@ -149,11 +148,11 @@ try:
subprocess.Popen(["xdg-open", canonical_state])
return web.json_response({"status": "ok", "path": canonical_state})
except Exception as e:
print(f"[SaturnNodes] 🍃 Error opening state file: {e}")
print(f"[SaturnNodes] Error opening state file: {e}")
return web.json_response({"status": "error", "message": str(e)}, status=500)
except Exception:
pass
except Exception as e:
print(f"[SaturnNodes] Notice: Skipped registering prompt iterator endpoints: {e}")
def parse_prompt_blocks(text_str, separator, custom_regex=""):
if not text_str or not text_str.strip():
@@ -188,11 +187,19 @@ def parse_prompt_blocks(text_str, separator, custom_regex=""):
def get_current_prompt_id():
try:
server = PromptServer.instance
if hasattr(server, "prompt_queue") and server.prompt_queue.currently_running:
for item in server.prompt_queue.currently_running.values():
if isinstance(item, (tuple, list)) and len(item) > 1:
return str(item[1])
server = getattr(PromptServer, "instance", None)
if server and hasattr(server, "prompt_queue"):
queue = server.prompt_queue
if hasattr(queue, "currently_running") and queue.currently_running:
mutex = getattr(queue, "mutex", None)
if mutex:
with mutex:
items = list(queue.currently_running.values())
else:
items = list(queue.currently_running.values())
for item in items:
if isinstance(item, (tuple, list)) and len(item) > 1:
return str(item[1])
except Exception:
pass
return None
+125 -52
View File
@@ -9,7 +9,7 @@ from server import PromptServer
import nodes
from .tray_icon import TrayIconManager, is_tray_icon_enabled
from .assets_restore import assets_restore_manager, is_assets_restore_enabled, get_assets_restore_count
from .utils import get_saturnnodes_user_dir, get_leafflow_user_dir, is_local_request, is_authenticated_local_request
from .utils import get_saturnnodes_user_dir, is_local_request, is_authenticated_local_request
QUEUE_CATEGORY = "🪐 SaturnNodes/Queue"
@@ -69,29 +69,35 @@ class PauseQueueManager:
def patched_get(*args, **kwargs):
while True:
# 1. If queue is paused, wait BEFORE popping any item from the queue!
# This guarantees that ComfyUI never sets currently_running, never sends
# execution_start, and never starts the elapsed timer while waiting.
if self.paused:
if not self.is_waiting:
self.is_waiting = True
print("[PauseQueue] Workflow paused after this run: Current workflow finished, queue paused.")
print("[SaturnNodes PauseQueue] Workflow paused: Queue is paused, waiting before next workflow.")
self.notify_clients()
while self.paused:
try:
import comfy.model_management as mm
if hasattr(mm, "processing_interrupted") and mm.processing_interrupted():
break
except Exception:
pass
self.event.wait(0.2)
self.is_waiting = False
self.notify_clients()
item = original_get(*args, **kwargs)
# 2. Use a short timeout (0.5s) when polling for items so that if the user
# enables pause while the queue is idle, we don't remain stuck inside
# a blocking original_get() that would prematurely pop an incoming workflow.
kwargs_copy = dict(kwargs)
if "timeout" not in kwargs_copy and len(args) == 0:
kwargs_copy["timeout"] = 0.5
if self.paused:
if not self.is_waiting:
self.is_waiting = True
print("[PauseQueue] Workflow paused after this run: Current workflow finished, queue paused.")
self.notify_clients()
while self.paused:
self.event.wait(0.2)
self.is_waiting = False
self.notify_clients()
return item
item = original_get(*args, **kwargs_copy)
if item is not None:
return item
queue.get = patched_get
@@ -99,24 +105,44 @@ class PauseQueueManager:
original_send_sync = server.send_sync
def patched_send_sync(event, data, sid=None):
result = original_send_sync(event, data, sid)
if event == "executing" and isinstance(data, dict) and data.get("node") is not None:
if self.paused and self.mode == "instantly":
if not self.is_waiting:
self.is_waiting = True
print(f"[PauseQueue] Workflow Paused Instant: Paused before executing node '{data.get('node')}'.")
print(f"[SaturnNodes PauseQueue] Workflow Paused Instant: Paused before executing node '{data.get('node')}'.")
self.notify_clients()
while self.paused and self.mode == "instantly":
# Check for user cancellation or interrupt while paused
try:
import comfy.model_management as mm
if hasattr(mm, "processing_interrupted") and mm.processing_interrupted():
self.paused = False
self.is_waiting = False
self.event.set()
self.notify_clients()
if hasattr(mm, "throw_exception_if_processing_interrupted"):
mm.throw_exception_if_processing_interrupted()
break
except Exception as err:
if "InterruptProcessingException" in type(err).__name__:
raise
if not self.is_currently_executing():
self.is_waiting = False
self.notify_clients()
break
self.event.wait(0.2)
self.is_waiting = False
self.notify_clients()
return original_send_sync(event, data, sid)
return result
server.send_sync = patched_send_sync
else:
print("[SaturnNodes] Queue control: Skipped patching send_sync (not found on server).")
self._patched = True
print("[SaturnNodes] Queue control: Pause manager initialized successfully.")
def is_currently_executing(self):
try:
@@ -136,26 +162,49 @@ class PauseQueueManager:
if not self.is_currently_executing():
self.is_waiting = True
if self.mode == "instantly":
print("[PauseQueue] Workflow Paused Instant: Queue is empty/idle, pause active.")
print("[SaturnNodes PauseQueue] Workflow Paused Instant: Queue is empty/idle, pause active.")
else:
print("[PauseQueue] Workflow paused after this run: Queue is empty/idle, pause active.")
print("[SaturnNodes PauseQueue] Workflow paused after this run: Queue is empty/idle, pause active.")
else:
self.is_waiting = False
if self.mode == "instantly":
print("[PauseQueue] Workflow Paused Instant requested. Waiting for current node to complete...")
print("[SaturnNodes PauseQueue] Workflow Paused Instant requested. Waiting for current node to complete...")
else:
print("[PauseQueue] Workflow paused after this run requested. Will pause when current workflow completes...")
print("[SaturnNodes PauseQueue] Workflow paused after this run requested. Will pause when current workflow completes...")
self.event.clear()
else:
self.is_waiting = False
self.event.set()
print("[PauseQueue] Continue pressed: Resuming execution.")
print("[SaturnNodes PauseQueue] Continue pressed: Resuming execution.")
self.notify_clients()
try:
server = getattr(PromptServer, "instance", None)
if server and hasattr(server, "prompt_queue"):
pq = server.prompt_queue
if hasattr(pq, "not_empty") and hasattr(pq, "mutex"):
# Use non-blocking acquire to avoid deadlock if worker thread is locked
acquired = pq.mutex.acquire(blocking=False)
if acquired:
try:
pq.not_empty.notify_all()
finally:
pq.mutex.release()
else:
def _notify_async():
try:
with pq.mutex:
pq.not_empty.notify_all()
except Exception:
pass
threading.Thread(target=_notify_async, daemon=True).start()
except Exception:
pass
def set_mode(self, mode):
self.mode = mode
print(f"[PauseQueue] Selected pause mode: '{self.mode}'")
print(f"[SaturnNodes PauseQueue] Selected pause mode: '{self.mode}'")
self.notify_clients()
def notify_clients(self):
@@ -198,11 +247,10 @@ class PersistentQueueManager:
for x in self.persistent_items:
if "batch_info" in x and "prompt_id" in x:
self.batch_meta[str(x["prompt_id"])] = x["batch_info"]
print(f"[PersistentQueue] Loaded {len(self.persistent_items)} saved queue item(s).")
else:
self.persistent_items = []
except Exception as e:
print(f"[PersistentQueue] Error loading persistent queue file: {e}")
print(f"[SaturnNodes PersistentQueue] Error loading persistent queue file: {e}")
self.persistent_items = []
else:
self.persistent_items = []
@@ -230,7 +278,7 @@ class PersistentQueueManager:
json.dump(self.persistent_items, f, indent=2, default=str)
os.replace(temp_file, PERSISTENT_FILE)
except Exception as e:
print(f"[PersistentQueue] Error saving persistent queue file: {e}")
print(f"[SaturnNodes PersistentQueue] Error saving persistent queue file: {e}")
def add_item(self, item_tuple):
if self.is_restoring or not is_persistent_queue_enabled():
@@ -252,9 +300,9 @@ class PersistentQueueManager:
self.persistent_items = [x for x in self.persistent_items if str(x.get("prompt_id")) != pid_str]
self.persistent_items.append(entry)
self.save_to_file()
print(f"[PersistentQueue] Persisted prompt {pid_str} to disk.")
print(f"[SaturnNodes PersistentQueue] Persisted prompt {pid_str} to disk.")
except Exception as e:
print(f"[PersistentQueue] Error formatting queue item for persistence: {e}")
print(f"[SaturnNodes PersistentQueue] Error formatting queue item for persistence: {e}")
def remove_item(self, prompt_id):
if not prompt_id:
@@ -267,7 +315,7 @@ class PersistentQueueManager:
changed = len(self.persistent_items) != initial_count
if changed and is_persistent_queue_enabled():
self.save_to_file()
print(f"[PersistentQueue] Removed prompt {pid_str} from disk.")
print(f"[SaturnNodes PersistentQueue] Removed prompt {pid_str} from disk.")
def wipe_all(self):
with self.lock:
@@ -275,7 +323,7 @@ class PersistentQueueManager:
self.batch_meta = {}
if is_persistent_queue_enabled():
self.save_to_file()
print("[PersistentQueue] Cleared all saved queue items.")
print("[SaturnNodes PersistentQueue] Cleared all saved queue items.")
def patch_server(self):
if self._patched:
@@ -361,14 +409,13 @@ class PersistentQueueManager:
server.send_sync = patched_send_sync
self._patched = True
print("[SaturnNodes] Queue control: Persistent queue manager initialized successfully.")
def restore_queue(self, active_client_id=None):
if self.has_claimed_once:
return
if not is_persistent_queue_enabled():
print("[PersistentQueue] Auto-recovery is disabled in settings.")
print("[SaturnNodes PersistentQueue] Auto-recovery is disabled in settings.")
self.has_claimed_once = True
return
@@ -383,7 +430,7 @@ class PersistentQueueManager:
elif restored_state_setting == "Force Running":
pause_manager.set_pause(False)
print(f"[PersistentQueue] Restoring {len(self.persistent_items)} saved queue item(s) to client '{active_client_id}'...")
print(f"[SaturnNodes PersistentQueue] Restoring {len(self.persistent_items)} saved queue item(s) to client '{active_client_id}'...")
self.is_restoring = True
max_number = 0
restored_count = 0
@@ -404,8 +451,11 @@ class PersistentQueueManager:
self.remove_item(pid)
continue
if active_client_id and len(item_list) > 3 and isinstance(item_list[3], dict):
item_list[3]["client_id"] = active_client_id
if len(item_list) > 3 and isinstance(item_list[3], dict):
if active_client_id:
item_list[3]["client_id"] = active_client_id
# Update create_time to current timestamp so resumed jobs sort as newest in history & assets
item_list[3]["create_time"] = int(time.time() * 1000)
if isinstance(item_list[0], (int, float)):
max_number = max(max_number, int(item_list[0]))
@@ -413,7 +463,7 @@ class PersistentQueueManager:
server.prompt_queue.put(tuple(item_list))
restored_count += 1
except Exception as e:
print(f"[PersistentQueue] Error restoring prompt {entry.get('prompt_id')}: {e}")
print(f"[SaturnNodes PersistentQueue] Error restoring prompt {entry.get('prompt_id')}: {e}")
finally:
self.is_restoring = False
self.has_claimed_once = True
@@ -465,7 +515,7 @@ class PowerControlManager:
with self.lock:
if action in ["restart", "shutdown"]:
if not is_process_management_enabled():
print(f"[SaturnNodes Power] Arm rejected: Process Management is disabled in LeafFlow settings.")
print(f"[SaturnNodes Power] Arm rejected: Process Management is disabled in SaturnNodes settings.")
return False
self.pending_action = action
import time
@@ -530,7 +580,7 @@ class PowerControlManager:
def execute_restart(self):
if not is_process_management_enabled():
print("[SaturnNodes Power] Rejected restart: Process Management is disabled in LeafFlow settings.")
print("[SaturnNodes Power] Rejected restart: Process Management is disabled in SaturnNodes settings.")
return False
def _run():
@@ -543,25 +593,47 @@ class PowerControlManager:
cmd.extend(sys.argv)
cwd = os.getcwd()
env = os.environ.copy()
if sys.platform.startswith("win"):
creationflags = subprocess.CREATE_NEW_CONSOLE if hasattr(subprocess, "CREATE_NEW_CONSOLE") else 0
subprocess.Popen(cmd, cwd=cwd, env=env, creationflags=creationflags)
else:
subprocess.Popen(cmd, cwd=cwd, env=env, start_new_session=True)
time.sleep(0.4)
proc = None
try:
if sys.platform.startswith("win"):
creationflags = subprocess.CREATE_NEW_CONSOLE if hasattr(subprocess, "CREATE_NEW_CONSOLE") else 0
proc = subprocess.Popen(cmd, cwd=cwd, env=env, creationflags=creationflags)
else:
proc = subprocess.Popen(cmd, cwd=cwd, env=env, start_new_session=True)
except Exception as e:
print(f"[SaturnNodes Power] Error spawning restart process: {e}")
self._executing = False
return
time.sleep(0.5)
if proc is not None and proc.poll() is not None:
print(f"[SaturnNodes Power] Child process exited prematurely with code {proc.returncode}. Aborting restart.")
self._executing = False
return
try:
sys.stdout.flush()
sys.stderr.flush()
except Exception:
pass
os._exit(0)
threading.Thread(target=_run, daemon=True).start()
return True
def execute_shutdown(self):
if not is_process_management_enabled():
print("[SaturnNodes Power] Rejected shutdown: Process Management is disabled in LeafFlow settings.")
print("[SaturnNodes Power] Rejected shutdown: Process Management is disabled in SaturnNodes settings.")
return False
def _run():
import os, time
import sys, os, time
print("[SaturnNodes Power] Shutting down ComfyUI server...")
time.sleep(0.6)
try:
sys.stdout.flush()
sys.stderr.flush()
except Exception:
pass
os._exit(0)
threading.Thread(target=_run, daemon=True).start()
return True
@@ -597,6 +669,7 @@ def _consume_power_ticket(ticket, expected_action=None):
pause_manager = PauseQueueManager()
persistent_manager = PersistentQueueManager()
persistent_queue_manager = persistent_manager
tray_manager = TrayIconManager(pause_manager)
power_manager = PowerControlManager(pause_manager)
@@ -763,7 +836,7 @@ def setup_queue_control_routes(server):
return web.json_response({"error": str(e)}, status=400)
return web.json_response({"success": False}, status=400)
@routes.get("/pause_queue/status")
@routes.get("/saturnnodes/pause_queue/status")
async def get_status(request):
if not is_local_request(request):
return web.json_response({"error": "Forbidden: Local access only"}, status=403)
@@ -774,7 +847,7 @@ def setup_queue_control_routes(server):
"waiting": pause_manager.is_waiting
})
@routes.post("/pause_queue/toggle")
@routes.post("/saturnnodes/pause_queue/toggle")
async def toggle_pause(request):
if not is_authenticated_local_request(request):
return web.json_response({"error": "Forbidden: Local authenticated access only"}, status=403)
@@ -791,7 +864,7 @@ def setup_queue_control_routes(server):
"waiting": pause_manager.is_waiting
})
@routes.post("/pause_queue/mode")
@routes.post("/saturnnodes/pause_queue/mode")
async def set_mode_route(request):
if not is_authenticated_local_request(request):
return web.json_response({"error": "Forbidden: Local authenticated access only"}, status=403)
@@ -807,7 +880,7 @@ def setup_queue_control_routes(server):
"waiting": pause_manager.is_waiting
})
@routes.post("/pause_queue/continue")
@routes.post("/saturnnodes/pause_queue/continue")
async def continue_queue(request):
if not is_authenticated_local_request(request):
return web.json_response({"error": "Forbidden: Local authenticated access only"}, status=403)
@@ -818,7 +891,7 @@ def setup_queue_control_routes(server):
"waiting": pause_manager.is_waiting
})
@routes.post("/persistent_queue/claim")
@routes.post("/saturnnodes/persistent_queue/claim")
async def claim_queue(request):
if not is_authenticated_local_request(request):
return web.json_response({"error": "Forbidden: Local authenticated access only"}, status=403)
@@ -828,5 +901,5 @@ def setup_queue_control_routes(server):
if client_id and not persistent_manager.has_claimed_once:
persistent_manager.restore_queue(client_id)
except Exception as e:
print(f"[PersistentQueue] Error in claim endpoint: {e}")
print(f"[SaturnNodes PersistentQueue] Error in claim endpoint: {e}")
return web.json_response({"status": "ok"})
+476
View File
@@ -0,0 +1,476 @@
import os
import urllib.request
import torch
import torch.nn.functional as F
import numpy as np
try:
import folder_paths
except ImportError:
folder_paths = None
# Global ONNX runtime session cache & predicted depth cache
_DEPTH_ORT_SESSION = None
_PREDICTED_DEPTH_CACHE = {}
def get_depth_model_path():
"""Returns local path to Depth Anything V2 Small ONNX model."""
if folder_paths and hasattr(folder_paths, "models_dir") and folder_paths.models_dir:
base_dir = os.path.join(folder_paths.models_dir, "depth")
else:
base_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "models")
os.makedirs(base_dir, exist_ok=True)
return os.path.join(base_dir, "depth-anything-v2-small-518.onnx")
def ensure_depth_model():
"""Downloads Depth Anything V2 Small ONNX model if not already present."""
target_path = get_depth_model_path()
if os.path.exists(target_path) and os.path.getsize(target_path) > 10 * 1024 * 1024:
return target_path
temp_path = target_path + ".tmp"
urls = [
"https://huggingface.co/onnx-community/depth-anything-v2-small/resolve/main/onnx/model.onnx",
"https://nqrlabs.com/Stereonix/models/depth-anything-v2-small-518.onnx"
]
print("[SaturnNodes 3D] Downloading Depth Anything V2 Small model (~94 MB)...")
for url in urls:
try:
req = urllib.request.Request(url, headers={"User-Agent": "ComfyUI-SaturnNodes"})
with urllib.request.urlopen(req, timeout=60) as resp, open(temp_path, "wb") as f:
total_size = int(resp.headers.get("Content-Length", 0))
downloaded = 0
last_pct = 0
while True:
chunk = resp.read(1024 * 1024 * 2)
if not chunk:
break
f.write(chunk)
downloaded += len(chunk)
if total_size > 0:
pct = int((downloaded / total_size) * 100)
if pct >= last_pct + 25 or pct == 100:
print(f"[SaturnNodes 3D] Model download: {pct}% ({downloaded // (1024*1024)}MB / {total_size // (1024*1024)}MB)")
last_pct = pct
if os.path.exists(temp_path) and os.path.getsize(temp_path) > 10 * 1024 * 1024:
os.replace(temp_path, target_path)
print(f"[SaturnNodes 3D] Successfully downloaded Depth Anything V2 to {target_path}")
return target_path
except Exception as e:
print(f"[SaturnNodes 3D] Download error from {url}: {e}")
if os.path.exists(temp_path):
try:
os.remove(temp_path)
except OSError:
pass
raise RuntimeError("Failed to download Depth Anything V2 Small ONNX model.")
def get_ort_session():
"""Retrieves or loads the ONNX runtime session for depth estimation."""
global _DEPTH_ORT_SESSION
if _DEPTH_ORT_SESSION is not None:
return _DEPTH_ORT_SESSION
try:
import onnxruntime as ort
except ImportError:
raise RuntimeError("onnxruntime is required for built-in depth estimation. Install via: pip install onnxruntime")
model_path = ensure_depth_model()
available_providers = ort.get_available_providers()
providers = ["CUDAExecutionProvider", "CPUExecutionProvider"] if "CUDAExecutionProvider" in available_providers else ["CPUExecutionProvider"]
_DEPTH_ORT_SESSION = ort.InferenceSession(model_path, providers=providers)
return _DEPTH_ORT_SESSION
def predict_depth_map(image_np):
"""
Runs Depth Anything V2 Small on a single [H, W, 3] float32 image (0.0 to 1.0).
Returns [H, W] normalized float32 depth map (0.0=far, 1.0=near).
If onnxruntime or the model is unavailable, gracefully falls back to a pseudo-depth map.
"""
H, W, _ = image_np.shape
try:
session = get_ort_session()
if session is None:
raise RuntimeError("ONNX runtime session could not be initialized.")
target_size = 518
scale = min(target_size / W, target_size / H)
scaled_w = max(1, int(round(W * scale)))
scaled_h = max(1, int(round(H * scale)))
offset_x = (target_size - scaled_w) // 2
offset_y = (target_size - scaled_h) // 2
# Letterbox to 518x518 with black padding using PIL
from PIL import Image
uint_img = (image_np * 255.0).clip(0, 255).astype(np.uint8)
scaled_pil = Image.fromarray(uint_img).resize((scaled_w, scaled_h), Image.Resampling.BILINEAR)
scaled_img = np.array(scaled_pil, dtype=np.uint8)
canvas = np.zeros((target_size, target_size, 3), dtype=np.uint8)
canvas[offset_y:offset_y + scaled_h, offset_x:offset_x + scaled_w] = scaled_img
# Normalize with ImageNet constants
mean = np.array([0.485, 0.456, 0.406], dtype=np.float32).reshape(1, 1, 3)
std = np.array([0.229, 0.224, 0.225], dtype=np.float32).reshape(1, 1, 3)
norm = ((canvas.astype(np.float32) / 255.0) - mean) / std
input_tensor = np.transpose(norm, (2, 0, 1))[np.newaxis, ...].astype(np.float32)
# Run inference
input_name = session.get_inputs()[0].name
raw_depth = session.run(None, {input_name: input_tensor})[0][0] # [518, 518]
# Crop out the letterbox padding and resize back to original (W, H)
valid_depth = raw_depth[offset_y:offset_y + scaled_h, offset_x:offset_x + scaled_w]
depth_pil = Image.fromarray(valid_depth.astype(np.float32), mode="F").resize((W, H), Image.Resampling.BILINEAR)
depth_full = np.array(depth_pil, dtype=np.float32)
# Normalize with p2 and p98 histogram percentiles
p2 = np.percentile(depth_full, 2)
p98 = np.percentile(depth_full, 98)
denom = max(float(p98 - p2), 1e-6)
depth_norm = np.clip((depth_full - p2) / denom, 0.0, 1.0).astype(np.float32)
return depth_norm
except Exception as e:
print(f"[SaturnNodes 3D] Notice: Automatic depth model unavailable ({e}). Using pseudo-depth gradient fallback.")
y_gradient = np.linspace(0.2, 1.0, H, dtype=np.float32).reshape(H, 1)
luminance = np.dot(image_np[..., :3], [0.299, 0.587, 0.114])
fallback = 0.7 * y_gradient + 0.3 * luminance
denom = max(float(fallback.max() - fallback.min()), 1e-6)
return ((fallback - fallback.min()) / denom).astype(np.float32)
def draw_alignment_dot(target_tensor, cx, cy, radius=5):
"""Draws a high-contrast white dot with black outline at (cx, cy) on [H, W, 3] tensor."""
H, W, _ = target_tensor.shape
y_min = max(0, cy - radius - 2)
y_max = min(H, cy + radius + 3)
x_min = max(0, cx - radius - 2)
x_max = min(W, cx + radius + 3)
if y_max <= y_min or x_max <= x_min:
return
yy, xx = torch.meshgrid(
torch.arange(y_min, y_max, device=target_tensor.device),
torch.arange(x_min, x_max, device=target_tensor.device),
indexing="ij"
)
dist_sq = (xx - cx) ** 2 + (yy - cy) ** 2
inner = dist_sq <= (radius ** 2)
outer = (dist_sq <= ((radius + 1.5) ** 2)) & (~inner)
target_tensor[yy[outer], xx[outer]] = 0.0
target_tensor[yy[inner], xx[inner]] = 1.0
class SaturnStereo3D:
"""
🪐 Stereoscopic 3D / Cross-Eye Generator
Generates side-by-side 3D stereograms, parallel views, and red-cyan anaglyphs
from 2D images using depth-based horizontal disparity mapping.
Includes built-in Depth Anything V2 Small auto-inference, zoom & pan cropping,
spacing/border padding, and alignment guide dots.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE",),
"mode": ([
"Cross-Eye",
"Parallel (Wall-Eyed)",
"Red-Cyan Anaglyph",
"Side-by-Side (Parallel)",
"Top-Bottom (Over-Under)",
"Left Eye Only",
"Right Eye Only"
], {"default": "Cross-Eye"}),
"depth_intensity": ("FLOAT", {
"default": 25.0, "min": 0.0, "max": 100.0, "step": 1.0,
"display": "slider",
"tooltip": "Controls how much the left and right perspectives shift apart."
}),
"depth_gamma": ("FLOAT", {
"default": 0.50, "min": 0.1, "max": 3.0, "step": 0.05,
"display": "slider",
"tooltip": "Adjust depth curve for realistic 3D falloff (Stereonix default is 0.50)."
}),
"invert_depth": ("BOOLEAN", {
"default": False,
"tooltip": "Flip which parts appear closer or further away."
}),
"convergence_plane": ("FLOAT", {
"default": 0.50, "min": 0.0, "max": 1.0, "step": 0.02,
"display": "slider",
"tooltip": "Depth level where parallax is zero (screen surface). Above pops out, below sinks in."
}),
"image_zoom": ("FLOAT", {
"default": 100.0, "min": 10.0, "max": 300.0, "step": 1.0,
"display": "slider",
"tooltip": "Zoom into areas of interest before generating 3D disparity."
}),
"pan_horizontal": ("FLOAT", {
"default": 0.0, "min": -100.0, "max": 100.0, "step": 1.0,
"display": "slider",
"tooltip": "Horizontal pan offset (-100 to 100)."
}),
"pan_vertical": ("FLOAT", {
"default": 0.0, "min": -100.0, "max": 100.0, "step": 1.0,
"display": "slider",
"tooltip": "Vertical pan offset (-100 to 100)."
}),
"gap_spacing": ("INT", {
"default": 20, "min": 0, "max": 1000, "step": 2,
"display": "number",
"tooltip": "Empty black space between the left and right images."
}),
"outer_border": ("INT", {
"default": 0, "min": 0, "max": 1000, "step": 2,
"display": "number",
"tooltip": "Black border padding around the canvas (allows shrinking images for easier cross-eye viewing)."
}),
"alignment_dots": ("BOOLEAN", {
"default": True,
"tooltip": "Place focus guide dots above each eye view to easily lock into 3D cross-eye view."
}),
"fill_method": ([
"Smooth (Bilinear Grid)",
"Nearest Neighbor (Stereonix)"
], {
"default": "Smooth (Bilinear Grid)",
"tooltip": "Hole-filling interpolation for occlusion gaps."
}),
"preview_zoom": ([
"Fit",
"25%",
"33%",
"50%",
"75%",
"100%"
], {
"default": "50%",
"tooltip": "Scale preview for easier cross-eye viewing on canvas (does not affect full output)."
}),
},
"optional": {
"depth_map": ("IMAGE", {
"tooltip": "Optional depth map. If disconnected, automatically runs Depth Anything V2."
}),
}
}
RETURN_TYPES = ("IMAGE", "IMAGE", "IMAGE", "IMAGE")
RETURN_NAMES = ("stereogram", "left_eye", "right_eye", "depth_map")
FUNCTION = "generate"
CATEGORY = "🪐 SaturnNodes/3D & Previews"
DESCRIPTION = (
"Creates side-by-side cross-eye stereograms, parallel 3D views, and red-cyan anaglyphs "
"from 2D images. Inspired by Stereonix, it includes automatic Depth Anything V2 Small fallback, "
"custom depth gamma/inversion, zoom & pan cropping, adjustable gap/border spacing, and focus alignment dots."
)
@torch.no_grad()
def generate(
self,
image,
mode="Cross-Eye",
depth_intensity=25.0,
depth_gamma=0.50,
invert_depth=False,
convergence_plane=0.50,
image_zoom=100.0,
pan_horizontal=0.0,
pan_vertical=0.0,
gap_spacing=20,
outer_border=0,
alignment_dots=True,
fill_method="Smooth (Bilinear Grid)",
preview_zoom="50%",
depth_map=None,
**kwargs
):
device = image.device
B, H, W, C = image.shape
# 1. Obtain or generate depth map
depth_tensors = []
if depth_map is not None:
# Handle incoming depth map tensor
d_map = depth_map.to(device=device, dtype=torch.float32)
if d_map.shape[1:3] != (H, W):
d_perm = d_map.permute(0, 3, 1, 2) if d_map.dim() == 4 else d_map.unsqueeze(1)
d_resized = F.interpolate(d_perm, size=(H, W), mode="bilinear", align_corners=False)
d_map = d_resized.permute(0, 2, 3, 1) if d_map.dim() == 4 else d_resized.squeeze(1)
if d_map.dim() == 4:
d_tensor = d_map[..., 0] # take single channel
else:
d_tensor = d_map
# Normalize 0 to 1
for b in range(B):
b_depth = d_tensor[b if b < d_tensor.shape[0] else 0]
min_v = b_depth.min()
max_v = b_depth.max()
denom = max(float(max_v - min_v), 1e-6)
depth_norm = torch.clamp((b_depth - min_v) / denom, 0.0, 1.0)
depth_tensors.append(depth_norm)
else:
# Automatic Depth Estimation via Depth Anything V2 Small ONNX (cached for instant slider responsiveness)
cpu_img = image.detach().cpu().numpy()
for b in range(B):
# Fast signature based on shape, sum, and corner samples
img_slice = cpu_img[b]
cache_key = (
img_slice.shape,
round(float(img_slice.sum()), 2),
round(float(img_slice[0, 0, 0]), 4),
round(float(img_slice[-1, -1, -1]), 4)
)
if cache_key in _PREDICTED_DEPTH_CACHE:
d_np = _PREDICTED_DEPTH_CACHE[cache_key]
else:
d_np = predict_depth_map(img_slice)
while len(_PREDICTED_DEPTH_CACHE) >= 16:
_PREDICTED_DEPTH_CACHE.pop(next(iter(_PREDICTED_DEPTH_CACHE)))
_PREDICTED_DEPTH_CACHE[cache_key] = d_np
depth_tensors.append(torch.from_numpy(d_np).to(device=device, dtype=torch.float32))
depth_batch = torch.stack(depth_tensors, dim=0) # [B, H, W]
# 2. Apply Invert & Depth Gamma
if invert_depth:
depth_batch = 1.0 - depth_batch
if abs(depth_gamma - 1.0) > 1e-4:
depth_batch = torch.pow(torch.clamp(depth_batch, 1e-6, 1.0), depth_gamma)
# 3. Apply Zoom & Pan cropping if requested
zoom_factor = max(0.1, float(image_zoom) / 100.0)
pan_x_norm = float(pan_horizontal) / 100.0
pan_y_norm = float(pan_vertical) / 100.0
grid_y = torch.linspace(-1, 1, H, device=device).view(1, H, 1, 1).expand(B, H, W, 1)
grid_x = torch.linspace(-1, 1, W, device=device).view(1, 1, W, 1).expand(B, H, W, 1)
if abs(zoom_factor - 1.0) > 1e-4 or abs(pan_x_norm) > 1e-4 or abs(pan_y_norm) > 1e-4:
crop_x = (grid_x - pan_x_norm) / zoom_factor
crop_y = (grid_y - pan_y_norm) / zoom_factor
crop_grid = torch.cat([crop_x, crop_y], dim=-1)
img_perm = image.permute(0, 3, 1, 2)
d_perm = depth_batch.unsqueeze(1)
image_cropped = F.grid_sample(img_perm, crop_grid, mode="bilinear", padding_mode="zeros", align_corners=True).permute(0, 2, 3, 1)
depth_cropped = F.grid_sample(d_perm, crop_grid, mode="bilinear", padding_mode="border", align_corners=True).squeeze(1)
else:
image_cropped = image
depth_cropped = depth_batch
# 4. Compute Parallax Shift (Horizontal Disparity)
# Shift magnitude scales with image width: at intensity 100, maximum shift is 3.5% of width
max_shift = (float(depth_intensity) / 100.0) * (W * 0.035)
# Shift relative to convergence plane
shift_px = (depth_cropped - float(convergence_plane)) * max_shift
shift_norm = (shift_px * (2.0 / W)).unsqueeze(-1) # [B, H, W, 1]
# 5. Generate Left and Right eye views
grid_left = torch.cat([grid_x - shift_norm, grid_y], dim=-1)
grid_right = torch.cat([grid_x + shift_norm, grid_y], dim=-1)
img_in = image_cropped.permute(0, 3, 1, 2)
if fill_method == "Nearest Neighbor (Stereonix)":
# Backward warp with nearest-neighbor lookup matching classic Stereonix
left_eye = F.grid_sample(img_in, grid_left, mode="nearest", padding_mode="border", align_corners=True).permute(0, 2, 3, 1)
right_eye = F.grid_sample(img_in, grid_right, mode="nearest", padding_mode="border", align_corners=True).permute(0, 2, 3, 1)
else:
# Smooth bilinear grid sampling
left_eye = F.grid_sample(img_in, grid_left, mode="bilinear", padding_mode="border", align_corners=True).permute(0, 2, 3, 1)
right_eye = F.grid_sample(img_in, grid_right, mode="bilinear", padding_mode="border", align_corners=True).permute(0, 2, 3, 1)
# 6. Composite according to Selected Mode
if mode == "Left Eye Only":
stereogram = left_eye
elif mode == "Right Eye Only":
stereogram = right_eye
elif mode == "Red-Cyan Anaglyph":
# Red channel from Left Eye, Cyan (Green + Blue) channels from Right Eye
stereogram = torch.zeros_like(left_eye)
stereogram[..., 0] = left_eye[..., 0]
stereogram[..., 1] = right_eye[..., 1]
stereogram[..., 2] = right_eye[..., 2]
elif mode == "Top-Bottom (Over-Under)":
gap_h = max(0, int(gap_spacing))
border = max(0, int(outer_border))
top_panel = left_eye
bot_panel = right_eye
if gap_h > 0:
gap_row = torch.zeros((B, gap_h, W, C), device=device, dtype=torch.float32)
stacked = torch.cat([top_panel, gap_row, bot_panel], dim=1)
else:
stacked = torch.cat([top_panel, bot_panel], dim=1)
if border > 0:
H_st, W_st = stacked.shape[1], stacked.shape[2]
stereogram = torch.zeros((B, H_st + border * 2, W_st + border * 2, C), device=device, dtype=torch.float32)
stereogram[:, border:border + H_st, border:border + W_st, :] = stacked
else:
stereogram = stacked
else:
# Side-by-Side: Cross-Eye vs Parallel
# In Cross-Eye: Left panel is Right-Eye, Right panel is Left-Eye
# In Parallel / Side-by-Side: Left panel is Left-Eye, Right panel is Right-Eye
if mode == "Cross-Eye":
panel_left = right_eye
panel_right = left_eye
else:
panel_left = left_eye
panel_right = right_eye
gap_w = max(0, int(gap_spacing))
border = max(0, int(outer_border))
if gap_w > 0:
gap_col = torch.zeros((B, H, gap_w, C), device=device, dtype=torch.float32)
side_by_side = torch.cat([panel_left, gap_col, panel_right], dim=2)
else:
side_by_side = torch.cat([panel_left, panel_right], dim=2)
# Apply outer border framing
if border > 0:
H_sbs, W_sbs = side_by_side.shape[1], side_by_side.shape[2]
stereogram = torch.zeros((B, H_sbs + border * 2, W_sbs + border * 2, C), device=device, dtype=torch.float32)
stereogram[:, border:border + H_sbs, border:border + W_sbs, :] = side_by_side
else:
stereogram = side_by_side
# Add alignment guide dots
if alignment_dots and (mode in ("Cross-Eye", "Parallel (Wall-Eyed)", "Side-by-Side (Parallel)")):
# Center coordinates above left and right panels
cx_left = border + (W // 2)
cx_right = border + W + gap_w + (W // 2)
cy_dot = border // 2 if border >= 18 else min(16, H // 12)
dot_radius = max(4, min(8, W // 100))
for b in range(B):
draw_alignment_dot(stereogram[b], cx_left, cy_dot, radius=dot_radius)
draw_alignment_dot(stereogram[b], cx_right, cy_dot, radius=dot_radius)
# 7. Convert Depth to 3-channel image for output
depth_output = depth_cropped.unsqueeze(-1).repeat(1, 1, 1, 3)
try:
import comfy.model_management
comfy.model_management.soft_empty_cache()
except Exception:
pass
return (stereogram, left_eye, right_eye, depth_output)
+1 -1
View File
@@ -88,6 +88,6 @@ class MultiTextReplacer:
replaced_count += count
result_text = re.sub(pattern_str, lambda m: replace, result_text, flags=flags)
except Exception as e:
print(f"[SaturnNodes] 🍃 Invalid regex pattern '{pattern_str}': {e}")
print(f"[SaturnNodes] Invalid regex pattern '{pattern_str}': {e}")
return (result_text, replaced_count)
-3
View File
@@ -85,6 +85,3 @@ class SaturnTextSplit:
t2 = t2.strip()
return (t1, t2)
LeafFlowTextSplit = SaturnTextSplit
SaturnTextSplit = SaturnTextSplit
+1 -2
View File
@@ -3,7 +3,7 @@ import sys
import threading
import webbrowser
from PIL import Image, ImageDraw
from .utils import get_saturnnodes_user_dir, get_leafflow_user_dir
from .utils import get_saturnnodes_user_dir
USER_DIR = get_saturnnodes_user_dir()
ENV_FILE = os.path.join(USER_DIR, ".env")
@@ -195,7 +195,6 @@ class TrayIconManager:
def _run():
try:
self._is_running = True
print("[SaturnNodes] System tray icon started.")
self._icon.run()
except Exception as e:
print(f"[SaturnNodes] System tray icon error: {e}")
+11 -25
View File
@@ -7,7 +7,6 @@ import folder_paths
def get_saturnnodes_user_dir():
"""
Returns the centralized user data directory: ComfyUI/user/default/SaturnNodes/
Automatically migrates any legacy LeafFlow directory contents if present.
"""
base_user = None
try:
@@ -28,24 +27,8 @@ def get_saturnnodes_user_dir():
saturn_dir = os.path.join(base_user, "SaturnNodes")
os.makedirs(saturn_dir, exist_ok=True)
# Seamless automatic migration from legacy LeafFlow folder if needed
legacy_dir = os.path.join(base_user, "LeafFlow")
if os.path.isdir(legacy_dir):
for f in [".env", "prompt_iterator_state.json"]:
src = os.path.join(legacy_dir, f)
dst = os.path.join(saturn_dir, f)
if os.path.isfile(src) and not os.path.exists(dst):
try:
import shutil
shutil.copy2(src, dst)
except Exception:
pass
return saturn_dir
get_leafflow_user_dir = get_saturnnodes_user_dir
_SESSION_CSRF_TOKEN = secrets.token_hex(32)
def get_csrf_token():
@@ -81,7 +64,7 @@ def is_same_origin_or_direct(request):
try:
parsed_ref = urlparse(referer)
ref_host = parsed_ref.hostname
if ref_host not in ["127.0.0.1", "localhost", "::1", "0.0.0.0", "testclient"]:
if ref_host not in ["127.0.0.1", "localhost", "::1", "0.0.0.0", "testclient", "::ffff:127.0.0.1"]:
return False
except Exception:
return False
@@ -93,7 +76,7 @@ def is_authenticated_local_request(request):
Guarantees user-initiated actions and protects against CSRF / drive-by requests from open browser tabs:
1. Originates strictly from loopback IP (is_local_request)
2. Not a cross-site drive-by request (is_same_origin_or_direct)
3. Contains a valid X-LeafFlow-CSRF-Token header matching the session secret.
3. Contains a valid X-SaturnNodes-CSRF-Token header matching the session secret.
"""
if not is_local_request(request):
return False
@@ -101,7 +84,7 @@ def is_authenticated_local_request(request):
return False
headers = getattr(request, "headers", {})
token = headers.get("X-SaturnNodes-CSRF-Token") or headers.get("X-LeafFlow-CSRF-Token")
token = headers.get("X-SaturnNodes-CSRF-Token")
if not token or not secrets.compare_digest(token, _SESSION_CSRF_TOKEN):
return False
@@ -109,7 +92,7 @@ def is_authenticated_local_request(request):
def is_local_request(request):
"""
Returns True if the HTTP request originates strictly from loopback (localhost / 127.0.0.1 / ::1).
Returns True if the HTTP request originates strictly from loopback (localhost / 127.0.0.1 / ::1 / ::ffff:127.0.0.1).
Used to protect sensitive endpoints (power control, system settings, file browsing).
"""
if request is None:
@@ -123,12 +106,15 @@ def is_local_request(request):
remote = peername[0]
if not remote:
return False
local_hosts = {"127.0.0.1", "::1", "localhost", "0.0.0.0", "testclient"}
if remote in local_hosts:
clean_remote = str(remote).strip("[]")
if ":" in clean_remote and clean_remote.count(":") == 1:
clean_remote = clean_remote.split(":")[0]
local_hosts = {"127.0.0.1", "::1", "localhost", "0.0.0.0", "testclient", "::ffff:127.0.0.1"}
if clean_remote in local_hosts or remote in local_hosts:
return True
try:
import ipaddress
ip = ipaddress.ip_address(remote)
ip = ipaddress.ip_address(clean_remote)
return ip.is_loopback
except Exception:
return False
@@ -232,7 +218,7 @@ def sanitize_image_loader_folder(folder_input, default_to_output=True):
def get_env_setting(key, default_val):
"""
Reads a key setting from ComfyUI/user/default/LeafFlow/.env safely.
Reads a key setting from ComfyUI/user/default/SaturnNodes/.env safely.
"""
user_dir = get_saturnnodes_user_dir()
env_file = os.path.join(user_dir, ".env")
+12 -3
View File
@@ -1,18 +1,27 @@
[project]
name = "comfyui-saturnnodes"
name = "saturnnodes"
description = "Essential workflow controls, mid-generation pausing, real-time queue persistence, folder watcher, and visual model loaders for ComfyUI."
version = "2.4.1"
version = "2.6.1"
readme = "README.md"
license = "MIT"
license = { file = "LICENSE" }
requires-python = ">=3.10"
dependencies = ["pillow", "numpy", "piexif"]
classifiers = [
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
]
[project.optional-dependencies]
tray = ["pystray"]
stereogram = ["onnxruntime"]
[project.urls]
Repository = "https://github.com/KOFiblto/ComfyUI-SaturnNodes"
"Bug Tracker" = "https://github.com/KOFiblto/ComfyUI-SaturnNodes/issues"
Documentation = "https://github.com/KOFiblto/ComfyUI-SaturnNodes#readme"
[tool.comfy]
PublisherId = "KOFiblto"
DisplayName = "ComfyUI-SaturnNodes"
Icon = "https://raw.githubusercontent.com/KOFiblto/ComfyUI-SaturnNodes/main/web/logo.png"
requires-comfyui = ">=0.3.0"
+2
View File
@@ -2,3 +2,5 @@ Pillow
piexif
numpy
# pystray # Optional: install manually if desktop system tray icon integration is enabled
# onnxruntime # Optional: install manually for built-in Depth Anything V2 estimation in 3D stereogram nodes
+1 -1
View File
@@ -1,7 +1,7 @@
import os
import sys
# Ensure LeafFlow root is at index 0 in sys.path
# Ensure SaturnNodes root is at index 0 in sys.path
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if ROOT in sys.path:
sys.path.remove(ROOT)
+11 -11
View File
@@ -3,17 +3,17 @@ import sys
import types
from unittest.mock import MagicMock
LEAFFLOW_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SATURNNODES_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Ensure LeafFlow root is prioritized at the very start of sys.path
while LEAFFLOW_ROOT in sys.path:
sys.path.remove(LEAFFLOW_ROOT)
sys.path.insert(0, LEAFFLOW_ROOT)
# Ensure SaturnNodes root is prioritized at the very start of sys.path
while SATURNNODES_ROOT in sys.path:
sys.path.remove(SATURNNODES_ROOT)
sys.path.insert(0, SATURNNODES_ROOT)
# If 'nodes' in sys.modules is ComfyUI's root nodes.py file, replace it with LeafFlow's nodes package
# If 'nodes' in sys.modules is ComfyUI's root nodes.py file, replace it with SaturnNodes' nodes package
if "nodes" in sys.modules:
nodes_mod = sys.modules["nodes"]
if not hasattr(nodes_mod, "__path__") or not getattr(nodes_mod, "__file__", "").startswith(LEAFFLOW_ROOT):
if not hasattr(nodes_mod, "__path__") or not getattr(nodes_mod, "__file__", "").startswith(SATURNNODES_ROOT):
del sys.modules["nodes"]
# Provide lightweight mock stubs for ComfyUI environment if running in standalone CI / test runner
@@ -67,12 +67,12 @@ if "comfy" not in sys.modules:
if "folder_paths" not in sys.modules:
fp_mock = types.ModuleType("folder_paths")
fp_mock.get_input_directory = MagicMock(return_value=os.path.join(LEAFFLOW_ROOT, "input"))
fp_mock.get_output_directory = MagicMock(return_value=os.path.join(LEAFFLOW_ROOT, "output"))
fp_mock.get_temp_directory = MagicMock(return_value=os.path.join(LEAFFLOW_ROOT, "temp"))
fp_mock.get_input_directory = MagicMock(return_value=os.path.join(SATURNNODES_ROOT, "input"))
fp_mock.get_output_directory = MagicMock(return_value=os.path.join(SATURNNODES_ROOT, "output"))
fp_mock.get_temp_directory = MagicMock(return_value=os.path.join(SATURNNODES_ROOT, "temp"))
fp_mock.get_filename_list = MagicMock(return_value=[])
fp_mock.get_full_path = MagicMock(return_value="")
fp_mock.base_path = LEAFFLOW_ROOT
fp_mock.base_path = SATURNNODES_ROOT
sys.modules["folder_paths"] = fp_mock
if "server" not in sys.modules:
+108
View File
@@ -0,0 +1,108 @@
import os
import sys
import unittest
import torch
import numpy as np
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import test_helper
from nodes.stereogram import SaturnStereo3D
class TestSaturnStereo3D(unittest.TestCase):
def setUp(self):
self.node = SaturnStereo3D()
self.img = torch.rand((1, 128, 128, 3), dtype=torch.float32)
self.depth = torch.linspace(0, 1, 128).view(1, 1, 128).expand(1, 128, 128).unsqueeze(-1).repeat(1, 1, 1, 3)
def test_cross_eye_mode_dimensions(self):
# Image is 128x128. With gap=10, border=5:
# Side by side: 128 + 10 + 128 = 266 width.
# With border=5 on each side: Width = 266 + 10 = 276. Height = 128 + 10 = 138.
res = self.node.generate(
self.img,
depth_map=self.depth,
mode="Cross-Eye",
depth_intensity=30.0,
gap_spacing=10,
outer_border=5,
alignment_dots=True
)
stereogram, left_eye, right_eye, depth_out = res
self.assertEqual(stereogram.shape, (1, 138, 276, 3))
self.assertEqual(left_eye.shape, (1, 128, 128, 3))
self.assertEqual(right_eye.shape, (1, 128, 128, 3))
self.assertEqual(depth_out.shape, (1, 128, 128, 3))
def test_parallel_mode(self):
res = self.node.generate(
self.img,
depth_map=self.depth,
mode="Parallel (Wall-Eyed)",
depth_intensity=25.0,
gap_spacing=0,
outer_border=0,
alignment_dots=False
)
stereogram, _, _, _ = res
self.assertEqual(stereogram.shape, (1, 128, 256, 3))
def test_anaglyph_mode(self):
res = self.node.generate(
self.img,
depth_map=self.depth,
mode="Red-Cyan Anaglyph",
depth_intensity=25.0
)
stereogram, left_eye, right_eye, _ = res
self.assertEqual(stereogram.shape, (1, 128, 128, 3))
np.testing.assert_allclose(stereogram[..., 0].cpu().numpy(), left_eye[..., 0].cpu().numpy(), atol=1e-5)
np.testing.assert_allclose(stereogram[..., 1].cpu().numpy(), right_eye[..., 1].cpu().numpy(), atol=1e-5)
np.testing.assert_allclose(stereogram[..., 2].cpu().numpy(), right_eye[..., 2].cpu().numpy(), atol=1e-5)
def test_top_bottom_mode(self):
res = self.node.generate(
self.img,
depth_map=self.depth,
mode="Top-Bottom (Over-Under)",
gap_spacing=6,
outer_border=0
)
stereogram, _, _, _ = res
self.assertEqual(stereogram.shape, (1, 262, 128, 3))
def test_single_eye_modes(self):
res_left = self.node.generate(self.img, depth_map=self.depth, mode="Left Eye Only")
res_right = self.node.generate(self.img, depth_map=self.depth, mode="Right Eye Only")
self.assertEqual(res_left[0].shape, (1, 128, 128, 3))
self.assertEqual(res_right[0].shape, (1, 128, 128, 3))
def test_zoom_and_pan(self):
res = self.node.generate(
self.img,
depth_map=self.depth,
image_zoom=150.0,
pan_horizontal=20.0,
pan_vertical=-10.0
)
stereogram = res[0]
self.assertIsNotNone(stereogram)
self.assertEqual(stereogram.dim(), 4)
def test_auto_depth_fallback(self):
from unittest.mock import patch
with patch("nodes.stereogram.get_ort_session", side_effect=RuntimeError("onnxruntime unavailable")):
res = self.node.generate(
self.img,
depth_map=None,
mode="Cross-Eye",
depth_intensity=20.0
)
stereogram, _, _, depth_out = res
self.assertEqual(stereogram.shape[0], 1)
self.assertEqual(depth_out.shape, (1, 128, 128, 3))
if __name__ == "__main__":
unittest.main()
+6 -4
View File
@@ -26,6 +26,8 @@ class TestUtils(unittest.TestCase):
self.assertTrue(is_local_request(DummyReq("127.0.0.1")))
self.assertTrue(is_local_request(DummyReq("::1")))
self.assertTrue(is_local_request(DummyReq("localhost")))
self.assertTrue(is_local_request(DummyReq("::ffff:127.0.0.1")))
self.assertTrue(is_local_request(DummyReq("[::ffff:127.0.0.1]")))
self.assertFalse(is_local_request(DummyReq("192.168.1.50")))
self.assertFalse(is_local_request(DummyReq("10.0.0.1")))
self.assertFalse(is_local_request(DummyReq("8.8.8.8")))
@@ -65,7 +67,7 @@ class TestUtils(unittest.TestCase):
# Valid local request with matching token
valid_req = DummyReq("127.0.0.1", {
"Origin": "http://127.0.0.1:8188",
"X-LeafFlow-CSRF-Token": valid_token
"X-SaturnNodes-CSRF-Token": valid_token
})
self.assertTrue(is_authenticated_local_request(valid_req))
@@ -76,21 +78,21 @@ class TestUtils(unittest.TestCase):
# Wrong token
wrong_token_req = DummyReq("127.0.0.1", {
"Origin": "http://127.0.0.1:8188",
"X-LeafFlow-CSRF-Token": "invalid_forged_token"
"X-SaturnNodes-CSRF-Token": "invalid_forged_token"
})
self.assertFalse(is_authenticated_local_request(wrong_token_req))
# Remote IP attempting to forge or replay token
remote_req = DummyReq("192.168.1.100", {
"Origin": "http://127.0.0.1:8188",
"X-LeafFlow-CSRF-Token": valid_token
"X-SaturnNodes-CSRF-Token": valid_token
})
self.assertFalse(is_authenticated_local_request(remote_req))
# Cross-site drive-by request (Sec-Fetch-Site: cross-site)
drive_by_req = DummyReq("127.0.0.1", {
"Sec-Fetch-Site": "cross-site",
"X-LeafFlow-CSRF-Token": valid_token
"X-SaturnNodes-CSRF-Token": valid_token
})
self.assertFalse(is_authenticated_local_request(drive_by_req))
+38 -40
View File
@@ -43,17 +43,9 @@ const BATCH_COLORS = [
];
const STORAGE_KEY = "saturnnodes_batch_queue_meta";
const LEGACY_STORAGE_KEY = "leafflow_batch_queue_meta";
const BATCH_COUNTER_KEY = "saturnnodes_batch_counter";
const LEGACY_BATCH_COUNTER_KEY = "leafflow_batch_counter";
const SETTING_ID = "SaturnNodes.🎨 Batch Queue.01_ShowBatchLines";
const LEGACY_SETTING_ID_0 = "SaturnNodes.8 - 🎨 Batch Queue.01_ShowBatchLines";
const LEGACY_SETTING_ID_1 = "SaturnNodes.BatchQueue.Enabled";
const LEGACY_SETTING_ID_2 = "LeafFlow.BatchQueue.Enabled";
const SETTING_SNAPSHOT_GUARD = "SaturnNodes.🎨 Batch Queue.02_SnapshotGuard";
const LEGACY_SETTING_SNAPSHOT_GUARD_0 = "SaturnNodes.8 - 🎨 Batch Queue.02_SnapshotGuard";
const LEGACY_SETTING_SNAPSHOT_GUARD_1 = "SaturnNodes.BatchQueue.SnapshotGuard";
const LEGACY_SETTING_SNAPSHOT_GUARD_2 = "LeafFlow.BatchQueue.SnapshotGuard";
// In-memory registry mapping prompt_id -> batch metadata
let batchRegistry = new Map();
@@ -62,7 +54,7 @@ let batchCounter = 0;
function loadStorage() {
try {
const raw = localStorage.getItem(STORAGE_KEY) || localStorage.getItem(LEGACY_STORAGE_KEY);
const raw = localStorage.getItem(STORAGE_KEY);
if (raw) {
const parsed = JSON.parse(raw);
if (Array.isArray(parsed)) {
@@ -73,7 +65,7 @@ function loadStorage() {
}
}
}
const savedCounter = localStorage.getItem(BATCH_COUNTER_KEY) || localStorage.getItem(LEGACY_BATCH_COUNTER_KEY);
const savedCounter = localStorage.getItem(BATCH_COUNTER_KEY);
if (savedCounter) {
batchCounter = parseInt(savedCounter, 10) || 0;
}
@@ -115,14 +107,14 @@ function getNextBatch(batchCount = 1) {
// Inject CSS for the 1D git-graph style line
function injectBatchStyles() {
if (typeof document === "undefined") return;
const styleId = "leafflow-batch-queue-styles";
const styleId = "saturnnodes-batch-queue-styles";
if (document.getElementById(styleId)) return;
const style = document.createElement("style");
style.id = styleId;
style.textContent = `
/* LeafFlow 1D Git-Graph Batch Line Container */
.leafflow-batch-line-wrap {
/* SaturnNodes 1D Git-Graph Batch Line Container */
.saturnnodes-batch-line-wrap {
position: absolute;
left: -9px;
top: 0;
@@ -136,7 +128,7 @@ function injectBatchStyles() {
overflow: visible;
}
.leafflow-batch-line-svg {
.saturnnodes-batch-line-svg {
width: 100%;
height: 100%;
display: block;
@@ -183,16 +175,16 @@ function buildSvgPath(segmentType) {
function renderBatchLineOnElement(element, segmentType, color) {
if (!element) return;
let wrap = element.querySelector(".leafflow-batch-line-wrap");
let wrap = element.querySelector(".saturnnodes-batch-line-wrap");
if (!wrap) {
wrap = document.createElement("div");
wrap.className = "leafflow-batch-line-wrap";
wrap.className = "saturnnodes-batch-line-wrap";
element.appendChild(wrap);
}
const dPath = buildSvgPath(segmentType);
wrap.innerHTML = `
<svg class="leafflow-batch-line-svg" viewBox="0 0 10 48" preserveAspectRatio="none">
<svg class="saturnnodes-batch-line-svg" viewBox="0 0 10 48" preserveAspectRatio="none">
<path d="${dPath}" stroke="${color}" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" fill="none" />
</svg>
`;
@@ -200,7 +192,7 @@ function renderBatchLineOnElement(element, segmentType, color) {
function removeBatchLineFromElement(element) {
if (!element) return;
const wrap = element.querySelector(".leafflow-batch-line-wrap");
const wrap = element.querySelector(".saturnnodes-batch-line-wrap");
if (wrap) {
wrap.remove();
}
@@ -209,18 +201,13 @@ function removeBatchLineFromElement(element) {
// Check if SaturnNodes Batch Queue is enabled in settings
function isBatchQueueEnabled() {
try {
const keys = [SETTING_ID, LEGACY_SETTING_ID_0, LEGACY_SETTING_ID_1, LEGACY_SETTING_ID_2];
if (app.extensionManager?.setting?.get) {
for (const k of keys) {
const val = app.extensionManager.setting.get(k);
if (val !== undefined) return val !== false;
}
const val = app.extensionManager.setting.get(SETTING_ID);
if (val !== undefined) return val !== false;
}
if (app.ui?.settings?.get) {
for (const k of keys) {
const val = app.ui.settings.get(k);
if (val !== undefined) return val !== false;
}
const val = app.ui.settings.get(SETTING_ID);
if (val !== undefined) return val !== false;
}
} catch (e) {}
return true;
@@ -228,18 +215,13 @@ function isBatchQueueEnabled() {
function isSnapshotGuardEnabled() {
try {
const keys = [SETTING_SNAPSHOT_GUARD, LEGACY_SETTING_SNAPSHOT_GUARD_0, LEGACY_SETTING_SNAPSHOT_GUARD_1, LEGACY_SETTING_SNAPSHOT_GUARD_2];
if (app.extensionManager?.setting?.get) {
for (const k of keys) {
const val = app.extensionManager.setting.get(k);
if (val !== undefined) return val !== false;
}
const val = app.extensionManager.setting.get(SETTING_SNAPSHOT_GUARD);
if (val !== undefined) return val !== false;
}
if (app.ui?.settings?.get) {
for (const k of keys) {
const val = app.ui.settings.get(k);
if (val !== undefined) return val !== false;
}
const val = app.ui.settings.get(SETTING_SNAPSHOT_GUARD);
if (val !== undefined) return val !== false;
}
} catch (e) {}
return true;
@@ -288,11 +270,27 @@ function mergeDynamicSeeds(snapPrompt, livePrompt) {
if (!snapNode || snapNode.id === undefined) continue;
const liveWfNode = liveWorkflowMap.get(String(snapNode.id));
if (liveWfNode && Array.isArray(liveWfNode.widgets_values) && Array.isArray(snapNode.widgets_values)) {
const graphNode = app.graph?.getNodeById?.(snapNode.id) || app.graph?.getNodeById?.(Number(snapNode.id));
for (let i = 0; i < liveWfNode.widgets_values.length; i++) {
const liveVal = liveWfNode.widgets_values[i];
const snapVal = snapNode.widgets_values[i];
if (typeof liveVal === "number" && typeof snapVal === "number" && liveVal !== snapVal) {
snapNode.widgets_values[i] = liveVal;
const widgetName = graphNode?.widgets?.[i]?.name;
if (widgetName) {
if (isSeedInput(widgetName, liveVal)) {
snapNode.widgets_values[i] = liveVal;
}
} else {
const apiInputs = cloned.output?.[String(snapNode.id)]?.inputs;
if (apiInputs) {
for (const [k, v] of Object.entries(apiInputs)) {
if (v === liveVal && isSeedInput(k, v)) {
snapNode.widgets_values[i] = liveVal;
break;
}
}
}
}
}
}
}
@@ -300,7 +298,7 @@ function mergeDynamicSeeds(snapPrompt, livePrompt) {
}
return cloned;
} catch (e) {
console.warn("[LeafFlow BatchQueue] Error merging dynamic seeds into snapshot:", e);
console.warn("[SaturnNodes BatchQueue] Error merging dynamic seeds into snapshot:", e);
return snapPrompt;
}
}
@@ -342,7 +340,7 @@ async function loadBatchFromServer() {
// Refresh visual lines in DOM for both v1 and v2
async function updateQueueBatchVisuals() {
if (!isBatchQueueEnabled()) {
document.querySelectorAll(".leafflow-batch-line-wrap").forEach(el => el.remove());
document.querySelectorAll(".saturnnodes-batch-line-wrap").forEach(el => el.remove());
return;
}
@@ -460,7 +458,7 @@ function setupQueueHooks() {
try {
activeBatchContext.snapshotPrompt = JSON.parse(JSON.stringify(prompt));
} catch (e) {
console.warn("[LeafFlow BatchQueue] Failed to snapshot prompt:", e);
console.warn("[SaturnNodes BatchQueue] Failed to snapshot prompt:", e);
}
} else if (activeBatchContext.snapshotPrompt) {
promptToSend = mergeDynamicSeeds(activeBatchContext.snapshotPrompt, prompt);
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -38,13 +38,12 @@ export async function authenticatedFetch(endpoint, options = {}) {
return api.fetchApi(endpoint, opts);
}
// Expose on window for all SaturnNodes extensions (with LeafFlow alias for backward compatibility)
// Expose on window for all SaturnNodes extensions
if (typeof window !== "undefined") {
const authObj = {
getToken: getCsrfToken,
fetch: authenticatedFetch
};
window._SaturnNodesAuth = authObj;
window._LeafFlowAuth = authObj;
}
+53 -49
View File
@@ -11,7 +11,7 @@ async function copyToClipboard(text) {
await navigator.clipboard.writeText(text);
return true;
} catch (e) {
console.warn("[LeafFlow] Navigator clipboard failed, trying textarea fallback:", e);
console.warn("[SaturnNodes CopyPrompt] Navigator clipboard failed, trying textarea fallback:", e);
}
}
try {
@@ -28,7 +28,7 @@ async function copyToClipboard(text) {
document.body.removeChild(textarea);
return successful;
} catch (err) {
console.error("[LeafFlow] Clipboard copy fallback failed:", err);
console.error("[SaturnNodes CopyPrompt] Clipboard copy fallback failed:", err);
return false;
}
}
@@ -36,27 +36,14 @@ async function copyToClipboard(text) {
function isCopyEnabled(settingKey, defaultVal = true) {
try {
let val;
const saturnNumberedKey = settingKey.replace(/^LeafFlow\./, "SaturnNodes.");
const saturnPlainKey = saturnNumberedKey.replace(/\d+\s*-\s*/, "");
const keysToCheck = [saturnPlainKey, saturnNumberedKey, settingKey];
if (app.extensionManager?.setting?.get) {
for (const k of keysToCheck) {
val = app.extensionManager.setting.get(k);
if (val !== undefined && val !== null && val !== "") break;
}
val = app.extensionManager.setting.get(settingKey);
}
if ((val === undefined || val === null || val === "") && app.ui?.settings?.getSettingValue) {
for (const k of keysToCheck) {
val = app.ui.settings.getSettingValue(k);
if (val !== undefined && val !== null && val !== "") break;
}
val = app.ui.settings.getSettingValue(settingKey);
}
if ((val === undefined || val === null || val === "") && app.ui?.settings?.get) {
for (const k of keysToCheck) {
val = app.ui.settings.get(k);
if (val !== undefined && val !== null && val !== "") break;
}
val = app.ui.settings.get(settingKey);
}
if (val === undefined || val === null || val === "") {
return defaultVal;
@@ -233,7 +220,7 @@ async function extractPromptFromImageUrl(imgSrc) {
} catch (_) {}
}
} catch (e) {
console.warn("[LeafFlow] Direct PNG metadata extraction failed:", e);
console.warn("[SaturnNodes CopyPrompt] Direct PNG metadata extraction failed:", e);
}
return null;
}
@@ -339,7 +326,7 @@ app.registerExtension({
nodeType.prototype.getExtraMenuOptions = function (_, options) {
if (origGetExtraMenuOptions) origGetExtraMenuOptions.apply(this, arguments);
if (!isCopyEnabled("LeafFlow.3 - 📋 Prompt Actions.02_EnableContextMenuCopyPrompt")) return;
if (!isCopyEnabled("SaturnNodes.📋 Prompt Actions.02_EnableContextMenuCopyPrompt")) return;
const imgs = this.imgs || this.images || (this.widgets && this.widgets.filter(w => w.type === "image" || w.name === "image"));
if (imgs && imgs.length > 0) {
@@ -354,12 +341,12 @@ app.registerExtension({
if (app.extensionManager?.toast?.add) {
app.extensionManager.toast.add({
severity: "warn",
summary: "LeafFlow Copy Prompt",
summary: "SaturnNodes Copy Prompt",
detail: "Could not extract positive prompt from this image.",
life: 3000
});
} else {
alert("LeafFlow: Could not extract positive prompt from this image.");
alert("SaturnNodes: Could not extract positive prompt from this image.");
}
}
},
@@ -435,8 +422,8 @@ function injectCopyPromptNextToDownload(downloadBtn) {
if (img.classList.contains("size-8") || img.closest(".size-8, .size-10, .h-12")) return;
const parent = downloadBtn.parentElement;
const enableCopy = isCopyEnabled("LeafFlow.3 - 📋 Prompt Actions.01_EnableAssetsCopyPromptButton");
const enableInspect = isCopyEnabled("LeafFlow.3 - 📋 Prompt Actions.04_EnableInspectAssetButton", false);
const enableCopy = isCopyEnabled("SaturnNodes.📋 Prompt Actions.01_EnableAssetsCopyPromptButton");
const enableInspect = isCopyEnabled("SaturnNodes.📋 Prompt Actions.04_EnableInspectAssetButton", false);
if (!enableCopy && !enableInspect) return;
@@ -459,14 +446,14 @@ function injectCopyPromptNextToDownload(downloadBtn) {
let lastBtn = downloadBtn;
// 1. Copy Prompt Button
let copyBtn = parent.querySelector(".leafflow-hover-copy");
let copyBtn = parent.querySelector(".saturnnodes-hover-copy");
if (enableCopy) {
if (!copyBtn) {
copyBtn = document.createElement("button");
copyBtn.type = "button";
copyBtn.title = "Copy Prompt";
copyBtn.setAttribute("aria-label", "Copy Prompt");
copyBtn.className = `leafflow-hover-btn leafflow-hover-copy ${baseClasses} shrink-0`;
copyBtn.className = `saturnnodes-hover-btn saturnnodes-hover-copy ${baseClasses} shrink-0`;
if (hasModernIcons) {
copyBtn.innerHTML = `<i class="icon-[lucide--copy] size-4 pointer-events-none"></i>`;
@@ -503,14 +490,14 @@ function injectCopyPromptNextToDownload(downloadBtn) {
}
// 2. Inspect Asset (Zoom) Button
let inspectBtn = parent.querySelector(".leafflow-hover-inspect");
let inspectBtn = parent.querySelector(".saturnnodes-hover-inspect");
if (enableInspect) {
if (!inspectBtn) {
inspectBtn = document.createElement("button");
inspectBtn.type = "button";
inspectBtn.title = "Inspect asset";
inspectBtn.setAttribute("aria-label", "Inspect asset");
inspectBtn.className = `leafflow-hover-btn leafflow-hover-inspect ${baseClasses} shrink-0`;
inspectBtn.className = `saturnnodes-hover-btn saturnnodes-hover-inspect ${baseClasses} shrink-0`;
inspectBtn.innerHTML = INSPECT_SVG;
inspectBtn.onclick = (e) => {
@@ -534,20 +521,37 @@ function injectCopyPromptNextToDownload(downloadBtn) {
// 4. Inject Copy Prompt into PrimeVue Context Menu Next to Download Item
function injectContextMenuCopy(contextMenu) {
if (!contextMenu) return;
if (contextMenu.querySelector(".leafflow-contextmenu-copy")) return;
if (!isCopyEnabled("LeafFlow.3 - 📋 Prompt Actions.02_EnableContextMenuCopyPrompt")) return;
if (contextMenu.querySelector(".saturnnodes-contextmenu-copy")) return;
if (!isCopyEnabled("SaturnNodes.📋 Prompt Actions.02_EnableContextMenuCopyPrompt")) return;
let downloadLi = contextMenu.querySelector(
'li[aria-label="Download"], li[aria-label*="ownload" i], [data-pc-section="item"][aria-label*="ownload" i]'
);
if (!downloadLi) {
const items = contextMenu.querySelectorAll('li, [data-pc-section="item"]');
for (const item of items) {
const text = item.textContent?.trim().toLowerCase() || "";
if (text.includes("download") || item.querySelector('.icon-[lucide--download], [class*="download" i]')) {
downloadLi = item;
break;
}
// Guard: strictly ignore top menu, menubar, command menus, and main application menus!
if (
contextMenu.closest?.(".comfy-command-menu, .comfy-menu, .p-menubar, [data-pc-name='menubar'], [data-pc-name='tieredmenu']") ||
contextMenu.classList?.contains("comfy-command-menu") ||
contextMenu.classList?.contains("p-tieredmenu") ||
contextMenu.querySelector?.(".p-menubar-root-list, .p-tieredmenu-root-list, li[aria-label='File'], li[aria-label='New'], li[aria-label='Edit'], li[aria-label='View']")
) {
return;
}
let downloadLi = null;
const candidates = contextMenu.querySelectorAll('li[role="menuitem"], [data-pc-section="item"]');
for (const item of candidates) {
const label = (item.getAttribute("aria-label") || "").trim().toLowerCase();
const text = (item.textContent || "").trim().toLowerCase();
// Strictly ignore workflow export / save actions
if (label.includes("export") || text.includes("export") || label.includes("save as") || text.includes("save as")) {
continue;
}
if (label === "download" || label === "download image" || text === "download" || text === "download image") {
downloadLi = item;
break;
}
if (!downloadLi && (label.includes("download") || text.includes("download"))) {
downloadLi = item;
}
}
if (!downloadLi || !downloadLi.parentElement) return;
@@ -563,7 +567,7 @@ function injectContextMenuCopy(contextMenu) {
);
const copyLi = document.createElement("li");
copyLi.className = "p-contextmenu-item leafflow-contextmenu-copy";
copyLi.className = "p-contextmenu-item saturnnodes-contextmenu-copy";
copyLi.setAttribute("role", "menuitem");
copyLi.setAttribute("aria-label", "Copy prompt");
copyLi.setAttribute("data-pc-section", "item");
@@ -605,8 +609,8 @@ function injectContextMenuCopy(contextMenu) {
// 5. Fallback Hook for Older Frontend Action Bars
function injectHoverCopyAction(overlayBar) {
if (!overlayBar || overlayBar.querySelector(".leafflow-hover-copy")) return;
if (!isCopyEnabled("LeafFlow.3 - 📋 Prompt Actions.01_EnableAssetsCopyPromptButton")) return;
if (!overlayBar || overlayBar.querySelector(".saturnnodes-hover-copy")) return;
if (!isCopyEnabled("SaturnNodes.📋 Prompt Actions.01_EnableAssetsCopyPromptButton")) return;
if (isQueueItemElement(overlayBar)) return;
@@ -634,7 +638,7 @@ function injectHoverCopyAction(overlayBar) {
const copyBtn = document.createElement("button");
copyBtn.className =
"leafflow-hover-btn leafflow-hover-copy relative inline-flex items-center justify-center cursor-pointer touch-manipulation appearance-none border-none text-xs font-medium font-inter transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 bg-white text-gray-700 hover:bg-gray-100 size-8 p-0 rounded-none pointer-events-auto border-r border-gray-200 shrink-0";
"saturnnodes-hover-btn saturnnodes-hover-copy relative inline-flex items-center justify-center cursor-pointer touch-manipulation appearance-none border-none text-xs font-medium font-inter transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 bg-white text-gray-700 hover:bg-gray-100 size-8 p-0 rounded-none pointer-events-auto border-r border-gray-200 shrink-0";
copyBtn.title = "Copy Prompt";
copyBtn.setAttribute("aria-label", "Copy Prompt");
copyBtn.setAttribute("data-pd-tooltip", "true");
@@ -672,7 +676,7 @@ function scanAndInject() {
);
downloadBtns.forEach(injectCopyPromptNextToDownload);
const menus = document.querySelectorAll('.p-contextmenu, .p-menu, .p-tieredmenu, [data-pc-name="contextmenu"], [data-pc-name="menu"], [data-pc-name="tieredmenu"]');
const menus = document.querySelectorAll('.p-contextmenu, [data-pc-name="contextmenu"]');
menus.forEach(injectContextMenuCopy);
const olderOverlays = document.querySelectorAll(
@@ -694,7 +698,7 @@ document.addEventListener("pointerover", (e) => {
const cardDl = card.querySelector('button[aria-label="Download"], button[aria-label*="ownload" i]');
if (cardDl) injectCopyPromptNextToDownload(cardDl);
}
const menu = e.target.closest?.('.p-contextmenu, .p-menu, .p-tieredmenu, [data-pc-name="contextmenu"], [data-pc-name="menu"], [data-pc-name="tieredmenu"]');
const menu = e.target.closest?.('.p-contextmenu, [data-pc-name="contextmenu"]');
if (menu) {
injectContextMenuCopy(menu);
}
@@ -710,7 +714,7 @@ const observer = new MutationObserver((mutations) => {
if (node.matches?.('button[aria-label="Download"], button[aria-label*="ownload" i]')) {
injectCopyPromptNextToDownload(node);
} else if (node.matches?.('.p-contextmenu, .p-menu, .p-tieredmenu, [data-pc-name="contextmenu"], [data-pc-name="menu"], [data-pc-name="tieredmenu"]')) {
} else if (node.matches?.('.p-contextmenu, [data-pc-name="contextmenu"]')) {
injectContextMenuCopy(node);
} else if (node.matches?.('[data-testid="asset-card-actions"], .asset-card-overlay, .asset-item-overlay')) {
injectHoverCopyAction(node);
@@ -718,7 +722,7 @@ const observer = new MutationObserver((mutations) => {
const dlBtns = node.querySelectorAll('button[aria-label="Download"], button[aria-label*="ownload" i]');
dlBtns.forEach(injectCopyPromptNextToDownload);
const ctxMenus = node.querySelectorAll('.p-contextmenu, .p-menu, .p-tieredmenu, [data-pc-name="contextmenu"], [data-pc-name="menu"], [data-pc-name="tieredmenu"]');
const ctxMenus = node.querySelectorAll('.p-contextmenu, [data-pc-name="contextmenu"]');
ctxMenus.forEach(injectContextMenuCopy);
const overlays = node.querySelectorAll('[data-testid="asset-card-actions"], .asset-card-overlay, .asset-item-overlay');
+52 -17
View File
@@ -5,7 +5,7 @@ import { authenticatedFetch } from "./auth_helper.js";
// Create global styles for the decision buttons
const styles = document.createElement("style");
styles.textContent = `
.leafflow-decision-btn {
.saturnnodes-decision-btn {
margin: 4px;
padding: 6px 12px;
border: none;
@@ -15,19 +15,19 @@ styles.textContent = `
color: white;
transition: all 0.2s;
}
.leafflow-decision-btn:disabled {
.saturnnodes-decision-btn:disabled {
opacity: 0.3;
cursor: not-allowed;
filter: grayscale(100%);
}
.leafflow-btn-continue { background-color: #2e7d32; }
.leafflow-btn-continue:hover:not(:disabled) { background-color: #388e3c; }
.leafflow-btn-cancel { background-color: #f57c00; }
.leafflow-btn-cancel:hover:not(:disabled) { background-color: #fb8c00; }
.leafflow-btn-stop { background-color: #d32f2f; }
.leafflow-btn-stop:hover:not(:disabled) { background-color: #f44336; }
.saturnnodes-btn-continue { background-color: #2e7d32; }
.saturnnodes-btn-continue:hover:not(:disabled) { background-color: #388e3c; }
.saturnnodes-btn-cancel { background-color: #f57c00; }
.saturnnodes-btn-cancel:hover:not(:disabled) { background-color: #fb8c00; }
.saturnnodes-btn-stop { background-color: #d32f2f; }
.saturnnodes-btn-stop:hover:not(:disabled) { background-color: #f44336; }
.leafflow-decision-container {
.saturnnodes-decision-container {
display: flex;
flex-direction: column;
align-items: center;
@@ -38,13 +38,48 @@ styles.textContent = `
`;
document.head.appendChild(styles);
function findGraphNode(id) {
if (!id && id !== 0) return null;
const strId = String(id);
const numId = Number(id);
// 1. Direct root graph lookup
let node = app.graph?.getNodeById?.(id) || app.graph?.getNodeById?.(numId) || app.graph?.getNodeById?.(strId);
if (node) return node;
// 2. Search root graph nodes and nested subgraphs
if (app.graph && Array.isArray(app.graph._nodes)) {
for (const n of app.graph._nodes) {
if (String(n.id) === strId) return n;
if (n.subgraph && typeof n.subgraph.getNodeById === "function") {
const sub = n.subgraph.getNodeById(id) || n.subgraph.getNodeById(numId) || n.subgraph.getNodeById(strId);
if (sub) return sub;
}
}
}
// 3. Search graph._subgraphs registry (v0.37+)
if (app.graph && app.graph._subgraphs) {
const subgraphs = Array.isArray(app.graph._subgraphs)
? app.graph._subgraphs
: Object.values(app.graph._subgraphs);
for (const sg of subgraphs) {
if (sg && typeof sg.getNodeById === "function") {
const sub = sg.getNodeById(id) || sg.getNodeById(numId) || sg.getNodeById(strId);
if (sub) return sub;
}
}
}
return null;
}
app.registerExtension({
name: "Comfy.SaturnNodesDecision",
name: "ComfyUI.SaturnNodes.Decision",
async setup() {
const handleWaiting = (event) => {
const data = event.detail;
if (data && data.node_id) {
const node = app.graph.getNodeById(data.node_id);
const node = findGraphNode(data.node_id);
if (node && node.enableDecisionButtons) {
node.enableDecisionButtons();
}
@@ -54,7 +89,7 @@ app.registerExtension({
const handleResolved = (event) => {
const data = event.detail;
if (data && data.node_id) {
const node = app.graph.getNodeById(data.node_id);
const node = findGraphNode(data.node_id);
if (node && node.disableDecisionButtons) {
node.disableDecisionButtons();
}
@@ -65,22 +100,22 @@ app.registerExtension({
api.addEventListener("saturnnodes_decision_resolved", handleResolved);
},
async nodeCreated(node) {
if (node.comfyClass === "SaturnDecision" || node.comfyClass === "LeafFlowDecision") {
if (node.comfyClass === "SaturnDecision") {
const container = document.createElement("div");
container.className = "leafflow-decision-container";
container.className = "saturnnodes-decision-container";
const btnContinue = document.createElement("button");
btnContinue.className = "leafflow-decision-btn leafflow-btn-continue";
btnContinue.className = "saturnnodes-decision-btn saturnnodes-btn-continue";
btnContinue.innerText = "Continue Workflow";
btnContinue.disabled = true;
const btnCancel = document.createElement("button");
btnCancel.className = "leafflow-decision-btn leafflow-btn-cancel";
btnCancel.className = "saturnnodes-decision-btn saturnnodes-btn-cancel";
btnCancel.innerText = "Cancel (Return True)";
btnCancel.disabled = true;
const btnStop = document.createElement("button");
btnStop.className = "leafflow-decision-btn leafflow-btn-stop";
btnStop.className = "saturnnodes-decision-btn saturnnodes-btn-stop";
btnStop.innerText = "Stop Workflow";
btnStop.disabled = true;
+174 -40
View File
@@ -1,6 +1,7 @@
import { app } from "/scripts/app.js";
import { api } from "/scripts/api.js";
import { isSaturnColorsEnabled } from "../saturnnodes_colors.js";
import { authenticatedFetch } from "./auth_helper.js";
// Hash folder name to get a consistent color for the border
function getFolderBorderColor(folderName) {
@@ -96,7 +97,9 @@ visualStyles.textContent = `
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 12px;
row-gap: 6px;
padding: 4px 6px;
background: #181818;
border: 1px solid #282828;
@@ -397,7 +400,7 @@ visualStyles.textContent = `
document.head.appendChild(visualStyles);
app.registerExtension({
name: "Comfy.FolderLoraLoader",
name: "ComfyUI.SaturnNodes.FolderLoraLoader",
async nodeCreated(node) {
// --- 1. ORIGINAL DROPDOWN NODES ---
if (node.comfyClass === "FolderLoraLoader" || node.comfyClass === "FolderLoraLoaderPretty" || node.type === "FolderLoraLoader" || node.type === "FolderLoraLoaderPretty") {
@@ -423,7 +426,7 @@ app.registerExtension({
activeRequest = currentRequest;
try {
const response = await api.fetchApi(`/folder_lora_loader/get_loras?folder=${encodeURIComponent(folder)}&pretty=${pretty}`);
const response = await api.fetchApi(`/saturnnodes/folder_lora_loader/get_loras?folder=${encodeURIComponent(folder)}&pretty=${pretty}`);
if (activeRequest !== currentRequest) return;
const data = await response.json();
@@ -530,31 +533,28 @@ app.registerExtension({
// Embed DOM Widget inside the node container
const domWidget = node.addDOMWidget("lora_visual_picker", "HTML", viewContainer, {
getValue() { return getHiddenWidget().value; },
setValue(val) { getHiddenWidget().value = val; },
getValue() { return hiddenWidget.value; },
setValue(val) { hiddenWidget.value = val; },
serialize: false
});
// Detect Vue UI vs LiteGraph by checking for the Vue container class eventually
const isVueUI = !!document.querySelector(".lg-node");
if (isVueUI) {
viewContainer.classList.add("vue-mode");
viewContainer.style.height = "160px";
} else {
viewContainer.classList.add("litegraph-mode");
const onResize = node.onResize;
node.onResize = function(size) {
if (onResize) onResize.apply(this, arguments);
if (viewContainer.style) {
viewContainer.style.height = `${size[1] - 160}px`;
}
};
}
viewContainer.style.setProperty("height", "100%", "important");
viewContainer.style.setProperty("max-height", "100%", "important");
viewContainer.style.setProperty("box-sizing", "border-box", "important");
// In ComfyUI LiteGraph (V1), computeLayoutSize handles dynamic widget space distribution.
// Removing computeSize avoids an infinite expansion loop in _arrangeWidgets.
domWidget.computeLayoutSize = function() {
return { minHeight: 160, maxHeight: undefined, minWidth: 300 };
};
delete domWidget.computeSize;
const onResize = node.onResize;
node.onResize = function(size) {
if (onResize) onResize.apply(this, arguments);
if (size) {
node.userCustomHeight = size[1];
}
};
// Add Zoom slider widget
const zoomWidget = node.addWidget(
"slider",
@@ -579,11 +579,27 @@ app.registerExtension({
activeRequest = currentRequest;
try {
const response = await api.fetchApi(`/folder_lora_loader/get_loras?folder=${encodeURIComponent(folder)}&pretty=true`);
const response = await api.fetchApi(`/saturnnodes/folder_lora_loader/get_loras?folder=${encodeURIComponent(folder)}&pretty=true`);
if (activeRequest !== currentRequest) return;
const data = await response.json();
viewContainer.innerHTML = "";
if (viewContainer._tileObserver) {
try { viewContainer._tileObserver.disconnect(); } catch (_) {}
}
const tileObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
if (img.dataset.src) {
img.src = img.dataset.src;
img.removeAttribute("data-src");
}
observer.unobserve(img);
}
});
}, { root: viewContainer, rootMargin: "150px" });
viewContainer._tileObserver = tileObserver;
// Calculate Top 3 Ranks by versionless pretty name
const getTop3Ranks = () => {
@@ -689,7 +705,10 @@ app.registerExtension({
}
const img = document.createElement("img");
img.src = `/folder_lora_loader/get_preview?lora=${encodeURIComponent(loraName)}&folder=${encodeURIComponent(folder)}&pretty=true`;
img.loading = "lazy";
const bypassThumbs = app.ui.settings?.getSettingValue?.("SaturnNodes.🖼️ Visual Loaders.07_BypassThumbnailDownscaling", false);
img.dataset.src = `/saturnnodes/folder_lora_loader/get_preview?lora=${encodeURIComponent(loraName)}&folder=${encodeURIComponent(folder)}&pretty=true` + (bypassThumbs ? "&full=true" : "&size=200");
tileObserver.observe(img);
img.onerror = () => {
img.remove();
@@ -776,6 +795,10 @@ app.registerExtension({
node.onConfigure = function(config) {
if (originalOnConfigure) originalOnConfigure.apply(this, arguments);
if (config && config.size && config.size[1]) {
node.userCustomHeight = config.size[1];
}
const savedTileSize = (config && config.properties && config.properties["tile_size"] != null)
? config.properties["tile_size"]
: (node.properties && node.properties["tile_size"] != null ? node.properties["tile_size"] : null);
@@ -791,7 +814,7 @@ app.registerExtension({
}
}
const curWidget = getHiddenWidget();
const curWidget = hiddenWidget;
const widgetIndex = node.widgets.indexOf(curWidget);
const savedValue = (config.widgets_values && widgetIndex !== -1) ? config.widgets_values[widgetIndex] : curWidget.value;
@@ -805,7 +828,7 @@ app.registerExtension({
}
// --- 3. VISUAL PRETTY PICKER V2 (Collapsible folders & Multi-selection) ---
if (node.comfyClass === "FolderLoraLoaderVisualPrettyV2" || node.comfyClass === "VisualLoraLoader" || node.type === "FolderLoraLoaderVisualPrettyV2" || node.type === "VisualLoraLoader") {
if (node.comfyClass === "VisualLoraLoader" || node.type === "VisualLoraLoader") {
node.size = [380, 360];
const folderWidget = node.widgets.find(w => w.name === "folder");
@@ -910,11 +933,9 @@ app.registerExtension({
} else {
viewContainer.classList.remove("show-all-mode");
viewContainer.classList.add("scrollable-mode");
const restoredH = node.userCustomHeight || userSavedHeight || 420;
const containerH = Math.max(180, restoredH - 150);
viewContainer.style.setProperty("height", `${containerH}px`, "important");
viewContainer.style.setProperty("max-height", `${containerH}px`, "important");
viewContainer.style.setProperty("height", "100%", "important");
viewContainer.style.setProperty("max-height", "100%", "important");
viewContainer.style.setProperty("overflow-y", "hidden", "important");
gridContainer.style.setProperty("height", "100%", "important");
@@ -922,7 +943,10 @@ app.registerExtension({
gridContainer.style.setProperty("overflow-y", "auto", "important");
gridContainer.style.setProperty("flex", "1 1 0px", "important");
node.setSize([node.size[0], Math.max(360, restoredH)]);
const targetH = node.userCustomHeight || userSavedHeight || (node.size ? node.size[1] : 420);
if (targetH && (!node.size || node.size[1] !== targetH)) {
node.setSize([node.size ? node.size[0] : 380, Math.max(360, targetH)]);
}
if (app.graph) app.graph.setDirtyCanvas(true, true);
}
};
@@ -932,7 +956,7 @@ app.registerExtension({
if (displayModeWidget && displayModeWidget.value === "Show All" && gridContainer) {
return [Math.max(380, node.size[0]), Math.max(360, (gridContainer.scrollHeight || 0) + 160)];
}
return [Math.max(380, node.size[0]), 360];
return [Math.max(380, node.size[0]), Math.max(360, node.size ? node.size[1] : 360)];
};
const updateNodeSize = () => {
@@ -1040,6 +1064,113 @@ app.registerExtension({
scrapeToggleContainer.appendChild(scrapeOffBtn);
controlBar.appendChild(scrapeToggleContainer);
// --- Maintenance Reset Container (cycle counter / usage counters / thumbnail cache) ---
const maintContainer = document.createElement("div");
maintContainer.className = "lora-toggle-container";
const maintLabel = document.createElement("span");
maintLabel.className = "lora-toggle-label";
maintLabel.innerText = "Reset:";
maintContainer.appendChild(maintLabel);
const postMaintenance = async (route, body) => {
const resp = await authenticatedFetch(route, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body || {})
});
const data = await resp.json().catch(() => ({}));
if (!resp.ok || (data && data.status === "error")) {
throw new Error((data && data.message) || `Request failed (${resp.status})`);
}
return data;
};
const makeMaintButton = (label, title, onClick) => {
const btn = document.createElement("button");
btn.type = "button";
btn.className = "lora-toggle-btn";
btn.innerText = label;
btn.title = title;
btn.dataset.defaultLabel = label;
btn.addEventListener("click", async (e) => {
e.preventDefault();
e.stopPropagation();
if (btn.disabled) return;
try {
const result = await onClick();
if (result === false) return;
btn.innerText = "✅ Done";
} catch (err) {
console.error(`[SaturnNodes] '${label}' maintenance action failed:`, err);
btn.innerText = "⚠️ Failed";
}
btn.disabled = true;
app.graph?.setDirtyCanvas(true, true);
setTimeout(() => {
btn.disabled = false;
btn.innerText = btn.dataset.defaultLabel;
app.graph?.setDirtyCanvas(true, true);
}, 1600);
app.graph?.setDirtyCanvas(true, true);
});
return btn;
};
// Cycle counter: resets Sequential/Random position + prompt->LoRA assignments for this node
const cycleResetBtn = makeMaintButton(
"↺ Counter",
"Reset this loader's Sequential/Random cycle counter and prompt-to-LoRA assignments",
async () => {
const ok = confirm(
"Reset this LoRA loader's cycle counter?\n\n" +
"• The next run starts again from the FIRST selected LoRA.\n" +
"• All prompt→LoRA assignments for this node are cleared.\n\n" +
"⚠️ Running and queued workflows will pick LoRAs from the start again,\n" +
"which can mismatch them against the prompt iterator mid-batch.\n" +
"Only do this between batches (when the queue is empty).\n\nContinue?"
);
if (!ok) return false;
await postMaintenance("/saturnnodes/folder_lora_loader/reset_cycle", { node_id: String(node.id) });
}
);
maintContainer.appendChild(cycleResetBtn);
// Usage counters: clears badges + 'Usage' sortings (cosmetic)
const usageResetBtn = makeMaintButton(
"🧹 Usage",
"Reset all LoRA usage counters (badges and 'Usage' sortings)",
async () => {
const ok = confirm(
"Reset all LoRA usage counters?\n\n" +
"• Every usage badge and 'Usage' sorting starts from 0.\n" +
"• Cosmetic only - LoRA loading itself is not affected.\n\nContinue?"
);
if (!ok) return false;
await postMaintenance("/saturnnodes/folder_lora_loader/reset_usage");
updateVisualGrid();
}
);
maintContainer.appendChild(usageResetBtn);
// Thumbnail cache: deletes cached WebP previews (regenerated automatically)
const cacheResetBtn = makeMaintButton(
"🗑 Cache",
"Delete cached LoRA thumbnail images (they regenerate automatically)",
async () => {
const ok = confirm(
"Clear the cached LoRA thumbnails?\n\n" +
"• Cached preview thumbnails are deleted from disk.\n" +
"• They regenerate automatically when you view the grid.\n\nContinue?"
);
if (!ok) return false;
await postMaintenance("/saturnnodes/folder_lora_loader/clear_cache");
}
);
maintContainer.appendChild(cacheResetBtn);
controlBar.appendChild(maintContainer);
viewContainer.appendChild(controlBar);
viewContainer.appendChild(gridContainer);
@@ -1051,8 +1182,10 @@ app.registerExtension({
});
// In ComfyUI LiteGraph (V1), computeLayoutSize handles dynamic widget space distribution.
// A computeSize returning (node.size[1] - offset) causes an infinite loop in _arrangeWidgets
// because LiteGraph sees (l > t) and expands node.size on every animation frame.
// Removing computeSize avoids an infinite expansion loop in _arrangeWidgets.
domWidget.computeLayoutSize = function() {
return { minHeight: 180, maxHeight: undefined, minWidth: 300 };
};
delete domWidget.computeSize;
const onResize = node.onResize;
@@ -1063,11 +1196,6 @@ app.registerExtension({
if (!isShowAll && size) {
node.userCustomHeight = size[1];
userSavedHeight = size[1];
if (viewContainer && viewContainer.style) {
const h = Math.max(180, size[1] - 150);
viewContainer.style.setProperty("height", `${h}px`, "important");
viewContainer.style.setProperty("max-height", `${h}px`, "important");
}
}
};
@@ -1258,7 +1386,7 @@ app.registerExtension({
activeRequest = currentRequest;
try {
const response = await api.fetchApi(`/folder_lora_loader/get_loras?folder=${encodeURIComponent(folder)}&pretty=true&scrape_on_new=${encodeURIComponent(scrapeOnNew)}`);
const response = await api.fetchApi(`/saturnnodes/folder_lora_loader/get_loras?folder=${encodeURIComponent(folder)}&pretty=true&scrape_on_new=${encodeURIComponent(scrapeOnNew)}`);
if (activeRequest !== currentRequest) return;
const data = await response.json();
@@ -1496,7 +1624,8 @@ app.registerExtension({
const img = document.createElement("img");
img.loading = "lazy";
img.dataset.src = `/folder_lora_loader/get_preview?system_path=${encodeURIComponent(item.systemPath)}`;
const bypassThumbs = app.ui.settings?.getSettingValue?.("SaturnNodes.🖼️ Visual Loaders.07_BypassThumbnailDownscaling", false);
img.dataset.src = `/saturnnodes/folder_lora_loader/get_preview?system_path=${encodeURIComponent(item.systemPath)}` + (bypassThumbs ? "&full=true" : "&size=200");
imageObserver.observe(img);
img.onerror = () => {
@@ -1596,6 +1725,11 @@ app.registerExtension({
const originalOnConfigure = node.onConfigure;
node.onConfigure = function(config) {
if (originalOnConfigure) originalOnConfigure.apply(this, arguments);
if (config && config.size && config.size[1]) {
node.userCustomHeight = config.size[1];
userSavedHeight = config.size[1];
}
const savedTileSize = (config && config.properties && config.properties["tile_size"] != null)
? config.properties["tile_size"]
+18 -16
View File
@@ -201,15 +201,13 @@ visualStyles.textContent = `
document.head.appendChild(visualStyles);
app.registerExtension({
name: "Comfy.ImageLoaderCustom",
name: "ComfyUI.SaturnNodes.VisualImageLoader",
async nodeCreated(node) {
const isVisualImageLoader = [
"VisualImageLoader",
"ImageLoaderVisualPrettyV2",
"ImageLoaderCustom",
].includes(node.comfyClass) || [
"VisualImageLoader",
"ImageLoaderVisualPrettyV2",
"ImageLoaderCustom",
].includes(node.type);
@@ -303,11 +301,9 @@ app.registerExtension({
} else {
viewContainer.classList.remove("show-all-mode");
viewContainer.classList.add("scrollable-mode");
const restoredH = node.userCustomHeight || userSavedHeight || 480;
const containerH = Math.max(180, restoredH - 150);
viewContainer.style.setProperty("height", `${containerH}px`, "important");
viewContainer.style.setProperty("max-height", `${containerH}px`, "important");
viewContainer.style.setProperty("height", "100%", "important");
viewContainer.style.setProperty("max-height", "100%", "important");
viewContainer.style.setProperty("overflow-y", "hidden", "important");
gridContainer.style.setProperty("height", "100%", "important");
@@ -315,7 +311,10 @@ app.registerExtension({
gridContainer.style.setProperty("overflow-y", "auto", "important");
gridContainer.style.setProperty("flex", "1 1 0px", "important");
node.setSize([node.size[0], Math.max(420, restoredH)]);
const targetH = node.userCustomHeight || userSavedHeight || (node.size ? node.size[1] : 480);
if (targetH && (!node.size || node.size[1] !== targetH)) {
node.setSize([node.size ? node.size[0] : 380, Math.max(420, targetH)]);
}
if (app.graph) app.graph.setDirtyCanvas(true, true);
}
};
@@ -325,7 +324,7 @@ app.registerExtension({
if (displayModeWidget && displayModeWidget.value === "Show All" && gridContainer) {
return [Math.max(380, node.size[0]), Math.max(420, (gridContainer.scrollHeight || 0) + 160)];
}
return [Math.max(380, node.size[0]), 420];
return [Math.max(380, node.size[0]), Math.max(420, node.size ? node.size[1] : 420)];
};
const updateNodeSize = () => {
@@ -351,6 +350,9 @@ app.registerExtension({
// In ComfyUI LiteGraph (V1), computeLayoutSize handles dynamic widget space distribution.
// Removing computeSize avoids an infinite expansion loop in _arrangeWidgets.
domWidget.computeLayoutSize = function() {
return { minHeight: 180, maxHeight: undefined, minWidth: 300 };
};
delete domWidget.computeSize;
const onResize = node.onResize;
@@ -361,11 +363,6 @@ app.registerExtension({
if (!isShowAll && size) {
node.userCustomHeight = size[1];
userSavedHeight = size[1];
if (viewContainer && viewContainer.style) {
const h = Math.max(180, size[1] - 150);
viewContainer.style.setProperty("height", `${h}px`, "important");
viewContainer.style.setProperty("max-height", `${h}px`, "important");
}
}
};
@@ -511,7 +508,7 @@ app.registerExtension({
const img = document.createElement("img");
let fetchFolder = folder;
img.dataset.src = `/image_loader/get_thumbnail?folder=${encodeURIComponent(fetchFolder)}&image=${encodeURIComponent(item.relPath)}`;
img.dataset.src = `/saturnnodes/image_loader/get_thumbnail?folder=${encodeURIComponent(fetchFolder)}&image=${encodeURIComponent(item.relPath)}`;
img.onload = () => img.classList.add("loaded");
img.onerror = () => {
@@ -562,7 +559,7 @@ app.registerExtension({
activeRequest = currentRequest;
try {
const response = await api.fetchApi(`/image_loader/get_images?folder=${encodeURIComponent(folder)}`);
const response = await api.fetchApi(`/saturnnodes/image_loader/get_images?folder=${encodeURIComponent(folder)}`);
if (activeRequest !== currentRequest) return;
imagesData = await response.json();
@@ -599,6 +596,11 @@ app.registerExtension({
node.onConfigure = function(config) {
if (originalOnConfigure) originalOnConfigure.apply(this, arguments);
if (config && config.size && config.size[1]) {
node.userCustomHeight = config.size[1];
userSavedHeight = config.size[1];
}
const savedTileSize = (config && config.properties && config.properties["tile_size"] != null)
? config.properties["tile_size"]
: (node.properties && node.properties["tile_size"] != null ? node.properties["tile_size"] : null);
+1 -1
View File
@@ -3,7 +3,7 @@ import { authenticatedFetch } from "./auth_helper.js";
// SaturnNodes Local File Runner In-Memory Consent Gate Extension
app.registerExtension({
name: "SaturnNodes.LocalRunner.Security",
name: "ComfyUI.SaturnNodes.LocalRunner",
async nodeCreated(node) {
if (node.comfyClass !== "RunLocalFileNode") return;
+40 -39
View File
@@ -3,7 +3,7 @@ import { api } from "/scripts/api.js";
import { authenticatedFetch } from "./auth_helper.js";
const EXTENSION_NAME = "SaturnNodes.PowerControlSidebar";
const STYLE_ID = "leafflow-power-sidebar-styles";
const STYLE_ID = "saturnnodes-power-sidebar-styles";
let currentPowerState = {
pending_action: null,
@@ -19,7 +19,7 @@ function injectStyles() {
style.id = STYLE_ID;
style.textContent = `
/* Power Sidebar Button Layout (Matching standard full-width sidebar button) */
#leafflow-power-bottom-btn {
#saturnnodes-power-bottom-btn {
width: 100% !important;
height: auto !important;
min-height: 48px !important;
@@ -29,7 +29,7 @@ function injectStyles() {
align-self: stretch !important;
}
#leafflow-power-bottom-btn .side-bar-button-content {
#saturnnodes-power-bottom-btn .side-bar-button-content {
width: 100% !important;
display: flex !important;
flex-direction: column !important;
@@ -38,33 +38,33 @@ function injectStyles() {
}
/* Power Sidebar Button Armed Red Warning State */
#leafflow-power-bottom-btn.leafflow-power-btn-armed,
.comfy-power-btn.leafflow-power-btn-armed,
.side-bar-button.leafflow-power-btn-armed,
.side-bar-button:has(.leafflow-power-icon-armed),
button[aria-label*="Power"].leafflow-power-btn-armed {
#saturnnodes-power-bottom-btn.saturnnodes-power-btn-armed,
.comfy-power-btn.saturnnodes-power-btn-armed,
.side-bar-button.saturnnodes-power-btn-armed,
.side-bar-button:has(.saturnnodes-power-icon-armed),
button[aria-label*="Power"].saturnnodes-power-btn-armed {
background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%) !important;
color: #ffffff !important;
border: 1px solid #f87171 !important;
box-shadow: 0 0 14px rgba(239, 68, 68, 0.8) !important;
animation: leafflow-power-pulse 1.8s infinite ease-in-out !important;
animation: saturnnodes-power-pulse 1.8s infinite ease-in-out !important;
}
.leafflow-power-btn-armed svg,
.leafflow-power-btn-armed .side-bar-button-icon,
.leafflow-power-btn-armed span {
.saturnnodes-power-btn-armed svg,
.saturnnodes-power-btn-armed .side-bar-button-icon,
.saturnnodes-power-btn-armed span {
color: #ffffff !important;
stroke: #ffffff !important;
}
@keyframes leafflow-power-pulse {
@keyframes saturnnodes-power-pulse {
0% { box-shadow: 0 0 6px rgba(239, 68, 68, 0.5); transform: scale(1); }
50% { box-shadow: 0 0 16px rgba(239, 68, 68, 0.95); transform: scale(1.03); }
100% { box-shadow: 0 0 6px rgba(239, 68, 68, 0.5); transform: scale(1); }
}
/* Power Side Popup Menu (like Help Center popup) */
.leafflow-power-popup {
.saturnnodes-power-popup {
position: fixed;
z-index: 10005;
min-width: 250px;
@@ -76,15 +76,15 @@ function injectStyles() {
padding: 8px;
color: var(--fg-color, #f4f4f5);
font-family: inherit;
animation: leafflow-popup-fade 0.15s ease-out;
animation: saturnnodes-popup-fade 0.15s ease-out;
}
@keyframes leafflow-popup-fade {
@keyframes saturnnodes-popup-fade {
from { opacity: 0; transform: translateX(-6px); }
to { opacity: 1; transform: translateX(0); }
}
.leafflow-power-popup .help-menu-item {
.saturnnodes-power-popup .help-menu-item {
display: flex;
align-items: center;
gap: 10px;
@@ -101,27 +101,27 @@ function injectStyles() {
transition: background 0.15s ease, color 0.15s ease;
}
.leafflow-power-popup .help-menu-item:hover {
.saturnnodes-power-popup .help-menu-item:hover {
background: var(--comfy-menu-secondary-bg, rgba(255, 255, 255, 0.08));
}
.leafflow-power-popup .help-menu-item.danger-item:hover {
.saturnnodes-power-popup .help-menu-item.danger-item:hover {
background: rgba(239, 68, 68, 0.15);
color: #f87171;
}
.leafflow-power-popup .help-menu-item.armed-cancel-item {
.saturnnodes-power-popup .help-menu-item.armed-cancel-item {
background: rgba(239, 68, 68, 0.85);
color: #ffffff;
font-weight: 600;
margin-bottom: 6px;
}
.leafflow-power-popup .help-menu-item.armed-cancel-item:hover {
.saturnnodes-power-popup .help-menu-item.armed-cancel-item:hover {
background: #dc2626;
}
.leafflow-power-popup .help-menu-icon-container {
.saturnnodes-power-popup .help-menu-icon-container {
display: flex;
align-items: center;
justify-content: center;
@@ -131,18 +131,18 @@ function injectStyles() {
color: var(--descrip-text, #a1a1aa);
}
.leafflow-power-popup .help-menu-item:hover .help-menu-icon-container {
.saturnnodes-power-popup .help-menu-item:hover .help-menu-icon-container {
color: var(--fg-color, #f4f4f5);
}
.leafflow-power-popup .menu-label {
.saturnnodes-power-popup .menu-label {
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.leafflow-power-popup .menu-divider {
.saturnnodes-power-popup .menu-divider {
height: 1px;
background: var(--border-color, #27272a);
margin: 4px 0;
@@ -150,7 +150,7 @@ function injectStyles() {
}
/* Power Confirm Modal */
.leafflow-power-modal {
.saturnnodes-power-modal {
display: flex;
flex-direction: column;
gap: 12px;
@@ -172,17 +172,17 @@ function getPowerIconSvg(size = 18) {
function updateSidebarButtonVisuals() {
const isArmed = Boolean(currentPowerState.pending_action);
const btns = document.querySelectorAll('#leafflow-power-bottom-btn, .comfy-power-btn, [aria-label*="Power"], .side-bar-button:has(.pi-power)');
const btns = document.querySelectorAll('#saturnnodes-power-bottom-btn, .comfy-power-btn, [aria-label*="Power"], .side-bar-button:has(.pi-power)');
btns.forEach(btn => {
if (isArmed) {
btn.classList.add("leafflow-power-btn-armed");
btn.classList.add("saturnnodes-power-btn-armed");
const icon = btn.querySelector(".side-bar-button-icon, i, svg");
if (icon) icon.classList.add("leafflow-power-icon-armed");
if (icon) icon.classList.add("saturnnodes-power-icon-armed");
btn.setAttribute("title", `⚠️ ComfyUI Power: Armed to ${currentPowerState.pending_action.toUpperCase()} after queue finish! Click to cancel.`);
} else {
btn.classList.remove("leafflow-power-btn-armed");
btn.classList.remove("saturnnodes-power-btn-armed");
const icon = btn.querySelector(".side-bar-button-icon, i, svg");
if (icon) icon.classList.remove("leafflow-power-icon-armed");
if (icon) icon.classList.remove("saturnnodes-power-icon-armed");
btn.setAttribute("title", "Power (Restart / Shutdown)");
}
});
@@ -210,7 +210,7 @@ function openConfirmModal(title, message, onConfirm, isDanger = false) {
overlay.style.backdropFilter = "blur(3px)";
const modal = document.createElement("div");
modal.className = "leafflow-power-modal";
modal.className = "saturnnodes-power-modal";
modal.style.border = isDanger ? "1px solid rgba(239, 68, 68, 0.5)" : "1px solid rgba(59, 130, 246, 0.5)";
modal.style.boxShadow = isDanger ? "0 0 25px rgba(239, 68, 68, 0.35)" : "0 0 25px rgba(59, 130, 246, 0.35)";
@@ -313,7 +313,7 @@ function showPowerSidePopup(anchorElement) {
}
const popup = document.createElement("div");
popup.className = "help-center-popup sidebar-left leafflow-power-popup";
popup.className = "help-center-popup sidebar-left saturnnodes-power-popup";
popup.setAttribute("data-testid", "power-popup");
const rect = anchorElement.getBoundingClientRect();
@@ -625,16 +625,17 @@ function showPowerSidePopup(anchorElement) {
}
function attachBottomSidebarButton() {
// Fast path for the DOM MutationObserver: bail out before any querySelector
// work when our button is already mounted (this callback fires for every
// mutation in the app while dragging/resizing UI elements).
const existingBtn = document.getElementById("saturnnodes-power-bottom-btn");
if (existingBtn && existingBtn.isConnected) return;
const bottomGroup = document.querySelector(".sidebar-item-group.mt-auto, .side-bar .mt-auto, [data-testid='bottom-sidebar']");
if (!bottomGroup) return;
if (document.getElementById("leafflow-power-bottom-btn")) {
updateSidebarButtonVisuals();
return;
}
const btn = document.createElement("button");
btn.id = "leafflow-power-bottom-btn";
btn.id = "saturnnodes-power-bottom-btn";
btn.type = "button";
btn.className = "relative inline-flex items-center justify-center gap-2 touch-manipulation whitespace-nowrap appearance-none font-medium font-inter transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([width]):not([height])]:size-4 [&_svg]:shrink-0 bg-transparent text-muted-foreground hover:bg-secondary-background-hover h-8 rounded-lg p-2 text-xs side-bar-button cursor-pointer border-none comfy-power-btn";
btn.setAttribute("aria-label", "Power");
+2 -2
View File
@@ -2,7 +2,7 @@ import { app } from "/scripts/app.js";
import { api } from "/scripts/api.js";
app.registerExtension({
name: "ComfyUI.LeafFlow.PreviewImageSizeAspectRatio",
name: "ComfyUI.SaturnNodes.PreviewImageSizeAspectRatio",
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData.name !== "PreviewImageSizeAspectRatio" && nodeData.name !== "TextAspectRatioFinder") return;
@@ -35,7 +35,7 @@ app.registerExtension({
// DOM Container for ComfyUI V2 Vue UI
const viewContainer = document.createElement("div");
viewContainer.className = "leafflow-ar-preview-container";
viewContainer.className = "saturnnodes-ar-preview-container";
viewContainer.style.width = "100%";
viewContainer.style.height = "calc(100% - 110px)";
viewContainer.style.minHeight = "80px";
+2 -2
View File
@@ -66,8 +66,8 @@ class PreviewManagerClass {
const images = document.querySelectorAll('img[alt*="Live sampling preview"]');
images.forEach(imgEl => {
const src = imgEl.src;
if (src && src.startsWith("blob:") && imgEl.dataset.lastLeafFlowSrc !== src) {
imgEl.dataset.lastLeafFlowSrc = src;
if (src && src.startsWith("blob:") && imgEl.dataset.lastSaturnNodesSrc !== src) {
imgEl.dataset.lastSaturnNodesSrc = src;
const nodeEl = imgEl.closest('[data-node-id], [data-widgets-grid-node-id], .lg-node');
const nodeId = nodeEl ? (nodeEl.dataset.nodeId || nodeEl.dataset.widgetsGridNodeId || nodeEl.getAttribute('data-node-id')) : null;
+1 -1
View File
@@ -40,7 +40,7 @@ function countPromptsInText(text, separator, customRegex) {
}
app.registerExtension({
name: "ComfyUI.LeafFlow.PromptCounter",
name: "ComfyUI.SaturnNodes.PromptCounter",
async nodeCreated(node) {
if (node.comfyClass === "PromptCounter") {
const textWidget = node.widgets?.find(w => w.name === "text");
+40 -1
View File
@@ -2,6 +2,38 @@ import { app } from "/scripts/app.js";
import { api } from "/scripts/api.js";
import { authenticatedFetch } from "./auth_helper.js";
function findGraphNode(id) {
if (!id && id !== 0) return null;
const strId = String(id);
const numId = Number(id);
let node = app.graph?.getNodeById?.(id) || app.graph?.getNodeById?.(numId) || app.graph?.getNodeById?.(strId);
if (node) return node;
if (app.graph && Array.isArray(app.graph._nodes)) {
for (const n of app.graph._nodes) {
if (String(n.id) === strId) return n;
if (n.subgraph && typeof n.subgraph.getNodeById === "function") {
const sub = n.subgraph.getNodeById(id) || n.subgraph.getNodeById(numId) || n.subgraph.getNodeById(strId);
if (sub) return sub;
}
}
}
if (app.graph && app.graph._subgraphs) {
const subgraphs = Array.isArray(app.graph._subgraphs)
? app.graph._subgraphs
: Object.values(app.graph._subgraphs);
for (const sg of subgraphs) {
if (sg && typeof sg.getNodeById === "function") {
const sub = sg.getNodeById(id) || sg.getNodeById(numId) || sg.getNodeById(strId);
if (sub) return sub;
}
}
}
return null;
}
app.registerExtension({
name: "ComfyUI.SaturnNodes.PromptQueueIterator",
async setup() {
@@ -9,7 +41,7 @@ app.registerExtension({
const handleProgress = (event) => {
const data = event.detail;
if (!data || !data.node_id) return;
const node = app.graph?.getNodeById(data.node_id);
const node = findGraphNode(data.node_id);
if (node && node.widgets) {
const statusWidget = node.widgets.find(w => w.name === "Progress");
if (statusWidget) {
@@ -29,6 +61,13 @@ app.registerExtension({
// 2. Reset Counter (0) Button
const resetBtn = node.addWidget("button", "Reset Counter (0)", null, async () => {
const proceed = confirm(
"Reset this node's prompt counter to 0?\n\n" +
"• New queued runs start again from the FIRST prompt.\n" +
"• Already-assigned running/queued items keep their prompt (crash recovery).\n" +
"• The state file is NOT emptied - use Settings → \"Reset All Queues\" for a full wipe.\n\nContinue?"
);
if (!proceed) return;
try {
resetBtn.name = "⏳ Resetting...";
app.graph?.setDirtyCanvas(true, true);
+25
View File
@@ -0,0 +1,25 @@
import { app } from "/scripts/app.js";
/**
* 🪐 SaturnNodes — Stereoscopic 3D Extension
*
* Configures the static 3D stereogram generator node (SaturnStereo3D).
*/
app.registerExtension({
name: "ComfyUI.SaturnNodes.SaturnStereo3D",
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData.name !== "SaturnStereo3D") return;
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
if (onNodeCreated) onNodeCreated.apply(this, arguments);
if (!this.size || this.size[0] < 340) {
this.size = [360, 500];
}
};
}
});
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

+1 -1
View File
@@ -1,4 +1,4 @@
/* LeafFlow PauseQueue CSS */
/* SaturnNodes PauseQueue CSS */
:root {
--pq-unpaused-color: #059669;
+8 -8
View File
@@ -33,13 +33,13 @@ class PauseQueueUI {
async fetchStatus() {
try {
const res = await api.fetchApi("/pause_queue/status");
const res = await api.fetchApi("/saturnnodes/pause_queue/status");
if (res.ok) {
const data = await res.json();
this.updateState(data);
}
} catch (e) {
console.error("[LeafFlow] Error fetching status:", e);
console.error("[SaturnNodes PauseQueue] Error fetching status:", e);
}
}
@@ -58,7 +58,7 @@ class PauseQueueUI {
async togglePause(paused) {
try {
const res = await authenticatedFetch("/pause_queue/toggle", {
const res = await authenticatedFetch("/saturnnodes/pause_queue/toggle", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ paused, mode: this.state.mode })
@@ -68,13 +68,13 @@ class PauseQueueUI {
this.updateState(data);
}
} catch (e) {
console.error("[LeafFlow] Error toggling pause:", e);
console.error("[SaturnNodes PauseQueue] Error toggling pause:", e);
}
}
async setMode(mode) {
try {
const res = await authenticatedFetch("/pause_queue/mode", {
const res = await authenticatedFetch("/saturnnodes/pause_queue/mode", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ mode })
@@ -84,19 +84,19 @@ class PauseQueueUI {
this.updateState(data);
}
} catch (e) {
console.error("[LeafFlow] Error setting mode:", e);
console.error("[SaturnNodes PauseQueue] Error setting mode:", e);
}
}
async continueQueue() {
try {
const res = await authenticatedFetch("/pause_queue/continue", { method: "POST" });
const res = await authenticatedFetch("/saturnnodes/pause_queue/continue", { method: "POST" });
if (res.ok) {
const data = await res.json();
this.updateState(data);
}
} catch (e) {
console.error("[LeafFlow] Error continuing queue:", e);
console.error("[SaturnNodes PauseQueue] Error continuing queue:", e);
}
}
+2 -2
View File
@@ -47,7 +47,7 @@ app.registerExtension({
const claimQueueOwnership = async () => {
if (api && api.clientId) {
try {
await authenticatedFetch("/persistent_queue/claim", {
await authenticatedFetch("/saturnnodes/persistent_queue/claim", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ client_id: api.clientId })
@@ -57,7 +57,7 @@ app.registerExtension({
setTimeout(patchRgthree, 150);
setTimeout(patchRgthree, 600);
} catch (e) {
console.error("[LeafFlow] Error claiming queue ownership:", e);
console.error("[SaturnNodes PersistentQueue] Error claiming queue ownership:", e);
}
}
};
+10 -10
View File
@@ -4,12 +4,12 @@ import { PreviewManager } from "./js/preview_manager.js";
// Global CSS injection to guarantee zero-expansion in Vue Node 2.0 and LiteGraph
if (typeof document !== "undefined") {
const styleId = "leafflow-live-preview-styles";
const styleId = "saturnnodes-live-preview-styles";
if (!document.getElementById(styleId)) {
const style = document.createElement("style");
style.id = styleId;
style.textContent = `
.leafflow-live-preview-container {
.saturnnodes-live-preview-container {
position: absolute !important;
inset: 0 !important;
top: 70px !important;
@@ -29,7 +29,7 @@ if (typeof document !== "undefined") {
box-sizing: border-box !important;
pointer-events: none !important;
}
.leafflow-live-preview-img {
.saturnnodes-live-preview-img {
position: absolute !important;
top: 0 !important;
left: 0 !important;
@@ -48,7 +48,7 @@ if (typeof document !== "undefined") {
min-height: 0 !important;
min-width: 0 !important;
}
[node-type="PreviewLatentLive"] .leafflow-live-preview-container {
[node-type="PreviewLatentLive"] .saturnnodes-live-preview-container {
position: absolute !important;
}
`;
@@ -176,7 +176,7 @@ function updateAllPreviewNodeDropdowns() {
}
app.registerExtension({
name: "ComfyUI.LeafFlow.PreviewLatentLive",
name: "ComfyUI.SaturnNodes.PreviewLatentLive",
async setup() {
PreviewManager.init(app, api);
@@ -234,7 +234,7 @@ app.registerExtension({
this.imageIndex = 0;
const viewContainer = document.createElement("div");
viewContainer.className = "leafflow-live-preview-container";
viewContainer.className = "saturnnodes-live-preview-container";
viewContainer.style.position = "absolute";
viewContainer.style.inset = "0";
viewContainer.style.top = "70px";
@@ -253,12 +253,12 @@ app.registerExtension({
viewContainer.style.pointerEvents = "none";
const fallbackText = document.createElement("div");
fallbackText.className = "leafflow-live-preview-fallback";
fallbackText.className = "saturnnodes-live-preview-fallback";
fallbackText.innerText = "Waiting for live preview...";
viewContainer.appendChild(fallbackText);
const imgElement = document.createElement("img");
imgElement.className = "leafflow-live-preview-img";
imgElement.className = "saturnnodes-live-preview-img";
imgElement.style.position = "absolute";
imgElement.style.top = "0";
imgElement.style.left = "0";
@@ -358,12 +358,12 @@ app.registerExtension({
this.imageIndex = 0;
if (typeof document !== "undefined") {
const domImgs = document.querySelectorAll(`[data-node-id="${this.id}"] .leafflow-live-preview-img, [data-widgets-grid-node-id="${this.id}"] .leafflow-live-preview-img`);
const domImgs = document.querySelectorAll(`[data-node-id="${this.id}"] .saturnnodes-live-preview-img, [data-widgets-grid-node-id="${this.id}"] .saturnnodes-live-preview-img`);
if (domImgs.length > 0) {
domImgs.forEach(imgEl => {
imgEl.src = img.src;
imgEl.style.display = "block";
const fallback = imgEl.parentElement?.querySelector(".leafflow-live-preview-fallback");
const fallback = imgEl.parentElement?.querySelector(".saturnnodes-live-preview-fallback");
if (fallback) fallback.style.display = "none";
});
}
+16 -17
View File
@@ -9,18 +9,14 @@ export const SATURN_NODE_TYPES = new Set([
"VisualLoraLoader",
"FolderLoraLoader",
"FolderLoraLoaderPretty",
"FolderLoraLoaderVisualPrettyV2",
"VisualImageLoader",
"ImageLoaderVisualPrettyV2",
"LoadRecentOutputs",
// Automation, Flow & Utilities
"LoadImageFromFolder",
"TextAspectRatioFinder",
"AspectRatioFinder",
"PreviewImageSizeAspectRatio",
"TextLoraFinder",
"LoraTextFinder",
"PromptQueueIterator",
"PromptCounter",
"MultiTextReplacer",
@@ -30,6 +26,7 @@ export const SATURN_NODE_TYPES = new Set([
// Queue & Previews
"PreviewLatentLive",
"SaturnStereo3D",
"PauseQueueNode",
"PersistentQueueNode"
]);
@@ -126,20 +123,22 @@ export function updateAllSaturnNodeColors() {
app.registerExtension({
name: "ComfyUI.SaturnNodes.Colors",
beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData && nodeData.name && SATURN_NODE_TYPES.has(nodeData.name)) {
if (isSaturnColorsEnabled()) {
const theme = getSaturnTheme();
nodeType.color = theme.color;
nodeType.bgcolor = theme.bgcolor;
nodeType.prototype.color = theme.color;
nodeType.prototype.bgcolor = theme.bgcolor;
} else {
nodeType.color = undefined;
nodeType.bgcolor = undefined;
nodeType.prototype.color = undefined;
nodeType.prototype.bgcolor = undefined;
try {
if (nodeData && nodeData.name && SATURN_NODE_TYPES.has(nodeData.name)) {
if (isSaturnColorsEnabled()) {
const theme = getSaturnTheme();
if (nodeType) {
nodeType.color = theme.color;
nodeType.bgcolor = theme.bgcolor;
}
} else {
if (nodeType) {
nodeType.color = undefined;
nodeType.bgcolor = undefined;
}
}
}
}
} catch (_) {}
},
async nodeCreated(node) {
applySaturnColorToNode(node);
+614 -91
View File
@@ -15,6 +15,118 @@ async function postSaturnNodesSettings(bodyObj) {
}
}
let _disabledNodesCache = null;
let _nodesInfoCache = null;
async function fetchDisabledNodes() {
try {
const res = await authenticatedFetch("/saturnnodes/disabled_nodes");
if (res && res.ok) {
const data = await res.json();
_disabledNodesCache = new Set(data.disabled_nodes || []);
if (Array.isArray(data.nodes_info) && data.nodes_info.length > 0) {
_nodesInfoCache = data.nodes_info;
}
return _disabledNodesCache;
}
} catch (e) {
console.warn("[SaturnNodes Settings] Failed to fetch disabled nodes:", e);
}
return new Set();
}
async function updateNodeDisabledState(nodeKey, isEnabled) {
try {
if (!_disabledNodesCache) {
await fetchDisabledNodes();
}
if (!_disabledNodesCache) {
_disabledNodesCache = new Set();
}
if (isEnabled) {
_disabledNodesCache.delete(nodeKey);
} else {
_disabledNodesCache.add(nodeKey);
}
await authenticatedFetch("/saturnnodes/disabled_nodes", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ disabled_nodes: Array.from(_disabledNodesCache) })
});
if (app.extensionManager?.toast?.add) {
app.extensionManager.toast.add({
severity: "info",
summary: "🪐 SaturnNodes",
detail: `Node availability updated. Reload server or refresh to apply.`,
life: 4000
});
}
} catch (e) {
console.warn(`[SaturnNodes Settings] Failed to update disabled state for ${nodeKey}:`, e);
}
}
const ALL_SATURN_KEYS_SET = new Set([
"FolderLoraLoader",
"FolderLoraLoaderPretty",
"VisualLoraLoader",
"VisualImageLoader",
"LoadImageFromFolder",
"LoadRecentOutputs",
"PreviewLatentLive",
"SaturnDecision",
"TextAspectRatioFinder",
"PreviewImageSizeAspectRatio",
"TextLoraFinder",
"PromptQueueIterator",
"PromptCounter",
"MultiTextReplacer",
"SaturnTextSplit",
"RunLocalFileNode",
"SaturnStereo3D"
]);
function checkLoadedWorkflowForDisabledNodes(graphData) {
if (!graphData || !Array.isArray(graphData.nodes)) return;
fetchDisabledNodes().then(disabledSet => {
if (!disabledSet || disabledSet.size === 0) return;
const found = [];
for (const node of graphData.nodes) {
const nodeType = node?.type;
if (nodeType && disabledSet.has(nodeType) && ALL_SATURN_KEYS_SET.has(nodeType)) {
if (!found.includes(nodeType)) {
found.push(nodeType);
}
}
}
if (found.length > 0) {
const namesList = found.join(", ");
if (app.extensionManager?.toast?.add) {
app.extensionManager.toast.add({
severity: "warn",
summary: "🪐 SaturnNodes: Disabled Nodes in Workflow",
detail: `This workflow uses disabled SaturnNodes: ${namesList}. Re-enable them in Settings -> SaturnNodes -> Node Management to run.`,
life: 10000
});
} else {
console.warn(`[SaturnNodes] Loaded workflow contains disabled nodes: ${namesList}`);
}
}
});
}
// Hook ComfyUI workflow loading to alert if disabled nodes are present in the workflow
try {
const origLoadGraphData = app.loadGraphData;
if (typeof origLoadGraphData === "function") {
app.loadGraphData = function (graphData, ...args) {
checkLoadedWorkflowForDisabledNodes(graphData);
return origLoadGraphData.apply(this, [graphData, ...args]);
};
}
} catch (_) {}
// Inject CSS to ensure settings buttons look distinct and dropdown menus retain proper styling
if (typeof document !== "undefined") {
const styleId = "saturnnodes-settings-button-styles";
@@ -25,12 +137,8 @@ if (typeof document !== "undefined") {
/* ComfyUI V2 Vue Toggle Switches Protection: NEVER apply button background or borders to switches */
[data-setting-id*="SaturnNodes"] button[role="switch"],
[data-setting-id*="saturnnodes"] button[role="switch"],
[data-setting-id*="LeafFlow"] button[role="switch"],
[data-setting-id*="leafflow"] button[role="switch"],
[data-setting-id*="SaturnNodes"] [role="switch"],
[data-setting-id*="saturnnodes"] [role="switch"],
[data-setting-id*="LeafFlow"] [role="switch"],
[data-setting-id*="leafflow"] [role="switch"],
button[role="switch"].saturnnodes-settings-btn {
background: transparent !important;
border: 0 !important;
@@ -71,11 +179,8 @@ if (typeof document !== "undefined") {
/* ComfyUI Settings Action Buttons (Buttons only: 1.5x height, font-size 13px) */
button.saturnnodes-settings-btn,
button.leafflow-settings-btn,
[data-setting-id*="SaturnNodes"] button:not([role="switch"]):not([data-pc-name="toggleswitch"]),
[data-setting-id*="saturnnodes"] button:not([role="switch"]):not([data-pc-name="toggleswitch"]),
[data-setting-id*="LeafFlow"] button:not([role="switch"]):not([data-pc-name="toggleswitch"]),
[data-setting-id*="leafflow"] button:not([role="switch"]):not([data-pc-name="toggleswitch"]) {
[data-setting-id*="saturnnodes"] button:not([role="switch"]):not([data-pc-name="toggleswitch"]) {
background: #8b7355 !important;
border: 1px solid #a68a67 !important;
color: #ffffff !important;
@@ -103,11 +208,8 @@ if (typeof document !== "undefined") {
}
button.saturnnodes-settings-btn:hover,
button.leafflow-settings-btn:hover,
[data-setting-id*="SaturnNodes"] button:not([role="switch"]):not([data-pc-name="toggleswitch"]):hover,
[data-setting-id*="saturnnodes"] button:not([role="switch"]):not([data-pc-name="toggleswitch"]):hover,
[data-setting-id*="LeafFlow"] button:not([role="switch"]):not([data-pc-name="toggleswitch"]):hover,
[data-setting-id*="leafflow"] button:not([role="switch"]):not([data-pc-name="toggleswitch"]):hover {
[data-setting-id*="saturnnodes"] button:not([role="switch"]):not([data-pc-name="toggleswitch"]):hover {
background: #9e8565 !important;
border-color: #c4a780 !important;
color: #ffffff !important;
@@ -116,7 +218,6 @@ if (typeof document !== "undefined") {
}
button.saturnnodes-settings-btn:active,
button.leafflow-settings-btn:active,
[data-setting-id*="SaturnNodes"] button:not([role="switch"]):not([data-pc-name="toggleswitch"]):active {
background: #7d6549 !important;
transform: translateY(0) !important;
@@ -500,6 +601,12 @@ function renderSketchColorSetting(settingId, defaultColor) {
if (typeof setter === "function") {
setter(newHex);
}
if (typeof app.ui?.settings?.setSettingValue === "function") {
try { app.ui.settings.setSettingValue(settingId, newHex); } catch (_) {}
}
if (typeof app.ui?.settings?.set === "function") {
try { app.ui.settings.set(settingId, newHex); } catch (_) {}
}
if (typeof localStorage !== "undefined") {
try {
localStorage.setItem(`Comfy.Settings.${settingId}`, JSON.stringify(newHex));
@@ -608,69 +715,26 @@ function renderSettingButton(label, workingText, successText, onClickHandler) {
};
}
/**
* Migration helper ensuring user preferences from legacy LeafFlow.* are seamlessly inherited.
*/
function migrateSavedSettings() {
try {
if (typeof localStorage === "undefined") return;
const keysToMigrate = [];
for (let i = 0; i < localStorage.length; i++) {
const k = localStorage.key(i);
if (k && (k.includes("LeafFlow.") || k.includes("leafflow."))) {
keysToMigrate.push(k);
}
}
for (const oldKey of keysToMigrate) {
const val = localStorage.getItem(oldKey);
if (val === null) continue;
const newKey = oldKey.replace(/LeafFlow/g, "SaturnNodes").replace(/leafflow/g, "saturnnodes");
if (newKey !== oldKey && localStorage.getItem(newKey) === null) {
localStorage.setItem(newKey, val);
}
}
} catch (e) {
console.warn("[SaturnNodes] Settings migration skipped:", e);
}
}
migrateSavedSettings();
function getInitialSetting(saturnId, defaultVal) {
if (typeof localStorage === "undefined") return defaultVal;
// Build lookup keys: unnumbered, numbered, and legacy variants
const variations = [saturnId];
const categoryMap = {
"🖼️ Visual Loaders": "1 - 🖼️ Visual Loaders",
"🔄 Prompt Iterator": "2 - 🔄 Prompt Iterator",
"📋 Prompt Actions": "3 - 📋 Prompt Actions",
"⏸️ Pause Controls": "4 - ⏸️ Pause Controls",
"💾 Persistent Queue": "5 - 💾 Persistent Queue",
"🖼️ Assets Restore": "6 - 🖼️ Assets Restore",
"🩺 Diagnostics": "7 - 🩺 Diagnostics",
"🎨 Batch Queue": "8 - 🎨 Batch Queue",
"🛡️ Security": "9 - 🛡️ Security"
};
for (const [plain, num] of Object.entries(categoryMap)) {
if (saturnId.includes(plain)) {
variations.push(saturnId.replace(plain, num));
break;
}
// 1. Check ComfyUI settings API (getSettingValue / get)
if (typeof app.ui?.settings?.getSettingValue === "function") {
try {
const val = app.ui.settings.getSettingValue(saturnId);
if (val !== undefined && val !== null) return val;
} catch (_) {}
}
if (typeof app.ui?.settings?.get === "function") {
try {
const val = app.ui.settings.get(saturnId);
if (val !== undefined && val !== null) return val;
} catch (_) {}
}
const len = variations.length;
for (let i = 0; i < len; i++) {
variations.push(variations[i].replace(/^SaturnNodes\./, "LeafFlow."));
}
for (const prefix of ["Comfy.Settings.", ""]) {
for (const vId of variations) {
const val = localStorage.getItem(`${prefix}${vId}`);
if (val !== null && val !== undefined) {
try { return JSON.parse(val); } catch (_) { return val; }
}
// 2. Check localStorage
if (typeof localStorage !== "undefined") {
const val = localStorage.getItem(`Comfy.Settings.${saturnId}`);
if (val !== null && val !== undefined) {
try { return JSON.parse(val); } catch (_) { return val; }
}
}
return defaultVal;
@@ -679,7 +743,6 @@ function getInitialSetting(saturnId, defaultVal) {
app.registerExtension({
name: "ComfyUI.SaturnNodes.Settings",
async setup() {
migrateSavedSettings();
// =========================================================================
// GROUP: 🖼️ Visual Loaders
@@ -839,6 +902,110 @@ app.registerExtension({
}
});
// 1.7 Bypass Thumbnail Downscaling (default: false)
app.ui.settings.addSetting({
id: "SaturnNodes.🖼️ Visual Loaders.07_BypassThumbnailDownscaling",
name: "Disable Thumbnail Downscaling (Serve Raw)",
type: "boolean",
defaultValue: getInitialSetting("SaturnNodes.🖼️ Visual Loaders.07_BypassThumbnailDownscaling", false),
tooltip: "When enabled, serves full-resolution original preview images directly without generating downscaled WebP thumbnails. Default is disabled (downscaled WebP thumbnails enabled for faster UI rendering).",
onChange(value) {
if (typeof localStorage !== "undefined") {
try {
localStorage.setItem("Comfy.Settings.SaturnNodes.🖼️ Visual Loaders.07_BypassThumbnailDownscaling", JSON.stringify(Boolean(value)));
} catch (_) {}
}
}
});
// =========================================================================
// GROUP: 👁️ Live Preview
// =========================================================================
// 10.1 Enable Floating Latent Dock (default: true)
app.ui.settings.addSetting({
id: "SaturnNodes.👁️ Live Preview.01_EnableFloatingDock",
name: "Enable Floating Latent Dock",
type: "boolean",
defaultValue: getInitialSetting("SaturnNodes.👁️ Live Preview.01_EnableFloatingDock", true),
tooltip: "Adds a floating picture-in-picture Live Latent preview dock to the bottom-right corner and a toggle button to the canvas toolbar.",
onChange(value) {
if (typeof localStorage !== "undefined") {
try {
localStorage.setItem("Comfy.Settings.SaturnNodes.👁️ Live Preview.01_EnableFloatingDock", JSON.stringify(Boolean(value)));
} catch (_) {}
}
const btn = document.getElementById("saturn-floating-dock-btn");
const dock = document.getElementById("saturn-latent-floating-dock");
if (btn) btn.style.display = value ? "inline-flex" : "none";
if (dock) {
if (value) {
dock.classList.remove("saturn-dock-hidden");
} else {
dock.classList.add("saturn-dock-hidden");
}
}
}
});
// 10.2a Floating Dock Max Width (default: 280)
const rawMaxWidth = getInitialSetting("SaturnNodes.👁️ Live Preview.02a_FloatingDockMaxWidth", 280);
const initialMaxWidth = Math.max(100, Math.min(2000, parseInt(String(rawMaxWidth).match(/\d+/)?.[0] || rawMaxWidth, 10) || 280));
app.ui.settings.addSetting({
id: "SaturnNodes.👁️ Live Preview.02a_FloatingDockMaxWidth",
name: "Floating Dock Max Width",
type: "slider",
attrs: { min: 100, max: 2000, step: 1 },
defaultValue: initialMaxWidth,
tooltip: "Maximum width limit (in pixels) for the floating live preview dock (100px to 2000px, 1px steps). Drag the dock's top-left corner to set any box size; the dock itself always matches the exact latent aspect ratio without distortion.",
onChange(value) {
const num = parseInt(value, 10) || 280;
if (typeof localStorage !== "undefined") {
try {
localStorage.setItem("Comfy.Settings.SaturnNodes.👁️ Live Preview.02a_FloatingDockMaxWidth", JSON.stringify(num));
} catch (_) {}
}
}
});
// 10.2b Floating Dock Max Height (default: 280)
const rawMaxHeight = getInitialSetting("SaturnNodes.👁️ Live Preview.02b_FloatingDockMaxHeight", 280);
const initialMaxHeight = Math.max(100, Math.min(2000, parseInt(String(rawMaxHeight).match(/\d+/)?.[0] || rawMaxHeight, 10) || 280));
app.ui.settings.addSetting({
id: "SaturnNodes.👁️ Live Preview.02b_FloatingDockMaxHeight",
name: "Floating Dock Max Height",
type: "slider",
attrs: { min: 100, max: 2000, step: 1 },
defaultValue: initialMaxHeight,
tooltip: "Maximum height limit (in pixels) for the floating live preview dock (100px to 2000px, 1px steps). Drag the dock's top-left corner to set any box size; the dock itself always matches the exact latent aspect ratio without distortion.",
onChange(value) {
const num = parseInt(value, 10) || 280;
if (typeof localStorage !== "undefined") {
try {
localStorage.setItem("Comfy.Settings.SaturnNodes.👁️ Live Preview.02b_FloatingDockMaxHeight", JSON.stringify(num));
} catch (_) {}
}
}
});
// 10.3 Auto-Hide Dock When Idle (default: false)
app.ui.settings.addSetting({
id: "SaturnNodes.👁️ Live Preview.03_AutoHideWhenIdle",
name: "Auto-Hide Dock When Idle",
type: "boolean",
defaultValue: getInitialSetting("SaturnNodes.👁️ Live Preview.03_AutoHideWhenIdle", false),
tooltip: "When enabled, the floating dock automatically hides when generation is idle and appears when sampling begins.",
onChange(value) {
if (typeof localStorage !== "undefined") {
try {
localStorage.setItem("Comfy.Settings.SaturnNodes.👁️ Live Preview.03_AutoHideWhenIdle", JSON.stringify(Boolean(value)));
} catch (_) {}
}
}
});
// =========================================================================
// GROUP: 🔄 Prompt Iterator
// =========================================================================
@@ -1017,6 +1184,242 @@ app.registerExtension({
}
});
// 4.8 Visible Queue Items (Height Limit) with Per-Resolution Memory & Direct Resize Handle
const getScreenProfileKey = () => {
if (typeof window === "undefined" || !window.screen) return "default";
return `${window.screen.width}x${window.screen.height}`;
};
const getEffectiveQueueHeight = () => {
try {
const saved = localStorage.getItem(`Comfy.SaturnNodes.QueueHeight.${getScreenProfileKey()}`);
if (saved) {
const parsed = parseInt(saved, 10);
if (!isNaN(parsed) && parsed > 0) return parsed;
}
} catch (_) {}
const rawQueueHeight = getInitialSetting("SaturnNodes.⏸️ Pause Controls.08_QueueOverlayMaxHeight", 0);
if (typeof rawQueueHeight === "number") return rawQueueHeight;
if (rawQueueHeight && rawQueueHeight !== "Native") {
const match = String(rawQueueHeight).match(/\d+/);
if (match) return parseInt(match[0], 10);
}
return 0;
};
let saturnQueueHeightPx = 0;
const ensureQueueHandleStyles = () => {
if (document.getElementById("saturn-queue-overlay-height")) return;
const style = document.createElement("style");
style.id = "saturn-queue-overlay-height";
style.textContent = `
.saturn-queue-resize-handle {
width: 100%;
height: 12px;
cursor: ns-resize;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
margin-top: auto;
background: transparent;
transition: background 0.15s ease;
user-select: none;
touch-action: none;
z-index: 25;
}
.saturn-queue-resize-handle:hover,
.saturn-queue-resize-handle.active {
background: rgba(245, 158, 11, 0.2);
}
.saturn-queue-resize-bar {
width: 36px;
height: 3px;
border-radius: 2px;
background: rgba(255, 255, 255, 0.3);
transition: background 0.15s ease, width 0.15s ease;
}
.saturn-queue-resize-handle:hover .saturn-queue-resize-bar,
.saturn-queue-resize-handle.active .saturn-queue-resize-bar {
background: #f59e0b;
width: 52px;
}
`;
document.head.appendChild(style);
};
// Applies the queue height via direct inline styles on the overlay elements.
// Rewriting a <style> element's text on every pointermove forced a full-document
// style recalculation and made resizing extremely laggy.
const applyQueueOverlayHeight = (val) => {
let px = 0;
if (typeof val === "number") {
px = val;
} else if (val && val !== "Native") {
const match = String(val).match(/\d+/);
if (match) px = parseInt(match[0], 10);
}
saturnQueueHeightPx = (px && px > 0) ? Math.min(1200, Math.round(px)) : 0;
const overlay = document.querySelector('[data-testid="queue-progress-overlay"]');
const lists = overlay
? Array.from(overlay.querySelectorAll(".comfy-list"))
: Array.from(document.querySelectorAll(".comfy-list"));
if (overlay) {
if (saturnQueueHeightPx > 0) {
overlay.style.setProperty("max-height", `${saturnQueueHeightPx}px`, "important");
} else {
overlay.style.removeProperty("max-height");
}
}
for (const listEl of lists) {
listEl.style.setProperty("overflow-y", "auto", "important");
if (saturnQueueHeightPx > 0) {
listEl.style.setProperty("max-height", `${saturnQueueHeightPx}px`, "important");
} else {
listEl.style.removeProperty("max-height");
}
}
};
const attachQueueResizeHandle = (overlay) => {
if (!overlay || overlay.querySelector(".saturn-queue-resize-handle")) return;
ensureQueueHandleStyles();
const handle = document.createElement("div");
handle.className = "saturn-queue-resize-handle";
handle.title = "Drag to resize queue overlay (remembers size per monitor)";
handle.innerHTML = `<div class="saturn-queue-resize-bar"></div>`;
handle.addEventListener("pointerdown", (e) => {
if (e.button !== 0) return;
e.preventDefault();
e.stopPropagation();
const startY = e.clientY;
const startH = overlay.offsetHeight || saturnQueueHeightPx || getEffectiveQueueHeight() || 360;
handle.classList.add("active");
document.body.style.cursor = "ns-resize";
let currentH = startH;
let rafPending = false;
let rafId = 0;
let finished = false;
// Pointer capture guarantees pointerup delivery even outside the window
try {
if (handle.setPointerCapture) handle.setPointerCapture(e.pointerId);
} catch (_) {}
const applyFrame = () => {
rafPending = false;
rafId = 0;
applyQueueOverlayHeight(currentH);
};
const onPointerMove = (me) => {
const dy = me.clientY - startY;
currentH = Math.max(120, Math.min(1200, Math.round(startH + dy)));
if (!rafPending) {
rafPending = true;
rafId = requestAnimationFrame(applyFrame);
}
};
const finishDrag = () => {
if (finished) return;
finished = true;
if (rafId) {
cancelAnimationFrame(rafId);
rafId = 0;
}
window.removeEventListener("pointermove", onPointerMove);
window.removeEventListener("pointerup", finishDrag);
window.removeEventListener("pointercancel", finishDrag);
window.removeEventListener("blur", finishDrag);
try {
if (handle.releasePointerCapture) handle.releasePointerCapture(e.pointerId);
} catch (_) {}
handle.classList.remove("active");
document.body.style.cursor = "";
const screenKey = getScreenProfileKey();
try {
localStorage.setItem(`Comfy.SaturnNodes.QueueHeight.${screenKey}`, String(currentH));
} catch (_) {}
try {
localStorage.setItem("Comfy.Settings.SaturnNodes.⏸️ Pause Controls.08_QueueOverlayMaxHeight", JSON.stringify(currentH));
if (app?.ui?.settings?.setSettingValue) {
app.ui.settings.setSettingValue("SaturnNodes.⏸️ Pause Controls.08_QueueOverlayMaxHeight", currentH);
}
} catch (_) {}
};
window.addEventListener("pointermove", onPointerMove);
window.addEventListener("pointerup", finishDrag);
window.addEventListener("pointercancel", finishDrag);
window.addEventListener("blur", finishDrag);
});
overlay.appendChild(handle);
// Re-apply the stored height budget to freshly mounted overlays
applyQueueOverlayHeight(saturnQueueHeightPx);
};
const existingQueueOverlay = document.querySelector('[data-testid="queue-progress-overlay"]');
if (existingQueueOverlay) attachQueueResizeHandle(existingQueueOverlay);
const queueOverlayObserver = new MutationObserver(() => {
const overlay = document.querySelector('[data-testid="queue-progress-overlay"]');
if (overlay) {
attachQueueResizeHandle(overlay);
}
});
queueOverlayObserver.observe(document.body, { childList: true, subtree: true });
// Listen for screen resolution changes when moving between laptop and 4K display
let lastScreenKey = getScreenProfileKey();
window.addEventListener("resize", () => {
const currentKey = getScreenProfileKey();
if (currentKey !== lastScreenKey) {
lastScreenKey = currentKey;
applyQueueOverlayHeight(getEffectiveQueueHeight());
}
});
const initialQueueHeight = getEffectiveQueueHeight();
applyQueueOverlayHeight(initialQueueHeight);
app.ui.settings.addSetting({
id: "SaturnNodes.⏸️ Pause Controls.08_QueueOverlayMaxHeight",
name: "Visible Queue Items (Height)",
type: "slider",
attrs: { min: 0, max: 1200, step: 1 },
defaultValue: initialQueueHeight,
tooltip: "Limits the visible height of the queue overlay panel in pixels (e.g. 360 ≈ 10 items, 500 ≈ 15 items) with a scrollbar. You can also drag the bottom edge of the queue overlay directly on screen (remembers size per monitor). Set to 0 for Native.",
onChange(value) {
const num = parseInt(value, 10) || 0;
const screenKey = getScreenProfileKey();
if (typeof localStorage !== "undefined") {
try {
localStorage.setItem("Comfy.Settings.SaturnNodes.⏸️ Pause Controls.08_QueueOverlayMaxHeight", JSON.stringify(num));
if (num > 0) {
localStorage.setItem(`Comfy.SaturnNodes.QueueHeight.${screenKey}`, String(num));
}
} catch (_) {}
}
applyQueueOverlayHeight(num);
}
});
// =========================================================================
// GROUP: 💾 Persistent Queue
// =========================================================================
@@ -1169,6 +1572,70 @@ app.registerExtension({
}
});
// =========================================================================
// GROUP: 🧩 Node Management
// =========================================================================
await fetchDisabledNodes();
const defaultSaturnNodeDefinitions = [
// Loaders
{ key: "FolderLoraLoader", name: "Loaders / LoRA Loader (Folder)", desc: "🪐 📁 LoRA Loader (Folder)" },
{ key: "FolderLoraLoaderPretty", name: "Loaders / LoRA Loader (Pretty)", desc: "🪐 ✨ LoRA Loader (Pretty)" },
{ key: "LoadRecentOutputs", name: "Loaders / Recent Outputs", desc: "🪐 ⏱️ Recent Outputs" },
{ key: "TextLoraFinder", name: "Loaders / Text LoRA Finder & Loader", desc: "🪐 🔎 Text LoRA Finder & Loader" },
{ key: "VisualImageLoader", name: "Loaders / Visual Image Loader", desc: "🪐 📷 Visual Image Loader" },
{ key: "VisualLoraLoader", name: "Loaders / Visual LoRA Loader", desc: "🪐 🖼️ Visual LoRA Loader" },
// Automation
{ key: "LoadImageFromFolder", name: "Automation / Load Image From Folder", desc: "🪐 📂 Load Image From Folder" },
{ key: "RunLocalFileNode", name: "Automation / Run Local File", desc: "🪐 ⚡ Run Local File" },
// Previews
{ key: "PreviewLatentLive", name: "Previews / Live Latent Preview", desc: "🪐 👁️ Live Latent Preview" },
// 3D & Previews
{ key: "SaturnStereo3D", name: "3D & Previews / Stereoscopic 3D Generator", desc: "🪐 👓 Stereoscopic 3D Generator" },
// Utils
{ key: "MultiTextReplacer", name: "Utils / Multi Text Replacer", desc: "🪐 🔤 Multi Text Replacer" },
{ key: "PreviewImageSizeAspectRatio", name: "Utils / Preview Image Size & Aspect Ratio", desc: "🪐 📐 Preview Image Size & Aspect Ratio" },
{ key: "PromptCounter", name: "Utils / Prompt Counter", desc: "🪐 📝 Prompt Counter" },
{ key: "PromptQueueIterator", name: "Utils / Prompt Queue Iterator", desc: "🪐 🔄 Prompt Queue Iterator" },
{ key: "SaturnDecision", name: "Utils / Saturn Decision", desc: "🪐 ⏸️ Saturn Decision" },
{ key: "TextAspectRatioFinder", name: "Utils / Text Aspect Ratio Finder", desc: "🪐 📐 Text Aspect Ratio Finder" },
{ key: "SaturnTextSplit", name: "Utils / Text Split", desc: "🪐 ✂️ Text Split" }
];
const saturnNodeDefinitions = (_nodesInfoCache && Array.isArray(_nodesInfoCache) && _nodesInfoCache.length > 0)
? _nodesInfoCache
: defaultSaturnNodeDefinitions;
saturnNodeDefinitions.forEach((node, index) => {
const numStr = String(index + 1).padStart(2, "0");
const settingId = `SaturnNodes.🧩 Node Management.${numStr}_${node.key}`;
const legacySettingId = `SaturnNodes.🧩 Node Management.${numStr}_Enable_${node.key}`;
const isInitialDisabled = _disabledNodesCache ? _disabledNodesCache.has(node.key) : false;
const defaultValue = isInitialDisabled ? false : getInitialSetting(settingId, getInitialSetting(legacySettingId, true));
app.ui.settings.addSetting({
id: settingId,
name: node.name,
type: "boolean",
defaultValue: defaultValue,
tooltip: `Enables or disables ${node.desc}. When disabled, the node is hidden from the node search menu (requires server restart to take effect).`,
onChange(value) {
if (typeof localStorage !== "undefined") {
try {
localStorage.setItem(`Comfy.Settings.${settingId}`, JSON.stringify(Boolean(value)));
localStorage.setItem(`Comfy.Settings.${legacySettingId}`, JSON.stringify(Boolean(value)));
} catch (_) {}
}
updateNodeDisabledState(node.key, Boolean(value));
}
});
});
// =========================================================================
// Automatically inject footer linking to GitHub, author profile, and README guide
setupSettingsFooterObserver();
@@ -1177,23 +1644,28 @@ app.registerExtension({
/**
* Injects a clean footer linking to GitHub, author profile, and settings reference
* at the bottom of the SaturnNodes settings panel.
* strictly at the bottom of the SaturnNodes settings panel, excluding it from search.
*/
function setupSettingsFooterObserver() {
function injectFooterIfMissing() {
const saturnItem = document.querySelector('[data-setting-id^="SaturnNodes.🛡️ Security"]') ||
document.querySelector('[data-setting-id^="SaturnNodes.9 - 🛡️ Security"]') ||
document.querySelector('[data-setting-id^="SaturnNodes."]');
if (!saturnItem || !saturnItem.parentElement) return;
function getSearchTerm() {
const dialog = document.querySelector('.p-dialog[role="dialog"]') ||
document.querySelector('.comfy-settings-dialog') ||
document.querySelector('[data-testid="settings-dialog"]');
if (!dialog) return "";
const searchInput = dialog.querySelector('input[type="search"]') ||
dialog.querySelector('input[placeholder*="Search" i]') ||
dialog.querySelector('input.p-inputtext');
return searchInput ? searchInput.value.trim() : "";
}
const container = saturnItem.parentElement;
if (container.querySelector(".saturnnodes-settings-footer")) return;
function createSettingsFooter() {
const githubSvg = `<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor" style="display:inline-block; vertical-align:text-bottom; margin-right:4px;"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>`;
const footer = document.createElement("div");
footer.className = "saturnnodes-settings-footer";
footer.style.cssText = `
margin-top: 48px !important;
padding: 20px 10px 10px;
margin-top: 40px !important;
padding: 20px 10px 12px;
border-top: 1px solid rgba(255, 255, 255, 0.12);
display: flex;
align-items: center;
@@ -1206,13 +1678,11 @@ function setupSettingsFooterObserver() {
box-sizing: border-box;
`;
const githubSvg = `<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor" style="display:inline-block; vertical-align:text-bottom; margin-right:4px;"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>`;
footer.innerHTML = `
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 16px;">🪐</span>
<span style="font-weight: 600; color: #e4e4e7;">ComfyUI-SaturnNodes</span>
<span style="font-size: 11px; padding: 2px 7px; border-radius: 4px; background: rgba(180, 140, 95, 0.18); color: #decbb2; border: 1px solid rgba(180, 140, 95, 0.35);">v2.4.1 (latest)</span>
<span style="font-size: 11px; padding: 2px 7px; border-radius: 4px; background: rgba(180, 140, 95, 0.18); color: #decbb2; border: 1px solid rgba(180, 140, 95, 0.35);">v2.6.1 (dev)</span>
</div>
<div style="display: flex; align-items: center; gap: 10px; flex-wrap: wrap;">
<a href="https://github.com/KOFiblto/ComfyUI-SaturnNodes" target="_blank" rel="noopener noreferrer" style="color: #decbb2; text-decoration: underline; text-decoration-color: rgba(222, 203, 178, 0.4); text-underline-offset: 3px; font-weight: 500; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.12); transition: all 0.2s ease;" onmouseover="this.style.color='#ffffff'; this.style.background='rgba(255,255,255,0.12)'; this.style.borderColor='rgba(255,255,255,0.25)';" onmouseout="this.style.color='#decbb2'; this.style.background='rgba(255,255,255,0.05)'; this.style.borderColor='rgba(255,255,255,0.12)';">
@@ -1226,15 +1696,68 @@ function setupSettingsFooterObserver() {
</a>
</div>
`;
container.appendChild(footer);
return footer;
}
function updateFooter() {
const dialog = document.querySelector('.p-dialog[role="dialog"]') ||
document.querySelector('.comfy-settings-dialog');
const existingFooter = document.querySelector(".saturnnodes-settings-footer");
if (!dialog) {
if (existingFooter) existingFooter.remove();
return;
}
const searchTerm = getSearchTerm();
// Hide footer immediately when searching so it doesn't pollute search results
if (searchTerm.length > 0) {
if (existingFooter) existingFooter.remove();
return;
}
// Find all setting groups in the dialog
const allGroups = Array.from(dialog.querySelectorAll('.setting-group'));
const saturnGroups = allGroups.filter(g => g.querySelector('[data-setting-id^="SaturnNodes."]'));
// If no SaturnNodes groups are rendered in the DOM, remove footer
if (saturnGroups.length === 0) {
if (existingFooter) existingFooter.remove();
return;
}
// Check if other category groups exist (e.g. Comfy core settings)
const otherGroups = allGroups.filter(g => g.querySelector('[data-setting-id]:not([data-setting-id^="SaturnNodes."])'));
// If other non-Saturn groups outnumber Saturn groups, user navigated to another category
if (otherGroups.length > 0 && otherGroups.length > saturnGroups.length) {
if (existingFooter) existingFooter.remove();
return;
}
// We are on SaturnNodes page! Locate the last SaturnNodes setting group
const lastGroup = saturnGroups[saturnGroups.length - 1];
if (!lastGroup) return;
let footer = existingFooter;
if (!footer) {
footer = createSettingsFooter();
}
// Append footer directly after the last SaturnNodes group
if (lastGroup.parentElement && lastGroup.nextElementSibling !== footer) {
lastGroup.after(footer);
}
}
try {
// Shallow body observer (settings dialog mounts/unmounts as a direct child);
// deep subtree observation fired this callback for every DOM mutation in the
// whole app. The 500ms interval below remains as the catch-all.
const observer = new MutationObserver(() => {
injectFooterIfMissing();
updateFooter();
});
observer.observe(document.body, { childList: true, subtree: true });
observer.observe(document.body, { childList: true, subtree: false });
} catch (_) {}
setInterval(injectFooterIfMissing, 1000);
setInterval(updateFooter, 500);
}