agentsclimarketplace

Code refactor

Skill unix2dos/skills/code-refactor

My personal collection of handcrafted AI agent skills — original prompting modules for code quality, knowledge exploration, and daily productivity.

Install
npx -y skills add unix2dos/skills --skill code-refactor

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when refactoring Go code for better structure, maintainability, extensibility, or testability - follows SOLID principles and idiomatic Go patterns

SKILL.md

2.0 KB, as published. Nobody here has run it

Code Refactor

Golang 代码重构技能,帮助重构和优化 Go 代码。

When to Use

  • 需要改变代码结构(拆函数、拆模块、改接口)
  • 需要引入设计模式(依赖注入、函数选项模式等)
  • 改善可扩展性、可测试性
  • 涉及 SOLID 原则级别的结构调整

When NOT to Use

  • 只需要删代码、降复杂度、去冗余 → 用 code-simplifier
  • 需要审查安全/并发/性能问题 → 用 go-code-review
  • 非 Go 语言代码 → 用 code-simplifier(支持任何语言)

重构约束(按优先级执行)

P0 - 行为等价性(不可妥协)

  • 所有公开 API 的输入输出保持一致
  • 边界条件处理不变
  • 并发安全性保留
  • 如发现原代码存在逻辑缺陷,明确标注但不修复

P1 - 可维护性

目标:降低认知负担

  • 函数职责单一(单一职责原则)
  • 命名自解释(避免注释依赖)
  • 嵌套层级 ≤ 3
  • 圈复杂度 ≤ 10(特殊业务逻辑可放宽至 15)
  • 使用 Early Return 减少嵌套

P2 - 可扩展性

策略:接口隔离 + 依赖注入

  • 反过度设计:不为"可能"的需求预留扩展点
  • 使用函数选项模式(Functional Options)
  • 配置与逻辑分离

P3 - 可测试性

原则:依赖可替换

  • 外部依赖通过接口注入
  • 避免包级变量(logger 等除外)
  • 纯函数优先

输出格式

先输出以下诊断报告,等待用户确认后,再进行重构。

重构策略

  1. 核心改动:[用一句话说明主要重构方向]
  2. 设计模式:[使用的模式及理由]
  3. 权衡说明:[哪些地方优先实用性而非理论完美]

风险评估

  • 破坏性变更:[是/否],具体:xxx
  • 性能影响:[提升/下降/持平],原因:xxx
  • 依赖变化:[新增/移除的依赖]

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.