|
| 1 | +# OpenCode Agents - Equinor Design System |
| 2 | + |
| 3 | +This directory contains custom AI agent configurations for OpenCode in the EDS repository. |
| 4 | + |
| 5 | +## Global Configuration |
| 6 | + |
| 7 | +The root `AGENTS.md` file provides **global instructions** for all AI coding tools (OpenCode, Claude Code, Cursor, GitHub Copilot). It contains repository-wide conventions that apply regardless of which agent or tool is used. |
| 8 | + |
| 9 | +The `.opencode/` directory contains **OpenCode-specific** agent definitions that build on top of the global instructions. |
| 10 | + |
| 11 | +## Planning Mode |
| 12 | + |
| 13 | +OpenCode has a **planning mode** that can be toggled with `Ctrl+L` (or `Cmd+L` on Mac). When enabled: |
| 14 | + |
| 15 | +- The agent analyzes the task before making changes |
| 16 | +- Creates a structured plan with steps |
| 17 | +- Useful for complex, multi-file changes |
| 18 | +- Helps ensure all requirements are considered upfront |
| 19 | + |
| 20 | +Use planning mode for larger features or refactors. Skip it for quick fixes or simple changes. |
| 21 | + |
| 22 | +## Instruction Pipeline |
| 23 | + |
| 24 | +OpenCode agents receive instructions from multiple sources, applied in this order: |
| 25 | + |
| 26 | +``` |
| 27 | +┌─────────────────────────────────────┐ |
| 28 | +│ OpenCode Base Model │ |
| 29 | +└─────────────────┬───────────────────┘ |
| 30 | + │ |
| 31 | +┌─────────────────▼───────────────────┐ |
| 32 | +│ AGENTS.md │ ← Repository conventions |
| 33 | +└─────────────────┬───────────────────┘ |
| 34 | + │ |
| 35 | +┌─────────────────▼───────────────────┐ |
| 36 | +│ .opencode/agent/<name>.md │ ← Agent-specific behavior |
| 37 | +└─────────────────┬───────────────────┘ |
| 38 | + │ |
| 39 | +┌─────────────────▼───────────────────┐ |
| 40 | +│ .github/instructions/*.md │ ← File-pattern instructions |
| 41 | +└─────────────────────────────────────┘ |
| 42 | +``` |
| 43 | + |
| 44 | +1. **Global instructions** - Built into OpenCode (base capabilities) |
| 45 | +2. **AGENTS.md** - Repository-level guidance for all AI tools |
| 46 | +3. **Agent-specific instructions** - `.opencode/agent/*.md` files define agent behavior |
| 47 | +4. **GitHub instructions** - `.github/instructions/*.md` applied by file pattern (e.g., `*.tsx` files get React instructions) |
| 48 | + |
| 49 | +## Agent Types |
| 50 | + |
| 51 | +### Primary Agents |
| 52 | + |
| 53 | +Primary agents are selectable by the user and run as the main conversation agent. |
| 54 | + |
| 55 | +| Agent | Description | Tools | |
| 56 | +|-------|-------------|-------| |
| 57 | +| `build` | Development agent with EDS conventions | All (asks for git commit/push/branch) | |
| 58 | +| `advisor` | Read-only architectural advice and code reviews | Read-only (no write/edit/bash) | |
| 59 | + |
| 60 | +### Sub-Agents |
| 61 | + |
| 62 | +Sub-agents are invoked by primary agents to perform specialized tasks. They cannot be selected directly, but must be mentioned in chat. |
| 63 | + |
| 64 | +| Agent | Description | Tools | |
| 65 | +|-------|-------------|-------| |
| 66 | +| `eds-component` | Builds EDS 2.0 React components following conventions | write, edit, bash | |
| 67 | +| `figma-component` | Builds components from Figma designs with MCP token extraction | write, edit, bash | |
| 68 | + |
| 69 | +## Agent Configuration |
| 70 | + |
| 71 | +Each agent is defined in a markdown file in `.opencode/agent/` with YAML frontmatter: |
| 72 | + |
| 73 | +```markdown |
| 74 | +--- |
| 75 | +description: Short description shown in agent picker |
| 76 | +mode: primary | subagent |
| 77 | +tools: |
| 78 | + write: true | false |
| 79 | + edit: true | false |
| 80 | + bash: true | false |
| 81 | +permission: |
| 82 | + bash: |
| 83 | + '*': 'allow' | 'ask' | 'deny' |
| 84 | + 'git commit*': 'ask' |
| 85 | +--- |
| 86 | + |
| 87 | +Agent-specific instructions go here... |
| 88 | +``` |
| 89 | + |
| 90 | +### Frontmatter Options |
| 91 | + |
| 92 | +| Field | Description | |
| 93 | +|-------|-------------| |
| 94 | +| `description` | Shown in the agent picker UI | |
| 95 | +| `mode` | `primary` (user-selectable) or `subagent` (invoked programmatically) | |
| 96 | +| `tools` | Enable/disable tool access (write, edit, bash) | |
| 97 | +| `permission.bash` | Fine-grained bash command permissions with glob patterns | |
| 98 | + |
| 99 | +### Permission Patterns |
| 100 | + |
| 101 | +Control which bash commands require user approval: |
| 102 | + |
| 103 | +```yaml |
| 104 | +permission: |
| 105 | + bash: |
| 106 | + '*': 'allow' # Allow all commands by default |
| 107 | + 'git commit*': 'ask' # Ask before committing |
| 108 | + 'git push*': 'ask' # Ask before pushing |
| 109 | + 'git checkout -b*': 'ask' # Ask before creating branches |
| 110 | + 'rm -rf*': 'deny' # Never allow destructive commands |
| 111 | +``` |
| 112 | +
|
| 113 | +## Using Agents |
| 114 | +
|
| 115 | +### Selecting a Primary Agent |
| 116 | +
|
| 117 | +Press `Tab` to cycle through available primary agents. The current agent is shown in the input area. |
| 118 | + |
| 119 | +### Invoking Sub-Agents |
| 120 | + |
| 121 | +Sub-agents are specialized agents that handle specific tasks. Mention them with `@` to invoke: |
| 122 | + |
| 123 | +``` |
| 124 | +@figma-component build the Button component from this Figma link |
| 125 | +``` |
| 126 | + |
| 127 | +``` |
| 128 | +@eds-component create a new Tooltip component |
| 129 | +``` |
| 130 | +
|
| 131 | +When a sub-agent is invoked: |
| 132 | +1. It receives the task with its specialized instructions |
| 133 | +2. Executes with its configured tools |
| 134 | +3. Returns results back to the conversation |
| 135 | +
|
| 136 | +## MCP Integration |
| 137 | +
|
| 138 | +Some agents use [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers to access external tools. The `figma-component` agent uses Figma MCP tools: |
| 139 | +
|
| 140 | +| MCP Tool | Purpose | |
| 141 | +|----------|---------| |
| 142 | +| `figma_get_design_context` | Analyze component structure and layers | |
| 143 | +| `figma_get_screenshot` | Get visual reference of the design | |
| 144 | +| `figma_get_variable_defs` | Extract design tokens for each component state | |
| 145 | +
|
| 146 | +### MCP Workflow Example |
| 147 | +
|
| 148 | +``` |
| 149 | +1. figma_get_design_context → Understand component structure |
| 150 | +2. figma_get_screenshot → Visual reference |
| 151 | +3. figma_get_variable_defs (Default state) → Base tokens |
| 152 | +4. figma_get_variable_defs (Hover state) → Hover tokens |
| 153 | +5. figma_get_variable_defs (Focus state) → Focus tokens |
| 154 | +6. figma_get_variable_defs (Disabled state) → Disabled tokens |
| 155 | +``` |
| 156 | +
|
| 157 | +MCP servers are configured globally in OpenCode settings, not in this repository. |
| 158 | +
|
| 159 | +## Creating New Agents |
| 160 | +
|
| 161 | +1. Create a new file in `.opencode/agent/` with a `.md` extension |
| 162 | +2. Add YAML frontmatter with required fields |
| 163 | +3. Write agent-specific instructions in markdown |
| 164 | +4. Reference `AGENTS.md` for shared conventions |
| 165 | +
|
| 166 | +### Example: Test Runner Agent |
| 167 | +
|
| 168 | +```markdown |
| 169 | +--- |
| 170 | +description: Writes and runs tests for EDS components |
| 171 | +mode: subagent |
| 172 | +tools: |
| 173 | + write: true |
| 174 | + edit: true |
| 175 | + bash: true |
| 176 | +--- |
| 177 | +
|
| 178 | +You write tests for EDS components in `packages/eds-core-react/src/components/next/`. |
| 179 | +
|
| 180 | +## Test Structure |
| 181 | +
|
| 182 | +- Use Jest + Testing Library + jest-axe |
| 183 | +- Organize with describe blocks: Rendering, Accessibility, Behavior |
| 184 | +- Query priority: getByRole > getByLabelText > getByText > getByTestId |
| 185 | +
|
| 186 | +## Commands |
| 187 | +
|
| 188 | +\`\`\`bash |
| 189 | +pnpm run test:core-react # Run all tests |
| 190 | +pnpm test -- --testPathPattern="Name" # Run specific test |
| 191 | +\`\`\` |
| 192 | +
|
| 193 | +Refer to AGENTS.md for full conventions. |
| 194 | +``` |
| 195 | + |
| 196 | +## Relationship to Other Instruction Files |
| 197 | + |
| 198 | +| File | Purpose | Scope | |
| 199 | +|------|---------|-------| |
| 200 | +| `AGENTS.md` | General AI agent guidance | All AI tools (Copilot, OpenCode, Claude) | |
| 201 | +| `.github/copilot-instructions.md` | GitHub Copilot hub | GitHub Copilot | |
| 202 | +| `.github/instructions/*.md` | File-pattern specific rules | GitHub Copilot (by `applyTo` pattern) | |
| 203 | +| `.opencode/agent/*.md` | OpenCode agent definitions | OpenCode only | |
| 204 | + |
| 205 | +## Directory Structure |
| 206 | + |
| 207 | +``` |
| 208 | +.opencode/ |
| 209 | +├── README.md # This file |
| 210 | +├── agent/ |
| 211 | +│ ├── build.md # Primary: Development agent |
| 212 | +│ ├── advisor.md # Primary: Read-only advisor |
| 213 | +│ ├── eds-component.md # Sub-agent: Component builder |
| 214 | +│ └── figma-component.md # Sub-agent: Figma-to-code |
| 215 | +``` |
| 216 | + |
| 217 | +## Best Practices |
| 218 | + |
| 219 | +1. **Keep agents focused** - Each agent should have a clear, single responsibility |
| 220 | +2. **Use sub-agents for specialization** - Complex workflows delegate to specialized sub-agents |
| 221 | +3. **Reference shared docs** - Point to `AGENTS.md` for common conventions instead of duplicating |
| 222 | +4. **Minimize permissions** - Only enable tools the agent actually needs |
| 223 | +5. **Be specific about MCP tools** - Document which MCP tools an agent expects to use |
0 commit comments