agentsclimarketplace

Cyclomatic complexity

Skill ambervdberg/sniff/skills/cyclomatic-complexity

Find the most cyclomatically complex functions/methods in a codebase, ranked by number of independent paths, using ast-grep structural matching. Use whenever the user wants to know which functions are too complex, asks "what's the most complex function", hunts for branch-heavy refactor candidates, wants a complexity hotspot list, or asks where to simplify control flow. Prefer this over grep or reading files manually: it runs one bundled command and returns only a small ranked table, so it answers for a tiny number of tokens instead of pulling source or AST JSON into context.From its SKILL.md

Install
npx -y skills add ambervdberg/sniff --skill cyclomatic-complexity

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

3.3 KB, as published. Nobody here has run it

Cyclomatic Complexity

Rank functions/methods by cyclomatic complexity, cheaply.

Why this exists

Branch-heavy functions are hard to test and to read, but counting paths by hand means reading files and burning tokens. This skill runs through the installed sniff CLI: it asks ast-grep for the functions and the decision points, derives each function's complexity from node containment, and prints a ~20-row table. You only ever see the table. Keep it that way, never pipe raw ast-grep --json output into your own context.

What "complexity" means

Cyclomatic complexity = 1 + the number of decision points in a function: each if/elif, loop, case, catch/except, ternary, and boolean operator (&&/||/and/or) adds one. A straight-line function is 1. Computed from AST node ranges, not text.

Usage

Run the detector through the installed sniff CLI:

  1. If sniff version fails: uv tool install sniff-smells (and uv tool install ast-grep-cli if ast-grep is missing).
  2. Run: sniff --only cyclomatic-complexity DIR [--top N] [--lang LANG] [--min N] [--include-tests]
  3. Report the table; do not paste raw file contents.

The output is a COMPLEXITY / NAME / LOCATION table sorted most-complex-first. Print the entire table verbatim. It IS the answer. Do NOT replace it with a summary or describe it in prose; the user wants every row. You may add ONE optional takeaway line after the table (e.g. the worst offender), but the full table comes first and in full. Do not re-read listed files unless the user then asks you to actually refactor one.

What it counts, and the caveats worth stating

  • Languages: auto-detected. TypeScript/TSX, JavaScript and Python are the best-tested; Java, C#, Go, Ruby, C/C++ are mapped but less battle-tested. A language with no decision-kinds mapping is skipped (not scored); if something you expected shows nothing, pass --lang and sanity-check.
  • Approximate. Boolean operators are counted per operator (a && b && c adds 2), and decision points inside a nested function currently count toward the enclosing function too. Treat the ranking as a hotspot finder, not a certified complexity value.
  • Complexity, not size or nesting. A complex function isn't always the longest or the deepest, those are separate skills (largest-methods, deepest-nesting).
  • --min defaults to 1 (show everything). Raise it to focus on the worst.
  • Tests excluded by default (*.spec.*, *.test.*); add --include-tests. node_modules, dist, build and similar are always skipped.
  • Names are best-effort, read from the definition's first line; LOCATION is authoritative.

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.