~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
fix: Address PR review comments and fix pre-commit hooks
LearningCircuit13cc976fdac6
diff --git a/.pre-commit-hooks/check-deprecated-db.py b/.pre-commit-hooks/check-deprecated-db.pynew file mode 100755index 0000000000..ff02ad4e1f--- /dev/null+++ b/.pre-commit-hooks/check-deprecated-db.py@@ -0,0 +1,112 @@+#!/usr/bin/env python3+"""+Pre-commit hook to check for usage of deprecated database connection methods.+Ensures code uses per-user database connections instead of the deprecated shared database.+"""++import sys+import re+import os++# Set environment variable for pre-commit hooks to allow unencrypted databases+os.environ["LDR_ALLOW_UNENCRYPTED"] = "true"+++def check_file(filepath):+ """Check a single file for deprecated database usage."""+ issues = []++ with open(filepath, "r", encoding="utf-8") as f:+ content = f.read()+ lines = content.split("\n")++ # Pattern to detect get_db_connection usage+ db_connection_pattern = re.compile(r"\bget_db_connection\s*\(")++ # Pattern to detect direct imports of get_db_connection+ import_pattern = re.compile(+ r"from\s+[\w.]+\s+import\s+.*\bget_db_connection\b"+ )++ # Check for usage+ for i, line in enumerate(lines, 1):+ if db_connection_pattern.search(line):+ issues.append(+ f"{filepath}:{i}: Usage of deprecated get_db_connection()"+ )++ if import_pattern.search(line):+ issues.append(+ f"{filepath}:{i}: Import of deprecated get_db_connection"+ )++ # Also check for patterns that suggest using shared database+ if "from ..web.models.database import get_db_connection" in content:+ issues.append(+ f"{filepath}: Imports deprecated get_db_connection from database module"+ )++ # Check for SQLite connections to shared database+ shared_db_pattern = re.compile(r"sqlite3\.connect\s*\([^)]*ldr\.db")+ for i, line in enumerate(lines, 1):+ if (+ shared_db_pattern.search(line)+ and "get_user_db_session" not in content+ ):+ issues.append(+ f"{filepath}:{i}: Direct SQLite connection to shared database - use get_user_db_session() instead"+ )++ return issues+++def main():+ """Main function to check all provided files."""+ if len(sys.argv) < 2:+ print("No files to check")+ return 0++ all_issues = []++ for filepath in sys.argv[1:]:+ # Skip the database.py file itself (it contains the deprecated function definition)+ if "web/models/database.py" in filepath:+ continue++ # Skip migration scripts and test files that might legitimately need shared DB access+ if any(+ skip in filepath+ for skip in ["migrations/", "tests/", "test_", ".pre-commit-hooks/"]+ ):+ continue++ issues = check_file(filepath)+ all_issues.extend(issues)++ if all_issues:+ print("❌ Deprecated database connection usage detected!\n")+ print("The shared database (get_db_connection) is deprecated.")+ print(+ "Please use get_user_db_session(username) for per-user database access.\n"+ )+ print("Issues found:")+ for issue in all_issues:+ print(f" - {issue}")+ print("\nExample fix:")+ print(" # Old (deprecated):")+ print(" conn = get_db_connection()")+ print(" cursor = conn.cursor()")+ print(" # ... SQL query execution ...")+ print()+ print(" # New (correct):")+ print(" from flask import session")+ print(" username = session.get('username', 'anonymous')")+ print(" with get_user_db_session(username) as db_session:")+ print(" results = db_session.query(Model).filter(...).all()")+ return 1++ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/.pre-commit-hooks/check-env-vars.py b/.pre-commit-hooks/check-env-vars.pyindex f329745b5f..e10c093216 100755--- a/.pre-commit-hooks/check-env-vars.py+++ b/.pre-commit-hooks/check-env-vars.py@@ -23,6 +23,7 @@ ALLOWED_PATTERNS = {"scripts/","utils/","cli.py",+ ".pre-commit-hooks/",# Example scripts demonstrating usage"examples/",# Specific modules that need direct accessdiff --git a/.pre-commit-hooks/check-ldr-db.py b/.pre-commit-hooks/check-ldr-db.pynew file mode 100755index 0000000000..4385f16341--- /dev/null+++ b/.pre-commit-hooks/check-ldr-db.py@@ -0,0 +1,93 @@+#!/usr/bin/env python3+"""+Pre-commit hook to prevent usage of ldr.db (shared database).+All data should be stored in per-user encrypted databases.+"""++import sys+import re+import os+from pathlib import Path++# Set environment variable for pre-commit hooks to allow unencrypted databases+os.environ["LDR_ALLOW_UNENCRYPTED"] = "true"+++def check_file_for_ldr_db(file_path):+ """Check if a file contains references to ldr.db."""+ try:+ with open(file_path, "r", encoding="utf-8") as f:+ content = f.read()+ except (UnicodeDecodeError, IOError):+ # Skip binary files or files we can't read+ return []++ # Pattern to find ldr.db references+ pattern = r"ldr\.db"+ matches = []++ for line_num, line in enumerate(content.splitlines(), 1):+ if re.search(pattern, line, re.IGNORECASE):+ # Skip comments and documentation+ stripped = line.strip()+ if not (+ stripped.startswith("#")+ or stripped.startswith("//")+ or stripped.startswith("*")+ or stripped.startswith('"""')+ or stripped.startswith("'''")+ ):+ matches.append((line_num, line.strip()))++ return matches+++def main():+ """Main function to check all Python files for ldr.db usage."""+ # Get all Python files from command line arguments+ files_to_check = sys.argv[1:] if len(sys.argv) > 1 else []++ if not files_to_check:+ # If no files specified, check all Python files+ src_dir = Path(__file__).parent.parent / "src"+ files_to_check = list(src_dir.rglob("*.py"))++ violations = []++ for file_path in files_to_check:+ file_path = Path(file_path)++ # Only skip this hook file itself+ if file_path.name == "check-ldr-db.py":+ continue++ matches = check_file_for_ldr_db(file_path)+ if matches:+ violations.append((file_path, matches))++ if violations:+ print("❌ DEPRECATED ldr.db USAGE DETECTED!")+ print("=" * 60)+ print("The shared ldr.db database is deprecated.")+ print("All data must be stored in per-user encrypted databases.")+ print("=" * 60)++ for file_path, matches in violations:+ print(f"\n📄 {file_path}")+ for line_num, line in matches:+ print(f" Line {line_num}: {line}")++ print("\n" + "=" * 60)+ print("MIGRATION REQUIRED:")+ print("1. Store user-specific data in encrypted per-user databases")+ print("2. Use get_user_db_session() instead of shared database access")+ print("3. See migration guide in documentation")+ print("=" * 60)++ return 1++ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/src/local_deep_research/report_generator.py b/src/local_deep_research/report_generator.pyindex 0b2604809e..d11ef08d6b 100644--- a/src/local_deep_research/report_generator.py+++ b/src/local_deep_research/report_generator.py@@ -133,8 +133,6 @@ class IntegratedReportGenerator:"citation","reference","bibliography",- "methodology",- "timeline",]# Only check the last section for source-related content