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
# Troubleshooting Guide

Common issues, solutions, and debugging techniques for code-digest.

## Installation Issues

### Cargo Installation Fails

**Problem**: `cargo install code-digest` fails with compilation errors.

**Solutions**:

```bash
# Update Rust to latest stable
rustup update stable

# Clear cargo cache
cargo clean
rm -rf ~/.cargo/registry/cache

# Install with verbose output
cargo install code-digest --verbose

# Try with specific features
cargo install code-digest --no-default-features
```

**Common Causes**:
- Outdated Rust version (requires 1.70.0+)
- Corrupted cargo cache
- Missing system dependencies

### Permission Denied

**Problem**: Cannot execute code-digest after installation.

**Solutions**:

```bash
# Linux/macOS: Fix permissions
sudo chown $(whoami) /usr/local/bin/code-digest
chmod +x /usr/local/bin/code-digest

# Add to PATH if installed via cargo
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

# Windows: Run as Administrator or add to user PATH
```

### LLM Tools Not Found

**Problem**: `gemini: command not found` or similar.

**Solutions**:

```bash
# Install gemini
pip install gemini

# Install codex CLI
npm install -g @openai/codex-cli

# Check PATH
echo $PATH
which gemini

# Use full path
code-digest -d project --tool /full/path/to/gemini "prompt"
```

## Runtime Issues

### Out of Memory Errors

**Problem**: Process killed or memory allocation failures.

**Solutions**:

```bash
# Use token limits to reduce memory usage
code-digest -d project --max-tokens 25000

# Process in smaller chunks
code-digest -d project/src --max-tokens 10000
code-digest -d project/lib --max-tokens 10000

# Exclude large files
echo "*.log" >> .digestignore
echo "node_modules/" >> .digestignore
echo "target/" >> .digestignore

# Monitor memory usage
top -p $(pgrep code-digest)
```

**Memory Optimization**:

```toml
# config.toml
[processing]
chunk_size = 500          # Smaller chunks
parallel_jobs = 2         # Fewer workers
memory_limit_mb = 512     # Per-worker limit

[cache]
enabled = false           # Disable caching if needed
```

### Performance Issues

**Problem**: Slow processing of large projects.

**Solutions**:

```bash
# Use all CPU cores
export RAYON_NUM_THREADS=$(nproc)

# Optimize for current CPU
export RUSTFLAGS="-C target-cpu=native"

# Profile performance
time code-digest -d project --max-tokens 50000

# Use parallel processing
code-digest -d project --progress --verbose
```

**Performance Configuration**:

```toml
[processing]
parallel_jobs = 0         # Auto-detect CPU cores
chunk_size = 2000         # Larger chunks for better performance
timeout_seconds = 300     # Prevent hangs

[cache]
enabled = true
max_size_mb = 2048        # Larger cache
```

### Token Count Issues

**Problem**: Output exceeds LLM context window.

**Solutions**:

```bash
# Set appropriate token limits
code-digest -d project --max-tokens 4000    # GPT-3.5
code-digest -d project --max-tokens 8000    # GPT-4
code-digest -d project --max-tokens 32000   # GPT-4 Turbo

# Check token usage
code-digest -d project --max-tokens 10000 --verbose

# Prioritize important files
cat > priority-config.toml << EOF
[[priorities]]
pattern = "src/main.*"
weight = 300.0

[[priorities]]
pattern = "src/core/*"
weight = 200.0
EOF

code-digest -c priority-config.toml -d project --max-tokens 15000
```

### File Access Errors

**Problem**: Permission denied reading files or directories.

**Solutions**:

```bash
# Check permissions
ls -la project/
ls -la project/src/

# Fix ownership
sudo chown -R $(whoami) project/

# Skip inaccessible files
code-digest -d project --verbose 2>&1 | grep -v "Permission denied"

# Use ignore patterns
echo "restricted/" >> .digestignore
```

## Configuration Issues

### Configuration Not Loading

**Problem**: Configuration file ignored or not found.

**Debug Steps**:

```bash
# Check configuration loading
code-digest --show-config

# Test specific config file
code-digest -c config.toml --validate-config

# Debug configuration loading
RUST_LOG=debug code-digest -d project 2>&1 | grep config

# Check file locations
ls -la ~/.config/code-digest/
ls -la .code-digest.toml
```

**Common Issues**:
- TOML syntax errors
- Wrong file location
- Incorrect permissions

### TOML Syntax Errors

**Problem**: Configuration parsing fails.

**Solutions**:

```bash
# Validate TOML syntax
toml-lint config.toml

# Use online validator
# https://www.toml-lint.com/

# Generate valid template
code-digest --config-template > valid-config.toml

# Common fixes:
# - Use double quotes for strings
# - Proper array syntax: ["item1", "item2"]
# - Correct section headers: [section]
```

**Example Fixes**:

```toml
# Wrong
ignore = [target/, node_modules/]

# Correct
ignore = ["target/", "node_modules/"]

# Wrong
[priority]
pattern = src/*.rs

# Correct
[[priorities]]
pattern = "src/*.rs"
```

### Pattern Matching Issues

**Problem**: Files not filtered as expected.

**Debug Patterns**:

```bash
# Test pattern matching
code-digest -d project --dry-run --verbose

# Show matched files
code-digest -d project --show-matches

# Test specific patterns
code-digest -d project --include "src/**/*.rs" --dry-run
```

**Pattern Examples**:

```bash
# Glob patterns (correct)
"src/**/*.rs"      # All .rs files in src/ recursively
"*.{js,ts}"        # All .js and .ts files
"**/test_*.py"     # All test files

# Common mistakes
"src/**.rs"        # Wrong: should be src/**/*.rs
"src/*.rs"         # Only matches direct children
"src**"            # Matches filenames starting with 'src'
```

## LLM Integration Issues

### API Key Problems

**Problem**: LLM tool authentication fails.

**Solutions**:

```bash
# Set API keys
export OPENAI_API_KEY="your-key"
export GOOGLE_API_KEY="your-key"
export ANTHROPIC_API_KEY="your-key"

# Verify keys are set
echo $OPENAI_API_KEY | cut -c1-10

# Test tool directly
gemini --help
codex --version

# Check tool configuration
code-digest --show-tools
```

### LLM Tool Timeouts

**Problem**: LLM requests timeout or fail.

**Solutions**:

```bash
# Increase timeout
code-digest -d project --llm-timeout 120 "prompt"

# Use smaller token limits
code-digest -d project --max-tokens 10000 "prompt"

# Test tool directly
echo "test prompt" | gemini

# Use alternative tool
code-digest -d project --tool codex "prompt"
```

**Configuration**:

```toml
[tools.gemini]
timeout = 120
max_retries = 3

[tools.codex]
timeout = 180
max_retries = 2
```

### Rate Limiting

**Problem**: API rate limits exceeded.

**Solutions**:

```bash
# Add delays between requests
code-digest -d project --llm-delay 5 "prompt"

# Use smaller chunks
code-digest -d project --max-tokens 5000 "prompt"

# Batch process with delays
for dir in src/*; do
    code-digest -d "$dir" --max-tokens 8000 "analyze this module"
    sleep 10
done
```

## Output Issues

### Malformed Markdown

**Problem**: Generated markdown has formatting issues.

**Solutions**:

```bash
# Validate markdown
markdownlint output.md

# Check encoding
file output.md
iconv -f UTF-8 -t UTF-8 output.md > clean-output.md

# Debug template issues
code-digest -d project --show-templates
```

**Template Fixes**:

```toml
[format]
file_header_template = "## {path}"          # Simple format
doc_header_template = "# Code Digest"       # Remove variables if problematic
```

### Empty or Minimal Output

**Problem**: Output contains very little content.

**Debug Steps**:

```bash
# Check if files are being found
code-digest -d project --dry-run --verbose

# Verify token limits aren't too low
code-digest -d project --max-tokens 50000 --verbose

# Check ignore patterns
code-digest -d project --show-ignored

# Test without token limits
code-digest -d project
```

### Encoding Issues

**Problem**: Special characters or encoding problems.

**Solutions**:

```bash
# Force UTF-8 encoding
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

# Convert encoding
iconv -f ISO-8859-1 -t UTF-8 input.md > output.md

# Check file encodings
file project/src/*.rs
```

## Platform-Specific Issues

### Windows Issues

**Problem**: Path or permission issues on Windows.

**Solutions**:

```powershell
# Use forward slashes or escape backslashes
code-digest -d "C:/Projects/MyApp"
code-digest -d "C:\\Projects\\MyApp"

# Run as Administrator for system-wide installation
# Right-click Command Prompt -> "Run as Administrator"

# Use Windows Subsystem for Linux (WSL)
wsl
code-digest -d /mnt/c/Projects/MyApp

# Fix line endings
git config --global core.autocrlf true
```

### macOS Issues

**Problem**: Code signing or notarization warnings.

**Solutions**:

```bash
# Allow unsigned binary
sudo spctl --master-disable

# Or allow specific binary
sudo xattr -r -d com.apple.quarantine /usr/local/bin/code-digest

# Install via Homebrew for signed version
brew install code-digest
```

### Linux Issues

**Problem**: Missing dependencies or library issues.

**Solutions**:

```bash
# Install required libraries
sudo apt-get install build-essential pkg-config
sudo apt-get install libssl-dev

# For older distributions
sudo apt-get install libc6-dev

# Check library dependencies
ldd $(which code-digest)

# Use static binary if available
wget https://releases.../code-digest-linux-static
```

## Debugging Techniques

### Enable Debug Logging

```bash
# Full debug output
RUST_LOG=debug code-digest -d project --verbose

# Specific module debugging
RUST_LOG=code_digest::core=debug code-digest -d project

# Trace level (very verbose)
RUST_LOG=trace code-digest -d project 2> debug.log

# Filter debug output
RUST_LOG=debug code-digest -d project 2>&1 | grep -E "(ERROR|WARN)"
```

### Performance Profiling

```bash
# Time execution
time code-digest -d project --max-tokens 50000

# Profile with system tools
perf record -g code-digest -d project
perf report

# Memory profiling
valgrind --tool=massif code-digest -d project
```

### Network Debugging

```bash
# Monitor network requests (for LLM integration)
tcpdump -i any port 443

# Check DNS resolution
nslookup api.openai.com

# Test connectivity
curl -v https://api.openai.com/

# Debug proxy issues
export HTTP_PROXY=http://proxy:8080
export HTTPS_PROXY=http://proxy:8080
```

## Recovery Procedures

### Reset Configuration

```bash
# Backup current config
cp ~/.config/code-digest/config.toml ~/.config/code-digest/config.toml.bak

# Reset to defaults
rm ~/.config/code-digest/config.toml
code-digest --generate-config > ~/.config/code-digest/config.toml

# Test with minimal config
code-digest -d project --no-config
```

### Clear Cache

```bash
# Clear application cache
rm -rf ~/.cache/code-digest/

# Clear cargo cache
cargo clean

# Clear temporary files
rm -rf /tmp/code-digest-*
```

### Reinstall

```bash
# Complete reinstall
cargo uninstall code-digest
rm -rf ~/.cargo/registry/cache/
cargo install code-digest

# Or use binary installation
curl -L https://github.com/.../latest/download/... | tar xz
sudo mv code-digest /usr/local/bin/
```

## Getting Help

### Collect Debug Information

```bash
# System information
uname -a
rustc --version
cargo --version

# Application version
code-digest --version

# Configuration dump
code-digest --show-config > debug-config.txt

# Test run with debug output
RUST_LOG=debug code-digest -d small-project 2> debug-output.txt
```

### Report Issues

When reporting issues, include:

1. **System Information**: OS, architecture, Rust version
2. **Code-digest Version**: `code-digest --version`
3. **Command Used**: Exact command that failed
4. **Error Output**: Full error messages
5. **Configuration**: Relevant config file contents
6. **Project Structure**: General description of project being analyzed

**Issue Template**:

```markdown
## Bug Report

**Environment:**
- OS: [Linux/macOS/Windows]
- Code-digest version: [output of `code-digest --version`]
- Rust version: [output of `rustc --version`]

**Command:**
```bash
code-digest -d my-project --max-tokens 50000
```

**Expected Behavior:**
[What you expected to happen]

**Actual Behavior:**
[What actually happened]

**Error Output:**
```
[Full error message]
```

**Configuration:**
```toml
[Relevant config file contents]
```

**Additional Context:**
[Any other relevant information]
```

### Community Resources

- **GitHub Issues**: [Report bugs and feature requests]https://github.com/matiasvillaverde/code-digest/issues
- **Discussions**: [Ask questions and share ideas]https://github.com/matiasvillaverde/code-digest/discussions
- **Documentation**: [Complete documentation]https://docs.rs/code-digest
- **Examples**: [Community examples repository]https://github.com/matiasvillaverde/code-digest-examples

## Prevention

### Best Practices

1. **Regular Updates**: Keep code-digest updated
2. **Configuration Validation**: Test configs before deployment
3. **Resource Monitoring**: Monitor memory and CPU usage
4. **Backup Configs**: Keep configuration backups
5. **Test Early**: Test with small projects first

### Health Checks

```bash
# Regular health check script
#!/bin/bash
echo "Code-digest Health Check"
echo "========================"

# Version check
echo "Version: $(code-digest --version)"

# Configuration check
if code-digest --validate-config; then
    echo "✓ Configuration valid"
else
    echo "✗ Configuration invalid"
fi

# Performance test
start_time=$(date +%s)
code-digest -d /tmp --max-tokens 1000 --quiet
end_time=$(date +%s)
duration=$((end_time - start_time))

echo "Performance: ${duration}s for small test"

if [ $duration -lt 10 ]; then
    echo "✓ Performance good"
else
    echo "! Performance degraded"
fi
```

This comprehensive troubleshooting guide should help users resolve most common issues they might encounter with code-digest.