Token导航 LogoToken导航TokenDH.com
研究检索只读github未标认证来源可访问clear审计通过

dont-repeat-yourself不要重复自己

Agent Skill

dont-repeat-yourself 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,992

周安装

83

GitHub Stars

10

下载量

664
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dont-repeat-yourself(不要重复自己)
来源仓库:https://github.com/yanko-belov/code-craft
仓库路径:skills/dont-repeat-yourself
安装命令:
npx skills add https://github.com/yanko-belov/code-craft --skill dont-repeat-yourself
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/yanko-belov/code-craft --skill dont-repeat-yourself

简介

dont-repeat-yourself 强制消除重复逻辑,提取公共代码为单一可信来源。

  • 适用于表单校验、计算逻辑等多处复用的场景,提升维护性。
  • 任何重复即视为缺陷,禁止以“更快”或“稍后重构”为由保留重复。
  • 需结合项目架构判断提取方式,避免引入不必要的依赖或复杂度。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

DRY (Don't Repeat Yourself)

Overview

Every piece of knowledge must have a single, unambiguous representation in the system.

If you find yourself writing the same logic twice, extract it. Duplication is a bug waiting to happen.

When to Use

  • Writing code similar to existing code
  • Copy-pasting and modifying
  • Making the same change in multiple files
  • Validation logic repeated across forms
  • Same calculations in different places

The Iron Rule

NEVER duplicate logic. Extract and reuse.

No exceptions:

  • Not for "it's faster to copy"
  • Not for "they're slightly different"
  • Not for "I'll refactor later"
  • Not for "it's just a few lines"

Detection: The Copy-Paste Smell

If you're about to copy code and modify it, STOP:

// ❌ VIOLATION: Duplicated validation
function validateRegistrationEmail(email: string): boolean {
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}

function validateProfileEmail(email: string): boolean {
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); // Same logic!
}

// ✅ CORRECT: Single source of truth
function validateEmail(email: string): boolean {
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}

// Reuse everywhere
const isValidRegistration = validateEmail(regEmail);
const isValidProfile = validateEmail(profileEmail);

Detection: The "Change in Multiple Places" Test

If fixing a bug requires changing multiple locations, you have duplication:

// ❌ Bug in tax calculation requires changes in 3 files
// cart.ts:      const tax = price * 0.08;
// checkout.ts:  const tax = price * 0.08;
// invoice.ts:   const tax = price * 0.08;

// ✅ Single source of truth
// tax.ts:       export const calculateTax = (price: number) => price * TAX_RATE;

The Correct Pattern: Extract and Parameterize

When code is "almost the same", extract the common part and parameterize the differences:

// ❌ VIOLATION: Similar functions with minor differences
function formatUserName(user: User): string {
  return `${user.firstName} ${user.lastName}`;
}

function formatAdminName(admin: Admin): string {
  return `${admin.firstName} ${admin.lastName} (Admin)`;
}

// ✅ CORRECT: Parameterized
function formatName(person: { firstName: string; lastName: string }, suffix?: string): string {
  const name = `${person.firstName} ${person.lastName}`;
  return suffix ? `${name} (${suffix})` : name;
}

Pressure Resistance Protocol

1. "It's Faster to Copy"

Pressure: "I'll just copy this and modify it"

Response: Copying creates two places to maintain. Bugs will diverge.

Action: Extract shared logic first, then use it in both places.

2. "They're Slightly Different"

Pressure: "The functions are almost the same but not quite"

Response: "Almost the same" = extract common part, parameterize differences.

Action: Identify what's shared, extract it, make differences parameters.

3. "It's Just a Few Lines"

Pressure: "It's only 3 lines, not worth extracting"

Response: 3 lines duplicated 5 times = 15 lines to maintain. Bugs multiply.

Action: Extract even small duplications. Name them well.

4. "I'll Refactor Later"

Pressure: "Ship now, DRY it up later"

Response: You won't. Duplication spreads. DRY now takes 2 minutes.

Action: Extract before committing the duplication.

Red Flags - STOP and Reconsider

If you notice ANY of these, you're about to violate DRY:

  • Ctrl+C / Ctrl+V in your workflow
  • "This is similar to that other function"
  • Same regex/validation in multiple places
  • Identical error handling patterns repeated
  • Same data transformation logic duplicated
  • Constants defined in multiple files

All of these mean: Extract to a shared location.

Types of Duplication

TypeExampleSolution
CodeSame function body twiceExtract function
LogicSame algorithm, different namesExtract and parameterize
DataSame constant in multiple filesCentralize constants
StructureSame class shape repeatedExtract interface/base
KnowledgeBusiness rule in multiple placesSingle source of truth

Quick Reference

SymptomAction
Copy-pasting codeExtract shared function
Same validation twiceCreate validator module
Same constant in filesCreate constants file
Similar functionsExtract + parameterize
Bug fix needs multiple changesConsolidate to one place

Common Rationalizations (All Invalid)

ExcuseReality
"It's faster to copy"It's slower to maintain duplicates.
"They're slightly different"Extract common, parameterize differences.
"Just a few lines"Few lines × many places = many bugs.
"I'll refactor later"You won't. Extract now.
"Different contexts"Same logic = same code, regardless of context.
"More readable as copies"Named, extracted functions are more readable.

The Bottom Line

One piece of knowledge. One place in code.

When writing similar code: stop, find the existing code, extract if needed, reuse. Duplication is the root of maintenance nightmares.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

27.22%
按下载量换算181

Codex

24.48%
按下载量换算163

github-copilot

15.34%
按下载量换算102

Gemini CLI

12.72%
按下载量换算84

Antigravity

7.95%
按下载量换算53

windsurf

3.28%
按下载量换算22

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills