@ateriss_/aiv-cli 1.0.1 → 1.0.3

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 CHANGED
@@ -1,26 +1,54 @@
1
1
  # aiv — AI PR Reviewer
2
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
3
  ```
6
4
  █████╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗██╗ ██╗██╗███████╗██╗ ██╗███████╗██████╗
7
5
  ██╔══██╗██║ ██╔══██╗██╔══██╗ ██╔══██╗██╔════╝██║ ██║██║██╔════╝██║ ██║██╔════╝██╔══██╗
8
6
  ███████║██║ ██████╔╝██████╔╝ ██████╔╝█████╗ ██║ ██║██║█████╗ ██║ █╗ ██║█████╗ ██████╔╝
9
7
  ██╔══██║██║ ██╔═══╝ ██╔══██╗ ██╔══██╗██╔══╝ ╚██╗ ██╔╝██║██╔══╝ ██║███╗██║██╔══╝ ██╔══██╗
10
8
  ██║ ██║██║ ██║ ██║ ██║ ██║ ██║███████╗ ╚████╔╝ ██║███████╗╚███╔███╔╝███████╗██║ ██║
11
- ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═══╝ ╚═╝╚══════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝`;
9
+ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═══╝ ╚═╝╚══════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
12
10
 
13
11
  by Ateriss
14
12
  ```
15
13
 
16
14
  ---
17
15
 
16
+ ## What is aiv?
17
+
18
+ Code review is one of the most important quality gates in a software team — and also one of the most time-consuming. Reviewers need to understand the business context, track architectural decisions, spot security risks, and catch regressions, all while reading through a diff that may span dozens of files.
19
+
20
+ **aiv** is a local-first CLI that runs that analysis for you, before a human ever opens the PR.
21
+
22
+ It sends the diff to three specialized AI agents in parallel — one focused on **business logic and domain rules**, one on **architecture and structural patterns**, and one on **security vulnerabilities** — and returns a structured risk report with severity-rated findings, specific suggestions per file, and an executive summary. The report is anchored to your project: aiv reads your `context.md` (project background, architecture decisions, sensitive zones) and `rules.yml` (custom business rules, required calls, forbidden patterns) so findings are relevant to your codebase, not just generic linting advice.
23
+
24
+ **What aiv catches that linters miss:**
25
+
26
+ - A retry loop that could cause duplicate charges because it skips the idempotency check your team agreed on
27
+ - A service that imports directly from a handler, breaking the layer contract
28
+ - A new endpoint that reads user data without going through the authorization middleware
29
+ - A payroll mutation that doesn't call `auditLog()` as required by your rules
30
+ - A function moved to a shared module that now exposes internal state to layers that shouldn't see it
31
+
32
+ **Two perspectives, one tool:**
33
+
34
+ aiv covers both sides of the code review workflow. As a **reviewer**, run `aiv review` to analyze an open PR and act directly from the terminal — approve, request changes, post the report as a comment, or merge. As the **author**, run `aiv check` before opening a PR to catch issues in your own branch first. If the report looks good, create the PR directly from the terminal; if not, save a `.aiv/checklist.md` with all findings as checkboxes so you know exactly what to fix.
35
+
36
+ **What happens after the review:**
37
+
38
+ Once the report is in, aiv lets you act on it directly from the terminal — approve the PR, request changes, post the full report as a formatted GitHub comment, or merge with your preferred strategy (squash, merge, rebase). If you've already reviewed the PR in a previous session, aiv detects the cached analysis in the PR comments and asks if you want to reuse it instead of re-running the agents.
39
+
40
+ **Works with any AI provider.** Claude, OpenAI, Gemini, Groq, Mistral, DeepSeek, Kimi, Ollama, or any OpenAI-compatible endpoint. Mix providers per agent — use a fast model for routine checks and a powerful one for security. Configure a fallback chain so a quota error on one provider silently switches to the next without losing the run.
41
+
42
+ ---
43
+
18
44
  ## Table of Contents
19
45
 
20
46
  - [Requirements](#requirements)
21
47
  - [Installation](#installation)
22
48
  - [Quick Start](#quick-start)
23
49
  - [Commands Reference](#commands-reference)
50
+ - [aiv review](#aiv-review)
51
+ - [aiv check](#aiv-check)
24
52
  - [Configuration](#configuration)
25
53
  - [Global Config](#global-config)
26
54
  - [Repo Config](#repo-config)
@@ -100,13 +128,22 @@ aiv context generate
100
128
  aiv prs
101
129
  ```
102
130
 
103
- **5. Review a PR:**
131
+ **5. Review a PR (as a reviewer):**
104
132
 
105
133
  ```bash
106
134
  aiv review 42
107
135
  ```
108
136
 
109
- After the report, aiv asks if you want to **approve**, **request changes**, or **merge** directly on GitHub.
137
+ After the report, aiv asks if you want to approve, request changes, post the report as a PR comment, or merge directly from the terminal.
138
+
139
+ **Or: analyze your own branch before opening a PR (as the author):**
140
+
141
+ ```bash
142
+ aiv check # compares current branch vs origin/main (auto-detected)
143
+ aiv check qa # compares current branch vs origin/qa
144
+ ```
145
+
146
+ After the report, aiv asks: create the PR on GitHub or save a checklist of findings to `.aiv/checklist.md`.
110
147
 
111
148
  ---
112
149
 
@@ -120,7 +157,8 @@ Every command has a short alias. Long and short forms are identical.
120
157
  |-----------|-------|-------------|
121
158
  | `aiv init` | `aiv i` | Initialize aiv globally and in the current repo |
122
159
  | `aiv prs` | `aiv p` | List open PRs, then optionally review one |
123
- | `aiv review [pr-number]` | `aiv r` | Review a PR or pick interactively |
160
+ | `aiv review [pr-number]` | `aiv r` | Review a PR or pick interactively (reviewer perspective) |
161
+ | `aiv check [base-branch]` | `aiv c` | Analyze local diff before opening a PR (author perspective) |
124
162
  | `aiv agents` | `aiv a` | List available agents and their focus areas |
125
163
 
126
164
  ### Context
@@ -207,7 +245,64 @@ aiv review 42 --agent business architecture
207
245
  aiv review 42 --json # raw JSON, no interactive prompt
208
246
  ```
209
247
 
210
- After the report prints, aiv asks whether to **approve**, **request changes**, or **skip** and submits the decision directly to GitHub. If you approve, you can optionally merge the PR right away and choose the merge strategy. `context.md` and `tree.json` are always refreshed after an approval.
248
+ If a previous aiv analysis exists as a comment on the PR, aiv asks whether to reuse it or run a fresh analysis. After the report, the post-review action menu lets you approve, request changes, post the report as a comment, or skip.
249
+
250
+ ---
251
+
252
+ ### `aiv check`
253
+
254
+ Analyzes your local branch against a remote base branch **before** opening a PR — the author's equivalent of `aiv review`.
255
+
256
+ ```bash
257
+ aiv check # auto-detects base (origin/main, origin/master, origin/develop)
258
+ aiv c
259
+
260
+ aiv check qa # compare current branch vs origin/qa
261
+ aiv check main # compare current branch vs origin/main
262
+ aiv check --agent security # run only the security agent
263
+ aiv check qa --json # raw JSON output
264
+ ```
265
+
266
+ The diff is always computed against the **remote** branch (`origin/<base>`), not your local copy, so findings reflect the actual gap that would be in the PR.
267
+
268
+ After the report, aiv detects whether your branch has unpushed commits and adjusts the menu accordingly:
269
+
270
+ ```
271
+ # If there are unpushed commits:
272
+ ? What would you like to do?
273
+ ❯ 🚀 Push y crear PR en GitHub
274
+ 📋 Guardar checklist en .aiv/
275
+ ────────────────────────────────────────
276
+ ↩ Skip
277
+
278
+ # If the branch is already up to date with the remote:
279
+ ? What would you like to do?
280
+ ❯ 🚀 Crear PR en GitHub
281
+ 📋 Guardar checklist en .aiv/
282
+ ────────────────────────────────────────
283
+ ↩ Skip
284
+ ```
285
+
286
+ - **Push y crear PR** — runs `git push origin <branch>`, then creates the PR via GitHub API. If the push fails, it stops before attempting PR creation.
287
+ - **Crear PR** — branch is already pushed; creates the PR directly without a push.
288
+ - **Guardar checklist** — writes `.aiv/checklist.md` with all findings as `- [ ]` checkboxes, grouped by severity. The `.aiv/` folder is gitignored so the file never reaches the remote.
289
+
290
+ **Example checklist (`aiv/checklist.md`):**
291
+
292
+ ```markdown
293
+ # aiv Check: feature/payments → main
294
+ Generated: 2026-05-18 | Risk: HIGH (74/100)
295
+
296
+ ## Critical & High
297
+
298
+ - [ ] **[HIGH]** Missing idempotency key on retry — `src/payments/retry.ts`
299
+ > Pass a stable key derived from the original transaction ID.
300
+ - [ ] **[CRITICAL]** auditLog() not called in retry path
301
+
302
+ ## Medium
303
+
304
+ - [ ] **[MEDIUM]** Direct database write outside billing module — `src/db/payments.ts`
305
+ ```
211
306
 
212
307
  ---
213
308
 
@@ -359,13 +454,15 @@ business_rules:
359
454
  - directDbWrite
360
455
  ```
361
456
 
457
+ The more specific your rules, the fewer false positives and the more actionable the findings.
458
+
362
459
  ---
363
460
 
364
461
  ### Context
365
462
 
366
463
  `.aiv/context.md` — project background that agents read before analyzing the diff.
367
464
 
368
- Auto-generated by `aiv init`, `aiv context refresh`, and `aiv context generate`. You can edit it freely — custom sections are preserved on the next refresh.
465
+ Auto-generated by `aiv init`, `aiv context refresh`, and `aiv context generate`. You can edit it freely — the richer this file, the more accurate the findings.
369
466
 
370
467
  ```markdown
371
468
  ## Business Context
@@ -385,8 +482,6 @@ Services must not import from handlers.
385
482
  - src/payments/ — Stripe integration, never bypass PaymentGateway
386
483
  ```
387
484
 
388
- The richer this file, the more accurate the agent findings.
389
-
390
485
  ---
391
486
 
392
487
  ## GitHub Account Management
@@ -489,7 +584,7 @@ gemini:
489
584
 
490
585
  ### OpenAI-compatible providers
491
586
 
492
- Any provider that exposes an OpenAI-compatible API can be registered with one command — no code changes, no updates needed when new providers launch.
587
+ Any provider that exposes an OpenAI-compatible API can be registered with one command — no code changes needed when new providers launch.
493
588
 
494
589
  ```bash
495
590
  # Kimi (Moonshot AI)
@@ -527,12 +622,6 @@ aiv config add-provider ollama \
527
622
  --base-url http://localhost:11434/v1 \
528
623
  --api-key-env OLLAMA_API_KEY \
529
624
  --model llama3.2
530
-
531
- # Any future provider that adopts the OpenAI spec
532
- aiv config add-provider newprovider \
533
- --base-url https://api.newprovider.com/v1 \
534
- --api-key-env NEWPROVIDER_API_KEY \
535
- --model their-model-name
536
625
  ```
537
626
 
538
627
  Once registered, custom providers work exactly like built-ins:
@@ -551,7 +640,6 @@ aiv config add-provider kimi --model moonshot-v1-32k --force # update
551
640
  Each agent (and the context generator) can use a different provider or model:
552
641
 
553
642
  ```bash
554
- # Assign provider/model per agent
555
643
  aiv config set-agent-provider business claude/claude-sonnet-4-6
556
644
  aiv config set-agent-provider security openai/gpt-4.1
557
645
  aiv config set-agent-provider architecture gemini/gemini-2.0-flash
@@ -569,8 +657,6 @@ aiv config set-agent-provider business --clear
569
657
 
570
658
  Valid agent roles: `business`, `architecture`, `security`, `context`.
571
659
 
572
- The `context` role is used by `aiv context generate`. All other roles map to the review agents.
573
-
574
660
  ---
575
661
 
576
662
  ### Fallback chain
@@ -675,11 +761,12 @@ After every review in an interactive terminal, aiv asks:
675
761
  ? What would you like to do with this PR?
676
762
  ❯ ✔ Approve PR
677
763
  ⚑ Request Changes
764
+ 💬 Post as PR comment
678
765
  ────────────────────────────────────────
679
766
  ↩ Skip
680
767
  ```
681
768
 
682
- - **Approve** — submits an `APPROVE` review to GitHub. aiv then asks if you want to merge:
769
+ - **Approve** — submits an `APPROVE` review to GitHub, then asks if you want to merge:
683
770
 
684
771
  ```
685
772
  ? Merge this PR now? (y/N)
@@ -693,8 +780,20 @@ After every review in an interactive terminal, aiv asks:
693
780
  After approving (with or without merge), `context.md` and `tree.json` are refreshed automatically.
694
781
 
695
782
  - **Request Changes** — submits a `REQUEST_CHANGES` review to GitHub.
783
+ - **Post as PR comment** — publishes the full report as a formatted GitHub comment. The comment includes severity-rated findings, suggestions, and agent summaries. It also embeds the analysis data so aiv can detect it on future runs.
696
784
  - **Skip** — does nothing, exits cleanly.
697
785
 
786
+ ### Analysis cache
787
+
788
+ When you run `aiv review` on a PR that already has an aiv comment, aiv detects the previous analysis and asks:
789
+
790
+ ```
791
+ Found a previous aiv analysis on this PR.
792
+ ? Use cached analysis? (Y/n)
793
+ ```
794
+
795
+ Choosing yes skips the AI agents entirely and uses the stored result — no API calls, instant output. Choose no to run a fresh analysis (useful after new commits are pushed).
796
+
698
797
  ---
699
798
 
700
799
  ## Multi-language
@@ -728,19 +827,14 @@ AIV_LANG=es aiv prs # per-session override
728
827
  | `AIV_LANG` | No | Override display language (`en` or `es`) |
729
828
  | `LANG` | No | System locale (auto-detected by aiv) |
730
829
 
731
- For custom providers, the env var name is whatever you passed to `--api-key-env`:
732
-
733
- ```bash
734
- export KIMI_API_KEY=sk-...
735
- aiv config add-provider kimi --api-key-env KIMI_API_KEY ...
736
- ```
830
+ For custom providers, the env var name is whatever you passed to `--api-key-env`.
737
831
 
738
832
  ### GitHub token permissions
739
833
 
740
834
  | Scope | Required for |
741
835
  |-------|-------------|
742
836
  | `repo` (private repos) or `public_repo` | Reading PRs and diffs |
743
- | `pull_requests: write` (fine-grained PAT) | Submitting reviews and merging |
837
+ | `pull_requests: write` (fine-grained PAT) | Submitting reviews, posting comments, merging |
744
838
 
745
839
  ---
746
840
 
@@ -758,14 +852,18 @@ cd your-repo && aiv init
758
852
 
759
853
  ### `Missing env var: GITHUB_TOKEN (account: default)`
760
854
 
761
- The token env var for the active account is not set.
855
+ The token env var for the active account is not set. Check which variable name the account expects:
762
856
 
763
857
  ```bash
764
- export GITHUB_TOKEN=ghp_...
765
- # or check which account/var is active:
766
858
  aiv config accounts
767
859
  ```
768
860
 
861
+ Then set it (once, permanently on Windows):
862
+
863
+ ```powershell
864
+ [System.Environment]::SetEnvironmentVariable("GITHUB_TOKEN", "ghp_...", "User")
865
+ ```
866
+
769
867
  ---
770
868
 
771
869
  ### `Missing env var: CLAUDE_API_KEY`
@@ -780,10 +878,8 @@ aiv config set-provider openai
780
878
 
781
879
  ### `Unknown provider: "xyz".`
782
880
 
783
- A provider name was used that isn't registered.
784
-
785
881
  ```bash
786
- aiv config list-providers # see what's configured
882
+ aiv config list-providers
787
883
  aiv config add-provider xyz --base-url <url> --api-key-env XYZ_API_KEY --model <model>
788
884
  ```
789
885
 
@@ -791,8 +887,6 @@ aiv config add-provider xyz --base-url <url> --api-key-env XYZ_API_KEY --model <
791
887
 
792
888
  ### `Could not detect GitHub owner/repo.`
793
889
 
794
- The git remote is missing or not a GitHub URL.
795
-
796
890
  ```bash
797
891
  aiv prs --owner myorg --repo myrepo
798
892
  # or set permanently:
@@ -801,21 +895,12 @@ aiv config set-repo myorg myrepo
801
895
 
802
896
  ---
803
897
 
804
- ### `Account "xyz" not found.`
805
-
806
- ```bash
807
- aiv config accounts
808
- aiv config add-account xyz --token-env MY_TOKEN
809
- ```
810
-
811
- ---
812
-
813
898
  ### `Failed to fetch PR: ...`
814
899
 
815
- - Token lacks `repo` scope — regenerate
816
- - PR number doesn't exist
817
- - GitHub rate limit — wait or switch token
818
- - Wrong owner/repo — check with `aiv config show`
900
+ - Token lacks `repo` scope — regenerate with the correct scopes
901
+ - PR number doesn't exist in this repo
902
+ - GitHub rate limit — wait or switch to a different account
903
+ - Wrong owner/repo — verify with `aiv config show`
819
904
 
820
905
  ---
821
906
 
@@ -823,10 +908,9 @@ aiv config add-account xyz --token-env MY_TOKEN
823
908
 
824
909
  - API key invalid or expired
825
910
  - Model quota exceeded — configure a [fallback chain](#fallback-chain)
826
- - Diff too large — reduce `max_tokens`:
911
+ - Diff too large — reduce `max_tokens` in `.aiv/config.yml`:
827
912
 
828
913
  ```yaml
829
- # .aiv/config.yml
830
914
  review:
831
915
  max_tokens: 10000
832
916
  ```
@@ -843,26 +927,38 @@ Right after `aiv init`, run:
843
927
  aiv context generate
844
928
  ```
845
929
 
846
- This gives you a ready-to-edit `context.md` and `rules.yml` based on what the AI infers from your project. Tune what it gets wrong rather than writing from scratch.
930
+ This produces a `context.md` and `rules.yml` based on what the AI infers from your project structure. Tune what it gets wrong rather than writing from scratch.
847
931
 
848
- ### Keep rules.yml current
932
+ ### Write specific rules
849
933
 
850
- Add a rule whenever your team agrees on a pattern reviews should catch:
934
+ Generic rules produce generic findings. The more specific `rules.yml` is, the more precise the business agent becomes:
851
935
 
852
936
  ```yaml
853
937
  business_rules:
854
938
  orders:
855
- required_calls: [validateInventory]
856
- forbidden_patterns: [skipFraudCheck]
939
+ required_calls: [validateInventory, reserveStock]
940
+ forbidden_patterns: [skipFraudCheck, directInventoryWrite]
941
+ ```
942
+
943
+ ### Check your own branch before opening a PR
944
+
945
+ ```bash
946
+ aiv check qa # or whatever branch you're merging into
857
947
  ```
858
948
 
949
+ Running `aiv check` before opening a PR catches issues that would otherwise land in the reviewer's lap. If the report shows problems, save a checklist to `.aiv/checklist.md`, fix, and run `aiv check` again. Once clean, aiv detects whether the branch needs a push and handles it — you go from analysis to open PR in one step.
950
+
951
+ ### Post the report as a PR comment
952
+
953
+ After reviewing, choose **Post as PR comment** to make the findings visible to the whole team directly in GitHub. The comment is also used as a cache — the next time anyone runs `aiv review` on the same PR, aiv detects it and offers to skip the AI calls.
954
+
859
955
  ### Refresh context after structural changes
860
956
 
861
957
  ```bash
862
958
  aiv context refresh
863
959
  ```
864
960
 
865
- Run after merging large refactors, adding modules, or changing the project layout.
961
+ Run after merging large refactors, adding new modules, or reorganizing the project layout.
866
962
 
867
963
  ### Use a fallback chain for reliability
868
964
 
@@ -872,20 +968,20 @@ aiv config set-fallback openai gemini
872
968
 
873
969
  If your primary provider is rate-limited mid-review, aiv switches automatically without losing the run.
874
970
 
875
- ### Match model to task with per-agent assignment
971
+ ### Match model to task
876
972
 
877
- Use a fast/cheap model for straightforward agents and a powerful one for the critical ones:
973
+ Use a fast/cheap model for straightforward agents and a stronger one for the most critical:
878
974
 
879
975
  ```bash
880
976
  aiv config set-agent-provider business claude/claude-haiku-4-5
881
977
  aiv config set-agent-provider architecture claude/claude-haiku-4-5
882
- aiv config set-agent-provider security claude/claude-sonnet-4-6 # strongest model here
978
+ aiv config set-agent-provider security claude/claude-sonnet-4-6
883
979
  ```
884
980
 
885
981
  ### Use `--agent` to narrow focus
886
982
 
887
983
  ```bash
888
- aiv review 101 --agent security # dependency bump
984
+ aiv review 101 --agent security # dependency bump — only security matters
889
985
  aiv review 202 --agent business architecture # domain change
890
986
  ```
891
987
 
@@ -893,15 +989,14 @@ Fewer agents = faster, cheaper, more focused output.
893
989
 
894
990
  ### Commit `.aiv/` to the repository
895
991
 
896
- Committing `config.yml`, `rules.yml`, and `context.md` means every team member gets identical review behavior with no setup. Only exclude `tree.json`:
992
+ Committing `config.yml`, `rules.yml`, and `context.md` means every team member gets identical review behavior with no local setup. `aiv init` automatically gitignores only the files that shouldn't be shared:
897
993
 
898
994
  ```
899
- # .gitignore
900
- .aiv/tree.json
995
+ # added automatically by aiv init
996
+ .aiv/tree.json # auto-generated snapshot — large, noise in diffs
997
+ .aiv/checklist.md # personal pre-PR draft — not team-relevant
901
998
  ```
902
999
 
903
- `aiv init` adds this automatically.
904
-
905
1000
  ### CI integration with `--json`
906
1001
 
907
1002
  ```bash
@@ -918,7 +1013,7 @@ fi
918
1013
  - Not a replacement for static analysis (ESLint, SonarQube)
919
1014
  - Not a style checker
920
1015
 
921
- Its value is **semantic understanding**: catching business rule violations, architectural drift, and security risks that automated tools miss because they require project context to understand.
1016
+ Its value is **semantic understanding**: catching business rule violations, architectural drift, and security risks that automated tools miss because they don't know your project's context, rules, or intent.
922
1017
 
923
1018
  ---
924
1019
 
@@ -928,9 +1023,9 @@ Its value is **semantic understanding**: catching business rule violations, arch
928
1023
  src/
929
1024
  agents/ — business, architecture, security reviewers
930
1025
  cli/
931
- commands/ — init, prs, review, config, context, agents
1026
+ commands/ — init, prs, review, check, config, context, agents
932
1027
  banner.ts — ASCII welcome banner
933
- renderer.ts — review result pretty-printer
1028
+ renderer.ts — terminal renderer + GitHub comment builder
934
1029
  selector.ts — interactive PR/action picker (inquirer)
935
1030
  config/ — two-level config load/save/merge
936
1031
  context/
@@ -938,7 +1033,7 @@ src/
938
1033
  generator.ts — AI-powered context + rules generation
939
1034
  manager.ts — context reader + refreshContextFiles helper
940
1035
  tree.ts — file tree scanner
941
- git/ — GitHub REST client + remote detection
1036
+ git/ — GitHub REST client, remote detection, local diff builder
942
1037
  i18n/ — EN/ES translations (all user-facing strings)
943
1038
  orchestrator/ — runs agents in parallel, aggregates results
944
1039
  providers/