8.6 KiB
8.6 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is a ComfyUI extension that adds a server-side notes sidebar for managing markdown notes. The extension provides a complete notes management system with both backend API endpoints and a frontend JavaScript interface.
Architecture
Backend (Python)
- Main Module:
__init__.py- Core extension entry point - NotesManager Class: Handles all note operations (CRUD) with file system storage
- API Endpoints: RESTful endpoints using aiohttp web framework integrated with ComfyUI's PromptServer
- File Storage: Notes stored as
.mdfiles in ComfyUI's user directory underdefault/comfyui-notes-sidebar/notes/(fallback to extension'snotes/directory)
Frontend (JavaScript)
- Extension Module:
js/extension.js- Main ComfyUI extension integration and UI orchestration - State Management:
js/stores/NotesStore.js- Event-driven state management using EventTarget pattern - Components:
js/components/AppendMenu.js- Append functionality (currently LoRA integration) with submenu UI
- API Layer:
js/api/notesApi.js- Centralized API calls with consistent error handling - Utilities:
js/utils/validation.js- Filename validation helpers - Styling:
js/notes-sidebar.css- Complete UI styling for dark theme integration
Key Components
- Server Integration: Uses ComfyUI's PromptServer.instance.routes for API endpoints
- File Management: Notes stored as markdown files with automatic directory creation
- UI Architecture: Tab-based interface with content area and action buttons
- Extension Registration: Properly registers with ComfyUI's extension manager as a sidebar tab
- State Management: Centralized state using NotesStore class with EventTarget pattern:
noteContent: Current content for each note (including unsaved)savedContent: Last saved content from serverunsavedChanges: Boolean flag for each note's modification state- Event-driven updates automatically sync UI components
API Endpoints
The extension exposes these REST endpoints:
Notes Management
GET /notes_sidebar/list- List all notesGET /notes_sidebar/note/{note_name}- Get specific note contentPOST /notes_sidebar/note/{note_name}- Save/create noteDELETE /notes_sidebar/note/{note_name}- Delete note
LoRA Integration
GET /notes_sidebar/loras- List all available LoRA filesGET /notes_sidebar/loras_with_metadata- List LoRAs with associated metadata from.txtfiles
Development Notes
Extension Structure
- Must export
NODE_CLASS_MAPPINGS,NODE_DISPLAY_NAME_MAPPINGS, andWEB_DIRECTORYfor ComfyUI compatibility - JavaScript extension uses ComfyUI's
app.registerExtension()pattern - Sidebar integration uses
app.extensionManager.registerSidebarTab()
File Operations
- Notes are automatically saved as
.mdfiles in thenotes/directory - File names are URL-encoded for safe handling
- Directory creation is handled automatically on initialization
UI State Management
- Active note tracking with tab highlighting
- Content persistence across sidebar open/close cycles
- Real-time tab rendering on note operations
- Button layout: Save/Rename/LoRA submenu on left, Delete on right, Zoom in/out and Refresh in tabs area
- Search Functionality: Live search through note content with highlighted results and line navigation
- Unsaved Changes Tracking: Visual indicators (*) for modified notes
- Content Preservation: Tab switching preserves unsaved content
- Change Detection: Automatic tracking of modifications vs saved state
- Append Integration: Submenu with three formatting options for appending LoRA lists (extensible for other content types)
- Font Size Control: Zoom in/out buttons with persistent settings storage (8-24px range)
Search Functionality
- Search Input: Located below button container with "Search lines..." placeholder
- Live Search: Results update as you type, case-insensitive matching
- Split View: Original textarea remains fully editable while search results appear below
- Result Navigation: Click any search result to jump to that line in the main editor
- Highlighting: Matching text highlighted with yellow background in search results
- Clear Button: PrimeVue
pi-times-circleicon for quick search clearing - Auto-Update: Search results refresh when switching between notes
- HTML Safety: Proper escaping prevents HTML injection in search results
Unsaved Changes Behavior
- Notes with modifications show asterisk (*) in tab name
- Switching tabs preserves unsaved content in inactive notes
onTextAreaChange()method tracks real-time content changes- Save operation clears unsaved state and updates saved content reference
- Delete/rename operations properly clean up tracking maps
Key Architectural Patterns
- State Management: Uses EventTarget pattern for reactive state updates
- File I/O: Synchronous file operations in Python with proper error handling
- API Design: RESTful endpoints with JSON responses and consistent error handling
- UI Updates: Event-driven architecture prevents manual DOM manipulation
- Extension Integration: Follows ComfyUI's extension patterns (NODE_CLASS_MAPPINGS, registerExtension)
- ComfyUI Integration: Leverages
folder_pathsmodule for LoRA discovery and metadata loading
Development Commands
Installation & Setup
- No build process required - extension loads directly in ComfyUI
- Place extension folder in ComfyUI's
custom_nodes/directory - Restart ComfyUI to load the extension
Testing the Extension
No automated tests defined. Manual testing workflow:
- Load extension in ComfyUI
- Verify sidebar tab appears with "Notes" label and book icon
- Test CRUD operations: create, edit, save, rename, delete notes
- Verify tab switching and content persistence
- Test search functionality: enter search terms, verify results highlighting and line navigation
- Test LoRA integration: verify submenu appears on click with three format options
- Verify unsaved changes tracking with asterisk (*) indicators
Development Workflow
- Modify Python code in
__init__.pyfor backend changes - Modify JavaScript in
js/extension.jsfor frontend changes - Update CSS in
js/notes-sidebar.cssfor styling changes - Python changes: Restart ComfyUI completely to reload the extension
- JavaScript/CSS changes: Browser refresh is sufficient
Common Development Tasks
- Adding new API endpoints: Add route handlers in
__init__.pyand corresponding methods injs/api/notesApi.js - Modifying note storage: Update
NotesManagerclass methods in__init__.py - UI state changes: Modify
NotesStoreclass injs/stores/NotesStore.js - Append functionality changes: Update
js/components/AppendMenu.jsand related backend endpoints - Adding new components: Create new files in
js/components/and import them inextension.js - Search functionality changes: Modify
onSearchChange()and related methods inextension.js - API changes: Update
js/api/notesApi.jsstatic methods and error handling
File Structure
notes/- Storage directory for markdown notes (auto-created, actual location determined by ComfyUI user directory)js/- Frontend assets loaded by ComfyUIextension.js- Main extension entry point (~580 lines, includes search functionality)stores/NotesStore.js- State management (~80 lines)components/AppendMenu.js- Append functionality (~170 lines)api/notesApi.js- API service layer (~90 lines)utils/validation.js- Validation utilities (~10 lines)notes-sidebar.css- UI styling (includes search component styles)
__init__.py- Main extension codepyproject.toml- Project metadata
Important Development Considerations
- Filename validation: Use
isValidFilename()fromjs/utils/validation.jsto validate user input - URL encoding: Note names are URL-encoded in API calls for safe handling
- Event-driven architecture: UI updates are triggered by state changes through EventTarget pattern in
NotesStore - Modular architecture: Components are separated by concern (state, UI, API, utilities)
- API centralization: All fetch calls are centralized in
js/api/notesApi.jswith consistent error handling - ComfyUI integration: Uses
folder_paths.get_filename_list("loras")for LoRA discovery - Error handling: All API endpoints include try/catch with JSON error responses
- Import structure: ES6 modules with clear dependency relationships