SDLC.ai VIRIM Agent Navigator

Find the right agent for your VIRIM project phase, role, or deliverable

sdlc-code-optimizer

Skill detail with category, linked agents, and source metadata.

sdlc-code-optimizer

Analyzes source code for quality issues. Detects dead code (unreferenced symbols, unused imports), near-identical logic blocks, high cyclomatic complexity, oversized functions, and performance anti-patterns. Produces a structured finding set with file/line references suitable for consumption by the Code Optimization Agent.

Category: code-analysis Used by 2 agents

Source: .github/skills/code-analysis/sdlc-code-optimizer/SKILL.md

Used By Agents

Preview

View source preview (first 3000 chars)

# sdlc-code-optimizer

Performs static code analysis to identify waste, duplication, and complexity in a codebase. This skill produces raw findings; the Code Optimization Agent interprets and structures them into a prioritized report.

## Responsibility

This skill focuses on one problem: reading source code and producing a structured list of issues across four quality dimensions: dead code, duplication, complexity, and performance anti-patterns.

It does not modify code. It does not make architectural judgments. It produces findings.

## Input

```json
{
  "repository_path": "absolute path to repo",
  "scope": "full | module_path | language_filter",
  "focus": ["all"] | ["dead_code", "duplication", "complexity", "performance"],
  "existing_analysis": "path to docs/codebase-analysis/ if available"
}
```

## Analysis Rules

### Dead Code Detection

- Report any function, method, or class defined but not referenced anywhere else in the codebase
- Report any import statement where the imported symbol is not used in the file
- Include: `file`, `symbol`, `line`, `kind` (function|class|method|import), `certainty` (certain|likely)
- Do NOT include entry points (main functions, exported public API, event handlers registered with frameworks)

### Duplication Detection

- Detect identical logic blocks of 6 or more lines across different files
- Detect near-identical blocks where the only differences are variable names or literals
- Include: `block_summary`, `occurrences` (list of file + start line + end line)
- Suggested extraction: name and location for the extracted function or module

### Complexity Detection

Cyclomatic complexity above threshold:
- Functions/methods with cyclomatic complexity above 10 (count: if, else if, for, while, do, switch case, catch, &&, ||, ?:)
- Functions/methods longer than 80 non-blank lines
- Include: `file`, `function_name`, `line_start`, `complexity_score`, `line_count`

### Performance Anti-patterns

Language-agnostic:
- N+1 query patterns (loop containing a database or HTTP call)
- Repeated object construction inside tight loops where the object is identical each iteration
- String concatenation in loops instead of a buffer or join
- Blocking synchronous calls in async contexts

Include: `file`, `line`, `pattern_name`, `description`, `recommended_alternative`

## Output Schema

```json
{
  "generated_by": {
    "skill": "sdlc-code-optimizer",
    "version": "1.0.0"
  },
  "repository_path": "",
  "scope": "",
  "findings": {
    "dead_code": [],
    "duplication": [],
    "high_complexity": [],
    "performance_anti_patterns": []
  },
  "summary": {
    "dead_code_count": 0,
    "duplication_count": 0,
    "high_complexity_count": 0,
    "performance_count": 0,
    "total": 0
  }
}
```

## Confidence Standard

Do not emit heuristic confidence labels. If a finding requires confidence scoring, reference token logprobs. When logprobs are unavailable, mark the finding as `needs_review: true`.