A code simplification and refactoring workflow. Automatically activates when a user mentions simplifying code, cleaning up PRs, refactoring, code optimization, code cleanup, or similar phrases. Inspired by the official code-simplifier agent used internally by the Claude Code team at Anthropic.
簡化與精煉程式碼以提升清晰度、一致性和可維護性,同時完整保留原有功能。 Simplifies and refines code for clarity, consistency, and maintainability while preserving all functionality.
⚠️ 阻塞型技能 BLOCKING SKILL
此技能是 PR 發布流程中的必須步驟,非可選的建議型。 在
pr-review-release流程中,必須完成此技能才能進入 Git 操作階段。This skill is a REQUIRED step in the PR release workflow, not an optional suggestion. In
pr-review-releaseworkflow, this skill must be completed before proceeding to Git operations.
黃金法則:永遠不改變程式碼的行為,只改變實現方式。 Golden Rule: Never change what the code does - only how it does it.
確認要簡化的程式碼範圍
取得最近變更的檔案 (如需)
git diff --name-only HEAD~5
# 或查看未提交的變更
git diff --name-only
遵循專案標準 (Project Standards)
CLAUDE.md、copilot-instructions.md 或 .editorconfig.github/copilot-instructions.md 中的規範識別簡化機會
套用以下五大簡化原則:
對於本專案 (singular-blockly):
function 關鍵字 (非 arrow functions)// ❌ 避免:巢狀三元運算子
const result = a ? (b ? x : y) : c ? z : w;
// ✅ 改用:switch 或 if/else
if (a && b) {
return x;
} else if (a) {
return y;
} else if (c) {
return z;
} else {
return w;
}
避免過度簡化:
選擇清晰而非簡潔:
// ❌ 過於緊湊
const process = d => d.filter(x => x.v > 0).map(x => x.v * 2);
// ✅ 明確易讀
function processPositiveValues(data: DataItem[]): number[] {
const positiveItems = data.filter(item => item.value > 0);
return positiveItems.map(item => item.value * 2);
}
執行測試確保功能不變
npm run test
執行 linting 確保風格一致
npm run lint
# 或
npx eslint . --fix
執行 build 確保沒有編譯錯誤
npm run compile
# 或
npm run package
審查變更
git diff
分階段提交 (如有多個簡化類型)
git add -p # 互動式選擇要提交的變更
使用 Conventional Commits 格式
git commit -m "refactor: simplify {component/module} for better readability"
git commit -m "style: apply consistent naming conventions"
git commit -m "refactor: reduce nesting in {function}"
// ❌ 深層巢狀
function process(data) {
if (data) {
if (data.items) {
if (data.items.length > 0) {
return data.items.map(i => i.value);
}
}
}
return [];
}
// ✅ 早期返回 (Guard Clauses)
function process(data) {
if (!data?.items?.length) {
return [];
}
return data.items.map(item => item.value);
}
// ❌ 難以理解
if (user.age >= 18 && user.country === 'TW' && user.verified && !user.banned) {
allowAccess();
}
// ✅ 自文件化
const isAdult = user.age >= 18;
const isFromTaiwan = user.country === 'TW';
const isVerifiedUser = user.verified && !user.banned;
if (isAdult && isFromTaiwan && isVerifiedUser) {
allowAccess();
}
// ❌ 重複的條件
if (type === 'A') {
return handleA();
} else if (type === 'B') {
return handleB();
} else if (type === 'C') {
return handleC();
} else {
return handleDefault();
}
// ✅ 使用物件映射
const handlers = {
A: handleA,
B: handleB,
C: handleC,
};
return (handlers[type] || handleDefault)();
// ❌ 描述顯而易見的事情
// Increment counter by 1
counter++;
// ✅ 只在需要時註解(解釋為什麼,而非什麼)
// Rate limit: max 100 requests per minute per user
counter++;
簡化程式碼的額外好處:減少未來 session 的 token 消耗。
有開發者報告使用 code-simplifier 後,token 消耗減少 20-30%。
npx skills add Shen-Ming-Hong/code-simplifier下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer