Imported from jackmaxwil/macos-modmanager (
AGENTS.md). Install upstream withnpx skills add jackmaxwil/macos-modmanager. Copyright stays with the author.
macOS Mod Manager - Agent Guidelines
Project Context
A Python-based mod manager for Cyberpunk 2077 on macOS. Provides web UI (FastAPI), TUI (Textual), and CLI for installing, managing, and validating mods. Integrates with Nexus Mods API for downloads.
Current Status (Canonical)
See docs/STATUS.md for the current run-state and pointers to the active roadmap/status docs.
Development Practices
Python Standards
- Python 3.11+. Use modern Python features: type hints, dataclasses,
matchstatements. - Async-first. All I/O operations should be async; use
asyncioandaiohttp. - Type annotations. All function signatures must have complete type hints.
- SQLAlchemy async. Use
AsyncSessionfor all database operations.
Package Management
- UV for deps. Use
uvfor fast dependency management;uv.lockis the source of truth. - Requirements.txt. Maintain for compatibility; sync with
pyproject.toml. - Virtual environment. Always work in
.venv; never install globally.
Code Organization
- Separation of concerns. API routes thin; business logic in
core/; data access inmodels/. - No circular imports. Use dependency injection or late imports when needed.
- Config in one place. All settings via
app/config.pyand environment variables.
Architecture
Directory Structure
app/
├── api/ # FastAPI route handlers
│ ├── mods.py # Mod CRUD operations
│ ├── fomod.py # FOMOD installer wizard
│ ├── nexus.py # Nexus API integration
│ └── ...
├── core/ # Business logic
│ ├── mod_manager.py # Central mod operations
│ ├── install_validator.py # Installation with rollback
│ ├── nexus_api.py # Nexus Mods client
│ ├── fomod_parser.py # FOMOD XML parsing
│ └── game_detector.py # Game path detection
├── models/ # SQLAlchemy models
├── templates/ # Jinja2 HTML templates
├── tui/ # Textual TUI application
│ ├── app.py # Main TUI app
│ ├── screens/ # TUI screens
│ └── services/ # TUI service layer
└── main.py # FastAPI app entry
scripts/ # Utility scripts
tests/ # Test suite
Key Components
- ModManager (
core/mod_manager.py) - Central orchestrator for all mod operations. - InstallValidator (
core/install_validator.py) - Atomic installation with filesystem rollback. - NexusAPIClient (
core/nexus_api.py) - Nexus Mods API integration with caching. - TUIModService (
tui/services/) - Bridge between TUI and core services.
Code Standards
Naming
- Files. Lowercase with underscores:
mod_manager.py,nexus_api.py. - Classes. PascalCase:
ModManager,NexusAPIClient,FomodParser. - Functions. snake_case:
install_mod(),get_mod_files(),validate_installation(). - Constants. SCREAMING_SNAKE:
NEXUS_API_BASE,DEFAULT_GAME_PATH.
Database
- Async sessions. Use
get_async_session_context()for transaction safety. - Model naming. Tables singular:
mod,profile,backup. - Migrations. Use Alembic; never modify database directly.
API Design
- RESTful routes.
GET /mods,POST /mods/install,DELETE /mods/{id}. - JSON responses. All API responses return JSON with consistent structure.
- Error handling. Return appropriate HTTP codes; 4xx for client errors, 5xx for server.
TUI Design
- Textual framework. Use Textual's reactive system and widgets.
- Screen-based navigation. Each major function is a separate screen.
- Background workers. Long operations use
@work(thread=True)decorator. - Progress feedback. Show progress bars for downloads and installations.
Mod Compatibility
macOS Compatibility Rules
- No Windows DLLs. Mods containing
.dllfiles without macOS equivalents are incompatible. - Archive mods OK. Pure
.archivemods work without modification. - RED4ext plugins. Require macOS
.dylibport; checkred4ext/plugins/. - Redscript mods. Generally compatible; may need path adjustments.
Compatibility Checking
# In core/mod_manager.py
async def check_compatibility(mod_id: int) -> CompatibilityResult:
# Scan for DLLs, check dependencies, verify paths
Testing
Running Tests
pytest tests/ -v
pytest tests/test_mod_manager.py -v # Specific file
Test Categories
- Unit tests. Test individual functions in isolation.
- Integration tests. Test API routes with database.
- TUI tests. Use Textual's testing utilities.
Mocking
- Mock Nexus API. Don't hit real API in tests; use fixtures.
- Mock filesystem. Use
tmp_pathfixture for file operations. - Mock database. Use in-memory SQLite for fast tests.
CLI Usage
Non-Interactive Mode
# Install mod
python -m app.tui.cli install --mod-id 3858 --auto-confirm
# Bulk install from file
python -m app.tui.cli bulk-install mods.txt --auto-confirm
# Check compatibility
python -m app.tui.cli check-compat https://nexusmods.com/cyberpunk2077/mods/3858
Environment Variables
NEXUS_API_KEY=xxx # Required for Nexus API
CP2077_GAME_PATH=/path # Game installation path
NON_INTERACTIVE=1 # Skip all prompts
AUTO_CONFIRM=1 # Auto-accept confirmations
Common Pitfalls
- Async context. Don't call async functions from sync code without
asyncio.run(). - Session lifecycle. Always use context manager for database sessions.
- File paths. macOS uses
/not\; usepathlib.Patheverywhere. - Archive handling. RAR5 requires
unarutility, not Pythonrarfile. - Nexus rate limits. Cache API responses; respect rate limit headers.
Game Path Detection
The mod manager auto-detects Cyberpunk 2077 installation:
~/Library/Application Support/Steam/steamapps/common/Cyberpunk 2077/
Important Paths
Cyberpunk 2077/
├── Cyberpunk2077.app/Contents/MacOS/ # Game binary
├── red4ext/
│ ├── plugins/ # RED4ext plugins
│ └── cyberpunk2077_addresses.json # Address database
├── r6/
│ ├── tweaks/ # TweakXL tweaks
│ └── scripts/ # Redscript mods
└── archive/pc/mod/ # Archive mods
Logging
- Structured logging. Use Python
loggingmodule with appropriate levels. - SQL logging. Controlled via
SQL_ECHOconfig; disable in production. - Log files. Stored in
data/logs/; rotated daily.