# video-factory

**GPU infrastructure control for Pi.** Install one package and your agent can
provision, deploy, run, monitor, and destroy GPU workloads on whatever cloud
infrastructure you have access to — with video generation (MiniMax H3, Wan 2.2,
HunyuanVideo, Seedance) as the first-class workload.

```bash
pi install npm:@lvrged/video-factory
```

Then, inside Pi:

> I need HunyuanVideo running on a GPU. Find the cheapest suitable provider,
> deploy it, expose an endpoint, test it, and make it available to me as a tool.

The agent figures out the rest — from `docs/pricing/` for provider comparison,
from the skills for the how-to, and from the ledger for cost control.

## What you get

- **`gpu_*` tools** — the normalized agent interface:
  `gpu_setup`, `gpu_status`, `gpu_ensure`, `gpu_provision`, `gpu_register`,
  `gpu_run`, `gpu_job_finish`, `gpu_jobs`, `gpu_spend`, `gpu_destroy`,
  `gpu_model_add`, `gpu_workflow_add`, `gpu_policy`.
- **`/gpu` commands** — the human dashboard: setup, status, deploy, jobs,
  spend, stop, policy.
- **Skills** — the knowledge: `gpu-setup`, `gpu-ops`, `comfyui`,
  `model-deployment`, `video-models`, `provider-adapters`.
- **Docs** — pricing snapshots for RunPod, Vast.ai, Modal, Lambda, Prime
  (`docs/pricing/`) and per-provider playbooks (`docs/providers/`).
- **A persistent registry + job ledger** in `<project>/.pi/gpu/` — the agent
  restarts tomorrow and still knows H3 is deployed, what it costs, and which
  workflow version made which video.

## Quickstart

1. **First run = onboarding.** The extension greets you with `/gpu onboard` —
   the H3 production economics (Turbo 4-8 step workflow, provider lanes,
   cost per finished minute) and the first-deployment flow. Or just say:
   *"set me up to make H3 videos cheaply"* — the agent runs the
   `gpu-onboarding` skill.
2. `/gpu setup` (or ask the agent to run `gpu_setup`) — detects provider CLIs,
   installs missing ones with your permission, checks auth.
3. Ask for a model: *"deploy h3 on the cheapest provider"* — the agent runs
   `gpu_ensure`, searches live prices, provisions, installs ComfyUI + weights
   (with the optimized Turbo/Sage/INT8 workflow), health-checks with a test
   generation, and registers the deployment.
4. Generate: *"run h3-image-to-video on slide-042.png with 'slow push-in',
   5 seconds"* — `gpu_run` opens a ledger entry; artifacts sync off the pod
   before shutdown.
5. *"How much did the last 100 videos cost?"* — `gpu_spend` answers from the
   ledger. *"Regenerate everything from workflow v3"* — `gpu_jobs` finds them.

## Provider coverage

| Provider | Interface | Kind | Notes |
| --- | --- | --- | --- |
| RunPod | `runpodctl` + API | managed instances | community (cheap) / secure pools, templates |
| Vast.ai | `vastai` | marketplace | cheapest lane; search live before every deploy |
| SaladCloud | REST API | containers on distributed GPUs | batch pricing — the economic outlier; bring your own image |
| Modal | `modal` | serverless | zero idle cost, cold starts |
| Lambda | REST API | premium on-demand | no egress fees; clusters need commitment |
| Prime | `prime` | decentralized marketplace | dynamic pricing, spot, parallel bids |

New providers don't need a new release: if its CLI is agent-friendly, the
provider-adapters skill teaches the agent how to operate it.

## Using the same skills with Claude Code (no Pi)

The repo ships a parallel skill set in `claude-skills/` for people who don't
run Pi — same knowledge, adapted to bash-only operation (no `gpu_*` tools),
sharing the same `.pi/gpu` JSON registry so Pi and Claude users can operate
identical infrastructure:

```bash
cp -r claude-skills/* /path/to/your/project/.claude/skills/
```

Claude Code picks them up automatically (gpu-setup, gpu-onboarding, gpu-ops,
comfyui, model-deployment, video-models, provider-adapters). The onboarding
skill walks a new Claude user through the same H3 economics card.

## Architecture

See `docs/ARCHITECTURE.md` (the core abstraction is the *deployment*, not the
provider) and `docs/REGISTRY.md` (state file schemas).

```
                Pi Agent
                    │
          video-factory extension
                    │
           provider capability tables
        ┌──────────┼──────────┬──────────┐
        │          │          │          │
     RunPod     Vast.ai    Modal     Lambda/Prime
        │          │          │          │
     CLI/API    CLI/API     CLI        API
```

## The spend policy (read this)

Extensions run arbitrary code — this one executes provider CLIs and **spends
real money**. The trust boundary is `.pi/gpu/policy.json`:

```json
{ "ceiling_per_job_usd": 5, "ceiling_daily_usd": 40, "ceiling_monthly_usd": 400, "confirm_above_usd": 1, "idle_shutdown_after_min": 30 }
```

Provisioning above `confirm_above_usd` always asks you in the UI, and ceilings
cap what the agent may do without checking in. Adjust with `gpu_policy` or
`/gpu policy`. Review this package's source before installing — it's yours.

## Development

```bash
npm install          # dev deps (typescript, pi types)
npx tsc --noEmit     # typecheck
pi -e .              # load the extension from this dir in a scratch session
```

## License

MIT
