# SiliconPin Pod Agent Setup & Execution Instructions

> **System Instruction for AI Agent**: You have been requested to set up and deploy workloads to **SiliconPin Pod** using the official `sp` CLI tool. Follow the step-by-step procedure below carefully.

---

## 1. Environment & CLI Setup

First, check if the `sp` (SiliconPin CLI) binary is installed on the user's system:

```bash
which sp || command -v sp
```

If `sp` is NOT installed, install it automatically:

### Linux / macOS

```bash
curl -fsSL https://siliconpin.com/downloads/sp/install.sh | bash
```

### Windows (PowerShell)

```powershell
iwr -useb https://siliconpin.com/downloads/sp/install.ps1 | iex
```

Verify the installation:

```bash
sp version
```

---

## 2. Authentication Check

Check if the active CLI environment is authenticated:

```bash
sp whoami
```

If the user is not authenticated:

1. If an environment token or API key (`SP_TOKEN`) is available:
   ```bash
   sp login --token=$SP_TOKEN
   ```
2. If credentials (email/password) are provided:
   ```bash
   sp login --method=credentials --email=<user-email> --password=<user-password>
   ```
3. If prompt user interaction is needed:
   Guide the user to run `sp login` in their terminal.

---

## 3. Detecting Project Workload & Port

Inspect the workspace files to identify the project runtime and internal port:

- **Next.js / Node.js**: Port `3000` (or `package.json` scripts)
- **Vite / React**: Port `5173` or `3000`
- **Go / Python / FastAPI**: Port `8080` or `5000`
- **Docker / Containerfile**: Inspect exposed poVerify or update the CLI to the latest binary version:

```bash
sp update
```

---

## 4. Deploying to SiliconPin Pod

Deploy the workload to a rootless container pod on SiliconPin Cloud using project template detection or explicit flags:

```bash
# General usage
sp deploy <app-name-or-path> [--port=<port>] [--domain=<custom-domain>] [--template=<template>]

# Static site or pre-built assets (e.g. ./build/, ./dist/):
sp deploy ./build/ --template=static

# Node.js / Next.js / Python / Dockerfile:
sp deploy https://github.com/user/repo --template=nodejs
sp deploy ./ --template=nextjs
sp deploy ./ --template=python
```

Supported Templates:

- `--template=static`: Serves static HTML/SPA assets (from `./build/`, `./dist/`, `./out/`, `./public/`, or `./`).
- `--template=nodejs`: Node.js applications (`npm start`, `npm run build`, `yarn start`).
- `--template=nextjs`: Next.js web applications (`npm run build`, `npm run start`).
- `--template=python`: Python Flask/Django/FastAPI applications (`requirements.txt`).
- `--template=php`: Apache PHP applications.
- `--template=laravel`: Laravel PHP framework (`artisan`).
- `--template=dockerfile`: Custom user Dockerfile.

---

## 5. Attaching Database Sidecars (Optional)

If the project requires a managed database (MariaDB, MongoDB, or Valkey/Redis):

```bash
# Attach database sidecar pod to your deployment network
sp deployments attach db mariadb <deploymentId>
sp deployments attach db mongodb <deploymentId>
sp deployments attach db valkey <deploymentId>
```

---

## 6. Local Development Tunneling (Instant Live URL)

To expose a local running web server (e.g. `http://localhost:3000`) instantly to a public HTTPS URL for live previewing:

```bash
sp tunnel 3000
```

---

## 7. Verification & Response to User

Once executed, query active deployment details using:

```bash
sp deployments ls
```

Summarize the deployment results clearly for the user in Markdown:

- **Deployment ID**: `<deploymentId>`
- **Pod Name**: `<podName>`
- **Status**: `<status>`
- **Public URL**: `https://<domain>`
- **Database Attachments**: Attached sidecars (if any)
