agentleFS
jmxt3jmxt3/gitscape.ai/.agents/skills/code-simplification/SKILL.md

code-simplification

Skill32 starsChanged 5 months agoApache-2.0View on GitHub

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

46 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use constraint-driven-development, doubt-driven-development and 4 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • vinvcnSkill

    constraint-driven-development

    把一个项目的质量线确立为书面契约,并阻止 agent 悄悄降低它。通过访谈确定用户在意哪些维度,当用户心里没有数字时提供合理的默认阈值,把一切记录进 CONSTRAINTS.md,并盯住 diff 中质量线被削弱的迹象——新增的 @ts-ignore 或 eslint-disable 抑制注释、被跳过或删除的测试、被剥掉的断言、未实现的 stub、被调低的阈值。当没有任何质量线被写下来时使用;当用户说 "set up constraints" 或 "define our standards" 时;当用户希望把他们在意的维度——无障碍性、Web 性能、覆盖率——设置成被强制执行的约束时;当 agent 为了变绿不断静默检查或跳过测试时;当你需要一个覆盖率或性能阈值却不知道该选什么数字时;或者当 agent 写下的代码超出任何人会读的体量时。

    Also in 4 projects that use this

  • mycelium-hqSkill

    doubt-driven-development

    Use when correctness matters more than speed: about to commit non-trivial code, make an architectural call under uncertainty, work in unfamiliar code, or assert what the compiler cannot check (''this is safe'', ''thread-safe'', ''this scales'', ''matches the spec''). Strongest on high-stakes surfaces (production deploys, security-sensitive logic, data migrations, irreversible operations) and when the user asks to sanity-check, red-team, double-check, or get a second opinion on a decision.

    Also in 19 projects that use this

  • luischanciSkill

    interview-me

    Interactive interview to formalize a research idea into a structured specification with hypotheses and empirical strategy.

    Also in 16 projects that use this

  • CloudflareSkill

    receiving-code-review

    Use when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation

    Also in 6 projects that use this

  • OpenAISkill

    requesting-code-review

    Use when completing tasks, implementing major features, or before merging to verify work meets requirements

    Also in 5 projects that use this

  • OpenAISkill

    executing-plans

    Use when you have a written implementation plan to execute in a separate session with review checkpoints

    Also in 5 projects that use this

The file

We split this skill into the rules it gives an agent

9 rules. 0 are common, 8 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 45 edited versions we read keep these.

  • 8

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before simplifying any code, answer: why was it written this way?

    line 27
  2. Distinctive:

    Read the function end-to-end

    line 33
  3. Distinctive:

    Read its callers — what do they expect?

    line 34
  4. Distinctive:

    Read its tests — what behavior is verified?

    line 35
  5. Very specific:

    Check git history: git log -p -- path/to/file.py

    line 36
  6. Distinctive:

    If the code lacks tests, add tests before simplifying.

    line 41
  7. Distinctive:

    Run them, confirm they pass.

    line 50
  8. Distinctive:

    Run the full test suite after each simplification:

    line 169
  9. Distinctive:

    If any test fails, revert that specific simplification and reconsider.

    line 175

“Common” is measured: kept by at least 6 in 10 of the 45 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Simplification

Overview

Reduce complexity while preserving exact behavior. The goal is code that a new engineer can read and understand without asking the author questions. Simplification is not optimization — do not change performance characteristics unless that is the explicit goal.

When to Use

  • Code works but is harder to read than it should be
  • A function is doing more than one thing
  • Nested conditionals make the control flow hard to follow
  • Variable names are generic (data, result, temp)
  • The same logic appears in multiple places
  • A reviewer needed to ask what the code does

When NOT to use: Code that is intentionally complex for performance reasons (document with a comment instead of simplifying).

The Chesterton's Fence Rule

"Don't remove a fence you don't understand."

Before simplifying any code, answer: why was it written this way? If you can't answer that, you risk removing a safeguard. Read the git history, grep for related tests, and understand the intent before changing anything.

The Simplification Process

Step 1: Understand Before Touching

  • Read the function end-to-end
  • Read its callers — what do they expect?
  • Read its tests — what behavior is verified?
  • Check git history: git log -p -- path/to/file.py
  • Do not change anything yet

Step 2: Cover First

If the code lacks tests, add tests before simplifying. You need a safety net:

def test_generate_skill_name_sanitizes_input():
    assert generate_skill_name("my repo") == "my-repo"
    assert generate_skill_name("My Repo!") == "my-repo"
    assert generate_skill_name("  spaces  ") == "spaces"

Run them, confirm they pass. Now you can simplify safely.

Step 3: Apply Simplifications Incrementally

Apply one simplification at a time, running tests after each:

Deep Nesting → Guard Clauses

# BAD: Pyramid of doom
def process_skill(skill):
    if skill is not None:
        if skill.get("name"):
            if len(skill["name"]) > 0:
                return skill["name"].lower()
        return None
    return None

# GOOD: Guard clauses
def process_skill(skill):
    if not skill:
        return None
    if not skill.get("name"):
        return None
    return skill["name"].lower()

Long Functions → Extracted Helpers

# BAD: One function doing three jobs
def export_skill(repo: str) -> bytes:
    # Fetch files
    files = []
    for branch in ["main", "master"]:
        try:
            contents = github_client.get_contents(repo, branch)
            files = contents
            break
        except Exception:
            continue
    
    # Filter relevant files
    relevant = [f for f in files if f.path.endswith((".md", ".py", ".ts"))]
    
    # Build zip
    buf = io.BytesIO()
    with zipfile.ZipFile(buf, "w") as zf:
        for f in relevant:
            zf.writestr(f.path, f.decoded_content)
    return buf.getvalue()

# GOOD: Each function does one thing
def export_skill(repo: str) -> bytes:
    files = fetch_repo_files(repo)
    relevant = filter_skill_files(files)
    return build_zip(relevant)

def fetch_repo_files(repo: str) -> list:
    for branch in ["main", "master"]:
        try:
            return github_client.get_contents(repo, branch)
        except Exception:
            continue
    return []

def filter_skill_files(files: list) -> list:
    return [f for f in files if f.path.endswith((".md", ".py", ".ts"))]

def build_zip(files: list) -> bytes:
    buf = io.BytesIO()
    with zipfile.ZipFile(buf, "w") as zf:
        for f in files:
            zf.writestr(f.path, f.decoded_content)
    return buf.getvalue()

Generic Names → Descriptive Names

# BAD
def process(d, r):
    result = []
    for item in d:
        if item["type"] == r:
            result.append(item)
    return result

# GOOD
def filter_files_by_type(files: list[dict], file_type: str) -> list[dict]:
    return [f for f in files if f["type"] == file_type]

Duplicated Logic → Shared Functions

# BAD: Same validation in three places
def create_skill(name: str):
    if not name or len(name) > 100:
        raise ValueError("Invalid name")
    ...

def update_skill(name: str):
    if not name or len(name) > 100:
        raise ValueError("Invalid name")
    ...

# GOOD
def validate_skill_name(name: str) -> None:
    if not name or len(name) > 100:
        raise ValueError("Skill name must be 1-100 characters")

def create_skill(name: str):
    validate_skill_name(name)
    ...

Step 4: Verify Nothing Changed

Run the full test suite after each simplification:

pytest tests/ -v

If any test fails, revert that specific simplification and reconsider. Simplification must not change behavior.

Step 5: Review the Result

After simplifying, ask:

  • Can a new engineer read this function without asking questions?
  • Is the control flow obvious?
  • Does every name say what the thing is, not what it does mechanically?
  • Are there any functions over 30 lines that could be split?

The Rule of 500

A file over 500 lines is a sign it's doing too much. Consider splitting. For GitScape:

  • api/app/skill_builder.py — if over 500 lines, split into name_sanitizer.py, file_filter.py, assembler.py
  • web/components/SkillExport.tsx — if over 500 lines, split by concern

Common Rationalizations

RationalizationReality
"I understand the code"You wrote it. Someone else reads it cold at 11 PM during an incident.
"Extracting functions adds overhead"Modern runtimes inline trivially. The overhead is unmeasurable. The clarity is immediate.
"The code is complex because the problem is complex"Complex problems have simple solutions and complex solutions. Always look for the simpler one.
"I shouldn't touch it — it works"Working code that no one understands becomes legacy code that no one can change safely.

Red Flags

  • Functions over 30 lines
  • Nesting deeper than 3 levels
  • Variables named data, result, temp, info
  • Comments that explain what the code does (rewrite instead)
  • Duplicated logic (copy-paste is a red flag)
  • Boolean parameters that change the function's behavior (create_skill(name, dry_run=True))

Verification

After simplification:

  • All tests still pass (no behavior change)
  • The diff is a net reduction in lines (usually)
  • No function is over 30 lines
  • No variable is named data, result, or temp
  • Duplicated logic has been extracted to a shared function
  • No comments that explain what the code does (only why)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.