Skip to content

~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.

refactor: address PR review feedback from djpetti

LearningCircuit47204c4cb157
diff --git a/.github/scripts/check-file-writes.sh b/.github/scripts/check-file-writes.sh
index a7c96d74f6..d9d14b11ae 100755
--- a/.github/scripts/check-file-writes.sh
+++ b/.github/scripts/check-file-writes.sh
@@ -90,8 +90,6 @@ SAFE_USAGE_PATTERNS=(
"security/file_write_verifier.py"
"import tempfile"
"tempfile\.mkdtemp"
- "def get_report_as_temp_file"
- "\.get_report_as_temp_file\("
"tmp_path"
"tmp_file"
)
@@ -125,7 +123,7 @@ for pattern in "${SUSPICIOUS_PATTERNS[@]}"; do
done
# Also check for specific problematic patterns in one pass
-temp_matches=$(grep -rn -I $EXCLUDE_ARGS -E "get_report_as_temp_file|tmp_path|tempfile|/tmp/" $SEARCH_PATHS --include="*.py" 2>/dev/null | head -500 || true)
+temp_matches=$(grep -rn -I $EXCLUDE_ARGS -E "tmp_path|tempfile|/tmp/" $SEARCH_PATHS --include="*.py" 2>/dev/null | head -500 || true)
if [ -n "$temp_matches" ]; then
ALL_MATCHES="$ALL_MATCHES$temp_matches\n"
fi
diff --git a/src/local_deep_research/security/file_write_verifier.py b/src/local_deep_research/security/file_write_verifier.py
index 44681ee86d..6c12cf237b 100644
--- a/src/local_deep_research/security/file_write_verifier.py
+++ b/src/local_deep_research/security/file_write_verifier.py
@@ -78,7 +78,7 @@ def write_json_verified(
setting_name: str,
required_value: Any = True,
context: str = "",
- indent: int = 2,
+ **json_kwargs,
) -> None:
"""Write JSON data to a file only if security settings allow it.
@@ -88,7 +88,8 @@ def write_json_verified(
setting_name: Configuration setting name to check
required_value: Required value for the setting (default: True)
context: Description of what's being written (for error messages)
- indent: JSON indentation (default: 2)
+ **json_kwargs: Additional keyword arguments to pass to json.dumps()
+ (e.g., indent=2, ensure_ascii=False, sort_keys=True, default=custom_serializer)
Raises:
FileWriteSecurityError: If the security setting doesn't match required value
@@ -98,10 +99,16 @@ def write_json_verified(
... "results.json",
... {"accuracy": 0.95},
... "benchmark.allow_file_output",
- ... context="benchmark results"
+ ... context="benchmark results",
+ ... indent=2,
+ ... sort_keys=True
... )
"""
- content = json.dumps(data, indent=indent)
+ # Default to indent=2 if not specified for readability
+ if "indent" not in json_kwargs:
+ json_kwargs["indent"] = 2
+
+ content = json.dumps(data, **json_kwargs)
write_file_verified(
filepath,
content,
diff --git a/src/local_deep_research/storage/base.py b/src/local_deep_research/storage/base.py
index 649b8d4976..f660b39f26 100644
--- a/src/local_deep_research/storage/base.py
+++ b/src/local_deep_research/storage/base.py
@@ -2,7 +2,6 @@
from abc import ABC, abstractmethod
from typing import Dict, Any, Optional
-from pathlib import Path
class ReportStorage(ABC):
@@ -88,45 +87,3 @@ class ReportStorage(ABC):
True if report exists, False otherwise
"""
pass
-
- def get_report_as_temp_file(
- self, research_id: str, username: Optional[str] = None
- ) -> Optional[Path]:
- """Get report content as a temporary file.
-
- WARNING: This creates an UNENCRYPTED temporary file on disk.
- This method is deprecated and should be avoided. Use in-memory
- export operations instead (see export_report_to_memory).
-
- Args:
- research_id: Unique identifier for the research
- username: Optional username for user-specific storage
-
- Returns:
- Path to temporary file if successful, None otherwise
- """
- import tempfile
- from ..security.file_write_verifier import write_file_verified
-
- content = self.get_report(research_id, username)
- if not content:
- return None
-
- try:
- # Create temp file path
- tmp_file = tempfile.NamedTemporaryFile(
- mode="w", suffix=".md", delete=False, encoding="utf-8"
- )
- tmp_path = Path(tmp_file.name)
- tmp_file.close()
-
- # Write with verification
- write_file_verified(
- tmp_path,
- content,
- "storage.allow_temp_file_export",
- context="temporary file export (UNENCRYPTED)",
- )
- return tmp_path
- except Exception:
- return None
diff --git a/src/local_deep_research/storage/database_with_file_backup.py b/src/local_deep_research/storage/database_with_file_backup.py
index 7a1664aa15..4a28201648 100644
--- a/src/local_deep_research/storage/database_with_file_backup.py
+++ b/src/local_deep_research/storage/database_with_file_backup.py
@@ -1,7 +1,6 @@
"""Storage that always uses database as primary storage with optional file backup."""
from typing import Dict, Any, Optional
-from pathlib import Path
from loguru import logger
from sqlalchemy.orm import Session
@@ -94,13 +93,6 @@ class DatabaseWithFileBackupStorage(ReportStorage):
# Always list from database for consistency
return self.db_storage.list_reports(username)
- def get_report_as_temp_file(
- self, research_id: str, username: Optional[str] = None
- ) -> Optional[Path]:
- """Get report as temporary file from database."""
- # Always use database implementation
- return self.db_storage.get_report_as_temp_file(research_id, username)
-
def get_report_with_metadata(
self, research_id: str, username: Optional[str] = None
) -> Optional[Dict[str, Any]]:
diff --git a/src/local_deep_research/storage/file.py b/src/local_deep_research/storage/file.py
index f0a9a74941..97e2e66a5e 100644
--- a/src/local_deep_research/storage/file.py
+++ b/src/local_deep_research/storage/file.py
@@ -142,10 +142,3 @@ class FileReportStorage(ReportStorage):
) -> bool:
"""Check if report file exists."""
return self._get_report_path(research_id).exists()
-
- def get_report_as_temp_file(
- self, research_id: str, username: Optional[str] = None
- ) -> Optional[Path]:
- """For file storage, just return the actual file path."""
- report_path = self._get_report_path(research_id)
- return report_path if report_path.exists() else None