Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1f8d3e7
feat: Implement network configuration and proxy detection (Issue #25)
Dec 22, 2025
791272c
fix: Address code review feedback for network configuration
Dec 22, 2025
c180143
[network_config] Update and fix tests, demo, and parallel LLM logic
Dec 22, 2025
f38fc4a
[formatting] Apply code formatting and lint fixes
Dec 22, 2025
115ab66
Add Python 3.14 free-threading compatibility
sujay-d07 Dec 22, 2025
3eaa994
Update docs/PYTHON_314_THREAD_SAFETY_AUDIT.md
sujay-d07 Dec 22, 2025
035d739
Update tests/test_thread_safety.py
sujay-d07 Dec 22, 2025
d1a1ec5
Update cortex/utils/db_pool.py
sujay-d07 Dec 22, 2025
ef0114b
Update tests/test_thread_safety.py
sujay-d07 Dec 22, 2025
7fd44d4
Update tests/test_thread_safety.py
sujay-d07 Dec 22, 2025
a7a3190
Fix linting issues (ruff)
sujay-d07 Dec 22, 2025
01d6686
Apply Black formatting
sujay-d07 Dec 22, 2025
fb87fb0
Refactor system prompt in diagnose_errors_parallel and simplify conne…
sujay-d07 Dec 22, 2025
7728398
Replace random with secrets.SystemRandom for improved randomness in s…
sujay-d07 Dec 22, 2025
16dbd38
Update tests/test_thread_safety.py
sujay-d07 Dec 24, 2025
8fa05fd
Update tests/test_thread_safety.py
sujay-d07 Dec 24, 2025
7a0e90b
fix: resolve 'SystemInfo' object has no attribute 'get' error in cort…
Dec 24, 2025
3d9d1ba
Enhance free-threading detection and improve connection pool timeout …
sujay-d07 Dec 24, 2025
f1c54ae
perf: implement lazy loading for network detection
Dec 24, 2025
b3d27d8
style: fix whitespace linting errors
Dec 24, 2025
2f65152
style: apply black formatting
Dec 24, 2025
4a93d0f
Fix SonarQube security warning by using variables for test credentials
Dec 24, 2025
08ccaed
Fix SonarQube security warning and apply code formatting
Dec 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cortex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from cortex.demo import run_demo
from cortex.installation_history import InstallationHistory, InstallationStatus, InstallationType
from cortex.llm.interpreter import CommandInterpreter
from cortex.network_config import NetworkConfig
from cortex.notification_manager import NotificationManager
from cortex.stack_manager import StackManager
from cortex.user_preferences import (
Expand Down Expand Up @@ -803,6 +804,29 @@ def main():

load_env()

# Auto-configure network settings (proxy detection, VPN compatibility, offline mode)
# Use lazy loading - only detect when needed to improve CLI startup time
try:
network = NetworkConfig(auto_detect=False) # Don't detect yet (fast!)

# Only detect network for commands that actually need it
# Parse args first to see what command we're running
temp_parser = argparse.ArgumentParser(add_help=False)
temp_parser.add_argument("command", nargs="?")
temp_args, _ = temp_parser.parse_known_args()

# Commands that need network detection
NETWORK_COMMANDS = ["install", "update", "upgrade", "search", "doctor", "stack"]

if temp_args.command in NETWORK_COMMANDS:
# Now detect network (only when needed)
network.detect(check_quality=True) # Include quality check for these commands
network.auto_configure()

except Exception as e:
# Network config is optional - don't block execution if it fails
console.print(f"[yellow]⚠️ Network auto-config failed: {e}[/yellow]")

parser = argparse.ArgumentParser(
prog="cortex",
description="AI-powered Linux command interpreter",
Expand Down
12 changes: 8 additions & 4 deletions cortex/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import re
import subprocess
import threading
from datetime import datetime
from pathlib import Path
from typing import Any, ClassVar
Expand Down Expand Up @@ -54,6 +55,7 @@ def __init__(self, sandbox_executor=None):
self.sandbox_executor = sandbox_executor
self.cortex_dir = Path.home() / ".cortex"
self.preferences_file = self.cortex_dir / "preferences.yaml"
self._file_lock = threading.Lock() # Protect file I/O operations

# Ensure .cortex directory exists with secure permissions
self.cortex_dir.mkdir(mode=0o700, exist_ok=True)
Expand Down Expand Up @@ -280,8 +282,9 @@ def _load_preferences(self) -> dict[str, Any]:
"""
if self.preferences_file.exists():
try:
with open(self.preferences_file) as f:
return yaml.safe_load(f) or {}
with self._file_lock:
with open(self.preferences_file) as f:
return yaml.safe_load(f) or {}
except Exception:
pass

Expand All @@ -295,8 +298,9 @@ def _save_preferences(self, preferences: dict[str, Any]) -> None:
preferences: Dictionary of preferences to save
"""
try:
with open(self.preferences_file, "w") as f:
yaml.safe_dump(preferences, f, default_flow_style=False)
with self._file_lock:
with open(self.preferences_file, "w") as f:
yaml.safe_dump(preferences, f, default_flow_style=False)
except Exception as e:
raise RuntimeError(f"Failed to save preferences: {e}")

Expand Down
Loading
Loading