mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
- Implement LoRA locking to prevent specific LoRAs from being changed during randomization - Add visual styling for locked state with amber accents and distinct backgrounds - Introduce `roll_mode` configuration with 'backend' (execute current selection while generating new) and 'frontend' (execute newly generated selection) behaviors - Move LoraPoolNode to 'Lora Manager/randomizer' category and remove standalone class mappings - Standardize RETURN_NAMES in LoraRandomizerNode for consistency
5.2 KiB
5.2 KiB
AGENTS.md
This file provides guidance for agentic coding assistants working in this repository.
Development Commands
Backend Development
# Install dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt
# Run standalone server (port 8188 by default)
python standalone.py --port 8188
# Run all backend tests
pytest
# Run specific test file
pytest tests/test_recipes.py
# Run specific test function
pytest tests/test_recipes.py::test_function_name
# Run backend tests with coverage
COVERAGE_FILE=coverage/backend/.coverage pytest \
--cov=py \
--cov=standalone \
--cov-report=term-missing \
--cov-report=html:coverage/backend/html \
--cov-report=xml:coverage/backend/coverage.xml \
--cov-report=json:coverage/backend/coverage.json
Frontend Development
# Install frontend dependencies
npm install
# Run frontend tests
npm test
# Run frontend tests in watch mode
npm run test:watch
# Run frontend tests with coverage
npm run test:coverage
Python Code Style
Imports
- Use
from __future__ import annotationsfor forward references in type hints - Group imports: standard library, third-party, local (separated by blank lines)
- Use absolute imports within
py/package:from ..services import X - Mock ComfyUI dependencies in tests using
tests/conftest.pypatterns
Formatting & Types
- PEP 8 with 4-space indentation
- Type hints required for function signatures and class attributes
- Use
TYPE_CHECKINGguard for type-checking-only imports - Prefer dataclasses for simple data containers
- Use
Optional[T]for nullable types,Union[T, None]only when necessary
Naming Conventions
- Files:
snake_case.py(e.g.,model_scanner.py,lora_service.py) - Classes:
PascalCase(e.g.,ModelScanner,LoraService) - Functions/variables:
snake_case(e.g.,get_instance,model_type) - Constants:
UPPER_SNAKE_CASE(e.g.,VALID_LORA_TYPES) - Private members:
_single_underscore(protected),__double_underscore(name-mangled)
Error Handling
- Use
logging.getLogger(__name__)for module-level loggers - Define custom exceptions in
py/services/errors.py - Use
asyncio.Lockfor thread-safe singleton patterns - Raise specific exceptions with descriptive messages
- Log errors at appropriate levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
Async Patterns
- Use
async deffor I/O-bound operations - Mark async tests with
@pytest.mark.asyncio - Use
async withfor context managers - Singleton pattern with class-level locks: see
ModelScanner.get_instance() - Use
aiohttp.web.Responsefor HTTP responses
Testing Patterns
- Use
pytestwith--import-mode=importlib - Fixtures in
tests/conftest.pyhandle ComfyUI mocking - Use
@pytest.mark.no_settings_dir_isolationfor tests needing real paths - Test files:
tests/test_*.py - Use
tmp_path_factoryfor temporary directory isolation
JavaScript Code Style
Imports & Modules
- ES modules with
import/export - Use
import { app } from "../../scripts/app.js"for ComfyUI integration - Export named functions/classes:
export function foo() {} - Widget files use
*_widget.jssuffix
Naming & Formatting
- camelCase for functions, variables, object properties
- PascalCase for classes/constructors
- Constants:
UPPER_SNAKE_CASE(e.g.,CONVERTED_TYPE) - Files:
snake_case.jsorkebab-case.js - 2-space indentation preferred (follow existing file conventions)
Widget Development
- Use
app.registerExtension()to register ComfyUI extensions - Use
node.addDOMWidget(name, type, element, options)for custom widgets - Event handlers attached via
addEventListeneror widget callbacks - See
web/comfyui/utils.jsfor shared utilities
Architecture Patterns
Service Layer
- Use
ServiceRegistrysingleton for dependency injection - Services follow singleton pattern via
get_instance()class method - Separate scanners (discovery) from services (business logic)
- Handlers in
py/routes/handlers/implement route logic
Model Types
- BaseModelService is abstract base for LoRA, Checkpoint, Embedding services
- ModelScanner provides file discovery and hash-based deduplication
- Persistent cache in SQLite via
PersistentModelCache - Metadata sync from CivitAI/CivArchive via
MetadataSyncService
Routes & Handlers
- Route registrars organize endpoints by domain:
ModelRouteRegistrar, etc. - Handlers are pure functions taking dependencies as parameters
- Use
WebSocketManagerfor real-time progress updates - Return
aiohttp.web.json_responseorweb.Response
Recipe System
- Base metadata in
py/recipes/base.py - Enrichment adds model metadata:
RecipeEnrichmentService - Parsers for different formats in
py/recipes/parsers/
Important Notes
- Always use English for comments (per copilot-instructions.md)
- Dual mode: ComfyUI plugin (uses folder_paths) vs standalone (reads settings.json)
- Detection:
os.environ.get("LORA_MANAGER_STANDALONE", "0") == "1" - Settings auto-saved in user directory or portable mode
- WebSocket broadcasts for real-time updates (downloads, scans)
- Symlink handling requires normalized paths
- API endpoints follow
/loras/*,/checkpoints/*,/embeddings/*patterns - Run
python scripts/sync_translation_keys.pyafter UI string updates