~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
Add theme auto-detection from CSS to eliminate duplicate maintenance
LearningCircuitc722a1f04202
diff --git a/src/local_deep_research/web/app_factory.py b/src/local_deep_research/web/app_factory.pyindex f5663482a4..c4ffeadbb0 100644--- a/src/local_deep_research/web/app_factory.py+++ b/src/local_deep_research/web/app_factory.py@@ -353,6 +353,11 @@ def create_app():vite.init_app(app)+ # Initialize Theme helper for auto-detecting themes from CSS+ from .utils.theme_helper import theme_helper++ theme_helper.init_app(app)+# Register socket servicesocket_service = SocketIOService(app=app)diff --git a/src/local_deep_research/web/static/css/themes.css b/src/local_deep_research/web/static/css/themes.cssindex c80964435c..7c3d9f155f 100644--- a/src/local_deep_research/web/static/css/themes.css+++ b/src/local_deep_research/web/static/css/themes.css@@ -1077,6 +1077,84 @@--card-bg: var(--bg-secondary);}+/* Light Owl Theme - Accessibility-focused for daylight */+[data-theme="light-owl"] {+ --bg-primary: #F0F0F0;+ --bg-secondary: #FAFAFA;+ --bg-tertiary: #E0E0E0;+ --accent-primary: #4876D6;+ --accent-secondary: #994CC3;+ --accent-tertiary: #0C969B;+ --text-primary: #403F53;+ --text-secondary: #5C5C72;+ --text-muted: #90A7B2;+ --border-color: #D6D6D6;+ --success-color: #4CA64C;+ --warning-color: #DAAA01;+ --error-color: #DE3D3B;++ --bg-primary-rgb: 240, 240, 240;+ --bg-secondary-rgb: 250, 250, 250;+ --bg-tertiary-rgb: 224, 224, 224;+ --accent-primary-rgb: 72, 118, 214;+ --accent-secondary-rgb: 153, 76, 195;+ --accent-tertiary-rgb: 12, 150, 155;+ --text-primary-rgb: 64, 63, 83;+ --text-secondary-rgb: 92, 92, 114;+ --text-muted-rgb: 144, 167, 178;+ --border-color-rgb: 214, 214, 214;+ --success-color-rgb: 76, 166, 76;+ --warning-color-rgb: 218, 170, 1;+ --error-color-rgb: 222, 61, 59;++ --card-shadow: 0 2px 12px rgba(64, 63, 83, 0.08);+ --glow-effect: 0 0 10px rgba(72, 118, 214, 0.15);+ --gradient-bg: linear-gradient(135deg, #FAFAFA 0%, #F0F0F0 100%);+ --overlay-color: rgba(64, 63, 83, 0.2);+ --backdrop-blur: blur(10px);+ --primary-color: var(--accent-primary);+ --card-bg: var(--bg-secondary);+}++/* Vesper Theme - Warm peppermint and orange */+[data-theme="vesper"] {+ --bg-primary: #101010;+ --bg-secondary: #1C1C1C;+ --bg-tertiary: #282828;+ --accent-primary: #FFC799;+ --accent-secondary: #60CDAB;+ --accent-tertiary: #FFCFA8;+ --text-primary: #FFFFFF;+ --text-secondary: #A0A0A0;+ --text-muted: #606060;+ --border-color: #333333;+ --success-color: #60CDAB;+ --warning-color: #FFC799;+ --error-color: #F07171;++ --bg-primary-rgb: 16, 16, 16;+ --bg-secondary-rgb: 28, 28, 28;+ --bg-tertiary-rgb: 40, 40, 40;+ --accent-primary-rgb: 255, 199, 153;+ --accent-secondary-rgb: 96, 205, 171;+ --accent-tertiary-rgb: 255, 207, 168;+ --text-primary-rgb: 255, 255, 255;+ --text-secondary-rgb: 160, 160, 160;+ --text-muted-rgb: 96, 96, 96;+ --border-color-rgb: 51, 51, 51;+ --success-color-rgb: 96, 205, 171;+ --warning-color-rgb: 255, 199, 153;+ --error-color-rgb: 240, 113, 113;++ --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);+ --glow-effect: 0 0 15px rgba(255, 199, 153, 0.2);+ --gradient-bg: linear-gradient(135deg, #1C1C1C 0%, #101010 100%);+ --overlay-color: rgba(16, 16, 16, 0.85);+ --backdrop-blur: blur(10px);+ --primary-color: var(--accent-primary);+ --card-bg: var(--bg-secondary);+}+/* Ayu Mirage Theme - Modern minimalist twilight */[data-theme="ayu-mirage"] {--bg-primary: #1F2430;diff --git a/src/local_deep_research/web/static/js/services/theme.js b/src/local_deep_research/web/static/js/services/theme.jsindex c87756cf3d..42ffa0ee11 100644--- a/src/local_deep_research/web/static/js/services/theme.js+++ b/src/local_deep_research/web/static/js/services/theme.js@@ -18,47 +18,17 @@const STORAGE_KEY_PREFIX = 'ldr-theme';const SETTING_KEY = 'app.theme';- // Available themes (must match CSS definitions in themes.css)- const THEMES = {- // Core themes+ // Themes are auto-detected from CSS and injected by base.html+ // window.LDR_THEME_METADATA is set before this script loads+ // This avoids having to maintain duplicate theme lists+ const THEMES = window.LDR_THEME_METADATA || {+ // Fallback in case metadata wasn't injected (shouldn't happen)'dark': { label: 'Dark', icon: 'fa-moon', group: 'core' },'light': { label: 'Light', icon: 'fa-sun', group: 'core' },- 'sepia': { label: 'Sepia', icon: 'fa-book-open', group: 'core' },- 'high-contrast': { label: 'High Contrast', icon: 'fa-eye', group: 'core' },- 'midnight': { label: 'Midnight', icon: 'fa-cloud-moon', group: 'core' },- // Nature themes- 'ocean': { label: 'Ocean', icon: 'fa-water', group: 'nature' },- 'forest': { label: 'Forest', icon: 'fa-tree', group: 'nature' },- 'sunset': { label: 'Sunset', icon: 'fa-sun', group: 'nature' },- 'rose': { label: 'Rose', icon: 'fa-heart', group: 'nature' },- 'lavender': { label: 'Lavender', icon: 'fa-spa', group: 'nature' },- // Popular developer themes- 'nord': { label: 'Nord', icon: 'fa-snowflake', group: 'dev' },- 'dracula': { label: 'Dracula', icon: 'fa-ghost', group: 'dev' },- 'monokai': { label: 'Monokai', icon: 'fa-code', group: 'dev' },- 'solarized-dark': { label: 'Solarized Dark', icon: 'fa-adjust', group: 'dev' },- 'solarized-light': { label: 'Solarized Light', icon: 'fa-circle', group: 'dev' },- 'gruvbox-dark': { label: 'Gruvbox Dark', icon: 'fa-square', group: 'dev' },- 'gruvbox-light': { label: 'Gruvbox Light', icon: 'fa-square-full', group: 'dev' },- 'tokyo-night': { label: 'Tokyo Night', icon: 'fa-city', group: 'dev' },- 'catppuccin': { label: 'Catppuccin', icon: 'fa-cat', group: 'dev' },- 'one-dark': { label: 'One Dark', icon: 'fa-atom', group: 'dev' },- // Research-focused themes (optimized for reading)- 'flexoki-dark': { label: 'Flexoki Dark', icon: 'fa-pen-nib', group: 'research' },- 'flexoki-light': { label: 'Flexoki Light', icon: 'fa-feather', group: 'research' },- 'rose-pine': { label: 'Rosé Pine', icon: 'fa-seedling', group: 'research' },- 'rose-pine-dawn': { label: 'Rosé Pine Dawn', icon: 'fa-cloud-sun', group: 'research' },- 'everforest-dark': { label: 'Everforest Dark', icon: 'fa-leaf', group: 'research' },- 'everforest-light': { label: 'Everforest Light', icon: 'fa-sun-plant-wilt', group: 'research' },- 'night-owl': { label: 'Night Owl', icon: 'fa-crow', group: 'research' },- 'ayu-mirage': { label: 'Ayu Mirage', icon: 'fa-mountain-sun', group: 'research' },- 'kanagawa': { label: 'Kanagawa', icon: 'fa-torii-gate', group: 'research' },- 'palenight': { label: 'Palenight', icon: 'fa-moon', group: 'research' },- // System'system': { label: 'System', icon: 'fa-desktop', group: 'system' }};- // Valid theme names for validation+ // Valid theme names for validation (auto-detected)const VALID_THEMES = Object.keys(THEMES);// Theme cycle order for quick toggle button (subset of popular themes)@@ -210,12 +180,13 @@// Clear existing optionsselectElement.innerHTML = '';- // Group themes+ // Group themes - dynamically determine groups from theme metadataconst groups = {'core': 'Core Themes','nature': 'Nature','dev': 'Developer Themes','research': 'Research & Reading',+ 'other': 'Other','system': 'System'};diff --git a/src/local_deep_research/web/templates/base.html b/src/local_deep_research/web/templates/base.htmlindex f3dde6aeeb..ea3f6c3bb2 100644--- a/src/local_deep_research/web/templates/base.html+++ b/src/local_deep_research/web/templates/base.html@@ -9,9 +9,14 @@<link rel="icon" type="image/png" href="/static/favicon.png"><!-- FOUC Prevention: Apply theme before any rendering -->+ <!-- Theme list is auto-detected from themes.css by ThemeHelper --><script>(function() {- var validThemes = ['dark','light','sepia','high-contrast','midnight','ocean','forest','sunset','rose','lavender','nord','dracula','monokai','solarized-dark','solarized-light','gruvbox-dark','gruvbox-light','tokyo-night','catppuccin','one-dark','flexoki-dark','flexoki-light','rose-pine','rose-pine-dawn','everforest-dark','everforest-light','night-owl','ayu-mirage','kanagawa','palenight','system'];+ // Auto-detected from CSS - no need to manually update this list+ var validThemes = {{ get_themes_json()|safe }};+ // Store theme metadata for JavaScript (used by theme.js)+ window.LDR_THEME_METADATA = {{ get_theme_metadata()|safe }};+var userId = '{{ session.username|default("anonymous", true) }}';var storageKey = 'ldr-theme-' + userId;var theme = localStorage.getItem(storageKey) || 'dark';diff --git a/src/local_deep_research/web/utils/theme_helper.py b/src/local_deep_research/web/utils/theme_helper.pynew file mode 100644index 0000000000..1f3b043d2e--- /dev/null+++ b/src/local_deep_research/web/utils/theme_helper.py@@ -0,0 +1,241 @@+"""+Theme Helper for Flask+Auto-detects available themes from themes.css+"""++import re+from pathlib import Path+from functools import lru_cache+from markupsafe import Markup+from loguru import logger+++class ThemeHelper:+ """Helper class for theme management with Flask"""++ # Theme metadata - icons and groups for each theme+ # Only needs to be updated when adding NEW themes (not for validation)+ THEME_METADATA = {+ # Core themes+ "dark": {"label": "Dark", "icon": "fa-moon", "group": "core"},+ "light": {"label": "Light", "icon": "fa-sun", "group": "core"},+ "sepia": {"label": "Sepia", "icon": "fa-book-open", "group": "core"},+ "high-contrast": {+ "label": "High Contrast",+ "icon": "fa-eye",+ "group": "core",+ },+ "midnight": {+ "label": "Midnight",+ "icon": "fa-cloud-moon",+ "group": "core",+ },+ # Nature themes+ "ocean": {"label": "Ocean", "icon": "fa-water", "group": "nature"},+ "forest": {"label": "Forest", "icon": "fa-tree", "group": "nature"},+ "sunset": {"label": "Sunset", "icon": "fa-sun", "group": "nature"},+ "rose": {"label": "Rose", "icon": "fa-heart", "group": "nature"},+ "lavender": {"label": "Lavender", "icon": "fa-spa", "group": "nature"},+ # Developer themes+ "nord": {"label": "Nord", "icon": "fa-snowflake", "group": "dev"},+ "dracula": {"label": "Dracula", "icon": "fa-ghost", "group": "dev"},+ "monokai": {"label": "Monokai", "icon": "fa-code", "group": "dev"},+ "solarized-dark": {+ "label": "Solarized Dark",+ "icon": "fa-adjust",+ "group": "dev",+ },+ "solarized-light": {+ "label": "Solarized Light",+ "icon": "fa-circle",+ "group": "dev",+ },+ "gruvbox-dark": {+ "label": "Gruvbox Dark",+ "icon": "fa-square",+ "group": "dev",+ },+ "gruvbox-light": {+ "label": "Gruvbox Light",+ "icon": "fa-square-full",+ "group": "dev",+ },+ "tokyo-night": {+ "label": "Tokyo Night",+ "icon": "fa-city",+ "group": "dev",+ },+ "catppuccin": {"label": "Catppuccin", "icon": "fa-cat", "group": "dev"},+ "one-dark": {"label": "One Dark", "icon": "fa-atom", "group": "dev"},+ # Research-focused themes+ "flexoki-dark": {+ "label": "Flexoki Dark",+ "icon": "fa-pen-nib",+ "group": "research",+ },+ "flexoki-light": {+ "label": "Flexoki Light",+ "icon": "fa-feather",+ "group": "research",+ },+ "rose-pine": {+ "label": "Rosé Pine",+ "icon": "fa-seedling",+ "group": "research",+ },+ "rose-pine-dawn": {+ "label": "Rosé Pine Dawn",+ "icon": "fa-cloud-sun",+ "group": "research",+ },+ "everforest-dark": {+ "label": "Everforest Dark",+ "icon": "fa-leaf",+ "group": "research",+ },+ "everforest-light": {+ "label": "Everforest Light",+ "icon": "fa-seedling",+ "group": "research",+ },+ "night-owl": {+ "label": "Night Owl",+ "icon": "fa-crow",+ "group": "research",+ },+ "light-owl": {+ "label": "Light Owl",+ "icon": "fa-dove",+ "group": "research",+ },+ "ayu-mirage": {+ "label": "Ayu Mirage",+ "icon": "fa-mountain-sun",+ "group": "research",+ },+ "kanagawa": {+ "label": "Kanagawa",+ "icon": "fa-torii-gate",+ "group": "research",+ },+ "palenight": {+ "label": "Palenight",+ "icon": "fa-moon",+ "group": "research",+ },+ "vesper": {"label": "Vesper", "icon": "fa-fire", "group": "research"},+ }++ # Group labels for dropdown+ GROUPS = {+ "core": "Core Themes",+ "nature": "Nature",+ "dev": "Developer Themes",+ "research": "Research & Reading",+ "system": "System",+ }++ def __init__(self, app=None):+ self.app = app+ self._themes_cache = None++ if app:+ self.init_app(app)++ def init_app(self, app):+ """Initialize the helper with Flask app"""+ self.app = app++ # Register template functions+ app.jinja_env.globals["get_themes"] = self.get_themes+ app.jinja_env.globals["get_themes_json"] = self.get_themes_json+ app.jinja_env.globals["get_theme_metadata"] = (+ self.get_theme_metadata_json+ )++ def _get_css_path(self) -> Path:+ """Get path to themes.css"""+ static_dir = self.app.config.get("STATIC_DIR", "static")+ return Path(static_dir) / "css" / "themes.css"++ @lru_cache(maxsize=1)+ def _parse_themes_from_css(self) -> list[str]:+ """Parse themes.css to extract theme names.++ Looks for patterns like [data-theme="theme-name"] {+ Only matches root theme definitions (not element-specific like [data-theme="x"] a)+ """+ css_path = self._get_css_path()+ themes = set()++ if not css_path.exists():+ logger.warning(f"themes.css not found at {css_path}")+ return list(self.THEME_METADATA.keys())++ try:+ content = css_path.read_text()+ # Match [data-theme="name"] { but not [data-theme="name"] element {+ pattern = r'\[data-theme="([^"]+)"\]\s*\{'+ matches = re.findall(pattern, content)+ themes = set(matches)+ logger.debug(f"Found {len(themes)} themes in CSS: {sorted(themes)}")+ except Exception:+ logger.exception("Error parsing themes.css")+ return list(self.THEME_METADATA.keys())++ # Always include 'system' as it's a virtual theme+ themes.add("system")++ return sorted(themes)++ def get_themes(self) -> list[str]:+ """Get list of available theme names (auto-detected from CSS)"""+ if self._themes_cache is None:+ self._themes_cache = self._parse_themes_from_css()+ return self._themes_cache++ def get_themes_json(self) -> Markup:+ """Get themes as JSON string for embedding in HTML"""+ import json++ themes = self.get_themes()+ return Markup(json.dumps(themes))++ def get_theme_metadata_json(self) -> Markup:+ """Get full theme metadata as JSON for JavaScript"""+ import json++ themes = self.get_themes()++ # Build metadata only for themes that exist in CSS+ metadata = {}+ for theme in themes:+ if theme in self.THEME_METADATA:+ metadata[theme] = self.THEME_METADATA[theme]+ elif theme == "system":+ metadata["system"] = {+ "label": "System",+ "icon": "fa-desktop",+ "group": "system",+ }+ else:+ # Auto-generate metadata for themes not in THEME_METADATA+ # This allows new themes to work even without metadata+ label = theme.replace("-", " ").title()+ metadata[theme] = {+ "label": label,+ "icon": "fa-palette",+ "group": "other",+ }+ logger.debug(f"Auto-generated metadata for theme: {theme}")++ return Markup(json.dumps(metadata))++ def clear_cache(self):+ """Clear the themes cache (useful for development)"""+ self._themes_cache = None+ self._parse_themes_from_css.cache_clear()+++# Singleton instance+theme_helper = ThemeHelper()diff --git a/tests/theme_tests/test_theme_system.py b/tests/theme_tests/test_theme_system.pyindex e58c4f0fc7..5a24788e17 100644--- a/tests/theme_tests/test_theme_system.py+++ b/tests/theme_tests/test_theme_system.py@@ -62,40 +62,24 @@ REQUIRED_RGB_VARIANTS = ["--error-color-rgb",]-# All 30 themes that should be defined-ALL_THEMES = [- "dark",- "light",- "sepia",- "high-contrast",- "midnight",- "ocean",- "forest",- "sunset",- "rose",- "lavender",- "nord",- "dracula",- "monokai",- "solarized-dark",- "solarized-light",- "gruvbox-dark",- "gruvbox-light",- "tokyo-night",- "catppuccin",- "one-dark",- # Research-focused themes- "flexoki-dark",- "flexoki-light",- "rose-pine",- "rose-pine-dawn",- "everforest-dark",- "everforest-light",- "night-owl",- "ayu-mirage",- "kanagawa",- "palenight",-]++# Auto-detect themes from CSS file (single source of truth)+def _parse_themes_from_css() -> list[str]:+ """Parse themes.css to extract theme names."""+ themes = set()+ if CSS_DIR.exists():+ themes_css = CSS_DIR / "themes.css"+ if themes_css.exists():+ content = themes_css.read_text()+ # Match [data-theme="name"] { but not [data-theme="name"] element {+ pattern = r'\[data-theme="([^"]+)"\]\s*\{'+ matches = re.findall(pattern, content)+ themes = set(matches)+ return sorted(themes)+++# All themes are auto-detected from CSS+ALL_THEMES = _parse_themes_from_css()# Hex color pattern (matches #fff, #ffffff, #FFFFFF)HEX_COLOR_PATTERN = re.compile(r"#[0-9a-fA-F]{3,8}\b")@@ -436,44 +420,28 @@ class TestThemeVariableUsage:class TestDarkLightThemes:"""Test that dark and light themes have appropriate brightness levels."""- # Themes that should have dark backgrounds+ # Light themes are identified by having "light" in name or specific names+ LIGHT_THEME_PATTERNS = ["light", "dawn", "sepia"]++ # Dynamically determine light/dark themes from ALL_THEMES+ @classmethod+ def _is_light_theme(cls, theme: str) -> bool:+ """Check if a theme is a light theme based on name patterns."""+ theme_lower = theme.lower()+ return any(+ pattern in theme_lower for pattern in cls.LIGHT_THEME_PATTERNS+ )++ # Auto-detect dark and light themesDARK_THEMES = [- "dark",- "midnight",- "ocean",- "forest",- "sunset",- "nord",- "dracula",- "monokai",- "solarized-dark",- "gruvbox-dark",- "tokyo-night",- "catppuccin",- "one-dark",- "high-contrast",- "rose",- "lavender",- # New research-focused dark themes- "flexoki-dark",- "rose-pine",- "everforest-dark",- "night-owl",- "ayu-mirage",- "kanagawa",- "palenight",+ t+ for t in ALL_THEMES+ if not any(p in t.lower() for p in ["light", "dawn", "sepia"])]-- # Themes that should have light backgroundsLIGHT_THEMES = [- "light",- "sepia",- "solarized-light",- "gruvbox-light",- # New research-focused light themes- "flexoki-light",- "rose-pine-dawn",- "everforest-light",+ t+ for t in ALL_THEMES+ if any(p in t.lower() for p in ["light", "dawn", "sepia"])]@pytest.fixture@@ -944,13 +912,17 @@ class TestThemeNamingConventions:)def test_theme_count(self, themes_css_content):- """Should have exactly 30 themes defined with data-theme attribute."""+ """Should have at least 20 themes defined with data-theme attribute."""theme_pattern = re.compile(r'\[data-theme="([^"]+)"\]')themes = set(theme_pattern.findall(themes_css_content))- # All 30 themes should have data-theme definitions- assert len(themes) == 30, (- f"Expected 30 data-theme themes, found {len(themes)}: {themes}"+ # Should have a reasonable number of themes (at least original 20)+ assert len(themes) >= 20, (+ f"Expected at least 20 data-theme themes, found {len(themes)}: {themes}"+ )+ # Verify detected count matches ALL_THEMES+ assert len(ALL_THEMES) == len(themes), (+ f"ALL_THEMES count ({len(ALL_THEMES)}) doesn't match CSS ({len(themes)})")