npm package: @fold-run/cli
Description: CLI for fold.run — deploy tools for your AI agent, manage secrets, and configure workflows
Latest version: 0.3.0

# @fold-run/cli

Command-line interface for [fold.run](https://fold.run) — deploy serverless functions with automatic TypeScript bundling, secrets management, and AI-powered code generation.

## Install

```bash
npm install -g @fold-run/cli
```

Requires Node.js 20+.

## Quick start

```bash
# Authenticate
fold login

# Scaffold a new project
fold init my-function

# Start local dev server
cd my-function
fold dev

# Deploy
fold deploy
```

## Commands

### Getting started

| Command            | Description                                             |
| ------------------ | ------------------------------------------------------- |
| `fold init [name]` | Scaffold a new project with `worker.ts` and `fold.json` |
| `fold login`       | Authenticate via email/password or API token            |
| `fold logout`      | Remove saved credentials                                |
| `fold whoami`      | Show current login info (API, tenant, role)             |
| `fold status`      | Show config and deployed functions                      |

### Deploy & manage

| Command                                 | Description                                             |
| --------------------------------------- | ------------------------------------------------------- |
| `fold deploy [file]`                    | Deploy a function (reads `fold.json` if no file given)  |
| `fold dev [file]`                       | Start a local dev server on port 8000                   |
| `fold functions`                        | List deployed functions                                 |
| `fold delete <function-id>`             | Delete a deployed function                              |
| `fold rollback <function-id> <version>` | Rollback to a previous version                          |
| `fold logs`                             | View activation logs (`-F` to follow, `-v` for details) |

### Configuration

| Command                             | Description                                        |
| ----------------------------------- | -------------------------------------------------- |
| `fold secrets set <name>`           | Create or update a tenant secret (masked input)    |
| `fold secrets list`                 | List secrets (names only)                          |
| `fold secrets delete <id>`          | Delete a secret                                    |
| `fold env set <name> -f <fn-id>`    | Set a function environment variable (masked input) |
| `fold env list -f <fn-id>`          | List function env vars                             |
| `fold env delete <name> -f <fn-id>` | Delete a function env var                          |

### Integrations

| Command                                | Description                  |
| -------------------------------------- | ---------------------------- |
| `fold webhooks list`                   | List webhook endpoints       |
| `fold webhooks create <fn-id> <path>`  | Create a webhook endpoint    |
| `fold webhooks delete <id>`            | Delete a webhook endpoint    |
| `fold schedules list`                  | List scheduled triggers      |
| `fold schedules create <fn-id> <cron>` | Create a cron trigger        |
| `fold schedules toggle <fn-id>`        | Enable or disable a schedule |
| `fold schedules delete <fn-id>`        | Delete a schedule            |

### AI & templates

| Command                                 | Description                                           |
| --------------------------------------- | ----------------------------------------------------- |
| `fold create-tool <name> <description>` | Generate and deploy an MCP tool from natural language |
| `fold tools list`                       | List deployed MCP tools                               |
| `fold templates list`                   | Browse the template marketplace                       |
| `fold templates get <name>`             | View a template's details and code                    |
| `fold templates deploy <name>`          | Deploy a function from a template                     |

## fold.json

The project manifest configures defaults for `fold deploy`:

```json
{
  "name": "my-function",
  "entrypoint": "function.ts",
  "tenant_id": "tenant-abc",
  "intent": {
    "trigger": "http",
    "bindings": ["kv", "db"]
  }
}
```

| Field             | Description                                              |
| ----------------- | -------------------------------------------------------- |
| `name`            | Function name (used if `--name` not passed)              |
| `entrypoint`      | File to deploy (used if no file argument given)          |
| `tenant_id`       | Default tenant (overridden by `--tenant` flag or config) |
| `intent.trigger`  | Trigger type hint                                        |
| `intent.bindings` | Resource bindings (`kv`, `storage`, `db`, `queue`, `ai`) |

## Global options

| Flag            | Description                                                                                   |
| --------------- | --------------------------------------------------------------------------------------------- |
| `--json`        | Output results as JSON (works with `functions`, `logs`, `deploy`, `secrets list`, `env list`) |
| `-V, --version` | Print version                                                                                 |
| `-h, --help`    | Show help                                                                                     |

## Authentication

Credentials are stored in `~/.config/fold/config.json` (mode `0600`). The CLI supports two auth methods:

- **Email/password** — authenticates via the API and stores a JWT
- **API token** — direct token input for CI/automation

The CLI checks JWT expiry before each command and exits early if the token has expired.

## TypeScript bundling

`.ts` and `.tsx` files are automatically bundled with esbuild before deploy:

- Target: `esnext`, format: ESM
- Tree-shaking and minification enabled
- `cloudflare:*` imports kept external
- Skip with `--no-bundle` to deploy raw JS

## Development

```bash
# Install dependencies
pnpm install

# Build
pnpm build

# Watch mode
pnpm dev

# Run tests
pnpm test

# Single test file
pnpm test src/test/deploy.test.ts

# Coverage
pnpm test -- --coverage

# Type check
pnpm typecheck
```

This project follows TDD — write failing tests first, then implement. Tests live in `src/test/`. Coverage thresholds: 50% lines/functions/statements, 40% branches.

## License

MIT