npm package: @noalia/code-titan
Description: Command-line interface for CodeTitan code analysis
Author: Noalia
Latest version: 1.0.2

# CodeTitan CLI

Command-line interface for CodeTitan - AI-powered code analysis with **TITAN MODE™** 8-level autonomy.

## Installation

```bash
npm install -g @codetitan/cli
```

## Quick Start

1. **Login** with your API key:
```bash
codetitan login
```

2. **Analyze** your code:
```bash
codetitan analyze ./src --level 5
```

## Global Options

These options work with all commands:

| Option | Description |
|--------|-------------|
| `-q, --quiet` | Suppress non-essential output (ideal for CI) |
| `--no-color` | Disable colored output |
| `-V, --version` | Display version number |
| `-h, --help` | Display help for command |

## Commands

### Authentication

#### `codetitan login`
Authenticate with your API key. Your key will be stored securely in `~/.config/codetitan/config.json`.

```bash
codetitan login
# Prompts for API key
```

#### `codetitan logout`
Remove saved credentials from your system.

```bash
codetitan logout
```

#### `codetitan whoami`
Display information about the currently authenticated user.

```bash
codetitan whoami
```

### Code Analysis

#### `codetitan analyze [path]`
Analyze code at the specified path.

**Options:**
- `-l, --level <number>` - Analysis level (1-8), default: 4
- `-f, --format <type>` - Output format (json|markdown|console), default: console
- `-o, --output <file>` - Save output to file
- `-u, --upload` - Upload report to CodeTitan Cloud
- `--single-file` - Analyze only the target file (faster)
- `--with-context` - Analyze file with full project context

**Examples:**
```bash
# Basic analysis
codetitan analyze

# Analyze specific path with level 8
codetitan analyze ./src --level 8

# Output as JSON and save to file
codetitan analyze --format json --output results.json

# Maximum analysis level
codetitan analyze --level 8 --format markdown
```

### Project Management

#### `codetitan projects list`
List all your projects.

```bash
codetitan projects list
```

#### `codetitan projects create`
Create a new project.

**Options:**
- `-n, --name <name>` - Project name
- `-d, --description <description>` - Project description
- `-r, --repo <url>` - Repository URL

**Examples:**
```bash
# Interactive creation
codetitan projects create

# Create with options
codetitan projects create --name "My App" --description "Production app" --repo "https://github.com/user/repo"
```

#### `codetitan projects delete <id>`
Delete a project by ID.

```bash
codetitan projects delete abc-123-def
```

### API Key Management

#### `codetitan keys list`
List all your API keys.

```bash
codetitan keys list
```

#### `codetitan keys create`
Create a new API key.

**Options:**
- `-n, --name <name>` - Key name

**Examples:**
```bash
# Interactive creation
codetitan keys create

# Create with name
codetitan keys create --name "Production Key"
```

**⚠️ Important:** API keys are shown in full only once upon creation. Save them securely!

#### `codetitan keys revoke <id>`
Revoke an API key by ID.

```bash
codetitan keys revoke abc-123-def
```

### Usage Statistics

#### `codetitan usage`
View your usage statistics for the current billing period.

**Options:**
- `-f, --format <type>` - Output format (table|json), default: table

**Examples:**
```bash
# View usage as table
codetitan usage

# Export usage as JSON
codetitan usage --format json
```

## Configuration

The CLI stores configuration in `~/.config/codetitan/config.json` (or platform equivalent).

**Configuration options:**
- `apiKey` - Your API key
- `apiEndpoint` - API endpoint URL (default: https://api.codetitan.dev)
- `defaultLevel` - Default analysis level (default: 4)
- `defaultFormat` - Default output format (default: console)

## TITAN MODE™ Levels

| Level | Name | Capability |
|-------|------|------------|
| 1 | **TITAN BASELINE** | Core static analysis, AST parsing, pattern matching |
| 2 | **TITAN ACCELERATED** | Parallel processing, smart caching, incremental analysis |
| 3 | **TITAN COMPREHENSIVE** | 5-domain analysis, cross-file analysis, dependency graphs |
| 4 | **TITAN DEEP ANALYSIS** | Semantic analysis, data flow tracking, taint analysis |
| 5 | **TITAN REMEDIATION** | Auto-fix generation, multi-AI verification, safe refactoring |
| 6 | **TITAN INTELLIGENCE** | ML-powered analysis, pattern recognition, adaptive thresholds |
| 7 | **TITAN COLLECTIVE** | Cross-project learning, industry benchmarking, trend prediction |
| 8 | **TITAN SENTINEL** | Self-healing infrastructure, autonomous incident response |

**Subscription Access:**
- **Free**: Levels 1-3 (Baseline → Comprehensive)
- **Starter ($29/mo)**: Levels 1-5 (+ Deep Analysis & Remediation)
- **Professional ($99/mo)**: Levels 1-8 (Full Titan Mode™)

## Output Formats

### Console (default)
Human-readable output with colors and formatting.

### JSON
Machine-readable JSON output for integration with tools.

```bash
codetitan analyze --format json | jq .
```

### Markdown
Formatted markdown report for documentation.

```bash
codetitan analyze --format markdown --output ANALYSIS.md
```

## Error Codes

- **401 Unauthorized**: Invalid or missing API key
- **403 Forbidden**: Insufficient permissions or subscription tier
- **429 Too Many Requests**: Rate limit exceeded
- **500 Internal Server Error**: Server error (please report)

## Getting an API Key

1. Visit [codetitan.dev/dashboard/api-keys](https://codetitan.dev/dashboard/api-keys)
2. Click "Create API Key"
3. Give it a name and copy the key
4. Run `codetitan login` and paste your key

## Subscription Tiers

| Tier | Price | API Calls | Analysis Levels | Projects |
|------|-------|-----------|-----------------|----------|
| Free | $0/mo | 100/month | 1-3 | 1 |
| Starter | $29/mo | 1,000/month | 1-5 | 10 |
| Professional | $99/mo | 10,000/month | 1-8 | Unlimited |

Upgrade at [codetitan.dev/dashboard/billing](https://codetitan.dev/dashboard/billing)

## Examples

### CI/CD Integration

```yaml
# .github/workflows/code-quality.yml
name: Code Quality
on: [push, pull_request]
jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
      - run: npm install -g @codetitan/cli
      - run: echo "${{ secrets.CODETITAN_API_KEY }}" | codetitan login
      - run: codetitan analyze --level 6 --format json --output analysis.json
      - uses: actions/upload-artifact@v3
        with:
          name: analysis-results
          path: analysis.json
```

### Pre-commit Hook

```bash
#!/bin/bash
# .git/hooks/pre-commit
codetitan analyze --level 4 || {
  echo "Code analysis failed. Fix issues before committing."
  exit 1
}
```

### Scheduled Analysis

```bash
# Crontab: Run daily at 2 AM
0 2 * * * cd /path/to/project && codetitan analyze --level 5 --output daily-report.md
```

## Support

- **Documentation**: [docs.codetitan.dev](https://docs.codetitan.dev)
- **Dashboard**: [codetitan.dev/dashboard](https://codetitan.dev/dashboard)
- **Support**: [codetitan.dev/contact](https://codetitan.dev/contact)
- **GitHub**: [github.com/codetitan/cli](https://github.com/codetitan/cli)

## License

MIT © CodeTitan