Communitygithub.com

alfathafp/技能编写

用于创建新技能、编辑现有技能或验证技能在部署前是否正常工作

技能编写 是什么?

本技能文档阐述了技能编写应遵循测试驱动开发(TDD)方法论,将测试用例(包含子代理的压力场景)应用于流程文档的编写。它强调在编写技能文档之前,必须首先观察没有该技能时代理的行为(基线失败),然后编写技能文档使代理行为符合预期,最后通过重构来堵住漏洞。支持 Claude Code、Codex、Copilot CLI、Gemini CLI 等平台,技能文件通常存放在 `~/.claude/skills/` 或 `~/.agents/skills/` 目录下。核心原则是:如果你没有看到代理在缺乏该技能时失败,你就不知道技能是否真正教会了它正确的事情。该文档还详细介绍了技能的类型(技术、模式、参考)、何时创建技能、SKILL.md 文件结构、技能发现优化(SDO)、流程图使用规范以及代码示例的最佳实践。

兼容平台✓Claude Code✓Codex CLI~Cursor✓Gemini CLI
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/writing-skills

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

技能编写 是做什么的?

概述

技能编写即是将测试驱动开发应用于流程文档。

个人技能位于运行时的技能目录中(Claude Code 上为 ~/.claude/skills/)——有关这些运行时的路径,请参阅 codex-tools.md 或 gemini-tools.md。Codex、Copilot CLI 和 Gemini CLI 也都将 ~/.agents/skills/ 识别为跨运行时别名。

你编写测试用例(包含子代理的压力场景),观察它们失败(基线行为),然后编写技能(文档),观察测试通过(代理遵从),最后重构(堵住漏洞)。

核心原则: 如果你没有看到代理在缺乏该技能时失败,你就不知道技能是否教会了它正确的事情。

必需背景: 在使用此技能前,你必须了解 superpowers:test-driven-development。该技能定义了基本的 RED-GREEN-REFACTOR 循环。本技能将 TDD 应用于文档。

官方指南: 有关 Anthropic 的官方技能编写最佳实践,请参阅 anthropic-best-practices.md。本文档提供了额外的模式和指南,作为对本技能中 TDD 方法的补充。

什么是技能?

技能是经过验证的技术、模式或工具的参考指南。技能有助于未来的代理找到并应用有效的方法。

技能包括: 可重用的技术、模式、工具、参考指南

技能不包括: 关于你如何解决某个问题的叙述性描述

技能的 TDD 映射

TDD 概念技能创建
测试用例包含子代理的压力场景
生产代码技能文档 (SKILL.md)
测试失败 (RED)代理在没有技能时违反规则(基线)
测试通过 (GREEN)代理在技能存在时遵从
重构堵住漏洞同时保持遵从
先写测试在编写技能之前运行基线场景
观察失败记录代理使用的确切理由
最小代码编写针对这些具体违规行为的技能
观察通过验证代理现在遵从
重构循环发现新理由 → 堵住 → 重新验证

整个技能创建过程遵循 RED-GREEN-REFACTOR。

何时创建技能

创建时机:

  • 该技术对你来说并非直观易懂
  • 你会在跨项目中再次参考它
  • 该模式适用于广泛场景(非项目特定)
  • 其他人会从中受益

不要创建:

  • 一次性解决方案
  • 其他地方已有完善文档的标准实践
  • 项目特定的约定(放入你的说明文件中)
  • 机械约束(如果可以通过正则表达式/验证强制执行,则将其自动化——保留文档供判断性使用)

技能类型

技术

具有可遵循步骤的具体方法(基于条件的等待、根本原因追溯)

模式

思考问题的方式(使用标志展平、测试不变性)

参考

API 文档、语法指南、工具文档(办公文档)

目录结构

skills/
  skill-name/
    SKILL.md              # 主要参考(必需)
    supporting-file.*     # 仅在需要时

扁平命名空间 - 所有技能都在一个可搜索的命名空间中

分离文件用于:

  1. 大量参考(100 行以上) - API 文档、全面语法
  2. 可重用工具 - 脚本、实用工具、模板

内联保留:

  • 原则和概念
  • 代码模式(< 50 行)
  • 其他所有内容

SKILL.md 结构

前置元数据(YAML):

  • 两个必需字段:name 和 description(参见 agentskills.io/specification 了解所有支持的字段)
  • 总字数最多 1024 个字符
  • name:仅使用字母、数字和连字符(不含括号、特殊字符)
  • description:第三人称,仅描述何时使用(而非其功能)
    • 以“Use when...”开头,聚焦触发条件
    • 包括具体的症状、情况和上下文
    • 切勿总结技能的过程或工作流(原因见 SDO 部分)
    • 如可能,保持在 500 个字符以下
---
name: Skill-Name-With-Hyphens
description: Use when [specific triggering conditions and symptoms]
---

# Skill Name

## Overview
这是什么?用 1-2 句话说明核心原则。

## When to Use
[如果决策非显而易见,使用小型内联流程图]

包含症状和用例的列表
何时不使用

## Core Pattern(用于技术/模式)
之前/之后的代码对比

## Quick Reference
用于扫描常见操作的表或列表

## Implementation
对于简单模式使用内联代码
对于大量参考或可重用工具链接到文件

## Common Mistakes
出错原因 + 修复方法

## Real-World Impact(可选)
具体成果

技能发现优化 (SDO)

对发现至关重要: 未来的代理需要找到你的技能

1. 丰富的描述字段

目的: 你的代理读取描述以决定针对给定任务加载哪些技能。让它回答:“我现在应该阅读这个技能吗?”

格式: 以“Use when...”开头,聚焦触发条件

关键:描述 = 何时使用,而非技能做什么

描述应仅描述触发条件。不要在描述中总结技能的过程或工作流。

为什么这很重要: 测试表明,当描述总结技能的工作流时,代理可能会遵循描述而不是阅读完整的技能内容。描述中写“任务间代码审查”导致代理只进行一次审查,尽管技能的流程图清楚显示两次审查(规范符合性 -> 代码质量)。

当描述改为“Use when executing implementation plans with independent tasks”(不含工作流总结)时,代理正确读取流程图并遵循两阶段审查过程。

陷阱: 总结工作流的描述会创建代理会遵循的快捷方式。技能主体成为代理跳过的文档。

# ❌ 错误:总结工作流 - 代理可能遵循此描述而不是阅读技能
description: Use when executing plans - dispatches subagent per task with code review between tasks

# ❌ 错误:包含过多过程细节
description: Use for TDD - write test first, watch it fail, write minimal code, refactor

# ✅ 正确:仅触发条件,无工作流总结
description: Use when executing implementation plans with independent tasks in the current session

# ✅ 正确:仅触发条件
description: Use when implementing any feature or bugfix, before writing implementation code

内容:

  • 使用具体的触发器、症状和表明此技能适用的情况
  • 描述问题(竞态条件、不一致行为),而非特定于语言的症状(setTimeout、sleep)
  • 保持触发器与技术无关,除非技能本身与技术相关
  • 如果技能与技术相关,在触发器中明确指出
  • 使用第三人称编写(注入到系统提示中)
  • 切勿总结技能的过程或工作流
# ❌ 错误:过于抽象、模糊,未包含何时使用
description: For async testing

# ❌ 错误:第一人称
description: I can help you with async tests when they're flaky

# ❌ 错误:提及技术但技能并非特定于此技术
description: Use when tests use setTimeout/sleep and are flaky

# ✅ 正确:以“Use when”开头,描述问题,无工作流
description: Use when tests have race conditions, timing dependencies, or pass/fail inconsistently

# ✅ 正确:特定于技术的技能,带有明确触发条件
description: Use when using React Router and handling authentication redirects

2. 关键词覆盖

使用代理会搜索的词:

  • 错误消息:“Hook timed out”、“ENOTEMPTY”、“race condition”
  • 症状:“flaky”、“hanging”、“zombie”、“pollution”
  • 同义词:“timeout/hang/freeze”、“cleanup/teardown/afterEach”
  • 工具:实际命令、库名、文件类型

3. 描述性命名

使用主动语态,以动词开头:

  • ✅ creating-skills 而非 skill-creation
  • ✅ condition-based-waiting 而非 async-test-helpers

4. Token 效率(关键)

问题: 入门指南和频繁引用的技能会加载到每个对话中。每个 token 都很重要。

目标字数:

  • 入门指南工作流:每个 <150 个单词
  • 频繁加载的技能:总计 <200 个单词
  • 其他技能:<500 个单词(仍需简洁)

技巧:

将细节移至工具帮助:

# ❌ 错误:在 SKILL.md 中记录所有标志
search-conversations supports --text, --both, --after DATE, --before DATE, --limit N

# ✅ 正确:引用 --help
search-conversations supports multiple modes and filters. Run --help for details.

使用交叉引用:

# ❌ 错误:重复工作流细节
When searching, dispatch subagent with template...
[20 lines of repeated instructions]

# ✅ 正确:引用其他技能
Always use subagents (50-100x context savings). REQUIRED: Use [other-skill-name] for workflow.

压缩示例:

# ❌ 错误:冗长示例(42 个单词)
your human partner: "How did we handle authentication errors in React Router before?"
You: I'll search past conversations for React Router authentication patterns.
[Dispatch subagent with search query: "React Router authentication error handling 401"]

# ✅ 正确:最小示例(20 个单词)
Partner: "How did we handle auth errors in React Router?"
You: Searching...
[Dispatch subagent → synthesis]

消除冗余:

  • 不要重复交叉引用技能中的内容
  • 不要解释从命令中显而易见的内容
  • 不要包含同一模式的多个示例

验证:

wc -w skills/path/SKILL.md
# getting-started workflows: aim for <150 each
# Other frequently-loaded: aim for <200 total

根据你的所做之事或核心见解命名:

  • ✅ condition-based-waiting > async-test-helpers
  • ✅ using-skills 而非 skill-usage
  • ✅ flatten-with-flags > data-structure-refactoring
  • ✅ root-cause-tracing > debugging-techniques

动名词 (-ing) 非常适合流程:

  • creating-skills、testing-skills、debugging-with-logs
  • 主动,描述你正在执行的操作

5. 交叉引用其他技能

在编写引用其他技能的文档时:

仅使用技能名称,并带有显式要求标记:

  • ✅ 正确:**REQUIRED SUB-SKILL:** Use superpowers:test-driven-development
  • ✅ 正确:**REQUIRED BACKGROUND:** You MUST understand superpowers:systematic-debugging
  • ❌ 错误:See skills/testing/test-driven-development(不清楚是否为必需)
  • ❌ 错误:@skills/testing/test-driven-development/SKILL.md(强制加载,消耗上下文)

为什么不用 @ 链接: @ 语法会立即强制加载文件,在需要使用它们之前消耗 200k+ 上下文。

流程图使用

digraph when_flowchart {
    "Need to show information?" [shape=diamond];
    "Decision where I might go wrong?" [shape=diamond];
    "Use markdown" [shape=box];
    "Small inline flowchart" [shape=box];

    "Need to show information?" -> "Decision where I might go wrong?" [label="yes"];
    "Decision where I might go wrong?" -> "Small inline flowchart" [label="yes"];
    "Decision where I might go wrong?" -> "Use markdown" [label="no"];
}

仅在以下情况下使用流程图:

  • 非显而易见的决策点
  • 可能过早停止的流程循环
  • “何时使用 A 与 B”的决策

绝不在以下情况使用流程图:

  • 参考材料 → 表格、列表
  • 代码示例 → Markdown 代码块
  • 线性指令 → 编号列表
  • 无语义含义的标签(step1、helper2)

请参阅此目录中的 graphviz-conventions.dot 了解 graphviz 样式规则。

为人工伙伴可视化: 使用此目录中的 render-graphs.js 将技能的流程图渲染为 SVG:

node ./render-graphs.js ../some-skill           # 分别渲染每个图表
node ./render-graphs.js ../some-skill --combine # 将所有图表合并为一个 SVG

代码示例

一个优秀的示例胜过多个平庸的示例

选择最相关的语言:

  • 测试技术 → TypeScript/JavaScript
  • 系统调试 → Shell/Python
  • 数据处理 → Python

优秀示例的特征:

  • 完整且可运行
  • 通过注释解释原因
  • 来自真实场景
  • 清晰展示模式
  • 可直接改编(非通用模板)

不要:

  • 用 5 种以上语言实现
  • 创建填空模板
  • 编写牵强的示例

你擅长移植——一个优秀的示例就足够了。

文件组织

自包含技能

defense-in-depth/
  SKILL.md    # 所有内容内联

适用:所有内容都能容纳,无需大量参考

包含可重用工具的技能

condition-based-waiting/
  SKILL.md    # 概述 + 模式
  example.ts  # 可供改编的工作辅助工具

适用:工具是可重用代码,而非仅仅是叙述

包含大量参考的技能

pptx/
  SKILL.md       # 概述 + 工作流
  pptxgenjs.md   # 600 行 API 参考
  ooxml.md       # 500 行 XML 结构
  scripts/       # 可执行工具

适用:参考材料过大,不适合内联

通过解释器调用捆绑的脚本(bash scripts/tool.sh、node scripts/tool.js),切勿使用裸路径:某些工具包会剥离可执行位,裸路径 scripts/tool.sh 会因 Permission denied 而失败。

铁律(与 TDD 相同)

NO SKILL WITHOUT A FAILING TEST FIRST

这适用于新技能和对现有技能的编辑。

在未测试之前编写技能?删除它。重新开始。 编辑技能而不测试?同样的违规。

无例外:

  • 不是“简单添加”
  • 不是“仅仅添加一个章节”
  • 不是“文档更新”
  • 不要将未经测试的更改保留为“参考”
  • 不要在运行测试时“改编”
  • 删除意味着删除

必需背景: superpowers:test-driven-development

...

[由于输入截断,此处为原文。实际翻译应覆盖完整 SKILL.md 内容。]

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

相关技能