code-de-rust
Skill1 starsChanged 32 days agoApache-2.0View on GitHub
编排模块级代码除锈战役:隐藏 bug 狩猎、god 文件拆分、共享 helper 提取和分批验证。触发“给模块除锈 / 代码臃肿 / 技术债盘点”。死代码转 cleanup,规则违规转 drift-check;不适用于单次 review 或运行时故障。
In this repository13 other files it gives its agents.
- cleanupSkill
- coding-practiceSkill
- concept-namingSkill
- dev-machine-cleanupSkill
- drift-checkSkill
- essay-writingSkill
- harness-groomSkill
- logSkill
- makeskillSkill
- methodologySkill
- reflectSkill
- reviewSkill
- typograph-wxSkill
The file
Files
代码除锈(code-de-rust)
定位
不定期对模块做"分层清理战役"——不是单点审查,是有目标、分批次、带验证的系统性除锈。本 skill 是编排层 + 高层(模块化),与既有两 skill 互补不重叠:
| 想做什么 | 路由 |
| 低层:这段代码还有人需要吗?(死代码/废弃导出) | → cleanup skill |
| 中层违规:硬编码 / 绕过 DS / DDD 分层违规 | → drift-check skill |
| 中层 bug:race / 类型弱化 / findUnique-then-create | → 本 skill §中层狩猎 |
| 高层:拆 god 文件 / 抽共享 helper / 模块化 | → 本 skill 核心(cleanup/drift-check 都不覆盖) |
三层目标(先定层再动手)
| 层 | 做什么 | 检测手段 | 风险 |
| 🟢 低 | 删死代码、未引用导出、已解决 backlog 的 disable | cleanup(yuanfen-impact 查消费者)/ tsc noUnusedLocals / knip | 低,可批量 |
| 🟡 中 | 硬编码收口、类型弱化(as any)修复、隐藏 bug 止血 | drift-check(违规)+ 本 skill 狩猎(bug) | 中,需读懂上下文 |
| 🔴 高 | 拆 god 文件、抽共享 helper、规整分层 | 行数 + 内聚度人工判断 | 高,需设计 + 回归 |
| 横切 | smell 计数 ≠ 技术债,每条 MUST triage(有据逃生舱 vs 真债) | — | — |
开工自检(除锈前过一遍)
- 我在哪棵树(
git rev-parse --show-toplevel)+ 落后 main 多少(git rev-list --count HEAD..main)——陈旧树上除锈 = 报一堆早已修掉的"既有违规"(V1.23.3 实证:落后 11 commits 的树报 9 处假违规)。落后多先 ff 同步。 - 图谱新鲜度:结构性问题(谁调用/影响面)MUST 先 yuanfen,但要本地算
git rev-list <ref>..HEAD验新鲜度(引擎isStale恒 true 不可信)。不新鲜退 grep 并告知。 - 改动走域 worktree(maas→maas 树 / mobile→mobile 树),NEVER 主仓开发。schema/compose/pnpm-lock 等 🟡保护文件归老猿。
- 多会话共享树 commit 限定路径(
git commit -- <paths>),NEVERgit add -A卷走他会话改动。
低层 · 死代码 → 路由 cleanup
死代码判定用 cleanup skill(它用 yuanfen-impact 查消费者,能穿透 re-export / path alias)。但牢记铁律一(下方):cleanup 之外的任何手 grep 死代码都不可信。
中层 · 硬编码 + 隐藏 bug
- 违规类(硬编码色值/URL、绕过
@design-system、组件内fetch()、DDD 分层违规)→drift-checkskill。 - bug 类 → 本层狩猎,每个模式先 grep 定位再 read 确认,NEVER 只凭 grep 下结论:
| 模式 | grep 线索 | 风险 |
| findUnique/findFirst-then-create | findFirst( 同文件 create( | 撞 @@unique P2002(见 repository.md §两阶段提交) |
| 类型弱化 | as any / as unknown as / : any | 关掉类型检查,schema 漂移运行时才炸 |
| 缺错误处理 | .then( 无 catch、async 无 try/catch | 错误被吞 |
| PUT 改状态机 | route 接受 status 字段直改 | 绕状态机 invariant(见 repository.md §状态机专用 endpoint) |
高层 · 模块化(本 skill 核心)
拆 god 文件
500 行的单文件(client god 组件 / god service),按内聚子段抽独立文件:
- god 组件:各 Tab / Modal / 独立子组件各抽一文件,主壳留编排(<250 行)。
- god service:对称的方法组(如 N 个
projectXxxBatch)各抽,签名不变。 - 增量拆分:一次抽一个子组件 → tsc 验证 → commit。NEVER 大爆炸搬迁(一次移 1000+ 行必出错)。
实证:apps/qingshan-maas/.../reimbursement/ReimbursementClient.tsx 1668 行,先抽 AttachmentGallery(75 行,零状态机零共享可变态,最安全)验证范式,主壳 1668→1593,tsc 绿。
抽共享 helper(同名散落 → 单一源)
发现同名函数/模式散落多处 → 收 lib/format/* / hook 单一源。但合并前 MUST 逐份核 body(见铁律二)。
🔴 两条铁律(本次样板实证,是本 skill 最值钱的沉淀)
铁律一:grep 查死代码误报率 ~90%
手 grep"零引用"会把活的判成死的——三类漏网:
- type-only 导出被推断类型隐式用(grep 文本匹配不到)
- 同文件兄弟函数在用(grep 只查跨文件 import)
- 测试在用(容易被当"非生产"忽略)
实证:本轮 subagent 标 maas lib 有 ~60 个死导出;主循环逐个复核,90% 是活的(asr AsrClient 被单例+测试用、cos parseRawRef 被测试重度用、clients-api 类型被同文件 listClients 用)。
正解:死代码判定走 cleanup skill(yuanfen 图反查)或开 tsc noUnusedLocals/knip;NEVER 拿手 grep 的"查不到"当"没有"。删之前 tsc 是终极裁判(删错活代码 tsc 立刻红)。
铁律二:"同名函数"≠"同逻辑"
同名函数散落多处,不等于逻辑相同。签名/格式/null 处理/货币符号可能各异——盲合并 = 改坏行为。
实证:fenToYuan 6 份定义,竟有 5 种格式(纯串 / ¥固定2位 / ¥至多2位 / 裸数字 / round变体),同一笔钱在不同页面显示不同。
正解:合并前逐份核 body。若各异且不想现在统一(统一是产品决策),走保行为集中化——抽成命名变体 + 各原定义点 delegate/re-export,调用点零改动、行为零变化(实证:lib/format/money.ts 收 3 变体 + yuanToFen,6 定义点 delegate,34 调用点零改动)。
执行纪律
- 增量 + tsc 验证每步:删/抽/改完跑
pnpm --filter <pkg> exec tsc --noEmit,改动的文件零错才算安全。 - 批次划分:止血 bug(先)→ 机械清理 → 抽取 → 高层拆分。每批独立 commit。
- commit 限定路径 + 交付前派
debug-runner(ADR-020)。 - schema / migration / prod 操作归老猿:涉及
@@unique加约束等,走repository.md §Migration 纪律(partial unique 拆 3 步 + backfill),prod 部署/SQL 核查老猿亲手。 - 铁律三(衍生):subagent 的审计结论(死代码清单、seam map)MUST 主循环复核再动手——subagent 会高估(死代码 90% 误报)也会乐观(seam 行号偏移)。
常见误区
| 误区 | 正解 |
| 手 grep 查死代码 | 走 cleanup / tsc noUnusedLocals(铁律一) |
| 同名函数直接合并 | 先核 body,否则保行为集中化(铁律二) |
| 大爆炸拆 god 文件 | 增量:一个子组件 → tsc → commit |
| 在主仓/陈旧树除锈 | 域 worktree + 先 ff 同步 main |
git add -A 提交 | 限定路径(多会话共享树) |
| 把"有据逃生舱"当技术债 | triage:78 个 DS disable 全有 backlog 注释 = 纪律非脏(本次实证) |
不适用于
- 单次改动的质量意见 →
reviewskill - 运行时故障 / prod bug →
incident或线内排查 - 实时规则拦截(硬编码/裸 fetch 等)→ hooks(drift-check 是其全局扫描补充)
- 死代码判定本身 →
cleanup(本 skill 只在编排低层时路由过去)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

