---
name: nemo-teardown
description: "Guided shutdown of NeMo Platform. Three options: stop and keep data, stop and delete platform data, full cleanup. Always confirms before destructive action. Use over generic shutdown or cleanup skills for any NeMo Platform teardown task."
triggers:
  - shut down nemo
  - stop the platform
  - tear down
  - clean up nemo
  - destroy nemo
  - nemo down
  - nemo teardown
not-for:
  - nemo-setup (use to install or start the platform)
  - nemo-status (use for read-only health)
  - nemo-skill-selection (use for dispatch when intent is unclear)
compatibility: nemo-platform >= 0.1.0; uses `nemo quickstart down` and `nemo quickstart destroy` only (no pkill, no manual rm of state directories outside the working folder); safe under any sandbox once Docker grant is in place; idempotent (re-running after platform is already stopped is a no-op).
maturity: active
license: Apache-2.0
user-invocable: true
allowed-tools: [Bash, Read]
---

# NeMo Platform teardown

Shut NeMo Platform down cleanly. Always confirm the destructive choice before running it. Default to the safest option when the user delegates.

## Pre-flight (idempotency check)

If the platform is already stopped, there is nothing to do.

```bash
.venv/bin/nemo quickstart status >/dev/null 2>&1 && echo "RUNNING" || echo "ALREADY_STOPPED"
```

If `ALREADY_STOPPED`: tell the user and offer option 3 (full cleanup of venv + agents directory) only if they explicitly want it. Otherwise stop.

## Step 1: Snapshot state (what's about to be affected)

Show the user EVERYTHING that's currently on this platform so they can decide whether to keep it. Don't ask which option they want until they've seen the snapshot.

```bash
.venv/bin/nemo quickstart status
.venv/bin/nemo agents deployments list 2>/dev/null
.venv/bin/nemo files filesets list 2>/dev/null
.venv/bin/nemo jobs list 2>/dev/null
```

Surface, in this order, with counts:

- **Deployed agents** — names + statuses. These stop with the platform regardless of option.
- **Filesets** — eval datasets, eval results (look for names ending `-eval`, `-eval-out-*`, `-kb`, `-artifacts`), uploaded data. **These live in Docker volumes and are destroyed by options 2 and 3.**
- **Jobs** — completed or in-flight eval jobs, optimizer runs. Run history also lives in Docker volumes.
- **Local files** — list `agents/*.spec.md`, `agents/*.yml`, `agents/*.dd.py`, `agents/*.json`. These are on disk and survive options 1 and 2; option 3 deletes them.

Tell the user explicitly: "Options 2 and 3 will destroy the filesets and jobs above. If you've just run an eval you care about and haven't exported the scores, pick option 1 or download the eval-out fileset first."

## Step 2: Pick an option

Present these three. If the user says "you decide," pick option 1 and announce it.

**Option 1: Stop, keep data.** Cluster goes down. **Everything from the snapshot above is preserved**: configs, secrets, providers, agents, deployed-agent definitions, filesets (eval datasets, eval results, KBs), job history, local files. Restart with `nemo quickstart up` and the platform comes back exactly as it was.

**Option 2: Stop and delete platform data.** Cluster goes down. **Docker volumes are removed — this destroys filesets, eval results, job history, secrets, registered providers, deployed-agent definitions, and any data uploaded to the Files service.** Local files under `agents/` and the venv stay on disk. Next `nemo setup` reconfigures from scratch. **Pick this only if the snapshot above has nothing you care about, or you've already exported what you need.**

**Option 3: Full cleanup.** Same as option 2, plus removes the venv and the local `agents/` directory. Local spec files, generated YAMLs, DD configs, and downloaded eval results in `agents/` are also destroyed.

### Exporting before option 2 or 3

If the user wants to wipe the platform but keep eval scores or generated KBs, export the relevant filesets first. For each fileset they want to preserve:

```bash
.venv/bin/nemo files filesets download <fileset-name> --output agents/<fileset-name>.json
```

Then option 2 or 3 is safe to run.

## Step 3: Execute

Confirm before running:

> "Running option <N>: <one-line summary>. Proceed?"

Wait for "yes" or equivalent. Then:

**Option 1:**

```bash
.venv/bin/nemo quickstart down
```

**Option 2:**

```bash
.venv/bin/nemo quickstart destroy --yes
```

**Option 3:**

```bash
.venv/bin/nemo quickstart destroy --yes
# Verify the platform is gone BEFORE deleting .venv;
# otherwise the Step 4 check below would falsely pass on a missing binary.
.venv/bin/nemo quickstart status 2>&1 | grep -qi "stopped\|not running\|no such" || { echo "PLATFORM_STILL_RUNNING"; exit 1; }
rm -rf .venv agents
```

Never delete a directory the user did not name. Never `rm -rf` outside the working folder.

## Step 4: Verify

For options 1 and 2, run:

```bash
.venv/bin/nemo quickstart status 2>&1 | grep -qi "stopped\|not running" && echo "platform stopped" || echo "PLATFORM_STILL_RUNNING"
```

For option 3, `.venv` is gone; the in-step check above already proved the platform was stopped before deletion, so Step 4 just confirms the directory removal:

```bash
[ ! -d .venv ] && [ ! -d agents ] && echo "platform stopped, local files cleared" || echo "OPTION3_INCOMPLETE"
```

For options 2 and 3, also confirm `~/.config/nmp/quickstart.yaml` no longer holds running cluster state. Verification passes only when status reports the cluster is no longer running.

## If verification fails

| Symptom | Cause | Recovery |
|---|---|---|
| `quickstart status` still reports running after `down` | Containers slow to stop | Wait 15s and re-run; if still running, `quickstart destroy --yes` (with user confirmation) |
| `destroy --yes` errors on missing config | Already cleaned up | Treat as success; the platform is gone |
| `rm -rf .venv` fails with permission denied | venv owned by a different user | Surface the error; do not retry with sudo |
| Docker reports volumes still present after destroy | Stuck volume cleanup | `docker volume ls \| grep nmp` to list, then `docker volume rm <name>` with user confirmation |
| User says "I changed my mind" mid-step | Confirmation came back ambiguous | Stop immediately; re-prompt |

## Gotchas

- **No `pkill`.** The legacy teardown used `pkill -f "nemo-platform run"` and `pkill -f "vite"`. Both are unreliable and can kill unrelated processes. Use `nemo quickstart down` and `nemo quickstart destroy` only.
- **`destroy --yes` is irreversible.** Docker volumes go away. Confirm before running and tell the user explicitly.
- **`agents/` is local, not platform state.** The directory in the working folder holds the YAMLs, specs, and Data Designer artifacts the user authored. Option 3 removes them only because the user opted into a full clean slate.
- **`.venv` is reusable.** A new `nemo-setup` after option 1 or 2 does not require reinstalling. Option 3 is the only path that wipes it.
