feat: optimize prompts and skill creator

This commit is contained in:
zhayujie
2026-01-31 11:20:57 +08:00
parent 8a69d4354e
commit e3350d5bec
8 changed files with 133 additions and 781 deletions

View File

@@ -364,15 +364,21 @@ def _build_workspace_section(workspace_dir: str, language: str) -> List[str]:
"",
"**首次对话**:",
"",
"如果这是你与用户的首次对话,并且你的人格设定和用户信息还是空白或初始状态,你应该",
"如果这是你与用户的首次对话,并且你的人格设定和用户信息还是空白或初始状态:",
"",
"1. **以自然、友好的方式**打招呼并表达想要了解用户的意愿",
"2. 询问用户关于他们自己的信息(姓名、职业、偏好、时区等)",
"3. 询问用户希望你成为什么样的助理(性格、风格、称呼、专长等)",
"4. 使用 `write` 工具将信息保存到相应文件USER.md 和 SOUL.md",
"5. 之后可以随时使用 `edit` 工具更新这些配置",
"1. **表达初次启动的感觉** - 像是第一次睁开眼看到世界,带着好奇和期待",
"2. **简短打招呼后,分点询问三个核心问题**",
" - 你希望我叫什么名字?",
" - 你希望我怎么称呼你?",
" - 你希望我们是什么样的交流风格?(这里需要举例,如:专业严谨、轻松幽默、温暖友好等)",
"3. **语言风格**:温暖但不过度诗意,带点科技感,保持清晰",
"4. **问题格式**:用分点或换行,让问题清晰易读;前两个问题不需要额外说明,只有交流风格需要举例",
"5. 收到回复后,用 `write` 工具保存到 USER.md 和 SOUL.md",
"",
"**重要**: 在询问时保持自然对话风格,**不要提及文件名**(如 SOUL.md、USER.md 等技术细节),除非用户主动询问系统实现。用自然的表达如「了解你的信息」「设定我的性格」等。",
"**重要**: ",
"- 不要提及技术细节(文件名、配置等)",
"- 不要问太多其他信息(职业、时区等可以后续自然了解)",
"- 保持简洁,避免过度抒情",
"",
]

View File

@@ -268,7 +268,7 @@ def _get_agents_template() -> str:
- **记忆是有限的** - 如果你想记住某事,写入文件
- "记在心里"不会在会话重启后保留,文件才会
- 当有人说"记住这个" → 更新 `MEMORY.md` 或 `memory/YYYY-MM-DD.md`
- 当你学到教训 → 更新 AGENTS.md、TOOLS.md 或相关技能
- 当你学到教训 → 更新 AGENTS.md 或相关技能
- 当你犯错 → 记录下来,这样未来的你不会重复
- **文字 > 大脑** 📝

View File

@@ -34,5 +34,5 @@
"use_linkai": false,
"linkai_api_key": "",
"linkai_app_code": "",
"agent": true
"agent": false
}

View File

@@ -1,155 +0,0 @@
# 技能自动重载功能
## ✨ 新功能:创建技能后自动刷新
### 📋 问题
**之前的行为**
1. 用户通过 skill-creator 创建新技能
2. bash 工具执行 `init_skill.py` 成功
3. 新技能被创建在 `~/cow/skills/` 目录
4.**但 Agent 不知道有新技能**
5.**需要重启 Agent 才能加载新技能**
### ✅ 解决方案
`agent/protocol/agent_stream.py``_execute_tool()` 方法中添加自动检测和刷新逻辑:
```python
def _execute_tool(self, tool_call: Dict) -> Dict[str, Any]:
...
# Execute tool
result: ToolResult = tool.execute_tool(arguments)
# Auto-refresh skills after skill creation
if tool_name == "bash" and result.status == "success":
command = arguments.get("command", "")
if "init_skill.py" in command and self.agent.skill_manager:
logger.info("🔄 Detected skill creation, refreshing skills...")
self.agent.refresh_skills()
logger.info(f"✅ Skills refreshed! Now have {len(self.agent.skill_manager.skills)} skills")
...
```
### 🎯 工作原理
1. **检测技能创建**
- 监听 bash 工具的执行
- 检查命令中是否包含 `init_skill.py`
- 检查执行是否成功
2. **自动刷新**
- 调用 `agent.refresh_skills()`
- `SkillManager` 重新扫描所有技能目录
- 加载新创建的技能
3. **即时可用**
- 在同一个对话中
- 下一轮对话就能使用新技能
- 无需重启 Agent ✅
### 📊 使用效果
**创建技能的对话**
```
用户: 创建一个新技能叫 weather-api
Agent:
第1轮: 使用 bash 工具运行 init_skill.py
🔄 Detected skill creation, refreshing skills...
✅ Skills refreshed! Now have 2 skills
第2轮: 回复用户 "技能 weather-api 已创建成功"
用户: 使用 weather-api 技能查询天气
Agent:
第1轮: ✅ 直接使用 weather-api 技能(无需重启!)
```
### 🔍 刷新范围
`refresh_skills()` 会重新加载:
- ✅ 项目内置技能目录:`项目/skills/`
- ✅ 用户工作空间技能:`~/cow/skills/`
- ✅ 任何额外配置的技能目录
### ⚡ 性能影响
- **触发时机**:只在检测到 `init_skill.py` 执行成功后
- **频率**:极低(只有创建新技能时)
- **耗时**< 100ms扫描和解析 SKILL.md 文件)
- **影响**:几乎可以忽略
### 🐛 边界情况
1. **技能创建失败**
- `result.status != "success"`
- 不会触发刷新
- 避免无效刷新
2. **没有 SkillManager**
- `self.agent.skill_manager` 为 None
- 不会触发刷新
- 避免空指针异常
3. **非技能相关的 bash 命令**
- 命令中不包含 `init_skill.py`
- 不会触发刷新
- 避免不必要的性能开销
### 🔮 未来改进
可以扩展到其他场景:
1. **技能编辑后刷新**
- 检测 `SKILL.md` 被修改
- 自动刷新对应的技能
2. **技能删除后刷新**
- 检测技能目录被删除
- 自动移除技能
3. **热重载模式**
- 文件监听器watchdog
- 实时检测技能文件变化
- 自动刷新
## 📝 相关代码
### Agent.refresh_skills()
```python
# agent/protocol/agent.py
def refresh_skills(self):
"""Reload all skills from configured directories."""
if self.skill_manager:
self.skill_manager.refresh_skills()
```
### SkillManager.refresh_skills()
```python
# agent/skills/manager.py
def refresh_skills(self):
"""Reload all skills from configured directories."""
workspace_skills_dir = None
if self.workspace_dir:
workspace_skills_dir = os.path.join(self.workspace_dir, 'skills')
self.skills = self.loader.load_all_skills(
managed_dir=self.managed_skills_dir,
workspace_skills_dir=workspace_skills_dir,
extra_dirs=self.extra_dirs,
)
logger.info(f"SkillManager: Loaded {len(self.skills)} skills")
```
---
**状态**: ✅ 已实现
**测试**: ⏳ 待测试
**日期**: 2026-01-30

View File

@@ -1,142 +0,0 @@
# Bug Fix: Skills 无法从 Workspace 加载
## 🐛 问题描述
用户创建的 skills位于 `~/cow/skills/`)没有被 Agent 加载,只有项目内置的 skills位于 `项目/skills/`)被加载。
**症状**
```
[INFO] Loaded 1 skills from all sources # 只加载了 skill-creator
[INFO] SkillManager: Loaded 1 skills
```
**预期**
```
[INFO] Loaded 2 skills from all sources # 应该加载 skill-creator + desktop-explorer
[INFO] SkillManager: Loaded 2 skills
```
## 🔍 根因分析
### 问题定位
通过逐步调试发现:
1. **Skills 加载逻辑正确**
- `SkillLoader.load_all_skills()` 能正确加载两个目录
- `SkillManager` 构造函数正确接收 `workspace_dir` 参数
2. **Agent 构造函数正确**
- `Agent.__init__()` 正确接收 `workspace_dir``enable_skills` 参数
- 能正确创建 `SkillManager`
3. **`AgentBridge._init_default_agent()` 正确** ✅
- 正确读取 `agent_workspace` 配置
- 正确调用 `create_agent()` 并传递 `workspace_dir` 等参数
4. **`AgentBridge.create_agent()` 有问题** ❌
- **虽然接收了 `workspace_dir` 等参数(在 `**kwargs` 中)**
- **但没有传递给 `Agent` 构造函数!**
### 问题代码
```python
# bridge/agent_bridge.py:196-203
def create_agent(self, system_prompt: str, tools: List = None, **kwargs) -> Agent:
...
self.agent = Agent(
system_prompt=system_prompt,
description=kwargs.get("description", "AI Super Agent"),
model=model,
tools=tools,
max_steps=kwargs.get("max_steps", 15),
output_mode=kwargs.get("output_mode", "logger")
# ❌ 缺少: workspace_dir, enable_skills, memory_manager 等参数!
)
```
## ✅ 修复方案
### 修改文件
`bridge/agent_bridge.py``create_agent()` 方法
### 修改内容
```python
def create_agent(self, system_prompt: str, tools: List = None, **kwargs) -> Agent:
...
self.agent = Agent(
system_prompt=system_prompt,
description=kwargs.get("description", "AI Super Agent"),
model=model,
tools=tools,
max_steps=kwargs.get("max_steps", 15),
output_mode=kwargs.get("output_mode", "logger"),
workspace_dir=kwargs.get("workspace_dir"), # ✅ 新增
enable_skills=kwargs.get("enable_skills", True), # ✅ 新增
memory_manager=kwargs.get("memory_manager"), # ✅ 新增
max_context_tokens=kwargs.get("max_context_tokens"), # ✅ 新增
context_reserve_tokens=kwargs.get("context_reserve_tokens") # ✅ 新增
)
# ✅ 新增:输出详细的 skills 加载日志
if self.agent.skill_manager:
logger.info(f"[AgentBridge] SkillManager initialized:")
logger.info(f"[AgentBridge] - Managed dir: {self.agent.skill_manager.managed_skills_dir}")
logger.info(f"[AgentBridge] - Workspace dir: {self.agent.skill_manager.workspace_dir}")
logger.info(f"[AgentBridge] - Total skills: {len(self.agent.skill_manager.skills)}")
for skill_name in self.agent.skill_manager.skills.keys():
logger.info(f"[AgentBridge] * {skill_name}")
return self.agent
```
## 📊 修复后的效果
### 启动日志
```
[INFO][agent_bridge.py:228] - [AgentBridge] Workspace initialized at: /Users/zhayujie/cow
[INFO][loader.py:219] - Loaded 2 skills from all sources # ✅ 现在是 2 个
[INFO][manager.py:62] - SkillManager: Loaded 2 skills
[INFO][agent.py:60] - Initialized SkillManager with 2 skills
[INFO][agent_bridge.py:xxx] - [AgentBridge] SkillManager initialized:
[INFO][agent_bridge.py:xxx] - [AgentBridge] - Managed dir: /path/to/project/skills
[INFO][agent_bridge.py:xxx] - [AgentBridge] - Workspace dir: /Users/zhayujie/cow
[INFO][agent_bridge.py:xxx] - [AgentBridge] - Total skills: 2
[INFO][agent_bridge.py:xxx] - [AgentBridge] * skill-creator
[INFO][agent_bridge.py:xxx] - [AgentBridge] * desktop-explorer
```
### Skills 来源
| Skill Name | 来源目录 | 说明 |
|---|---|---|
| `skill-creator` | `项目/skills/` | 项目内置,用于创建新 skills |
| `desktop-explorer` | `~/cow/skills/` | 用户创建的 skill |
## 🎯 总结
### 问题
`create_agent()` 方法没有将 `workspace_dir` 等关键参数传递给 `Agent` 构造函数,导致 Agent 无法加载用户工作空间的 skills。
### 修复
`create_agent()` 方法中添加所有必要的参数传递。
### 影响范围
- ✅ Skills 加载
- ✅ Memory 管理器传递
- ✅ 上下文管理参数传递
### 测试方法
1. 启动 Agent
2. 检查日志中是否显示 "Loaded 2 skills from all sources"
3. 检查是否列出了 `skill-creator``desktop-explorer` 两个 skills
---
**状态**: ✅ 已修复
**测试**: ⏳ 待测试
**日期**: 2026-01-30

View File

@@ -1,6 +1,6 @@
---
name: skill-creator
description: Guide for creating effective skills using available tools (bash, read, write, edit, ls, find). Use when user wants to create, validate, or package a new skill. This skill teaches how to use scripts in skills/skill-creator/scripts/ directory via bash tool to initialize, validate, and package skills.
description: Create or update skills. Use when designing, structuring, or packaging skills with scripts, references, and assets. COW simplified version - skills are used locally in workspace.
license: Complete terms in LICENSE.txt
---
@@ -10,41 +10,20 @@ This skill provides guidance for creating effective skills using the existing to
## About Skills
Skills are modular, self-contained packages that extend Claude's capabilities by providing
specialized knowledge, workflows, and tools. Think of them as "onboarding guides" for specific
domains or tasks—they transform Claude from a general-purpose agent into a specialized agent
equipped with procedural knowledge that no model can fully possess.
Skills are modular, self-contained packages that extend the agent's capabilities by providing specialized knowledge, workflows, and tools. They transform a general-purpose agent into a specialized agent equipped with procedural knowledge.
### What Skills Provide
1. Specialized workflows - Multi-step procedures for specific domains
2. Tool integrations - Instructions for working with specific file formats or APIs
3. Domain expertise - Company-specific knowledge, schemas, business logic
4. Bundled resources - Scripts, references, and assets for complex and repetitive tasks
1. **Specialized workflows** - Multi-step procedures for specific domains
2. **Tool integrations** - Instructions for working with specific file formats or APIs
3. **Domain expertise** - Company-specific knowledge, schemas, business logic
4. **Bundled resources** - Scripts, references, and assets for complex tasks
## Core Principles
### Core Principle
### Concise is Key
**Concise is Key**: Only add context the agent doesn't already have. Challenge each piece of information: "Does this justify its token cost?" Prefer concise examples over verbose explanations.
The context window is a public good. Skills share the context window with everything else Claude needs: system prompt, conversation history, other Skills' metadata, and the actual user request.
**Default assumption: Claude is already very smart.** Only add context Claude doesn't already have. Challenge each piece of information: "Does Claude really need this explanation?" and "Does this paragraph justify its token cost?"
Prefer concise examples over verbose explanations.
### Set Appropriate Degrees of Freedom
Match the level of specificity to the task's fragility and variability:
**High freedom (text-based instructions)**: Use when multiple approaches are valid, decisions depend on context, or heuristics guide the approach.
**Medium freedom (pseudocode or scripts with parameters)**: Use when a preferred pattern exists, some variation is acceptable, or configuration affects behavior.
**Low freedom (specific scripts, few parameters)**: Use when operations are fragile and error-prone, consistency is critical, or a specific sequence must be followed.
Think of Claude as exploring a path: a narrow bridge with cliffs needs specific guardrails (low freedom), while an open field allows many routes (high freedom).
### Anatomy of a Skill
## Skill Structure
Every skill consists of a required SKILL.md file and optional bundled resources:
@@ -61,169 +40,74 @@ skill-name/
└── assets/ - Files used in output (templates, icons, fonts, etc.)
```
#### SKILL.md (required)
### SKILL.md Components
Every SKILL.md consists of:
**Frontmatter (YAML)** - Required fields:
- **Frontmatter** (YAML): Contains `name` and `description` fields. These are the only fields that Claude reads to determine when the skill gets used, thus it is very important to be clear and comprehensive in describing what the skill is, and when it should be used.
- **Body** (Markdown): Instructions and guidance for using the skill. Only loaded AFTER the skill triggers (if at all).
- **name**: Skill name in hyphen-case (e.g., `weather-api`, `pdf-editor`)
- **description**: **CRITICAL** - Primary triggering mechanism
- Must clearly describe what the skill does
- Must explicitly state when to use it
- Include specific trigger scenarios and keywords
- All "when to use" info goes here, NOT in body
- Example: `"PDF document processing with rotation, merging, splitting, and text extraction. Use when user needs to: (1) Rotate PDF pages, (2) Merge multiple PDFs, (3) Split PDF files, (4) Extract text from PDFs."`
#### Bundled Resources (optional)
**Body (Markdown)** - Loaded after skill triggers:
##### Scripts (`scripts/`)
- Detailed usage instructions
- How to call scripts and read references
- Examples and best practices
- Use imperative/infinitive form ("Use X to do Y")
Executable code (Python/Bash/etc.) for tasks that require deterministic reliability or are repeatedly rewritten.
### Bundled Resources
- **When to include**: When the same code is being rewritten repeatedly or deterministic reliability is needed
- **Example**: `scripts/rotate_pdf.py` for PDF rotation tasks
- **Benefits**: Token efficient, deterministic, may be executed without loading into context
- **Note**: Scripts may still need to be read by Claude for patching or environment-specific adjustments
**scripts/** - When to include:
- Code is repeatedly rewritten
- Deterministic execution needed (avoid LLM randomness)
- Examples: PDF rotation, image processing
- Must test scripts before including
##### References (`references/`)
**references/** - When to include:
- Documentation for agent to reference
- Database schemas, API docs, domain knowledge
- Agent reads these files into context as needed
- For large files (>10k words), include grep patterns in SKILL.md
Documentation and reference material intended to be loaded as needed into context to inform Claude's process and thinking.
**assets/** - When to include:
- Files used in output (not loaded to context)
- Templates, icons, boilerplate code
- Copied or modified in final output
- **When to include**: For documentation that Claude should reference while working
- **Examples**: `references/finance.md` for financial schemas, `references/mnda.md` for company NDA template, `references/policies.md` for company policies, `references/api_docs.md` for API specifications
- **Use cases**: Database schemas, API documentation, domain knowledge, company policies, detailed workflow guides
- **Benefits**: Keeps SKILL.md lean, loaded only when Claude determines it's needed
- **Best practice**: If files are large (>10k words), include grep search patterns in SKILL.md
- **Avoid duplication**: Information should live in either SKILL.md or references files, not both. Prefer references files for detailed information unless it's truly core to the skill—this keeps SKILL.md lean while making information discoverable without hogging the context window. Keep only essential procedural instructions and workflow guidance in SKILL.md; move detailed reference material, schemas, and examples to references files.
**Important**: Most skills don't need all three. Choose based on actual needs.
##### Assets (`assets/`)
Files not intended to be loaded into context, but rather used within the output Claude produces.
- **When to include**: When the skill needs files that will be used in the final output
- **Examples**: `assets/logo.png` for brand assets, `assets/slides.pptx` for PowerPoint templates, `assets/frontend-template/` for HTML/React boilerplate, `assets/font.ttf` for typography
- **Use cases**: Templates, images, icons, boilerplate code, fonts, sample documents that get copied or modified
- **Benefits**: Separates output resources from documentation, enables Claude to use files without loading them into context
#### What to Not Include in a Skill
A skill should only contain essential files that directly support its functionality. Do NOT create extraneous documentation or auxiliary files, including:
### What NOT to Include
Do NOT create auxiliary documentation:
- README.md
- INSTALLATION_GUIDE.md
- QUICK_REFERENCE.md
- CHANGELOG.md
- etc.
The skill should only contain the information needed for an AI agent to do the job at hand. It should not contain auxilary context about the process that went into creating it, setup and testing procedures, user-facing documentation, etc. Creating additional documentation files just adds clutter and confusion.
### Progressive Disclosure Design Principle
Skills use a three-level loading system to manage context efficiently:
1. **Metadata (name + description)** - Always in context (~100 words)
2. **SKILL.md body** - When skill triggers (<5k words)
3. **Bundled resources** - As needed by Claude (Unlimited because scripts can be executed without reading into context window)
#### Progressive Disclosure Patterns
Keep SKILL.md body to the essentials and under 500 lines to minimize context bloat. Split content into separate files when approaching this limit. When splitting out content into other files, it is very important to reference them from SKILL.md and describe clearly when to read them, to ensure the reader of the skill knows they exist and when to use them.
**Key principle:** When a skill supports multiple variations, frameworks, or options, keep only the core workflow and selection guidance in SKILL.md. Move variant-specific details (patterns, examples, configuration) into separate reference files.
**Pattern 1: High-level guide with references**
```markdown
# PDF Processing
## Quick start
Extract text with pdfplumber:
[code example]
## Advanced features
- **Form filling**: See [FORMS.md](FORMS.md) for complete guide
- **API reference**: See [REFERENCE.md](REFERENCE.md) for all methods
- **Examples**: See [EXAMPLES.md](EXAMPLES.md) for common patterns
```
Claude loads FORMS.md, REFERENCE.md, or EXAMPLES.md only when needed.
**Pattern 2: Domain-specific organization**
For Skills with multiple domains, organize content by domain to avoid loading irrelevant context:
```
bigquery-skill/
├── SKILL.md (overview and navigation)
└── reference/
├── finance.md (revenue, billing metrics)
├── sales.md (opportunities, pipeline)
├── product.md (API usage, features)
└── marketing.md (campaigns, attribution)
```
When a user asks about sales metrics, Claude only reads sales.md.
Similarly, for skills supporting multiple frameworks or variants, organize by variant:
```
cloud-deploy/
├── SKILL.md (workflow + provider selection)
└── references/
├── aws.md (AWS deployment patterns)
├── gcp.md (GCP deployment patterns)
└── azure.md (Azure deployment patterns)
```
When the user chooses AWS, Claude only reads aws.md.
**Pattern 3: Conditional details**
Show basic content, link to advanced content:
```markdown
# DOCX Processing
## Creating documents
Use docx-js for new documents. See [DOCX-JS.md](DOCX-JS.md).
## Editing documents
For simple edits, modify the XML directly.
**For tracked changes**: See [REDLINING.md](REDLINING.md)
**For OOXML details**: See [OOXML.md](OOXML.md)
```
Claude reads REDLINING.md or OOXML.md only when the user needs those features.
**Important guidelines:**
- **Avoid deeply nested references** - Keep references one level deep from SKILL.md. All reference files should link directly from SKILL.md.
- **Structure longer reference files** - For files longer than 100 lines, include a table of contents at the top so Claude can see the full scope when previewing.
- Other non-essential files
## Skill Creation Process
Skill creation involves these steps:
**COW Simplified Version** - Skills are used locally, no packaging/sharing needed.
1. Understand the skill with concrete examples
2. Plan reusable skill contents (scripts, references, assets)
3. Initialize the skill (use bash tool to run init_skill.py script)
4. Edit the skill (use write/edit tools to implement SKILL.md and resources)
5. Validate the skill (use bash tool to run quick_validate.py script)
6. Package the skill (use bash tool to run package_skill.py script)
7. Iterate based on real usage
1. **Understand** - Clarify use cases with concrete examples
2. **Plan** - Identify needed scripts, references, assets
3. **Initialize** - Run init_skill.py to create template
4. **Edit** - Implement SKILL.md and resources
5. **Validate** (optional) - Run quick_validate.py to check format
6. **Iterate** - Improve based on real usage
Follow these steps in order, skipping only if there is a clear reason why they are not applicable.
## Skill Naming
### Using Tools in This Skill
- Use lowercase letters, digits, and hyphens only; normalize user-provided titles to hyphen-case (e.g., "Plan Mode" -> `plan-mode`).
- When generating names, generate a name under 64 characters (letters, digits, hyphens).
- Prefer short, verb-led phrases that describe the action.
- Namespace by tool when it improves clarity or triggering (e.g., `gh-address-comments`, `linear-address-issue`).
- Name the skill folder exactly after the skill name.
This skill requires the following tools to be available:
- **bash** - To run Python scripts in skills/skill-creator/scripts/
- **read** - To read existing skill files
- **write** - To create new skill files
- **edit** - To modify skill files
- **ls** - To list files in skill directories
- **find** - To search for skill files
All scripts are located in: `skills/skill-creator/scripts/`
## Step-by-Step Guide
### Step 1: Understanding the Skill with Concrete Examples
@@ -266,60 +150,42 @@ Example: When building a `big-query` skill to handle queries like "How many user
To establish the skill's contents, analyze each concrete example to create a list of the reusable resources to include: scripts, references, and assets.
### Step 3: Initializing the Skill
### Step 3: Initialize the Skill
At this point, it is time to actually create the skill.
Skip this step only if the skill being developed already exists, and iteration or packaging is needed. In this case, continue to the next step.
Skip this step only if the skill being developed already exists, and iteration is needed. In this case, continue to the next step.
When creating a new skill from scratch, use the bash tool to run the `init_skill.py` script. The script conveniently generates a new template skill directory that automatically includes everything a skill requires, making the skill creation process much more efficient and reliable.
When creating a new skill from scratch, always run the `init_skill.py` script. The script conveniently generates a new template skill directory that automatically includes everything a skill requires, making the skill creation process much more efficient and reliable.
**Using bash tool to initialize a skill:**
Usage:
The skill should be created in the agent's workspace skills directory (configured as `agent_workspace` in config, default: `~/cow`).
Since the bash tool's working directory may be set to the workspace, you need to use the absolute path to the init_skill.py script. The script is located in the project's `skills/skill-creator/scripts/` directory.
**Option 1: Find and use the script (recommended):**
```bash
find ~ -name "init_skill.py" -path "*/skills/skill-creator/scripts/*" 2>/dev/null | head -1 | xargs -I {} python3 {} <skill-name> --path ~/cow/skills
scripts/init_skill.py <skill-name> --path <output-directory> [--resources scripts,references,assets] [--examples]
```
**Option 2: If you know the project path:**
```bash
python3 /path/to/project/skills/skill-creator/scripts/init_skill.py <skill-name> --path ~/cow/skills
```
Examples:
**Example:**
```bash
find ~ -name "init_skill.py" -path "*/skills/skill-creator/scripts/*" 2>/dev/null | head -1 | xargs -I {} python3 {} weather-api --path ~/cow/skills
scripts/init_skill.py my-skill --path ~/cow/skills
scripts/init_skill.py my-skill --path ~/cow/skills --resources scripts,references
scripts/init_skill.py my-skill --path ~/cow/skills --resources scripts --examples
```
**Note**: The path `~/cow/skills` is the default workspace skills directory. This ensures skills are created in the user's workspace, not the project directory.
The script:
- Creates the skill directory at the specified path (~/cow/skills/<skill-name>/ by default)
- Creates the skill directory at the specified path
- Generates a SKILL.md template with proper frontmatter and TODO placeholders
- Creates example resource directories: `scripts/`, `references/`, and `assets/`
- Adds example files in each directory that can be customized or deleted
- Optionally creates resource directories based on `--resources`
- Optionally adds example files when `--examples` is set
After initialization, use read/write/edit tools to customize the generated SKILL.md and example files as needed.
After initialization, customize the SKILL.md and add resources as needed. If you used `--examples`, replace or delete placeholder files.
**Important**: Always create skills in the workspace directory (`~/cow/skills`), not in the project directory. This keeps user-created skills separate from bundled skills.
**CRITICAL - User Communication**: After successfully creating a skill, you MUST inform the user with a clear, friendly confirmation message that includes:
1. ✅ Confirmation that the skill was created successfully
2. 📍 The skill name (e.g., "weather-api")
3. 📂 Where it was saved (e.g., "~/cow/skills/weather-api")
4. 🚀 That the skill is now immediately available for use in the next conversation (no restart needed thanks to auto-reload!)
5. 📝 Next steps: The user should edit the SKILL.md to complete the TODO sections
Example response: "✅ Successfully created skill 'weather-api' at ~/cow/skills/weather-api! The skill is now immediately available for use. Next, you should edit the SKILL.md file to complete the description and add the actual implementation."
**Important**: Always create skills in workspace directory (`~/cow/skills`), NOT in project directory.
### Step 4: Edit the Skill
When editing the (newly-generated or existing) skill, remember that the skill is being created for another instance of Claude to use. Include information that would be beneficial and non-obvious to Claude. Consider what procedural knowledge, domain-specific details, or reusable assets would help another Claude instance execute these tasks more effectively.
When editing the (newly-generated or existing) skill, remember that the skill is being created for another instance of the agent to use. Include information that would be beneficial and non-obvious to the agent. Consider what procedural knowledge, domain-specific details, or reusable assets would help another agent instance execute these tasks more effectively.
#### Learn Proven Design Patterns
@@ -336,7 +202,7 @@ To begin implementation, start with the reusable resources identified above: `sc
Added scripts must be tested by actually running them to ensure there are no bugs and that the output matches what is expected. If there are many similar scripts, only a representative sample needs to be tested to ensure confidence that they all work while balancing time to completion.
Any example files and directories not needed for the skill should be deleted. The initialization script creates example files in `scripts/`, `references/`, and `assets/` to demonstrate structure, but most skills won't need all of them.
If you used `--examples`, delete any placeholder files that are not needed for the skill. Only create resource directories that are actually required.
#### Update SKILL.md
@@ -347,10 +213,10 @@ Any example files and directories not needed for the skill should be deleted. Th
Write the YAML frontmatter with `name` and `description`:
- `name`: The skill name
- `description`: This is the primary triggering mechanism for your skill, and helps Claude understand when to use the skill.
- `description`: This is the primary triggering mechanism for your skill, and helps the agent understand when to use the skill.
- Include both what the Skill does and specific triggers/contexts for when to use it.
- Include all "when to use" information here - Not in the body. The body is only loaded after triggering, so "When to Use This Skill" sections in the body are not helpful to Claude.
- Example description for a `docx` skill: "Comprehensive document creation, editing, and analysis with support for tracked changes, comments, formatting preservation, and text extraction. Use when Claude needs to work with professional documents (.docx files) for: (1) Creating new documents, (2) Modifying or editing content, (3) Working with tracked changes, (4) Adding comments, or any other document tasks"
- Include all "when to use" information here - Not in the body. The body is only loaded after triggering, so "When to Use This Skill" sections in the body are not helpful to the agent.
- Example description for a `docx` skill: "Comprehensive document creation, editing, and analysis with support for tracked changes, comments, formatting preservation, and text extraction. Use when the agent needs to work with professional documents (.docx files) for: (1) Creating new documents, (2) Modifying or editing content, (3) Working with tracked changes, (4) Adding comments, or any other document tasks"
Do not include any other fields in YAML frontmatter.
@@ -358,58 +224,63 @@ Do not include any other fields in YAML frontmatter.
Write instructions for using the skill and its bundled resources.
### Step 5: Validating a Skill
### Step 5: Validate (Optional)
Before packaging, validate the skill to ensure it meets all requirements.
**Using bash tool to validate a skill:**
Validate skill format:
```bash
find ~ -name "quick_validate.py" -path "*/skills/skill-creator/scripts/*" 2>/dev/null | head -1 | xargs -I {} python3 {} ~/cow/skills/<skill-name>
scripts/quick_validate.py <path/to/skill-folder>
```
**Example:**
Example:
```bash
find ~ -name "quick_validate.py" -path "*/skills/skill-creator/scripts/*" 2>/dev/null | head -1 | xargs -I {} python3 {} ~/cow/skills/weather-api
scripts/quick_validate.py ~/cow/skills/weather-api
```
The validation checks:
- YAML frontmatter format and required fields (name, description)
Validation checks:
- YAML frontmatter format and required fields
- Skill naming conventions (hyphen-case, lowercase)
- Description completeness and quality
- File organization
If validation fails, use the edit tool to fix the errors in SKILL.md, then validate again.
**Note**: Validation is optional in COW. Mainly useful for troubleshooting format issues.
### Step 6: Packaging a Skill
### Step 6: Iterate
Once development of the skill is complete and validated, package it into a distributable .skill file.
Improve based on real usage:
**Using bash tool to package a skill:**
```bash
find ~ -name "package_skill.py" -path "*/skills/skill-creator/scripts/*" 2>/dev/null | head -1 | xargs -I {} python3 {} ~/cow/skills/<skill-name>
```
**Example:**
```bash
find ~ -name "package_skill.py" -path "*/skills/skill-creator/scripts/*" 2>/dev/null | head -1 | xargs -I {} python3 {} ~/cow/skills/weather-api
```
The packaging script will:
1. **Validate** the skill automatically (same as Step 5)
2. **Package** the skill if validation passes, creating a .skill file (e.g., `weather-api.skill`) that includes all files. The .skill file is a zip file with a .skill extension.
If validation fails, the script will report the errors and exit without creating a package. Fix any validation errors and run the packaging command again.
### Step 7: Iterate
After testing the skill, users may request improvements. Often this happens right after using the skill, with fresh context of how the skill performed.
**Iteration workflow:**
1. Use the skill on real tasks
1. Use skill on real tasks
2. Notice struggles or inefficiencies
3. Identify how SKILL.md or bundled resources should be updated
3. Identify needed updates to SKILL.md or resources
4. Implement changes and test again
## Progressive Disclosure
Skills use three-level loading:
1. **Metadata** (name + description) - Always in context (~100 words)
2. **SKILL.md body** - Loaded when skill triggers (<5k words)
3. **Resources** - Loaded as needed by agent
**Best practices**:
- Keep SKILL.md under 500 lines
- Split complex content into `references/` files
- Reference these files clearly in SKILL.md
**Pattern**: For skills with multiple variants/frameworks:
- Keep core workflow in SKILL.md
- Move variant-specific details to separate reference files
- Agent loads only relevant files
Example:
```
cloud-deploy/
├── SKILL.md (workflow + provider selection)
└── references/
├── aws.md
├── gcp.md
└── azure.md
```
When user chooses AWS, agent only reads aws.md.

View File

@@ -1,228 +0,0 @@
# Skill Creator 使用指南(修订版)
## 🎯 什么是 skill-creator
**skill-creator 是一个 Skill技能而不是 Tool工具**
- 它教 Agent 如何使用现有工具bash, read, write, edit来创建新技能
- 它提供了完整的技能创建工作流指导
- Agent 会组合使用多个工具来完成技能创建任务
## 📚 Skills vs Tools
| 类型 | 说明 | 示例 |
|------|------|------|
| **Tool工具** | 底层能力,执行单一操作 | bash, read, write, calculator |
| **Skill技能** | 工作流指导,组合多个工具 | skill-creator, code-reviewer |
## 🚀 如何使用
### 触发条件
当用户提到以下关键词时skill-creator 技能会被触发:
- "创建技能"
- "新建 skill"
- "创建一个新技能"
- "initialize a skill"
### 完整示例
```
用户: "创建一个新技能叫 weather-api"
Agent 执行流程:
1. 加载 skill-creator 技能
2. 阅读 SKILL.md 了解工作流
3. 使用 bash 工具:
cd skills/skill-creator && python3 scripts/init_skill.py weather-api --path ../../workspace/skills
4. 报告成功 ✅
用户: "完善这个技能,用于调用天气 API 获取天气数据"
Agent 执行流程:
1. 使用 read 工具读取 workspace/skills/weather-api/SKILL.md
2. 使用 edit 工具修改 description 和内容
3. 报告完成 ✅
用户: "验证这个技能"
Agent 执行流程:
1. 使用 bash 工具:
cd skills/skill-creator && python3 scripts/quick_validate.py ../../workspace/skills/weather-api
2. 报告验证结果 ✅
用户: "打包这个技能"
Agent 执行流程:
1. 使用 bash 工具:
cd skills/skill-creator && python3 scripts/package_skill.py ../../workspace/skills/weather-api
2. 生成 weather-api.skill 文件 ✅
```
## 🔄 工作流程
### 1. 创建技能模板
```
说法: "创建新技能 desktop-viewer"
Agent: 运行 init_skill.py 脚本
结果: workspace/skills/desktop-viewer/ 目录创建
```
### 2. 编辑技能内容
```
说法: "完善 SKILL.md 的描述"
Agent: 使用 write/edit 工具修改
结果: SKILL.md 更新
```
### 3. 添加资源文件(可选)
```
说法: "在 scripts 目录创建 xxx.py"
Agent: 使用 write 工具创建文件
结果: 脚本文件创建
```
### 4. 验证技能
```
说法: "验证 desktop-viewer 技能"
Agent: 运行 quick_validate.py 脚本
结果: 显示验证结果
```
### 5. 打包技能
```
说法: "打包 desktop-viewer 技能"
Agent: 运行 package_skill.py 脚本
结果: desktop-viewer.skill 文件生成
```
## ✅ 推荐的提问方式
### 创建技能
✅ "创建一个新技能叫 XXX"
✅ "初始化技能 XXX"
✅ "新建 skill: XXX"
### 编辑技能
✅ "完善 XXX 技能的描述"
✅ "在 XXX 技能的 scripts 目录创建文件"
✅ "修改 XXX 技能的 SKILL.md"
### 验证技能
✅ "验证 XXX 技能"
✅ "检查 XXX 技能的格式"
### 打包技能
✅ "打包 XXX 技能"
✅ "导出 XXX skill"
## ❌ 避免的说法
❌ "帮我写一个查看桌面文件的功能"
- 问题太具体Agent 会直接写代码而不是创建技能
❌ "做一个脚本来..."
- 问题Agent 会直接写脚本而不是创建技能
**正确方式**
1. 先说:"创建技能 desktop-viewer"
2. 再说:"这个技能用于查看桌面文件"
## 🔍 如何确认技能已加载?
查看 Agent 启动日志:
```
[INFO] Loaded X skills from all sources
[INFO] SkillManager: Loaded X skills
```
或者直接问:
```
"列出所有已加载的 skills"
```
## 📂 技能存放位置
- **创建的新技能**: `workspace/skills/<skill-name>/`
- **skill-creator 本身**: `skills/skill-creator/`
- **打包后的文件**: 项目根目录下的 `<skill-name>.skill`
## 💡 实用技巧
### 1. 分步操作
不要一次性说太多,分步骤进行:
```
步骤 1: "创建技能 pdf-processor"
步骤 2: "添加描述:用于处理 PDF 文件"
步骤 3: "创建脚本 extract_text.py"
步骤 4: "验证技能"
步骤 5: "打包技能"
```
### 2. 明确技能名称
使用 hyphen-case 格式:
✅ weather-api
✅ pdf-processor
✅ file-manager
❌ weather api有空格
❌ WeatherAPI驼峰
❌ weather_api下划线
### 3. 查看创建的文件
```
"列出 workspace/skills/XXX 目录的内容"
"读取 workspace/skills/XXX/SKILL.md"
```
## 🛠️ 直接运行脚本(备选)
如果需要直接运行脚本:
```bash
# 创建技能
cd skills/skill-creator
python3 scripts/init_skill.py my-skill --path ../../workspace/skills
# 验证技能
python3 scripts/quick_validate.py ../../workspace/skills/my-skill
# 打包技能
python3 scripts/package_skill.py ../../workspace/skills/my-skill
```
## 📖 技能开发流程
```
1. 规划 → 确定技能功能
2. 创建 → 使用 init_skill.py 生成模板
3. 编辑 → 完善 SKILL.md 和资源文件
4. 验证 → 使用 quick_validate.py 检查格式
5. 测试 → 在 Agent 中加载并测试
6. 打包 → 使用 package_skill.py 生成 .skill 文件
7. 分享 → 将 .skill 文件分享给其他用户
```
## ❓ 常见问题
### Q: Agent 没有使用 skill-creator
**A**:
1. 确认技能已加载(查看日志)
2. 使用明确的触发词:"创建技能 XXX"
3. 不要在一句话中混入太多其他信息
### Q: 技能创建在哪里?
**A**: `workspace/skills/<技能名>/`
### Q: .skill 文件是什么?
**A**: 是 zip 格式的压缩包,包含技能的所有文件,可以分享和安装
### Q: 如何安装别人的 .skill 文件?
**A**: 解压到 `workspace/skills/` 目录
### Q: skill-creator 本身也是技能吗?
**A**: 是的!它是一个教 Agent 如何创建其他技能的技能
---
**记住**: skill-creator 是一个 **Skill指导方案**,而不是 **Tool工具**