| inlined-imports | true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| name | Code Complexity Detector | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description | Find overly complex code and file a simplification report | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| imports |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| engine |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| true |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| concurrency |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| permissions |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tools |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mcp-servers |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| strict | false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| safe-outputs |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeout-minutes | 90 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps |
|
Find overly complex code and file a simplification report.
Inputs
- Languages:
${{ inputs.languages }} - File globs:
${{ inputs.file-globs }}
- Determine file globs and store them as a space-delimited
GLOBSlist:- If
file-globsis set, split it on commas and trim whitespace. - Otherwise, map
languages(comma-separated) to globs using:- go →
**/*.go - python →
**/*.py - javascript →
**/*.{js,mjs,cjs} - typescript →
**/*.{ts,tsx} - java →
**/*.java - ruby →
**/*.rb - csharp →
**/*.cs - rust →
**/*.rs
- go →
- If
- Find all matching files (excluding tests and generated files):
FILES=$(for glob in ${GLOBS}; do rg --files \ -g "${glob}" \ -g "!**/*_test.*" \ -g "!**/test_*" \ -g "!**/*.spec.*" \ -g "!**/*.test.*" \ -g "!**/*.pb.*" \ -g "!**/*_gen.*" \ -g "!**/generated/**" done | sort -u)
- If no files are found, call
noopwith a brief reason and stop. - Call Serena
activate_projectwith${{ github.workspace }}. - If there are more than 200 files, focus on the 200 largest by line count:
printf '%s\n' "$FILES" | xargs wc -l | sort -nr | head -200 | awk '{print $2}'
- For each selected file, use
get_symbols_overview(Serena) when supported; otherwise, extract functions/methods with language-appropriatergpatterns and light file inspection. - Use the Pick Three, Keep Many pattern for the analysis phase: spawn 3
general-purposesub-agents, each searching for complexity from a different angle (e.g., one measuring nesting depth and cyclomatic complexity, one looking for redundant conditionals and style outliers, one checking for inline logic that reimplements existing helpers). Include the file list, symbol inventory, and the full "How to Analyze" / "What to Skip" criteria in each sub-agent prompt. Each sub-agent should return all findings that meet the quality criteria.
- Build an inventory by file and directory of:
- Module/package/namespace (when applicable)
- Function and method names (with receivers/classes if relevant)
- Rough line count per function
- Identify complexity hotspots:
- Deep nesting (3+ levels of indentation within a function)
- Redundant conditionals (branches that collapse to simpler logic)
- Long functions (>50 lines with multiple responsibilities)
- Style outliers (verbose patterns where the rest of the codebase uses a concise idiom)
- Inline reimplementation (custom logic that duplicates an existing helper or standard library function)
- Use Serena (
find_symbol,search_for_pattern,find_referencing_symbols) when supported to trace helper reuse and identify reimplementations. - Focus on high-impact, actionable findings where a simplification is clearly safe and behavior-preserving.
A finding must clear at least one of these bars to be worth reporting:
- Style conformance — the code is a clear outlier compared to the rest of the codebase (e.g., one function uses a verbose pattern that every other function avoids).
- Helper reuse — an existing utility or helper function already does what the code is reimplementing.
- Significant clarity improvement — the change meaningfully reduces complexity (e.g., collapsing 10+ lines of tangled logic into 2–3 readable lines, early returns eliminating deep nesting, extracting a helper from repeated inline logic).
Do not report micro-changes that swap one valid idiom for another (renaming variables, reordering equivalent expressions, replacing a two-line pattern with a one-liner). These are not worth a maintainer's time to review.
- Test or generated files
- Trivial helpers (<5 lines) unless they are style outliers
- Subjective complexity preferences — only flag code that is clearly overcomplicated, not "could be slightly cleaner"
- Functions that are long but straightforward (e.g., switch statements mapping many values)
Issue title: Code complexity findings (date)
Issue body:
- Files analyzed: [count]
- Functions cataloged: [count]
- Complexity hotspots found: [count]
File:
path/to/file.extFunction:FuncName(...)Complexity: [brief description — e.g., 4 levels of nesting, 3 nested conditionals] Suggested simplification: [early returns / extract helper / collapse conditionals]File:
path/to/file.extFunction:FuncName(...)Why outlier: [brief explanation] Suggested simplification: [use existing helper / match codebase convention]
- [Concrete action for each finding]
- Serena tools used:
activate_project,get_symbols_overview,find_symbol,search_for_pattern- Analysis date: [timestamp]
Noop is the expected outcome most days. Only create an issue when findings are:
- Concrete: You can name the exact functions, files, and what should change.
- High-impact: The simplification would meaningfully improve readability, not just satisfy an abstract ideal.
- Non-controversial: A maintainer would agree this is a clear improvement without debate.
If findings are marginal or subjective, call noop.
${{ inputs.additional-instructions }}