# backend/requirements.txt
# Consolidated requirements for Guaardvark
#
# REQUIRES PYTHON 3.12. Do not install on 3.13/3.14 — numpy<2.0, mediapipe,
# basicsr/gfpgan and realesrgan have no wheels for those yet and the build
# fails (issue #35). Create the venv with python3.12 before installing.

# pkg_resources guard — setuptools >=81 dropped pkg_resources, which several
# ML libs in this stack still import (resemble-perth via chatterbox-tts hit
# this on 2026-04-28; gfpgan/basicsr/mediapipe historically use it too).
# Once the rest of the stack migrates off pkg_resources we can drop this.
setuptools<85

# Core Flask/Backend Dependencies
Flask==3.1.3
Flask-Executor==1.0.0
Flask-Migrate==4.1.0
Flask-SQLAlchemy==3.1.1
Flask-SocketIO==5.7.0
flask-cors==6.0.5
alembic==1.20.0
anthropic>=1.7.0
python-dotenv==1.2.4

# Background Tasks & Caching
celery==5.7.0
# kombu 5.7 refuses redis-py below 6.4 at run time, so the two move together.
# redis-py 8 speaks RESP3 and needs a Redis server of 6.0 or newer.
kombu==5.7.0
redis==8.1.0
eventlet==0.41.2
# Cron expressions for scheduled tasks (backend/api/task_scheduler_api.py).
croniter==6.2.4

# Data Processing & Analysis
numpy<2.0,>=1.26.4  # Pin to <2.0 for PyTorch compatibility
pandas==2.2.2
pydantic==2.14.1
psutil==7.2.2
# regex runs search_code's caller-supplied patterns under a per-call timeout
# (backend/tools/llama_code_tools.py). transformers, nltk and tiktoken install it
# too; it is named here because backend code imports it directly. The floor is
# the one transformers 5.16 already requires.
regex>=2025.10.22
# nvidia-ml-py (imports as pynvml) is GPU-only — it powers VRAM queries in
# gpu_resource_coordinator/ollama_resource_manager, but every importer does so
# lazily inside try/except and falls back to nvidia-smi or "unknown". On
# CPU/ARM/AMD/Mac it has no purpose; the CPU branch of install_pytorch.sh even
# uninstalls pynvml to silence a FutureWarning. Installing it unconditionally
# here re-adds it right after that uninstall. Install it only on NVIDIA hosts —
# recommended start.sh wiring documented in requirements-cv.txt's header / the
# P3-10b report. Left here (still imports cleanly everywhere) to avoid a
# behavior change start.sh isn't yet wired for; flagged for GPU-only gating.
# nvidia-ml-py>=12.0.0  # GPU-only (pynvml) — now gated (see dep_reconciler and start.sh; not in base to avoid FutureWarning on CPU/ARM per edge audit)

# Web Scraping & File Processing
beautifulsoup4==4.15.0
lxml==6.1.3
pypdf==6.21.4
requests==2.34.2
# Transitive dependencies (Flask, requests, llama-index-core) named only to hold a
# security floor: unnamed, an existing venv keeps whatever release it already has.
Werkzeug>=3.1.9
urllib3>=2.8.0
aiohttp>=3.14.5
google-auth==2.62.0
# Interconnector machine keys and request signatures (backend/utils/node_auth.py,
# Ed25519). google-auth installs it too; it is named here because the fleet's
# signing depends on it. The floor is the version these signatures were built on.
cryptography>=50.0.2
websocket-client==1.8.0
# HTTP client for web search (backend/utils/bing_search.py): requests with a
# browser's TLS and header profile.
primp==2.0.1

# Database & Utilities
psycopg2-binary==2.9.9
python-slugify==8.0.4
loguru==0.7.2

# LLM/AI Dependencies
ollama>=0.6.3
llama-index-core>=0.14.26,<0.15.0
llama-index-llms-ollama>=0.12.0
llama-index-embeddings-ollama>=0.11.0
llama-index-readers-file>=0.5.0  # Updated for llama-index-core 0.14.x
llama-index-retrievers-bm25>=0.8.0  # Hybrid search: BM25 keyword retrieval
# Retrieval storage and reranking. Both were silent missing deps: without the
# pgvector store the index falls back to SimpleVectorStore and reports success
# throughout — measured 0/7 needles retrieved on scripts/rag_validation, 6/7 at
# rank 1 once installed. Without sentence-transformers the cross-encoder rerank
# is skipped. Verified at 0.8.1 / 6.0.0 against llama-index-core 0.14.24.
llama-index-vector-stores-postgres>=0.10.0
sentence-transformers>=6.0.1
# Layout-aware parsing for .pdf/.docx/.pptx (backend/utils/docling_loader.py).
# Without it those formats have no reader at all and fall through to a legacy
# path that raises. Pulls rapidocr, which requires opencv-python>=4.5 with no
# upper bound, so install under backend/constraints.txt (PIP_CONSTRAINT) to keep
# numpy<2.0. Verified at 2.150.1: numpy 1.26.4 and opencv-python 4.11.0.86 held.
docling>=2.142.0  # first release whose parser and layout models accept Pillow 13
# PyTorch is installed by scripts/install_pytorch.sh (smart installer) - do not pin versions here
# torch, torchvision, torchaudio versions are auto-detected based on GPU hardware

# MCP Server Dependencies
# Powers `python -m backend.mcp` (stdio/http server exposing the gated tool
# registry + read-only output resources to Claude / Cursor / Grok / Zed).
# Requires the 2.x SDK: handlers are Server constructor args (on_list_tools=...);
# the 1.x decorator API the adapters previously used was removed in 2.0.
mcp>=2.3.0,<3
jsonschema>=4.20  # MCP client: validates tool arguments against the server's input schema

# Image Generation Dependencies
diffusers>=0.43.0
transformers>=5.2.0,<6.0  # Krea2/Qwen3-VL needs 5.2+ (rope_parameters); was <5.0 for legacy ComfyUI pin
# A range, not a pin: Settings > Training libraries moves accelerate to 1.4+ (TRL
# needs it, and transformers' Trainer calls unwrap_model(keep_torch_compile=),
# new in 1.3), and an exact pin here would put it back on the next start-up's
# `pip install -r`. Verified at 1.15.0: diffusers 0.40 model and sequential CPU
# offload, transformers 5.16 Trainer and device_map, peft 0.20.
accelerate>=1.15.0,<2
peft>=0.20.0  # Z-Image LoRA training runs in this venv (plugins/lora_trainer/scripts/run_zimage_trainer.py); without it training stops at "train deps missing: No module named 'peft'"
safetensors>=0.8.0
Pillow>=13.0.0
pillow-heif>=1.7.0  # AVIF/HEIF image support for vision analysis
mss>=10.2.0  # Fast screenshot capture for agent virtual display

# ComfyUI / Video Generation Dependencies
torchsde>=0.2.6
sentencepiece>=0.2.2
kornia>=0.7.1
spandrel>=0.4.2
av>=18.1.0
pydantic-settings>=2.15.0
gguf>=0.19.0

# Face-restore heavy CV deps moved to the OPTIONAL extra
# backend/requirements-cv.txt (P3-10b): gfpgan, realesrgan, facexlib, basicsr,
# lmdb, tb-nightly, opencv-python. They lack aarch64/Pi wheels and aborted the
# whole install; only the (lazy, guarded) face_restoration_service uses them.
# scipy/tqdm/PyYAML stay here — they're shared transitive deps of the always-on
# stack (transformers/huggingface_hub require tqdm+pyyaml), not CV-exclusive.
scipy>=1.10.0  # used by image/audio paths; also a GFPGAN dep
tqdm>=4.65.0   # transitive dep of transformers/huggingface_hub (always-on)
PyYAML>=6.0    # transitive dep of transformers/huggingface_hub (always-on)

# Video Processing Dependencies
imageio==2.38.1
imageio-ffmpeg==0.6.0

# Voice Processing Dependencies
piper-tts==1.8.0
onnxruntime==1.30.0
pydub==0.25.1
librosa>=0.10.2  # Audio decode + duration probe in voice_api.py
numba>=0.61  # librosa's JIT; its numpy ceiling is what bounds the numpy line in constraints.txt
soundfile>=0.14.0  # WAV/FLAC IO for voice_api + audio_foundry backends

# Testing Dependencies
pytest==9.0.3
pytest-timeout==2.4.0
pytest-playwright==0.8.0  # 0.7.0 caps pytest<9.0.0; 0.8.0 supports pytest 9.x
playwright==1.52.0

# Desktop Automation Dependencies
pyautogui>=0.9.54      # GUI automation (mouse, keyboard)
pynput>=1.8.2          # Keyboard/mouse monitoring
watchdog>=6.0.0        # File system monitoring
pyperclip>=1.8.2       # Cross-platform clipboard
plyer>=2.1.0           # Native notifications

# Development Tools (Optional - uncomment if needed)
# black==25.1.0
# isort==6.0.1
# mypy==1.16.1
# ruff==0.11.13
faster-whisper>=1.2.1

# Code Intelligence Dependencies
tree-sitter>=0.26.0
tree-sitter-python>=0.25.0
tree-sitter-javascript>=0.25.0
tree-sitter-typescript>=0.23.2
tree-sitter-java>=0.23.5
tree-sitter-go>=0.23.0
tree-sitter-rust>=0.24.2
tree-sitter-c>=0.24.2
tree-sitter-cpp>=0.23.4
tree-sitter-ruby>=0.23.0
tree-sitter-php>=0.24.1
tree-sitter-c-sharp>=0.23.5
pathspec>=1.1.1
networkx>=3.2
