Agent Skillsvudovn/ag-kit › simplify-code

simplify-code

GitHub

指导识别并消除代码中的过度工程、死代码、深层嵌套及不必要抽象,通过增量简化流程降低认知负荷,同时确保行为不变和测试通过。

.agents/skills/simplify-code/SKILL.md vudovn/ag-kit

Trigger Scenarios

需要重构复杂或难以理解的代码 清理未使用的导入、变量或注释代码 优化过深的条件嵌套逻辑 简化参数过多或过度设计的函数

Install

npx skills add vudovn/ag-kit --skill simplify-code -g -y
More Options

Non-standard path

npx skills add https://github.com/vudovn/ag-kit/tree/main/.agents/skills/simplify-code -g -y

Use without installing

npx skills use vudovn/ag-kit@simplify-code

指定 Agent (Claude Code)

npx skills add vudovn/ag-kit --skill simplify-code -a claude-code -g -y

安装 repo 全部 skill

npx skills add vudovn/ag-kit --all -g -y

预览 repo 内 skill

npx skills add vudovn/ag-kit --list

SKILL.md

Frontmatter
{
    "name": "simplify-code",
    "effort": "medium",
    "version": "1.0.0",
    "description": "Reduce complexity of over-engineered code. Identify unnecessary abstractions, remove dead code, flatten deep nesting, and simplify logic while preserving behavior.",
    "when_to_use": "When code is over-engineered, overly abstract, deeply nested, or more complex than needed. When user asks to 'simplify', 'clean up', 'reduce complexity', or 'make this simpler'. NOT for adding new features.",
    "allowed-tools": "Read, Write, Edit, Grep, Glob"
}

Simplify Code — Reduce Unnecessary Complexity

The best code is the code you don't have to write. The second best is the code anyone can read.

Core Principle

Complexity is a cost. Every abstraction, every indirection, every clever pattern
adds cognitive load. Simplify ruthlessly unless complexity serves a clear purpose.

Simplification Checklist

1. Unnecessary Abstractions

Smell Simplification
Wrapper class that just delegates Remove wrapper, use the inner class directly
Factory that creates only one type Replace with direct constructor
Strategy pattern with one strategy Replace with simple function
Interface with one implementation Remove interface, use the class
Abstract class with one child Merge into the child class
Config object for 2 values Use function parameters

2. Dead Code

Smell Action
Unused imports Remove
Unreachable branches Remove (check tests first)
Commented-out code Remove (it's in git history)
Unused variables/functions Remove
TODO comments older than 6 months Remove or create issue
Feature flags for launched features Remove flag, keep the code

3. Deep Nesting

// ❌ Before: 4 levels deep
function process(data) {
  if (data) {
    if (data.items) {
      for (const item of data.items) {
        if (item.active) {
          doSomething(item)
        }
      }
    }
  }
}

// ✅ After: Early returns + filter
function process(data) {
  if (!data?.items) return

  data.items
    .filter(item => item.active)
    .forEach(doSomething)
}

4. Over-Parameterized Functions

// ❌ Before: 8 parameters
function createUser(name, email, age, role, dept, active, verified, avatar) { }

// ✅ After: Object parameter
function createUser(opts: CreateUserOpts) { }

5. Premature Optimization

Smell Simplification
Custom cache for <100 items Remove cache, measure first
Memoization on cheap functions Remove memo
Lazy loading for small modules Use direct import
Complex state machine for 3 states Use simple if/else or switch

Simplification Protocol

Step 1: Identify Complexity

- Count nesting levels (target: ≤3)
- Count function parameters (target: ≤4)
- Count lines per function (target: ≤30)
- Count abstractions per feature (target: ≤2)
- Check for dead code (target: 0)

Step 2: Verify Understanding

Before simplifying, ensure you understand:

  • What the code does (not what it looks like it does)
  • Why it was written this way (maybe there's a reason)
  • What tests cover it (simplification must not break tests)

Step 3: Simplify Incrementally

1. Remove dead code first (safest)
2. Flatten nesting with early returns
3. Inline trivial abstractions
4. Merge related functions
5. Simplify data structures

Step 4: Verify Behavior Preserved

npm run test    # All existing tests still pass
npm run build   # Still compiles

When NOT to Simplify

Situation Why Keep Complexity
Performance-critical hot path Optimization may look complex but is necessary
Required by framework/library External constraints
Explicitly requested pattern User chose this architecture
Will need extension soon Abstraction prepares for known growth

Ask first: "This pattern seems over-engineered. Should I simplify it, or is there a reason for the abstraction?"

Version History

  • 211561c Current 2026-08-20 11:39

Same Skill Collection

.agents/skills/api-patterns/SKILL.md
.agents/skills/app-builder/SKILL.md
.agents/skills/app-builder/templates/SKILL.md
.agents/skills/architecture/SKILL.md
.agents/skills/bash-linux/SKILL.md
.agents/skills/batch-operations/SKILL.md
.agents/skills/behavioral-modes/SKILL.md
.agents/skills/brainstorming/SKILL.md
.agents/skills/clean-code/SKILL.md
.agents/skills/code-review-checklist/SKILL.md
.agents/skills/code-review-graph/SKILL.md
.agents/skills/context-compression/SKILL.md
.agents/skills/coordinator-mode/SKILL.md
.agents/skills/database-design/SKILL.md
.agents/skills/deployment-procedures/SKILL.md
.agents/skills/design-spec/SKILL.md
.agents/skills/documentation-templates/SKILL.md
.agents/skills/frontend-architecture/SKILL.md
.agents/skills/frontend-design/SKILL.md
.agents/skills/game-development/2d-games/SKILL.md
.agents/skills/game-development/3d-games/SKILL.md
.agents/skills/game-development/game-art/SKILL.md
.agents/skills/game-development/game-audio/SKILL.md
.agents/skills/game-development/game-design/SKILL.md
.agents/skills/game-development/mobile-games/SKILL.md
.agents/skills/game-development/multiplayer/SKILL.md
.agents/skills/game-development/pc-games/SKILL.md
.agents/skills/game-development/SKILL.md
.agents/skills/game-development/vr-ar/SKILL.md
.agents/skills/game-development/web-games/SKILL.md
.agents/skills/geo-fundamentals/SKILL.md
.agents/skills/i18n-localization/SKILL.md
.agents/skills/intelligent-routing/SKILL.md
.agents/skills/lint-and-validate/SKILL.md
.agents/skills/mcp-builder/SKILL.md
.agents/skills/memory-system/SKILL.md
.agents/skills/mobile-design/SKILL.md
.agents/skills/nextjs-react-expert/SKILL.md
.agents/skills/nodejs-best-practices/SKILL.md
.agents/skills/parallel-agents/SKILL.md
.agents/skills/performance-profiling/SKILL.md
.agents/skills/plan-writing/SKILL.md
.agents/skills/powershell-windows/SKILL.md
.agents/skills/python-patterns/SKILL.md
.agents/skills/red-team-tactics/SKILL.md
.agents/skills/rust-pro/SKILL.md
.agents/skills/seo-fundamentals/SKILL.md
.agents/skills/server-management/SKILL.md
.agents/skills/skillify/SKILL.md

Metadata

Files
0
Version
211561c
Hash
1e2ab8d0
Indexed
2026-08-20 11:39

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-04 03:55
浙ICP备14020137号-1 $bản đồ khách truy cập$