Skip to main content

Tool to compute and export code metrics

Project description

mehen

mehen is a Rust-powered CLI for detecting heuristic source code metrics at scale: complexity, maintainability, lines of code, and more.

It is designed for fast, deterministic analysis over large codebases, helping both human and AI engineers track how complexity evolves over time.

What is Mehen?

In Ophidiarium projects, names matter.

Mehen is a mythical ancient Egyptian serpent associated with guarding Ra. In the same spirit, mehen helps guard your codebase from slowly collapsing under complexity.

Why Teams Use Mehen

Most common usage patterns we see:

  • CI jobs that compute metrics for changed files and publish trend reports
  • Pre-PR / pre-CR hooks that provide immediate quality feedback
  • Automation workflows that enrich pull request templates with a glance view of metric deltas

Current Language Support

Today mehen supports:

  • Python
  • TypeScript / JavaScript (.ts, .mts, .cts, .js, .mjs, .cjs)
  • TSX / JSX (.tsx, .jsx)
  • Rust
  • Go
  • Ruby
  • Kotlin
  • PowerShell
  • C (.c, .h)
  • Markdown (.md, .markdown, .mdown, .mkd, .mkdn, .mdx) — documentation metrics only

Because TypeScript is a superset of JavaScript, mehen analyzes .js/.mjs/.cjs files through the TypeScript grammar and .jsx files through the TSX grammar.

Markdown files receive a dedicated documentation metric suite (maintainability, reading path complexity, link debt, filler/lazy risk, readability) rather than the code-style metrics — Markdown has no functions, classes, or interfaces to score. See the Markdown metric chapter.

We also providing comprehensive support for polyglot monorepos, with per-file language detection and reporting.

What Mehen Computes

mehen provides a broad metric set for source code, including:

  • Cyclomatic complexity
  • Cognitive complexity
  • Maintainability Index
  • Halstead metrics
  • ABC metrics
  • NArgs / NOM / NExit
  • LOC family (SLOC, PLOC, LLOC, CLOC, blanks)
  • NPA / NPM / WMC

Markdown documentation metrics

For Markdown (README, ADRs, runbooks, API references, tutorials, generated docs), mehen ships a dedicated metric suite that treats code fences, diagrams, tables, images, links, math, and repository references as first-class document constructs instead of stripping them before counting words. The structural layer covers a Markdown LOC family (prose vs. code vs. tables vs. math vs. blank lines), Markdown Reading Path Complexity, a Markdown Cognitive Complexity analogue, Markdown Halstead, a Documentation Maintainability Index (DMI), link debt, table burden, visual scaffold, repository grounding, evidence coverage, filler/lazy structure risk, and a review criticality index. An opt-in language-aware prose layer adds English readability (Flesch, Flesch-Kincaid, Fog, SMOG, ARI, Coleman-Liau, Dale-Chall, FORCAST, LIX/RIX), lexical diversity (MATTR, hapax, density), wording quality (passive, hedges, weasels, wordy, adverbs, nominalizations, cliches, illusions), inclusive-language flags, Japanese script composition, the Tateishi simplified readability score, a Jōyō-grade proxy, JTF rule conformance, and a textlint-ja subset. Full reference in the Markdown metric chapter of the book.

Distribution

mehen ships native binaries through both ecosystems:

  • npm (mehen + platform packages)
  • PyPI (mehen via maturin binary packaging)

Quick Start

Run without installation

From npm ecosystem:

bunx mehen --help

From Python/uv ecosystem:

uv tool run mehen --help
# or
uvx mehen --help

Run locally from source

cargo run -- --help

Typical examples

Analyze metrics for a directory:

mehen -m -p src

Export metrics as JSON/TOML/YAML/CBOR:

mehen -m -p src -O json -o ./metrics

GitHub Actions

Use the in-repository action to publish changed-file metric trends on pull requests:

permissions:
  contents: read
  pull-requests: write
  issues: write

steps:
  - uses: actions/checkout@v6
    with:
      fetch-depth: 0

  - uses: ophidiarium/mehen@v0
    with:
      paths: src

For polyglot monorepos, pass each root you want tracked. mehen will analyze only supported languages in changed files under those roots:

- uses: ophidiarium/mehen@v0
  with:
    paths: |
      crates/api/src
      apps/web/src
      tools
    thresholds: |
      cyclomatic=5
      cognitive=4
      loc.lloc=120

Thresholds are optional. When configured, the action fails if an adverse per-file metric delta exceeds the configured limit.

When enabled and a PR touches one or more Markdown files, mehen diff will also emit a Documentation Metrics section inside the same sticky comment, anchored by <!-- mehen-docs -->. Once fully wired, it will report DMI, word count, FKGL / Tateishi RS, link debt, and filler risk per file, plus a template-driven callout list for objective defects (broken links, new inclusive-language flags, long sentences, heading skips, unlabelled code fences, etc.). The full specification — anchor rules, cell format, callout template catalog, planned --fail-on gating — is in commands/pr-comment.md. Until the Markdown renderer emits the anchor and the callout catalog is wired end-to-end, the GitHub Action only publishes the source-code metrics section.

Reporting and Integrations

Current machine-readable outputs:

  • JSON
  • YAML
  • TOML
  • CBOR

Roadmap direction:

  • Native git integration for changed-file detection
  • Rich markdown reports for AI/human review flows
  • More polished console reporting for local developer loops

Implementation Notes

Internally, mehen is built on:

mehen continues in its own CLI-focused direction while preserving and evolving that foundation.

Development

Build and check:

cargo check
cargo build
cargo fmt --all
cargo clippy --all-targets --all-features --locked

Tests:

cargo test --all-targets --locked

Snapshot tests (insta):

cargo insta test --all-features --check --unreferenced reject --test-runner nextest --no-test-runner-fallback --disable-nextest-doctest

See mehen-book/src/developers/ for developer docs, including language and grammar updates.

Contributing

Contributions are welcome via issues and pull requests:

License

mehen is released under the Mozilla Public License v2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mehen-0.7.0.tar.gz (5.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mehen-0.7.0-py3-none-win_arm64.whl (4.5 MB view details)

Uploaded Python 3Windows ARM64

mehen-0.7.0-py3-none-win_amd64.whl (4.8 MB view details)

Uploaded Python 3Windows x86-64

mehen-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

mehen-0.7.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (5.0 MB view details)

Uploaded Python 3manylinux: glibc 2.5+ x86-64

mehen-0.7.0-py3-none-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

mehen-0.7.0-py3-none-macosx_10_12_x86_64.whl (4.8 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file mehen-0.7.0.tar.gz.

File metadata

  • Download URL: mehen-0.7.0.tar.gz
  • Upload date:
  • Size: 5.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mehen-0.7.0.tar.gz
Algorithm Hash digest
SHA256 6c669a3e7ae304981b60cdafb8caf4471ae2fc77d397647688d2e643cf6a033e
MD5 b64a84edc94c8e6ccfe6c73d2c5850d0
BLAKE2b-256 6cc2004f06e9d2a6392f81c6246eb253a96f3895daf088a9f6bd6c67103bd951

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-0.7.0.tar.gz:

Publisher: release.yml on ophidiarium/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-0.7.0-py3-none-win_arm64.whl.

File metadata

  • Download URL: mehen-0.7.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 4.5 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mehen-0.7.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 cc2ee142dff2def123c5fd6ae2c2a91b8e547682855e42ed47801aa882dcd5a1
MD5 c7ffe972c9c8fb0ea30e7d4722eec636
BLAKE2b-256 64b7d01764a725a452c0e60770f9c54e374ffead9de1c86647174c0266811a2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-0.7.0-py3-none-win_arm64.whl:

Publisher: release.yml on ophidiarium/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-0.7.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: mehen-0.7.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 4.8 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mehen-0.7.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 9d8634f5cd1656c57317ed8c3e2faf8f83667b164ee2a80674ce3076be04f3d0
MD5 005bcb8b4c3e9cae8731d877bb98a90d
BLAKE2b-256 e5186719cf67a3c8f5659ff230186739e8156616170e6f44181b69dce60d7477

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-0.7.0-py3-none-win_amd64.whl:

Publisher: release.yml on ophidiarium/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mehen-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b295692dc4e6d255cdf87d673ca16407f4509e2cfe6250867ae94ffbbe0371d
MD5 3c75463a3e16b305465fe2f22750daef
BLAKE2b-256 a94f55f293a23ebbe776987ad30a0312b8a6c5b666530a0a21ece35e0d4bfa57

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on ophidiarium/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-0.7.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for mehen-0.7.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 edb775838adc98a538f1f7d6b598f8eef7f1f15a70f020656a7a582ae05497aa
MD5 16e7d6e72b3677407487733a292c71b6
BLAKE2b-256 d5a6e05f010416793f6f5c47cb686bf834686262c93d3ad4409a6e1aef1e642c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-0.7.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl:

Publisher: release.yml on ophidiarium/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-0.7.0-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: mehen-0.7.0-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 4.7 MB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mehen-0.7.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 63b394d04845aebcc1fc7d639dcde3a78f5a8cd1eed45c221d32aec78154c381
MD5 16d306c6b79f5922023e998ac585b698
BLAKE2b-256 7b9f23eca82bc47a127876265590f7336d6a3c6aba583eb796323e299a966a44

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-0.7.0-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on ophidiarium/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-0.7.0-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for mehen-0.7.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0925df1d62d29d352312be62ad095781fac525c6d6e007b51d9e4cbe2f2a7842
MD5 d58236e190a4704c2181eeb9ed1d8cd3
BLAKE2b-256 dd9966f15aeeab8752d07842247430159423827605d5676a66ca0908daa4f1aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-0.7.0-py3-none-macosx_10_12_x86_64.whl:

Publisher: release.yml on ophidiarium/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page