# struere deploy

> Deploy all resources to production

The `deploy` command syncs all local resource definitions directly to the **production** environment.

## Usage

```bash
bunx struere deploy
bunx struere deploy --dry-run
bunx struere deploy --force
bunx struere deploy --json
bunx struere deploy --verbose
```

## Flags

| Flag | Description |
|------|-------------|
| `--dry-run` | Show what would be deployed without making any changes |
| `--force` | Skip destructive sync confirmation prompts |
| `--json` | Output results as JSON |
| `-v, --verbose` | Show detailed resource information (loaded counts, per-resource sync results, timing) |

## What It Does

The deploy command auto-regenerates the `.struere/` virtual module shim, loads all resource definitions from your local directories, and validates cross-resource references before syncing. Validation checks that router agent references match loaded agents, trigger entity type references match loaded entity types, and warns when agents use tools that require integration configuration (whatsapp, calendar, airtable, email, payment). Errors block the deploy; warnings display but allow it to continue. After validation, it builds a sync payload and sends it directly to the production environment via `syncOrganization`. It syncs agents, data types, roles, triggers, routers, custom tools, and fixtures.

If any resources exist remotely but not locally, the command warns about deletions and asks for confirmation before proceeding (unless `--force` is used).

## Development vs Production

Struere enforces full environment isolation between development and production:

| Aspect | `struere dev` | `struere deploy` |
|--------|---------------|------------------|
| Target environment | `development` | `production` |
| Data isolation | Development data, threads, events | Production data, threads, events |
| API keys | Development keys only | Production keys only |
| Source | Local files | Local files |

When you run `struere dev`, all synced resources are created in the development environment. When you run `struere deploy`, the same local files are synced directly to production.

## Deployment Flow

```
Local files ──[struere dev]────► Development environment

Local files ──[struere deploy]─► Production environment
```

Both commands read from local files. The `deploy` command does not promote from development — it syncs local definitions directly to production.

## Dry Run

Use `--dry-run` to preview what would be deployed:

```bash
bunx struere deploy --dry-run
```

This lists all agents, data types, roles, eval suites, and any resources that would be deleted, without making changes.

## JSON Output

Use `--json` for machine-readable output:

```bash
bunx struere deploy --json
```

Returns a JSON object with `success`, `environment`, and per-resource breakdowns of `created`, `updated`, and `deleted` slugs.

## Environment Scoping

The following resources are scoped per environment:

- Agent configurations (model, system prompt, tools)
- Data types and data
- Roles, policies, scope rules, and field masks
- Threads and messages
- Events and executions
- Automation runs
- API keys

Agents themselves (name, slug, description) are shared across environments — only their configurations are environment-specific.

## API Key Environments

API keys carry an `environment` field. When an API request arrives, the environment is extracted from the API key and threaded through the entire request:

- Config lookup uses the key's environment
- Threads are created in that environment
- Actor context carries the environment
- Tool execution respects environment boundaries
- Events are logged with the environment

A development API key cannot access production data, and vice versa.

## Production Checklist

Before deploying, verify:

1. **Test in development** — Use `struere dev` and development API keys to test your agents thoroughly
2. **Review with `struere status`** — Compare your local definitions against the remote state
3. **Check permissions** — Ensure roles and policies are correctly configured for production use
4. **Verify API keys** — Create production API keys in the dashboard for your applications
