code-digest 0.5.0

High-performance CLI tool to convert codebases to Markdown for LLM context
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
# Examples

Real-world examples of using code-digest for various scenarios and project types.

## Quick Start Examples

### Basic Project Analysis

```bash
# Analyze current directory
code-digest

# Analyze specific project
code-digest -d ~/projects/my-app

# Save analysis to file
code-digest -d ~/projects/my-app -o analysis.md

# Get quick overview with token limit
code-digest -d ~/projects/my-app --max-tokens 10000
```

### LLM Integration Examples

```bash
# Ask specific questions about the codebase
code-digest -d ~/projects/web-app "What does this application do?"

code-digest -d ~/projects/api "How is authentication implemented?"

code-digest -d ~/projects/ml-model "Explain the machine learning pipeline"

# Code review and analysis
code-digest -d ~/projects/feature-branch "Review this code for security issues"

code-digest -d ~/projects/legacy-app "Identify technical debt and improvement opportunities"
```

## Project Type Examples

### Rust Projects

```bash
# Rust project with Cargo
cd ~/rust-projects/web-server
code-digest -d . -o rust-analysis.md --max-tokens 50000

# Focus on core functionality
code-digest -d src/ --max-tokens 25000 "Explain the main application architecture"

# Configuration for Rust projects
cat > .code-digest.toml << EOF
[defaults]
max_tokens = 75000
progress = true

ignore = ["target/", "Cargo.lock"]

[[priorities]]
pattern = "src/main.rs"
weight = 200.0

[[priorities]]
pattern = "src/lib.rs"
weight = 180.0

[[priorities]]
pattern = "src/**/*.rs"
weight = 150.0

[[priorities]]
pattern = "Cargo.toml"
weight = 120.0
EOF
```

### JavaScript/Node.js Projects

```bash
# Node.js project analysis
cd ~/js-projects/express-api
code-digest -d . -o nodejs-analysis.md

# Focus on source code, ignore dependencies
code-digest -d src/ --max-tokens 40000

# Configuration for Node.js projects
cat > .code-digest.toml << EOF
[defaults]
max_tokens = 60000
progress = true

ignore = [
    "node_modules/",
    "dist/",
    "build/",
    "coverage/",
    "*.log"
]

[[priorities]]
pattern = "src/index.*"
weight = 200.0

[[priorities]]
pattern = "src/**/*.js"
weight = 150.0

[[priorities]]
pattern = "src/**/*.ts"
weight = 150.0

[[priorities]]
pattern = "package.json"
weight = 120.0

[[priorities]]
pattern = "*.config.js"
weight = 100.0
EOF
```

### Python Projects

```bash
# Python project analysis
cd ~/python-projects/django-app
code-digest -d . -o python-analysis.md

# Django-specific analysis
code-digest -d . "Explain the Django models and views structure"

# Configuration for Python projects
cat > .code-digest.toml << EOF
[defaults]
max_tokens = 55000
progress = true

ignore = [
    "__pycache__/",
    "*.pyc",
    "*.pyo",
    ".venv/",
    "venv/",
    ".pytest_cache/",
    "htmlcov/",
    "dist/",
    "build/",
    "*.egg-info/"
]

[[priorities]]
pattern = "main.py"
weight = 200.0

[[priorities]]
pattern = "app.py"
weight = 200.0

[[priorities]]
pattern = "manage.py"
weight = 180.0

[[priorities]]
pattern = "**/*.py"
weight = 150.0

[[priorities]]
pattern = "requirements.txt"
weight = 120.0

[[priorities]]
pattern = "setup.py"
weight = 120.0

[[priorities]]
pattern = "pyproject.toml"
weight = 120.0
EOF
```

### Go Projects

```bash
# Go project analysis
cd ~/go-projects/api-server
code-digest -d . -o go-analysis.md

# Configuration for Go projects
cat > .code-digest.toml << EOF
[defaults]
max_tokens = 50000
progress = true

ignore = [
    "vendor/",
    "bin/",
    "*.exe",
    "*.test",
    ".DS_Store"
]

[[priorities]]
pattern = "main.go"
weight = 200.0

[[priorities]]
pattern = "cmd/**/*.go"
weight = 180.0

[[priorities]]
pattern = "pkg/**/*.go"
weight = 150.0

[[priorities]]
pattern = "internal/**/*.go"
weight = 140.0

[[priorities]]
pattern = "go.mod"
weight = 120.0

[[priorities]]
pattern = "Makefile"
weight = 100.0
EOF
```

### Java Projects

```bash
# Java/Maven project
cd ~/java-projects/spring-boot-app
code-digest -d . -o java-analysis.md

# Configuration for Java projects
cat > .code-digest.toml << EOF
[defaults]
max_tokens = 65000
progress = true

ignore = [
    "target/",
    "build/",
    "*.class",
    "*.jar",
    "*.war",
    ".gradle/",
    "out/"
]

[[priorities]]
pattern = "src/main/java/**/Application.java"
weight = 200.0

[[priorities]]
pattern = "src/main/java/**/*.java"
weight = 150.0

[[priorities]]
pattern = "pom.xml"
weight = 120.0

[[priorities]]
pattern = "build.gradle"
weight = 120.0

[[priorities]]
pattern = "src/main/resources/**/*"
weight = 100.0
EOF
```

## Use Case Examples

### Code Review and Quality Analysis

```bash
# Comprehensive code review
code-digest -d feature-branch "Perform a comprehensive code review focusing on:"
code-digest -d feature-branch "1. Code quality and best practices"
code-digest -d feature-branch "2. Security vulnerabilities"
code-digest -d feature-branch "3. Performance optimization opportunities"
code-digest -d feature-branch "4. Maintainability and documentation"

# Compare with main branch
git diff main..feature-branch --name-only > changed-files.txt
code-digest -d . --include-from changed-files.txt "Review only the changed files"

# Security-focused review
cat > security-review.toml << EOF
[defaults]
max_tokens = 30000
verbose = true

ignore = ["tests/", "docs/"]

[[priorities]]
pattern = "**/auth*"
weight = 300.0

[[priorities]]
pattern = "**/security*"
weight = 300.0

[[priorities]]
pattern = "**/*login*"
weight = 250.0

[[priorities]]
pattern = "**/*password*"
weight = 250.0

[[priorities]]
pattern = "**/*token*"
weight = 200.0
EOF

code-digest -c security-review.toml -d . "Analyze this code for security vulnerabilities"
```

### Documentation Generation

```bash
# Generate API documentation
code-digest -d src/api/ "Generate comprehensive API documentation with:"
code-digest -d src/api/ "1. Endpoint descriptions"
code-digest -d src/api/ "2. Request/response schemas"
code-digest -d src/api/ "3. Authentication requirements"
code-digest -d src/api/ "4. Usage examples"

# Architecture documentation
code-digest -d . --max-tokens 40000 "Create system architecture documentation"

# Onboarding guide
code-digest -d . "Create a comprehensive onboarding guide for new developers"

# Configuration for documentation focus
cat > docs-config.toml << EOF
[defaults]
max_tokens = 50000

ignore = ["tests/", "node_modules/", "target/"]

[[priorities]]
pattern = "README.*"
weight = 300.0

[[priorities]]
pattern = "docs/**/*"
weight = 250.0

[[priorities]]
pattern = "src/**/*.md"
weight = 200.0

[[priorities]]
pattern = "*.config.*"
weight = 150.0
EOF
```

### Legacy Code Analysis

```bash
# Understand legacy codebase
code-digest -d legacy-system "Help me understand this legacy codebase:"
code-digest -d legacy-system "1. What is the main purpose and functionality?"
code-digest -d legacy-system "2. What are the key components and their relationships?"
code-digest -d legacy-system "3. What technologies and frameworks are used?"
code-digest -d legacy-system "4. What are the main pain points and technical debt?"

# Migration planning
code-digest -d old-app "Create a migration plan from this PHP application to modern Node.js"

# Refactoring opportunities
cat > refactor-analysis.toml << EOF
[defaults]
max_tokens = 45000

[[priorities]]
pattern = "**/*legacy*"
weight = 200.0

[[priorities]]
pattern = "**/*old*"
weight = 180.0

[[priorities]]
pattern = "**/*deprecated*"
weight = 160.0

[[priorities]]
pattern = "**/*.php"
weight = 150.0  # If migrating from PHP
EOF

code-digest -c refactor-analysis.toml -d . "Identify refactoring opportunities"
```

### Performance Analysis

```bash
# Performance-focused analysis
code-digest -d . "Analyze this codebase for performance bottlenecks:"
code-digest -d . "1. Identify CPU-intensive operations"
code-digest -d . "2. Find memory leaks and inefficient memory usage"
code-digest -d . "3. Detect slow database queries"
code-digest -d . "4. Suggest caching opportunities"

# Configuration for performance analysis
cat > performance-config.toml << EOF
[defaults]
max_tokens = 40000

[[priorities]]
pattern = "**/*performance*"
weight = 300.0

[[priorities]]
pattern = "**/*benchmark*"
weight = 250.0

[[priorities]]
pattern = "**/*cache*"
weight = 200.0

[[priorities]]
pattern = "**/*db*"
weight = 200.0

[[priorities]]
pattern = "**/*database*"
weight = 200.0

[[priorities]]
pattern = "**/*query*"
weight = 180.0
EOF
```

### Testing and Quality Assurance

```bash
# Test coverage analysis
code-digest -d tests/ "Analyze test coverage and suggest improvements"

# Testing strategy
code-digest -d . "Suggest a comprehensive testing strategy for this project"

# Quality metrics
cat > quality-config.toml << EOF
[defaults]
max_tokens = 35000

[[priorities]]
pattern = "tests/**/*"
weight = 200.0

[[priorities]]
pattern = "**/*test*"
weight = 180.0

[[priorities]]
pattern = "**/*spec*"
weight = 180.0

[[priorities]]
pattern = "**/test_*"
weight = 160.0

[[priorities]]
pattern = "jest.config.*"
weight = 120.0

[[priorities]]
pattern = "pytest.ini"
weight = 120.0

[[priorities]]
pattern = "Cargo.toml"
weight = 120.0  # For Rust test configuration
EOF

code-digest -c quality-config.toml -d . "Evaluate test quality and coverage"
```

## Workflow Integration Examples

### Git Hooks Integration

```bash
# Pre-commit hook
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
# Generate code analysis before commit

echo "Generating code analysis..."
code-digest -d . -o .git/commit-analysis.md --max-tokens 20000 --quiet

if [ $? -eq 0 ]; then
    echo "Code analysis generated successfully"
else
    echo "Failed to generate code analysis"
    exit 1
fi
EOF

chmod +x .git/hooks/pre-commit
```

### CI/CD Pipeline Integration

```yaml
# .github/workflows/code-analysis.yml
name: Code Analysis

on:
  pull_request:
    branches: [main]

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Install code-digest
        run: cargo install code-digest
      
      - name: Analyze changed files
        run: |
          # Get changed files
          git diff --name-only origin/main..HEAD > changed-files.txt
          
          # Generate analysis
          code-digest -d . --include-from changed-files.txt \
            --max-tokens 30000 -o pr-analysis.md
      
      - name: Comment on PR
        uses: actions/github-script@v6
        with:
          script: |
            const fs = require('fs');
            const analysis = fs.readFileSync('pr-analysis.md', 'utf8');
            
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `## Code Analysis\n\n${analysis}`
            });
```

### VS Code Integration

```json
// .vscode/tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Generate Code Analysis",
            "type": "shell",
            "command": "code-digest",
            "args": [
                "-d", "${workspaceFolder}",
                "-o", "${workspaceFolder}/docs/analysis.md",
                "--max-tokens", "50000",
                "--progress"
            ],
            "group": "build",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "problemMatcher": []
        },
        {
            "label": "Quick Code Review",
            "type": "shell",
            "command": "code-digest",
            "args": [
                "-d", "${workspaceFolder}",
                "--max-tokens", "20000",
                "Review this code for potential issues"
            ],
            "group": "build"
        }
    ]
}
```

## Advanced Configuration Examples

### Multi-Project Workspace

```toml
# ~/.config/code-digest/config.toml
[defaults]
max_tokens = 50000
progress = true

# Project-specific configurations
[projects."/workspace/frontend"]
max_tokens = 40000
tool = "gemini"
ignore = ["node_modules/", "dist/"]

[projects."/workspace/backend"]
max_tokens = 60000
tool = "codex"
ignore = ["target/", "logs/"]

[projects."/workspace/mobile"]
max_tokens = 35000
ignore = ["build/", "*.xcworkspace"]

[[priorities]]
pattern = "src/main.*"
weight = 200.0

[[priorities]]
pattern = "src/lib.*"
weight = 180.0
```

### Template Configurations

```toml
# rust-template.toml
[defaults]
max_tokens = 75000
progress = true
verbose = false

ignore = [
    "target/",
    "Cargo.lock",
    "*.rlib",
    "*.rmeta"
]

[[priorities]]
pattern = "src/main.rs"
weight = 200.0

[[priorities]]
pattern = "src/lib.rs"
weight = 180.0

[[priorities]]
pattern = "src/**/*.rs"
weight = 150.0

[[priorities]]
pattern = "Cargo.toml"
weight = 120.0

[[priorities]]
pattern = "README.*"
weight = 100.0

# Use with: code-digest -c rust-template.toml -d project/
```

```toml
# web-template.toml
[defaults]
max_tokens = 60000
progress = true

ignore = [
    "node_modules/",
    "dist/",
    "build/",
    "coverage/",
    ".next/",
    ".nuxt/",
    "*.bundle.js",
    "*.chunk.js"
]

[[priorities]]
pattern = "src/App.*"
weight = 200.0

[[priorities]]
pattern = "src/index.*"
weight = 190.0

[[priorities]]
pattern = "src/main.*"
weight = 190.0

[[priorities]]
pattern = "src/**/*.{js,ts,jsx,tsx,vue}"
weight = 150.0

[[priorities]]
pattern = "package.json"
weight = 120.0

[[priorities]]
pattern = "*.config.{js,ts}"
weight = 110.0
```

## Scripting Examples

### Batch Processing Script

```bash
#!/bin/bash
# analyze-projects.sh - Batch analyze multiple projects

PROJECTS=(
    "/workspace/project1"
    "/workspace/project2"
    "/workspace/project3"
)

OUTPUT_DIR="./analyses"
mkdir -p "$OUTPUT_DIR"

for project in "${PROJECTS[@]}"; do
    project_name=$(basename "$project")
    echo "Analyzing $project_name..."
    
    code-digest -d "$project" \
        -o "$OUTPUT_DIR/${project_name}-analysis.md" \
        --max-tokens 50000 \
        --progress
    
    echo "Analysis saved to $OUTPUT_DIR/${project_name}-analysis.md"
done

echo "All analyses complete!"
```

### Interactive Analysis Script

```bash
#!/bin/bash
# interactive-analysis.sh - Interactive code analysis

echo "Code Digest Interactive Analysis"
echo "================================"

read -p "Enter project directory: " PROJECT_DIR
read -p "Enter max tokens (default 50000): " MAX_TOKENS
MAX_TOKENS=${MAX_TOKENS:-50000}

read -p "Enter analysis question: " QUESTION

echo "Analyzing project..."
code-digest -d "$PROJECT_DIR" \
    --max-tokens "$MAX_TOKENS" \
    --verbose \
    "$QUESTION"
```

### Monitoring Script

```bash
#!/bin/bash
# monitor-codebase.sh - Monitor codebase changes

WATCH_DIR="$1"
OUTPUT_FILE="codebase-analysis.md"

if [ -z "$WATCH_DIR" ]; then
    echo "Usage: $0 <directory-to-watch>"
    exit 1
fi

echo "Monitoring $WATCH_DIR for changes..."

# Generate initial analysis
code-digest -d "$WATCH_DIR" -o "$OUTPUT_FILE" --max-tokens 40000

# Watch for changes
fswatch -o "$WATCH_DIR" | while read change; do
    echo "Changes detected, regenerating analysis..."
    code-digest -d "$WATCH_DIR" -o "$OUTPUT_FILE" --max-tokens 40000 --quiet
    echo "Analysis updated at $(date)"
done
```

## Next Steps

- Read the [Configuration Reference]configuration.md for detailed options
- Check [Usage Guide]usage.md for more command examples
- See [API Reference]api.md for programmatic usage
- Visit [Troubleshooting]troubleshooting.md for common issues