code-review-ai-cli 1.3.0__tar.gz → 1.3.2__tar.gz

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.
Files changed (38) hide show
  1. code_review_ai_cli-1.3.2/PKG-INFO +430 -0
  2. code_review_ai_cli-1.3.2/README.md +393 -0
  3. code_review_ai_cli-1.3.2/code_review_ai_cli.egg-info/PKG-INFO +430 -0
  4. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/code_review_ai_cli.egg-info/SOURCES.txt +2 -6
  5. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/pyproject.toml +1 -1
  6. code_review_ai_cli-1.3.2/src/ai_review.py +965 -0
  7. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/src/config.py +4 -158
  8. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/src/formatter.py +29 -24
  9. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/src/git_utils.py +35 -119
  10. code_review_ai_cli-1.3.2/src/llm_client.py +1305 -0
  11. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/src/prompts/config.yaml.template +7 -98
  12. code_review_ai_cli-1.3.2/src/prompts/review_prompt.md.template +2 -0
  13. code_review_ai_cli-1.3.2/src/tfs_client.py +826 -0
  14. code_review_ai_cli-1.3.2/tests/test_ai_review.py +554 -0
  15. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/tests/test_config.py +3 -82
  16. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/tests/test_formatter.py +42 -2
  17. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/tests/test_git_utils.py +64 -119
  18. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/tests/test_llm_client.py +133 -231
  19. code_review_ai_cli-1.3.2/tests/test_tfs_client.py +515 -0
  20. code_review_ai_cli-1.3.0/PKG-INFO +0 -326
  21. code_review_ai_cli-1.3.0/README.md +0 -289
  22. code_review_ai_cli-1.3.0/code_review_ai_cli.egg-info/PKG-INFO +0 -326
  23. code_review_ai_cli-1.3.0/src/ai_review.py +0 -2314
  24. code_review_ai_cli-1.3.0/src/llm_client.py +0 -2114
  25. code_review_ai_cli-1.3.0/src/prompts/review_context.example.md +0 -59
  26. code_review_ai_cli-1.3.0/src/rag_engine.py +0 -162
  27. code_review_ai_cli-1.3.0/src/tfs_client.py +0 -1813
  28. code_review_ai_cli-1.3.0/src/usage_tracker.py +0 -374
  29. code_review_ai_cli-1.3.0/tests/test_ai_review.py +0 -1115
  30. code_review_ai_cli-1.3.0/tests/test_rag_engine.py +0 -250
  31. code_review_ai_cli-1.3.0/tests/test_tfs_client.py +0 -926
  32. code_review_ai_cli-1.3.0/tests/test_usage_tracker.py +0 -195
  33. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/code_review_ai_cli.egg-info/dependency_links.txt +0 -0
  34. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/code_review_ai_cli.egg-info/entry_points.txt +0 -0
  35. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/code_review_ai_cli.egg-info/requires.txt +0 -0
  36. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/code_review_ai_cli.egg-info/top_level.txt +0 -0
  37. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/setup.cfg +0 -0
  38. {code_review_ai_cli-1.3.0 → code_review_ai_cli-1.3.2}/src/__init__.py +0 -0
@@ -0,0 +1,430 @@
1
+ Metadata-Version: 2.4
2
+ Name: code-review-ai-cli
3
+ Version: 1.3.2
4
+ Summary: Automated AI-powered code review CLI for Azure DevOps / TFS Pull Requests
5
+ License: MIT
6
+ Keywords: code-review,ai,azure-devops,tfs,pull-request,llm
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Environment :: Console
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Software Development :: Quality Assurance
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: requests>=2.28.0
19
+ Requires-Dist: PyYAML>=6.0
20
+ Provides-Extra: bedrock
21
+ Requires-Dist: boto3>=1.34.0; extra == "bedrock"
22
+ Provides-Extra: openai
23
+ Requires-Dist: openai>=1.0.0; extra == "openai"
24
+ Provides-Extra: gemini
25
+ Requires-Dist: google-generativeai>=0.3.0; extra == "gemini"
26
+ Provides-Extra: claude
27
+ Requires-Dist: anthropic>=0.18.0; extra == "claude"
28
+ Provides-Extra: all
29
+ Requires-Dist: boto3>=1.34.0; extra == "all"
30
+ Requires-Dist: openai>=1.0.0; extra == "all"
31
+ Requires-Dist: google-generativeai>=0.3.0; extra == "all"
32
+ Requires-Dist: anthropic>=0.18.0; extra == "all"
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest>=8.3.0; extra == "dev"
35
+ Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
36
+ Requires-Dist: pytest-mock>=3.14.0; extra == "dev"
37
+
38
+ # AI Code Review
39
+
40
+ Automated code review tool with Pull Request integration for Azure DevOps/TFS and support for multiple LLM providers.
41
+
42
+ The main entry point is in `src/ai_review.py`. The project also includes dedicated modules for configuration, output formatting, Git diff capture, TFS/Azure DevOps integration, and communication with the LLM provider.
43
+
44
+ ## Features
45
+
46
+ - AI Pull Request review (`pr-review`)
47
+ - Structured PR comments (inline + general summary)
48
+ - `dry-run` mode to validate without posting
49
+ - PR listing with filters (`list-prs`)
50
+ - Configuration exclusively via `config.yaml`
51
+ - Providers LLM: OpenAI, Azure OpenAI, Gemini, Claude, Ollama, GitHub Copilot, AWS Bedrock
52
+
53
+ ## Installation
54
+
55
+ Install from PyPI:
56
+
57
+ ```bash
58
+ pip install code-review-ai-cli
59
+ ```
60
+
61
+ Or install with optional LLM SDK extras:
62
+
63
+ ```bash
64
+ pip install "code-review-ai-cli[bedrock]" # AWS Bedrock
65
+ pip install "code-review-ai-cli[openai]" # OpenAI SDK
66
+ pip install "code-review-ai-cli[gemini]" # Google Gemini SDK
67
+ pip install "code-review-ai-cli[claude]" # Anthropic Claude SDK
68
+ pip install "code-review-ai-cli[all]" # All optional SDKs
69
+ ```
70
+
71
+ All providers also work without their optional SDK — the tool communicates via HTTP directly.
72
+
73
+ If you plan to run the test suite locally, also install development dependencies:
74
+
75
+ ```bash
76
+ pip install "code-review-ai-cli[dev]"
77
+ ```
78
+
79
+ ## Configuration
80
+
81
+ After installing the package, generate ready-to-edit configuration files in your working directory:
82
+
83
+ ```bash
84
+ ai-review init
85
+ ```
86
+
87
+ This copies two bundled templates:
88
+
89
+ - **`config.yaml`** — all available options with inline documentation
90
+ - **`review_prompt.md`** — default review style rules, injected into every LLM prompt
91
+
92
+ ```text
93
+ ✅ config.yaml created at: /home/user/my-project/config.yaml
94
+ ✅ review_prompt.md created at: /home/user/my-project/review_prompt.md
95
+ Edit them to add your credentials, preferences and review rules.
96
+ ```
97
+
98
+ If either file already exists you will be prompted individually before it is overwritten:
99
+
100
+ ```text
101
+ config.yaml already exists in the current directory.
102
+ Overwrite? [y/N]
103
+ ```
104
+
105
+ The tool looks for `config.yaml` in the **current working directory** at runtime. You can also pass a different path with `--config`:
106
+
107
+ ```bash
108
+ ai-review pr-review --config ~/configs/ai-review.yaml
109
+ ```
110
+
111
+ ### Minimal Example
112
+
113
+ ```yaml
114
+ llm:
115
+ provider: openai
116
+ model: gpt-4o
117
+
118
+ openai:
119
+ api_key: sk-xxxx
120
+
121
+ tfs:
122
+ base_url: https://dev.azure.com/your-organization
123
+ project: ProjectName
124
+ pat: xxxxxxxxx
125
+ verify_ssl: true
126
+ # ca_bundle: C:/certs/corporate-root-ca.pem
127
+
128
+ review:
129
+ language: pt
130
+ verbosity: detailed
131
+ scope: diff_only
132
+ custom_prompt_file: review_prompt.md
133
+ # file limit sent to the LLM
134
+ max_diff_files: 50
135
+ # per-file limit
136
+ max_diff_lines: 2000
137
+ # extension allowlist (empty list = all files)
138
+ file_extensions_filter: [".cs", ".ts", ".py"]
139
+
140
+ pr:
141
+ auto_post_comments: false
142
+ dry_run: false
143
+ comment_mode: structured
144
+
145
+ output:
146
+ format: terminal
147
+ file: ""
148
+ color: true
149
+ ```
150
+
151
+ ### Review Scope
152
+
153
+ `review.scope` controls how much code is sent to the LLM for each changed file.
154
+
155
+ | Scope | Description |
156
+ |---|---|
157
+ | `diff_only` | Default. Unified diff (changed lines only) + full file content as read-only context. |
158
+ | `full_code` | All lines of the new file version, every line prefixed with `+`. No baseline. |
159
+
160
+ #### `diff_only` — diff with full-file context (default)
161
+
162
+ ```yaml
163
+ review:
164
+ scope: diff_only
165
+ scope: full_code
166
+ ```
167
+
168
+ When `diff_only` is active, the tool:
169
+
170
+ 1. Generates a standard unified diff (added/removed lines with 3 lines of surrounding context) for each changed file.
171
+ 2. Appends the **complete new-version file content** as a clearly-marked, read-only context block immediately after the diff for that file:
172
+ 3. Strips all context lines and deleted lines (`-`) before sending to the LLM, so only added lines (`+`) and structural headers remain in the diff section.
173
+ 4. Instructs the LLM (via the system prompt) to **use the full-file block as read-only background** and to focus the review exclusively on the `+` lines.
174
+
175
+ #### `full_code` — entire new file as added lines
176
+ Every line of the new file version is prefixed with `+` and sent without a `-` baseline. The LLM receives the complete content and is asked to review only the new code. This is more expensive and slower but may catch issues in unchanged lines that are affected by the changes.
177
+
178
+ ### Filter by File Extension
179
+
180
+ `file_extensions_filter` works as an **allowlist**: only files with listed extensions are sent to the LLM for review. Remaining files are excluded from the diff before any processing.
181
+
182
+ ```yaml
183
+ review:
184
+ # Review only C#, TypeScript, and Python code
185
+ file_extensions_filter: [".cs", ".ts", ".py"]
186
+ ```
187
+
188
+ To review **all** PR files, leave the list empty:
189
+
190
+ ```yaml
191
+ review:
192
+ file_extensions_filter: []
193
+ ```
194
+
195
+ > **Note:** If no eligible files remain after filtering, the review ends with a warning without calling the LLM.
196
+
197
+ ### Markdown-Customizable Prompt
198
+
199
+ `ai-review init` creates a `review_prompt.md` alongside `config.yaml`. This file is loaded automatically and injected into LLM instructions on every run.
200
+
201
+ Edit it to tailor the review to your team:
202
+
203
+ - Define comment tone and format
204
+ - Add mandatory validation rules
205
+ - Include business/architecture context
206
+ - Add examples of good/bad comments
207
+
208
+ The path is configurable in `config.yaml` (default: `review_prompt.md` in the current directory):
209
+
210
+ ```yaml
211
+ review:
212
+ custom_prompt_file: review_prompt.md
213
+ ```
214
+
215
+ ### Bedrock Example
216
+
217
+ **Option 1 — Bedrock long-term API key** (AWS Console → Amazon Bedrock → API Keys):
218
+ ```yaml
219
+ llm:
220
+ provider: bedrock
221
+ model: arn:aws:bedrock:eu-north-1:123456789:application-inference-profile/xxxxxxxx
222
+
223
+ bedrock:
224
+ region: eu-north-1
225
+ access_key_id: ABSK... # long-term API key — no secret_access_key
226
+ ```
227
+
228
+ **Option 2 — IAM explicit credentials** (access key ID + secret):
229
+ ```yaml
230
+ llm:
231
+ provider: bedrock
232
+ model: anthropic.claude-3-5-sonnet-20240620-v1:0
233
+
234
+ bedrock:
235
+ region: us-east-1
236
+ access_key_id: AKIA...
237
+ secret_access_key: wJalr...
238
+ # session_token: ... # optional, for temporary STS credentials
239
+ ```
240
+
241
+ **Option 3 — AWS SSO / named profile**:
242
+ ```yaml
243
+ bedrock:
244
+ region: us-east-1
245
+ profile: my-sso-profile
246
+ ```
247
+
248
+ ## CLI Usage
249
+
250
+ ### Help
251
+
252
+ ```bash
253
+ ai-review pr-review --help
254
+ ```
255
+
256
+ ### Bootstrap configuration
257
+
258
+ Generate `config.yaml` and `review_prompt.md` templates in the current directory:
259
+
260
+ ```bash
261
+ ai-review init
262
+ ```
263
+
264
+ ### Interactive Mode
265
+
266
+ ```bash
267
+ ai-review pr-review
268
+ ```
269
+
270
+ ### Pull Request Review
271
+
272
+ List PRs and select interactively:
273
+
274
+ ```bash
275
+ ai-review pr-review pr-review
276
+ ```
277
+
278
+ Review a specific PR:
279
+
280
+ ```bash
281
+ ai-review pr-review pr-review 42
282
+ ```
283
+
284
+ Dry-run:
285
+
286
+ ```bash
287
+ ai-review pr-review pr-review 42 --dry-run
288
+ ```
289
+
290
+ Full review of changed files (in addition to diff-focused review):
291
+
292
+ ```bash
293
+ ai-review pr-review pr-review 42 --review-scope full_code
294
+ ```
295
+
296
+ Automatic posting (without confirmation):
297
+
298
+ ```bash
299
+ ai-review pr-review pr-review 42 --auto-post
300
+ ```
301
+
302
+ Filter PRs in interactive selection:
303
+
304
+ ```bash
305
+ ai-review pr-review pr-review --author "John Smith" --target-branch main
306
+ ```
307
+
308
+ Choose provider/model via CLI:
309
+
310
+ ```bash
311
+ ai-review pr-review pr-review 42 --provider bedrock --model anthropic.claude-3-5-sonnet-20240620-v1:0
312
+ ```
313
+
314
+ ### List Pull Requests
315
+
316
+ ```bash
317
+ ai-review pr-review list-prs
318
+ ai-review pr-review list-prs --status completed
319
+ ai-review pr-review list-prs --repo-name backend --author "John"
320
+ ```
321
+
322
+ ## Execution Flow
323
+
324
+ The diagram below summarizes how the review application moves from CLI entry to PR analysis and comment posting.
325
+
326
+ ```mermaid
327
+ flowchart TD
328
+ A[Start: ai-review pr-review] --> B{Arguments provided?}
329
+ B -->|No| C[Interactive mode]
330
+ B -->|Yes| D[Parse CLI command]
331
+
332
+ C --> E{Choose action}
333
+ E -->|PR review| F[Start PR review workflow]
334
+ E -->|List PRs| G[List pull requests]
335
+ E -->|Show config| H[Display current configuration]
336
+
337
+ D --> I{Command}
338
+ I -->|pr-review| F
339
+ I -->|list-prs| G
340
+
341
+ F --> J[Load and validate config]
342
+ J --> K[Initialize TFS client]
343
+ K --> L{PR ID provided?}
344
+ L -->|No| M[Fetch active PRs and select one]
345
+ L -->|Yes| N[Use provided PR ID]
346
+ M --> O[Get PR details]
347
+ N --> O
348
+ O --> P[Get PR diff or full changed-file context]
349
+ P --> Q[Filter by allowed file extensions]
350
+ Q --> R[Keep additions only]
351
+ R --> S[Limit files with max_diff_files]
352
+ S --> T[Build changed-files summary]
353
+ T --> U[Truncate each file with max_diff_lines]
354
+ U --> V[Run AI general review]
355
+ V --> W[Run AI structured comment generation]
356
+ W --> X[Preview review and suggested comments]
357
+ X --> Y{Dry-run enabled?}
358
+ Y -->|Yes| Z[Stop after preview]
359
+ Y -->|No| AA{Auto-post enabled?}
360
+ AA -->|Yes| AB[Post all review comments]
361
+ AA -->|No| AC[Select comments to post]
362
+ AC --> AB
363
+ AB --> AD[Post general PR summary]
364
+ AD --> AE{Output file configured?}
365
+ AE -->|Yes| AF[Save formatted review output]
366
+ AE -->|No| AG[Finish]
367
+ AF --> AG
368
+
369
+ G --> AH[Fetch PR list with filters]
370
+ AH --> AI[Display PR list]
371
+ ```
372
+
373
+ ## Supported Commands and Options
374
+
375
+ ### `pr-review`
376
+
377
+ ```bash
378
+ ai-review pr-review pr-review [pr_id]
379
+ ```
380
+
381
+ Options:
382
+
383
+ - `--repo-name`, `-r`
384
+ - `--dry-run`
385
+ - `--auto-post`
386
+ - `--author`
387
+ - `--target-branch`
388
+ - `--quick` / `--detailed` / `--security`
389
+ - `--review-scope {diff_only,full_code}` (default: `diff_only`)
390
+ - `--max-diff-files N` — overrides `review.max_diff_files` from config.yaml
391
+ - `--context`, `-c`
392
+ - `--format {terminal,markdown,json}`
393
+ - `--output`, `-o`
394
+ - `--no-color`
395
+ - `--model`, `-m`
396
+ - `--provider`, `-p`
397
+ - `--config`
398
+
399
+ ### `list-prs`
400
+
401
+ ```bash
402
+ ai-review pr-review list-prs
403
+ ```
404
+
405
+ Options:
406
+
407
+ - `--repo-name`, `-r`
408
+ - `--status {active,completed,abandoned,all}`
409
+ - `--author`
410
+
411
+ ## Available VS Code Tasks
412
+
413
+ - `AI Review: Pull Request (Interactive)`
414
+ - `AI Review: PR (Dry-Run)`
415
+ - `AI Review: List Active PRs`
416
+ - `AI Review: Interactive Mode`
417
+
418
+ ## Troubleshooting
419
+
420
+ ### TLS/SSL Error in On-Prem TFS
421
+
422
+ Prefer using a CA bundle:
423
+
424
+ ```yaml
425
+ tfs:
426
+ verify_ssl: true
427
+ ca_bundle: C:/certs/corporate-root-ca.pem
428
+ ```
429
+
430
+ Avoid `verify_ssl: false` except for temporary troubleshooting.