convez.ai
AgenteDevOps & InfraestruturaIntermediário
sebastianbreguel

Agent Complexity Optimizer

sebastianbreguel/agent-complexity-optimizer

Detecte hotspots de complexidade e N+1 queries em qualquer codebase

Ver no GitHub
InicialPluginScore · de 0 a 100

Scanner de codebases que detecta gargalos de complexidade algorítmica como loops O(n²), queries N+1 e problemas de performance. Funciona como skill/plugin para 13+ agentes de IA ou via CLI Python, gerando relatórios estruturados com severidade, localização e sugestões de correção.

Instalação

$npx convez-ai sebastianbreguel/agent-complexity-optimizer

1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.

Métricas

Estrelas
7
Forks
0
Acompanhando
0
Saúde
42%
Último commit
há 1 mês
Versão
—
Issues abertas
0
Contribuidores
1

Casos de uso

  • Otimizar performance de algoritmos antes de deploy
  • Identificar queries duplicadas em loops de banco de dados
  • Auditar complexidade de código em pull requests
  • Integrar análise de performance em fluxos de agentes de IA

Veredito

Ferramenta bem-construída para detectar antipadrões de performance com suporte amplo a linguagens. Útil para times que querem automatizar auditorias de complexidade, mas requer interpretação humana das sugestões geradas.

README

A tradução para o português deste README ainda está na fila.

agent-complexity-optimizer

License: MIT npm Agents CI

Scan any codebase for O(n^2) hotspots, N+1 queries, and algorithmic complexity issues. Get a structured report with severity, location, and fix suggestions — without modifying a single file.

Works as a skill/plugin for 13 AI coding agents, or standalone via Python CLI.

Extended from codex-complexity-optimizer by Kappaemme. See CREDITS.md for full attribution and a breakdown of what this project adds.

Demo

What it does

Full-quality video: demo/promo.mp4

Given this code:

def find_duplicates(users, transactions):
    duplicates = []
    for t in transactions:
        for u in users:                          # O(n*m) nested scan
            if u["id"] == t["user_id"]:
                duplicates.append(t)
    return duplicates

def get_user_orders(user_ids, db):
    results = []
    for uid in user_ids:
        order = db.query(f"SELECT * FROM orders WHERE user_id = {uid}")  # N+1
        results.append(order)
    return results

The scanner produces:

# Complexity Hotspots

## HIGH nested-loop
- Location: `example.py:4`
- Finding: Nested loop may create O(n^2) or worse behavior.
- Suggestion: Check whether a map/set index, sort+two-pointer pass,
  grouping, or batching can replace the inner scan.

## HIGH io-or-query-in-loop
- Location: `example.py:12`
- Finding: Potential database/API/file operation inside a loop.
- Suggestion: Look for N+1 behavior; batch or preload while preserving
  auth, filters, ordering, and error handling.

What It Detects

PatternSeverityExample
Nested loopsHighfor x in A: for y in B — O(n*m)
N+1 queriesHighdb.query() / fetch() inside a loop
Sorting inside loopsHigh.sort() called per iteration
Membership checks in loopsMedium.includes(), in, indexOf() inside iteration
Render-path recomputationMedium.filter().map() in React component body
Pairwise comparisonsHighEvery-pair scan that could be sort+sweep

Supports: Python (AST-based), JavaScript, TypeScript, JSX/TSX, Java, Go, C, C++, C#, Ruby, PHP, Swift, Rust, Kotlin, Scala, Lua, Zig, Elixir, Erlang, Dart, R, Julia, OCaml, Clojure, and more (regex-based).

Install

Claude Code (marketplace)

/plugin marketplace add sebastianbreguel/agent-complexity-optimizer
/plugin install complexity-optimizer@complexity-optimizer

Codex

npx skills add sebastianbreguel/agent-complexity-optimizer -a codex -g -y

All other agents (auto-detect)

npx agent-complexity-optimizer

Auto-detects installed agents (Cursor, Windsurf, Gemini CLI, Cline/Roo, Aider, OpenCode, Continue.dev, Amazon Q, Zed AI) and writes the correct config format for each. Preview with --dry-run.

GitHub Copilot reads instructions per-repository, so the installer can't set it up globally. Copy these into the repo you want to scan:

cp agents/copilot/copilot-instructions.md <your-repo>/.github/
mkdir -p <your-repo>/.github/complexity-optimizer
cp skills/complexity-optimizer/scripts/analyze_complexity.py <your-repo>/.github/complexity-optimizer/

Standalone (no agent needed)

python3 skills/complexity-optimizer/scripts/analyze_complexity.py /path/to/repo --format markdown
python3 skills/complexity-optimizer/scripts/analyze_complexity.py /path/to/repo --format json

Supported Agents

AgentInstallConfig format
Claude Codemarketplace / npx skills addSKILL.md
Codex (OpenAI)npx skills addSKILL.md + openai.yaml
Pinpm install -gSKILL.md (pi.skills)
Cursorauto-detect.mdc rule
Windsurfauto-detect.windsurfrules
GitHub Copilotmanual (per-repo .github/)copilot-instructions.md
Gemini CLIauto-detectGEMINI.md
Cline / Roo Codeauto-detect.clinerules
Aiderauto-detectCONVENTIONS.md
OpenCodeauto-detectAGENTS.md
Continue.devauto-detectCustom command YAML
Amazon Qauto-detectRules .md
Zed AIauto-detectAssistant rules

Agent config files under agents/ are generated from skills/complexity-optimizer/SKILL.md and a condensed template — edit the source, then run python3 scripts/sync_agents.py (CI fails on drift).

Usage

Ask your agent naturally:

Analyze this codebase for complexity hotspots and give me a report.
Scan for performance issues — nested loops, N+1 queries, O(n^2) patterns.

Reports are read-only by default. To apply a fix:

Implement the lowest-risk optimization from the report and run the tests.

What This Project Adds

The original project supported Codex only. This fork extends it to 13 agents and adds:

  • Universal installer — auto-detects agents and writes native config formats
  • Claude Code marketplace — first-class plugin support
  • Extended scanner — additional languages (Rust, Kotlin, Scala, Lua, Zig, Elixir, Erlang, Dart, R, Julia, OCaml, Clojure) and patterns (list comprehensions, generator expressions, more query signatures)
  • Fewer false positives — membership checks against sets/dicts are skipped (Python AST tracks what was built as a set), and generic verbs like .get()/.find() only count as potential N+1 when called on a client-like receiver (db, session, client, requests, ...)
  • Structured reports — with severity ranking, benchmark sections, and safety checklists

License

MIT

Ver o original no GitHub

Bom para

Relacionados