← Back to Skills Marketplace
aqbjqtd

Code Simplifier

by sniper-one · GitHub ↗ · v1.1.1 · MIT-0
cross-platform ✓ Security Clean
624
Downloads
0
Stars
5
Active Installs
3
Versions
Install in OpenClaw
/install code-simplifier
Description
当用户要求简化代码、重构代码、优化代码、改进代码质量时使用此技能。提供代码简化原则和最佳实践指导,确保代码符合质量标准。
README (SKILL.md)

Code Simplifier

提供代码简化、重构和优化的原则指导。

核心原则

函数设计

  • 单一职责: 每个函数只做一件事
  • 长度控制: 目标 \x3C 50 行,理想 10-30 行
  • 参数控制: ≤ 4 个参数;超过时使用数据类或配置对象
  • 早期返回: 用 guard clauses 避免深层嵌套

代码组织

  • DRY: 提取重复逻辑为公共函数
  • 命名清晰: 变量名反映意图,避免单字母(循环变量除外)
  • 无魔法数字: 提取为命名常量
  • 嵌套控制: 嵌套层级 ≤ 3 层

错误处理

  • 捕获具体异常,不使用裸 except:
  • 保留原始异常链 (raise ... from e)
  • 使用 context manager 管理资源

语言特定规范

Python

# ✅ 类型注解
def process(user_id: int, data: dict) -> dict | None:
    ...

# ✅ list/dict comprehension(避免嵌套)
result = [x for x in items if x.condition]

# ✅ 命名
snake_case(变量/函数), PascalCase(类), UPPER_SNAKE_CASE(常量)

# ❌ 避免
# - 嵌套 comprehension
# - 过度使用 lambda
# - 裸 except:

JavaScript / TypeScript

// ✅ const/let,无 var
// ✅ 箭头函数
const process = (data) => data.filter(x => x.valid);

// ✅ 解构
const { name, email } = user;

// ✅ 命名
camelCase(变量/函数), PascalCase(类/接口), UPPER_SNAKE_CASE(常量)

自动化工具

命令行分析工具

python scripts/code_simplifier.py \x3Cfile.py> --analyze        # 分析复杂度
python scripts/code_simplifier.py \x3Cfile.py> --suggest       # 生成重构建议
python scripts/code_simplifier.py \x3Cfile.py> --simplify      # 自动简化代码
python scripts/code_simplifier.py \x3Cfile.py> --output=out.py # 指定输出文件

输出格式支持 text(默认)和 json

质量检查清单

函数级别

  • 函数长度 \x3C 50 行
  • 嵌套层级 \x3C 3 层
  • 单一职责
  • 命名有意义

代码级别

  • 无重复代码
  • 无魔法数字
  • 无未使用变量/导入
  • 错误处理具体

整体质量

  • 符合语言规范
  • 类型注解/标注完整
  • 可读性良好
  • 易于维护

前端编码规范(网页项目必须遵守)

  1. HTML 安全:所有动态内容用 textContent 赋值,禁止 innerHTML;必须用 escapeHTML() 转义 \x3C > & ' "
  2. 移动端兼容:按钮 touch-action: manipulation,点击目标 ≥44px
  3. CSS 布局:用 Flexbox/Grid,不用 float
  4. 响应式:相对单位(rem/em/%),viewport meta tag
  5. 性能:LCP \x3C 2.5s、INP \x3C 200ms、CLS \x3C 0.1

修复阶段加载 web-fixing 技能诊断;编码阶段遵守以上 5 条即可预防大部分问题。

参考文档

  • 重构模式: refactoring_patterns.md — Early Return、Extract Method、Guard Clauses、Async/Await 等 20+ 模式
  • 最佳实践: best-practices.md — 函数设计、代码组织、错误处理、性能优化、测试友好设计
  • 故障排除: troubleshooting.md — 代码异味诊断、复杂度分析、自动化工具、重构工作流
Usage Guidance
This skill appears coherent and local: it analyzes code via AST and offers refactoring suggestions. Before installing or running, review the full scripts (scripts/code_simplifier.py) yourself for any unexpected imports or network/socket/subprocess calls (search for requests, socket, subprocess, os.system, urllib, http, ftplib) — the provided excerpts show only local analysis. When running against untrusted code, use a sandbox or run on a copy (the tool reads files you pass it). If you need networked features later, require explicit documentation and minimal, well-justified credentials.
Capability Analysis
Type: OpenClaw Skill Name: code-simplifier Version: 1.1.1 The bundle is a legitimate tool for code analysis and refactoring. The core logic in `scripts/code_simplifier.py` uses Python's `ast` module for safe static analysis of code complexity and regex for pattern matching, without using dangerous functions like `eval()` or performing unauthorized network/file operations. The instructions in `SKILL.md` and the supporting documentation in the `references/` directory provide standard software engineering best practices and lack any signs of prompt injection or malicious intent.
Capability Assessment
Purpose & Capability
Name/description (code simplification, refactoring guidance) match the provided SKILL.md, reference docs, and the included Python script that analyzes and suggests refactors. No unrelated binaries, env vars, or config paths are requested.
Instruction Scope
SKILL.md is focused on coding best-practices and tells the agent to run the bundled CLI script (python scripts/code_simplifier.py) on user-provided files and produce analysis/suggestions. The instructions only reference analyzing files the user passes and producing text/json output — no guidance to read system-wide secrets, shell history, or exfiltrate results to external endpoints.
Install Mechanism
No install spec is provided (instruction-only with an included script). The script appears to be a local AST-based analyzer; there are no downloads or archive extraction steps. The SKILL.md mentions third-party tools (radon, black, pylint) as optional tooling but does not attempt to install arbitrary remote code.
Credentials
The skill requests no environment variables, credentials, or config paths. The content includes examples referencing common developer libs (e.g., an import example that mentions OpenAI) only in documentation; there are no declared secrets or credential needs that are disproportionate to a refactoring tool.
Persistence & Privilege
always is false and the skill does not request persistent or elevated privileges. It does not modify other skills' configs or system-wide settings based on the provided materials.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install code-simplifier
  3. After installation, invoke the skill by name or use /code-simplifier
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.1.1
- Added documentation for a command-line code analysis and simplification tool, including usage examples and output formats. - Introduced mandatory front-end coding standards for web projects, covering HTML safety, mobile compatibility, CSS layout, responsiveness, and performance metrics. - Removed example/demo and script test files from the project. - Updated references and best practices documentation to reflect new guidance and tools.
v1.1.0
- Added usage examples and testing scripts to demonstrate and validate the skill (examples/demo_usage.py, scripts/test_simplifier.py). - Updated best practices and core documentation for improved clarity (SKILL.md, references/best-practices.md). - Removed the section on command-line analysis tools from the main documentation.
v1.0.0
Initial release with code analysis, refactoring suggestions, and simplification tools
Metadata
Slug code-simplifier
Version 1.1.1
License MIT-0
All-time Installs 5
Active Installs 5
Total Versions 3
Frequently Asked Questions

What is Code Simplifier?

当用户要求简化代码、重构代码、优化代码、改进代码质量时使用此技能。提供代码简化原则和最佳实践指导,确保代码符合质量标准。 It is an AI Agent Skill for Claude Code / OpenClaw, with 624 downloads so far.

How do I install Code Simplifier?

Run "/install code-simplifier" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Code Simplifier free?

Yes, Code Simplifier is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Code Simplifier support?

Code Simplifier is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Code Simplifier?

It is built and maintained by sniper-one (@aqbjqtd); the current version is v1.1.1.

💬 Comments