Elegant Code 标志

Elegant Code

社区
athola
elegant-code

Guide minimal code via a decision ladder with full safety, edge, and negative-case coverage. Use when adding code, choosing a dependency, or auditing a diff.

概览

发布者athola
代码仓库claude-night-market
技能名称elegant-code
星标数
343
复刻数
37
附带文件
1
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 1 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 athola 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Elegant Code AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/athola/claude-night-market/tree/master/plugins/conserve/skills/elegant-code
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/athola/claude-night-market.git /tmp/claude-night-market
mkdir -p .claude/skills
cp -r /tmp/claude-night-market/plugins/conserve/skills/elegant-code .claude/skills/elegant-code
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Elegant Code,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Elegant Code。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Elegant Code 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Elegant Code

Write the minimal, elegant code that fully solves the problem: its performance, its edge cases, and its failure cases. Minimal is not fewest lines. It is no incidental complexity, with nothing essential omitted.

What this skill is (and is not)

This skill codifies a discipline that strong models already exhibit some of the time. Its value is not teaching a missing capability. Its value is three things:

  1. A shared vocabulary (the rungs, the floor) that review skills can point at, so "you skipped rung 2" is a concrete, auditable note.
  2. Consistency: the ladder is applied every time, not just when the model happens to think of it.
  3. A guard: the negligence floor below is never traded away for brevity.

It is the generative counterpart to the review-side contract in leyline:additive-bias-defense.

When To Use

  • Before adding a function, file, class, abstraction, or dependency.
  • When choosing between reuse and writing new code.
  • When auditing a diff for lines that can be deleted.

When NOT To Use

  • Throwaway scripts or one-time migrations where review cost is near zero.
  • Cases where the negligence floor (below) is in play: there, add the guard first and optimize length second.

The Decision Ladder

Walk the rungs in order. Climb down only when the current rung does not hold. Stop at the first rung that solves the problem.

#RungAskStop here whenExample
1Need-to-existDoes this need to exist at all?The requirement is speculative or already met. Delete or defer."Config loader for a value used once" -> inline the value
2Builtin / stdlibCan a language builtin or the standard library do it?The stdlib covers it.str.zfill, f"{n:05d}", pathlib, itertools
3Native platformIs there a native platform or framework feature?The platform already ships it.URLSession retry, fetch, framework validators
4Installed dependencyIs an already-installed, audited dependency enough?A dep in the lockfile covers it.reuse requests/urllib3 backoff before adding tenacity
5A few linesCan it be one line or a small explicit block?A short, obvious block solves it.a 20-line retry loop over a retry framework

A new dependency is the last resort, below rung 5, not rung 4. Before adding one, verify it actually exists and is safe with Skill(imbue:dependency-verification): generated code imports non-existent packages at measurable rates, and recurring fake names enable slopsquatting (arXiv 2406.10279, USENIX 2025).

Prefer reuse of an installed, audited dependency over both a new dependency and a hand-rolled reinvention. Zero-dependency code is not automatically cheaper: it relocates the maintenance and bug surface into your own tree (see references/sources.md).

What minimal must still cover

Minimal does not mean fewest lines. It means no incidental complexity, with nothing essential omitted. The decision ladder removes incidental code: reinvention, speculative abstraction, needless dependencies. Three things are essential and are never traded for brevity.

Correctness and safety (the negligence floor)

Never cut for brevity. A review must never propose deleting these as "extra code":

  • Trust-boundary and input validation on untrusted data.
  • Authorization checks (permission gates, row-level security).
  • Data-loss handling (transactions, idempotency keys, retries that cannot double-charge).
  • Error handling on fallible I/O.
  • Security-relevant paths (authn, secrets, crypto).
  • Accessibility.

This floor is evidence-backed, not a slogan. The dangerous failure mode in generated code is omission: roughly 45% of AI-generated samples carry a security flaw, with a measured ~2.74x vulnerability rate versus human code, driven by missing validation, missing authorization, and missing error handling (Veracode 2025). CVE-2025-48757 is a concrete case: generated schemas shipped without row-level security policies. An absent guard is not zero bugs. It is one latent bug per untrusted input.

Performance

Handle the expected input size and the hot path: avoid accidental quadratic loops, N+1 queries, and unbounded memory growth. Do not micro-optimize speculatively. Premature, speculative optimization is itself incidental complexity, so YAGNI applies to performance too. Optimize what the known input size or a profiler justifies, not what feels fast.

Edge and negative cases

The negative path is part of the spec, not extra code. Cover empty, None, and zero inputs; boundary values; malformed or hostile input; partial failure and timeouts; and concurrency where it applies. Code that handles only the happy path is not minimal. It is unfinished.

Elegance, not terseness

Prefer the clearest expression a reader can verify, not the cleverest or the shortest. Terseness and cleverness raise review cost and defect risk: dense one-liners hide edge cases, and correctness-only evaluation misses the maintainability they cost (arXiv 2407.11470). Elegance is minimal incidental complexity plus maximal clarity, which is not the same as minimal characters.

Why minimal (stated honestly)

The case for less code rests on surfaces you can measure, not on a clean "fewer lines means fewer bugs" law. That law is not empirically settled: studies find weak or absent correlation between complexity metrics and defect rate (arXiv 1912.01142, 1912.04014). Argue instead from:

  • Attack surface: fewer imports and branches are fewer places for a known failure mode (hallucinated import, unhandled path).
  • Review cost: a document, and a diff, costs the sum of its readers' time. Less code is less to review correctly.
  • Token and latency cost: shorter output is cheaper to generate and faster to run.
  • Iteration risk: additive self-refinement is not free. One study measured a +37.6% rise in critical vulnerabilities after five refinement rounds (arXiv 2506.11022). Bias the loop toward deletion, then stop.

Verification hooks

After writing, cross-check deletability with real tools instead of guessing from the diff. Gate each behind command -v and fall back cleanly when absent.

bash
# JS/TS: unused files, exports, dependencies
command -v knip >/dev/null && knip || echo "knip absent; skipping"

# Python: dead code
command -v vulture >/dev/null && vulture . || echo "vulture absent; skipping"

# Rust: unused dependencies (nightly)
command -v cargo-udeps >/dev/null && cargo +nightly udeps \
  || echo "cargo-udeps absent; skipping"

Treat tool output as candidates, not verdicts. Code reachable only via reflection, dynamic dispatch, or framework magic can be flagged as dead while being live. Cross-check against the negligence floor before deleting anything.

How this composes

SkillRelationship
imbue:dependency-verificationRung 4/new-dep gate: confirm a package exists before adding it
leyline:additive-bias-defenseReview-side burden-of-proof contract this skill generates against
conserve:code-quality-principlesKISS/YAGNI principles this ladder operationalizes pre-code
conserve:unbloatWhole-codebase cleanup (this skill is per-change)
imbue:scope-guardFeature-level worthiness (this skill is line and dependency level)
pensive:hardenSecurity review that enforces the negligence floor

The /conserve:elegant-code-review command applies this ladder to the current working diff.

Exit Criteria

  • Each addition was walked down the ladder, and the chosen rung is stated (for example, "rung 2: stdlib zfill").
  • Any new dependency passed Skill(imbue:dependency-verification) and reuse of an installed dependency was ruled out first.
  • Every untrusted input has its negligence-floor guard present (validation, authorization, error handling).
  • A deletion tool was run, or its absence was noted, and no flagged candidate that is a guard was deleted.

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Elegant Code AI 技能有什么作用?

Guide minimal code via a decision ladder with full safety, edge, and negative-case coverage. Use when adding code, choosing a dependency, or auditing a diff.

为什么在 TypingMind 中使用 Elegant Code?

因为您只需安装一次,就能搭配任何模型使用。Elegant Code 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Elegant Code?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/athola/claude-night-market/tree/master/plugins/conserve/skills/elegant-code。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Elegant Code?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Elegant Code 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Elegant Code 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Elegant Code AI 技能免费吗?

是的。athola 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇