simplify
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode Simplification Skill
代码简化Skill
Multi-agent code analysis and simplification workflow.
多Agent代码分析与简化工作流。
Execution Flow
执行流程
┌─────────────────────────────────────────────────────────┐
│ 1. Determine Scope (git diff or user input) │
├─────────────────────────────────────────────────────────┤
│ 2. Phase 1: 4 Analysis Agents (Parallel) │
│ ┌─────────────────┬─────────────────┐ │
│ │ complexity- │ pattern- │ │
│ │ analyzer │ checker │ │
│ ├─────────────────┼─────────────────┤ │
│ │ naming- │ readability- │ │
│ │ reviewer │ analyzer │ │
│ └─────────────────┴─────────────────┘ │
├─────────────────────────────────────────────────────────┤
│ 3. Consolidate Issues │
├─────────────────────────────────────────────────────────┤
│ 4. Phase 2: Issue Simplifiers (Parallel) │
│ ┌────────┬────────┬────────┬────────┐ │
│ │ issue1 │ issue2 │ issue3 │ ... │ │
│ └────────┴────────┴────────┴────────┘ │
├─────────────────────────────────────────────────────────┤
│ 5. Present Changes & AskUserQuestion │
├─────────────────────────────────────────────────────────┤
│ 6. Apply Selected Changes │
└─────────────────────────────────────────────────────────┘┌─────────────────────────────────────────────────────────┐
│ 1. Determine Scope (git diff or user input) │
├─────────────────────────────────────────────────────────┤
│ 2. Phase 1: 4 Analysis Agents (Parallel) │
│ ┌─────────────────┬─────────────────┐ │
│ │ complexity- │ pattern- │ │
│ │ analyzer │ checker │ │
│ ├─────────────────┼─────────────────┤ │
│ │ naming- │ readability- │ │
│ │ reviewer │ analyzer │ │
│ └─────────────────┴─────────────────┘ │
├─────────────────────────────────────────────────────────┤
│ 3. Consolidate Issues │
├─────────────────────────────────────────────────────────┤
│ 4. Phase 2: Issue Simplifiers (Parallel) │
│ ┌────────┬────────┬────────┬────────┐ │
│ │ issue1 │ issue2 │ issue3 │ ... │ │
│ └────────┴────────┴────────┴────────┘ │
├─────────────────────────────────────────────────────────┤
│ 5. Present Changes & AskUserQuestion │
├─────────────────────────────────────────────────────────┤
│ 6. Apply Selected Changes │
└─────────────────────────────────────────────────────────┘Step 1: Determine Scope
步骤1:确定范围
With Arguments
带参数时
Use provided file/directory path as scope.
使用提供的文件/目录路径作为范围。
Without Arguments (Recent Changes)
无参数时(最近变更)
bash
git diff --name-only HEAD~3 2>/dev/null | grep -E '\.(ts|tsx|js|jsx|py|go|rs|java)$'If no git changes, ask user for scope.
bash
git diff --name-only HEAD~3 2>/dev/null | grep -E '\.(ts|tsx|js|jsx|py|go|rs|java)$'如果没有Git变更,询问用户获取范围。
Step 2: Phase 1 - Analysis Agents (Parallel)
步骤2:阶段1 - 分析Agents(并行执行)
Execute 4 agents in parallel (single message with 4 Task calls).
并行执行4个Agent(通过单条消息发起4个Task调用)。
Scope Context (Provide to all agents)
范围上下文(提供给所有Agents)
Scope:
- Files: [List of files to analyze]
- Recent changes: [git diff summary if available]Scope:
- Files: [待分析文件列表]
- Recent changes: [若有则提供git diff摘要]Parallel Execution
并行执行
Task(subagent_type="simplify:complexity-analyzer", ...)
Task(subagent_type="simplify:pattern-checker", ...)
Task(subagent_type="simplify:naming-reviewer", ...)
Task(subagent_type="simplify:readability-analyzer", ...)| Agent | Role | Output |
|---|---|---|
| complexity-analyzer | Nested ternary, deep nesting, over-abstraction | Issue list with locations |
| pattern-checker | Project standards violation, inconsistency | Issue list with locations |
| naming-reviewer | Variable/function naming improvements | Issue list with suggestions |
| readability-analyzer | Readability issues, unnecessary comments | Issue list with suggestions |
Task(subagent_type="simplify:complexity-analyzer", ...)
Task(subagent_type="simplify:pattern-checker", ...)
Task(subagent_type="simplify:naming-reviewer", ...)
Task(subagent_type="simplify:readability-analyzer", ...)| Agent | 职责 | 输出 |
|---|---|---|
| complexity-analyzer | 检测嵌套三元表达式、深层嵌套、过度抽象 | 带位置信息的问题列表 |
| pattern-checker | 检测违反项目规范、不一致的代码 | 带位置信息的问题列表 |
| naming-reviewer | 提出变量/函数命名优化建议 | 带建议的问题列表 |
| readability-analyzer | 检测可读性问题、冗余注释 | 带建议的问题列表 |
Step 3: Consolidate Issues
步骤3:整合问题
Merge results from all 4 agents into a unified issue list:
markdown
undefined将4个Agent的结果合并为统一的问题列表:
markdown
undefinedIssues Found
Issues Found
Issue 1: [Title]
Issue 1: [标题]
- File: path/to/file.ts:42
- Type: complexity | pattern | naming | readability
- Description: [What's wrong]
- Suggestion: [How to fix]
- File: path/to/file.ts:42
- Type: complexity | pattern | naming | readability
- Description: [问题描述]
- Suggestion: [修复建议]
Issue 2: [Title]
Issue 2: [标题]
...
If no issues found, report "No improvements needed" and end....
如果未发现问题,报告“无需优化”并结束流程。Step 4: Phase 2 - Issue Simplifiers (Parallel)
步骤4:阶段2 - 问题简化Agents(并行执行)
For each issue, run an issue-simplifier agent in parallel:
Task(subagent_type="simplify:issue-simplifier", prompt="""
Issue: [Issue title]
File: [file path]
Location: [line numbers]
Type: [issue type]
Description: [description]
Suggestion: [suggestion]
Read the file and provide the exact code change needed.
Output format:
- Original code block
- Simplified code block
- Brief explanation
""")IMPORTANT: Run ALL issue-simplifier agents in a single message with multiple Task calls.
针对每个问题,并行运行issue-simplifier Agent:
Task(subagent_type="simplify:issue-simplifier", prompt="""
Issue: [问题标题]
File: [文件路径]
Location: [行号]
Type: [问题类型]
Description: [问题描述]
Suggestion: [修复建议]
Read the file and provide the exact code change needed.
Output format:
- Original code block
- Simplified code block
- Brief explanation
""")重要提示: 在单条消息中发起多个Task调用,并行运行所有issue-simplifier Agents。
Step 5: Present Changes
步骤5:展示变更
Compile all proposed changes:
markdown
undefined整理所有建议的变更:
markdown
undefinedProposed Simplifications
Proposed Simplifications
1. [File:Line] - [Issue Type]
1. [File:Line] - [Issue Type]
Original:
[original code]Simplified:
[simplified code]Reason: [explanation]
Original:
[original code]Simplified:
[simplified code]Reason: [说明]
2. [File:Line] - [Issue Type]
2. [File:Line] - [Issue Type]
...
undefined...
undefinedStep 6: Action Selection
步骤6:选择操作
AskUserQuestion(
questions=[{
"question": "Which simplifications would you like to apply?",
"header": "Apply",
"multiSelect": true,
"options": [
{"label": "Apply all (Recommended)", "description": "Apply all proposed changes"},
{"label": "Select individually", "description": "Choose specific changes"},
{"label": "Skip", "description": "Don't apply any changes"}
]
}]
)If "Select individually", present each change for approval.
AskUserQuestion(
questions=[{
"question": "Which simplifications would you like to apply?",
"header": "Apply",
"multiSelect": true,
"options": [
{"label": "Apply all (Recommended)", "description": "Apply all proposed changes"},
{"label": "Select individually", "description": "Choose specific changes"},
{"label": "Skip", "description": "Don't apply any changes"}
]
}]
)如果选择“Select individually”,逐个展示每个变更供用户确认。
Step 7: Apply Selected Changes
步骤7:应用选中的变更
Use Edit tool to apply approved changes.
使用Edit工具应用已确认的变更。
Principles
原则
- Clarity over Brevity: Explicit, readable code over compact one-liners
- No Nested Ternaries: Use switch/if-else for multiple conditions
- Reduce Complexity: Eliminate unnecessary nesting and redundant abstractions
- Preserve Functionality: Never change what code does, only how it's written
- 清晰优先于简洁:优先选择明确、可读的代码,而非紧凑的单行代码
- 禁用嵌套三元表达式:多条件判断使用switch/if-else
- 降低复杂度:消除不必要的嵌套与冗余抽象
- 保留功能不变:绝不修改代码的功能,仅优化代码的写法
Example Improvements
优化示例
- Nested ternary operators → clear if/else chains
- Deep nesting → early returns or extracted functions
- Redundant abstractions → direct implementations
- Unclear names → descriptive identifiers
- 嵌套三元表达式 → 清晰的if/else分支
- 深层嵌套 → 提前返回或提取函数
- 冗余抽象 → 直接实现
- 模糊命名 → 具有描述性的标识符