diff --git a/README.md b/README.md index 035acd0..6edb7b0 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,15 @@ Here is what we will build together in this README. We'll start with a Hello Wor https://github.com/user-attachments/assets/9badad0d-f939-4243-ba39-68cafdae0078 +> **Windows Users**: Please see [WINDOWS.md](WINDOWS.md) for a complete Windows-specific guide with PowerShell commands and troubleshooting tips. + ### Prerequisites - **Install Python 3.12+ (Required)**: https://www.python.org/downloads/ +#### macOS/Linux + ```bash # Install uv (fast Python package manager) https://docs.astral.sh/uv/getting-started/installation/ curl -LsSf https://astral.sh/uv/install.sh | sh @@ -62,6 +66,22 @@ brew install docker docker-compose node brew services stop redis ``` +#### Windows + +```powershell +# Install uv (fast Python package manager) https://docs.astral.sh/uv/getting-started/installation/ +powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" + +# Install Docker Desktop for Windows +# Download from: https://www.docker.com/products/docker-desktop/ + +# Install Node.js +# Download from: https://nodejs.org/ + +# Note: Windows users should use PowerShell scripts (build.ps1) instead of Makefiles +# All make commands have equivalent PowerShell commands +``` + #### Install the Agentex SDK You will need the Agentex CLI to create your first Agent. Use `uv tool` to install the `agentex` CLI in an self-contained environment, but still make it globally available. @@ -89,6 +109,8 @@ First, open up a terminal. Then run the following commands. *Note: you should run these commands at the root of this repository.* +#### macOS/Linux + ```bash cd agentex/ # Install dependencies in a virtual environment @@ -97,6 +119,18 @@ uv venv && source .venv/bin/activate && uv sync make dev ``` +#### Windows (PowerShell) + +```powershell +cd agentex/ +# Install dependencies in a virtual environment +uv venv +.venv\Scripts\Activate.ps1 +uv sync +# Start backend services via docker compose (see build.ps1 for details) +.\build.ps1 dev +``` + ### (Optional) Terminal 1.5 - LazyDocker It's hard to see if everything is healthy when you just run docker compose in a single terminal since all the logs are jumbled up. Instead, we recommend installing [lazydocker](https://github.com/jesseduffield/lazydocker) and running the following shortcut in a separate terminal. @@ -122,6 +156,8 @@ Then, open up a second terminal. Then run the following commands. *Note: you should run these commands at the root of this repository.* +#### macOS/Linux + ```bash cd agentex-ui/ # Install dependencies (see Makefile for details) @@ -130,6 +166,16 @@ make install make dev ``` +#### Windows (PowerShell) + +```powershell +cd agentex-ui/ +# Install dependencies (see build.ps1 for details) +.\build.ps1 install +# Starts web interface on localhost (default port 3000) +.\build.ps1 dev +``` + ## Create Your First Agent The Agentex Python SDK natively ships with a CLI. Use this CLI to scaffold your first "Hello World" agent. Run `agentex -h` to ensure the CLI is available. @@ -153,12 +199,23 @@ Here is an example of the CLI flow you should follow with some example responses Set up your virtual environment, install dependencies, and enter your virtual environment +#### macOS/Linux + ```bash cd your-agent-name/ uv venv && source .venv/bin/activate && uv sync ``` -> Note: If you are using an IDE, we recommend you setting your virtual environment path to `.venv/bin/python` to get linting +#### Windows (PowerShell) + +```powershell +cd your-agent-name/ +uv venv +.venv\Scripts\Activate.ps1 +uv sync +``` + +> Note: If you are using an IDE, we recommend you setting your virtual environment path to `.venv/bin/python` (macOS/Linux) or `.venv\Scripts\python.exe` (Windows) to get linting ### Your Agent Server @@ -273,27 +330,49 @@ Here are the differences between Open Source vs Enterprise to meet different org ## Troubleshooting #### Redis Port Conflict + If you have Redis running locally, it may conflict with Docker Redis: + +**macOS:** ```bash -# Stop local Redis (macOS) +# Stop local Redis brew services stop redis +``` -# Stop local Redis (Linux) +**Linux:** +```bash +# Stop local Redis sudo systemctl stop redis-server ``` +**Windows:** +```powershell +# If you have Redis service installed, stop it +Stop-Service redis +# Or if running manually, find and kill the process +Get-Process redis-server | Stop-Process +``` + #### Port or Address Already in Use - If you are running multiple agents at the same time and see `ACP: ERROR: [Errno 48] Address already in use`, modify the `local_development.agent.port` field in your `manifest.yaml` to use a different port for each agent or just Ctrl-C any agents you're not currently working on. Don't wory your messages will still persist. - If you are running processes that conflict witht he ports in the docker compose, either kill those conflicting processes (if you don't need them) or modify the docker compose to use different ports. -Use this command to find and kill processes on conflicting ports (if you don't need those processes). +**macOS/Linux:** ```bash # Kill process on specific port (replace and accordingly) lsof -i TCP: kill -9 ``` +**Windows (PowerShell):** +```powershell +# Find process on specific port (replace ) +netstat -ano | findstr : +# Kill process by PID (replace ) +Stop-Process -Id -Force +``` + #### `agentex` Command Not Found If you get "command not found: agentex", make sure you've installed the SDK: ```bash diff --git a/WINDOWS.md b/WINDOWS.md new file mode 100644 index 0000000..d2c8304 --- /dev/null +++ b/WINDOWS.md @@ -0,0 +1,338 @@ +# Windows Development Guide + +This guide explains how to use Agentex on Windows. All functionality available through Makefiles is also available via PowerShell scripts. + +## Prerequisites + +### Required Software + +1. **Python 3.12+** - Download from https://www.python.org/downloads/ +2. **Docker Desktop for Windows** - Download from https://www.docker.com/products/docker-desktop/ + 1. Alternatively, if you need a license-free version, explore: + https://rancherdesktop.io/ + https://podman.io/docs/installation +3. **Node.js** - Download from https://nodejs.org/ +4. **uv (Python package manager)** - Install with PowerShell: + +```powershell +powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" +``` + +## PowerShell Scripts + +Each directory with a Makefile now has an equivalent `build.ps1` PowerShell script: + +- `/build.ps1` - Root workspace commands +- `/agentex/build.ps1` - Backend development commands +- `/agentex-ui/build.ps1` - Frontend development commands + +### PowerShell Execution Policy + +If you encounter execution policy errors when running scripts, you may need to adjust your PowerShell execution policy: + +```powershell +# Check current policy +Get-ExecutionPolicy + +# Set policy for current user (recommended) +Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser +``` + +## Getting Started + +### 1. Setup the Repository + +```powershell +# Clone the repository +git clone https://github.com/scaleapi/scale-agentex.git +cd scale-agentex + +# Setup the workspace +.\build.ps1 repo-setup +``` + +### 2. Start the Backend (Terminal 1) + +```powershell +cd agentex + +# Create and activate virtual environment +uv venv +.venv\Scripts\Activate.ps1 + +# Install dependencies +uv sync + +# Start development server with Docker Compose +.\build.ps1 dev +``` + +### 3. Start the Frontend (Terminal 2) + +```powershell +cd agentex-ui + +# Install dependencies +.\build.ps1 install + +# Start development server +.\build.ps1 dev +``` + +The UI will be available at http://localhost:3000 + +### 4. Create and Run Your Agent (Terminal 3) + +```powershell +# Install the Agentex SDK globally +uv tool install agentex-sdk + +# Create a new agent +agentex init + +# Navigate to your agent directory +cd your-agent-name + +# Create and activate virtual environment +uv venv +.venv\Scripts\Activate.ps1 +uv sync + +# Start your agent +agentex agents run --manifest manifest.yaml +``` + +## Command Reference + +### Root Workspace Commands + +| Purpose | Command | +|---------|---------| +| Setup development environment | `.\build.ps1 repo-setup` | +| Show help | `.\build.ps1 help` | + +### Backend (agentex/) Commands + +| Purpose | Command | +|---------|---------| +| Install dependencies | `.\build.ps1 install` | +| Install with dev dependencies | `.\build.ps1 install-dev` | +| Start development server | `.\build.ps1 dev` | +| Stop development server | `.\build.ps1 dev-stop` | +| Run tests | `.\build.ps1 test` | +| Run unit tests | `.\build.ps1 test-unit` | +| Run integration tests | `.\build.ps1 test-integration` | +| Create migration | `.\build.ps1 migration -Name "migration_name"` | +| Apply migrations | `.\build.ps1 apply-migrations` | +| Serve documentation | `.\build.ps1 serve-docs` | +| Build Docker image | `.\build.ps1 docker-build` | +| Show all commands | `.\build.ps1 help` | + +### Frontend (agentex-ui/) Commands + +| Purpose | Command | +|---------|---------| +| Install dependencies | `.\build.ps1 install` | +| Start development server | `.\build.ps1 dev` | +| Run TypeScript type checking | `.\build.ps1 typecheck` | +| Run linting | `.\build.ps1 lint` | +| Build Docker image | `.\build.ps1 build` | +| Run Docker container | `.\build.ps1 run` | +| Stop Docker container | `.\build.ps1 stop` | +| Show all commands | `.\build.ps1 help` | + +## Common Issues + +### Port Conflicts + +If you encounter port conflicts: + +```powershell +# Find process using a specific port (e.g., 5003) +netstat -ano | findstr :5003 + +# Kill process by PID +Stop-Process -Id -Force +``` + +### Redis Conflicts + +If you have Redis installed as a Windows service: + +```powershell +# Stop Redis service +Stop-Service redis + +# Or kill Redis process +Get-Process redis-server | Stop-Process +``` + +### Virtual Environment + +To activate your virtual environment: + +```powershell +# PowerShell +.venv\Scripts\Activate.ps1 + +# Command Prompt +.venv\Scripts\activate.bat +``` + +To deactivate: + +```powershell +deactivate +``` + +### Docker Issues + +Ensure Docker Desktop is running: + +1. Open Docker Desktop +2. Wait for it to fully start (green indicator in system tray) +3. Verify with: `docker --version` + +If Docker Compose fails: + +```powershell +# Try stopping and cleaning up +cd agentex +.\build.ps1 dev-wipe + +# Then start again +.\build.ps1 dev +``` + +## Testing + +### Running Tests + +```powershell +cd agentex + +# Run all tests +.\build.ps1 test + +# Run specific test file +.\build.ps1 test -File tests\unit\test_example.py + +# Run tests matching a pattern +.\build.ps1 test -Name "crud" + +# Run with coverage +.\build.ps1 test-cov + +# Show test help +.\build.ps1 test-help +``` + +## Docker Builds + +### Building Images + +```powershell +# Backend +cd agentex +.\build.ps1 docker-build + +# Frontend +cd agentex-ui +.\build.ps1 build-and-load +``` + +### Running Containers + +```powershell +cd agentex-ui + +# Run in foreground +.\build.ps1 run + +# Run in background +.\build.ps1 run-detached + +# View logs +.\build.ps1 logs + +# Stop container +.\build.ps1 stop +``` + +## IDE Configuration + +### VS Code + +Add to your `.vscode/settings.json`: + +```json +{ + "python.defaultInterpreterPath": ".venv\\Scripts\\python.exe", + "python.terminal.activateEnvironment": true +} +``` + +### PyCharm + +1. Open Settings → Project → Python Interpreter +2. Click gear icon → Add +3. Select "Existing environment" +4. Browse to `.venv\Scripts\python.exe` + +## Differences from macOS/Linux + +### Path Separators + +Windows uses backslashes (`\`) instead of forward slashes (`/`) for paths: + +- macOS/Linux: `.venv/bin/activate` +- Windows: `.venv\Scripts\Activate.ps1` + +### Line Endings + +Windows uses CRLF (`\r\n`) while Linux uses LF (`\n`). Git should handle this automatically, but if you encounter issues: + +```powershell +# Configure Git to handle line endings +git config --global core.autocrlf true +``` + +### Shell Differences + +Some commands work differently: + +| Purpose | macOS/Linux | Windows PowerShell | +|---------|-------------|-------------------| +| List files | `ls` | `Get-ChildItem` or `ls` (alias) | +| Environment variables | `export VAR=value` | `$env:VAR = "value"` | +| Current directory | `pwd` | `Get-Location` or `pwd` (alias) | +| Remove files | `rm -rf folder` | `Remove-Item -Recurse -Force folder` | + +## Getting Help + +For any command, use the help flag: + +```powershell +# Root workspace +.\build.ps1 help + +# Backend +cd agentex +.\build.ps1 help + +# Frontend +cd agentex-ui +.\build.ps1 help + +# Agentex CLI +agentex --help +``` + +## Additional Resources + +- [Main README](../README.md) - General getting started guide +- [Agentex Backend README](../agentex/README.md) - Backend-specific details +- [Agentex UI README](../agentex-ui/README.md) - Frontend-specific details +- [Python SDK](https://github.com/scaleapi/scale-agentex-python) - Agent development examples +- [Documentation](https://agentex.sgp.scale.com/docs) - Comprehensive concepts and guides + diff --git a/agentex-ui/README.md b/agentex-ui/README.md index ed77960..8583cf1 100644 --- a/agentex-ui/README.md +++ b/agentex-ui/README.md @@ -60,17 +60,28 @@ A modern web interface for building, testing, and monitoring intelligent agents. - npm - Running Agentex backend (see `../agentex/README.md`) +> **Windows Users**: Use PowerShell scripts (`build.ps1`) instead of Make commands throughout this guide. + ## Getting Started from Scratch ### 1. Start the Backend Before running the frontend, ensure the Agentex backend is running: +#### macOS/Linux + ```bash cd ../agentex make dev ``` +#### Windows (PowerShell) + +```powershell +cd ../agentex +.\build.ps1 dev +``` + This starts all required services (PostgreSQL, Redis, MongoDB, Temporal) and the FastAPI backend on port 5003. ### 2. Configure Environment Variables @@ -99,27 +110,37 @@ This installs all required packages including Next.js, React, Tailwind CSS, and ### 4. Run the Development Server +#### macOS/Linux + ```bash npm run dev # or using make make dev ``` +#### Windows (PowerShell) + +```powershell +npm run dev +# or using PowerShell script +.\build.ps1 dev +``` + The application will start on [http://localhost:3000](http://localhost:3000). ## Scripts **Development:** -- `make dev` or `npm run dev` — Start dev server with Turbopack +- `npm run dev` — Start dev server with Turbopack - `npm run build` — Create production build - `npm start` — Start production server **Code Quality:** -- `make lint` or `npm run lint` — Run ESLint with zero warnings policy +- `npm run lint` — Run ESLint with zero warnings policy - `npm run lint:fix` — Auto-fix linting issues -- `make typecheck` or `npm run typecheck` — TypeScript type checking +- `npm run typecheck` — TypeScript type checking - `npm run format` — Format code with Prettier - `npm run format:check` — Check formatting without writing @@ -130,6 +151,19 @@ The application will start on [http://localhost:3000](http://localhost:3000). - `npm run test:ui` — Open Vitest UI for interactive testing - `npm run test:coverage` — Generate coverage report +**Using PowerShell Scripts (Windows):** + +For Windows users, the following PowerShell commands are available via `build.ps1`: + +- `.\build.ps1 dev` — Start dev server (runs install and npm run dev) +- `.\build.ps1 install` — Install dependencies +- `.\build.ps1 typecheck` — TypeScript type checking +- `.\build.ps1 lint` — Run linting +- `.\build.ps1 build` — Build Docker image (includes typecheck and lint) +- `.\build.ps1 help` — Show all available commands + +For Docker-related commands, see the Docker section in `build.ps1 help`. + ## Architecture ### Code Structure diff --git a/agentex-ui/build.ps1 b/agentex-ui/build.ps1 new file mode 100644 index 0000000..185ee83 --- /dev/null +++ b/agentex-ui/build.ps1 @@ -0,0 +1,298 @@ +# AgentEx UI PowerShell Build Script +# Provides Docker build automation for Windows users + +param( + [Parameter(Position=0)] + [string]$Command = "help", + + [string]$ImageName = "agentex-ui", + [string]$Tag = "latest", + [string]$Platform = "linux/amd64", + [string]$Registry = "" +) + +# Calculate full image name +$FullImageName = if ($Registry) { "$Registry/$ImageName" } else { $ImageName } + +function Show-Help { + Write-Host "Available targets:" -ForegroundColor Cyan + Write-Host "" + Write-Host "Setup:" -ForegroundColor Yellow + Write-Host " setup-buildx Set up Docker buildx builder (run once)" -ForegroundColor Green + Write-Host "" + Write-Host "Build Commands:" -ForegroundColor Yellow + Write-Host " build Build Docker image for linux/amd64 platform" -ForegroundColor Green + Write-Host " build-no-cache Build Docker image without cache" -ForegroundColor Green + Write-Host " build-debug Build Docker image with verbose output for debugging" -ForegroundColor Green + Write-Host " build-and-load Build Docker image and load it to local Docker daemon" -ForegroundColor Green + Write-Host "" + Write-Host "Run Commands:" -ForegroundColor Yellow + Write-Host " run Run the Docker container locally" -ForegroundColor Green + Write-Host " run-detached Run the Docker container in detached mode" -ForegroundColor Green + Write-Host " stop Stop the running container" -ForegroundColor Green + Write-Host "" + Write-Host "Registry Commands:" -ForegroundColor Yellow + Write-Host " push Push the image to registry (requires -Registry)" -ForegroundColor Green + Write-Host " build-and-push Build and push Docker image directly (requires -Registry)" -ForegroundColor Green + Write-Host "" + Write-Host "Utility Commands:" -ForegroundColor Yellow + Write-Host " clean Remove the Docker image" -ForegroundColor Green + Write-Host " inspect Inspect the Docker image" -ForegroundColor Green + Write-Host " logs Show logs from running container" -ForegroundColor Green + Write-Host " shell Open shell in running container" -ForegroundColor Green + Write-Host "" + Write-Host "Development Commands:" -ForegroundColor Yellow + Write-Host " dev Run development server locally (without Docker)" -ForegroundColor Green + Write-Host " install Install dependencies" -ForegroundColor Green + Write-Host " typecheck Run TypeScript type checking" -ForegroundColor Green + Write-Host " lint Run linting" -ForegroundColor Green + Write-Host "" + Write-Host "Quick Commands:" -ForegroundColor Yellow + Write-Host " build-and-run Build and run the container" -ForegroundColor Green + Write-Host " build-and-run-detached Build and run the container in detached mode" -ForegroundColor Green + Write-Host "" + Write-Host "Usage: .\build.ps1 [options]" -ForegroundColor Cyan + Write-Host "" + Write-Host "Examples:" -ForegroundColor Yellow + Write-Host " .\build.ps1 build -Tag v1.0.0 -Registry myregistry.com" -ForegroundColor Green + Write-Host " .\build.ps1 push -Tag v1.0.0 -Registry myregistry.com" -ForegroundColor Green + Write-Host " .\build.ps1 build -ImageName my-custom-name -Tag latest" -ForegroundColor Green +} + +function Invoke-SetupBuildx { + Write-Host "Setting up Docker buildx builder..." -ForegroundColor Cyan + + # Check if builder exists + $builderExists = docker buildx inspect agentex-builder 2>$null + + if (-not $builderExists) { + Write-Host "Creating new buildx builder..." -ForegroundColor Yellow + docker buildx create --name agentex-builder --driver docker-container --bootstrap + if ($LASTEXITCODE -ne 0) { + Write-Host "Failed to create buildx builder" -ForegroundColor Red + exit 1 + } + } + + docker buildx use agentex-builder + if ($LASTEXITCODE -eq 0) { + Write-Host "✅ Docker buildx builder 'agentex-builder' is ready" -ForegroundColor Green + } else { + Write-Host "Failed to use buildx builder" -ForegroundColor Red + exit 1 + } +} + +function Invoke-Typecheck { + Write-Host "Running TypeScript type checking..." -ForegroundColor Cyan + npm run typecheck + if ($LASTEXITCODE -ne 0) { + Write-Host "Type checking failed" -ForegroundColor Red + exit 1 + } +} + +function Invoke-Lint { + Write-Host "Running linting..." -ForegroundColor Cyan + npm run lint + if ($LASTEXITCODE -ne 0) { + Write-Host "Linting failed" -ForegroundColor Red + exit 1 + } +} + +function Invoke-Build { + Write-Host "Building ${FullImageName}:${Tag} for platform ${Platform}..." -ForegroundColor Cyan + Invoke-Typecheck + Invoke-Lint + + docker buildx build --platform $Platform -t "${FullImageName}:${Tag}" . + if ($LASTEXITCODE -eq 0) { + Write-Host "✅ Build complete: ${FullImageName}:${Tag}" -ForegroundColor Green + } else { + Write-Host "Build failed" -ForegroundColor Red + exit 1 + } +} + +function Invoke-BuildNoCache { + Write-Host "Building ${FullImageName}:${Tag} for platform ${Platform} (no cache)..." -ForegroundColor Cyan + Invoke-Typecheck + Invoke-Lint + + docker buildx build --platform $Platform --no-cache -t "${FullImageName}:${Tag}" . + if ($LASTEXITCODE -eq 0) { + Write-Host "✅ Build complete: ${FullImageName}:${Tag}" -ForegroundColor Green + } else { + Write-Host "Build failed" -ForegroundColor Red + exit 1 + } +} + +function Invoke-BuildDebug { + Write-Host "Building ${FullImageName}:${Tag} for platform ${Platform} (debug mode)..." -ForegroundColor Cyan + Invoke-Typecheck + Invoke-Lint + + docker buildx build --platform $Platform --progress=plain --no-cache -t "${FullImageName}:${Tag}" . + if ($LASTEXITCODE -eq 0) { + Write-Host "✅ Build complete: ${FullImageName}:${Tag}" -ForegroundColor Green + } else { + Write-Host "Build failed" -ForegroundColor Red + exit 1 + } +} + +function Invoke-BuildAndLoad { + Write-Host "Building and loading ${FullImageName}:${Tag} for platform ${Platform}..." -ForegroundColor Cyan + Invoke-Typecheck + Invoke-Lint + + docker buildx build --platform $Platform --load -t "${FullImageName}:${Tag}" . + if ($LASTEXITCODE -eq 0) { + Write-Host "✅ Build complete and loaded: ${FullImageName}:${Tag}" -ForegroundColor Green + } else { + Write-Host "Build and load failed" -ForegroundColor Red + exit 1 + } +} + +function Invoke-Run { + Write-Host "Running ${FullImageName}:${Tag}..." -ForegroundColor Cyan + docker run --rm -p 3000:3000 --platform $Platform "${FullImageName}:${Tag}" +} + +function Invoke-RunDetached { + Write-Host "Running ${FullImageName}:${Tag} in detached mode..." -ForegroundColor Cyan + docker run -d --name agentex-ui -p 3000:3000 --platform $Platform "${FullImageName}:${Tag}" + if ($LASTEXITCODE -eq 0) { + Write-Host "✅ Container started. Access at http://localhost:3000" -ForegroundColor Green + } else { + Write-Host "Failed to start container" -ForegroundColor Red + exit 1 + } +} + +function Invoke-Stop { + Write-Host "Stopping agentex-ui container..." -ForegroundColor Cyan + docker stop agentex-ui 2>$null + docker rm agentex-ui 2>$null + Write-Host "✅ Container stopped and removed" -ForegroundColor Green +} + +function Invoke-Push { + if ([string]::IsNullOrWhiteSpace($Registry)) { + Write-Host "❌ Error: REGISTRY must be set to push image" -ForegroundColor Red + Write-Host "Usage: .\build.ps1 push -Registry your-registry.com" -ForegroundColor Yellow + exit 1 + } + + Write-Host "Pushing ${FullImageName}:${Tag}..." -ForegroundColor Cyan + docker push "${FullImageName}:${Tag}" + if ($LASTEXITCODE -eq 0) { + Write-Host "✅ Push complete: ${FullImageName}:${Tag}" -ForegroundColor Green + } else { + Write-Host "Push failed" -ForegroundColor Red + exit 1 + } +} + +function Invoke-BuildAndPush { + if ([string]::IsNullOrWhiteSpace($Registry)) { + Write-Host "❌ Error: REGISTRY must be set to build and push image" -ForegroundColor Red + Write-Host "Usage: .\build.ps1 build-and-push -Registry your-registry.com" -ForegroundColor Yellow + exit 1 + } + + Write-Host "Building and pushing ${FullImageName}:${Tag} for platform ${Platform}..." -ForegroundColor Cyan + Invoke-Typecheck + Invoke-Lint + + docker buildx build --platform $Platform --push -t "${FullImageName}:${Tag}" . + if ($LASTEXITCODE -eq 0) { + Write-Host "✅ Build and push complete: ${FullImageName}:${Tag}" -ForegroundColor Green + } else { + Write-Host "Build and push failed" -ForegroundColor Red + exit 1 + } +} + +function Invoke-Clean { + Write-Host "Removing ${FullImageName}:${Tag}..." -ForegroundColor Cyan + docker rmi "${FullImageName}:${Tag}" 2>$null + Write-Host "✅ Image removed" -ForegroundColor Green +} + +function Invoke-Inspect { + Write-Host "Inspecting ${FullImageName}:${Tag}..." -ForegroundColor Cyan + docker inspect "${FullImageName}:${Tag}" +} + +function Invoke-Logs { + Write-Host "Showing logs from agentex-ui container..." -ForegroundColor Cyan + docker logs -f agentex-ui +} + +function Invoke-Shell { + Write-Host "Opening shell in agentex-ui container..." -ForegroundColor Cyan + docker exec -it agentex-ui /bin/sh +} + +function Invoke-Dev { + Write-Host "Starting development server..." -ForegroundColor Cyan + Invoke-Install + npm run dev +} + +function Invoke-Install { + Write-Host "Installing dependencies..." -ForegroundColor Cyan + npm install + if ($LASTEXITCODE -eq 0) { + Write-Host "✅ Dependencies installed" -ForegroundColor Green + } else { + Write-Host "Installation failed" -ForegroundColor Red + exit 1 + } +} + +function Invoke-BuildAndRun { + Invoke-BuildAndLoad + Invoke-Run +} + +function Invoke-BuildAndRunDetached { + Invoke-BuildAndLoad + Invoke-RunDetached +} + +# Main command dispatcher +switch ($Command.ToLower()) { + "help" { Show-Help } + "setup-buildx" { Invoke-SetupBuildx } + "build" { Invoke-Build } + "build-no-cache" { Invoke-BuildNoCache } + "build-debug" { Invoke-BuildDebug } + "build-and-load" { Invoke-BuildAndLoad } + "run" { Invoke-Run } + "run-detached" { Invoke-RunDetached } + "stop" { Invoke-Stop } + "push" { Invoke-Push } + "build-and-push" { Invoke-BuildAndPush } + "clean" { Invoke-Clean } + "inspect" { Invoke-Inspect } + "logs" { Invoke-Logs } + "shell" { Invoke-Shell } + "dev" { Invoke-Dev } + "install" { Invoke-Install } + "typecheck" { Invoke-Typecheck } + "lint" { Invoke-Lint } + "build-and-run" { Invoke-BuildAndRun } + "build-and-run-detached" { Invoke-BuildAndRunDetached } + default { + Write-Host "Unknown command: $Command" -ForegroundColor Red + Write-Host "" + Show-Help + exit 1 + } +} + diff --git a/agentex/README.md b/agentex/README.md index 08a5477..1d18aea 100644 --- a/agentex/README.md +++ b/agentex/README.md @@ -3,3 +3,45 @@ This package is part of the [Scale Agentex](https://github.com/scaleapi/scale-agentex) project. For installation, development, and deployment instructions, please refer to the main [Agentex README](https://github.com/scaleapi/scale-agentex#readme). + +## Windows Support + +Windows users should use the PowerShell build script (`build.ps1`) instead of the Makefile for all development commands. + +### Quick Start (Windows) + +```powershell +# Install dependencies +.\build.ps1 install-dev + +# Start development server +.\build.ps1 dev + +# Run tests +.\build.ps1 test + +# See all available commands +.\build.ps1 help +``` + +### Command Reference + +All `make` commands have equivalent PowerShell commands: + +| Makefile Command | PowerShell Command | +|-----------------|-------------------| +| `make help` | `.\build.ps1 help` | +| `make install` | `.\build.ps1 install` | +| `make install-dev` | `.\build.ps1 install-dev` | +| `make dev` | `.\build.ps1 dev` | +| `make dev-stop` | `.\build.ps1 dev-stop` | +| `make test` | `.\build.ps1 test` | +| `make test-unit` | `.\build.ps1 test-unit` | +| `make migration NAME="name"` | `.\build.ps1 migration -Name "name"` | +| `make serve-docs` | `.\build.ps1 serve-docs` | + +For a complete list of available commands, run: + +```powershell +.\build.ps1 help +``` diff --git a/agentex/build.ps1 b/agentex/build.ps1 new file mode 100644 index 0000000..7f4ecb7 --- /dev/null +++ b/agentex/build.ps1 @@ -0,0 +1,291 @@ +# AgentEx PowerShell Build Script +# Provides automation for development workflows on Windows + +param( + [Parameter(Position=0)] + [string]$Command = "help", + + [Parameter(Position=1)] + [string]$Name = "", + + [Parameter(Position=2)] + [string]$File = "", + + [string]$Args = "", + + [string]$Tag = "latest", + [string]$ImageName = "agentex", + [string]$Platform = "linux/amd64", + [string]$Registry = "" +) + +function Show-Help { + Write-Host "AgentEx Development Commands:" -ForegroundColor Cyan + Write-Host "" + Write-Host "Development Commands:" -ForegroundColor Yellow + Write-Host " install Install dependencies" -ForegroundColor Green + Write-Host " install-dev Install dependencies including dev group" -ForegroundColor Green + Write-Host " install-docs Install docs dependencies" -ForegroundColor Green + Write-Host " clean Clean virtual environment and lock file" -ForegroundColor Green + Write-Host " env Show how to activate virtual environment" -ForegroundColor Green + Write-Host "" + Write-Host "Development Server:" -ForegroundColor Yellow + Write-Host " dev Start development server with Docker Compose" -ForegroundColor Green + Write-Host " dev-stop Stop development server" -ForegroundColor Green + Write-Host " dev-wipe Stop dev server and wipe DB" -ForegroundColor Green + Write-Host "" + Write-Host "Database Commands:" -ForegroundColor Yellow + Write-Host " migration Create a new migration (usage: .\build.ps1 migration -Name 'migration_name')" -ForegroundColor Green + Write-Host " apply-migrations Apply database migrations" -ForegroundColor Green + Write-Host "" + Write-Host "Documentation:" -ForegroundColor Yellow + Write-Host " serve-docs Serve documentation locally" -ForegroundColor Green + Write-Host " build-docs Build documentation" -ForegroundColor Green + Write-Host "" + Write-Host "Docker:" -ForegroundColor Yellow + Write-Host " docker-build Build production Docker image" -ForegroundColor Green + Write-Host " docker-build-with-docs Build production Docker image with docs" -ForegroundColor Green + Write-Host "" + Write-Host "Test Commands:" -ForegroundColor Yellow + Write-Host " test Run tests" -ForegroundColor Green + Write-Host " test-unit Run unit tests only" -ForegroundColor Green + Write-Host " test-integration Run integration tests only" -ForegroundColor Green + Write-Host " test-cov Run tests with coverage report" -ForegroundColor Green + Write-Host " test-docker-check Check Docker environment setup for testing" -ForegroundColor Green + Write-Host " test-help Show test command examples" -ForegroundColor Green + Write-Host "" + Write-Host "Usage: .\build.ps1 [options]" -ForegroundColor Cyan +} + +function Invoke-Install { + Write-Host "🚀 Installing dependencies..." -ForegroundColor Cyan + uv sync + if ($LASTEXITCODE -ne 0) { exit 1 } + + Push-Location .. + uv run pre-commit install + Pop-Location + + Write-Host "Installation complete!" -ForegroundColor Green +} + +function Invoke-InstallDev { + Write-Host "🚀 Installing dependencies with dev group..." -ForegroundColor Cyan + + # Check if parent repo-setup is needed + if (-not (Test-Path "../.venv")) { + Write-Host "Running repo-setup..." -ForegroundColor Yellow + Push-Location .. + & ".\build.ps1" repo-setup + Pop-Location + } + + uv sync --group dev + if ($LASTEXITCODE -ne 0) { exit 1 } + + Write-Host "Dev installation complete!" -ForegroundColor Green +} + +function Invoke-InstallDocs { + Write-Host "🚀 Installing docs dependencies..." -ForegroundColor Cyan + uv sync --group docs + if ($LASTEXITCODE -ne 0) { exit 1 } + Write-Host "Docs dependencies installed!" -ForegroundColor Green +} + +function Invoke-Clean { + Write-Host "🧹 Cleaning virtual environment..." -ForegroundColor Cyan + if (Test-Path ".venv") { + Remove-Item -Recurse -Force .venv + Write-Host "Removed .venv directory" -ForegroundColor Yellow + } + if (Test-Path "uv.lock") { + Remove-Item -Force uv.lock + Write-Host "Removed uv.lock file" -ForegroundColor Yellow + } + Write-Host "Clean complete!" -ForegroundColor Green +} + +function Show-EnvActivation { + Write-Host "To activate the virtual environment, use:" -ForegroundColor Cyan + Write-Host " .venv\Scripts\Activate.ps1" -ForegroundColor Green + Write-Host "" + Write-Host "Or in Command Prompt:" -ForegroundColor Cyan + Write-Host " .venv\Scripts\activate.bat" -ForegroundColor Green +} + +function Invoke-Dev { + Write-Host "🚀 Starting development server with Docker Compose..." -ForegroundColor Cyan + Invoke-InstallDev + docker compose up --build +} + +function Invoke-DevStop { + Write-Host "Stopping dev server..." -ForegroundColor Cyan + docker compose down + Write-Host "Dev server stopped!" -ForegroundColor Green +} + +function Invoke-DevWipe { + Write-Host "Stopping dev server and wiping DB..." -ForegroundColor Cyan + docker compose down -v + Write-Host "Dev server stopped and DB wiped!" -ForegroundColor Green +} + +function Invoke-Migration { + if ([string]::IsNullOrWhiteSpace($Name)) { + Write-Host "❌ Error: NAME is required" -ForegroundColor Red + Write-Host "Usage: .\build.ps1 migration -Name 'migration_name'" -ForegroundColor Yellow + exit 1 + } + + Write-Host "Creating migration: $Name" -ForegroundColor Cyan + Push-Location database\migrations + alembic revision --autogenerate -m $Name + if ($LASTEXITCODE -eq 0) { + alembic history | Out-File -FilePath migration_history.txt -Encoding utf8 + Write-Host "Migration created successfully!" -ForegroundColor Green + } else { + Write-Host "Failed to create migration" -ForegroundColor Red + } + Pop-Location +} + +function Invoke-ApplyMigrations { + Write-Host "Applying database migrations..." -ForegroundColor Cyan + Push-Location database\migrations + alembic upgrade head + if ($LASTEXITCODE -eq 0) { + Write-Host "Migrations applied successfully!" -ForegroundColor Green + } else { + Write-Host "Failed to apply migrations" -ForegroundColor Red + } + Pop-Location +} + +function Invoke-ServeDocs { + Write-Host "📚 Installing docs dependencies..." -ForegroundColor Cyan + uv sync --group docs + if ($LASTEXITCODE -ne 0) { exit 1 } + + Write-Host "Starting docs server..." -ForegroundColor Cyan + Push-Location docs + uv run mkdocs serve -a localhost:8001 + Pop-Location +} + +function Invoke-BuildDocs { + Write-Host "📚 Building documentation..." -ForegroundColor Cyan + uv sync --group docs + if ($LASTEXITCODE -ne 0) { exit 1 } + + Push-Location docs + uv run mkdocs build + if ($LASTEXITCODE -eq 0) { + Write-Host "Documentation built successfully!" -ForegroundColor Green + } + Pop-Location +} + +function Invoke-DockerBuild { + Write-Host "🐳 Building production Docker image..." -ForegroundColor Cyan + docker buildx build --platform=$Platform --load -f Dockerfile --target production -t ${ImageName}:${Tag} ../ + if ($LASTEXITCODE -eq 0) { + Write-Host "Docker image built successfully!" -ForegroundColor Green + } +} + +function Invoke-DockerBuildWithDocs { + Write-Host "🐳 Building production Docker image with docs..." -ForegroundColor Cyan + docker buildx build --platform=$Platform --load -f Dockerfile --target production -t ${ImageName}:${Tag} --build-arg INCLUDE_DOCS=true . + if ($LASTEXITCODE -eq 0) { + Write-Host "Docker image with docs built successfully!" -ForegroundColor Green + } +} + +function Invoke-Test { + $testArgs = @() + + if (-not [string]::IsNullOrWhiteSpace($File)) { + $testArgs += $File + } + + if (-not [string]::IsNullOrWhiteSpace($Name)) { + $testArgs += "-k" + $testArgs += $Name + } + + if (-not [string]::IsNullOrWhiteSpace($Args)) { + $testArgs += "--pytest-args" + $testArgs += $Args + } + + Write-Host "Running tests..." -ForegroundColor Cyan + uv run python scripts/run_tests.py @testArgs +} + +function Invoke-TestUnit { + Write-Host "Running unit tests..." -ForegroundColor Cyan + uv run python scripts/run_tests.py -m unit +} + +function Invoke-TestIntegration { + Write-Host "Running integration tests..." -ForegroundColor Cyan + uv run python scripts/run_tests.py -m integration +} + +function Invoke-TestCov { + Write-Host "Running tests with coverage..." -ForegroundColor Cyan + uv run python scripts/run_tests.py --cov=src --cov-report=html --cov-report=term +} + +function Invoke-TestDockerCheck { + Write-Host "Checking Docker environment..." -ForegroundColor Cyan + uv run python scripts/test_setup.py --check-docker +} + +function Show-TestHelp { + Write-Host "Test Command Examples:" -ForegroundColor Cyan + Write-Host " .\build.ps1 test # Run all tests" -ForegroundColor Green + Write-Host " .\build.ps1 test -File tests/unit/ # Run all unit tests" -ForegroundColor Green + Write-Host " .\build.ps1 test -File tests/unit/test_foo.py # Run specific file" -ForegroundColor Green + Write-Host " .\build.ps1 test -Name crud # Run tests matching 'crud'" -ForegroundColor Green + Write-Host " .\build.ps1 test -Name 'test_create or test_update' # Multiple patterns" -ForegroundColor Green + Write-Host " .\build.ps1 test -Args '-v -s' # Pass pytest arguments" -ForegroundColor Green + Write-Host " .\build.ps1 test-unit # Shortcut for unit tests" -ForegroundColor Green + Write-Host " .\build.ps1 test-integration # Shortcut for integration tests" -ForegroundColor Green + Write-Host " .\build.ps1 test-cov # Run with coverage report" -ForegroundColor Green + Write-Host " .\build.ps1 test-docker-check # Check Docker setup" -ForegroundColor Green +} + +# Main command dispatcher +switch ($Command.ToLower()) { + "help" { Show-Help } + "install" { Invoke-Install } + "install-dev" { Invoke-InstallDev } + "install-docs" { Invoke-InstallDocs } + "clean" { Invoke-Clean } + "env" { Show-EnvActivation } + "dev" { Invoke-Dev } + "dev-stop" { Invoke-DevStop } + "dev-wipe" { Invoke-DevWipe } + "migration" { Invoke-Migration } + "apply-migrations" { Invoke-ApplyMigrations } + "serve-docs" { Invoke-ServeDocs } + "build-docs" { Invoke-BuildDocs } + "docker-build" { Invoke-DockerBuild } + "docker-build-with-docs" { Invoke-DockerBuildWithDocs } + "test" { Invoke-Test } + "test-unit" { Invoke-TestUnit } + "test-integration" { Invoke-TestIntegration } + "test-cov" { Invoke-TestCov } + "test-docker-check" { Invoke-TestDockerCheck } + "test-help" { Show-TestHelp } + default { + Write-Host "Unknown command: $Command" -ForegroundColor Red + Write-Host "" + Show-Help + exit 1 + } +} + diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..1b4173b --- /dev/null +++ b/build.ps1 @@ -0,0 +1,56 @@ +# AgentEx Workspace PowerShell Script +# This script provides the same functionality as the Makefile for Windows users + +param( + [Parameter(Position=0)] + [string]$Command = "help" +) + +function Show-Help { + Write-Host "AgentEx Workspace Commands:" -ForegroundColor Cyan + Write-Host "" + Write-Host " repo-setup Setup development environment for the workspace" -ForegroundColor Green + Write-Host " help Show this help message" -ForegroundColor Green + Write-Host "" + Write-Host "Usage: .\build.ps1 " -ForegroundColor Yellow + Write-Host "Example: .\build.ps1 repo-setup" -ForegroundColor Yellow +} + +function Invoke-RepoSetup { + Write-Host "Setting up development environment..." -ForegroundColor Cyan + + # Run uv sync with dev group + Write-Host "Installing dependencies with uv..." -ForegroundColor Yellow + uv sync --group dev + if ($LASTEXITCODE -ne 0) { + Write-Host "Error: Failed to sync dependencies" -ForegroundColor Red + exit 1 + } + + # Install pre-commit hooks + Write-Host "Installing pre-commit hooks..." -ForegroundColor Yellow + uv run pre-commit install + if ($LASTEXITCODE -ne 0) { + Write-Host "Error: Failed to install pre-commit hooks" -ForegroundColor Red + exit 1 + } + + Write-Host "Repository setup complete!" -ForegroundColor Green +} + +# Main command dispatcher +switch ($Command.ToLower()) { + "repo-setup" { + Invoke-RepoSetup + } + "help" { + Show-Help + } + default { + Write-Host "Unknown command: $Command" -ForegroundColor Red + Write-Host "" + Show-Help + exit 1 + } +} +