debtmap 0.16.6

Code complexity and technical debt analyzer
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
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
# CLI Reference

Complete reference for Debtmap command-line interface.

## Quick Start

```bash
# Basic analysis
debtmap analyze src/

# With coverage integration
debtmap analyze src/ --coverage-file coverage.lcov

# Generate JSON report
debtmap analyze . --format json --output report.json

# Show top 10 priority items only
debtmap analyze . --top 10 --min-priority high

# Initialize configuration and validate
debtmap init
debtmap validate . --config debtmap.toml
```

## Global Options

Options that apply to all commands:

- `--show-config-sources` - Show where each configuration value came from (spec 201)
  - Displays the source of each configuration value (default, config file, environment, CLI)
  - Useful for debugging configuration precedence issues
- `--config <PATH>` - Custom config file path (overrides default locations)
  - Can also use `DEBTMAP_CONFIG` environment variable

**Example:**
```bash
# Show configuration sources
debtmap --show-config-sources analyze .

# Use custom config file
debtmap --config /path/to/debtmap.toml validate .
```

## Commands

Debtmap provides seven main commands: five for analysis and validation, plus two debugging tools.

### `analyze`

Analyze code for complexity and technical debt.

**Usage:**
```bash
debtmap analyze <PATH> [OPTIONS]
```

**Arguments:**
- `<PATH>` - Path to analyze (file or directory)

**Description:**
Primary command for code analysis. Supports multiple output formats (json, markdown, terminal), coverage file integration, parallel processing, context-aware risk analysis, and comprehensive filtering options.

See [Options](#options) section below for all available flags.

### `init`

Initialize a Debtmap configuration file.

**Usage:**
```bash
debtmap init [OPTIONS]
```

**Options:**
- `-f, --force` - Force overwrite existing config

**Description:**
Creates a `.debtmap.toml` configuration file in the current directory with default settings. Use `--force` to overwrite an existing configuration file.

### `validate`

Validate code against thresholds defined in configuration file.

**Usage:**
```bash
debtmap validate <PATH> [OPTIONS]
```

**Arguments:**
- `<PATH>` - Path to analyze

**Options:**

*Configuration & Output:*
- `-c, --config <CONFIG>` - Configuration file path
- `-f, --format <FORMAT>` - Output format: json, markdown, terminal, dot
- `-o, --output <OUTPUT>` - Output file path (defaults to stdout)

*Coverage & Context:*
- `--coverage-file <PATH>` / `--lcov <PATH>` - LCOV coverage file for risk analysis
- `--context` / `--enable-context` - Enable context-aware risk analysis
- `--context-providers <PROVIDERS>` - Context providers to use (comma-separated)
- `--disable-context <PROVIDERS>` - Disable specific context providers

*Thresholds & Validation:*
- `--max-debt-density <N>` - Maximum debt density allowed (per 1000 LOC)

*Display Filtering:*
- `--top <N>` / `--head <N>` - Show only top N priority items
- `--tail <N>` - Show only bottom N priority items
- `-s, --summary` - Use summary format with tiered priority display

*Analysis Control:*
- `--semantic-off` - Disable semantic analysis (fallback mode)

*Performance Control:*
- `--no-parallel` - Disable parallel call graph construction (enabled by default)
- `-j, --jobs <N>` - Number of threads for parallel processing (0 = use all cores)
  - Can also use `DEBTMAP_JOBS` environment variable

*Debugging & Verbosity:*
- `-v, --verbose` - Increase verbosity level (can be repeated: -v, -vv, -vvv)

**Description:**
Similar to `analyze` but enforces thresholds defined in configuration file. Returns non-zero exit code if thresholds are exceeded, making it suitable for CI/CD integration.

The `validate` command supports a focused subset of `analyze` options, primarily for output control, coverage integration, context-aware analysis, and display filtering.

**Note:** The following `analyze` options are NOT available in the `validate` command:
- `--threshold-complexity`, `--threshold-duplication`, `--threshold-preset` (configure these in `.debtmap.toml` instead)
- `--languages` (language filtering)

**Note:** The `--explain-score` flag exists in the `validate` command but is deprecated (hidden). Use `-v`, `-vv`, or `-vvv` for verbosity instead.

Configure analysis thresholds in your `.debtmap.toml` configuration file for use with the `validate` command.

**Exit Codes:**
- `0` - Success (no errors, all thresholds passed)
- Non-zero - Failure (errors occurred or thresholds exceeded)

### `compare`

Compare two analysis results and generate a diff report.

**Usage:**
```bash
debtmap compare --before <FILE> --after <FILE> [OPTIONS]
```

**Required Options:**
- `--before <FILE>` - Path to "before" analysis JSON
- `--after <FILE>` - Path to "after" analysis JSON

**Optional Target Location:**
- `--plan <FILE>` - Path to implementation plan (to extract target location)
- `--target-location <LOCATION>` - Target location in format `file:function:line`

**Note:** `--plan` and `--target-location` are mutually exclusive options. Using both together will cause a CLI error:
```
error: the argument '--plan <FILE>' cannot be used with '--target-location <LOCATION>'
```
Use one or the other to specify the target location.

**Output Options:**
- `-f, --format <FORMAT>` - Output format: json, markdown, terminal, dot (default: json)
- `-o, --output <OUTPUT>` - Output file (defaults to stdout)

**Description:**
Compares two analysis results and generates a diff showing improvements or regressions in code quality metrics.

### `validate-improvement`

Validate that technical debt improvements meet quality thresholds.

**Usage:**
```bash
debtmap validate-improvement --comparison <FILE> [OPTIONS]
```

**Required Options:**
- `--comparison <FILE>` - Path to comparison JSON file (from `debtmap compare`)

**Optional Options:**
- `-o, --output <FILE>` - Output file path for validation results (default: `.prodigy/debtmap-validation.json`)
- `--previous-validation <FILE>` - Path to previous validation result for trend tracking
- `--threshold <N>` - Improvement threshold percentage (default: 75.0)
- `-f, --format <FORMAT>` - Output format: json, markdown, terminal, dot (default: json)
- `--quiet` - Suppress console output (useful for automation)

**Description:**
Validates improvement quality by analyzing comparison output from `debtmap compare`. Calculates a composite improvement score based on weighted components:

**Composite Score Calculation:**
1. **Target Item Improvement (50% weight)** - Measures direct improvement to the specific target item being fixed
   - Compares complexity, debt score, and other metrics before/after
   - Weight: 0.5 × (target improvement percentage)

2. **Overall Project Health (30% weight)** - Evaluates project-wide quality changes
   - Analyzes aggregate metrics across entire codebase
   - Considers new issues introduced, total debt changes
   - Weight: 0.3 × (project health percentage)

3. **Absence of Regressions (20% weight)** - Penalizes introduction of new technical debt
   - Checks for new high-priority issues in other parts of codebase
   - Ensures improvements don't shift complexity elsewhere
   - Weight: 0.2 × (regression-free percentage)

**Final Score:** `composite_score = (0.5 × target) + (0.3 × health) + (0.2 × no_regressions)`

The default threshold (75%) requires strong improvement in the target item while maintaining overall project quality.

When `--previous-validation` is provided, tracks progress trends across multiple attempts and provides recommendations for continuing or adjusting the improvement approach.

**Example:**
```bash
# Basic validation
debtmap validate-improvement --comparison comparison.json

# With trend tracking and custom threshold
debtmap validate-improvement \
  --comparison .prodigy/comparison.json \
  --previous-validation .prodigy/validation.json \
  --output .prodigy/validation.json \
  --threshold 80.0
```

### `diagnose-coverage` (Debugging)

Diagnose and validate LCOV coverage files.

**Usage:**
```bash
debtmap diagnose-coverage <COVERAGE_FILE> [OPTIONS]
```

**Arguments:**
- `<COVERAGE_FILE>` - Path to the LCOV coverage file to diagnose

**Options:**
- `--format <FORMAT>` - Output format: text or json (default: text)

**Description:**
Validates and diagnoses LCOV coverage files with detailed analysis. This command helps identify issues with coverage data before using it with the `analyze` command. Use this when:
- Coverage data seems incorrect or incomplete
- You want to validate an LCOV file before integration
- Debugging coverage parsing issues

**Example:**
```bash
# Validate coverage file with text output
debtmap diagnose-coverage coverage.lcov

# Get JSON output for automation
debtmap diagnose-coverage lcov.info --format json
```

### `explain-coverage` (Debugging)

Explain coverage detection for a specific function.

**Usage:**
```bash
debtmap explain-coverage <PATH> --coverage-file <FILE> --function <NAME> [OPTIONS]
```

**Arguments:**
- `<PATH>` - Path to the codebase to analyze

**Required Options:**
- `--coverage-file <FILE>` / `--lcov <FILE>` - LCOV coverage file
- `--function <NAME>` - Function name to explain (e.g., "create_auto_commit")

**Optional Options:**
- `--file <PATH>` - File path containing the function (helps narrow search)
- `-v, --verbose` - Show all attempted matching strategies
- `-f, --format <FORMAT>` - Output format: text or json (default: text)

**Description:**
Debugging tool that explains how coverage detection works for a specific function. Shows all attempted matching strategies and helps diagnose coverage mapping issues. This command is particularly useful when:
- Coverage appears incorrect for specific functions
- You need to understand why a function isn't matched in coverage data
- Debugging LCOV line mapping issues

**Example:**
```bash
# Explain coverage for a specific function
debtmap explain-coverage src/ --coverage-file coverage.lcov --function "process_file"

# Narrow search to specific file with verbose output
debtmap explain-coverage . --lcov lcov.info --function "analyze_complexity" --file "src/analyzer.rs" -v

# JSON output for automation
debtmap explain-coverage . --coverage-file coverage.lcov --function "my_function" --format json
```

## Options

Options are organized by category for clarity. Most options apply to the `analyze` command, with a subset available for `validate`.

### Output Control

Control how analysis results are formatted and displayed.

**Format Options:**
- `-f, --format <FORMAT>` - Output format: json, markdown, terminal, dot (default: terminal for analyze)
  - `json` - JSON format for programmatic processing
  - `markdown` - Markdown format with comprehensive analysis (uses LLM-optimized writer)
  - `terminal` - Human-readable terminal output with colors and formatting
  - `dot` - Graphviz DOT format for dependency visualization
- `-o, --output <OUTPUT>` - Output file path (defaults to stdout)
- `--plain` - Plain output mode: ASCII-only, no colors, no emoji, machine-parseable

**Display Filtering:**
- `--top <N>` / `--head <N>` - Show only top N priority items
- `--tail <N>` - Show only bottom N priority items (lowest priority)
- `-s, --summary` - Use summary format with tiered priority display (compact output)
- `-c, --compact` - Use compact output format (minimal details, top metrics only). Conflicts with verbosity flags (-v, -vv, -vvv). Only available in `analyze` command (note: `validate` uses `-c` for `--config`)
- `--min-priority <PRIORITY>` - Minimum priority to display: low, medium, high, critical
- `--min-score <N>` - Minimum score threshold for filtering T3/T4 recommendations (default: 3.0)
  - T1 Critical Architecture and T2 Complex Untested items bypass this filter and are always shown
  - Overrides config file setting (Spec 193, 205)
- `--show-filter-stats` - Show filter statistics (how many items were filtered and why)
- `--filter <CATEGORIES>` - Filter by debt categories (comma-separated)
- `--aggregate-only` - Show only aggregated file-level scores
- `--group-by-category` - Group output by debt category

**Progress Display:**
- `--no-tui` - Disable TUI progress visualization (use simple progress bars instead)
- `-q, --quiet` - Suppress progress output (quiet mode)

**Streaming Output:**
- `--streaming` - Enable streaming output mode for large codebases (Spec 003)
  - Streams results to output as they're generated with O(1) memory overhead
  - Useful for processing large codebases that would otherwise exhaust memory
- `--stream-to <FILE>` - Output file for streaming mode (requires --streaming)
  - Use "-" for stdout

**Dependency Display Options:**
- `--show-dependencies` - Show caller/callee information in output
- `--no-dependencies` - Hide dependency information (conflicts with --show-dependencies)
- `--max-callers <N>` - Maximum number of callers to display (default: 5)
- `--max-callees <N>` - Maximum number of callees to display (default: 5)
- `--show-external-calls` - Include external crate calls in dependencies
- `--show-std-lib-calls` - Include standard library calls in dependencies

### Analysis Control

Configure analysis behavior, thresholds, and language selection.

**Thresholds:**
- `--threshold-complexity <N>` - Complexity threshold (default: 10) [analyze command]
- `--threshold-duplication <N>` - Duplication threshold in lines (default: 50) [analyze command]
- `--threshold-preset <PRESET>` - Complexity threshold preset: strict, balanced, lenient [analyze command]
  - `strict` - Strict thresholds for high code quality standards
  - `balanced` - Balanced thresholds for typical projects (default)
  - `lenient` - Lenient thresholds for legacy or complex domains
- `--max-debt-density <N>` - Maximum debt density allowed per 1000 LOC [validate command]

**Note:** Threshold options (`--threshold-complexity`, `--threshold-duplication`, `--threshold-preset`) are command-line options for the `analyze` command. For the `validate` command, these thresholds are configured via the `--config` file (`.debtmap.toml`) rather than as command-line flags.

**Language Selection:**
- `--languages <LANGS>` - Comma-separated list of languages to analyze
  - Example: `--languages rust,python,javascript`
  - Supported: rust, python, javascript, typescript

**Analysis Modes:**
- `--semantic-off` - Disable semantic analysis (fallback mode)
- `--no-context-aware` - Disable context-aware false positive reduction (enabled by default)
- `--no-multi-pass` - Disable multi-pass analysis (use single-pass for performance)
- `--attribution` - Show complexity attribution details (requires multi-pass, which is the default)

**Functional Programming Analysis:**
- `--ast-functional-analysis` - Enable AST-based functional composition analysis (spec 111)
  - Analyzes code for functional programming patterns and composition
  - Detects pure functions, immutability, and side effects
- `--functional-analysis-profile <PROFILE>` - Set functional analysis profile
  - `strict` - Strict functional purity requirements (for pure FP codebases)
  - `balanced` - Balanced analysis suitable for mixed paradigms (default)
  - `lenient` - Lenient thresholds for imperative codebases

### Context & Coverage

Enable context-aware risk analysis and integrate test coverage data.

**Context-Aware Risk Analysis:**
- `--context` / `--enable-context` - Enable context-aware risk analysis
- `--context-providers <PROVIDERS>` - Context providers to use (comma-separated)
  - Available: `critical_path`, `dependency`, `git_history`
  - Example: `--context-providers critical_path,git_history`
- `--disable-context <PROVIDERS>` - Disable specific context providers (comma-separated)

**Coverage Integration:**
- `--coverage-file <PATH>` / `--lcov <PATH>` - LCOV coverage file for risk analysis
  - Coverage data dampens debt scores for well-tested code (multiplier = 1.0 - coverage)
  - Surfaces untested complex functions as higher priority
  - Total debt score with coverage ≤ score without coverage
- `--validate-loc` - Validate LOC consistency across analysis modes (with/without coverage)

### Performance

Optimize analysis performance through parallelization.

**Parallel Processing:**
- `--no-parallel` - Disable parallel call graph construction (enabled by default)
- `-j, --jobs <N>` - Number of threads for parallel processing
  - `0` = use all available CPU cores (default)
  - Specify number to limit thread count

**Other Performance:**
- `--max-files <N>` - Maximum number of files to analyze (0 = no limit)

**Profiling:**
- `--profile` - Enable profiling to identify performance bottlenecks (Spec 001)
  - Outputs timing breakdown for each analysis phase when complete
- `--profile-output <FILE>` - Write profiling data to file in JSON format (requires --profile)
  - Use for post-analysis performance investigation

### Debugging & Verbosity

Control diagnostic output and debugging information.

**Verbosity Levels:**
- `-v, --verbose` - Increase verbosity level (can be repeated: -v, -vv, -vvv)
  - `-v` - Show main score factors
  - `-vv` - Show detailed calculations
  - `-vvv` - Show all debug information

**Specialized Debugging:**
- `--explain-metrics` - Explain metric definitions and formulas (measured vs estimated)
- `--verbose-macro-warnings` - Show verbose macro parsing warnings (Rust analysis)
- `--show-macro-stats` - Show macro expansion statistics at end of analysis
- `--detail-level <LEVEL>` - Detail level for diagnostic reports
  - Options: summary, standard, comprehensive, debug (default: standard)

**Call Graph Debugging:**
- `--debug-call-graph` - Enable detailed call graph debugging with resolution information
- `--trace-function <FUNCTIONS>` - Trace specific functions during call resolution (comma-separated)
  - Example: `--trace-function 'my_function,another_function'`
- `--call-graph-stats` - Show only call graph statistics (no detailed failure list)
- `--validate-call-graph` - Validate call graph structure and report issues
- `--debug-format <FORMAT>` - Debug output format: text or json (default: text)
  - Use with call graph debugging flags to control output format

### Aggregation

Control file-level aggregation and god object detection.

**File Aggregation:**
- `--aggregate-only` - Show only aggregated file-level scores
- `--no-aggregation` - Disable file-level aggregation
- `--aggregation-method <METHOD>` - File aggregation method (default: weighted_sum)
  - Options: sum, weighted_sum, logarithmic_sum, max_plus_average
- `--min-problematic <N>` - Minimum number of problematic functions for file aggregation
- `--no-god-object` - Disable god object detection

**God Object Split Recommendations:**
- `--show-splits` - Show detailed module split recommendations for god objects and large files (experimental)
  - Suggests how to decompose large files into smaller, focused modules
- `--min-split-methods <N>` - Minimum methods per god object split recommendation (default: 10)
- `--min-split-lines <N>` - Minimum lines per god object split recommendation (default: 150)

**Dead Code Analysis:**
- `--no-public-api-detection` - Disable public API detection heuristics for dead code analysis
- `--public-api-threshold <N>` - Public API confidence threshold (0.0-1.0, default: 0.7)
  - Functions above this threshold are considered public APIs

**Pattern Detection:**
- `--no-pattern-detection` - Disable pattern recognition
- `--patterns <PATTERNS>` - Enable specific patterns only (comma-separated)
  - Available patterns: observer, singleton, factory, strategy, callback, template_method
- `--pattern-threshold <N>` - Pattern confidence threshold (0.0-1.0, default: 0.7)
- `--show-pattern-warnings` - Show pattern warnings for uncertain detections

### Option Aliases

Common option shortcuts and aliases for convenience:

- `--lcov` is alias for `--coverage-file`
- `--enable-context` is alias for `--context`
- `--head` is alias for `--top`
- `-s` is short form for `--summary`
- `-v` is short form for `--verbose`
- `-f` is short form for `--format`
- `-o` is short form for `--output`
- `-c` is short form for `--config`
- `-j` is short form for `--jobs`

### Deprecated Options

The following options are deprecated and should be migrated:

- `--explain-score` (hidden) - **Deprecated:** use `-v` instead
  - **Migration:** Use `-v`, `-vv`, or `-vvv` for increasing verbosity levels

## Configuration

### Configuration File

Created via `debtmap init` command. The configuration file (`.debtmap.toml`) is used by the `validate` command for threshold enforcement and default settings.

**Creating Configuration:**
```bash
# Create new config
debtmap init

# Overwrite existing config
debtmap init --force
```

### Environment Variables

- `DEBTMAP_CONFIG` - Custom config file path (same as `--config` global flag)
  - Example: `export DEBTMAP_CONFIG=/path/to/debtmap.toml`
  - Overrides default configuration file locations
  - Useful for CI/CD environments with centralized config
  - Source: src/cli.rs:45

- `DEBTMAP_JOBS` - Number of threads for parallel processing (same as `--jobs` / `-j` flag)
  - Example: `export DEBTMAP_JOBS=8  # Same as --jobs 8`
  - Use `0` to utilize all available CPU cores
  - Controls thread pool size for parallel call graph construction

- `DEBTMAP_SINGLE_PASS` - Disable multi-pass analysis globally (same as `--no-multi-pass` flag)
  - Example: `export DEBTMAP_SINGLE_PASS=1  # Disable multi-pass analysis`
  - Set to `1` or `true` to disable multi-pass analysis by default
  - Useful for CI/CD environments where performance is critical
  - Can be overridden by command-line flags

- `PRODIGY_AUTOMATION` - Enable automation mode for `validate-improvement` command
  - Example: `export PRODIGY_AUTOMATION=true`
  - Set to `true` to enable automation mode (suppresses interactive prompts)
  - Used in automated workflows for continuous improvement validation
  - Source: src/main.rs:549

- `PRODIGY_VALIDATION` - Alternative flag for automation mode (same effect as `PRODIGY_AUTOMATION`)
  - Example: `export PRODIGY_VALIDATION=true`
  - Set to `true` to enable automation mode
  - Provided for backward compatibility with existing workflows
  - Source: src/main.rs:552

### Getting Help

Get help for any command:
```bash
# General help
debtmap --help

# Command-specific help
debtmap analyze --help
debtmap validate --help
debtmap compare --help
debtmap init --help
```

## Common Workflows

### Basic Analysis

Analyze a project and view results in terminal:
```bash
debtmap analyze src/
```

Generate JSON report for further processing:
```bash
debtmap analyze . --format json --output report.json
```

Generate Markdown report:
```bash
debtmap analyze . --format markdown --output report.md
```

### Coverage-Integrated Analysis

Analyze with test coverage to surface untested complex code:
```bash
# Generate coverage file first (example for Rust)
cargo tarpaulin --out lcov

# Run analysis with coverage
debtmap analyze src/ --coverage-file lcov.info
```

Coverage dampens debt scores for well-tested code, making untested complex functions more visible.

### Context-Aware Analysis

Enable context providers for risk-aware prioritization:
```bash
# Use all context providers
debtmap analyze . --context

# Use specific context providers
debtmap analyze . --context --context-providers critical_path,git_history
```

Context-aware analysis reduces false positives and prioritizes code based on:
- Critical execution paths
- Dependency relationships
- Git history (change frequency)

### Filtered & Focused Analysis

Show only top priority items:
```bash
debtmap analyze . --top 10 --min-priority high
```

Filter by specific debt categories:
```bash
debtmap analyze . --filter complexity,duplication
```

Use summary mode for compact output:
```bash
debtmap analyze . --summary
```

Show only file-level aggregations:
```bash
debtmap analyze . --aggregate-only
```

### Performance Tuning

Control parallelization:
```bash
# Use 8 threads
debtmap analyze . --jobs 8

# Disable parallel processing
debtmap analyze . --no-parallel
```

Limit analysis scope:
```bash
# Analyze maximum 100 files
debtmap analyze . --max-files 100

# Analyze specific languages only
debtmap analyze . --languages rust,python
```

### CI/CD Integration

Use the `validate` command in CI/CD pipelines:
```bash
# Initialize configuration (one time)
debtmap init

# Edit debtmap.toml to set thresholds
# ...

# In CI pipeline: validate against thresholds
debtmap validate . --config debtmap.toml --max-debt-density 50
```

The `validate` command returns non-zero exit code if thresholds are exceeded, failing the build.

### Comparison & Tracking

Compare analysis results before and after changes:
```bash
# Before changes
debtmap analyze . --format json --output before.json

# Make code changes...

# After changes
debtmap analyze . --format json --output after.json

# Generate comparison report
debtmap compare --before before.json --after after.json --format markdown
```

With implementation plan:
```bash
debtmap compare --before before.json --after after.json --plan IMPLEMENTATION_PLAN.md
```

### Debugging Analysis

Increase verbosity to understand scoring:
```bash
# Show main score factors
debtmap analyze src/ -v

# Show detailed calculations
debtmap analyze src/ -vv

# Show all debug information
debtmap analyze src/ -vvv
```

Debug call graph resolution issues:
```bash
# Enable call graph debugging
debtmap analyze . --debug-call-graph

# Trace specific functions
debtmap analyze . --debug-call-graph --trace-function 'problematic_function'

# Validate call graph structure
debtmap analyze . --validate-call-graph --debug-format json
```

Show macro expansion statistics (Rust):
```bash
debtmap analyze . --show-macro-stats --verbose-macro-warnings
```

Use detailed diagnostic reports:
```bash
debtmap analyze . --detail-level comprehensive
```

Analyze functional programming patterns:
```bash
# Enable functional analysis
debtmap analyze . --ast-functional-analysis

# Use strict profile for pure FP codebases
debtmap analyze . --ast-functional-analysis --functional-analysis-profile strict
```

## Examples

### Basic Analysis
```bash
# Analyze current directory
debtmap analyze .

# Analyze specific directory
debtmap analyze src/

# Generate JSON output
debtmap analyze . --format json --output report.json
```

### With Coverage
```bash
# Analyze with LCOV coverage file
debtmap analyze src/ --coverage-file coverage.lcov

# Alternative alias
debtmap analyze src/ --lcov coverage.lcov
```

### Context-Aware Analysis
```bash
# Enable all context providers
debtmap analyze . --context

# Use specific context providers
debtmap analyze . --context --context-providers critical_path,git_history

# Disable specific providers
debtmap analyze . --context --disable-context dependency
```

### Filtered Output
```bash
# Top 10 priority items only
debtmap analyze . --top 10

# High priority and above
debtmap analyze . --min-priority high

# Specific categories
debtmap analyze . --filter complexity,duplication

# Summary format
debtmap analyze . --summary

# Group by category
debtmap analyze . --group-by-category
```

### Performance Tuning
```bash
# Use 8 threads
debtmap analyze . --jobs 8

# Disable parallelization
debtmap analyze . --no-parallel

# Limit file count
debtmap analyze . --max-files 100
```

### Validation
```bash
# Initialize config
debtmap init --force

# Validate against config
debtmap validate . --config debtmap.toml

# With max debt density threshold
debtmap validate . --max-debt-density 50
```

### Comparison
```bash
# Compare two analyses
debtmap compare --before before.json --after after.json

# With markdown output
debtmap compare --before before.json --after after.json --format markdown

# With implementation plan
debtmap compare --before before.json --after after.json --plan IMPLEMENTATION_PLAN.md

# With target location
debtmap compare --before before.json --after after.json --target-location "src/main.rs:process_file:42"
```

### Language Selection
```bash
# Analyze only Rust files
debtmap analyze . --languages rust

# Multiple languages
debtmap analyze . --languages rust,python,javascript
```

### Threshold Configuration
```bash
# Custom complexity threshold
debtmap analyze . --threshold-complexity 15

# Use preset
debtmap analyze . --threshold-preset strict

# Custom duplication threshold
debtmap analyze . --threshold-duplication 100
```

### Plain/Machine-Readable Output
```bash
# Plain output (no colors, no emoji)
debtmap analyze . --plain

# Combine with JSON for CI
debtmap analyze . --format json --plain --output report.json
```

### Advanced Debugging
```bash
# Call graph debugging with detailed information
debtmap analyze . --debug-call-graph --debug-format json

# Trace specific functions during call resolution
debtmap analyze . --debug-call-graph --trace-function 'process_file,analyze_complexity'

# Validate call graph structure
debtmap analyze . --validate-call-graph

# Show only call graph statistics
debtmap analyze . --debug-call-graph --call-graph-stats

# Functional programming analysis with strict profile
debtmap analyze . --ast-functional-analysis --functional-analysis-profile strict

# Explain metric definitions
debtmap analyze . --explain-metrics -v
```

## Command Compatibility Matrix

| Option | analyze | validate | compare | init | diagnose-coverage | explain-coverage |
|--------|---------|----------|---------|------|-------------------|------------------|
| `<PATH>` argument | ✓ | ✓ | ✗ | ✗ | ✓ | ✓ |
| `--format` | ✓ | ✓ | ✓ | ✗ | ✓ | ✓ |
| `--output` | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ |
| `--coverage-file` | ✓ | ✓ | ✗ | ✗ | ✗ | ✓ |
| `--context` | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ |
| `--threshold-*` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--top / --tail` | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ |
| `--min-score` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--show-filter-stats` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--quiet` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--no-tui` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--streaming` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--stream-to` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--jobs` | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ |
| `--no-parallel` | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ |
| `--profile` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--profile-output` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--verbose` | ✓ | ✓ | ✗ | ✗ | ✗ | ✓ |
| `--show-splits` | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ |
| `--min-split-methods` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--min-split-lines` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--no-public-api-detection` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--public-api-threshold` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--no-pattern-detection` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--patterns` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--pattern-threshold` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--show-pattern-warnings` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--explain-metrics` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--debug-call-graph` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--trace-function` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--call-graph-stats` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--validate-call-graph` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--debug-format` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--show-dependencies` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--no-dependencies` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--max-callers` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--max-callees` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--show-external-calls` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--show-std-lib-calls` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--ast-functional-analysis` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--functional-analysis-profile` | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `--function` | ✗ | ✗ | ✗ | ✗ | ✗ | ✓ |
| `--file` | ✗ | ✗ | ✗ | ✗ | ✗ | ✓ |
| `--config` | ✗ | ✓ | ✗ | ✗ | ✗ | ✗ |
| `--before / --after` | ✗ | ✗ | ✓ | ✗ | ✗ | ✗ |
| `--force` | ✗ | ✗ | ✗ | ✓ | ✗ | ✗ |

**Note:** The `validate` command supports output control (`--format`, `--output`), coverage integration (`--coverage-file`), context-aware analysis (`--context`), display filtering (`--top`, `--tail`, `--summary`, `--show-splits`), performance control (`--jobs`, `--no-parallel`), and verbosity options (`--verbose`) from the `analyze` command. Analysis thresholds (`--threshold-complexity`, `--threshold-duplication`, `--threshold-preset`) are configured via the `--config` file rather than as command-line options. Debugging features like call graph debugging, functional analysis, profiling, and pattern detection are specific to the `analyze` command. The `diagnose-coverage` and `explain-coverage` commands are specialized debugging tools for diagnosing coverage issues and have their own unique options.

## Troubleshooting

### Performance Issues

**Problem:** Analysis is slow on large codebases

**Solutions:**
```bash
# Use more threads (if you have CPU cores available)
debtmap analyze . --jobs 16

# Limit analysis scope
debtmap analyze . --max-files 500 --languages rust
```

### Memory Issues

**Problem:** Analysis runs out of memory

**Solutions:**
```bash
# Disable parallelization
debtmap analyze . --no-parallel

# Limit file count
debtmap analyze . --max-files 100

# Analyze in batches by language
debtmap analyze . --languages rust
debtmap analyze . --languages python
```

### Output Issues

**Problem:** Terminal output has garbled characters

**Solution:**
```bash
# Use plain mode
debtmap analyze . --plain
```

**Problem:** Want machine-readable output

**Solution:**
```bash
# Use JSON with plain mode
debtmap analyze . --format json --plain --output report.json
```

### Threshold Issues

**Problem:** Too many items flagged

**Solutions:**
```bash
# Use lenient preset
debtmap analyze . --threshold-preset lenient

# Increase threshold
debtmap analyze . --threshold-complexity 20

# Filter to high priority only
debtmap analyze . --min-priority high
```

**Problem:** Not enough items flagged

**Solutions:**
```bash
# Use strict preset
debtmap analyze . --threshold-preset strict

# Lower threshold
debtmap analyze . --threshold-complexity 5

# Show all items
debtmap analyze . --min-priority low
```

## Best Practices

### Regular Analysis

Run analysis regularly to track code quality trends:
```bash
# Daily in CI
debtmap validate . --config debtmap.toml

# Weekly deep analysis with coverage
debtmap analyze . --coverage-file coverage.lcov --format json --output weekly-report.json
```

### Performance Optimization

For large codebases:
```bash
# Use maximum parallelization
debtmap analyze . --jobs 0  # 0 = all cores

# Focus on changed files in CI
# (implement via custom scripts to analyze git diff)
```

### Integration with Coverage

Always analyze with coverage when available:
```bash
# Rust example
cargo tarpaulin --out lcov
debtmap analyze src/ --coverage-file lcov.info

# Python example
pytest --cov --cov-report=lcov
debtmap analyze . --coverage-file coverage.lcov
```

Coverage integration helps prioritize untested complex code.

## Additional Tools

### prodigy-validate-debtmap-improvement

Specialized validation tool for Prodigy workflow integration.

**Description:**
This binary is part of the Prodigy workflow system and provides specialized validation for Debtmap improvement workflows.

**Usage:**
See Prodigy documentation for detailed usage instructions.

## See Also

- [Configuration Format](./configuration.md) - Detailed configuration file format
- [Output Formats](./output-formats.md) - Understanding JSON, Markdown, and Terminal output
- [Coverage Integration](./coverage-integration.md) - Integrating test coverage data
- [Context Providers](./context-providers.md) - Understanding context-aware analysis
- [Examples](./examples.md) - More comprehensive usage examples