Agent skill

Refactor Method Complexity Reduce

by totvs in totvs/engpro-advpl-tlpp-skills

Refactor given method ${input:methodName} to reduce its cognitive complexity to ${input:complexityThreshold} or below, by extracting helper methods.

MITAuto-check passedDevelopment

Install Refactor Method Complexity Reduce

skills CLI
$ npx skills add totvs/engpro-advpl-tlpp-skills --skill refactor-method-complexity-reduce -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install totvs/engpro-advpl-tlpp-skills refactor-method-complexity-reduce --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/totvs/engpro-advpl-tlpp-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/advpl-tlpp/refactor-method-complexity-reduce .claude/skills/refactor-method-complexity-reduce && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
refactor-method-complexity-reduce
GitHub stars
141
Token cost
~1.9k tokens
SKILL.md length
688 words
Files
1
Skills in repo
19
Repo updated
First seen
Licence
MIT

At a glance

Refactor given method ${input:methodName} to reduce its cognitive complexity to ${input:complexityThreshold} or below, by extracting helper methods.

  • Works in 6 steps: Analyze the current method to identify… → Identify extraction opportunities → Extract focused helper methods → …
  • User says reduce complexity
  • SKILL.md covers Objective, Instructions, Implementation Approach and Result, plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Refactor Method Complexity Reduce is an agent skill from totvs/engpro-advpl-tlpp-skills. Refactor given method ${input:methodName} to reduce its cognitive complexity to ${input:complexityThreshold} or below, by extracting helper methods. Use when user says 'reduce complexity', 'simplify method', 'cognitive complexity too high'.

Its SKILL.md is about 1.9k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Refactoring and Code simplification. The repository describes itself as: Repositório contendo skills para orientar desenvolvimento ADVPL/TLPP com agentes de IA. The licence is MIT.

When your agent uses it

  • User says reduce complexity
  • Simplify method
  • Cognitive complexity too high

Example prompts

  • “reduce complexity”
  • “simplify method”
  • “cognitive complexity too high”
  • “/refactor-method-complexity-reduce”

Workflow steps

6 steps, taken from the first numbered list in SKILL.md.

  1. Analyze the current method to identify sources of cognitive complexity
  2. Identify extraction opportunities
  3. Extract focused helper methods
  4. Simplify the main method
  5. Preserve functionality
  6. Best practices

What it can do on your machine

Read from SKILL.md and the folder at commit 3908e4e. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are diff).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Refactor Method Complexity Reduce loads about 1.9k tokens when it runs. Until then it costs about 70 tokens; SKILL.md has 688 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~70
When it runs · the whole SKILL.md, loaded when a task matches
~1.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from totvs/engpro-advpl-tlpp-skills at commit 3908e4e, republished under its MIT licence (© totvs). 688 words, ~1,912 tokens.

Download SKILL.mdSave it as .claude/skills/refactor-method-complexity-reduce/SKILL.md (or your agent's skills folder).
name
refactor-method-complexity-reduce
description
Refactor given method `${input:methodName}` to reduce its cognitive complexity to `${input:complexityThreshold}` or below, by extracting helper methods. Use when user says 'reduce complexity', 'simplify method', 'cognitive complexity too high'.
license
MIT
metadata.domain
Protheus
metadata.maintainer
Customizações ADVPL/TLPP
metadata.author
Thalion Starforge
metadata.version
4.1.0
metadata.category
Code Quality and Review

Refactor Method to Reduce Cognitive Complexity

Objective

Refactor the method ${input:methodName}, to reduce its cognitive complexity to ${input:complexityThreshold} or below, by extracting logic into focused helper methods.

Instructions

  1. Analyze the current method to identify sources of cognitive complexity:

    • Nested conditional statements
    • Multiple if-else or switch chains
    • Repeated code blocks
    • Multiple loops with conditions
    • Complex boolean expressions
  2. Identify extraction opportunities:

    • Validation logic that can be extracted into a separate method
    • Type-specific or case-specific processing that repeats
    • Complex transformations or calculations
    • Common patterns that appear multiple times
  3. Extract focused helper methods:

    • Each helper should have a single, clear responsibility
    • Extract validation into separate Validate* methods
    • Extract type-specific logic into handler methods
    • Create utility methods for common operations
    • Use appropriate access levels (static, private, async)
  4. Simplify the main method:

    • Reduce nesting depth
    • Replace massive if-else chains with smaller orchestrated calls
    • Use switch statements where appropriate for cleaner dispatch
    • Ensure the main method reads as a high-level flow
  5. Preserve functionality:

    • Maintain the same input/output behavior
    • Keep all validation and error handling
    • Preserve exception types and error messages
    • Ensure all parameters are properly passed to helpers
  6. Best practices:

    • Make helper methods static when they don't need instance state
    • Use null checks and guard clauses early
    • Avoid creating unnecessary local variables
    • Consider using tuples for multiple return values
    • Group related helper methods together

Implementation Approach

  • Extract helper methods before refactoring the main flow
  • Test incrementally to ensure no regressions
  • Use meaningful names that describe the extracted responsibility
  • Keep extracted methods close to where they're used
  • Consider making repeated code patterns into generic methods

Result

The refactored method should:

  • Have cognitive complexity reduced to the target threshold of ${input:complexityThreshold} or below
  • Be more readable and maintainable
  • Have clear separation of concerns
  • Be easier to test and debug
  • Retain all original functionality

Testing and Validation

CRITICAL: After completing the refactoring, you MUST:

  1. Run all existing tests related to the refactored method and its surrounding functionality
  2. MANDATORY: Explicitly verify test results show "failed=0"
    • NEVER assume tests passed - always examine the actual test output
    • Search for the summary line containing pass/fail counts (e.g., "passed=X failed=Y")
    • If the summary shows any number other than "failed=0", tests have FAILED
    • If test output is in a file, read the entire file to locate and verify the failure count
    • Running tests is NOT the same as verifying tests passed
    • Do not proceed until you have explicitly confirmed zero failures
  3. If any tests fail (failed > 0):
    • State clearly how many tests failed
    • Analyze each failure to understand what functionality was broken
    • Common causes: null handling, empty collection checks, condition logic errors
    • Identify the root cause in the refactored code
    • Correct the refactored code to restore the original behavior
    • Re-run tests and verify "failed=0" in the output
    • Repeat until all tests pass (failed=0)
  4. Verify compilation - Ensure there are no compilation errors
  5. Check cognitive complexity - Confirm the metric is at or below the target threshold of ${input:complexityThreshold}
Show full SKILL.md (197 more words)Show less

Confirmation Checklist

  • Code compiles without errors
  • Test results explicitly state "failed=0" (verified by reading the output)
  • All test failures analyzed and corrected (if any occurred)
  • Cognitive complexity is at or below the target threshold of ${input:complexityThreshold}
  • All original functionality is preserved
  • Code follows project conventions and standards

AdvPL/TLPP Complexity Reduction Patterns

When reducing complexity in AdvPL/TLPP functions, apply these ecosystem-specific extraction patterns.

Typical High-Complexity AdvPL Functions

Protheus legacy routines (e.g., MATA010, FINA010, COMA010) often contain monolithic User Function implementations exceeding 500 lines with deeply nested conditionals. Common complexity sources:

  • Nested If/ElseIf/Else/EndIf chains for business rules
  • Do Case / Case / EndCase with many branches
  • While loops with multiple embedded conditions for workarea processing
  • Mixed validation, processing, and UI logic in a single function
Extraction Strategy for AdvPL/TLPP
diff
// BEFORE: Monolithic function with high complexity
- User Function FINA010()
-   If cAction == "INCLUDE"
-     If ValidateHeader()
-       // 50 lines of inclusion logic
-       For nI := 1 To Len(aItems)
-         If aItems[nI][1] > 0
-           // 30 lines of item processing
-           If lTaxRequired
-             // 20 lines of tax calculation
-           EndIf
-         EndIf
-       Next nI
-     EndIf
-   ElseIf cAction == "ALTER"
-     // 80 lines of update logic
-   ElseIf cAction == "DELETE"
-     // 40 lines of delete logic
-   EndIf
- Return

// AFTER: Orchestrator + focused helpers
+ User Function FINA010()
+   Do Case
+     Case cAction == "INCLUDE"
+       ProcessInclusion()
+     Case cAction == "ALTER"
+       ProcessUpdate()
+     Case cAction == "DELETE"
+       ProcessDeletion()
+   EndCase
+ Return
+
+ Static Function ProcessInclusion() as Logical
+   If !ValidateHeader()
+     Return .F.
+   EndIf
+   Return ProcessItems(aItems)
+
+ Static Function ProcessItems(aItems as Array) as Logical
+   Local nI as Numeric
+   For nI := 1 To Len(aItems)
+     If aItems[nI][1] > 0
+       ProcessSingleItem(aItems[nI])
+     EndIf
+   Next nI
+ Return .T.
+
+ Static Function ProcessSingleItem(aItem as Array) as Logical
+   // focused item logic
+   If IsTaxRequired(aItem)
+     CalculateItemTax(aItem)
+   EndIf
+ Return .T.
AdvPL/TLPP Helper Method Guidelines
GuidelineAdvPL/TLPP Application
Make helpers staticUse Static Function — invisible outside the source file
Use guard clausesEarly Return to reduce nesting depth
Meaningful namesTLPP allows long identifiers; use them (e.g., ValidateCustomerCredit)
Type annotations (TLPP)Add as Type to all parameters and return values
Avoid Private varsExtracted helpers should use Local variables only
Preserve PARAMIXBIf the original function reads PARAMIXB, pass values explicitly to helpers

© totvs, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/advpl-tlpp/refactor-method-complexity-reduce of totvs/engpro-advpl-tlpp-skills.

Open the folder on GitHubat commit 3908e4e

Compare with similar skills

Refactor Method Complexity Reduce next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Refactor Method Complexity Reduce compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Refactor Method Complexity Reduce this skilltotvs/engpro-advpl-tlpp-skills141—~1.9kAutomated safety check: PassMIT
PonytailDavidObando/gsharp5648 repos~1.7kAutomated safety check: PassMIT
Code Simplification for ego-litecitrolabs/ego-lite17k—~1.2kAutomated safety check: PassMIT
Refactor Pass for Simplicitystar-history/star-history9.6k1 repos~168Automated safety check: PassMIT
RTK Rust Code Simplifierrtk-ai/rtk83k—~1.1kAutomated safety check: PassApache-2.0
Deslopmillionco/react-doctor15k—~1.2kAutomated safety check: PassCustom licence

Similar skills

  • Ponytail

    DavidObando/gsharp

    Forces the laziest solution that actually works, simplest, shortest, most minimal.

    564 GitHub starsUsed in 8 repos~1.7k tokens
    DevelopmentAuto-check passed
  • Finds and implements evidence-backed simplifications in the ego-lite repository, such as dead code, duplicated state and speculative abstractions, without hiding behavior changes.

    17k GitHub stars~1.2k tokensUpdated 14 days ago
    DevelopmentAuto-check passed
  • Refactor Pass for Simplicity

    star-history/star-history

    Perform a refactor pass focused on simplicity after recent changes. Use when the user asks for a refactor/cleanup pass, simplification, or dead-code removal…

    9.6k GitHub starsUsed in 1 repo~168 tokens
    DevelopmentAuto-check passed
  • Reviews RTK's Rust code for over-engineering and verbose patterns, applying idioms like iterator chains and early returns while protecting a specific list of constraints from being simplified away.

    83k GitHub stars~1.1k tokensUpdated today
    DevelopmentAuto-check passed
  • Deslop

    millionco/react-doctor

    Simplify and refine recently modified code while preserving functionality.

    15k GitHub stars~1.2k tokensUpdated today
    DevelopmentAuto-check passed
  • Simplify Codebase

    tt-a1i/simplify-codebase

    Simplification audit or authorized codebase simplification whose stated objective is to remove accidental complexity.

    504 GitHub stars~2.2k tokensUpdated 1 mo ago
    DevelopmentAuto-check passed

More from totvs/engpro-advpl-tlpp-skills

All 19 skills in this repo
  • AdvPL UTF-8 to CP1252 Converter

    totvs/engpro-advpl-tlpp-skills

    Converts AdvPL and TLPP source files from UTF-8 to Windows-1252 in place after code generation, because the Protheus compiler accepts only CP1252 files.

    141 GitHub stars~2.6k tokensUpdated 2 days ago
    Auto-check passed
  • AdvPL/TLPP Compile in VS Code

    totvs/engpro-advpl-tlpp-skills

    Compiles AdvPL and TLPP sources from VS Code with the TOTVS Developer Studio extension, handling server setup, connection and compile result reporting.

    141 GitHub stars~3.7k tokensUpdated 2 days ago
    Auto-check passed
  • Protheus Spec-Driven Development

    totvs/engpro-advpl-tlpp-skills

    Plans and builds Protheus AdvPL/TLPP features through Specify, Design, Tasks and Execute phases whose depth scales with the size of the change.

    141 GitHub stars~3.6k tokensUpdated 2 days ago
    Auto-check passed
  • AdvPL and TLPP Code Review

    totvs/engpro-advpl-tlpp-skills

    Reviews AdvPL and TLPP source against SonarQube rules, ProtheusDOC requirements, security, performance and Protheus conventions, and reports findings by severity.

    141 GitHub stars~2.5k tokensUpdated 2 days ago
    Auto-check passed
  • Protheus Data Dictionary Lookup

    totvs/engpro-advpl-tlpp-skills

    Queries the TOTVS Protheus ERP data dictionary for tables, fields, indexes, parameters, triggers and lookups, including impact checks during refactoring.

    141 GitHub stars~1.5k tokensUpdated 2 days ago
    Auto-check passed
  • Protheus MVC Generator

    totvs/engpro-advpl-tlpp-skills

    Generates Protheus MVC screens in ADVPL/TLPP, with ModelDef, ViewDef, MenuDef and Browse functions for single-entity and master-detail layouts.

    141 GitHub stars~2.2k tokensUpdated 2 days ago
    Auto-check passed

Categories

Questions about Refactor Method Complexity Reduce

What does Refactor Method Complexity Reduce do?

Refactor given method ${input:methodName} to reduce its cognitive complexity to ${input:complexityThreshold} or below, by extracting helper methods. Refactor Method Complexity Reduce is an agent skill from totvs/engpro-advpl-tlpp-skills. Refactor given method ${input:methodName} to reduce its cognitive complexity to ${input:complexityThreshold} or below, by extracting helper methods.

When should I use Refactor Method Complexity Reduce?

Refactor Method Complexity Reduce fits situations like: user says reduce complexity; simplify method; cognitive complexity too high.

How do I install Refactor Method Complexity Reduce in Claude Code?

Run `npx skills add totvs/engpro-advpl-tlpp-skills --skill refactor-method-complexity-reduce -a claude-code`. Or copy the skill folder (skills/advpl-tlpp/refactor-method-complexity-reduce in totvs/engpro-advpl-tlpp-skills) into .claude/skills/refactor-method-complexity-reduce in your project. Claude Code loads it when a task matches its description.

How do I install Refactor Method Complexity Reduce in Codex?

Run `npx skills add totvs/engpro-advpl-tlpp-skills --skill refactor-method-complexity-reduce -a codex`. Or copy the skill folder (skills/advpl-tlpp/refactor-method-complexity-reduce in totvs/engpro-advpl-tlpp-skills) into .agents/skills/refactor-method-complexity-reduce in your project. Codex loads it when a task matches its description.

Can I use Refactor Method Complexity Reduce in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add totvs/engpro-advpl-tlpp-skills --skill refactor-method-complexity-reduce -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/refactor-method-complexity-reduce, .gemini/skills/refactor-method-complexity-reduce, .github/skills/refactor-method-complexity-reduce and .opencode/skills/refactor-method-complexity-reduce in your project.

What does Refactor Method Complexity Reduce need to run?

SKILL.md names no scripts, command-line tools or credentials: Refactor Method Complexity Reduce is instructions for the agent only.

Does Refactor Method Complexity Reduce access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Refactor Method Complexity Reduce safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Refactor Method Complexity Reduce use?

Refactor Method Complexity Reduce is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Refactor Method Complexity Reduce use?

About 1.9k tokens (SKILL.md is roughly 7.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Refactor Method Complexity Reduce?

Skills that share tags, products or a category with Refactor Method Complexity Reduce: Ponytail (DavidObando/gsharp, 564 stars), Code Simplification for ego-lite (citrolabs/ego-lite, 17k stars), Refactor Pass for Simplicity (star-history/star-history, 9.6k stars) and RTK Rust Code Simplifier (rtk-ai/rtk, 83k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Refactor Method Complexity Reduce?

totvs (a GitHub organization) maintains it in totvs/engpro-advpl-tlpp-skills, which has 141 GitHub stars. The repository holds 19 skills in this directory. The repository was last updated on October 5, 2026.

Source: totvs/engpro-advpl-tlpp-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.