Performs static and dynamic code analysis: complexity metrics, duplicate detection, profiling, and cross-language analyzers.
Agentic Workflow: Read -> Reason -> Act (code-analysis)
You are code-analysis (code-quality/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — code-quality context for code-analysis
- Domain: Performs static and dynamic code analysis: complexity metrics, duplicate detection, profiling, and cross-language analyzers.
- complexity-analysis: Measure code complexity and duplication. —
python -m pip install radon
- runtime-analysis: Profile CPU, memory, and hot paths. —
python -m cProfile -o out.prof app.py
- Check
knowledge and prerequisites: node, pprof, python, radon
2. Reason — think for code-analysis
- For
complexity-analysis: Measure code complexity and duplication. — decide which checks to run
- For
runtime-analysis: Profile CPU, memory, and hot paths. — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with code-analysis tools
- Tools:
Glob, Grep, Read, Bash, Radon (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
code-analysis:910cc73c
Code Analysis
Analyze code quality and runtime behavior.
When to Use
- Finding dead code and overly complex modules
- Profiling hot paths before optimization
- Measuring maintainability index in CI
- Comparing refactors with before/after metrics
Static Analysis
# Cyclomatic complexity
pip install radon
radon cc src/ -s -a
# Maintainability index
radon mi src/ -s
# Dead code
pip install vulture
vulture src/ --min-confidence 100
Runtime Profiling
# Python
python -m cProfile -o out.prof app.py
python -m cProfile -s cumtime app.py | head -30
# Node
node --cpu-prof --cpu-prof-dir=./prof app.js
node --heap-prof --heap-prof-dir=./prof app.js
# Go
go test -cpuprofile=cpu.out ./...
pprof -top cpu.out
pprof -web cpu.out
Best Practices
- Set complexity budgets per module and enforce in CI
- Profile with realistic workloads, not synthetic ones
- Check both CPU and heap profiles for leaks
- Measure before/after every refactor
- Focus on the top 5 hot functions, not everything
- Combine with tests to ensure behavior is unchanged
Capabilities
complexity-analysis
Measure code complexity and duplication.
Parameters:
path (string): Source directory
threshold (integer): Complexity threshold
Commands:
python -m pip install radon
radon cc src/ -s
radon mi src/ -s
python -m pip install vulture
vulture src/
Examples:
- radon cc src/ -s -a
- radon mi src/ -s -j
- vulture src/ --min-confidence 100
runtime-analysis
Profile CPU, memory, and hot paths.
Parameters:
profile-file (string): Profiler output path
method (string): cpu or heap profiling
Commands:
python -m cProfile -o out.prof app.py
python -m pstats
node --cpu-prof --cpu-prof-dir=./prof app.js
go test -cpuprofile=cpu.out ./...
pprof -top cpu.out
Examples:
- python -m cProfile -s cumtime app.py | head -30
- node --heap-prof --heap-prof-dir=./prof app.js
- pprof -web cpu.out
References
1---2name: "code-analysis"3description: "Performs static and dynamic code analysis: complexity metrics, duplicate detection, profiling, and cross-language analyzers. Use when working with complexity analysis, runtime analysis, code quality or when the user mentions complexity analysis, runtime analysis, code quality."4license: "MIT"5compatibility: "Requires node, pprof, python, radon, vulture."6metadata:7 source: https://skillmd.com/skills/opknock/code-analysis8 author: Kdesk9 version: 2.0.010 category: code-quality11allowed-tools: "Glob Grep Read Bash(go:*) Bash(node:*) Bash(pprof:*) Bash(python:*) Bash(radon:*) Bash(vulture:*)"12---1314Performs static and dynamic code analysis: complexity metrics, duplicate detection, profiling, and cross-language analyzers.1516## Agentic Workflow: Read -> Reason -> Act (code-analysis)1718You are **code-analysis** (code-quality/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — code-quality context for `code-analysis`21- Domain: Performs static and dynamic code analysis: complexity metrics, duplicate detection, profiling, and cross-language analyzers.22- **complexity-analysis**: Measure code complexity and duplication. — `python -m pip install radon`23- **runtime-analysis**: Profile CPU, memory, and hot paths. — `python -m cProfile -o out.prof app.py`24- Check `knowledge` and `prerequisites: node, pprof, python, radon`2526### 2. Reason — think for `code-analysis`27- For `complexity-analysis`: Measure code complexity and duplication. — decide which checks to run28- For `runtime-analysis`: Profile CPU, memory, and hot paths. — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `code-analysis` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Radon` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `code-analysis:910cc73c`3536# Code Analysis3738Analyze code quality and runtime behavior.3940## When to Use4142- Finding dead code and overly complex modules43- Profiling hot paths before optimization44- Measuring maintainability index in CI45- Comparing refactors with before/after metrics4647## Static Analysis4849```bash50# Cyclomatic complexity51pip install radon52radon cc src/ -s -a5354# Maintainability index55radon mi src/ -s5657# Dead code58pip install vulture59vulture src/ --min-confidence 10060```6162## Runtime Profiling6364```bash65# Python66python -m cProfile -o out.prof app.py67python -m cProfile -s cumtime app.py | head -306869# Node70node --cpu-prof --cpu-prof-dir=./prof app.js71node --heap-prof --heap-prof-dir=./prof app.js7273# Go74go test -cpuprofile=cpu.out ./...75pprof -top cpu.out76pprof -web cpu.out77```7879## Best Practices8081- Set complexity budgets per module and enforce in CI82- Profile with realistic workloads, not synthetic ones83- Check both CPU and heap profiles for leaks84- Measure before/after every refactor85- Focus on the top 5 hot functions, not everything86- Combine with tests to ensure behavior is unchanged8788## Capabilities8990### complexity-analysis91Measure code complexity and duplication.9293**Parameters:**94- `path` (string): Source directory95- `threshold` (integer): Complexity threshold9697**Commands:**98- `python -m pip install radon`99- `radon cc src/ -s`100- `radon mi src/ -s`101- `python -m pip install vulture`102- `vulture src/`103104**Examples:**105- radon cc src/ -s -a106- radon mi src/ -s -j107- vulture src/ --min-confidence 100108109### runtime-analysis110Profile CPU, memory, and hot paths.111112**Parameters:**113- `profile-file` (string): Profiler output path114- `method` (string): cpu or heap profiling115116**Commands:**117- `python -m cProfile -o out.prof app.py`118- `python -m pstats`119- `node --cpu-prof --cpu-prof-dir=./prof app.js`120- `go test -cpuprofile=cpu.out ./...`121- `pprof -top cpu.out`122123**Examples:**124- python -m cProfile -s cumtime app.py | head -30125- node --heap-prof --heap-prof-dir=./prof app.js126- pprof -web cpu.out127128## References129- [Radon Docs](https://radon.readthedocs.io)130- [Vulture Docs](https://github.com/jendrikseipp/vulture)131- [pprof Docs](https://github.com/google/pprof)