Skip to content

6. Skill 开发最佳实践

6.1 结构化模板

markdown
---
name: my-skill
description: Clear, concise description (one sentence)
triggers:
  - keyword1
  - keyword2
version: 1.0.0
---

# Skill Name

## When to Use

Clearly state when this skill should be activated.

## Prerequisites

List what needs to be in place before using this skill.

## Workflow

### Step 1: Title

Clear instructions with code examples.

\`\`\`bash
# Command with explanation
command --flag value
\`\`\`

### Step 2: Title

Continue with next step.

## Common Issues

### Issue: Problem description

**Symptom**: What the user sees

**Solution**: How to fix it

## References

- [Related Doc](./references/doc.md)

6.2 编写技巧

DO ✅:

markdown
## Triggers

Use specific, relevant keywords:

triggers:
  - deploy
  - deployment
  - production
  - release
  - ship

## Description

Be specific and actionable:

description: Deploy applications to production using Docker and Kubernetes with automated rollback

## Content

Provide concrete examples:

\`\`\`bash
# Build Docker image
docker build -t myapp:1.0.0 .

# Push to registry
docker push registry.example.com/myapp:1.0.0
\`\`\`

DON'T ❌:

markdown
## Triggers

Too generic:

triggers:
  - help
  - do
  - thing

## Description

Too vague:

description: Helps with stuff

## Content

No examples:

"Build and deploy the application using standard procedures."

6.3 测试 Skill

typescript
class SkillTester {
  // 测试触发条件
  async testTriggers(skillName: string) {
    const skill = await this.loadSkill(skillName);

    const testCases = [
      "Deploy to production",
      "I need to deploy",
      "How do I release?",
      "Ship the new version"
    ];

    for (const input of testCases) {
      const detected = await this.detector.detect(input);
      const found = detected.some(s => s.name === skillName);

      console.log(`Input: "${input}"`);
      console.log(`Detected: ${found ? '✓' : '✗'}`);
    }
  }

  // 测试内容完整性
  async testContent(skillName: string) {
    const skill = await this.loadSkill(skillName);

    const checks = [
      {
        name: 'Has frontmatter',
        test: () => skill.content.startsWith('---')
      },
      {
        name: 'Has description',
        test: () => skill.description.length > 10
      },
      {
        name: 'Has triggers',
        test: () => skill.triggers.length > 0
      },
      {
        name: 'Has workflow section',
        test: () => skill.content.includes('## Workflow')
      },
      {
        name: 'Has code examples',
        test: () => skill.content.includes('```')
      }
    ];

    for (const check of checks) {
      const passed = check.test();
      console.log(`${check.name}: ${passed ? '✓' : '✗'}`);
    }
  }
}

前端面试知识库