> ## Documentation Index
> Fetch the complete documentation index at: https://haiprotocol.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Installation

> Install and set up the HAIP CLI

<Note>
  **New protocol version released**: This page may contain outdated information.
</Note>

The HAIP CLI can be installed and used in multiple ways. Choose the method that best fits your environment and requirements.

## Prerequisites

<CardGroup cols={3}>
  <Card title="Node.js" icon="code">
    Version 20.0.0 or higher
  </Card>

  <Card title="npm" icon="box">
    Version 9.0.0 or higher
  </Card>

  <Card title="Git" icon="code-branch">
    For cloning the repository
  </Card>
</CardGroup>

## Method 1: From Source (Recommended)

<Steps>
  <Step title="Clone the Repository">
    ```bash git clone https://github.com/haiprotocol/haip-cli.git cd haip-cli theme={null}
    ```
  </Step>

  <Step title="Install Dependencies">`bash npm install `</Step>
  <Step title="Build the Project">`bash npm run build `</Step>

  <Step title="Verify Installation">
    `bash node dist/index.js --help ` You should see the HAIP CLI banner and
    help information.
  </Step>
</Steps>

### Optional: Install Globally

```bash theme={null}
# Link globally (requires sudo on some systems)
npm link

# Test global installation
haip --help
```

## Method 2: From NPM

<Note>**Available Now**: The HAIP CLI is available on npm as `@haip/cli`.</Note>

[![npm version](https://badge.fury.io/js/%40haip%2Fcli.svg)](https://badge.fury.io/js/%40haip%2Fcli)
[![npm downloads](https://img.shields.io/npm/dm/@haip/cli)](https://www.npmjs.com/package/@haip/cli)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

```bash theme={null}
# Install globally from NPM
npm install -g @haip/cli

# Verify installation
haip --help
```

## Method 3: Docker

<Note>
  **Docker**: Docker images will be available on Docker Hub as `haip/cli` in the
  future.
</Note>

### Pull the Image

```bash theme={null}
docker pull haip/cli:latest
```

### Run the Container

```bash theme={null}
# Run with interactive terminal
docker run -it haip/cli:latest --help

# Run with volume mount for configuration
docker run -it -v $(pwd):/workspace haip/cli:latest health
```

## Development Setup

### Prerequisites for Development

* **Node.js** 20.0.0 or higher
* **npm** 9.0.0 or higher
* **TypeScript** 5.0.0 or higher
* **Git** for version control

### Development Installation

```bash theme={null}
# Clone the repository
git clone https://github.com/haiprotocol/haip-cli.git
cd haip-cli

# Install dependencies
npm install

# Build the project
npm run build

# Run tests
npm test

# Run with coverage
npm run test:coverage

# Lint code
npm run lint

# Fix linting issues
npm run lint:fix
```

### Development Mode

```bash theme={null}
# Start in development mode (watch for changes)
npm run dev

# Link for global testing
npm link
```

## Verification

After installation, verify that the CLI is working correctly:

### 1. Check Version

```bash theme={null}
node dist/index.js version
```

Expected output:

```
HAIP CLI v1.0.0
Human-Agent Interaction Protocol Command Line Interface
https://github.com/haiprotocol/haip-cli
```

### 2. Check System Information

```bash theme={null}
node dist/index.js info
```

Expected output:

```
HAIP CLI System Information
────────────────────────────────────────
Node.js: v20.11.0
Platform: darwin
Architecture: arm64
HAIP Version: 1.1.2
CLI Version: 1.0.0
```

### 3. Check Help System

```bash theme={null}
node dist/index.js --help
```

You should see the ASCII art banner and complete command listing.

### 4. Test Commands

```bash theme={null}
# Test health command
node dist/index.js health --help

# Test send command
node dist/index.js send --help

# Test monitor command
node dist/index.js monitor --help
```

## Configuration

### Environment Variables

The CLI can be configured using environment variables:

```bash theme={null}
# Server configuration
export HAIP_DEFAULT_URL=ws://localhost:8080
export HAIP_DEFAULT_TRANSPORT=websocket
export HAIP_DEFAULT_TOKEN=your-jwt-token

# Connection settings
export HAIP_TIMEOUT=10000
export HAIP_RECONNECT_ATTEMPTS=3
export HAIP_RECONNECT_DELAY=1000

# Output settings
export HAIP_VERBOSE=false
export HAIP_COLOR=true
```

### Configuration File (Future Enhancement)

Create a configuration file for persistent settings:

```bash theme={null}
# Create config directory
mkdir -p ~/.haip

# Create configuration file
cat > ~/.haip/config.json << EOF
{
  "defaultUrl": "ws://localhost:8080",
  "defaultTransport": "websocket",
  "timeout": 10000,
  "reconnectAttempts": 3,
  "verbose": false,
  "color": true
}
EOF
```

## Troubleshooting

### Common Issues

#### Permission Denied

```bash theme={null}
# If you get permission errors when linking globally
sudo npm link

# Or use npx to run without global installation
npx haip --help
```

#### Node Version Issues

```bash theme={null}
# Check your Node.js version
node --version

# If version is too old, update Node.js
# Using nvm (Node Version Manager)
nvm install 16
nvm use 16

# Or download from https://nodejs.org/
```

#### Build Errors

```bash theme={null}
# Clean and rebuild
npm run clean
npm install
npm run build

# Check TypeScript errors
npx tsc --noEmit
```

#### Test Failures

```bash theme={null}
# Run tests with verbose output
npm test -- --verbose

# Run specific test suites
npm test -- --testNamePattern="utils"
```

### Getting Help

If you encounter issues:

1. **Check the logs** - Run with verbose output: `node dist/index.js --verbose`
2. **Check Node.js version** - Ensure you're using Node.js 16+
3. **Check dependencies** - Run `npm install` to ensure all dependencies are installed
4. **Check TypeScript** - Run `npx tsc --noEmit` to check for type errors
5. **Check tests** - Run `npm test` to ensure everything is working

## Next Steps

* [Quick Start](/cli/quickstart) - Get up and running quickly
* [Command Reference](/cli/commands) - Learn about available commands
* [Configuration](/cli/configuration) - Configure the CLI
* [Examples](/cli/examples) - See usage examples
