@ateriss_/aiv-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +954 -0
- package/dist/index.js +318 -0
- package/package.json +41 -0
- package/src/agents/architecture.ts +32 -0
- package/src/agents/base.ts +125 -0
- package/src/agents/business.ts +32 -0
- package/src/agents/index.ts +4 -0
- package/src/agents/security.ts +33 -0
- package/src/cache/index.ts +47 -0
- package/src/cli/banner.ts +32 -0
- package/src/cli/commands/agents.ts +49 -0
- package/src/cli/commands/config.ts +426 -0
- package/src/cli/commands/context.ts +131 -0
- package/src/cli/commands/init.ts +117 -0
- package/src/cli/commands/prs.ts +118 -0
- package/src/cli/commands/review.ts +171 -0
- package/src/cli/renderer.ts +102 -0
- package/src/cli/selector.ts +78 -0
- package/src/config/index.ts +241 -0
- package/src/context/builder.ts +199 -0
- package/src/context/generator.ts +138 -0
- package/src/context/manager.ts +83 -0
- package/src/context/tree.ts +90 -0
- package/src/git/github.ts +112 -0
- package/src/git/utils.ts +51 -0
- package/src/i18n/en.ts +203 -0
- package/src/i18n/es.ts +203 -0
- package/src/i18n/index.ts +57 -0
- package/src/index.ts +29 -0
- package/src/orchestrator/index.ts +110 -0
- package/src/providers/base.ts +16 -0
- package/src/providers/claude.ts +36 -0
- package/src/providers/factory.ts +84 -0
- package/src/providers/fallback.ts +47 -0
- package/src/providers/gemini.ts +58 -0
- package/src/providers/mock.ts +27 -0
- package/src/providers/openai.ts +41 -0
- package/src/types.ts +175 -0
- package/tsconfig.json +17 -0
- package/tsup.config.ts +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,954 @@
|
|
|
1
|
+
# aiv — AI PR Reviewer
|
|
2
|
+
|
|
3
|
+
A local-first, multi-agent CLI for reviewing GitHub pull requests using any supported AI provider. Runs three specialized agents in parallel (Business, Architecture, Security) and produces a structured risk report with findings, suggestions, and an executive summary.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
█████╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗██╗ ██╗██╗███████╗██╗ ██╗███████╗██████╗
|
|
7
|
+
██╔══██╗██║ ██╔══██╗██╔══██╗ ██╔══██╗██╔════╝██║ ██║██║██╔════╝██║ ██║██╔════╝██╔══██╗
|
|
8
|
+
███████║██║ ██████╔╝██████╔╝ ██████╔╝█████╗ ██║ ██║██║█████╗ ██║ █╗ ██║█████╗ ██████╔╝
|
|
9
|
+
██╔══██║██║ ██╔═══╝ ██╔══██╗ ██╔══██╗██╔══╝ ╚██╗ ██╔╝██║██╔══╝ ██║███╗██║██╔══╝ ██╔══██╗
|
|
10
|
+
██║ ██║██║ ██║ ██║ ██║ ██║ ██║███████╗ ╚████╔╝ ██║███████╗╚███╔███╔╝███████╗██║ ██║
|
|
11
|
+
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═══╝ ╚═╝╚══════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
|
12
|
+
|
|
13
|
+
by Ateriss
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Table of Contents
|
|
19
|
+
|
|
20
|
+
- [Requirements](#requirements)
|
|
21
|
+
- [Installation](#installation)
|
|
22
|
+
- [Quick Start](#quick-start)
|
|
23
|
+
- [Commands Reference](#commands-reference)
|
|
24
|
+
- [Configuration](#configuration)
|
|
25
|
+
- [Global Config](#global-config-aivconfig-yml)
|
|
26
|
+
- [Repo Config](#repo-config-aivconfigyml)
|
|
27
|
+
- [Rules](#rules-aivrules-yml)
|
|
28
|
+
- [Context](#context-aivcontextmd)
|
|
29
|
+
- [GitHub Account Management](#github-account-management)
|
|
30
|
+
- [AI Providers](#ai-providers)
|
|
31
|
+
- [Review Output](#review-output)
|
|
32
|
+
- [Multi-language](#multi-language)
|
|
33
|
+
- [Environment Variables](#environment-variables)
|
|
34
|
+
- [Error Reference](#error-reference)
|
|
35
|
+
- [Best Practices](#best-practices)
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Requirements
|
|
40
|
+
|
|
41
|
+
- Node.js 18 or higher
|
|
42
|
+
- A GitHub personal access token with `repo` scope
|
|
43
|
+
- An API key for at least one supported AI provider (see [AI Providers](#ai-providers))
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install -g aiv
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Or clone and build locally:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
git clone https://github.com/your-org/aiv-cli
|
|
57
|
+
cd aiv-cli
|
|
58
|
+
npm install
|
|
59
|
+
npm run build
|
|
60
|
+
npm link
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Quick Start
|
|
66
|
+
|
|
67
|
+
**1. Initialize aiv in your project repository:**
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
cd your-repo
|
|
71
|
+
aiv init
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This creates:
|
|
75
|
+
- `~/.aiv/config.yml` — global config (AI provider, GitHub accounts)
|
|
76
|
+
- `.aiv/config.yml` — repo config (owner, repo, account override)
|
|
77
|
+
- `.aiv/rules.yml` — custom review rules for agents
|
|
78
|
+
- `.aiv/context.md` — auto-generated project context
|
|
79
|
+
- `.aiv/tree.json` — project file structure snapshot
|
|
80
|
+
|
|
81
|
+
**2. Set your API key and GitHub token:**
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
export CLAUDE_API_KEY=sk-ant-...
|
|
85
|
+
export GITHUB_TOKEN=ghp_...
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**3. List open pull requests:**
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
aiv prs
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**4. Review a PR:**
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
aiv review 42
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
That's it. The three agents run in parallel and print a full report.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Commands Reference
|
|
105
|
+
|
|
106
|
+
Every command has a short alias. Long and short forms are identical.
|
|
107
|
+
|
|
108
|
+
| Long form | Short alias | Description |
|
|
109
|
+
|----------------------------------------|---------------|---------------------------------------------------|
|
|
110
|
+
| `aiv init` | `aiv i` | Initialize aiv in the current repo |
|
|
111
|
+
| `aiv prs` | `aiv p` | List open PRs and optionally review one |
|
|
112
|
+
| `aiv review [pr-number]` | `aiv r` | Review a PR or pick one interactively |
|
|
113
|
+
| `aiv context refresh` | `aiv ctx refresh` | Rebuild `context.md` and `tree.json` |
|
|
114
|
+
| `aiv context show` | `aiv ctx show` | Print current `context.md` |
|
|
115
|
+
| `aiv config show` | `aiv cf show` | Show global and repo config |
|
|
116
|
+
| `aiv config set-provider <provider>` | `aiv cf set-provider` | Switch AI provider |
|
|
117
|
+
| `aiv config set-repo <owner> <repo>` | `aiv cf set-repo` | Set GitHub owner/repo in repo config |
|
|
118
|
+
| `aiv config set-lang <lang>` | `aiv cf set-lang` | Change display language (`en` / `es`) |
|
|
119
|
+
| `aiv config rules` | `aiv cf rules` | Print `rules.yml` |
|
|
120
|
+
| `aiv config accounts` | `aiv cf accounts` | List GitHub accounts |
|
|
121
|
+
| `aiv config add-account <name>` | `aiv cf add-account` | Add a GitHub account |
|
|
122
|
+
| `aiv config remove-account <name>` | `aiv cf remove-account` | Remove a GitHub account |
|
|
123
|
+
| `aiv config default-account <name>` | `aiv cf default-account` | Set global default account |
|
|
124
|
+
| `aiv config use-account <name>` | `aiv cf use-account` | Use an account for this repo |
|
|
125
|
+
| `aiv agents` | `aiv a` | List available agents and their focus areas |
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### `aiv init`
|
|
130
|
+
|
|
131
|
+
Initializes aiv globally and in the current repository.
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
aiv init
|
|
135
|
+
aiv i
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Safe to run in any order — if `~/.aiv/config.yml` already exists it is preserved. Re-running `init` inside a repo always rebuilds `context.md` and `tree.json` to reflect the current state of the project.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
### `aiv prs`
|
|
143
|
+
|
|
144
|
+
Fetches and displays open pull requests in a table, then opens an interactive selector.
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
aiv prs
|
|
148
|
+
aiv p
|
|
149
|
+
|
|
150
|
+
# Limit results
|
|
151
|
+
aiv prs --limit 10
|
|
152
|
+
|
|
153
|
+
# Override repo auto-detection
|
|
154
|
+
aiv prs --owner myorg --repo myrepo
|
|
155
|
+
|
|
156
|
+
# List only, skip interactive selector
|
|
157
|
+
aiv prs --no-select
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The table shows PR number, title, author, branch, diff size (`+additions/-deletions`), and creation date. After the table, an interactive prompt lets you select a PR and launch a review without typing a number.
|
|
161
|
+
|
|
162
|
+
**Repo auto-detection:** aiv reads `git remote get-url origin` to detect the GitHub owner and repo. If the remote is not a GitHub URL or is missing, use `--owner`/`--repo` flags or configure them in `.aiv/config.yml`.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
### `aiv review`
|
|
167
|
+
|
|
168
|
+
Reviews a pull request. Accepts a PR number directly or launches an interactive selector if omitted.
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# Review by number
|
|
172
|
+
aiv review 42
|
|
173
|
+
aiv r 42
|
|
174
|
+
|
|
175
|
+
# Interactive selector (fetches open PRs first)
|
|
176
|
+
aiv review
|
|
177
|
+
aiv r
|
|
178
|
+
|
|
179
|
+
# Override repo
|
|
180
|
+
aiv review 42 --owner myorg --repo myrepo
|
|
181
|
+
|
|
182
|
+
# Run specific agents only
|
|
183
|
+
aiv review 42 --agent security
|
|
184
|
+
aiv review 42 --agent business architecture
|
|
185
|
+
|
|
186
|
+
# Output raw JSON (useful for scripting and CI)
|
|
187
|
+
aiv review 42 --json
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Available agents: `business`, `architecture`, `security`. All three run in parallel by default.
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
### `aiv context`
|
|
195
|
+
|
|
196
|
+
Manages the project context used by agents during reviews.
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Rebuild context.md and tree.json from the current directory
|
|
200
|
+
aiv context refresh
|
|
201
|
+
aiv ctx refresh
|
|
202
|
+
|
|
203
|
+
# Print the current context.md
|
|
204
|
+
aiv context show
|
|
205
|
+
aiv ctx show
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Run `context refresh` after major structural changes to the project (new modules, new dependencies, large refactors) so agents have accurate background information.
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
### `aiv config`
|
|
213
|
+
|
|
214
|
+
All configuration subcommands. Running `aiv config` or `aiv cf` alone prints help.
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# Show global and repo config files
|
|
218
|
+
aiv config show
|
|
219
|
+
aiv cf show
|
|
220
|
+
|
|
221
|
+
# Switch AI provider
|
|
222
|
+
aiv config set-provider openai
|
|
223
|
+
aiv cf set-provider claude
|
|
224
|
+
|
|
225
|
+
# Set repo owner/repo explicitly
|
|
226
|
+
aiv config set-repo myorg myrepo
|
|
227
|
+
|
|
228
|
+
# Change display language
|
|
229
|
+
aiv config set-lang es
|
|
230
|
+
aiv config set-lang en
|
|
231
|
+
|
|
232
|
+
# Show rules.yml
|
|
233
|
+
aiv config rules
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
### `aiv agents`
|
|
239
|
+
|
|
240
|
+
Lists all available agents with their description and focus areas.
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
aiv agents
|
|
244
|
+
aiv a
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
| Agent | Focus areas |
|
|
248
|
+
|--------------|--------------------------------------------------------------------------|
|
|
249
|
+
| business | Business logic, domain invariants, rule violations, functional regressions |
|
|
250
|
+
| architecture | Layer violations, coupling, SRP, dependency direction, abstraction quality |
|
|
251
|
+
| security | Auth bypass, injection, data leakage, OWASP Top 10, sensitive data handling |
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Configuration
|
|
256
|
+
|
|
257
|
+
aiv uses a two-level configuration system:
|
|
258
|
+
|
|
259
|
+
| File | Scope | Purpose |
|
|
260
|
+
|-----------------------|--------|---------------------------------------------------|
|
|
261
|
+
| `~/.aiv/config.yml` | Global | AI providers, GitHub accounts, default settings |
|
|
262
|
+
| `.aiv/config.yml` | Repo | Owner/repo override, account override, token limits |
|
|
263
|
+
|
|
264
|
+
Repo-level settings always override global defaults.
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
### Global Config (`~/.aiv/config.yml`)
|
|
269
|
+
|
|
270
|
+
Created automatically by `aiv init`. Edit manually or use `aiv config` subcommands.
|
|
271
|
+
|
|
272
|
+
```yaml
|
|
273
|
+
lang: en # 'en' or 'es'
|
|
274
|
+
|
|
275
|
+
providers:
|
|
276
|
+
default: claude # 'claude', 'openai', or 'mock'
|
|
277
|
+
|
|
278
|
+
claude:
|
|
279
|
+
model: claude-sonnet-4-6
|
|
280
|
+
api_key_env: CLAUDE_API_KEY # env var holding your Anthropic key
|
|
281
|
+
|
|
282
|
+
openai:
|
|
283
|
+
model: gpt-4.1
|
|
284
|
+
api_key_env: OPENAI_API_KEY # env var holding your OpenAI key
|
|
285
|
+
|
|
286
|
+
review:
|
|
287
|
+
max_tokens: 20000 # max tokens sent to the model per agent
|
|
288
|
+
max_findings: 20 # max findings returned per review
|
|
289
|
+
|
|
290
|
+
github:
|
|
291
|
+
default_account: personal
|
|
292
|
+
accounts:
|
|
293
|
+
personal:
|
|
294
|
+
token_env: GITHUB_TOKEN
|
|
295
|
+
username: alice
|
|
296
|
+
description: Personal account
|
|
297
|
+
work:
|
|
298
|
+
token_env: GITHUB_TOKEN_WORK
|
|
299
|
+
username: alice-corp
|
|
300
|
+
description: Work account
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
### Repo Config (`.aiv/config.yml`)
|
|
306
|
+
|
|
307
|
+
Created in each repository by `aiv init`. Overrides global defaults for that repo.
|
|
308
|
+
|
|
309
|
+
```yaml
|
|
310
|
+
github:
|
|
311
|
+
account: work # use the 'work' account from global config
|
|
312
|
+
owner: myorg # override auto-detected GitHub owner
|
|
313
|
+
repo: backend-api # override auto-detected GitHub repo
|
|
314
|
+
|
|
315
|
+
review:
|
|
316
|
+
max_tokens: 30000 # allow larger diffs for this repo
|
|
317
|
+
max_findings: 30
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Leave any field out to inherit from global config. The `account` field references a named account defined in `~/.aiv/config.yml`.
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
### Rules (`.aiv/rules.yml`)
|
|
325
|
+
|
|
326
|
+
Defines custom rules that all agents respect. Edit after `aiv init`.
|
|
327
|
+
|
|
328
|
+
```yaml
|
|
329
|
+
sensitive_modules:
|
|
330
|
+
- auth
|
|
331
|
+
- payroll
|
|
332
|
+
- payments
|
|
333
|
+
- billing
|
|
334
|
+
|
|
335
|
+
business_rules:
|
|
336
|
+
payroll:
|
|
337
|
+
required_calls:
|
|
338
|
+
- auditLog
|
|
339
|
+
- validateTransaction
|
|
340
|
+
auth:
|
|
341
|
+
required_checks:
|
|
342
|
+
- permissionValidation
|
|
343
|
+
payments:
|
|
344
|
+
forbidden_patterns:
|
|
345
|
+
- directDbWrite
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
Rules are passed verbatim to every agent on every review. The business and security agents use them to flag violations explicitly.
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
### Context (`.aiv/context.md`)
|
|
353
|
+
|
|
354
|
+
Auto-generated by `aiv init` and `aiv context refresh`. Contains a summary of the project that agents use as background knowledge before reading the diff. You can append custom sections manually — they are preserved on the next refresh.
|
|
355
|
+
|
|
356
|
+
```markdown
|
|
357
|
+
## Business Context
|
|
358
|
+
|
|
359
|
+
This is an e-commerce platform handling real-money transactions.
|
|
360
|
+
All changes touching `src/payments/` must include an audit log entry.
|
|
361
|
+
The `UserBalance` model must never be modified outside the `billing` module.
|
|
362
|
+
|
|
363
|
+
## Architecture
|
|
364
|
+
|
|
365
|
+
Three-layer: HTTP handlers → service layer → repositories.
|
|
366
|
+
Cross-layer imports are forbidden; services must not import from handlers.
|
|
367
|
+
|
|
368
|
+
## Sensitive Zones
|
|
369
|
+
|
|
370
|
+
- src/auth/ — JWT issuance and validation
|
|
371
|
+
- src/payments/ — Stripe integration, never bypass PaymentGateway
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
The richer this file, the more accurate the agent findings.
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
## GitHub Account Management
|
|
379
|
+
|
|
380
|
+
aiv supports multiple GitHub accounts (personal, work, CI bot) stored globally and activated per repo.
|
|
381
|
+
|
|
382
|
+
### Add accounts
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
# Minimum — just the env var name
|
|
386
|
+
aiv config add-account personal --token-env GITHUB_TOKEN
|
|
387
|
+
|
|
388
|
+
# With optional metadata
|
|
389
|
+
aiv config add-account work \
|
|
390
|
+
--token-env GITHUB_TOKEN_WORK \
|
|
391
|
+
--username alice-corp \
|
|
392
|
+
--description "Work GitHub account"
|
|
393
|
+
|
|
394
|
+
# Overwrite an existing account
|
|
395
|
+
aiv config add-account work --token-env NEW_VAR --force
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### List accounts
|
|
399
|
+
|
|
400
|
+
```bash
|
|
401
|
+
aiv config accounts
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
Shows all configured accounts, their token env vars, which ones are set, and which is the global default.
|
|
405
|
+
|
|
406
|
+
### Set global default
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
aiv config default-account work
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
All repos without an explicit account override will use this account.
|
|
413
|
+
|
|
414
|
+
### Use a specific account for one repo
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
cd my-work-repo
|
|
418
|
+
aiv config use-account work
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
This writes `github.account: work` into `.aiv/config.yml`. Only affects the current repo.
|
|
422
|
+
|
|
423
|
+
### Remove an account
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
aiv config remove-account old-account
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
### Account resolution order
|
|
430
|
+
|
|
431
|
+
When aiv needs a GitHub token it checks:
|
|
432
|
+
|
|
433
|
+
1. `github.account` in `.aiv/config.yml` (repo-level override)
|
|
434
|
+
2. `github.default_account` in `~/.aiv/config.yml`
|
|
435
|
+
3. First account listed in `~/.aiv/config.yml`
|
|
436
|
+
4. Fallback to `GITHUB_TOKEN` env var directly
|
|
437
|
+
|
|
438
|
+
---
|
|
439
|
+
|
|
440
|
+
## AI Providers
|
|
441
|
+
|
|
442
|
+
aiv supports three kinds of providers:
|
|
443
|
+
|
|
444
|
+
| Type | Examples | Notes |
|
|
445
|
+
|------|----------|-------|
|
|
446
|
+
| **Built-in** | Claude, OpenAI, Gemini | Native adapters, configured in `~/.aiv/config.yml` |
|
|
447
|
+
| **OpenAI-compatible** | Kimi, Groq, Mistral, DeepSeek, Ollama, Together AI, … | Any new provider with a compatible endpoint — no code changes |
|
|
448
|
+
| **Mock** | — | Deterministic offline responses for testing |
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
### Claude (default)
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
export CLAUDE_API_KEY=sk-ant-...
|
|
456
|
+
aiv config set-provider claude
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
Update model or key env without editing the file:
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
aiv config add-provider claude --model claude-opus-4-7
|
|
463
|
+
aiv config add-provider claude --api-key-env MY_CLAUDE_KEY
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
```yaml
|
|
467
|
+
# ~/.aiv/config.yml
|
|
468
|
+
claude:
|
|
469
|
+
model: claude-sonnet-4-6
|
|
470
|
+
api_key_env: CLAUDE_API_KEY
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
### OpenAI
|
|
476
|
+
|
|
477
|
+
```bash
|
|
478
|
+
export OPENAI_API_KEY=sk-...
|
|
479
|
+
aiv config set-provider openai
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
```yaml
|
|
483
|
+
openai:
|
|
484
|
+
model: gpt-4.1
|
|
485
|
+
api_key_env: OPENAI_API_KEY
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
### Google Gemini
|
|
491
|
+
|
|
492
|
+
Gemini uses a dedicated REST adapter (no extra SDK required).
|
|
493
|
+
|
|
494
|
+
```bash
|
|
495
|
+
export GEMINI_API_KEY=AIza...
|
|
496
|
+
aiv config set-provider gemini
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
Update model:
|
|
500
|
+
|
|
501
|
+
```bash
|
|
502
|
+
aiv config add-provider gemini --model gemini-2.0-flash-exp
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
```yaml
|
|
506
|
+
gemini:
|
|
507
|
+
model: gemini-2.0-flash
|
|
508
|
+
api_key_env: GEMINI_API_KEY
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
---
|
|
512
|
+
|
|
513
|
+
### OpenAI-compatible providers (custom)
|
|
514
|
+
|
|
515
|
+
Any provider that exposes an OpenAI-compatible API can be registered with one command. This includes every new provider that adopts the OpenAI spec — no code changes or updates needed.
|
|
516
|
+
|
|
517
|
+
```bash
|
|
518
|
+
# Kimi (Moonshot AI)
|
|
519
|
+
export KIMI_API_KEY=sk-...
|
|
520
|
+
aiv config add-provider kimi \
|
|
521
|
+
--base-url https://api.moonshot.cn/v1 \
|
|
522
|
+
--api-key-env KIMI_API_KEY \
|
|
523
|
+
--model moonshot-v1-8k
|
|
524
|
+
|
|
525
|
+
# Groq
|
|
526
|
+
export GROQ_API_KEY=gsk_...
|
|
527
|
+
aiv config add-provider groq \
|
|
528
|
+
--base-url https://api.groq.com/openai/v1 \
|
|
529
|
+
--api-key-env GROQ_API_KEY \
|
|
530
|
+
--model llama-3.3-70b-versatile
|
|
531
|
+
|
|
532
|
+
# Mistral
|
|
533
|
+
export MISTRAL_API_KEY=...
|
|
534
|
+
aiv config add-provider mistral \
|
|
535
|
+
--base-url https://api.mistral.ai/v1 \
|
|
536
|
+
--api-key-env MISTRAL_API_KEY \
|
|
537
|
+
--model mistral-large-latest
|
|
538
|
+
|
|
539
|
+
# DeepSeek
|
|
540
|
+
aiv config add-provider deepseek \
|
|
541
|
+
--base-url https://api.deepseek.com/v1 \
|
|
542
|
+
--api-key-env DEEPSEEK_API_KEY \
|
|
543
|
+
--model deepseek-chat
|
|
544
|
+
|
|
545
|
+
# Together AI
|
|
546
|
+
aiv config add-provider together \
|
|
547
|
+
--base-url https://api.together.xyz/v1 \
|
|
548
|
+
--api-key-env TOGETHER_API_KEY \
|
|
549
|
+
--model meta-llama/Llama-3-70b-chat-hf
|
|
550
|
+
|
|
551
|
+
# Ollama (local, no key needed)
|
|
552
|
+
aiv config add-provider ollama \
|
|
553
|
+
--base-url http://localhost:11434/v1 \
|
|
554
|
+
--api-key-env OLLAMA_API_KEY \
|
|
555
|
+
--model llama3.2
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
Once registered, use any custom provider exactly like a built-in:
|
|
559
|
+
|
|
560
|
+
```bash
|
|
561
|
+
aiv config set-provider kimi
|
|
562
|
+
aiv config set-agent-provider security groq/llama-3.3-70b-versatile
|
|
563
|
+
aiv config set-fallback groq openai
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
Manage custom providers:
|
|
567
|
+
|
|
568
|
+
```bash
|
|
569
|
+
aiv config list-providers # show all built-in + custom
|
|
570
|
+
aiv config remove-provider kimi # remove a custom provider
|
|
571
|
+
aiv config add-provider kimi --model moonshot-v1-32k --force # update
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
### Per-agent provider assignment
|
|
577
|
+
|
|
578
|
+
Run each agent with a different provider or model:
|
|
579
|
+
|
|
580
|
+
```bash
|
|
581
|
+
aiv config set-agent-provider business claude/claude-sonnet-4-6
|
|
582
|
+
aiv config set-agent-provider security openai/gpt-4.1
|
|
583
|
+
aiv config set-agent-provider architecture gemini/gemini-2.0-flash
|
|
584
|
+
aiv config set-agent-provider context kimi/moonshot-v1-8k
|
|
585
|
+
|
|
586
|
+
# View current assignments
|
|
587
|
+
aiv config show-agents
|
|
588
|
+
|
|
589
|
+
# Remove an override (reverts to default)
|
|
590
|
+
aiv config set-agent-provider business --clear
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
### Fallback chain
|
|
596
|
+
|
|
597
|
+
If a provider hits a rate limit or quota error, aiv automatically switches to the next in the chain:
|
|
598
|
+
|
|
599
|
+
```bash
|
|
600
|
+
# Try openai first, then gemini, then kimi
|
|
601
|
+
aiv config set-fallback openai gemini kimi
|
|
602
|
+
|
|
603
|
+
# Clear the chain
|
|
604
|
+
aiv config set-fallback
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
When a fallback fires, aiv prints:
|
|
608
|
+
|
|
609
|
+
```
|
|
610
|
+
⚡ "claude" quota/rate limit — switching to "openai"
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
---
|
|
614
|
+
|
|
615
|
+
### Mock (offline testing)
|
|
616
|
+
|
|
617
|
+
```bash
|
|
618
|
+
aiv config set-provider mock
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
Returns deterministic placeholder findings. Use this to test the CLI locally without consuming API credits.
|
|
622
|
+
|
|
623
|
+
---
|
|
624
|
+
|
|
625
|
+
## Review Output
|
|
626
|
+
|
|
627
|
+
A typical review looks like:
|
|
628
|
+
|
|
629
|
+
```
|
|
630
|
+
aiv review — PR #42
|
|
631
|
+
|
|
632
|
+
Account: personal (GITHUB_TOKEN)
|
|
633
|
+
|
|
634
|
+
✔ PR loaded: "Add payment retry logic" (8 files)
|
|
635
|
+
✔ Context loaded
|
|
636
|
+
|
|
637
|
+
Running agents: business, architecture, security
|
|
638
|
+
|
|
639
|
+
Review: PR #42 — Add payment retry logic
|
|
640
|
+
Risk Score: 74/100 HIGH Generated: 5/17/26
|
|
641
|
+
|
|
642
|
+
Executive Summary
|
|
643
|
+
─────────────────
|
|
644
|
+
High-risk changes to the payment processing pipeline. The retry
|
|
645
|
+
loop lacks idempotency guards and could cause duplicate charges.
|
|
646
|
+
No audit log entries were added for the new retry paths.
|
|
647
|
+
|
|
648
|
+
Security Issues
|
|
649
|
+
───────────────
|
|
650
|
+
[HIGH] Missing idempotency key on retry
|
|
651
|
+
File: src/payments/retry.ts
|
|
652
|
+
Retry attempts do not include an idempotency key, allowing
|
|
653
|
+
the payment provider to process the same charge multiple times.
|
|
654
|
+
Suggestion: Pass a stable idempotency key derived from the
|
|
655
|
+
original transaction ID.
|
|
656
|
+
|
|
657
|
+
Business Risks
|
|
658
|
+
──────────────
|
|
659
|
+
[CRITICAL] auditLog() not called in retry path
|
|
660
|
+
rules.yml requires auditLog for all payroll mutations.
|
|
661
|
+
|
|
662
|
+
Architecture Issues
|
|
663
|
+
───────────────────
|
|
664
|
+
[MEDIUM] Direct database write outside billing module
|
|
665
|
+
src/payments/retry.ts imports UserBalance from outside
|
|
666
|
+
the billing boundary.
|
|
667
|
+
|
|
668
|
+
Agent Summaries
|
|
669
|
+
───────────────
|
|
670
|
+
business — 2 finding(s) [score: 88]
|
|
671
|
+
architecture — 1 finding(s) [score: 55]
|
|
672
|
+
security — 1 finding(s) [score: 74]
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
### Risk score
|
|
676
|
+
|
|
677
|
+
Computed as `max_score × 0.6 + average_score × 0.4` across all agents.
|
|
678
|
+
|
|
679
|
+
| Score | Label |
|
|
680
|
+
|--------|----------|
|
|
681
|
+
| 0–25 | LOW |
|
|
682
|
+
| 26–50 | MEDIUM |
|
|
683
|
+
| 51–75 | HIGH |
|
|
684
|
+
| 76–100 | CRITICAL |
|
|
685
|
+
|
|
686
|
+
### JSON output
|
|
687
|
+
|
|
688
|
+
Use `--json` to get the full structured result for scripts or CI pipelines:
|
|
689
|
+
|
|
690
|
+
```bash
|
|
691
|
+
aiv review 42 --json | jq '.riskScore'
|
|
692
|
+
aiv review 42 --json > review-42.json
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
The JSON shape matches the `ReviewResult` type: `prNumber`, `prTitle`, `riskScore`, `riskLabel`, `executiveSummary`, `agents[]`, `securityIssues[]`, `businessRisks[]`, `architectureIssues[]`, `possibleRegressions[]`.
|
|
696
|
+
|
|
697
|
+
---
|
|
698
|
+
|
|
699
|
+
## Multi-language
|
|
700
|
+
|
|
701
|
+
aiv supports English and Spanish. All terminal output — errors, spinners, table headers, severity labels — follows the configured language.
|
|
702
|
+
|
|
703
|
+
### Switch language
|
|
704
|
+
|
|
705
|
+
```bash
|
|
706
|
+
# Permanently (saved to ~/.aiv/config.yml)
|
|
707
|
+
aiv config set-lang es
|
|
708
|
+
aiv config set-lang en
|
|
709
|
+
|
|
710
|
+
# Per-session via env var (overrides config)
|
|
711
|
+
AIV_LANG=es aiv prs
|
|
712
|
+
AIV_LANG=en aiv review 42
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
### Language detection order
|
|
716
|
+
|
|
717
|
+
1. `AIV_LANG` environment variable
|
|
718
|
+
2. `lang` in `~/.aiv/config.yml`
|
|
719
|
+
3. System `LANG` environment variable (auto-detected `es_*` locales use Spanish)
|
|
720
|
+
4. Default: `en`
|
|
721
|
+
|
|
722
|
+
---
|
|
723
|
+
|
|
724
|
+
## Environment Variables
|
|
725
|
+
|
|
726
|
+
| Variable | Required | Description |
|
|
727
|
+
|-----------------------|----------|------------------------------------------------------|
|
|
728
|
+
| `GITHUB_TOKEN` | Yes | GitHub personal access token (default account) |
|
|
729
|
+
| `CLAUDE_API_KEY` | Yes* | Anthropic API key (*required when using Claude) |
|
|
730
|
+
| `OPENAI_API_KEY` | Yes* | OpenAI API key (*required when using OpenAI) |
|
|
731
|
+
| `AIV_LANG` | No | Override display language (`en` or `es`) |
|
|
732
|
+
| `LANG` | No | System locale (auto-detected by aiv) |
|
|
733
|
+
|
|
734
|
+
For additional GitHub accounts, the env var name is whatever you passed to `--token-env`:
|
|
735
|
+
|
|
736
|
+
```bash
|
|
737
|
+
export GITHUB_TOKEN_WORK=ghp_...
|
|
738
|
+
aiv config add-account work --token-env GITHUB_TOKEN_WORK
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
GitHub tokens require `repo` scope to read pull requests and diffs.
|
|
742
|
+
|
|
743
|
+
---
|
|
744
|
+
|
|
745
|
+
## Error Reference
|
|
746
|
+
|
|
747
|
+
### `Not initialized. Run aiv init first.`
|
|
748
|
+
|
|
749
|
+
You ran a command that requires `.aiv/config.yml` but it doesn't exist in the current directory.
|
|
750
|
+
|
|
751
|
+
```bash
|
|
752
|
+
cd your-repo
|
|
753
|
+
aiv init
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
---
|
|
757
|
+
|
|
758
|
+
### `Missing env var: GITHUB_TOKEN (account: default)`
|
|
759
|
+
|
|
760
|
+
The token env var for the active account is not set in the environment.
|
|
761
|
+
|
|
762
|
+
```bash
|
|
763
|
+
export GITHUB_TOKEN=ghp_...
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
If you use a named account with a different env var, check which account is active and what it expects:
|
|
767
|
+
|
|
768
|
+
```bash
|
|
769
|
+
aiv config accounts
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
---
|
|
773
|
+
|
|
774
|
+
### `Missing env var: CLAUDE_API_KEY`
|
|
775
|
+
|
|
776
|
+
The AI provider API key is not set. Set the env var or switch providers:
|
|
777
|
+
|
|
778
|
+
```bash
|
|
779
|
+
export CLAUDE_API_KEY=sk-ant-...
|
|
780
|
+
# or switch to OpenAI
|
|
781
|
+
aiv config set-provider openai
|
|
782
|
+
export OPENAI_API_KEY=sk-...
|
|
783
|
+
```
|
|
784
|
+
|
|
785
|
+
---
|
|
786
|
+
|
|
787
|
+
### `Could not detect GitHub owner/repo.`
|
|
788
|
+
|
|
789
|
+
aiv could not parse the GitHub owner and repo from `git remote get-url origin`. This happens when the remote is not a GitHub URL, the repo has no remote, or the remote uses an unsupported format.
|
|
790
|
+
|
|
791
|
+
Fix — pass flags directly:
|
|
792
|
+
```bash
|
|
793
|
+
aiv prs --owner myorg --repo myrepo
|
|
794
|
+
aiv review 42 --owner myorg --repo myrepo
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
Fix — set permanently in repo config:
|
|
798
|
+
```bash
|
|
799
|
+
aiv config set-repo myorg myrepo
|
|
800
|
+
```
|
|
801
|
+
|
|
802
|
+
---
|
|
803
|
+
|
|
804
|
+
### `Account "xyz" not found.`
|
|
805
|
+
|
|
806
|
+
You referenced an account name that doesn't exist in `~/.aiv/config.yml`.
|
|
807
|
+
|
|
808
|
+
```bash
|
|
809
|
+
aiv config accounts # list what's available
|
|
810
|
+
aiv config add-account xyz --token-env MY_TOKEN # add the missing account
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
---
|
|
814
|
+
|
|
815
|
+
### `Account "xyz" already exists. Use --force to overwrite.`
|
|
816
|
+
|
|
817
|
+
```bash
|
|
818
|
+
aiv config add-account xyz --token-env NEW_VAR --force
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
---
|
|
822
|
+
|
|
823
|
+
### `Failed to fetch PR: ...`
|
|
824
|
+
|
|
825
|
+
Network or GitHub API error. Common causes:
|
|
826
|
+
|
|
827
|
+
- Token lacks `repo` scope — regenerate with full repo permissions
|
|
828
|
+
- PR number does not exist in the target repository
|
|
829
|
+
- GitHub rate limit hit — wait or switch to a token with higher limits
|
|
830
|
+
- Wrong `owner`/`repo` — verify with `aiv config show`
|
|
831
|
+
|
|
832
|
+
---
|
|
833
|
+
|
|
834
|
+
### `Review failed: ...`
|
|
835
|
+
|
|
836
|
+
The AI provider returned an error. Common causes:
|
|
837
|
+
|
|
838
|
+
- API key is invalid or expired
|
|
839
|
+
- Model quota exceeded
|
|
840
|
+
- Network timeout on a very large diff — reduce `max_tokens` in config:
|
|
841
|
+
|
|
842
|
+
```yaml
|
|
843
|
+
# .aiv/config.yml
|
|
844
|
+
review:
|
|
845
|
+
max_tokens: 10000
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
---
|
|
849
|
+
|
|
850
|
+
## Best Practices
|
|
851
|
+
|
|
852
|
+
### Fill in context before the first review
|
|
853
|
+
|
|
854
|
+
After `aiv init`, open `.aiv/context.md` and describe your project: what it does, which modules are critical, invariants that must never be violated. This is the single most impactful thing you can do to improve finding accuracy.
|
|
855
|
+
|
|
856
|
+
### Define rules for your domain
|
|
857
|
+
|
|
858
|
+
Add a rule every time your team agrees on a pattern that reviews should enforce. Rules are passed to every agent on every review — they act as a live checklist that doesn't drift.
|
|
859
|
+
|
|
860
|
+
```yaml
|
|
861
|
+
business_rules:
|
|
862
|
+
orders:
|
|
863
|
+
required_calls:
|
|
864
|
+
- validateInventory
|
|
865
|
+
forbidden_patterns:
|
|
866
|
+
- skipFraudCheck
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
### Refresh context after major changes
|
|
870
|
+
|
|
871
|
+
```bash
|
|
872
|
+
aiv context refresh
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
Run this after merging a large refactor, adding a new module, or changing the project structure significantly. Stale context silently reduces finding quality.
|
|
876
|
+
|
|
877
|
+
### Use `--agent` to narrow the focus
|
|
878
|
+
|
|
879
|
+
Not every PR needs all three agents. If you're reviewing a dependency bump, only security matters. If it's a UI-only change, skip security and architecture:
|
|
880
|
+
|
|
881
|
+
```bash
|
|
882
|
+
aiv review 101 --agent security
|
|
883
|
+
aiv review 202 --agent business architecture
|
|
884
|
+
```
|
|
885
|
+
|
|
886
|
+
Fewer agents means faster results and lower API cost.
|
|
887
|
+
|
|
888
|
+
### Use named accounts from day one
|
|
889
|
+
|
|
890
|
+
Even with a single GitHub account, naming it makes configuration explicit and makes it trivial to add a second account later:
|
|
891
|
+
|
|
892
|
+
```bash
|
|
893
|
+
aiv config add-account personal \
|
|
894
|
+
--token-env GITHUB_TOKEN \
|
|
895
|
+
--username alice \
|
|
896
|
+
--description "Personal GitHub"
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
### Commit `.aiv/` to the repository
|
|
900
|
+
|
|
901
|
+
Committing `config.yml`, `rules.yml`, and `context.md` means every team member gets identical review behavior without any manual setup. Add only `tree.json` to `.gitignore` since it's a generated snapshot:
|
|
902
|
+
|
|
903
|
+
```
|
|
904
|
+
# .gitignore
|
|
905
|
+
.aiv/tree.json
|
|
906
|
+
```
|
|
907
|
+
|
|
908
|
+
`aiv init` adds this entry automatically.
|
|
909
|
+
|
|
910
|
+
### Integrate into CI with `--json`
|
|
911
|
+
|
|
912
|
+
```bash
|
|
913
|
+
SCORE=$(aiv review $PR_NUMBER --json | jq '.riskScore')
|
|
914
|
+
if [ "$SCORE" -gt 75 ]; then
|
|
915
|
+
echo "High-risk PR — human review required before merge"
|
|
916
|
+
exit 1
|
|
917
|
+
fi
|
|
918
|
+
```
|
|
919
|
+
|
|
920
|
+
### What aiv is not
|
|
921
|
+
|
|
922
|
+
- Not a linter or formatter — it won't tell you about semicolons
|
|
923
|
+
- Not a replacement for static analysis tools (ESLint, SonarQube)
|
|
924
|
+
- Not checking code style
|
|
925
|
+
|
|
926
|
+
Its value is **semantic understanding**: catching what automated tools miss — business rule violations, architectural drift, and security risks that only make sense in context.
|
|
927
|
+
|
|
928
|
+
---
|
|
929
|
+
|
|
930
|
+
## Project Structure
|
|
931
|
+
|
|
932
|
+
```
|
|
933
|
+
src/
|
|
934
|
+
agents/ — business, architecture, security (extend BaseAgent)
|
|
935
|
+
cli/
|
|
936
|
+
commands/ — one file per command (init, prs, review, config, context, agents)
|
|
937
|
+
banner.ts — ASCII welcome banner
|
|
938
|
+
renderer.ts — review result pretty-printer
|
|
939
|
+
selector.ts — interactive PR picker (inquirer)
|
|
940
|
+
config/ — two-level config load/save/merge
|
|
941
|
+
context/ — project tree scanner and context builder
|
|
942
|
+
git/ — GitHub REST client and git remote detection
|
|
943
|
+
i18n/ — EN/ES translations (all user-facing strings)
|
|
944
|
+
orchestrator/ — runs agents in parallel, aggregates results
|
|
945
|
+
providers/ — Claude, OpenAI, Mock AI client wrappers
|
|
946
|
+
types.ts — shared TypeScript interfaces
|
|
947
|
+
index.ts — CLI entry point (Commander root)
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
---
|
|
951
|
+
|
|
952
|
+
## License
|
|
953
|
+
|
|
954
|
+
MIT
|