codecritique 1.1.1 → 1.2.1
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 +53 -579
- package/package.json +1 -1
- package/src/index.js +13 -12
- package/src/llm.js +59 -40
- package/src/llm.test.js +14 -2
- package/src/project-analyzer.js +13 -50
- package/src/prompt-cache.js +627 -0
- package/src/rag-analyzer.js +112 -512
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/codecritique)
|
|
4
4
|
[](https://www.npmjs.com/package/codecritique)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
[](https://nodejs.org/)
|
|
7
7
|
[](https://github.com/cosmocoder/CodeCritique/actions/workflows/release.yml)
|
|
8
8
|
|
|
9
9
|
**AI-Powered Code Review. Context-Aware. Privacy-First.**
|
|
@@ -55,10 +55,7 @@ npm install -g codecritique
|
|
|
55
55
|
- [Quick Start](#quick-start)
|
|
56
56
|
- [GitHub Actions Integration](#github-actions-integration)
|
|
57
57
|
- [Commands Reference](#commands-reference)
|
|
58
|
-
- [RAG Architecture](#rag-architecture)
|
|
59
58
|
- [Configuration](#configuration)
|
|
60
|
-
- [Output Formats](#output-formats)
|
|
61
|
-
- [Error Handling & Troubleshooting](#error-handling--troubleshooting)
|
|
62
59
|
- [Contributing](#contributing)
|
|
63
60
|
- [License](#license)
|
|
64
61
|
|
|
@@ -99,7 +96,7 @@ This RAG-based approach provides more accurate, project-specific code reviews co
|
|
|
99
96
|
|
|
100
97
|
### Prerequisites
|
|
101
98
|
|
|
102
|
-
- **Node.js** v22.
|
|
99
|
+
- **Node.js** v22.14.0 or higher
|
|
103
100
|
- **Git** (for diff-based analysis)
|
|
104
101
|
- **Anthropic API key** (for LLM analysis)
|
|
105
102
|
|
|
@@ -202,7 +199,7 @@ For easier integration with non-JavaScript projects, you can use the provided sh
|
|
|
202
199
|
|
|
203
200
|
3. **Environment setup** (the script handles this automatically):
|
|
204
201
|
- Creates/uses `.env` file in your project directory
|
|
205
|
-
- Validates Node.js v22.
|
|
202
|
+
- Validates Node.js v22.14.0+ requirement
|
|
206
203
|
- Provides helpful error messages for missing dependencies
|
|
207
204
|
|
|
208
205
|
## Quick Start
|
|
@@ -336,6 +333,7 @@ jobs:
|
|
|
336
333
|
- name: Generate Embeddings
|
|
337
334
|
uses: cosmocoder/CodeCritique/.github/actions/generate-embeddings@main
|
|
338
335
|
with:
|
|
336
|
+
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
339
337
|
verbose: true
|
|
340
338
|
```
|
|
341
339
|
|
|
@@ -343,6 +341,7 @@ jobs:
|
|
|
343
341
|
|
|
344
342
|
| Parameter | Description | Required | Default |
|
|
345
343
|
| --------------------------- | ------------------------------------------------------- | -------- | ---------------- |
|
|
344
|
+
| `anthropic-api-key` | Anthropic API key for Claude models | **Yes** | - |
|
|
346
345
|
| `files` | Specific files or patterns to process (space-separated) | No | `''` (all files) |
|
|
347
346
|
| `concurrency` | Number of concurrent embedding requests | No | Auto-detected |
|
|
348
347
|
| `exclude` | Patterns to exclude (space-separated glob patterns) | No | `''` |
|
|
@@ -350,28 +349,7 @@ jobs:
|
|
|
350
349
|
| `verbose` | Show verbose output | No | `false` |
|
|
351
350
|
| `embeddings-retention-days` | Number of days to retain embedding artifacts | No | `30` |
|
|
352
351
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
##### Processing Specific Files
|
|
356
|
-
|
|
357
|
-
```yaml
|
|
358
|
-
- name: Generate Embeddings for TypeScript Files
|
|
359
|
-
uses: cosmocoder/CodeCritique/.github/actions/generate-embeddings@main
|
|
360
|
-
with:
|
|
361
|
-
files: 'src/**/*.ts src/**/*.tsx'
|
|
362
|
-
exclude: '**/*.test.ts **/*.spec.ts'
|
|
363
|
-
verbose: true
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
##### High Performance Setup
|
|
367
|
-
|
|
368
|
-
```yaml
|
|
369
|
-
- name: Generate Embeddings (High Performance)
|
|
370
|
-
uses: cosmocoder/CodeCritique/.github/actions/generate-embeddings@main
|
|
371
|
-
with:
|
|
372
|
-
concurrency: 20
|
|
373
|
-
embeddings-retention-days: 60
|
|
374
|
-
```
|
|
352
|
+
> **See [GitHub Actions Advanced Configuration](docs/GITHUB_ACTIONS.md)** for processing specific files, high performance setup, and more examples.
|
|
375
353
|
|
|
376
354
|
---
|
|
377
355
|
|
|
@@ -423,15 +401,16 @@ jobs:
|
|
|
423
401
|
|
|
424
402
|
#### Input Parameters
|
|
425
403
|
|
|
426
|
-
| Parameter | Description
|
|
427
|
-
| ------------------- |
|
|
428
|
-
| `anthropic-api-key` | Anthropic API key for Claude models
|
|
429
|
-
| `skip-label` | Label name to skip AI review
|
|
430
|
-
| `verbose` | Show verbose output
|
|
431
|
-
| `model` | LLM model to use (e.g., `claude-sonnet-4-
|
|
432
|
-
| `max-tokens` | Maximum tokens for LLM response
|
|
433
|
-
| `
|
|
434
|
-
| `
|
|
404
|
+
| Parameter | Description | Required | Default |
|
|
405
|
+
| ------------------- | -------------------------------------------------------------------------------------------------------- | -------- | -------------------- |
|
|
406
|
+
| `anthropic-api-key` | Anthropic API key for Claude models | **Yes** | - |
|
|
407
|
+
| `skip-label` | Label name to skip AI review | No | `ai-review-disabled` |
|
|
408
|
+
| `verbose` | Show verbose output | No | `false` |
|
|
409
|
+
| `model` | LLM model to use (e.g., `claude-sonnet-4-5`) | No | Auto-selected |
|
|
410
|
+
| `max-tokens` | Maximum tokens for LLM response | No | Auto-calculated |
|
|
411
|
+
| `cache-ttl` | Cache TTL for LLM prompts: "5m" (default, no extra cost) or "1h" (extended, extra cost for cache writes) | No | `5m` |
|
|
412
|
+
| `concurrency` | Concurrency for processing multiple files | No | `3` |
|
|
413
|
+
| `custom-docs` | Custom documents (format: `"title:path,title:path"`) | No | `''` |
|
|
435
414
|
|
|
436
415
|
> **Note**: The action uses sensible defaults for all review parameters. It always:
|
|
437
416
|
>
|
|
@@ -441,381 +420,59 @@ jobs:
|
|
|
441
420
|
> - Tracks feedback to improve future reviews
|
|
442
421
|
> - Uses optimal temperature and similarity thresholds
|
|
443
422
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
The action provides several outputs that can be used in subsequent workflow steps:
|
|
447
|
-
|
|
448
|
-
| Output | Description |
|
|
449
|
-
| ------------------------ | -------------------------------------- |
|
|
450
|
-
| `comments-posted` | Number of review comments posted |
|
|
451
|
-
| `issues-found` | Total number of issues found |
|
|
452
|
-
| `files-analyzed` | Number of files analyzed |
|
|
453
|
-
| `analysis-time` | Time taken for analysis (seconds) |
|
|
454
|
-
| `embedding-cache-hit` | Whether embeddings were found and used |
|
|
455
|
-
| `review-score` | Overall review score (0-100) |
|
|
456
|
-
| `security-issues` | Number of security issues found |
|
|
457
|
-
| `performance-issues` | Number of performance issues found |
|
|
458
|
-
| `maintainability-issues` | Number of maintainability issues found |
|
|
459
|
-
| `review-report-path` | Path to the detailed review report |
|
|
460
|
-
|
|
461
|
-
#### Advanced Configuration Examples
|
|
462
|
-
|
|
463
|
-
##### Skipping Reviews with Labels
|
|
464
|
-
|
|
465
|
-
You can skip AI reviews for specific PRs by adding a label. This is useful when:
|
|
466
|
-
|
|
467
|
-
- You want to merge urgent hotfixes without waiting for AI review
|
|
468
|
-
- The PR contains only documentation or configuration changes
|
|
469
|
-
- You're making experimental changes that don't need review
|
|
470
|
-
|
|
471
|
-
By default, the action checks for the `ai-review-disabled` label, but you can customize this:
|
|
472
|
-
|
|
473
|
-
```yaml
|
|
474
|
-
- name: AI Code Review (Customizable Skip)
|
|
475
|
-
uses: cosmocoder/CodeCritique/.github/actions/pr-review@main
|
|
476
|
-
with:
|
|
477
|
-
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
478
|
-
skip-label: 'no-ai-review' # Custom label name
|
|
479
|
-
```
|
|
480
|
-
|
|
481
|
-
When a PR has the skip label, the workflow will exit early with a message:
|
|
482
|
-
|
|
483
|
-
```
|
|
484
|
-
⏭️ Skipping AI review - PR has 'ai-review-disabled' label
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
To use this feature:
|
|
488
|
-
|
|
489
|
-
1. Add the label to your repository (e.g., create a label named `ai-review-disabled`)
|
|
490
|
-
2. Add the label to any PR you want to skip
|
|
491
|
-
3. The action will automatically detect it and skip the review
|
|
492
|
-
|
|
493
|
-
##### Custom Model and Performance Settings
|
|
494
|
-
|
|
495
|
-
```yaml
|
|
496
|
-
- name: AI Code Review with Custom Settings
|
|
497
|
-
uses: cosmocoder/CodeCritique/.github/actions/pr-review@main
|
|
498
|
-
with:
|
|
499
|
-
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
500
|
-
model: 'claude-3-5-sonnet-20241022'
|
|
501
|
-
max-tokens: '4000'
|
|
502
|
-
concurrency: '5'
|
|
503
|
-
verbose: true
|
|
504
|
-
```
|
|
505
|
-
|
|
506
|
-
##### With Custom Documentation
|
|
507
|
-
|
|
508
|
-
```yaml
|
|
509
|
-
- name: AI Code Review with Team Guidelines
|
|
510
|
-
uses: cosmocoder/CodeCritique/.github/actions/pr-review@main
|
|
511
|
-
with:
|
|
512
|
-
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
513
|
-
custom-docs: 'Style Guide:./docs/style-guide.md,API Standards:./docs/api-standards.md'
|
|
514
|
-
verbose: true
|
|
515
|
-
```
|
|
423
|
+
> **See [GitHub Actions Advanced Configuration](docs/GITHUB_ACTIONS.md)** for output values, skipping reviews with labels, custom model settings, and more.
|
|
516
424
|
|
|
517
425
|
---
|
|
518
426
|
|
|
519
427
|
## Commands Reference
|
|
520
428
|
|
|
521
|
-
|
|
429
|
+
CodeCritique provides commands for code analysis, embedding management, and PR history analysis.
|
|
522
430
|
|
|
523
|
-
|
|
431
|
+
### Core Commands
|
|
524
432
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
|
532
|
-
|
|
|
533
|
-
|
|
|
534
|
-
|
|
|
535
|
-
| `--file <file>` | Analyze a single file | - |
|
|
536
|
-
| `-d, --directory <dir>` | Working directory for git operations (use with --diff-with) | - |
|
|
537
|
-
| `-o, --output <format>` | Output format (text, json, markdown) | `text` |
|
|
538
|
-
| `--no-color` | Disable colored output | `false` |
|
|
539
|
-
| `--verbose` | Show verbose output | `false` |
|
|
433
|
+
| Command | Description |
|
|
434
|
+
| ---------------------- | ------------------------------------------------------ |
|
|
435
|
+
| `analyze` | Analyze code using RAG with context retrieval |
|
|
436
|
+
| `embeddings:generate` | Generate embeddings for your codebase |
|
|
437
|
+
| `embeddings:stats` | Show statistics about stored embeddings |
|
|
438
|
+
| `embeddings:clear` | Clear embeddings for current project |
|
|
439
|
+
| `embeddings:clear-all` | Clear ALL embeddings (all projects - use with caution) |
|
|
440
|
+
| `pr-history:analyze` | Analyze PR comment history |
|
|
441
|
+
| `pr-history:status` | Check PR analysis status |
|
|
442
|
+
| `pr-history:clear` | Clear PR analysis data |
|
|
540
443
|
|
|
541
|
-
|
|
542
|
-
| `--temperature <number>` | LLM temperature | `0.2` |
|
|
543
|
-
| `--max-tokens <number>` | LLM max tokens | `8192` |
|
|
544
|
-
| `--similarity-threshold <number>` | Threshold for finding similar code examples | `0.6` |
|
|
545
|
-
| `--max-examples <number>` | Max similar code examples to use | `5` |
|
|
546
|
-
| `--concurrency <number>` | Concurrency for processing multiple files | `3` |
|
|
547
|
-
| `--doc <specs...>` | Custom documents to provide to LLM (format: "Title:./path/to/file.md") | - |
|
|
548
|
-
|
|
549
|
-
#### Examples
|
|
444
|
+
### Quick Examples
|
|
550
445
|
|
|
551
446
|
```bash
|
|
552
447
|
# Analyze a single file
|
|
553
448
|
codecritique analyze --file src/components/Button.tsx
|
|
554
449
|
|
|
555
|
-
# Analyze
|
|
556
|
-
codecritique analyze --files "src/**/*.
|
|
450
|
+
# Analyze files matching patterns
|
|
451
|
+
codecritique analyze --files "src/**/*.ts" "lib/*.js"
|
|
557
452
|
|
|
558
|
-
# Analyze
|
|
453
|
+
# Analyze branch diff
|
|
559
454
|
codecritique analyze --diff-with feature-branch
|
|
560
455
|
|
|
561
|
-
#
|
|
562
|
-
codecritique analyze --file src/utils/validation.ts \
|
|
563
|
-
--doc "Engineering Guidelines:./docs/guidelines.md"
|
|
564
|
-
|
|
565
|
-
# Analyze with custom LLM settings
|
|
566
|
-
codecritique analyze --file app.py \
|
|
567
|
-
--temperature 0.1 \
|
|
568
|
-
--max-tokens 4096 \
|
|
569
|
-
--similarity-threshold 0.7
|
|
570
|
-
|
|
571
|
-
# Analyze changes in specific directory
|
|
572
|
-
codecritique analyze --diff-with feature-branch --directory /path/to/repo
|
|
573
|
-
|
|
574
|
-
# Output as JSON
|
|
575
|
-
codecritique analyze --files "src/**/*.ts" --output json > review.json
|
|
576
|
-
```
|
|
577
|
-
|
|
578
|
-
### embeddings:generate
|
|
579
|
-
|
|
580
|
-
Generate embeddings for the codebase to enable context-aware analysis.
|
|
581
|
-
|
|
582
|
-
```bash
|
|
583
|
-
codecritique embeddings:generate [options]
|
|
584
|
-
```
|
|
585
|
-
|
|
586
|
-
#### Options
|
|
587
|
-
|
|
588
|
-
| Option | Description | Default |
|
|
589
|
-
| ---------------------------- | ------------------------------------------------------------------------------ | ------- |
|
|
590
|
-
| `-d, --directory <dir>` | Directory to process | `.` |
|
|
591
|
-
| `-f, --files <files...>` | Specific files or patterns to process | - |
|
|
592
|
-
| `-c, --concurrency <number>` | Number of concurrent embedding requests | `10` |
|
|
593
|
-
| `--verbose` | Show verbose output | `false` |
|
|
594
|
-
| `--exclude <patterns...>` | Patterns to exclude (e.g., "**/\*.test.js" "docs/**") | - |
|
|
595
|
-
| `--exclude-file <file>` | File containing patterns to exclude (one per line) | - |
|
|
596
|
-
| `--no-gitignore` | Disable automatic exclusion of files in .gitignore | `false` |
|
|
597
|
-
| `--max-lines` | Maximum lines per code file that will be considered when generating embeddings | `1000` |
|
|
598
|
-
| `--force-analysis` | Force regeneration of project analysis summary (bypasses cache) | `false` |
|
|
599
|
-
|
|
600
|
-
#### Examples
|
|
601
|
-
|
|
602
|
-
```bash
|
|
603
|
-
# Generate embeddings for current directory
|
|
604
|
-
codecritique embeddings:generate
|
|
605
|
-
|
|
606
|
-
# Generate for specific directory
|
|
456
|
+
# Generate embeddings
|
|
607
457
|
codecritique embeddings:generate --directory src
|
|
608
458
|
|
|
609
|
-
#
|
|
610
|
-
codecritique
|
|
611
|
-
|
|
612
|
-
# Exclude test files and docs
|
|
613
|
-
codecritique embeddings:generate --exclude "**/*.test.js" "**/*.spec.js" "docs/**"
|
|
614
|
-
|
|
615
|
-
# Use exclusion file
|
|
616
|
-
codecritique embeddings:generate --exclude-file exclusion-patterns.txt
|
|
617
|
-
|
|
618
|
-
# Process without gitignore exclusions
|
|
619
|
-
codecritique embeddings:generate --no-gitignore
|
|
620
|
-
|
|
621
|
-
# High concurrency for large codebases
|
|
622
|
-
codecritique embeddings:generate --concurrency 20 --verbose
|
|
623
|
-
|
|
624
|
-
# Force regeneration of project analysis (useful after major codebase changes)
|
|
625
|
-
codecritique embeddings:generate --force-analysis --verbose
|
|
626
|
-
|
|
627
|
-
# Combine force analysis with specific directory processing
|
|
628
|
-
codecritique embeddings:generate --directory src --force-analysis
|
|
629
|
-
```
|
|
630
|
-
|
|
631
|
-
### embeddings:stats
|
|
632
|
-
|
|
633
|
-
Show statistics about stored embeddings.
|
|
634
|
-
|
|
635
|
-
```bash
|
|
636
|
-
codecritique embeddings:stats [options]
|
|
637
|
-
```
|
|
638
|
-
|
|
639
|
-
#### Options
|
|
640
|
-
|
|
641
|
-
| Option | Description | Default |
|
|
642
|
-
| ----------------------- | -------------------------------------------------------------------------------- | ------- |
|
|
643
|
-
| `-d, --directory <dir>` | Directory of the project to show stats for (shows all projects if not specified) | - |
|
|
644
|
-
|
|
645
|
-
#### Examples
|
|
646
|
-
|
|
647
|
-
```bash
|
|
648
|
-
# Show stats for all projects
|
|
649
|
-
codecritique embeddings:stats
|
|
650
|
-
|
|
651
|
-
# Show stats for specific project
|
|
652
|
-
codecritique embeddings:stats --directory /path/to/project
|
|
653
|
-
```
|
|
654
|
-
|
|
655
|
-
### embeddings:clear
|
|
656
|
-
|
|
657
|
-
Clear stored embeddings for the current project.
|
|
658
|
-
|
|
659
|
-
```bash
|
|
660
|
-
codecritique embeddings:clear [options]
|
|
661
|
-
```
|
|
662
|
-
|
|
663
|
-
#### Options
|
|
664
|
-
|
|
665
|
-
| Option | Description | Default |
|
|
666
|
-
| ----------------------- | ------------------------------------------------ | ------- |
|
|
667
|
-
| `-d, --directory <dir>` | Directory of the project to clear embeddings for | `.` |
|
|
668
|
-
|
|
669
|
-
#### Examples
|
|
670
|
-
|
|
671
|
-
```bash
|
|
672
|
-
# Clear embeddings for current project
|
|
673
|
-
codecritique embeddings:clear
|
|
674
|
-
|
|
675
|
-
# Clear embeddings for specific project
|
|
676
|
-
codecritique embeddings:clear --directory /path/to/project
|
|
677
|
-
```
|
|
678
|
-
|
|
679
|
-
### embeddings:clear-all
|
|
680
|
-
|
|
681
|
-
Clear ALL stored embeddings (affects all projects - use with caution).
|
|
682
|
-
|
|
683
|
-
```bash
|
|
684
|
-
codecritique embeddings:clear-all
|
|
685
|
-
```
|
|
686
|
-
|
|
687
|
-
**Warning**: This command clears embeddings for all projects on the machine.
|
|
688
|
-
|
|
689
|
-
### pr-history:analyze
|
|
690
|
-
|
|
691
|
-
Analyze PR comment history for the current project or specified repository.
|
|
692
|
-
|
|
693
|
-
```bash
|
|
694
|
-
codecritique pr-history:analyze [options]
|
|
459
|
+
# Analyze PR history
|
|
460
|
+
codecritique pr-history:analyze --repository owner/repo
|
|
695
461
|
```
|
|
696
462
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
| Option | Description | Default |
|
|
700
|
-
| ------------------------- | ------------------------------------------------------------------- | ------- |
|
|
701
|
-
| `-d, --directory <dir>` | Project directory to analyze (auto-detects GitHub repo) | `.` |
|
|
702
|
-
| `-r, --repository <repo>` | GitHub repository in format "owner/repo" (overrides auto-detection) | - |
|
|
703
|
-
| `-t, --token <token>` | GitHub API token (or set GITHUB_TOKEN env var) | - |
|
|
704
|
-
| `--since <date>` | Only analyze PRs since this date (ISO format) | - |
|
|
705
|
-
| `--until <date>` | Only analyze PRs until this date (ISO format) | - |
|
|
706
|
-
| `--limit <number>` | Limit number of PRs to analyze | - |
|
|
707
|
-
| `--resume` | Resume interrupted analysis | `false` |
|
|
708
|
-
| `--clear` | Clear existing data before analysis | `false` |
|
|
709
|
-
| `--concurrency <number>` | Number of concurrent requests | `2` |
|
|
710
|
-
| `--batch-size <number>` | Batch size for processing | `50` |
|
|
711
|
-
| `--verbose` | Show verbose output | `false` |
|
|
712
|
-
|
|
713
|
-
#### Examples
|
|
714
|
-
|
|
715
|
-
```bash
|
|
716
|
-
# Analyze current project (auto-detect repo)
|
|
717
|
-
codecritique pr-history:analyze
|
|
718
|
-
|
|
719
|
-
# Analyze specific repository
|
|
720
|
-
codecritique pr-history:analyze --repository owner/repo --token ghp_xxx
|
|
721
|
-
|
|
722
|
-
# Analyze with date range
|
|
723
|
-
codecritique pr-history:analyze --since 2024-01-01 --until 2024-12-31
|
|
463
|
+
> **See [Commands Reference](docs/COMMANDS.md)** for complete documentation of all commands, options, and examples.
|
|
724
464
|
|
|
725
|
-
|
|
726
|
-
codecritique pr-history:analyze --clear --limit 100
|
|
727
|
-
|
|
728
|
-
# Resume interrupted analysis
|
|
729
|
-
codecritique pr-history:analyze --resume
|
|
730
|
-
```
|
|
731
|
-
|
|
732
|
-
### pr-history:status
|
|
733
|
-
|
|
734
|
-
Check PR analysis status for the current project or specified repository.
|
|
735
|
-
|
|
736
|
-
```bash
|
|
737
|
-
codecritique pr-history:status [options]
|
|
738
|
-
```
|
|
739
|
-
|
|
740
|
-
#### Options
|
|
741
|
-
|
|
742
|
-
| Option | Description | Default |
|
|
743
|
-
| ------------------------- | ------------------------------------------------------------------- | ------- |
|
|
744
|
-
| `-d, --directory <dir>` | Project directory to check status for | `.` |
|
|
745
|
-
| `-r, --repository <repo>` | GitHub repository in format "owner/repo" (overrides auto-detection) | - |
|
|
746
|
-
|
|
747
|
-
#### Examples
|
|
748
|
-
|
|
749
|
-
```bash
|
|
750
|
-
# Check status for current project
|
|
751
|
-
codecritique pr-history:status
|
|
752
|
-
|
|
753
|
-
# Check status for specific repository
|
|
754
|
-
codecritique pr-history:status --repository owner/repo
|
|
755
|
-
```
|
|
756
|
-
|
|
757
|
-
### pr-history:clear
|
|
758
|
-
|
|
759
|
-
Clear PR analysis data for the current project or specified repository.
|
|
760
|
-
|
|
761
|
-
```bash
|
|
762
|
-
codecritique pr-history:clear [options]
|
|
763
|
-
```
|
|
764
|
-
|
|
765
|
-
#### Options
|
|
766
|
-
|
|
767
|
-
| Option | Description | Default |
|
|
768
|
-
| ------------------------- | ------------------------------------------------------------------- | ------- |
|
|
769
|
-
| `-d, --directory <dir>` | Project directory to clear data for | `.` |
|
|
770
|
-
| `-r, --repository <repo>` | GitHub repository in format "owner/repo" (overrides auto-detection) | - |
|
|
771
|
-
| `--force` | Skip confirmation prompts | `false` |
|
|
772
|
-
|
|
773
|
-
#### Examples
|
|
774
|
-
|
|
775
|
-
```bash
|
|
776
|
-
# Clear data for current project (with confirmation)
|
|
777
|
-
codecritique pr-history:clear
|
|
778
|
-
|
|
779
|
-
# Clear data for specific repository without confirmation
|
|
780
|
-
codecritique pr-history:clear --repository owner/repo --force
|
|
781
|
-
```
|
|
465
|
+
---
|
|
782
466
|
|
|
783
467
|
## RAG Architecture
|
|
784
468
|
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
The Retrieval-Augmented Generation (RAG) approach enhances traditional AI code review by providing rich context:
|
|
788
|
-
|
|
789
|
-
```mermaid
|
|
790
|
-
graph TD
|
|
791
|
-
A[Code Input] --> B[File Analysis]
|
|
792
|
-
B --> C[Context Retrieval]
|
|
793
|
-
C --> D[Similar Code Examples]
|
|
794
|
-
C --> E[Relevant Documentation]
|
|
795
|
-
C --> F[PR History Patterns]
|
|
796
|
-
C --> G[Custom Guidelines]
|
|
797
|
-
D --> H[LLM Analysis]
|
|
798
|
-
E --> H
|
|
799
|
-
F --> H
|
|
800
|
-
G --> H
|
|
801
|
-
H --> I[Contextualized Review]
|
|
802
|
-
```
|
|
803
|
-
|
|
804
|
-
### Components
|
|
469
|
+
CodeCritique uses **Retrieval-Augmented Generation (RAG)** to provide context-aware code analysis. Instead of generic static analysis, it retrieves relevant context from your codebase (similar code examples, documentation, PR history) and provides this to the LLM for more accurate, project-specific reviews.
|
|
805
470
|
|
|
806
|
-
|
|
807
|
-
2. **Vector Database**: LanceDB stores embeddings for fast similarity search
|
|
808
|
-
3. **Context Retrieval**: Finds relevant code examples, documentation, and historical patterns
|
|
809
|
-
4. **LLM Integration**: Anthropic Claude analyzes code with rich contextual information
|
|
810
|
-
5. **PR History Analyzer**: Learns from past code review patterns in your repository
|
|
471
|
+
Key components include local embeddings via FastEmbed, vector storage with LanceDB, and LLM analysis with Anthropic Claude.
|
|
811
472
|
|
|
812
|
-
|
|
473
|
+
> **See [Architecture Documentation](docs/ARCHITECTURE.md)** for detailed diagrams, component descriptions, and benefits.
|
|
813
474
|
|
|
814
|
-
|
|
815
|
-
- **Learning**: Improves recommendations based on historical data
|
|
816
|
-
- **Comprehensive**: Considers code, docs, and review history together
|
|
817
|
-
- **Efficient**: Local embeddings provide fast context retrieval
|
|
818
|
-
- **Privacy**: Embeddings are stored locally, code never leaves your machine
|
|
475
|
+
---
|
|
819
476
|
|
|
820
477
|
## Configuration
|
|
821
478
|
|
|
@@ -879,213 +536,30 @@ VERBOSE=true
|
|
|
879
536
|
|
|
880
537
|
## Output Formats
|
|
881
538
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
Human-readable colored output for terminal usage:
|
|
885
|
-
|
|
886
|
-
```
|
|
887
|
-
===== AI Code Review Summary =====
|
|
888
|
-
Files Analyzed: 3
|
|
889
|
-
Files with Issues: 2
|
|
890
|
-
Total Issues Found: 5
|
|
891
|
-
|
|
892
|
-
===== Review for src/components/Button.tsx =====
|
|
893
|
-
Summary: Component has naming inconsistency and missing prop validation
|
|
894
|
-
|
|
895
|
-
Issues:
|
|
896
|
-
[MAJOR] (Lines: 5) Component name 'ButtonComponent' doesn't match filename 'Button'
|
|
897
|
-
Suggestion: Rename component to 'Button' or update file name
|
|
898
|
-
|
|
899
|
-
[MINOR] (Lines: 12-15) Missing prop type validation
|
|
900
|
-
Suggestion: Add PropTypes or TypeScript interface
|
|
901
|
-
|
|
902
|
-
Positives:
|
|
903
|
-
- Good use of semantic HTML elements
|
|
904
|
-
- Proper accessibility attributes
|
|
905
|
-
```
|
|
906
|
-
|
|
907
|
-
### JSON
|
|
908
|
-
|
|
909
|
-
Structured output for programmatic processing:
|
|
910
|
-
|
|
911
|
-
```json
|
|
912
|
-
{
|
|
913
|
-
"summary": {
|
|
914
|
-
"totalFilesReviewed": 3,
|
|
915
|
-
"filesWithIssues": 2,
|
|
916
|
-
"totalIssues": 5,
|
|
917
|
-
"skippedFiles": 0,
|
|
918
|
-
"errorFiles": 0
|
|
919
|
-
},
|
|
920
|
-
"details": [
|
|
921
|
-
{
|
|
922
|
-
"filePath": "src/components/Button.tsx",
|
|
923
|
-
"success": true,
|
|
924
|
-
"language": "typescript",
|
|
925
|
-
"review": {
|
|
926
|
-
"summary": "Component has naming inconsistency and missing prop validation",
|
|
927
|
-
"issues": [
|
|
928
|
-
{
|
|
929
|
-
"severity": "major",
|
|
930
|
-
"description": "Component name 'ButtonComponent' doesn't match filename 'Button'",
|
|
931
|
-
"lineNumbers": [5],
|
|
932
|
-
"suggestion": "Rename component to 'Button' or update file name"
|
|
933
|
-
}
|
|
934
|
-
],
|
|
935
|
-
"positives": ["Good use of semantic HTML elements", "Proper accessibility attributes"]
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
]
|
|
939
|
-
}
|
|
940
|
-
```
|
|
941
|
-
|
|
942
|
-
### Markdown
|
|
943
|
-
|
|
944
|
-
Documentation-friendly format:
|
|
945
|
-
|
|
946
|
-
```markdown
|
|
947
|
-
# AI Code Review Results (RAG Approach)
|
|
948
|
-
|
|
949
|
-
## Summary
|
|
950
|
-
|
|
951
|
-
- **Files Analyzed:** 3
|
|
952
|
-
- **Files with Issues:** 2
|
|
953
|
-
- **Total Issues Found:** 5
|
|
954
|
-
|
|
955
|
-
## Detailed Review per File
|
|
956
|
-
|
|
957
|
-
### src/components/Button.tsx
|
|
958
|
-
|
|
959
|
-
**Summary:** Component has naming inconsistency and missing prop validation
|
|
960
|
-
|
|
961
|
-
**Issues Found (2):**
|
|
962
|
-
|
|
963
|
-
- **[MAJOR] 🔥 (Lines: 5)**: Component name 'ButtonComponent' doesn't match filename 'Button'
|
|
964
|
-
- **[MINOR] 💡 (Lines: 12-15)**: Missing prop type validation
|
|
965
|
-
|
|
966
|
-
**Positives Found (2):**
|
|
967
|
-
|
|
968
|
-
- Good use of semantic HTML elements
|
|
969
|
-
- Proper accessibility attributes
|
|
970
|
-
```
|
|
971
|
-
|
|
972
|
-
## Error Handling & Troubleshooting
|
|
973
|
-
|
|
974
|
-
### Common Issues
|
|
975
|
-
|
|
976
|
-
#### API Key Issues
|
|
977
|
-
|
|
978
|
-
**Error**: `ANTHROPIC_API_KEY not found in environment variables`
|
|
979
|
-
|
|
980
|
-
**Solution**:
|
|
981
|
-
|
|
982
|
-
```bash
|
|
983
|
-
# Set environment variable
|
|
984
|
-
export ANTHROPIC_API_KEY=your_api_key
|
|
985
|
-
|
|
986
|
-
# Or create .env file
|
|
987
|
-
echo "ANTHROPIC_API_KEY=your_api_key" > .env
|
|
988
|
-
```
|
|
989
|
-
|
|
990
|
-
#### Git Repository Issues
|
|
991
|
-
|
|
992
|
-
**Error**: `Not a git repository`
|
|
993
|
-
|
|
994
|
-
**Solution**: Ensure you're in a git repository when using `--diff-with`:
|
|
539
|
+
CodeCritique supports three output formats:
|
|
995
540
|
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
git commit -m "Initial commit"
|
|
1000
|
-
```
|
|
1001
|
-
|
|
1002
|
-
#### File Not Found
|
|
1003
|
-
|
|
1004
|
-
**Error**: `File not found: path/to/file.js`
|
|
1005
|
-
|
|
1006
|
-
**Solution**: Check file path and ensure it exists:
|
|
541
|
+
- **Text** (default) - Human-readable colored output for terminal usage
|
|
542
|
+
- **JSON** - Structured output for programmatic processing
|
|
543
|
+
- **Markdown** - Documentation-friendly format
|
|
1007
544
|
|
|
1008
545
|
```bash
|
|
1009
|
-
|
|
1010
|
-
codecritique analyze --file /
|
|
1011
|
-
|
|
1012
|
-
# Or relative from current directory
|
|
1013
|
-
ls path/to/file.js # Verify file exists
|
|
1014
|
-
```
|
|
1015
|
-
|
|
1016
|
-
#### Embedding Generation Issues
|
|
1017
|
-
|
|
1018
|
-
**Error**: `Failed to generate embeddings`
|
|
1019
|
-
|
|
1020
|
-
**Solutions**:
|
|
1021
|
-
|
|
1022
|
-
```bash
|
|
1023
|
-
# Clear existing embeddings and regenerate
|
|
1024
|
-
codecritique embeddings:clear
|
|
1025
|
-
codecritique embeddings:generate --verbose
|
|
1026
|
-
|
|
1027
|
-
# Reduce concurrency for memory issues
|
|
1028
|
-
codecritique embeddings:generate --concurrency 5
|
|
1029
|
-
|
|
1030
|
-
# Exclude problematic files
|
|
1031
|
-
codecritique embeddings:generate --exclude "large-files/**"
|
|
546
|
+
codecritique analyze --file src/app.ts --output json
|
|
547
|
+
codecritique analyze --file src/app.ts --output markdown
|
|
1032
548
|
```
|
|
1033
549
|
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
**Error**: `JavaScript heap out of memory`
|
|
550
|
+
> **See [Output Formats](docs/OUTPUT_FORMATS.md)** for detailed examples of each format.
|
|
1037
551
|
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
```bash
|
|
1041
|
-
# Increase Node.js memory limit
|
|
1042
|
-
export NODE_OPTIONS="--max-old-space-size=4096"
|
|
1043
|
-
|
|
1044
|
-
# Process fewer files at once
|
|
1045
|
-
codecritique embeddings:generate --concurrency 3
|
|
1046
|
-
|
|
1047
|
-
# Exclude large files
|
|
1048
|
-
codecritique embeddings:generate --exclude "**/*.min.js" "dist/**"
|
|
1049
|
-
```
|
|
552
|
+
---
|
|
1050
553
|
|
|
1051
|
-
|
|
554
|
+
If you encounter issues, see the **[Troubleshooting Guide](docs/TROUBLESHOOTING.md)** for solutions to common problems including API key issues, memory errors, and performance optimization tips.
|
|
1052
555
|
|
|
1053
|
-
|
|
556
|
+
For quick debugging, use verbose mode:
|
|
1054
557
|
|
|
1055
558
|
```bash
|
|
1056
559
|
codecritique analyze --file app.py --verbose
|
|
1057
560
|
```
|
|
1058
561
|
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
```bash
|
|
1062
|
-
DEBUG=true codecritique analyze --file app.py
|
|
1063
|
-
```
|
|
1064
|
-
|
|
1065
|
-
### Performance Optimization
|
|
1066
|
-
|
|
1067
|
-
1. **Generate embeddings first** for better context:
|
|
1068
|
-
|
|
1069
|
-
```bash
|
|
1070
|
-
codecritique embeddings:generate
|
|
1071
|
-
codecritique analyze --files "src/**/*.ts"
|
|
1072
|
-
```
|
|
1073
|
-
|
|
1074
|
-
2. **Use exclusion patterns** to skip irrelevant files:
|
|
1075
|
-
|
|
1076
|
-
```bash
|
|
1077
|
-
codecritique embeddings:generate --exclude "**/*.test.js" "dist/**"
|
|
1078
|
-
```
|
|
1079
|
-
|
|
1080
|
-
3. **Adjust concurrency** based on system resources:
|
|
1081
|
-
|
|
1082
|
-
```bash
|
|
1083
|
-
# For powerful machines
|
|
1084
|
-
codecritique embeddings:generate --concurrency 20
|
|
1085
|
-
|
|
1086
|
-
# For resource-constrained environments
|
|
1087
|
-
codecritique embeddings:generate --concurrency 3
|
|
1088
|
-
```
|
|
562
|
+
---
|
|
1089
563
|
|
|
1090
564
|
## Contributing
|
|
1091
565
|
|