Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mehen.ophi.dev/llms.txt

Use this file to discover all available pages before exploring further.

mehen’s internals are organized around a clean separation between parsing, analyzing, and reporting.

Crate layout

CrateResponsibility
mehen-cliCLI binary — entry point, command routing, exit codes.
mehen-enginePipeline orchestration — run_diff, run_top_offenders, registry, language detection.
mehen-coreParser-neutral domain types and the LanguageAnalyzer trait.
mehen-metricsShared metric formulas, accumulators, finalizers (Halstead, cyclomatic, cognitive, MI, ABC, LOC, NOM, NPA, NPM, WMC).
mehen-<lang>Per-language analyzer crates. Each owns parsing and metric interpretation.
mehen-tree-sitterShared tree-sitter wrapper and CST traversal helpers, used only by the tree-sitter-backed languages.
mehen-markdownMarkdown analyzer (pulldown-cmark) with embedded-code dispatch via LanguageDispatcher.
mehen-gitGit operations for mehen diff.
mehen-reportJSON, YAML, TOML, and GitHub-Markdown rendering.
xtaskDeveloper-only commands (kind-enum codegen, AST dumps, audits).

Parser diversity, single contract

A core architectural decision: each language uses the parser best suited to it, but every analyzer returns the same LanguageAnalysis shape. mehen does not force a single AST model across languages.
LanguageParserWhat it gives us
PythonRuffModern Python syntax (match, exception groups, f-strings, async); typed AST plus semantic model.
TS / JS / TSX / JSXOxcDecorators, class fields, parameter properties, JSX nesting, satisfies, dynamic import.
PHPMagoAttributes, promoted properties, enums, traits, readonly, null-safe calls, match.
RubyPrismBlocks, lambdas, numbered params, rescue modifiers, endless methods, pattern matching.
Rustra_ap_syntaxThe same syntax library rust-analyzer uses internally.
Markdownpulldown-cmarkCommonMark + GFM with byte-accurate spans.
Go, Kotlin, C, PowerShelltree-sitterMature grammars where tree-sitter’s coverage is the best available.
mehen-metrics owns the math (Halstead formulas, MI variants, cyclomatic accumulators); each per-language analyzer owns the interpretation — which syntax constructs count as decisions, which tokens classify as Halstead operators, which members count as public methods.

Pipeline

file path

language detection (extension-driven)

parser (per-language: Ruff / Oxc / Mago / Prism / ra_ap_syntax / pulldown-cmark / tree-sitter)

analyzer.analyze(tree)              ← per-language metric interpretation

LanguageAnalysis  (Send + 'static)  ← parser-neutral, owned, no parser-arena lifetimes

metric finalizers (mehen-metrics)

reporter (mehen-report)             ← JSON / Markdown / YAML / TOML
The key constraint: LanguageAnalysis is parser-neutral and Send + 'static. That lets the engine analyze files in parallel via rayon without arena-backed parsers (Oxc, Mago) leaking lifetimes across thread boundaries.

Markdown is special

The Markdown analyzer (mehen-markdown) parses the document into a block/inline AST and dispatches code fences back through LanguageDispatcher. That is how Markdown Halstead and MCC credit embedded code blocks without duplicating language logic.

See also