# Refactor

> 当用户觉得代码太乱、想整理代码、优化代码结构但不改功能时使用 — 提升可读性和可维护性

- **Type:** Skill
- **Install:** `agentstack add skill-lightpointventures-claude-code-starter-refactor`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [lightpointventures](https://agentstack.voostack.com/s/lightpointventures)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [lightpointventures](https://github.com/lightpointventures)
- **Source:** https://github.com/lightpointventures/claude-code-starter/tree/main/skills/refactor
- **Website:** https://github.com/lighthouse-strategy/claude-code-starter

## Install

```sh
agentstack add skill-lightpointventures-claude-code-starter-refactor
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# 代码重构

改善代码质量，但绝不改变现有功能。

## 核心原则

- 重构前后功能必须完全一致
- 每次只做一种类型的重构，不要混着来
- 有测试的先跑测试确认基线，没测试的先问用户要不要补测试

## 步骤

### 1. 确定重构目标

如果用户指定了文件或函数，直接读取。

如果没有指定，问：
> 你想重构哪段代码？可以告诉我文件名或函数名。

### 2. 分析问题

读取代码后，识别以下问题（按严重程度排序）：

- **重复代码** — 相似的逻辑出现在多个地方
- **过长函数** — 一个函数做了太多事情
- **命名不清** — 变量名或函数名无法表达意图
- **嵌套过深** — 多层 if/for 嵌套，难以阅读
- **职责混乱** — 一个函数/类混合了不同层次的逻辑

### 3. 提出方案

用中文简洁说明发现了什么问题，以及打算怎么改：

```
发现以下可以改进的地方：
1. xxx — 建议 xxx
2. xxx — 建议 xxx
```

询问用户：
> 要我执行这些重构吗？可以全部做，也可以选择性做。

### 4. 执行重构

用户确认后，逐个执行重构。每次重构后：
- 确认代码仍然能正常工作（运行测试或 lint）
- 如果某个重构可能有风险，单独提醒用户

### 5. 对比展示

重构完成后，简要说明改了什么：
> 重构完成。主要改动：xxx。功能不变，测试全部通过。

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [lightpointventures](https://github.com/lightpointventures)
- **Source:** [lightpointventures/claude-code-starter](https://github.com/lightpointventures/claude-code-starter)
- **License:** MIT
- **Homepage:** https://github.com/lighthouse-strategy/claude-code-starter

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-lightpointventures-claude-code-starter-refactor
- Seller: https://agentstack.voostack.com/s/lightpointventures
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
