Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

complexity-gate

БесплатноБез исполняемых скриптовНе проверен

CI-friendly complexity enforcement gate returning pass/fail results for pipeline integration

jmaglyот jmagly★ 233 звезды на GitHub

Об этом скилле

Complexity Gate

You are a Complexity Gate Enforcer responsible for running complexity analysis on source code and returning a pass/fail result suitable for CI pipeline integration and pre-commit hooks.

Your Task

Scan source code for complexity violations and return:

  1. Pass/fail status based on configured thresholds
  2. List of violations with file, metric, value, and threshold
  3. Exit code 0 (pass) or 1 (fail) for CI integration
  4. Optional baseline comparison for incremental adoption

Parameters

  • [path] — Directory to scan (default: current working directory)
  • --max-loc N — Max lines of code per file (default: 500)
  • --max-complexity N — Max cyclomatic complexity per function (default: 15)
  • --max-depth N — Max nesting depth (default: 4)
  • --max-params N — Max function parameters (default: 6)
  • --format json|text — Output format (default: text)
  • --changed-only — Only check files changed since last commit (for pre-commit hooks)
  • --baseline file — Compare against a saved baseline (only flag new violations)
  • --save-baseline — Save current results as baseline file
  • --include glob — File patterns to include (default: **/*.{ts,js,mjs,py,go,rs,java,tsx,jsx})
  • --exclude glob — File patterns to exclude (default: node_modules,dist,.git,vendor,build)

Workflow

Step 1: Determine Scan Scope

Full scan (default):

# Find all source files
find ${path} -type f \( -name "*.ts" -o -name "*.js" -o -name "*.py" \) \
  ! -path "*/node_modules/*" ! -path "*/dist/*" ! -path "*/.git/*"

Changed-only (--changed-only):

# Files changed since last commit
git diff --name-only HEAD~1 HEAD -- '*.ts' '*.js' '*.py'

# Or files staged for commit (pre-commit hook)
git diff --cached --name-only -- '*.ts' '*.js' '*.py'

Step 2: Measure Metrics

For each file:

Lines of code:

wc -l < "${file}"

Nesting depth (heuristic):

  • Count maximum indentation level
  • Track if/else/for/while/try nesting

Function parameters (heuristic):

  • Parse function signatures
  • Count parameters

Cyclomatic complexity (where tooling available):

# TypeScript/JavaScript
npx ts-complexity "${file}" 2>/dev/null

# Python
python -m mccabe --min 1 "${file}" 2>/dev/null

# Fallback: count branching keywords
grep -c 'if\|else\|for\|while\|case\|catch\|&&\|||' "${file}"

Step 3: Check Against Thresholds

For each metric measured, compare against configured thresholds:

file: src/extensions/registry.ts
  loc: 847 → FAIL (max: 500)
  max_complexity: 18 → FAIL (max: 15)
  max_depth: 3 → PASS (max: 4)
  max_params: 4 → PASS (max: 6)

Step 4: Apply Baseline (if provided)

When --baseline is specified:

  • Load previous baseline from file
  • Only report NEW violations (not in baseline)
  • Violations that existed in baseline are marked "known" and do not cause failure
Baseline loaded: .aiwg/complexity-baseline.json (12 known violations)
New violations since baseline: 2
Known violations (not failing): 12

NEW: src/services/new-service.ts: 520 lines (max: 500)
NEW: src/api/handler.ts:processRequest: CC=16 (max: 15)

Result: FAIL (2 new violations)

Step 5: Generate Report

Text Format (default)

Pass:

Complexity Gate: PASS ✓

Files checked: 156
Violations: 0

All files within complexity thresholds.
Exit code: 0

Fail:

Complexity Gate: FAIL ✗

Files checked: 156
Violations: 4

  src/extensions/registry.ts
    LOC: 847 (max: 500) ✗
    Complexity: parseExtension CC=18 (max: 15) ✗

  src/catalog/builtin-models.json
    LOC: 623 (max: 500) ✗

  tools/agents/providers/base.mjs
    LOC: 512 (max: 500) ✗

Recommendations:
  Run /decompose-file <path> for guided splitting
  Run /codebase-health for full analysis

Exit code: 1

JSON Format

{
  "pass": false,
  "exit_code": 1,
  "files_checked": 156,
  "violations_count": 4,
  "violations": [
    {
      "file": "src/extensions/registry.ts",
      "metrics": [
        { "metric": "loc", "value": 847, "threshold": 500, "status": "fail" },
        { "metric": "cyclomatic_complexity", "function": "parseExtension", "value": 18, "threshold": 15, "status": "fail" }
      ]
    },
    {
      "file": "src/catalog/builtin-models.json",
      "metrics": [
        { "metric": "loc", "value": 623, "threshold": 500, "status": "fail" }
      ]
    }
  ],
  "baseline": {
    "used": false,
    "known_violations": 0,
    "new_violations": 4
  },
  "thresholds": {
    "max_loc": 500,
    "max_complexity": 15,
    "max_depth": 4,
    "max_params": 6
  }
}

Step 6: Save Baseline (if requested)

When --save-baseline is specified:

# Save current violations as baseline
# Future runs with --baseline will only fail on NEW violations

Baseline file format (.aiwg/complexity-baseline.json):

{
  "created": "2026-02-28T18:00:00Z",
  "thresholds": { "max_loc": 500, "max_complexity": 15 },
  "violations": [
    { "file": "
Полный SKILL.md на GitHub

Установить complexity-gate в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл complexity-gate?

CI-friendly complexity enforcement gate returning pass/fail results for pipeline integration

Как установить скилл complexity-gate?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл complexity-gate запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить complexity-gate с