# @indemn/cli

CLI, MCP server, and Claude Code plugin for managing Indemn AI agents. Create, configure, evaluate, and chat with agents programmatically.

## Install

```bash
npm install -g @indemn/cli
```

## Authenticate

```bash
indemn login --env dev
# Enter your Indemn email and password
# MFA code will be sent to your email if enabled
```

This does a one-time Firebase login, generates a persistent API key, and saves it to `~/.indemn/config.json`. You won't need to log in again.

## Verify

```bash
indemn whoami          # shows your user, org, environment
indemn agents list     # lists your agents
```

## Quick Start

```bash
# Create an agent
indemn agents create --name "My Insurance Bot"

# Set its prompt
indemn config set <agent-id> --prompt "You are a helpful insurance assistant."

# Chat with it
indemn chat <agent-id>

# Run evaluations
indemn eval run <agent-id> --test-set <id> --rubric <id> --wait
```

## Command Reference

### Authentication
```bash
indemn login [--env dev|production]   # Authenticate via Firebase
indemn logout                          # Clear stored credentials
indemn whoami                          # Show current user/org/env
```

### Agent Management
```bash
indemn agents list [--json] [--limit N]
indemn agents get <id> [--json]
indemn agents create --name "..." [--channels WEB,VOICE]
indemn agents update <id> [--name] [--description] [--webhook-url]
indemn agents delete <id>
indemn agents clone <id>
```

### Configuration
```bash
indemn config get <agent-id> [--field prompt|greeting|model] [--json]
indemn config set <agent-id> [--prompt "..."] [--prompt-file path] [--model "..."]
```

### Functions
```bash
indemn functions list <agent-id> [--json]
indemn functions create <agent-id> --type rest_api --description "..."
indemn functions update <agent-id> <func-id> [--description "..."]
indemn functions delete <agent-id> <func-id>
indemn functions test <agent-id> <func-id>
indemn functions export <agent-id>
indemn functions import <agent-id> --url "..."
indemn functions master-list                    # list master function templates
indemn functions params list <agent-id> <func-id>
indemn functions params add <agent-id> <func-id> --name "..." --type string [--required]
indemn functions params update <agent-id> <func-id> <param-id> [--description "..."]
indemn functions params delete <agent-id> <func-id> <param-id>
```

### Knowledge Bases
```bash
indemn kb list [--json] [--limit N] [--page N]
indemn kb create --name "..." --type qna
indemn kb get <kb-id>
indemn kb update <kb-id> [--name "..."]
indemn kb delete <kb-id>
indemn kb data list <kb-id>
indemn kb data add <kb-id> --question "..." --answer "..."     # QnA data
indemn kb data add <kb-id> --source-url "https://..."          # URL scraping
indemn kb data add <kb-id> --file /path/to/file.pdf            # file upload
indemn kb link <agent-id> <kb-id> [kb-id...]
indemn kb unlink <agent-id> <kb-id>
indemn kb export <kb-id> [--format csv]
```

### Evaluations
```bash
indemn eval run <agent-id> --test-set <id> [--rubric <id>] [--wait] [--eval-model gpt-4o] [--limit N]
indemn eval list [--agent-id <id>] [--json] [--limit N]
indemn eval status <run-id> [--json]
indemn eval results <run-id> [--json]
indemn eval bot-context <agent-id> [--json]
```

### Rubrics & Test Sets
```bash
indemn rubric list [--agent-id <id>]
indemn rubric create --file rubric.json
indemn rubric get <id> [--revision N]
indemn rubric update <id> --file rubric.json
indemn rubric delete <id>
indemn rubric versions <id>

indemn testset list --agent-id <id>              # --agent-id required
indemn testset create --file testset.json
indemn testset get <id> [--revision N]
indemn testset update <id> --file testset.json
indemn testset delete <id>
indemn testset versions <id>
```

### Chat
```bash
indemn chat <agent-id> [--session <session-id>]           # interactive
indemn chat <agent-id> --message "Hello"                   # single message
```

### Models
```bash
indemn models                                              # list available LLM providers and models
```

### MCP Server
```bash
indemn mcp serve   # Start MCP server on stdio
```

## Claude Code Integration

### MCP Server (tools)

Add the MCP server so Claude Code can manage agents directly:

```bash
claude mcp add -s user \
  -e INDEMN_API_KEY=ind_dev_... \
  -e INDEMN_ENV=dev \
  -- indemn npx @indemn/cli mcp serve
```

Or add manually to your Claude Code MCP settings:
```json
{
  "indemn": {
    "command": "npx",
    "args": ["@indemn/cli", "mcp", "serve"],
    "env": {
      "INDEMN_API_KEY": "ind_dev_...",
      "INDEMN_ENV": "dev"
    }
  }
}
```

The MCP server exposes 55 tools: `list_agents`, `create_agent`, `set_prompt`, `run_evaluation`, `chat_with_agent`, etc.

### Plugin (skills)

Install the plugin to get workflow skills in Claude Code:

```bash
claude plugins marketplace add https://github.com/indemn-ai/indemn-cli
claude plugins install indemn-cli
```

| Skill | Purpose |
|-------|---------|
| `eval-orchestration` | Full evaluation lifecycle with directive allocation |
| `test-set-creation` | Design test sets with scenarios and diagnostics |
| `rubric-creation` | Create universal behavioral rubrics (3-6 rules) |
| `agent-setup` | End-to-end agent creation workflow |

## Global Flags

```bash
indemn --env dev agents list       # override environment for a single command
indemn agents list --json          # JSON output (available on most commands)
indemn agents list --limit 5       # limit results
indemn agents list --limit 5 --page 2  # pagination
```

## Environment Variables

| Variable | Description |
|----------|-------------|
| `INDEMN_API_KEY` | API key (alternative to `indemn login`) |
| `INDEMN_ENV` | Environment: `dev` or `production` (default: `dev`) |
| `INDEMN_ORG_ID` | Organization ID (alternative to config file) |

## Architecture

```
@indemn/cli
├── SDK (TypeScript API client)
│   ├── Copilot Server → Agents, Functions, KBs, Config
│   ├── Evaluations Service → Rubrics, Test Sets, Runs
│   └── Middleware → Chat via Socket.IO
├── CLI (Commander.js terminal interface)
├── MCP Server (55 tools for Claude Code)
└── Skills (workflow guides for Claude)
```

## Development

```bash
git clone https://github.com/indemn-ai/indemn-cli.git
cd indemn-cli
npm install
npm run build        # Compile TypeScript
npm run dev          # Watch mode
npm test             # Run tests
```

## License

MIT
