Skip to content

feat: regex-based over-engineering pre-filter for ponytail-review #289

Description

Problem

ponytail-review relies entirely on LLM analysis to detect over-engineering in diffs. This is thorough but slow -- each review requires a full model inference pass. For large diffs or CI pipelines, this adds latency and cost.

Proposed addition

A standalone detectOverEngineering(text) function that uses regex patterns to quickly flag known over-engineering signals before the LLM does deeper analysis. Returns [{ pattern, alternative, snippet }] -- actionable findings that map directly to ladder rungs 2-4.

Patterns

Regex Ladder Rung Native Alternative
import (moment|dayjs|date-fns|luxon) 3 -- Native platform Intl.DateTimeFormat / native Date
import (lodash|ramda|underscore) 2 -- Stdlib native Array/Object methods
import (axios|node-fetch|got) 3 -- Native platform native fetch()
JSON.parse(JSON.stringify( 3 -- Native platform structuredClone()
new Date().toISOString() 3 -- Native platform Date.now()
trivial getter/setter class 6 -- One line direct property access
small function wrapping single expression 6 -- One line inline expression

Usage in ponytail-review

// Fast pre-filter: regex pass catches obvious patterns
const findings = detectOverEngineering(diffText);

// Then LLM does deeper analysis on remaining context
// findings are passed as hints to the model

This is a complement, not a replacement -- regex catches import-level signals; the LLM catches architectural over-engineering that regex can't see.

Source

I built this for a transparent compression proxy (adal-compress) that sits between AdaL CLI and the API. The function is standalone, MIT-licensed, and not coupled to the proxy. It has 32 unit tests covering edge cases.

The function lives in my compression engine at compression.mjs:719. Happy to extract it into a standalone module for easy integration.

Why this helps

  • Faster reviews: regex pass is O(n) vs LLM inference
  • CI-friendly: can run as a pre-commit check without model access
  • Teaches the pattern: each finding includes the native alternative, reinforcing the ladder
  • Complementary: catches import-level signals that the LLM might miss in large diffs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions