a dotfile but it's really big

skills: more skill builder guidance

karitham.dev 22ae174e 272f50f4

verified
+253 -78
+253 -78
modules/opencode/skills/skill-builder/SKILL.md
··· 1 1 --- 2 2 name: skill-builder 3 - description: Complete guide for creating new opencode skills and agents. Covers naming conventions, description requirements, directory structure for global and project-local skills, frontmatter formats with permission settings, content guidelines including line limits and RFC 2119 language, and a validation checklist. Use when building a new skill, creating a new agent, or setting up skill/agent directories. 3 + description: Guide for creating opencode skills and agents. Covers skill directory structure, SKILL.md frontmatter format, writing effective descriptions with trigger phrases, progressive disclosure across three loading levels, content patterns (templates, workflows, feedback loops), agent file format with permissions, testing strategies, and a validation checklist. Use when building a new skill, creating a new agent, or setting up skill/agent directories. 4 4 --- 5 5 6 - ## Naming Conventions 6 + # Skill & Agent Authoring 7 + 8 + You are creating a skill or agent for opencode. A skill is a folder containing a `SKILL.md` file. An agent is a standalone `.md` file. Both use YAML frontmatter + markdown body. 9 + 10 + ## 1. Skill Structure 11 + 12 + ``` 13 + <skill-name>/ 14 + ├── SKILL.md # required — the single entrypoint 15 + ├── scripts/ # optional — bundled scripts for validation, generation 16 + ├── references/ # optional — detailed docs, specs, examples 17 + └── assets/ # optional — templates, config files 18 + ``` 19 + 20 + - File MUST be named exactly `SKILL.md` (case-sensitive) 21 + - Folder MUST use kebab-case: lowercase, hyphens only, no spaces/capitals/underscores 22 + - MUST NOT include a README.md inside skill folders, because SKILL.md is the single entrypoint and a README creates ambiguity about which file is authoritative 23 + - Skills live at `~/.config/opencode/skills/<name>/` (global) or `.opencode/skills/<name>/` (project-local) 24 + 25 + ## 2. Frontmatter Reference 26 + 27 + ```yaml 28 + --- 29 + name: my-skill # required 30 + description: ... # required 31 + license: MIT # optional 32 + compatibility: ... # optional 33 + metadata: # optional 34 + author: jane 35 + version: "1.0" 36 + allowed-tools: Bash Read # optional, space-delimited 37 + --- 38 + ``` 39 + 40 + | Field | Constraints | 41 + |---|---| 42 + | `name` | 1-64 chars. Lowercase alphanumeric + hyphens. No leading/trailing/consecutive hyphens. MUST match folder name. | 43 + | `description` | 1-1024 chars. No XML angle brackets. See §3. | 44 + | `license` | Short license identifier (e.g., MIT, Apache-2.0). | 45 + | `compatibility` | 1-500 chars. Environment requirements (OS, runtime, tools). | 46 + | `metadata` | Key-value string map. | 47 + | `allowed-tools` | Space-delimited tool names pre-approved for this skill. | 48 + 49 + Security constraints: 50 + - MUST NOT use XML angle brackets (`<` `>`) in any frontmatter value, because frontmatter is injected into XML-structured system prompts and unescaped brackets break parsing 51 + - `name` MUST NOT contain "claude" or "anthropic" (reserved) 52 + 53 + ## 3. Writing Effective Descriptions 54 + 55 + The description is the most important part of a skill. It determines whether the agent loads the skill. Descriptions are injected into the system prompt as-is, so they MUST be written in third person. 56 + 57 + ### Structure 7 58 8 - ### Skills 59 + ``` 60 + [What it does] + [When to use it] + [Key capabilities/keywords] 61 + ``` 9 62 10 - - 1-64 characters 11 - - Lowercase alphanumeric with single hyphens only 12 - - NO leading or trailing hyphens 13 - - NO consecutive hyphens 14 - - MUST match the folder name 63 + Front-load the primary use case. Include trigger phrases — the words a user would actually say. 15 64 16 - ### Agents 65 + ### Good Examples 17 66 18 - - Filename determines agent name (e.g., `orchestrator.md` creates `orchestrator` agent) 19 - - MUST use `.md` extension 67 + ``` 68 + Systematic debugging protocol emphasizing empirical investigation over code 69 + reasoning. Covers the observe-hypothesize-experiment-narrow loop, establishing 70 + failure conditions, gathering evidence from logs and git history. Use when 71 + investigating crashes, test failures, unexpected behavior, or any situation 72 + where the system is not doing what it should. 73 + ``` 20 74 21 - ## Description Requirements 75 + ``` 76 + Guide for writing database migrations in PostgreSQL. Covers safe column 77 + additions, index creation with CONCURRENTLY, data backfills, and rollback 78 + strategies. Use when creating, modifying, or reviewing database migrations. 79 + Keywords: schema change, ALTER TABLE, CREATE INDEX. 80 + ``` 22 81 23 - MUST include: 82 + ``` 83 + Enforces clean coding conventions for any implementation task. Covers guard 84 + clauses, happy-path alignment, pure functions, error handling. Use when writing 85 + new code, refactoring, fixing bugs, or reviewing code for quality. 86 + ``` 87 + 88 + ### Bad Examples 89 + 90 + - `"Helps with projects"` — too vague, no trigger conditions, will never fire 91 + - `"A comprehensive tool for managing all aspects of deployment"` — no specifics, no keywords 92 + - `"Use this skill when needed"` — circular, gives the agent nothing to match against 93 + 94 + ### Preventing Mis-triggers 95 + 96 + SHOULD include negative triggers when the skill's domain overlaps with common tasks: 97 + 98 + ``` 99 + Do NOT use for simple one-off SQL queries — only for schema migrations. 100 + ``` 101 + 102 + ### Debugging Trigger Issues 103 + 104 + Ask the agent: _"When would you use the [skill name] skill?"_ If it cannot answer clearly, the description needs work. 105 + 106 + ## 4. Progressive Disclosure 107 + 108 + Skills load in three levels to minimize context cost: 109 + 110 + | Level | What loads | When | Budget | 111 + |---|---|---|---| 112 + | 1. Frontmatter | `name` + `description` | Always (system prompt) | ~100 tokens per skill | 113 + | 2. SKILL.md body | Core instructions | Agent triggers the skill | Keep under 500 lines | 114 + | 3. Linked files | references/, scripts/, assets/ | Agent reads explicitly | No cost until accessed | 115 + 116 + Practical guidance: 117 + 118 + - SKILL.md SHOULD contain only core instructions the agent needs on every invocation 119 + - Move detailed reference material (API specs, long examples, lookup tables) to `references/` and link to them from SKILL.md 120 + - Keep references one level deep from SKILL.md, because agents may partially read or skip deeply nested file trees 121 + - Reference files over 100 lines SHOULD include a table of contents at the top 122 + 123 + ## 5. Content Guidelines 124 + 125 + Default assumption: the agent is already competent. Only add context it does not already have. 126 + 127 + - Be specific and actionable. Not _"handle errors appropriately"_ but _"return errors with context using fmt.Errorf"_ 128 + - Use examples (input/output pairs) to show expected behavior 129 + - Use RFC 2119 keywords (MUST, SHOULD, MAY) for all constraints 130 + - Negative constraints (MUST NOT, SHOULD NOT) MUST include a reason explaining why 131 + - Use consistent terminology — pick one term and use it throughout 132 + - MUST NOT include time-sensitive information (version numbers, release dates), because skills are not updated on a schedule 133 + 134 + ### Degree of Freedom 135 + 136 + Match instruction specificity to task fragility: 137 + 138 + - **High freedom** (prose instructions): when multiple valid approaches exist. _"SHOULD use guard clauses for early returns."_ 139 + - **Low freedom** (exact commands/scripts): when operations are fragile or destructive. _"MUST run `pg_dump` before applying migration."_ 140 + 141 + For critical validations, prefer bundled scripts over prose instructions, because code is deterministic and prose is interpreted. 142 + 143 + ## 6. Content Patterns 144 + 145 + ### Template Pattern 146 + 147 + Provide output format templates. Mark required vs. optional sections. 148 + 149 + ```markdown 150 + ## Summary 151 + [required — 1-2 sentences] 152 + 153 + ## Details 154 + [optional — supporting context] 155 + ``` 156 + 157 + ### Workflow Pattern 158 + 159 + Sequential steps with validation gates. 160 + 161 + ``` 162 + 1. Run linter → MUST pass before proceeding 163 + 2. Run tests → fix failures, repeat step 1 164 + 3. Generate docs → review output 165 + ``` 24 166 25 - 1. WHAT the skill/agent does 26 - 2. WHEN to use it 27 - 3. Trigger phrases users would say 167 + ### Feedback Loop Pattern 28 168 29 - MUST NOT: 169 + ``` 170 + 1. Run validator: `./scripts/validate.sh` 171 + 2. If errors, fix and go to step 1 172 + 3. If clean, proceed 173 + ``` 30 174 31 - - Exceed 1024 characters 32 - - Contain XML angle brackets (`<` or `>`) in frontmatter 175 + ### Conditional Workflow 33 176 34 - ## Directory Structure 177 + Decision trees for different paths: 35 178 36 179 ``` 37 - ~/.config/opencode/ 38 - ├── skills/ 39 - │ └── <skill-name>/ 40 - │ └── SKILL.md 41 - ├── agents/ 42 - │ └── <agent-name>.md 180 + If new table → use CREATE TABLE template 181 + If adding column → use ALTER TABLE template with NOT NULL + default 182 + If dropping column → require migration plan review first 43 183 ``` 44 184 45 - OR in project root: 185 + ### Examples Pattern 186 + 187 + Input/output pairs showing expected behavior: 46 188 47 189 ``` 48 - .opencode/ 49 - ├── skills/<skill-name>/SKILL.md 50 - └── agents/<agent-name>.md 190 + Input: createUser("jane", "admin") 191 + Output: { id: 1, name: "jane", role: "admin", createdAt: "..." } 51 192 ``` 52 193 53 - ## Frontmatter 194 + ## 7. Agents 195 + 196 + Agents are standalone `.md` files. The filename determines the agent name (`orchestrator.md` → `orchestrator`). 197 + 198 + ### Location 199 + 200 + - Global: `~/.config/opencode/agents/<name>.md` 201 + - Project: `.opencode/agents/<name>.md` 54 202 55 - ### Agents 203 + ### Frontmatter 56 204 57 205 ```yaml 58 206 --- 59 - description: ... 207 + description: Coordinates multi-step tasks by delegating to specialized subagents. 60 208 mode: primary|subagent 61 - 62 209 permission: 63 210 edit: allow|deny|ask 64 211 bash: 65 - "*": ask|allow|deny 212 + "*": ask 66 213 "git *": allow 214 + "npm test": allow 67 215 skill: 68 - "*": allow|deny|ask 216 + "*": allow 69 217 task: 70 - "*": allow|deny|ask 218 + "*": allow 71 219 --- 72 220 ``` 73 221 74 - ### Skills 222 + | Field | Required | Notes | 223 + |---|---|---| 224 + | `description` | Yes | Same rules as skill descriptions (§3). | 225 + | `mode` | No | `primary` (top-level) or `subagent` (delegated to). | 226 + | `permission` | No | Tool permission overrides. Pattern-matched, most specific wins. | 227 + 228 + ### Content 75 229 76 - ```yaml 77 - --- 78 - name: skill-name 79 - description: ... 80 - --- 230 + Agent body defines role, protocol, and constraints. Keep under 100 lines. 231 + 232 + ```markdown 233 + You are the **Code Reviewer**. You review pull requests for correctness and style. 234 + 235 + ## Protocol 236 + 1. Read the diff 237 + 2. Check against project conventions 238 + 3. Report issues with file:line references 239 + 240 + ## Constraints 241 + - MUST NOT suggest style changes that contradict existing patterns 242 + - MUST NOT approve without reading every changed file 81 243 ``` 82 244 83 - ## Content Guidelines 245 + ## 8. Testing 84 246 85 - - Agents: keep under 100 lines 86 - - Skills: keep under 500 lines 87 - - Use RFC 2119 keywords (MUST, SHOULD, MAY) for all constraints 88 - - Negative constraints (MUST NOT, SHOULD NOT) MUST include a reason explaining why. 89 - - NEVER use sycophantic language ("Good call", "Great question", etc.) 90 - - Be direct and concise 247 + ### Trigger Testing 91 248 92 - ## Trigger Phrases 249 + - Does the skill trigger on direct requests? (_"Create a new skill for..."_) 250 + - Does it trigger on paraphrased requests? (_"I need to set up an agent"_) 251 + - Does it stay silent on unrelated tasks? (_"Fix this CSS bug"_) 93 252 94 - Example triggers for a skill: 253 + ### Functional Testing 95 254 96 - - "Create a new agent for..." 97 - - "I need a skill that..." 98 - - "How do I add a new..." 255 + - Does it produce correct output for typical inputs? 256 + - Does error handling work (missing fields, invalid names)? 257 + - Are edge cases covered (empty descriptions, long names)? 99 258 100 - Example triggers for an agent: 259 + ### Iteration 101 260 102 - - "Use the orchestrator agent" 103 - - "Delegate to subagent" 261 + | Problem | Fix | 262 + |---|---| 263 + | Under-triggering | Add more keywords and trigger phrases to description | 264 + | Over-triggering | Be more specific, add negative triggers | 265 + | Wrong output | Add examples, tighten constraints | 104 266 105 - ## Validation Checklist 267 + Debug with: _"When would you use the [skill name] skill?"_ 106 268 107 - Before committing: 269 + ## 9. Validation Checklist 108 270 109 - - [ ] SKILL.md exists (case-sensitive) 110 - - [ ] Frontmatter has required fields 111 - - Skills: `name` + `description` 112 - - Agents: `description` 113 - - [ ] Name matches folder/filename exactly 114 - - [ ] Description under 1024 characters 115 - - [ ] No XML brackets in frontmatter 116 - - [ ] All constraints use RFC 2119 language (MUST/SHOULD/MAY) 271 + ### Skills 117 272 118 - ## Creating a Skill 273 + - [ ] File is named `SKILL.md` (case-sensitive) 274 + - [ ] Folder uses kebab-case 275 + - [ ] Frontmatter has `name` and `description` 276 + - [ ] `name` matches folder name exactly 277 + - [ ] `name` does not contain "claude" or "anthropic" 278 + - [ ] Description is 1-1024 characters 279 + - [ ] Description includes what, when, and trigger keywords 280 + - [ ] Description written in third person 281 + - [ ] No XML angle brackets in frontmatter 282 + - [ ] No README.md in skill folder 283 + - [ ] Body under 500 lines 284 + - [ ] All constraints use RFC 2119 language 285 + - [ ] Negative constraints include a reason 119 286 120 - 1. Create directory: `mkdir -p ~/.config/opencode/skills/<name>` 121 - 2. Create SKILL.md with frontmatter 122 - 3. Add content following guidelines 123 - 4. Validate against checklist 287 + ### Agents 288 + 289 + - [ ] File uses `.md` extension 290 + - [ ] Frontmatter has `description` 291 + - [ ] Description is 1-1024 characters 292 + - [ ] No XML angle brackets in frontmatter 293 + - [ ] Body under 100 lines 294 + - [ ] `mode` is `primary` or `subagent` (if specified) 295 + - [ ] Permission patterns are valid 124 296 125 - ## Creating an Agent 297 + ## 10. Anti-patterns 126 298 127 - 1. Create file: `~/.config/opencode/agents/<name>.md` 128 - 2. Add frontmatter with description, mode, permissions 129 - 3. Add agent content 130 - 4. Validate against checklist 299 + - **Vague descriptions** — _"Helps with projects"_ tells the agent nothing 300 + - **Missing trigger phrases** — skill exists but never fires 301 + - **Deeply nested references** — agents lose track past one level of nesting 302 + - **Too many options without a default** — _"you could use A, B, or C"_ without guidance on which to pick 303 + - **Time-sensitive content** — version numbers and dates go stale silently 304 + - **Inconsistent terminology** — using "skill", "plugin", and "extension" interchangeably 305 + - **Backslash paths** — use forward slashes; backslashes break on Unix systems