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

This guide covers all aspects of using code-digest effectively, from basic commands to advanced workflows.

## Basic Usage

### Simple Markdown Generation

```bash
# Generate markdown for current directory
code-digest

# Process specific directory
code-digest -d /path/to/project

# Save to file
code-digest -d /path/to/project -o project.md

# Process with progress indicators
code-digest -d /path/to/project -o project.md --progress
```

### LLM Integration

```bash
# Direct LLM interaction (requires gemini or codex)
code-digest -d /path/to/project "Explain the architecture"

# With specific LLM tool
code-digest -d /path/to/project --tool gemini "Review this code"
code-digest -d /path/to/project --tool codex "Find potential bugs"

# Analyze specific aspects
code-digest -d /path/to/project "What are the main security concerns?"
code-digest -d /path/to/project "How can we improve performance?"
```

## Command Line Options

### Core Options

```bash
# Directory to process (default: current directory)
code-digest -d /path/to/project
code-digest --directory /path/to/project

# Output file (default: stdout)
code-digest -o output.md
code-digest --output output.md

# Maximum tokens (for token-limited LLMs)
code-digest --max-tokens 50000
code-digest --max-tokens 100000

# LLM tool selection
code-digest -t gemini
code-digest --tool codex

# Configuration file
code-digest -c config.toml
code-digest --config /path/to/config.toml
```

### Verbosity and Output

```bash
# Quiet mode (suppress all output except errors)
code-digest -q
code-digest --quiet

# Verbose mode (detailed logging)
code-digest -v
code-digest --verbose

# Progress indicators
code-digest --progress

# Combined options
code-digest -d /path/to/project -o output.md --verbose --progress
```

### Help and Information

```bash
# Show help
code-digest -h
code-digest --help

# Show version
code-digest --version

# List supported file types
code-digest --list-types

# Show configuration schema
code-digest --config-schema
```

## Token Management

### Understanding Token Limits

Token limits help optimize output for LLM context windows:

```bash
# GPT-3.5 Turbo (4K context)
code-digest --max-tokens 3000

# GPT-4 (8K context)
code-digest --max-tokens 7000

# GPT-4 Turbo (128K context)
code-digest --max-tokens 120000

# Claude-3 (200K context)
code-digest --max-tokens 180000
```

### Token Usage Examples

```bash
# Small project analysis
code-digest -d small-project --max-tokens 5000

# Medium project with prioritization
code-digest -d medium-project --max-tokens 25000 --verbose

# Large project with careful selection
code-digest -d large-project --max-tokens 100000 --progress

# No token limit (include everything)
code-digest -d project  # No --max-tokens
```

## File Filtering

### Using .digestignore

Create a `.digestignore` file in your project root:

```bash
# Example .digestignore
node_modules/
target/
.git/
*.log
*.tmp
dist/
build/
.DS_Store
__pycache__/
*.pyc
.env
secrets.txt
```

### Configuration-based Filtering

```toml
# In config.toml
ignore = [
    "tests/",
    "docs/",
    "*.md",
    "*.json"
]

include = [
    "src/**/*.rs",
    "lib/**/*.js",
    "*.toml"
]
```

## Configuration Files

### Basic Configuration

```toml
# ~/.config/code-digest/config.toml

[defaults]
max_tokens = 50000
progress = true
verbose = false
tool = "gemini"

ignore = [
    "node_modules/",
    "target/",
    ".git/"
]

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

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

[[priorities]]
pattern = "*.toml"
weight = 100.0
```

### Project-specific Configuration

```bash
# Create project config
cat > .code-digest.toml << EOF
[defaults]
max_tokens = 25000
progress = true

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

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

# Use project config
code-digest -c .code-digest.toml -d .
```

## Workflow Examples

### Code Review Workflow

```bash
# 1. Generate comprehensive review
code-digest -d feature-branch --max-tokens 50000 -o review.md

# 2. Focus on changes
git diff main..feature-branch --name-only | while read file; do
    echo "## $file" >> changes.md
    code-digest -d . --include "$file" >> changes.md
done

# 3. Interactive review with LLM
code-digest -d feature-branch "Review this code for:"
code-digest -d feature-branch "1. Security vulnerabilities"
code-digest -d feature-branch "2. Performance issues"
code-digest -d feature-branch "3. Code quality concerns"
```

### Documentation Generation

```bash
# Generate API documentation
code-digest -d src/ --max-tokens 30000 "Generate API documentation"

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

# Architecture overview
code-digest -d . --max-tokens 20000 "Explain the system architecture"

# Technical debt analysis
code-digest -d . "Identify areas of technical debt"
```

### Migration Planning

```bash
# Analyze codebase for migration
code-digest -d legacy-app "Analyze for Python 2 to 3 migration"
code-digest -d js-app "Plan migration from JavaScript to TypeScript"
code-digest -d . "Identify dependencies for cloud migration"

# Generate migration checklist
code-digest -d . -o migration-analysis.md --max-tokens 40000
```

### Learning and Understanding

```bash
# Understand new codebase
code-digest -d unknown-project "Explain what this project does"

# Learn specific patterns
code-digest -d . "Show examples of the observer pattern"

# Understand architecture
code-digest -d . "Describe the microservices architecture"

# Find examples
code-digest -d . "Show how authentication is implemented"
```

## Advanced Usage

### Parallel Processing

```bash
# Control parallelism
export RAYON_NUM_THREADS=8
code-digest -d large-project

# Process multiple projects
parallel -j4 'code-digest -d {} -o {/.}.md' ::: project1 project2 project3 project4
```

### Batch Processing

```bash
#!/bin/bash
# Process multiple directories

for project in projects/*/; do
    echo "Processing $project..."
    code-digest -d "$project" -o "docs/$(basename "$project").md" --progress
done
```

### Custom Templates

```bash
# Using configuration templates
code-digest -c templates/api-docs.toml -d api/
code-digest -c templates/security-review.toml -d .
code-digest -c templates/performance.toml -d critical-path/
```

### Integration with CI/CD

```yaml
# .github/workflows/documentation.yml
name: Generate Documentation

on:
  push:
    branches: [main]

jobs:
  docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Install code-digest
        run: cargo install code-digest
      
      - name: Generate documentation
        run: |
          code-digest -d . -o docs/codebase.md --max-tokens 100000
          
      - name: Commit documentation
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add docs/codebase.md
          git commit -m "Update codebase documentation" || exit 0
          git push
```

## Output Formats

### Standard Markdown

```bash
# Basic markdown output
code-digest -d project -o project.md

# With table of contents
code-digest -d project -o project.md  # TOC included by default

# File tree structure
code-digest -d project -o project.md  # Tree included by default
```

### Custom Formatting

```toml
# Custom format configuration
[format]
include_stats = true
include_tree = true
include_toc = true
group_by_type = false
sort_by_priority = true

file_header_template = "## 📁 {path}"
doc_header_template = "# 🚀 Code Digest: {directory}"
```

## Performance Optimization

### Large Projects

```bash
# Use token limits for large projects
code-digest -d huge-project --max-tokens 50000 --progress

# Exclude unnecessary files
code-digest -d huge-project -c minimal-config.toml

# Process in chunks
find huge-project -type d -maxdepth 1 | xargs -I {} code-digest -d {} -o {}.md
```

### Memory Management

```bash
# For memory-constrained environments
export CODE_DIGEST_CHUNK_SIZE=1000
code-digest -d project --max-tokens 10000

# Streaming mode for very large outputs
code-digest -d project | head -n 10000 > partial.md
```

### Caching

```bash
# Enable caching (experimental)
export CODE_DIGEST_CACHE_DIR=~/.cache/code-digest
code-digest -d project -o project.md

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

## Error Handling

### Common Issues and Solutions

```bash
# Permission denied
sudo chown -R $(whoami) /path/to/project
code-digest -d /path/to/project

# Out of memory
code-digest -d project --max-tokens 10000

# LLM tool not found
which gemini  # Check if installed
export PATH="$PATH:/path/to/llm/tools"
code-digest -d project --tool gemini "prompt"

# Configuration error
code-digest --config-schema > schema.json
code-digest -c config.toml --validate-config
```

### Debugging

```bash
# Debug mode
RUST_LOG=debug code-digest -d project --verbose

# Trace execution
RUST_LOG=trace code-digest -d project 2> debug.log

# Check configuration
code-digest -c config.toml --dry-run

# Validate before processing
code-digest -d project --validate-only
```

## Tips and Best Practices

### Performance Tips

1. **Use token limits** for large projects to avoid memory issues
2. **Configure .digestignore** to exclude unnecessary files
3. **Use --progress** for long-running operations
4. **Set appropriate parallelism** with RAYON_NUM_THREADS
5. **Cache frequently accessed projects** (when available)

### Quality Tips

1. **Use descriptive prompts** for LLM integration
2. **Configure priorities** for important files
3. **Review output** before using with LLMs
4. **Use project-specific configs** for consistency
5. **Validate configurations** before deployment

### Security Tips

1. **Review .digestignore** to exclude secrets
2. **Use configuration files** to avoid command-line exposure
3. **Limit token output** for sensitive codebases
4. **Check output files** for sensitive information
5. **Use secure LLM endpoints** for private code

## Next Steps

- Check out [Configuration Reference]configuration.md for advanced setup
- See [Examples]examples.md for real-world use cases
- Read [API Reference]api.md for programmatic usage
- Visit [Troubleshooting]troubleshooting.md for common issues