with one click
code-simplifier
代码简化器,KISS原则执行者,Linus品味守护者
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
代码简化器,KISS原则执行者,Linus品味守护者
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
| name | code-simplifier |
| description | 代码简化器,KISS原则执行者,Linus品味守护者 |
| trigger | 开发阶段自动加载 |
"Simplicity is the ultimate sophistication." — Leonardo da Vinci "代码越少,Bug越少。" — 工程真理
在开发过程中主动识别和简化复杂代码,确保代码符合 Linus 的"品味"标准。
// ❌ 过长函数 (>50行)
function processUser(data) {
// ... 100行代码
}
// ✅ 拆分为小函数
function processUser(data) {
const validated = validateUser(data);
const normalized = normalizeUser(validated);
return saveUser(normalized);
}
// ❌ 嵌套地狱
if (a) {
if (b) {
if (c) {
doSomething();
}
}
}
// ✅ 早返回
if (!a) return;
if (!b) return;
if (!c) return;
doSomething();
// ❌ 手动循环
const result = [];
for (let i = 0; i < items.length; i++) {
if (items[i].active) {
result.push(items[i].name);
}
}
// ✅ 声明式
const result = items
.filter(item => item.active)
.map(item => item.name);
// ❌ 过度类型体操
type DeepPartial<T> = T extends object
? { [P in keyof T]?: DeepPartial<T[P]> }
: T;
// ✅ 简单直接(除非真的需要)
interface UserUpdate {
name?: string;
email?: string;
}
// ❌ 过度抽象
abstract class AbstractRepositoryFactory<T extends BaseEntity> {
abstract createRepository(): IRepository<T>;
}
// ✅ 需要时再抽象
function getUsers(): User[] {
return db.query('SELECT * FROM users');
}
开发时自动检测以下问题:
| 检测项 | 阈值 | 动作 |
|---|---|---|
| 函数行数 | >50行 | 建议拆分 |
| 嵌套深度 | >3层 | 建议重构 |
| 参数数量 | >4个 | 建议封装对象 |
| 圈复杂度 | >10 | 建议简化 |
| 重复代码 | >3处 | 建议提取 |
| 魔法数字 | 任意 | 建议常量 |
每次代码提交前检查:
any 类型写代码 → 自检 → 发现复杂 → 简化 → 验证 → 提交
↓
记录到 Memory
(下次避免)
发现的简化模式和反模式,记录到 Memory MCP:
memory.add({
category: "code_pattern",
content: "避免超过3层嵌套,使用早返回模式",
tags: ["simplification", "nesting"]
})
// Before
if (user.age >= 18 && user.country === 'US' && user.verified) {
// ...
}
// After
function canAccess(user: User): boolean {
return user.age >= 18 && user.country === 'US' && user.verified;
}
if (canAccess(user)) {
// ...
}
// Before
function getArea(shape) {
if (shape.type === 'circle') return Math.PI * shape.radius ** 2;
if (shape.type === 'square') return shape.side ** 2;
}
// After
interface Shape { getArea(): number; }
class Circle implements Shape { getArea() { return Math.PI * this.radius ** 2; } }
class Square implements Shape { getArea() { return this.side ** 2; } }
// Before
switch (status) {
case 'pending': return '待处理';
case 'approved': return '已批准';
case 'rejected': return '已拒绝';
}
// After
const STATUS_MAP = {
pending: '待处理',
approved: '已批准',
rejected: '已拒绝',
};
return STATUS_MAP[status];
简化有度,以下情况保持原样:
每次开发完成后,输出简化报告:
## 代码简化报告
### 已简化
- `src/auth/login.ts`: 拆分为3个函数,减少30行
- `src/utils/format.ts`: 移除重复代码
### 建议简化
- `src/api/orders.ts:45`: 嵌套4层,建议重构
### 指标
- 平均函数长度: 25行 ✅
- 最大嵌套深度: 2层 ✅
- 重复代码: 0处 ✅
触发: 开发阶段自动加载 | 协作: LD + QE | 记忆: 沉淀到 Memory MCP
Athena 全局首次配置 (跨项目, 一次性). 从分发包部署 settings/config/rules/standards/hooks/agents/skills 到 ~/.claude/ (CC) 与 ~/.codex/ (CX). 和 athena-init 区别: setup 全局一次性, init 每项目一次. 已装则转 verify/upgrade (走 athena-migrate).
会话记忆固化 skill (v9.8.0 新). 会话结束/中途, agent 自己总结本会话增量写进 .ai_state (_index.md 当前状态 + sprints/{slug}/session-log.md), 免去用户每次手动描述一堆让它存. 手动 /checkpoint 触发. 与 compact-snapshot hook 互补 (hook 机械兜底, skill 做需推理的总结).
Athena 主入口 skill. 接收用户任务, 做 PACE 路由分诊 (brainstorm/roadmap/plan/...), 启动对应 stage. v9.7.0: 铁律引用名称化 (CC/CX 编号非对称, 引用一律用 铁律[名称]).
Athena 项目初始化 skill. 在项目中执行 /athena-init 时调用. 职责: 探测平台 / 工具可用性, 创建 .ai_state/ 目录 + 复制 _index.md 模板 + 填入探测结果.
Bugfix 路径的结构化问题流程: report → analyze → fix-note 三件套档案, 落在 sprints/{slug}/. 把"偏轻"的 Bugfix 升级成可复现 / 可追溯 / 可复盘. 借 CodeStable issue 实体, 适配 agent-in-loop.
Athena 版本迁移工具. v9.6.4 重写: 含 v9.6.2 → v9.6.4 破坏式重构 (sprints/ + compound/ + 4 新 ai_state 文件 + lessons.md 三选项交互).