Skip to content

About

Agent skill to simplify and refactor code in any mainstream language while preserving behavior and public APIs.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simplify-code

An agent skill for simplifying, cleaning up, and safely refactoring (extract / move / split / dedupe / rename with a behavior-preservation proof) existing code, plus explicit functional and performance optimization. Cleanup preserves behavior and public APIs; optimization records its goal, protected contracts, intentional effects, and before/after evidence.

一个 Agent 技能:简化、整理、安全重构(提取/迁移/拆分/去重/重命名,先定义行为保持边界与证明)现有代码,并支持目标明确的功能与性能优化。简化默认不改变行为和公共 API;优化必须记录目标、保护条件、预期行为变化及前后对比,不把功能变更伪装成重构。

Coverage / 覆盖场景

  • 结构重构: 行为保持边界、行为与调用方联合验证、用户改动保护、按逻辑检查点迁移;私有已知调用方优先原子修改,公共/分阶段迁移使用 expand→migrate→contract。按重复性与风险选择自动化,不以 500 行作为强制门槛。
  • 通用简化: 死代码、嵌套、重复知识、命名、条件分支、长函数/上帝类、过浅抽象、资源清理。
  • JavaScript / TypeScript: 空值与假值、严格/宽松比较、集合与排序、类型收窄、泛型、satisfies、async 顺序、同步抛出、请求竞态。
  • Vue 3 / SFC: props/emits/slots/defineExpose 契约、computed 与 watcher、组合式函数、响应式拆分、列表 key、effect 清理、最后一次请求获胜、渲染优化。
  • HTML / CSS: DOM/选择器钩子、级联与优先级、shorthand、设计 token、flex/grid 尺寸、响应式溢出、键盘/焦点/减少动画、布局与绘制优化。
  • Go: 错误链与文本、nil/empty、HTTP context、资源释放、goroutine/channel/WaitGroup、限流并发、N+1、分配与 pprof/benchmark。
  • Rust: Option/Result、?、entry/iterator、clone 与借用、Drop 顺序、async cancellation、锁跨 await、MSRV/feature/target 验证。
  • 其他语言: Python、Java、C#、C/C++、PHP、SQL、Shell、Kotlin、Swift、PowerShell,以及第二梯队常见语言。
  • 工作模式: 等价简化、安全重构、有基线的功能/性能优化、只读评估;支持中英文请求。

Workflow / 工作方式

  1. 确认模式、范围和项目规范,识别并保护用户已有改动;不自动暂存或提交。
  2. 找出公开契约、调用方、副作用、错误、异步时序与资源所有权,明确目标结构。
  3. 编辑前建立行为与类型检查基线;允许在现有框架补特征测试,记录已有失败。优化先测量,只有必要时才做前置重构。
  4. 将候选分为 apply / optimize / propose / skip;只加载对应语言和风险章节。
  5. 按逻辑检查点修改和验证;测试 import/路径可以同步迁移,行为断言不得弱化。失败只撤销本轮自己的改动。
  6. 重跑相关检查,要求相对基线无新增失败,并明确已有失败、缺失工具和未验证平台。
  7. 按任务规模简短报告,区分等价重构、用户要求的行为变化、实际测量与未运行检查。

Evaluation / 评测

evals/evals.json 包含 41 个场景:原有 34 个场景、2 个明确标注的重构规划场景、2 个可执行多文件重构场景(handler 去重、公共签名兼容迁移)、3 个负向/恢复规划场景。文件型用例提供行为 harness;inline/planning 用例不代表实际完成了迁移。

评测协议:只把 files 中的输入复制到隔离候选目录,验证器与固定基线保留在评测端、不得修改。成功必须同时满足退出码 0、明确 PASS、未超时且评测器完整性不变;行为、类型 API、结构目标、真实命令记录分别评分。对于不可信 Agent,需要外部只读隔离/完整性校验;进程内测试器不是安全沙盒。

运行 python3 -B evals/test_harnesses.py 可验证测试器自身的正反例:正确输入可通过,空/重复回调、截断 golden、语义漂移、未完成迁移和类型 API 破坏应失败。它使用自动清理的临时目录,不执行数据库迁移,不代表模型效果评测。当前验证结果:10 个测试方法,9 个通过,Java 项因本机缺少 JDK 跳过;未安装工具。新增场景尚未记录模型对比分数。

Historical results / 历史结果

Agent model glm-5.3-flash-external via miniagent, 2026-10-19, skill v1.1.0. 7 cases, mostly behavior traps checked by hidden test harnesses. One run per case. These results do not cover v2.x or the new frontend/backend scenarios.

With skill Baseline (no skill)
Assertions 28 / 31 (6/7 cases all-pass) 20 / 31 (2/7)
  • Wins were on behavior traps: Java toMap duplicates 5/5 vs 2/5; TS Promise.all ordering 5/5 vs 3/5; negative page index 3/3 vs 2/3; already-minimal Go 5/5 vs 4/5.
  • Triggering: 24 mixed queries, 4 skills installed: 5/6 recall, 0 false triggers. The miss was a “flatten these nested ifs” request that read no skill.
  • Caveats: the JS falsy-defaults trap timed out at 900s (2/5); a retry still failed strict-equality behavior. Runs with the skill were about 2.6× slower. Only 1 of 7 runs stated a mode; each case ran once.

历史结果仅属于 v1.1.0 的 7 个用例,不代表 v2.x 或新增场景的效果;不要据此宣称新场景已经通过模型评测。

Install / 安装

git clone --depth 1 https://github.com/linkxzhou/simplify-code.git ~/.claude/skills/simplify-code

Structure / 结构

SKILL.md                    # Modes, workflow, golden rules, reporting / 模式、流程、底线、报告
references/
  rules.md                 # General design and simplification rules / 通用设计规则
  languages.md             # Language and domain-guide index / 语言与领域索引
  languages-tier1.md       # Mainstream language notes / 主流语言要点
  languages-tier2.md       # Additional language notes / 其他语言要点
  frontend.md              # JS/TS, Vue, CSS, browser and accessibility / 前端专项
  backend.md               # Go/Rust services, concurrency and resources / 后端专项
  refactoring.md           # Refactor mode: boundary, proof, sequencing, recipes / 结构重构
  optimization.md          # Goal, baseline, guard rails and measurement / 优化与测量
  behavior-traps.md        # Non-equivalent rewrites / 非等价改写陷阱
  examples.md              # Safe, propose-only, reject and domain recipes / 示例配方
  assessment.md            # Read-only and constrained verification / 只读评估
  sources.md               # Books, official docs and style guides / 来源
evals/                     # Eval definitions and behavior fixtures / 评测定义与样例

About

Agent skill to simplify and refactor code in any mainstream language while preserving behavior and public APIs.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages