code-review-ai-cli 1.0.0__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.
@@ -0,0 +1,441 @@
1
+ Metadata-Version: 2.4
2
+ Name: code-review-ai-cli
3
+ Version: 1.0.0
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 a ready-to-edit `config.yaml` in your working directory:
82
+
83
+ ```bash
84
+ ai-review init
85
+ ```
86
+
87
+ This copies the bundled template with all available options and inline documentation:
88
+
89
+ ```
90
+ ✅ config.yaml created at: /home/user/my-project/config.yaml
91
+ Edit it to add your credentials and preferences.
92
+ ```
93
+
94
+ If a `config.yaml` already exists you will be prompted before it is overwritten:
95
+
96
+ ```
97
+ config.yaml already exists in the current directory.
98
+ Overwrite? [y/N]
99
+ ```
100
+
101
+ The tool looks for `config.yaml` in the **current working directory** at runtime. You can also pass a different path with `--config`:
102
+
103
+ ```bash
104
+ ai-review pr-review --config ~/configs/ai-review.yaml
105
+ ```
106
+
107
+ ### Minimal Example
108
+
109
+ ```yaml
110
+ llm:
111
+ provider: openai
112
+ model: gpt-4o
113
+
114
+ openai:
115
+ api_key: sk-xxxx
116
+
117
+ tfs:
118
+ base_url: https://dev.azure.com/your-organization
119
+ project: ProjectName
120
+ pat: xxxxxxxxx
121
+ verify_ssl: true
122
+ # ca_bundle: C:/certs/corporate-root-ca.pem
123
+
124
+ review:
125
+ language: pt
126
+ verbosity: detailed
127
+ scope: diff_only
128
+ custom_prompt_file: review_prompt.md
129
+ # file limit sent to the LLM
130
+ max_diff_files: 50
131
+ # per-file limit
132
+ max_diff_lines: 2000
133
+ # extension allowlist (empty list = all files)
134
+ file_extensions_filter: [".cs", ".ts", ".py"]
135
+
136
+ pr:
137
+ auto_post_comments: false
138
+ dry_run: false
139
+ comment_mode: structured
140
+
141
+ output:
142
+ format: terminal
143
+ file: ""
144
+ color: true
145
+ ```
146
+
147
+ ### Filter by File Extension
148
+
149
+ `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.
150
+
151
+ ```yaml
152
+ review:
153
+ # Review only C#, TypeScript, and Python code
154
+ file_extensions_filter: [".cs", ".ts", ".py"]
155
+ ```
156
+
157
+ To review **all** PR files, leave the list empty:
158
+
159
+ ```yaml
160
+ review:
161
+ file_extensions_filter: []
162
+ ```
163
+
164
+ > **Note:** If no eligible files remain after filtering, the review ends with a warning without calling the LLM.
165
+
166
+ ### Markdown-Customizable Prompt
167
+
168
+ You can adjust review rules, context, and examples in `review_prompt.md`.
169
+ This file is loaded automatically and injected into LLM instructions on each run.
170
+
171
+ Example in `config.yaml`:
172
+
173
+ ```yaml
174
+ review:
175
+ custom_prompt_file: review_prompt.md
176
+ ```
177
+
178
+ Suggested usage for this file:
179
+
180
+ - Define comment tone and format
181
+ - Add mandatory validation rules
182
+ - Include business/architecture context
183
+ - Add examples of good/bad comments
184
+
185
+ ### Bedrock Example
186
+
187
+ ```yaml
188
+ llm:
189
+ provider: bedrock
190
+ model: anthropic.claude-3-5-sonnet-20240620-v1:0
191
+
192
+ bedrock:
193
+ region: us-east-1
194
+ # profile: default
195
+ # access_key_id: AKIA...
196
+ # secret_access_key: ...
197
+ # session_token: ...
198
+
199
+ tfs:
200
+ base_url: https://dev.azure.com/your-organization
201
+ project: ProjectName
202
+ pat: xxxxxxxxx
203
+ ```
204
+ Bedrock notes:
205
+
206
+ - You can use `profile` or explicit credentials in YAML.
207
+ - If explicit credentials are not defined, the AWS SDK uses the default credentials chain.
208
+
209
+ ## Review Flow
210
+
211
+ The main `pr-review` workflow is:
212
+
213
+ 1. load and validate configuration
214
+ 2. fetch Pull Request metadata from Azure DevOps/TFS
215
+ 3. fetch the PR diff
216
+ 4. filter and truncate the diff according to configuration
217
+ 5. request textual analysis and structured comments from the LLM provider
218
+ 6. display a preview in the terminal
219
+ 7. post inline or general PR comments when applicable
220
+
221
+ ## Tests
222
+
223
+ The project's functional coverage is reflected in the `tests/` folder, including:
224
+
225
+ - `tests/test_ai_review.py` for the CLI and main workflow
226
+ - `tests/test_config.py` for configuration and validation
227
+ - `tests/test_formatter.py` for terminal/markdown/json rendering
228
+ - `tests/test_git_utils.py` for diffs and Git utilities
229
+ - `tests/test_llm_client.py` for prompts, parsing, and LLM providers
230
+ - `tests/test_tfs_client.py` for TFS/Azure DevOps integration
231
+
232
+ Run the suite:
233
+
234
+ ```bash
235
+ python -m pytest --cov=src --cov-report=term
236
+ ```
237
+
238
+ ## CLI Usage
239
+
240
+ ### Help
241
+ ```bash
242
+ python src/ai_review.py --help
243
+ ```
244
+
245
+ ### Bootstrap configuration
246
+
247
+ Generate a `config.yaml` template in the current directory:
248
+
249
+ ```bash
250
+ ai-review init
251
+ ```
252
+
253
+ ### Interactive Mode
254
+
255
+ ```bash
256
+ python ai_review.py
257
+ ```
258
+
259
+ ### Pull Request Review
260
+
261
+ List PRs and select interactively:
262
+
263
+ ```bash
264
+ python ai_review.py pr-review
265
+ ```
266
+
267
+ Review a specific PR:
268
+
269
+ ```bash
270
+ python ai_review.py pr-review 42
271
+ ```
272
+
273
+ Dry-run:
274
+
275
+ ```bash
276
+ python ai_review.py pr-review 42 --dry-run
277
+ ```
278
+
279
+ Full review of changed files (in addition to diff-focused review):
280
+
281
+ ```bash
282
+ python ai_review.py pr-review 42 --review-scope full_code
283
+ ```
284
+
285
+ Automatic posting (without confirmation):
286
+
287
+ ```bash
288
+ python ai_review.py pr-review 42 --auto-post
289
+ ```
290
+
291
+ Filter PRs in interactive selection:
292
+
293
+ ```bash
294
+ python ai_review.py pr-review --author "John Smith" --target-branch main
295
+ ```
296
+
297
+ Choose provider/model via CLI:
298
+
299
+ ```bash
300
+ python ai_review.py pr-review 42 --provider bedrock --model anthropic.claude-3-5-sonnet-20240620-v1:0
301
+ ```
302
+
303
+ ### List Pull Requests
304
+
305
+ ```bash
306
+ python ai_review.py list-prs
307
+ python ai_review.py list-prs --status completed
308
+ python ai_review.py list-prs --repo-name backend --author "John"
309
+ ```
310
+
311
+ ## Execution Flow
312
+
313
+ The diagram below summarizes how the review application moves from CLI entry to PR analysis and comment posting.
314
+
315
+ ```mermaid
316
+ flowchart TD
317
+ A[Start: python ai_review.py] --> B{Arguments provided?}
318
+ B -->|No| C[Interactive mode]
319
+ B -->|Yes| D[Parse CLI command]
320
+
321
+ C --> E{Choose action}
322
+ E -->|PR review| F[Start PR review workflow]
323
+ E -->|List PRs| G[List pull requests]
324
+ E -->|Show config| H[Display current configuration]
325
+
326
+ D --> I{Command}
327
+ I -->|pr-review| F
328
+ I -->|list-prs| G
329
+
330
+ F --> J[Load and validate config]
331
+ J --> K[Initialize TFS client]
332
+ K --> L{PR ID provided?}
333
+ L -->|No| M[Fetch active PRs and select one]
334
+ L -->|Yes| N[Use provided PR ID]
335
+ M --> O[Get PR details]
336
+ N --> O
337
+ O --> P[Get PR diff or full changed-file context]
338
+ P --> Q[Filter by allowed file extensions]
339
+ Q --> R[Keep additions only]
340
+ R --> S[Limit files with max_diff_files]
341
+ S --> T[Build changed-files summary]
342
+ T --> U[Truncate each file with max_diff_lines]
343
+ U --> V[Run AI general review]
344
+ V --> W[Run AI structured comment generation]
345
+ W --> X[Preview review and suggested comments]
346
+ X --> Y{Dry-run enabled?}
347
+ Y -->|Yes| Z[Stop after preview]
348
+ Y -->|No| AA{Auto-post enabled?}
349
+ AA -->|Yes| AB[Post all review comments]
350
+ AA -->|No| AC[Select comments to post]
351
+ AC --> AB
352
+ AB --> AD[Post general PR summary]
353
+ AD --> AE{Output file configured?}
354
+ AE -->|Yes| AF[Save formatted review output]
355
+ AE -->|No| AG[Finish]
356
+ AF --> AG
357
+
358
+ G --> AH[Fetch PR list with filters]
359
+ AH --> AI[Display PR list]
360
+ ```
361
+
362
+ ## Supported Commands and Options
363
+
364
+ ### `pr-review`
365
+
366
+ ```bash
367
+ python ai_review.py pr-review [pr_id]
368
+ ```
369
+
370
+ Options:
371
+
372
+ - `--repo-name`, `-r`
373
+ - `--dry-run`
374
+ - `--auto-post`
375
+ - `--author`
376
+ - `--target-branch`
377
+ - `--quick` / `--detailed` / `--security`
378
+ - `--review-scope {diff_only,full_code}` (default: `diff_only`)
379
+ - `--max-diff-files N` — overrides `review.max_diff_files` from config.yaml
380
+ - `--context`, `-c`
381
+ - `--format {terminal,markdown,json}`
382
+ - `--output`, `-o`
383
+ - `--no-color`
384
+ - `--model`, `-m`
385
+ - `--provider`, `-p`
386
+ - `--config`
387
+
388
+ ### `list-prs`
389
+
390
+ ```bash
391
+ python ai_review.py list-prs
392
+ ```
393
+
394
+ Options:
395
+
396
+ - `--repo-name`, `-r`
397
+ - `--status {active,completed,abandoned,all}`
398
+ - `--author`
399
+
400
+ ## Available VS Code Tasks
401
+
402
+ - `🌟 AI Review: Pull Request (Interactive)`
403
+ - `🌟 AI Review: PR (Dry-Run)`
404
+ - `📋 AI Review: List Active PRs`
405
+ - `🤖 AI Review: Interactive Mode`
406
+
407
+ ## Troubleshooting
408
+
409
+ ### TLS/SSL Error in On-Prem TFS
410
+
411
+ Prefer using a CA bundle:
412
+
413
+ ```yaml
414
+ tfs:
415
+ verify_ssl: true
416
+ ca_bundle: C:/certs/corporate-root-ca.pem
417
+ ```
418
+
419
+ Avoid `verify_ssl: false` except for temporary troubleshooting.
420
+
421
+ ### Bedrock Authentication Error
422
+
423
+ - Confirm `bedrock.region`.
424
+ - Confirm `llm.model` with a valid Bedrock model ID in the chosen region.
425
+ - Validate AWS credentials (`profile` or explicit keys).
426
+
427
+ ## Architecture
428
+
429
+ ```text
430
+ ai_code_review_script/
431
+ ├── src/
432
+ │ ├── config.py # YAML-only configuration
433
+ │ ├── ai_review.py # Main PR CLI and workflow
434
+ │ ├── llm_client.py # LLM provider integration (includes Bedrock)
435
+ │ ├── tfs_client.py # Azure DevOps/TFS (PRs and comments)
436
+ │ ├── formatter.py # Output formatting
437
+ │ └── git_utils.py # Utilities for diff parsing/truncation
438
+ ├── config.yaml # Single configuration file
439
+ ├── requirements.txt # Python dependencies
440
+ └── .vscode/tasks.json # PR review tasks
441
+ ```