package skills import ( "os" "path/filepath" "time" ) var builtinSkills = []Skill{ { Name: "env-setup", Description: "Set up a complete development environment for any language. Detects missing tools, installs them, and configures the project.", Author: "muyue", Version: "1.0.0", Target: "both", Tags: []string{"setup", "environment", "install"}, Content: `# Environment Setup Use this skill when setting up a new development environment or project. ## Steps 1. Detect the project type by checking for config files: - ` + "`go.mod`" + ` → Go - ` + "`package.json`" + ` → Node.js - ` + "`requirements.txt` / `pyproject.toml` / `setup.py`" + ` → Python - ` + "`Cargo.toml`" + ` → Rust - ` + "`pom.xml` / `build.gradle`" + ` → Java 2. Check if required tools are installed: - Language runtime (go, node, python, etc.) - Package manager (npm, pip, cargo, etc.) - Linter/formatter - Test runner 3. If tools are missing, install them using the system package manager: - Linux: apt/dnf/pacman - macOS: brew - Windows: winget/scoop 4. Install project dependencies: - ` + "`go mod download`" + ` for Go - ` + "`npm install`" + ` / ` + "`pnpm install`" + ` for Node.js - ` + "`pip install -r requirements.txt`" + ` / ` + "`uv sync`" + ` for Python - ` + "`cargo build`" + ` for Rust 5. Configure git hooks if ` + "`pre-commit`" + ` config exists. 6. Verify the setup by running tests or build. ## Error Handling - If a tool cannot be installed automatically, provide the manual install command. - If dependency installation fails, check for version conflicts and suggest fixes. - Always check for lock files first to ensure reproducible installs.`, }, { Name: "git-workflow", Description: "Manage git branches, commits, and pull requests following best practices. Handles branching strategy, conventional commits, and PR creation.", Author: "muyue", Version: "1.0.0", Target: "both", Tags: []string{"git", "workflow", "branching", "commits"}, Content: `# Git Workflow Use this skill when the user needs to create branches, make commits, or manage pull requests. ## Branch Naming Convention - ` + "`feature/-`" + ` for new features - ` + "`fix/-`" + ` for bug fixes - ` + "`refactor/`" + ` for refactoring - ` + "`docs/`" + ` for documentation ## Commit Messages Follow Conventional Commits: - ` + "`feat: add user authentication`" + ` - ` + "`fix: resolve null pointer in login`" + ` - ` + "`refactor: extract validation logic`" + ` - ` + "`docs: update API documentation`" + ` - ` + "`test: add integration tests for auth`" + ` - ` + "`chore: update dependencies`" + ` ## Workflow 1. Before starting, pull latest changes: ` + "`git pull --rebase origin main`" + ` 2. Create branch: ` + "`git checkout -b feature/my-feature`" + ` 3. Make changes and commit frequently with meaningful messages 4. Before pushing, rebase: ` + "`git rebase origin/main`" + ` 5. Push: ` + "`git push -u origin feature/my-feature`" + ` 6. Create PR with description following template ## PR Description Template ` + "```" + ` ## Summary <1-3 bullet points> ## Changes - ## Test Plan - [ ] ` + "```" + ` ## Error Handling - If rebase has conflicts, help resolve them file by file - If push is rejected, pull with rebase first - Never force push to main/master`, }, { Name: "api-design", Description: "Design and implement REST or GraphQL APIs following best practices. Includes endpoint design, error handling, and documentation.", Author: "muyue", Version: "1.0.0", Target: "both", Tags: []string{"api", "rest", "graphql", "design"}, Content: `# API Design Use this skill when designing or implementing an API. ## REST API Design Rules 1. Use nouns for resources, not verbs: ` + "`/users`" + ` not ` + "`/getUsers`" + ` 2. Use plural nouns: ` + "`/users`" + ` not ` + "`/user`" + ` 3. Use proper HTTP methods: - GET for reading - POST for creating - PUT/PATCH for updating - DELETE for removing 4. Use query parameters for filtering: ` + "`/users?role=admin&active=true`" + ` 5. Use pagination: ` + "`/users?page=1&limit=20`" + ` 6. Return proper status codes: - 200: Success - 201: Created - 204: No Content (successful delete) - 400: Bad Request - 401: Unauthorized - 403: Forbidden - 404: Not Found - 422: Validation Error - 500: Internal Server Error ## Error Response Format ` + "```" + `json { "error": { "code": "VALIDATION_ERROR", "message": "Human readable message", "details": [ {"field": "email", "message": "Invalid email format"} ] } } ` + "```" + ` ## Implementation Steps 1. Define the API spec (endpoints, request/response schemas) 2. Implement data models 3. Add validation middleware 4. Implement handlers 5. Add error handling 6. Write tests 7. Generate documentation (OpenAPI/Swagger)`, }, { Name: "debug-assist", Description: "Systematic debugging assistant. Helps identify, isolate, and fix bugs using a structured approach.", Author: "muyue", Version: "1.0.0", Target: "both", Tags: []string{"debug", "troubleshooting", "bugs"}, Content: `# Debug Assist Use this skill when the user reports a bug or asks for help debugging. ## Debugging Process 1. **Reproduce** — Understand the exact steps to reproduce 2. **Isolate** — Narrow down the scope: - Is it frontend or backend? - Does it happen consistently or intermittently? - Does it happen in all environments or just one? 3. **Hypothesize** — Form a hypothesis about the root cause 4. **Verify** — Add logging or breakpoints to confirm 5. **Fix** — Make the minimal change to fix the issue 6. **Test** — Verify the fix works and doesn't break other things 7. **Prevent** — Add a test to prevent regression ## Common Patterns - **Null/Nil errors**: Check for missing initialization or unexpected nil values - **Type errors**: Check API contracts and type assertions - **Race conditions**: Look for shared mutable state without synchronization - **Memory leaks**: Check for unclosed resources (connections, files, channels) - **Off-by-one**: Check loop bounds and array indexing - **State issues**: Check if state is properly reset between operations ## Debugging Commands - Check logs: Look for error messages and stack traces - Check recent changes: ` + "`git diff HEAD~5`" + ` to see what changed - Check dependencies: Verify versions match expected - Check environment: Compare config between working and broken environments`, }, { Name: "code-review", Description: "Perform a thorough code review. Checks for bugs, security issues, performance problems, and style consistency.", Author: "muyue", Version: "1.0.0", Target: "both", Tags: []string{"review", "quality", "security"}, Content: `# Code Review Use this skill when reviewing code changes or pull requests. ## Review Checklist ### Correctness - Does the code do what it's supposed to? - Are edge cases handled? - Are there off-by-one errors? - Are error paths handled? ### Security - Is user input sanitized? - Are there SQL injection risks? - Are secrets hardcoded? - Are authentication/authorization checks in place? - Is sensitive data logged? ### Performance - Are there N+1 queries? - Are there unnecessary loops or computations? - Is caching used where appropriate? - Are large allocations avoided? ### Readability - Are names descriptive? - Is the code self-documenting? - Are complex parts commented? - Is the code modular? ### Testing - Are there unit tests? - Are edge cases tested? - Are error paths tested? - Are tests independent and deterministic? ## Review Format 1. Summary of changes 2. Issues found (critical → minor) 3. Suggestions for improvement 4. Positive observations ## Severity Levels - **Critical**: Security vulnerabilities, data loss risks, crashes - **Major**: Bugs, performance issues, missing error handling - **Minor**: Style issues, naming, minor refactoring opportunities - **Suggestion**: Alternative approaches, improvements`, }, } func InstallBuiltinSkills() error { dir, err := SkillsDir() if err != nil { return err } for _, s := range builtinSkills { skillDir := filepath.Join(dir, s.Name) skillPath := filepath.Join(skillDir, "SKILL.md") if _, err := os.Stat(skillPath); err == nil { continue } s.CreatedAt = time.Now() s.UpdatedAt = time.Now() if err := os.MkdirAll(skillDir, 0755); err != nil { return err } content := renderSkill(&s) if err := os.WriteFile(skillPath, []byte(content), 0644); err != nil { return err } } return nil }