|
| 1 | +# CodeAnt CLI |
| 2 | + |
| 3 | +A command-line tool for code review and security scanning. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install -g codeant-cli |
| 9 | +``` |
| 10 | + |
| 11 | +Or run locally: |
| 12 | + |
| 13 | +```bash |
| 14 | +git clone https://github.com/codeantai/codeant-cli.git |
| 15 | +cd codeant-cli |
| 16 | +npm install |
| 17 | +npm link |
| 18 | +``` |
| 19 | + |
| 20 | +## Quick Start |
| 21 | + |
| 22 | +```bash |
| 23 | +# Login to CodeAnt |
| 24 | +codeant login |
| 25 | + |
| 26 | +# Scan staged files for secrets |
| 27 | +codeant secrets |
| 28 | +``` |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +```bash |
| 33 | +codeant <command> [options] |
| 34 | +``` |
| 35 | + |
| 36 | +### Commands |
| 37 | + |
| 38 | +#### `login` |
| 39 | + |
| 40 | +Authenticate with CodeAnt. Opens a browser window for login. |
| 41 | + |
| 42 | +```bash |
| 43 | +codeant login |
| 44 | +``` |
| 45 | + |
| 46 | +#### `logout` |
| 47 | + |
| 48 | +Log out from CodeAnt. |
| 49 | + |
| 50 | +```bash |
| 51 | +codeant logout |
| 52 | +``` |
| 53 | + |
| 54 | +#### `secrets` |
| 55 | + |
| 56 | +Scan your code for exposed secrets, API keys, and credentials. |
| 57 | + |
| 58 | +```bash |
| 59 | +codeant secrets [options] |
| 60 | +``` |
| 61 | + |
| 62 | +**Options:** |
| 63 | + |
| 64 | +| Option | Description | |
| 65 | +|--------|-------------| |
| 66 | +| `--staged` | Scan only staged files (default) | |
| 67 | +| `--all` | Scan all changed files compared to base branch | |
| 68 | +| `--uncommitted` | Scan all uncommitted changes | |
| 69 | +| `--last-commit` | Scan files from the last commit | |
| 70 | +| `--fail-on <level>` | Fail only on HIGH, MEDIUM, or all (default: HIGH) | |
| 71 | +| `--include <patterns>` | Comma-separated glob patterns to include files | |
| 72 | +| `--exclude <patterns>` | Comma-separated glob patterns to exclude files | |
| 73 | + |
| 74 | +**Examples:** |
| 75 | + |
| 76 | +```bash |
| 77 | +# Scan staged files (default) |
| 78 | +codeant secrets |
| 79 | + |
| 80 | +# Scan all changed files |
| 81 | +codeant secrets --all |
| 82 | + |
| 83 | +# Scan last commit |
| 84 | +codeant secrets --last-commit |
| 85 | + |
| 86 | +# Only fail on HIGH confidence secrets (default) |
| 87 | +codeant secrets --fail-on HIGH |
| 88 | + |
| 89 | +# Fail on HIGH and MEDIUM confidence secrets |
| 90 | +codeant secrets --fail-on MEDIUM |
| 91 | + |
| 92 | +# Fail on all secrets (except false positives) |
| 93 | +codeant secrets --fail-on all |
| 94 | + |
| 95 | +# Filter files using glob patterns |
| 96 | +codeant secrets --include '**/*.js' # Only JS files |
| 97 | +codeant secrets --exclude 'node_modules/**,*.test.js' # Exclude patterns |
| 98 | +codeant secrets --include 'src/**' --exclude '*.test.*' # Combine both |
| 99 | +``` |
| 100 | + |
| 101 | +**File Filtering:** |
| 102 | + |
| 103 | +Use `--include` and `--exclude` with glob patterns to filter files: |
| 104 | +- `*` matches any characters except `/` |
| 105 | +- `**` matches any characters including `/` |
| 106 | +- `*.{js,ts}` matches multiple extensions |
| 107 | +- Comma-separated for multiple patterns: `--exclude 'test/**,dist/**'` |
| 108 | + |
| 109 | +**Exit codes:** |
| 110 | +- `0` - No blocking secrets found (or only false positives) |
| 111 | +- `1` - Secrets detected that match the `--fail-on` threshold |
| 112 | + |
| 113 | +**Confidence Levels:** |
| 114 | +- `HIGH` - High confidence, likely a real secret |
| 115 | +- `MEDIUM` - Medium confidence, may need review |
| 116 | +- `FALSE_POSITIVE` - Detected but likely not a real secret (always ignored) |
| 117 | + |
| 118 | +#### `set-base-url <url>` |
| 119 | + |
| 120 | +Set a custom API base URL. |
| 121 | + |
| 122 | +```bash |
| 123 | +codeant set-base-url https://api.example.com |
| 124 | +``` |
| 125 | + |
| 126 | +#### `get-base-url` |
| 127 | + |
| 128 | +Show the current API base URL and its source. |
| 129 | + |
| 130 | +```bash |
| 131 | +codeant get-base-url |
| 132 | +``` |
| 133 | + |
| 134 | +### Global Options |
| 135 | + |
| 136 | +```bash |
| 137 | +codeant --version # Show version |
| 138 | +codeant --help # Show help |
| 139 | +``` |
| 140 | + |
| 141 | +## Configuration |
| 142 | + |
| 143 | +Config is stored in `~/.codeant/config.json`. |
| 144 | + |
| 145 | +You can also use environment variables: |
| 146 | + |
| 147 | +| Variable | Description | |
| 148 | +|----------|-------------| |
| 149 | +| `CODEANT_API_URL` | API base URL (overrides config) | |
| 150 | +| `CODEANT_API_TOKEN` | Authentication token (overrides config) | |
| 151 | + |
| 152 | +**Priority order:** |
| 153 | +1. Environment variables (highest) |
| 154 | +2. Config file (`~/.codeant/config.json`) |
| 155 | +3. Default values |
| 156 | + |
| 157 | +## Git Hooks |
| 158 | + |
| 159 | +Use CodeAnt as a pre-commit hook to prevent secrets from being committed. |
| 160 | + |
| 161 | +### Manual Setup |
| 162 | + |
| 163 | +Create `.git/hooks/pre-commit`: |
| 164 | + |
| 165 | +```bash |
| 166 | +#!/bin/sh |
| 167 | +codeant secrets |
| 168 | +``` |
| 169 | + |
| 170 | +Make it executable: |
| 171 | + |
| 172 | +```bash |
| 173 | +chmod +x .git/hooks/pre-commit |
| 174 | +``` |
| 175 | + |
| 176 | +### With Husky |
| 177 | + |
| 178 | +```bash |
| 179 | +npx husky add .husky/pre-commit "codeant secrets" |
| 180 | +``` |
| 181 | + |
| 182 | +### With lefthook |
| 183 | + |
| 184 | +Add to `lefthook.yml`: |
| 185 | + |
| 186 | +```yaml |
| 187 | +pre-commit: |
| 188 | + commands: |
| 189 | + secrets: |
| 190 | + run: codeant secrets |
| 191 | +``` |
| 192 | +
|
| 193 | +## Example Output |
| 194 | +
|
| 195 | +### Secrets Found (blocking) |
| 196 | +
|
| 197 | +``` |
| 198 | +✗ 2 secret(s) found! |
| 199 | + |
| 200 | +src/config.js |
| 201 | + Line 5: AWS Access Key (HIGH) |
| 202 | + Line 12: API Key (HIGH) |
| 203 | + |
| 204 | +Remove secrets before committing. |
| 205 | +``` |
| 206 | + |
| 207 | +### Only False Positives (non-blocking) |
| 208 | + |
| 209 | +``` |
| 210 | +⚠ 1 potential secret(s) found (ignored) |
| 211 | +
|
| 212 | +Ignored (false positives): |
| 213 | + src/example.js |
| 214 | + Line 10: Generic Secret (FALSE_POSITIVE) |
| 215 | +
|
| 216 | +✓ Commit allowed (only false positives found) |
| 217 | +``` |
| 218 | + |
| 219 | +### No Secrets |
| 220 | + |
| 221 | +``` |
| 222 | +✓ No secrets found |
| 223 | +``` |
| 224 | + |
| 225 | +## Development |
| 226 | + |
| 227 | +```bash |
| 228 | +# Run locally |
| 229 | +node src/index.js secrets |
| 230 | + |
| 231 | +# Run with npm |
| 232 | +npm start secrets |
| 233 | + |
| 234 | +# Test different scan types |
| 235 | +node src/index.js secrets --last-commit |
| 236 | +node src/index.js secrets --all |
| 237 | +``` |
| 238 | + |
| 239 | +## License |
| 240 | + |
| 241 | +MIT |
0 commit comments