# src/commands/analyze

All `normalize analyze` and `normalize rank` subcommand implementations (~47 files). Each file defines a report struct, implements `OutputFormatter` (`format_text` / `format_pretty`), and exposes a computation function. Rank-pattern commands (files, imports, ownership, docs, ceremony, surface, depth-map, layering, test-ratio, budget, density, coupling, uniqueness) implement `RankEntry` on their entry structs and use `format_ranked_table()` from `normalize-analyze::ranked` for shared tabular rendering. All rank commands also implement `DiffableRankEntry` for `--diff <ref>` support (compare current state against a git ref). The four scalar trend commands have been merged into `trend-metric --metric <complexity|length|density|test-ratio>`. `UnionFind` in `clusters.rs` is shared by `coupling_clusters.rs` and `fragments.rs`.

Representative files: `complexity.rs`, `length.rs`, `hotspots.rs`, `coupling.rs`, `coupling_clusters.rs` (queries `co_change_edges` from the structural index when available; falls back to git walk with a `tracing::warn!` when table is empty), `duplicates.rs`, `duplicates_views.rs`, `docs.rs`, `imports.rs`, `import_path.rs` (`ImportPathReport`, BFS over resolved import graph for `normalize view import-path <from> <to>`; supports `--all` for all simple paths and `--reverse` to find paths in the other direction), `layering.rs`, `ownership.rs`, `security.rs`, `trace.rs`, `trend.rs`, `trend_metric.rs`, `call_graph.rs` (`CallEntry` struct with optional `access` field for read/write distinction), `graph.rs`, `dependents.rs`, `fragments.rs`, `skeleton_diff.rs`, `summary.rs`. `git_utils.rs` is the central gix-based git utility module (pure-Rust, no `git` binary required) providing: `open_repo`, `git_head`, `git_commit_timestamps`, `git_log_timestamps`, `resolve_ref`, `resolve_merge_base`, `git_show`, `git_diff_name_status`, `git_ls_files`, `git_remote_origin_url`, `git_activity_commits`, `git_file_churn_stats`, `git_per_commit_files`, `git_author_commit_counts`, `git_has_uncommitted_content_changes`, `git_summary_has_uncommitted_changes`, `git_last_commit_for_path`, `git_commit_count_for_path`, `format_unix_date`, and `run_in_worktree` (shell-out, gix lacks worktree create/delete). `resolve_ref_shellout` is now an alias for `resolve_ref`. `git_history.rs` provides shared worktree infrastructure (`run_in_worktree`, `resolve_ref`, `git_log_timestamps`, `select_snapshots`) used by `trend.rs` and `trend_metric.rs`. Native rule checks and the `gitignore_walk()` walker live in `normalize-native-rules`, not here. Progress bars (indicatif) are used in `duplicates.rs` and `architecture.rs` for long-running operations. Duplicate detection suppresses widespread body-pattern clusters and parallel-impl directory pairs to avoid O(N²) noise. `ast.rs` exports `build_ast_output(file, at_line, sexp, depth, compact)` — `depth` (-1 = unlimited) truncates the CST at that level, `compact` produces a node-type outline without source text via `tree_to_outline()`.
