From 6153911e460bc59208e464956f4ef8ff997e4685 Mon Sep 17 00:00:00 2001 From: voson Date: Fri, 23 Jan 2026 10:41:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(opencode):=20=E9=87=8D=E6=96=B0=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=20OpenCode=20=E6=8A=80=E8=83=BD=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=B9=B6=E6=B7=BB=E5=8A=A0=20Cursor=20?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 恢复完整的技能创建指南文档 - 新增技能同步到 Cursor IDE 功能 - 更新 SKILL.md 支持技能同步触发短语 --- skill/opencode/SKILL.md | 158 ++++++++++++++++++ skill/opencode/command-creation.md | 201 +++++++++++++++++++++++ skill/opencode/skill-creation.md | 251 +++++++++++++++++++++++++++++ skill/opencode/sync-to-cursor.md | 242 +++++++++++++++++++++++++++ 4 files changed, 852 insertions(+) create mode 100644 skill/opencode/SKILL.md create mode 100644 skill/opencode/command-creation.md create mode 100644 skill/opencode/skill-creation.md create mode 100644 skill/opencode/sync-to-cursor.md diff --git a/skill/opencode/SKILL.md b/skill/opencode/SKILL.md new file mode 100644 index 0000000..726fd1f --- /dev/null +++ b/skill/opencode/SKILL.md @@ -0,0 +1,158 @@ +--- +name: opencode +description: Create and manage OpenCode commands and skills with templates and best practices. Includes skill synchronization to Cursor IDE. Use this skill when users ask to create commands, skills, or sync to Cursor. +--- + +# OpenCode Command and Skill Management + +You are an expert in OpenCode configuration and extension development. This skill serves as the entry point for creating and managing OpenCode commands and skills. + +**Trigger Phrases**: When users mention any of the following, automatically use this skill: +- "创建command", "创建命令", "make command", "create command" +- "创建skill", "创建技能", "make skill", "create skill" +- "添加command", "添加命令", "add command" +- "添加skill", "添加技能", "add skill" +- "opcode command", "opencode skill" +- "同步技能", "sync skills", "sync to cursor", "同步到cursor" +- "技能同步", "skill sync", "同步opencode技能" + +## Overview + +OpenCode extensions are organized into two main types: +- **Commands**: User-invoked prompts for repetitive tasks, defined in `command/` directory +- **Skills**: Reusable behavior definitions for agents, defined in `skill//SKILL.md` + +## Detailed Guides + +This skill folder contains comprehensive guides for command and skill creation: + +### Command Creation +For detailed command creation guidelines, refer to: +- `skill/opencode/command-creation.md` - Complete guide to creating OpenCode commands +- Includes: file structure, templates, best practices, troubleshooting + +### Skill Creation +For detailed skill creation guidelines, refer to: +- `skill/opencode/skill-creation.md` - Complete guide to creating OpenCode skills +- Includes: directory structure, naming rules, templates, testing + +### Skill Synchronization (OpenCode → Cursor) +For syncing OpenCode skills to Cursor IDE, refer to: +- `skill/opencode/sync-to-cursor.md` - Guide to synchronize OpenCode skills to Cursor IDE +- Includes: sync strategies, operation steps, error handling, best practices + +## Quick Start + +### To Create a Command +1. Determine command name (kebab-case, descriptive) +2. **Default location**: global (`~/.config/opencode/command/`) +3. Create file: `.md` +4. Add frontmatter with `description` +5. Write template with `$ARGUMENTS` support + +### To Create a Skill +1. Validate skill name (lowercase, hyphens, alphanumeric) +2. **Default location**: global (`~/.config/opencode/skill//`) +3. Create directory: `skill//` +4. Create `SKILL.md` with required frontmatter +5. Add structured content: Purpose, Usage, Examples, Troubleshooting + +## Automatic Name Generation + +When users request command or skill creation, names are automatically generated based on the description to provide a seamless experience. + +### For Commands: +1. **Keyword Extraction**: Identify action verbs and target nouns from the description +2. **English Conversion**: Convert Chinese keywords to English equivalents (e.g., "创建" → "create", "总结" → "summarize") +3. **Kebab-case Format**: Combine words with hyphens, all lowercase (e.g., "create-summary") +4. **Conflict Resolution**: Check if name exists in `command/` directory, append numeric suffix if needed + +### For Skills: +1. **Function Extraction**: Identify core functionality from the description +2. **Simplified Naming**: Use lowercase, hyphen-separated words describing the skill's purpose +3. **Validation**: Ensure name follows `[a-z0-9-]+` pattern +4. **Conflict Check**: Verify uniqueness in `skill/` directory + +### Examples: +- "创建command,用于归纳总结当前对话中有价值的内容" → `summarize-conversation` +- "创建skill,用于管理git工作流" → `git-workflow` +- "添加命令来处理图片压缩" → `compress-images` +- "创建技能用于代码审查" → `code-review` + +### User Override: +If users explicitly provide a name in their request, use the provided name instead of auto-generation. + +## Response Guide for Creation Requests + +When users ask to create commands or skills, follow this structured approach: + +### For "创建command" or "创建命令" requests: +1. **自动生成名称**: 基于用户描述自动生成 kebab-case 命令名称 + - 从描述中提取关键词(动词+名词) + - 转换为英文 kebab-case 格式 + - 如果名称已存在,添加数字后缀(如 `-2`, `-3`) +2. **验证名称**: 确保名称符合 kebab-case 规范 +3. **默认位置**: 全局 (`~/.config/opencode/command/`) +4. **创建模板**: + - 生成包含 `description` 的 frontmatter + - 创建支持 `$ARGUMENTS` 的模板 + - 包含使用示例 +5. **写入文件**: 在默认位置创建命令文件 +6. **测试**: 验证文件存在且格式正确 + +### For "创建skill" or "创建技能" requests: +1. **自动生成名称**: 基于用户描述自动生成 skill 名称 + - 从描述中提取核心功能关键词 + - 转换为小写字母、连字符格式 + - 如果名称已存在,添加数字后缀 +2. **验证名称**: 确保名称符合命名规则(小写字母、连字符、字母数字) +3. **默认位置**: 全局 (`~/.config/opencode/skill//`) +4. **创建目录**: `skill//` +5. **创建 SKILL.md**: + - 包含 `name` 和 `description` 的 frontmatter + - 结构化内容:Purpose, Usage, Examples, Best Practices, Troubleshooting +6. **写入文件**: 在默认位置创建完整的 SKILL.md 文件 +7. **测试**: 验证技能可正常加载 `skill({ name: "" })` + +### Sample Response Format: +``` +我将帮你创建 [command/skill]。 + +基于您的描述,自动生成名称:[generated-name] + +**自动命名规则**: +- 从描述中提取关键词(动词+名词) +- 转换为 kebab-case 格式(小写字母、连字符) +- 检查名称冲突,自动添加数字后缀 + +**文件详情**: +- 名称: [generated-name] +- 用途: [brief-description] +- 位置: 全局 (~/.config/opencode/[command|skill]/) + +已创建 [file-path]: + +```markdown +[complete file content] +``` + +要测试,请运行:[/command-name] 或 skill({ name: "skill-name" }) +``` + +## Resources + +- [OpenCode Skills Documentation](https://opencode.ai/docs/skills) +- [OpenCode Commands Documentation](https://opencode.ai/docs/commands) +- [OpenCode Configuration Guide](https://opencode.ai/docs/config) +- [GitHub Repository](https://github.com/anomalyco/opencode) + +## Updates and Maintenance + +1. **Regular Review**: Periodically review and update commands/skills +2. **Version Tracking**: Use Git to track changes +3. **Community Sharing**: Share useful commands/skills with community +4. **Feedback Integration**: Incorporate user feedback for improvements + +--- + +*Last updated: 2026-01-15* diff --git a/skill/opencode/command-creation.md b/skill/opencode/command-creation.md new file mode 100644 index 0000000..9148407 --- /dev/null +++ b/skill/opencode/command-creation.md @@ -0,0 +1,201 @@ +# Command Creation Guide + +## Overview +OpenCode commands are user-invoked prompts for repetitive tasks, defined in the `command/` directory. + +## File Location +- **Default location (Global)**: `~/.config/opencode/command/.md` +- **Project-specific**: `.opencode/command/.md` (when needed) + +## Command Structure +Each command file must contain YAML frontmatter followed by the prompt template. + +### Required Frontmatter Fields +- `description`: Brief description shown in TUI (1-2 sentences) + +### Optional Frontmatter Fields +- `agent`: Specific agent to execute this command +- `model`: Override default model +- `subtask`: Boolean to force subagent invocation + +## Template Features +The command template supports several placeholders: + +- `$ARGUMENTS`: All arguments passed to the command +- `$1`, `$2`, `$3`: Individual positional arguments +- `!``command``: Execute bash command and inject output +- `@filename`: Include file content in prompt + +## Example Command +Create `~/.config/opencode/command/new-skill.md`: + +```markdown +--- +description: Create a new OpenCode skill with proper structure +--- + +Create a new OpenCode skill named "$ARGUMENTS" with comprehensive documentation. + +**Skill Requirements:** +1. Directory: `skill/$ARGUMENTS/SKILL.md` +2. Frontmatter with `name` and `description` +3. Clear sections for usage, examples, best practices +4. Follow naming conventions: lowercase, hyphens, alphanumeric + +**Steps:** +1. Create directory structure +2. Write SKILL.md with frontmatter +3. Include practical examples +4. Add troubleshooting section + +Output the complete SKILL.md content for review. +``` + +## Best Practices + +### Command Design +1. **Clear Purpose**: Each command should have a single, focused purpose +2. **Descriptive Names**: Use verbs that describe the action (e.g., `create-`, `review-`, `analyze-`) +3. **Argument Handling**: Use `$ARGUMENTS` or `$1`, `$2` for flexible input +4. **Error Handling**: Include validation in prompts +5. **Output Format**: Structure responses for easy parsing + +### Naming Conventions +- Use kebab-case (lowercase with hyphens) +- Start with verb describing the action +- Keep names concise but descriptive + +## Quick Reference + +### Command Creation Checklist +- [ ] File name matches command name (kebab-case) +- [ ] Frontmatter includes `description` +- [ ] Template uses appropriate placeholders +- [ ] Includes examples of usage +- [ ] Tested with `/command-name` invocation + +### Common Patterns + +**Create a new command:** +```bash +# Create command file +touch ~/.config/opencode/command/my-command.md + +# Edit with template +cat > ~/.config/opencode/command/my-command.md << 'EOF' +--- +description: Description of my command +--- + +Command template with $ARGUMENTS support. + +Example: /my-command argument1 argument2 +EOF +``` + +## Testing and Validation + +### Test Command Loading +```bash +# Check if command appears in TUI +# Type "/" in OpenCode TUI and search for your command +``` + +### Verify Syntax +```bash +# Check YAML frontmatter +head -20 command/my-command.md +``` + +## Troubleshooting + +### Command Not Appearing +1. **Check file location**: Ensure command is in correct `command/` directory +2. **Verify frontmatter**: Must have `description` field +3. **Check permissions**: No restrictive permissions blocking command +4. **Restart OpenCode**: Some changes require restart + +### Common Errors +- **"Command not found"**: File not in correct location or missing `.md` extension +- **"Invalid frontmatter"**: Missing required fields or YAML syntax error + +## Integration with OpenCode Config + +### Permissions Configuration +Add to `opencode.json`: +```json +{ + "permission": { + "skill": { + "*": "allow", + "experimental-*": "ask", + "internal-*": "deny" + } + } +} +``` + +### Agent-Specific Settings +```json +{ + "agent": { + "plan": { + "permission": { + "skill": { + "analysis-*": "allow" + } + } + } + } +} +``` + +## Response Guide for Command Creation Requests + +When users ask to create commands, follow this structured approach: + +1. **自动生成名称**: 基于用户描述自动生成 kebab-case 命令名称 + - 从描述中提取关键词(动词+名词) + - 转换为英文 kebab-case 格式 + - 如果名称已存在,添加数字后缀(如 `-2`, `-3`) +2. **验证名称**: 确保名称符合 kebab-case 规范 +3. **默认位置**: 全局 (`~/.config/opencode/command/`) - commands are created here by default +4. **创建模板**: + - 生成包含 `description` 的 frontmatter + - 创建支持 `$ARGUMENTS` 的模板 + - 包含使用示例 +5. **写入文件**: 创建命令文件并写入内容 +6. **测试**: 验证文件存在且格式正确 + +### Sample Response Format: +``` +我将帮你创建命令。 + +基于您的描述,自动生成名称:[generated-name] + +**自动命名规则**: +- 从描述中提取关键词(动词+名词) +- 转换为 kebab-case 格式(小写字母、连字符) +- 检查名称冲突,自动添加数字后缀 + +**文件详情**: +- 名称: [generated-name] +- 用途: [brief-description] +- 位置: 全局 (~/.config/opencode/command/) + +已创建 [file-path]: + +```markdown +[complete file content] +``` + +要测试,请运行:[/command-name] +``` + +## Resources +- [OpenCode Commands Documentation](https://opencode.ai/docs/commands) +- [OpenCode Configuration Guide](https://opencode.ai/docs/config) + +--- + +*Last updated: 2026-01-15* \ No newline at end of file diff --git a/skill/opencode/skill-creation.md b/skill/opencode/skill-creation.md new file mode 100644 index 0000000..17ce5e9 --- /dev/null +++ b/skill/opencode/skill-creation.md @@ -0,0 +1,251 @@ +# Skill Creation Guide + +## Overview +OpenCode skills are reusable behavior definitions for agents, defined in `skill//SKILL.md` files. + +## Directory Structure +**Default location (Global):** +``` +~/.config/opencode/skill/ +└── / + └── SKILL.md +``` + +**Project-specific location (when needed):** +``` +.opencode/skill/ +└── / + └── SKILL.md +``` + +## Skill File Requirements + +### Frontmatter (Required) +- `name`: Skill name (must match directory name) +- `description`: Concise description (1-1024 characters) + +### Frontmatter (Optional) +- `license`: License identifier +- `compatibility`: Compatibility constraints +- `metadata`: Key-value pairs for additional context + +## Naming Rules +Skill names must: +- Be 1-64 characters +- Use lowercase alphanumeric with single hyphens +- Not start or end with hyphen +- Not contain consecutive hyphens +- Match regex: `^[a-z0-9]+(-[a-z0-9]+)*$` + +## Skill Content Structure +A well-structured skill should include: + +1. **Introduction**: Purpose and scope +2. **Usage Instructions**: When and how to use the skill +3. **Examples**: Practical implementation examples +4. **Best Practices**: Recommended approaches +5. **Troubleshooting**: Common issues and solutions +6. **References**: Related documentation + +## Example Skill Template +```markdown +--- +name: example-skill +description: Brief description of what this skill does +--- + +# Skill Title + +## Purpose +Explain what this skill helps achieve and when to use it. + +## Core Concepts +- Key principle 1 +- Key principle 2 + +## Usage +Step-by-step instructions for using this skill. + +## Examples +### Basic Example +```bash +# Example code or commands +``` + +### Advanced Example +Detailed example with explanation. + +## Best Practices +1. Recommended approach 1 +2. Recommended approach 2 + +## Troubleshooting +| Issue | Solution | +|-------|----------| +| Common problem | How to fix it | + +## References +- [Documentation link](https://opencode.ai/docs) +- Related skills or commands +``` + +## Best Practices + +### Skill Development +1. **Modular Design**: Keep skills focused on specific domains +2. **Comprehensive Documentation**: Include examples and edge cases +3. **Consistent Formatting**: Follow existing skill patterns +4. **Testing**: Verify skill loads correctly with `skill({ name: "skill-name" })` +5. **Version Control**: Track skill changes in Git + +### Organization +1. **Default location**: Global (`~/.config/opencode/skill/`) - skills are created here by default for reuse across projects +2. **Naming Conventions**: Use kebab-case for all skill names +3. **Documentation**: Maintain README or index of available skills +4. **Permissions**: Configure access controls in `opencode.json` + +## Quick Reference + +### Skill Creation Checklist +- [ ] Directory name matches skill name +- [ ] SKILL.md contains required frontmatter +- [ ] Description is 1-1024 characters +- [ ] Name follows naming rules +- [ ] Content includes usage and examples +- [ ] Skill loads without errors + +### Common Patterns + +**Create a new skill:** +```bash +# Create skill directory +mkdir -p ~/.config/opencode/skill/my-skill + +# Create SKILL.md +cat > ~/.config/opencode/skill/my-skill/SKILL.md << 'EOF' +--- +name: my-skill +description: Description of my skill +--- + +# My Skill + +## Usage +Instructions here. + +## Examples +Example content. +EOF +``` + +## Testing and Validation + +### Test Skill Loading +```bash +# In OpenCode session +skill({ name: "my-skill" }) +``` + +### Verify Syntax +```bash +# Check YAML frontmatter +head -20 skill/my-skill/SKILL.md + +# Validate naming +echo "skill-name" | grep -E '^[a-z0-9]+(-[a-z0-9]+)*$' +``` + +## Troubleshooting + +### Skill Not Loading +1. **Directory name**: Must match skill name in frontmatter +2. **File name**: Must be `SKILL.md` (all caps) +3. **Frontmatter**: Requires `name` and `description` +4. **Naming rules**: Verify name follows conventions +5. **Permissions**: Check `opencode.json` permissions + +### Common Errors +- **"Skill not found"**: Directory name mismatch or missing SKILL.md +- **"Invalid frontmatter"**: Missing required fields or YAML syntax error +- **"Permission denied"**: Skill blocked by permission configuration + +## Integration with OpenCode Config + +### Permissions Configuration +Add to `opencode.json`: +```json +{ + "permission": { + "skill": { + "*": "allow", + "experimental-*": "ask", + "internal-*": "deny" + } + } +} +``` + +### Agent-Specific Settings +```json +{ + "agent": { + "plan": { + "permission": { + "skill": { + "analysis-*": "allow" + } + } + } + } +} +``` + +## Response Guide for Skill Creation Requests + +When users ask to create skills, follow this structured approach: + +1. **自动生成名称**: 基于用户描述自动生成 skill 名称 + - 从描述中提取核心功能关键词 + - 转换为小写字母、连字符格式 + - 如果名称已存在,添加数字后缀 +2. **验证名称**: 确保名称符合命名规则(小写字母、连字符、字母数字) +3. **默认位置**: 全局 (`~/.config/opencode/skill//`) - skills are created here by default +4. **创建 SKILL.md**: + - 包含 `name` 和 `description` 的 frontmatter + - 结构化内容:Purpose, Usage, Examples, Best Practices, Troubleshooting +5. **写入文件**: 创建完整的 SKILL.md 文件 +6. **测试**: 验证技能可正常加载 `skill({ name: "" })` + +### Sample Response Format: +``` +我将帮你创建技能。 + +基于您的描述,自动生成名称:[generated-name] + +**自动命名规则**: +- 从描述中提取核心功能关键词 +- 转换为小写字母、连字符格式 +- 检查名称冲突,自动添加数字后缀 + +**文件详情**: +- 名称: [generated-name] +- 主要功能: [brief-description] +- 位置: 全局 (~/.config/opencode/skill/) + +已创建 [file-path]: + +```markdown +[complete file content] +``` + +要测试,请运行:skill({ name: "skill-name" }) +``` + +## Resources +- [OpenCode Skills Documentation](https://opencode.ai/docs/skills) +- [OpenCode Configuration Guide](https://opencode.ai/docs/config) +- [GitHub Repository](https://github.com/anomalyco/opencode) + +--- + +*Last updated: 2026-01-15* \ No newline at end of file diff --git a/skill/opencode/sync-to-cursor.md b/skill/opencode/sync-to-cursor.md new file mode 100644 index 0000000..ea003af --- /dev/null +++ b/skill/opencode/sync-to-cursor.md @@ -0,0 +1,242 @@ +# OpenCode 技能同步到 Cursor IDE 指南 + +将 OpenCode 技能同步到 Cursor IDE 的技能目录,实现配置一致和统一管理。 + +## 目的 + +- 保持 OpenCode 和 Cursor 的技能配置一致 +- 简化技能维护工作流 +- 支持一键同步操作 +- 提供错误处理和回滚机制 + +## 目录结构 + +### 源目录(OpenCode 技能) +``` +~/.config/opencode/skill/ +├── git/ +├── android/ +├── electron/ +└── ...其他技能 +``` + +### 目标目录(Cursor 技能) +``` +~/.cursor/skills/ +├── git/ +├── android/ +├── electron/ +└── ...其他技能 +``` + +**注意**:Cursor 目录中可能包含额外的技能(如 `opencode/`),同步时应保留这些额外技能不被删除。 + +## 同步策略 + +### 默认同步操作 +1. **覆盖更新**:用 OpenCode 版本覆盖 Cursor 中的同名技能 +2. **新增技能**:复制 OpenCode 中有但 Cursor 中没有的技能 +3. **保留额外**:保留 Cursor 中独有的技能(如 `opencode/`) +4. **不删除**:不同步删除操作,仅添加和更新 + +### 文件级同步 +- 递归复制整个技能目录 +- 保留文件权限和时间戳 +- 使用 `cp -Rf` 强制覆盖已存在的文件 + +## 操作步骤 + +### 1. 检查目录结构 +```bash +# 检查源目录 +ls -la ~/.config/opencode/skill/ + +# 检查目标目录 +ls -la ~/.cursor/skills/ 2>/dev/null || echo "目标目录不存在" +``` + +### 2. 同步技能 +```bash +# 确保目标目录存在 +mkdir -p ~/.cursor/skills/ + +# 同步所有技能(覆盖更新) +cp -Rf ~/.config/opencode/skill/* ~/.cursor/skills/ +``` + +### 3. 验证同步结果 +```bash +# 比较目录结构 +echo "源目录:" +ls ~/.config/opencode/skill/ +echo "目标目录:" +ls ~/.cursor/skills/ + +# 检查特定技能文件 +diff ~/.config/opencode/skill/git/SKILL.md ~/.cursor/skills/git/SKILL.md +``` + +### 4. 完整同步脚本 +```bash +#!/bin/bash + +# 配置路径 +SOURCE_DIR="$HOME/.config/opencode/skill" +TARGET_DIR="$HOME/.cursor/skills" + +echo "开始同步 OpenCode 技能到 Cursor..." +echo "源目录: $SOURCE_DIR" +echo "目标目录: $TARGET_DIR" + +# 检查源目录 +if [ ! -d "$SOURCE_DIR" ]; then + echo "错误: 源目录不存在 $SOURCE_DIR" + exit 1 +fi + +# 创建目标目录(如不存在) +mkdir -p "$TARGET_DIR" + +# 同步技能 +echo "正在同步技能..." +cp -Rf "$SOURCE_DIR"/* "$TARGET_DIR"/ + +# 验证结果 +echo "同步完成。验证结果:" +echo "已同步技能:" +ls "$SOURCE_DIR" +echo "" +echo "目标目录内容:" +ls "$TARGET_DIR" + +# 检查文件差异 +echo "" +echo "检查关键文件差异:" +for skill in $(ls "$SOURCE_DIR"); do + if [ -f "$SOURCE_DIR/$skill/SKILL.md" ] && [ -f "$TARGET_DIR/$skill/SKILL.md" ]; then + if ! diff -q "$SOURCE_DIR/$skill/SKILL.md" "$TARGET_DIR/$skill/SKILL.md" >/dev/null; then + echo " ⚠️ $skill/SKILL.md 存在差异" + else + echo " ✓ $skill/SKILL.md 一致" + fi + fi +done + +echo "同步完成!" +``` + +## 错误处理 + +### 常见问题 + +#### 1. 目标目录不存在 +```bash +# 检查并创建目录 +if [ ! -d ~/.cursor/skills ]; then + mkdir -p ~/.cursor/skills + echo "已创建目录: ~/.cursor/skills" +fi +``` + +#### 2. 权限不足 +```bash +# 检查权限 +ls -ld ~/.cursor +# 如果需要,调整权限(谨慎操作) +# chmod 755 ~/.cursor +``` + +#### 3. 磁盘空间不足 +```bash +# 检查可用空间 +df -h ~/.cursor +``` + +#### 4. 文件冲突 +```bash +# 备份现有文件后再同步 +BACKUP_DIR=~/.cursor/skills-backup-$(date +%Y%m%d) +cp -R ~/.cursor/skills "$BACKUP_DIR" +echo "已备份到: $BACKUP_DIR" +``` + +### 回滚操作 +```bash +# 从备份恢复 +BACKUP_DIR=~/.cursor/skills-backup-20250123 +if [ -d "$BACKUP_DIR" ]; then + rm -rf ~/.cursor/skills + cp -R "$BACKUP_DIR" ~/.cursor/skills + echo "已从备份恢复: $BACKUP_DIR" +fi +``` + +## 最佳实践 + +### 定期同步 +建议在以下时机同步技能: +- 添加新技能后 +- 更新现有技能后 +- 定期维护时(如每周一次) + +### 版本控制 +```bash +# 将 OpenCode 配置目录加入版本控制 +cd ~/.config/opencode +git status +git add skill/ +git commit -m "feat: 更新技能配置" +``` + +### 自动化脚本 +将同步脚本保存为 `~/.config/opencode/command/sync-skills.md` 作为 OpenCode 命令: + +```markdown +--- +description: 同步 OpenCode 技能到 Cursor IDE +--- +#!/bin/bash +# 同步脚本内容... +``` + +## 集成到 OpenCode Workflow + +### 作为技能使用 +在 OpenCode 技能中引用此文档: +```markdown +## 相关文档 +- [技能同步指南](./skill-sync.md) - 同步 OpenCode 技能到 Cursor +``` + +### 作为命令调用 +用户可直接请求:"同步技能到 Cursor" 或 "sync skills to cursor" + +### 触发时机 +- 用户修改技能配置后 +- 安装新技能后 +- 系统配置变更时 + +## 注意事项 + +1. **备份重要数据**:同步前建议备份 Cursor 技能目录 +2. **网络环境**:如果使用网络同步,确保连接稳定 +3. **兼容性**:确保技能格式与 Cursor 兼容 +4. **测试验证**:同步后测试关键技能是否正常工作 + +## 故障排除 + +| 问题 | 可能原因 | 解决方案 | +|------|----------|----------| +| 同步后技能不生效 | Cursor 缓存 | 重启 Cursor IDE | +| 文件权限错误 | 权限不足 | 检查目录权限 | +| 目标目录只读 | 系统限制 | 以管理员权限运行 | +| 部分技能缺失 | 同步中断 | 重新执行同步 | + +## 更新记录 + +- **2026-01-23**:创建初始版本 +- **功能**:基础同步、错误处理、最佳实践 + +--- + +*该文档是 OpenCode 技能管理的一部分,用于维护技能配置的一致性。* \ No newline at end of file