diff --git a/.claude/commands/deploy.md b/.claude/commands/deploy.md deleted file mode 100644 index 98198280..00000000 --- a/.claude/commands/deploy.md +++ /dev/null @@ -1,171 +0,0 @@ -# Deploy - -Deploy and connect Computing Provider to Swan Inference server in development mode. - -## Arguments: $ARGUMENTS - -## Instructions - -This command helps deploy and configure the Computing Provider to connect to a local Swan Inference server running in development mode. - ---- - -## Testnet Information - -### Base Sepolia (Swan Inference Chain) - -| Property | Value | -|----------|-------| -| Network | Base Sepolia | -| Chain ID | 84532 | -| RPC | https://sepolia.base.org | -| Explorer | https://sepolia.basescan.org | - -### Deployed Contracts - -| Contract | Address | -|----------|---------| -| Collateral | `0x5EBc65E856ad97532354565560ccC6FAB51b255a` | -| Task | `0x6c1f6ad2b4Cb8A7ba4027b348D7f20A14706d3C2` | - -### Authentication Mode - -**Development:** Node ID based authentication (no on-chain registration required) -- Provider authenticates via wallet signature -- No gas fees required for testing -- Suitable for local development - -**Production:** On-chain CP account registration on Swan Chain required - ---- - -## Development Server Configuration - -### Swan Inference Dev Server - -Connect to the local Swan Inference server: -- **HTTP API**: http://localhost:8080 -- **WebSocket**: ws://localhost:8081 (used by ECP2 client) - ---- - -## Deployment Steps - -### Step 1: Verify Prerequisites - -Ensure the following are running: -1. Swan Inference server on `localhost:8080` -2. Docker daemon with NVIDIA Container Toolkit (for GPU support) -3. Computing Provider built for testnet (`make testnet && make install`) - -### Step 2: Configure ECP2 for Dev Mode - -Update `$CP_PATH/config.toml` to point to the local dev server: - -```toml -[API] -Port = 8085 -MultiAddress = "/ip4/127.0.0.1/tcp/8085" -Domain = "localhost" -PortRange = ["40000-40050"] - -[RPC] -# Use local or testnet RPC -SWAN_CHAIN_RPC = "https://rpc-testnet.swanchain.io" - -[ECP2] -Enable = true -ServiceURL = "http://localhost:8080" # HTTP API (not currently used by client) -WebSocketURL = "ws://localhost:8081" # WebSocket connection to Swan Inference -Models = ["llama-3.1-8b", "qwen2.5-7b"] # Models this provider serves - -# Base Sepolia (Swan Inference chain) -ChainRPC = "https://sepolia.base.org" -CollateralContract = "0x5EBc65E856ad97532354565560ccC6FAB51b255a" -TaskContract = "0x6c1f6ad2b4Cb8A7ba4027b348D7f20A14706d3C2" -``` - -**Note:** The ECP2 client connects to Swan Inference via WebSocket (`WebSocketURL`), not HTTP. -Contracts are deployed on Base Sepolia (chainId: 84532). - -### Step 3: Set Environment Variables - -```bash -export CP_PATH=~/.swan/computing - -# Optional: Override WebSocket URL for dev (takes precedence over config.toml) -export INFERENCE_WS_URL=ws://localhost:8081 -``` - -### Step 4: Start Computing Provider in Dev Mode - -```bash -# Start the UBI daemon connecting to local swan-inference -computing-provider run -``` - ---- - -## Dev Server Endpoints - -When connected to Swan Inference dev server: - -**HTTP API (localhost:8080)** -| Endpoint | Description | -|----------|-------------| -| `GET /health` | Health check | -| `POST /v1/inference` | Submit inference request | -| `GET /v1/models` | List available models | - -**WebSocket (ws://localhost:8081)** -| Message Type | Description | -|--------------|-------------| -| `register` | Provider registration with models | -| `inference` | Inference request from server | -| `heartbeat` | Provider liveness check | -| `stream_chunk` | Streaming response chunk | - ---- - -## Troubleshooting Dev Mode - -### Connection Refused -```bash -# Verify swan-inference HTTP API is running -curl http://localhost:8080/health - -# Check WebSocket port is listening -nc -zv localhost 8081 -``` - -### Port Already in Use -```bash -# Check what's using port 8080 -lsof -i :8080 -``` - -### Docker Permission Issues -```bash -# Run with docker group -sg docker -c "computing-provider run" -``` - ---- - -## Quick Start Commands - -```bash -# 1. Build for testnet -make clean && make testnet && make install - -# 2. Initialize (if not already done) -computing-provider init --multi-address=/ip4/127.0.0.1/tcp/8085 --node-name=dev-provider - -# 3. Edit config to enable ECP2 -# $CP_PATH/config.toml: -# [ECP2] -# Enable = true - -# 4. Start daemon with dev WebSocket URL override -INFERENCE_WS_URL=ws://localhost:8081 computing-provider run -``` diff --git a/.claude/commands/research.md b/.claude/commands/research.md deleted file mode 100644 index 7ca0d24d..00000000 --- a/.claude/commands/research.md +++ /dev/null @@ -1,173 +0,0 @@ -# Research - -Research assistant for Computing Provider v2 development. Analyzes codebase, searches documentation, and provides implementation guidance. - -## Topic: $ARGUMENTS - -## Instructions - -You are a technical researcher helping develop the Computing Provider v2 for Swan Chain. This is a Go CLI that turns GPUs into AI inference endpoints via WebSocket connection to Swan Inference. - -1. Understand the feature or topic being researched -2. Analyze existing codebase patterns -3. Search for relevant best practices -4. Provide actionable implementation guidance - ---- - -## Research Process - -### Step 1: Understand the Request - -Parse the research topic from `$ARGUMENTS`. Identify: -- What feature or component is being researched -- What specific questions need answering -- What context is needed from the codebase - -### Step 2: Analyze Existing Codebase - -Search the codebase to understand current patterns: - -**Architecture Overview** -``` -cmd/computing-provider/ # CLI commands (urfave/cli) -internal/computing/ # Core services -internal/contract/ # Smart contract bindings -internal/setup/ # Setup wizard & model discovery -internal/dashboard/ # Web dashboard -conf/ # Configuration -``` - -**CLI Commands** (`cmd/computing-provider/`) -- `main.go` - Command registration -- `ubi.go` - `run` command, REST API routes, inference startup -- `setup.go` - Setup wizard (auth, model discovery, config generation) -- `inference.go` - Swan Inference status/config commands -- `wallet.go` - Wallet management -- `task.go` - Task listing - -**Inference Core** (`internal/computing/`) -- `inference_client.go` - WebSocket client for Swan Inference (connect, register, heartbeat, message handling) -- `inference_service.go` - Request forwarding to model servers, streaming, warmup -- `model_registry.go` - Model config management, hot-reload from models.json -- `model_health_checker.go` - Health monitoring with circuit breaker -- `docker_service.go` - Docker container management -- `metrics_collector.go` - Request/latency/token metrics - -**Setup & Discovery** (`internal/setup/`) -- `discovery.go` - Auto-discover model servers (SGLang, vLLM, Ollama), match to Swan Inference model IDs -- `auth_client.go` - Swan Inference API auth (signup, login, API key management) -- `prompter.go` - Interactive CLI prompts - -**Configuration** (`conf/`) -- `config.go` - Config structs, defaults, environment overrides -- Config file: `$CP_PATH/config.toml` -- Model endpoints: `$CP_PATH/models.json` - -**Smart Contracts** (`internal/contract/`) -- `ecp/` - Edge Computing Provider contracts -- `account/` - CP account registration -- `token/` - SWAN token operations - -**Dashboard** (`internal/dashboard/`) -- `server.go` - Dashboard HTTP server (port 3060) -- `ui/` - React frontend (Vite + Tailwind) - -### Step 3: Search External Resources - -Use web search to find: -- Go best practices for the specific feature -- WebSocket patterns (gorilla/websocket) -- Docker SDK patterns -- OpenAI-compatible API patterns -- Similar implementations in other Go projects - -### Step 4: Provide Implementation Guidance - -Deliver a research report with: - -1. **Executive Summary** - Brief overview of findings -2. **Existing Patterns** - How similar features are implemented in the codebase -3. **Recommended Approach** - Step-by-step implementation plan -4. **Key Files to Modify** - Specific files that need changes -5. **Code Examples** - Sample code following project conventions -6. **Considerations** - Security, performance, and operational notes -7. **References** - Links to relevant documentation - ---- - -## Common Research Topics - -### WebSocket & Swan Inference Integration -- `internal/computing/inference_client.go` - Connection, registration, heartbeat, message types -- Message types: register, inference, stream_chunk, stream_end, warmup, heartbeat, ack, error -- Auth: Bearer token in status check, API key in register payload -- Config: `WebSocketURL`, `ApiKey`, `Models` in `[Inference]` section - -### Model Server Integration -- `internal/computing/inference_service.go` - Forward requests to `/v1/chat/completions` -- `internal/computing/model_registry.go` - Load models.json, hot-reload -- Supports: SGLang, vLLM, Ollama (OpenAI-compatible API) -- `local_model` field maps Swan model IDs to server model names - -### Adding a New CLI Command -- Pattern: `cmd/computing-provider/*.go` using `urfave/cli` -- Register in `main.go` app.Commands -- Use `conf.GetConfig()` for configuration access -- Use `logs.GetLogger()` for logging - -### REST API Endpoints -- Routes defined in `cmd/computing-provider/ubi.go` (gin router) -- Base path: `/api/v1/computing/` -- Inference endpoints: `/api/v1/computing/inference/*` -- Add new routes in the `startAPIServer()` function - -### Docker Container Management -- `internal/computing/docker_service.go` - Container lifecycle -- Uses Docker SDK (`github.com/docker/docker/client`) -- NVIDIA GPU support via container toolkit - -### Model Health & Monitoring -- `internal/computing/model_health_checker.go` - Periodic health checks -- Circuit breaker pattern for failing models -- Health updates sent to Swan Inference via WebSocket - -### Setup Wizard & Model Discovery -- `internal/setup/discovery.go` - Probe endpoints for model servers -- `internal/setup/auth_client.go` - Swan Inference API (signup/login) -- Auto-match local models to Swan Inference model catalog - -### Dashboard -- `internal/dashboard/server.go` - Go HTTP server -- `internal/dashboard/ui/` - React + Vite + Tailwind -- Proxies to inference API endpoints - ---- - -## Project Conventions - -### Go Patterns -- `internal/` for non-exported packages -- `urfave/cli` for CLI framework -- `gin` for HTTP router -- `gorilla/websocket` for WebSocket client -- Docker SDK for container management - -### Error Handling -- Return errors up the call stack -- Use `logs.GetLogger()` for logging -- Include context in error messages - -### Configuration -- Config loaded from `$CP_PATH/config.toml` -- Environment overrides: `CP_PATH`, `INFERENCE_API_KEY`, `INFERENCE_WS_URL` -- Use `conf.GetConfig()` to access configuration - -### Development -- `go run ./cmd/computing-provider run` (always runs latest code) -- `make clean && make mainnet && make install` for binary -- Dashboard: `computing-provider dashboard` (port 3060) - -### Build -- Use Makefile targets (`make mainnet`, `make testnet`) -- Binary installed to `/usr/local/bin/computing-provider` diff --git a/.claude/skills/computing-provider/SKILL.md b/.claude/skills/computing-provider/SKILL.md deleted file mode 100644 index 974ae6a0..00000000 --- a/.claude/skills/computing-provider/SKILL.md +++ /dev/null @@ -1,79 +0,0 @@ ---- -name: computing-provider -description: Helps build, test, deploy, and troubleshoot the Swan Chain Computing Provider CLI. Use when working with ECP (Edge Computing Provider) for ZK proofs, FCP (Fog Computing Provider) for AI tasks, or managing wallets, accounts, and collateral. -allowed-tools: Bash, Read, Grep, Glob ---- - -# Computing Provider Development Guide - -## Quick Reference - -### Build Commands -```bash -# Mainnet build -make clean && make mainnet && make install - -# Testnet build -make clean && make testnet && make install - -# Run tests -go test ./... -``` - -### Provider Types - -| Type | Purpose | Requires K8s | Start Command | -|------|---------|--------------|---------------| -| ECP | ZK-Snark proofs (FIL-C2, Aleo) | No | `computing-provider ubi daemon` | -| FCP | AI model training/deployment | Yes | `computing-provider run` | - -### Task Types -- 1 = FIL-C2 (ECP) -- 2 = Mining (ECP) -- 3 = AI (FCP) -- 4 = Inference (ECP) -- 5 = NodePort -- 100 = Exit - -## ECP Setup Checklist - -1. Install NVIDIA Container Toolkit for GPU access in Docker -2. Download v28 parameters (200GB+ storage needed) -3. Set environment variables: - - `FIL_PROOFS_PARAMETER_CACHE=` - - `RUST_GPU_TOOLS_CUSTOM_GPU=":"` -4. Map port 9085 to public network -5. Create account with task-types 1,2,4 -6. Add ECP collateral and sequencer funds - -## Common ECP Errors - -| Error | Solution | -|-------|----------| -| `permission denied...docker.sock` | Add user to docker group or use `sg docker -c "..."` | -| `could not select device driver "nvidia"` | Install NVIDIA Container Toolkit | -| `container name "/resource-exporter" is already in use` | Run `docker rm -f resource-exporter` | -| `CP Account is empty` | Create account with `computing-provider account create ...` | - -## Key Directories - -- `cmd/computing-provider/`: CLI commands -- `internal/computing/`: Core services (K8s, Docker, UBI) -- `internal/contract/`: Smart contract bindings -- `conf/`: Configuration loading -- `build/`: Network parameters (mainnet/testnet) - -## Configuration Files - -- `$CP_PATH/config.toml`: Main configuration -- `$CP_PATH/price.toml`: Resource pricing -- Default CP_PATH: `~/.swan/computing` - -## Sequencer Configuration - -In `config.toml`: -```toml -[UBI] -EnableSequencer = true # Use sequencer for lower gas costs -AutoChainProof = false # Fallback when sequencer unavailable -```