plugins/sdlc/skills/complexity-gate/SKILL.md
CI-friendly complexity enforcement gate returning pass/fail results for pipeline integration
npx skillsauth add jmagly/aiwg complexity-gateInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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.
Scan source code for complexity violations and return:
**/*.{ts,js,mjs,py,go,rs,java,tsx,jsx})node_modules,dist,.git,vendor,build)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'
For each file:
Lines of code:
wc -l < "${file}"
Nesting depth (heuristic):
if/else/for/while/try nestingFunction parameters (heuristic):
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}"
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)
When --baseline is specified:
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)
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
{
"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
}
}
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": "src/extensions/registry.ts", "metric": "loc", "value": 847 }
]
}
- name: Complexity Gate
run: |
aiwg complexity-gate --format json --baseline .aiwg/complexity-baseline.json > complexity-report.json
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "::error::Complexity gate failed. See complexity-report.json"
fi
exit $exit_code
#!/bin/bash
# .git/hooks/pre-commit
aiwg complexity-gate --changed-only --format text
Installation via tdd-enforce pattern:
/setup-tdd --add-hook complexity-gate
steps:
- name: Complexity Check
run: aiwg complexity-gate --ci --baseline .aiwg/complexity-baseline.json
Thresholds configurable in .aiwg/config.yaml:
complexity_gate:
max_loc: 500
max_complexity: 15
max_depth: 4
max_params: 6
baseline_file: .aiwg/complexity-baseline.json
include:
- "**/*.{ts,js,mjs,py,go}"
exclude:
- "node_modules"
- "dist"
- "*.test.*"
- "*.spec.*"
Complexity Gate: PASS ✓ (no files to check)
--changed-only mode: no source files changed since last commit.
Warning: Baseline file .aiwg/complexity-baseline.json not found.
Running without baseline (all violations reported).
To create a baseline: aiwg complexity-gate --save-baseline
Warning: Cyclomatic complexity analysis requires ts-complexity or mccabe.
Falling back to LOC and nesting depth checks only.
Install: npm install -g ts-complexity (TypeScript)
Install: pip install mccabe (Python)
/codebase-health (diagnostic dashboard vs. pass/fail gate)/decompose-file (remediation for violations)tdd-enforce skill (pre-commit hook integration)This command succeeds when:
--changed-only mode for pre-commit hooks--baseline mode for incremental adoption--changed-only modedata-ai
Report which research-corpus radar sidecars are overdue for refresh. Computes staleness (days since last refresh vs the cadence window) for every radar, sorted most-overdue-first. Runs via `aiwg corpus radar-status`.
data-ai
Aggregate research-corpus radar sidecars into a corpus or per-cluster freshness report — totals, overdue count, per-cluster / per-GRADE / per-trajectory breakdowns, an overdue table, and per-radar rationale snippets. Runs via `aiwg corpus radar-report`.
testing
Scaffold radar/freshness sidecars for research-corpus REFs. Pulls title/authors from the citation sidecar and GRADE from the analysis doc, defaults the refresh cadence from GRADE and the cluster from a corpus-local map, and stamps documentation/radar/REF-XXX-radar.md. Runs via `aiwg corpus radar-init`.
data-ai
Compute an entity's publication trajectory — per-year paper counts, topic drift, hot-streak detection (≥3 consecutive A-grade years), and career phase. Runs via `aiwg corpus profile-temporal`.