Install
openclaw skills install @elisabeth15501/skill-clean-audit第一性原理 clean code 审计法。从单根前提「代码是写给人看的」推导出两根判据—— A. 理解成本(读起来费不费劲)/ B. 修改风险(改起来怕不怕),用红/黄/绿三档给代码打分, 并明确允许「有意的、注释了的、范围可控的技术债」暂时存在。专用于审计你自己的 WorkBuddy Skill 脚本或其他 Python 代码,产出带证据(文件:行)的可勾选报告。 触发词:「用第一性原理审代码」「理解成本/修改风险」「clean code 审计」「审计我的 Skill 脚本」 「按红黄绿审代码」「clean code 审计样例」。注意:本 skill 只做可读性/可维护性的第一性原理审计, 不做通用 PR/MR 审查(那用 code-review-assistant 或 critical-code-reviewer), 不替代 clean-code 的写代码规范手册,也不做 lint/格式化(那用 project-code-standard)。 First-Principles Clean Code Audit. Derives two criteria from one root premise — "code is written for humans": A. Comprehension cost (how hard to read) / B. Change risk (how scary to modify) — scored red/amber/green, explicitly permitting intentional, documented, scoped tech debt. Audits your own WorkBuddy skill scripts or Python code, emitting an evidence-backed (file:line) checklist report. Triggers: "audit code with first principles", "comprehension/change risk", "clean code audit", "audit my skill scripts". Read-only: emits findings, never edits. Note: this skill does first-principles readability/maintainability audit only — not generic PR/MR review (use code-review-assistant / critical-code-reviewer), not a style handbook (use clean-code), and not lint/format (use project-code-standard).
openclaw skills install @elisabeth15501/skill-clean-audit是 / Is:一个审计方法论 + 可落地产物。拿两根判据去戳代码,逐项打勾带证据,出报告。 An audit methodology + a concrete artifact. Pokes code with two criteria, ticks items with evidence, emits a report.
不是 / Is not(明确边界,避免和已有 skill 重叠 / explicit boundaries, to avoid overlap with existing skills):
code-review-assistant / critical-code-reviewerclean-code(SRP/DRY/KISS 那套)project-code-standard(ruff/eslint/prettier)uncle-bob(本 skill 只从第一性原理推导,不抄它的规则;见 references/smells_crosswalk.md 做等价桥接)本 skill 的价值在三点,现有 skill 都没有:① 规则是推导出来的不是给定的;② 用成本/风险两轴而非类别桶;③ 允许有意的债。 Three things no existing skill does: ① rules are derived, not given; ② a cost/risk two-axis model, not category buckets; ③ permits intentional debt.
关键反推 / Key reversal:为凑清单而清单(为短拆七层 tiny function、为 DRY 抽象没人用的接口)反而抬高成本,是脏的。 Checklist-for-its-own-sake raises cost — that is dirty.
import *)、重复/矛盾的说明、注释退化成 changelog(满屏工单号)、模块级可变全局状态控行为、命名与行为不一致 / 隐藏副作用(CQS 违反:函数名像查询却偷偷改状态或打印)、重复逻辑(DRY 违反)、裸 except 静默吞错。
Implicit symbol origin (import *), contradictory docs, comments degraded into a changelog, module-level mutable global controlling behavior, name≠behavior / hidden side effects (CQS violation), duplicated logic (DRY violation), bare except swallowing errors.except(单源失败不拖垮管线)。黄=暂时可接受,但必须写清「为什么」且范围可控。
Long functions (>40 lines but cohesive), unnamed magic numbers/strings, intentional best-effort except. Amber = temporarily acceptable, but the "why" must be written and scope controlled.except 均精确。
Naming is documentation, explicit beats implicit, behavior depends only on inputs, tested, every except precise.完整可勾选清单见 assets/clean_code_checklist.html(打开即可逐项打勾,带实时计数)。
Full interactive checklist: assets/clean_code_checklist.html (open to tick items, with a live counter).
以下数字只作「值得多看一眼」的探针,不是自动判红。第一性原理的判据永远是 A/B 两轴,指标只是帮你更快定位疑点: The numbers below are only probes for "worth a closer look" — not automatic red flags. The first-principles criteria remain the A/B axes; metrics just help you locate suspects faster:
def f(..., dry_run=False)):A 信号,函数实际做两件相反的事,违反单一职责。
Boolean flag params: A signal, the function does two opposite things (SRP violation).重申 / Restated:指标命中 ≠ 脏。若它能用「注释说清 + 范围可控」解释,且真降低了理解/修改成本,仍是干净的。指标只为节省你逐行扫的时间。 Metric hit ≠ dirty. If explained by "comment + scoped" and it truly lowers cost, it stays clean. Metrics only save you line-by-line scanning time.
assets/clean_code_checklist.html 每一项,判断在目标代码里是否命中。常见 smell 的标准命名(Rigidity/Fragility/Opacity…)对照见 references/smells_crosswalk.md,便于把发现标准化。
For each item in assets/clean_code_checklist.html, judge whether it hits. Standard smell names (Rigidity/Fragility/Opacity…) crosswalk: references/smells_crosswalk.md.文件:行号 和一句话「它抬高了 A 还是 B、怎么抬的」。无证据的直觉不打勾。
Every hit needs file:line and one sentence on whether it raises A or B, and how. No evidence, no tick.references/clean_code_audit_sample.md(那是一份用合成示例脚本 demo-skill/scripts/aggregate.py 的 main() 真审出来的样例,照它的结构写;样例片段自带行号、可逐行核对,不对应任何真实项目)。
Format below; full sample: references/clean_code_audit_sample.md (a real audit of synthetic demo-skill/scripts/aggregate.py; snippet is line-numbered, checkable, maps to no real project).落盘到当前 agent 会话的工作区根目录(即本对话打开的项目目录,例如 ~/WorkBuddy/<session>/),文件名 clean_code_audit_<target>.md,结构:
Write to the current agent session's workspace root (the opened project dir, e.g. ~/WorkBuddy/<session>/), filename clean_code_audit_<target>.md, structure:
本 skill 只读不改,但报告「结论」段的优先级建议按此原则给: This skill reads only, but the report's "conclusion" priority follows this principle:
底层逻辑仍是第一性原理:重构也要花理解成本。只对「正在被修改、因而修改风险本就升高」的代码投资清理,才划算;对无人碰的代码提前重构,是净亏。 Same first principle: refactoring also costs comprehension. Only invest cleanup in code already being modified (where change risk is already high); pre-refactoring untouched code is a net loss.
收尾必须点明:红的全修;黄了只要「注释说清 + 范围可控」就先留着;绿的出现说明干净。同一处若「为清单而清单」反而是脏的。本 skill 只读不改——若要落地修复,另开一轮按优先级逐个 PR。 Closing note: fix all red; keep amber if "comment + scoped"; green means clean. Checklist-for-its-own-sake is itself dirty. This skill reads only — for fixes, open a separate prioritized pass.
assets/clean_code_checklist.html 复制到当前 agent 工作区根目录(命名 clean_code_checklist.html),作为可反复使用的交互式清单;下次审计直接打开它打勾。
Copy assets/clean_code_checklist.html to the workspace root (as clean_code_checklist.html) for reuse; open it next audit to tick.clean_code_audit_<target>.md,并调用 present_files 把该文件(及清单)呈现给用户预览。
Write the audit report to the workspace root clean_code_audit_<target>.md and call present_files to preview it (and the checklist) for the user.clean_code_audit_*.md / clean_code_checklist*.html)已被仓库 .gitignore 忽略,不进版本控制。
Generated artifacts (clean_code_audit_*.md / clean_code_checklist*.html) are git-ignored, never version-controlled.references/ 新增会读环境变量或调用二进制的脚本,必须同步在 metadata.openclaw.requires.env / requires.bins 声明(ClawHub 的 mismatch 审核红线)。当前本 skill 无任何此类依赖。
If you later add a script that reads env vars or calls binaries, declare it in metadata.openclaw.requires.env / requires.bins (ClawHub's mismatch-audit red line). This skill has none today.license: MIT 供 SkillHub;ClawHub 导出副本由发布脚本剥离 license 字段并排除 LICENSE(见 .clawhubignore)。
Multi-platform: the source keeps license: MIT for SkillHub; the ClawHub export strips the license field and excludes LICENSE (see .clawhubignore).