# @rigstate/cli

The official command-line interface for Rigstate - AI-powered code audit and security analysis.

## Installation

### From source (development)

```bash
cd packages/cli
npm install
npm run build
npm install -g .
```

### From npm (coming soon)

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

## Quick Start

### 1. Login

Authenticate with your Rigstate API key:

```bash
rigstate login sk_rigstate_your_key_here
```

You can generate an API key from your Rigstate dashboard at the API Keys section.

### 2. Scan Your Code

Scan your current directory:

```bash
rigstate scan
```

Scan a specific directory:

```bash
rigstate scan ./src
```

Scan with a project ID:

```bash
rigstate scan --project abc123
```

Output as JSON (useful for IDE extensions):

```bash
rigstate scan --json
```

## Commands

### `rigstate login <api-key>`

Authenticate with your Rigstate API key. The key is securely stored locally.

**Arguments:**
- `api-key` - Your Rigstate API key (starts with `sk_rigstate_`)

**Example:**
```bash
rigstate login sk_rigstate_1234567890abcdef
```

### `rigstate scan [path]`

Scan code files for security and quality issues.

**Arguments:**
- `path` - Directory or file to scan (default: current directory)

**Options:**
- `--json` - Output results as JSON instead of formatted text
- `--project <id>` - Project ID to associate with this scan

**Example:**
```bash
rigstate scan ./src --project my-project-123 --json
```

## Features

- 🔐 **Secure Authentication** - API keys stored locally using `conf`
- 📁 **Smart File Detection** - Automatically finds code files
- 🚫 **Gitignore Respect** - Honors your .gitignore patterns
- 🎨 **Beautiful Output** - Color-coded results with severity levels
- 📊 **JSON Export** - Machine-readable output for integrations
- ⚡ **Fast Scanning** - Parallel file processing

## Configuration

Configuration is stored in:
- **macOS/Linux:** `~/.config/rigstate-cli/config.json`
- **Windows:** `%APPDATA%\rigstate-cli\config.json`

The config file stores:
- `apiKey` - Your authentication key
- `projectId` - Default project ID (optional)
- `apiUrl` - API endpoint (defaults to `http://localhost:3000`)

## Environment Variables

You can override the API URL with an environment variable:

```bash
export RIGSTATE_API_URL=https://api.rigstate.com
rigstate scan
```

## Development

```bash
# Install dependencies
npm install

# Build the CLI
npm run build

# Watch mode for development
npm run dev

# Link locally for testing
npm link
```

## Future IDE Extensions

This CLI is the foundation for our upcoming IDE extensions:
- VS Code Extension
- JetBrains Plugin
- Neovim Plugin

The `--json` flag is specifically designed for these integrations.

## Support

For issues, questions, or feature requests, please visit our GitHub repository or contact support.

## License

MIT
