|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance to AI coding agents working with code in this repository. |
| 4 | + |
| 5 | +## Repository Overview |
| 6 | + |
| 7 | +A collection of Agent Skills for the Rspack ecosystem (Rspack, Rsbuild, Rslib, Rstest, Rsdoctor). Skills are packaged instructions and scripts that extend agent capabilities for debugging, profiling, and development workflows. |
| 8 | + |
| 9 | +## Project Structure |
| 10 | + |
| 11 | +``` |
| 12 | +agent-skills/ |
| 13 | +├── skills/ # Skills directory, contains all Skills |
| 14 | +├── packages/ # Source code projects for complex scripts |
| 15 | +├── scripts/ # Project-level configurations and tools |
| 16 | +│ └── config/ # Common configurations (rslib, tsconfig, etc.) |
| 17 | +├── biome.json # Biome code formatting configuration |
| 18 | +├── pnpm-workspace.yaml # pnpm workspace configuration |
| 19 | +├── pnpm-lock.yaml # Dependency lock file |
| 20 | +├── package.json # Project configuration file |
| 21 | +└── README.md # Project documentation |
| 22 | +``` |
| 23 | + |
| 24 | +### Directory Explanations |
| 25 | + |
| 26 | +- **skills/**: Contains all Skills, each Skill is an independent folder |
| 27 | + - Each Skill includes `SKILL.md` (required), `scripts/` (optional), `references/` (optional), `assets/` (optional) |
| 28 | +- **packages/**: Contains source code for complex scripts that need compilation |
| 29 | + - Corresponds to Skills with the same name in the skills directory |
| 30 | + - Compiled by Rslib and output to the corresponding `skills/{skill-name}/scripts/` directory |
| 31 | +- **scripts/config/**: Contains project-level common configurations |
| 32 | + - `rslib.config.ts`: Rslib base configuration |
| 33 | + - `tsconfig.json`: TypeScript base configuration |
| 34 | + |
| 35 | +## Creating a New Skill |
| 36 | + |
| 37 | +### 1. Initialize Skill Template |
| 38 | + |
| 39 | +Execute in the `skills/` directory: |
| 40 | + |
| 41 | +```bash |
| 42 | +cd skills |
| 43 | +npx skills init my-skill |
| 44 | +``` |
| 45 | + |
| 46 | +This will generate a `SKILL.md` file with YAML front-matter and Markdown content. |
| 47 | + |
| 48 | +### 2. Configure Front-matter |
| 49 | + |
| 50 | +Configure in the YAML front-matter at the top of the `SKILL.md` file: |
| 51 | + |
| 52 | +```yaml |
| 53 | +--- |
| 54 | +name: my-skill |
| 55 | +description: Feature description and trigger scenarios, which is key for Agents to determine whether to use this Skill |
| 56 | +--- |
| 57 | +``` |
| 58 | + |
| 59 | +**Field Descriptions**: |
| 60 | + |
| 61 | +- **name** (required) |
| 62 | + - Unique identifier for the Skill |
| 63 | + - Maximum 64 characters |
| 64 | + - Only lowercase letters, numbers, and hyphens |
| 65 | + - Must not start or end with a hyphen |
| 66 | + - Example: `rspack-tracing` |
| 67 | + |
| 68 | +- **description** (required) |
| 69 | + - Feature description and trigger scenarios |
| 70 | + - Maximum 1024 characters |
| 71 | + - Recommended to include trigger keywords, such as "when user encounters segmentation fault in Rspack" |
| 72 | + |
| 73 | +### 3. Write Skill Content |
| 74 | + |
| 75 | +Standard Skill structure: |
| 76 | + |
| 77 | +``` |
| 78 | +my-skill/ |
| 79 | +├── SKILL.md # Required: instructions + metadata |
| 80 | +├── scripts/ # Optional: executable scripts |
| 81 | +├── references/ # Optional: reference documentation |
| 82 | +└── assets/ # Optional: templates, resource files |
| 83 | +``` |
| 84 | + |
| 85 | +Write in `SKILL.md`: |
| 86 | + |
| 87 | +- **Use Cases**: Explain when to use this Skill |
| 88 | +- **Workflow**: Detailed operation steps |
| 89 | +- **Code Examples**: Provide code examples |
| 90 | +- **Reference Documentation**: Link to detailed documentation in the `references/` directory |
| 91 | + |
| 92 | +## Writing Skill Scripts |
| 93 | + |
| 94 | +### Simple Scripts |
| 95 | + |
| 96 | +For simple scripts (such as single-file scripts), create them directly in the `skills/{skill-name}/scripts/` directory. |
| 97 | + |
| 98 | +Example: |
| 99 | + |
| 100 | +```javascript |
| 101 | +// skills/my-skill/scripts/simple.js |
| 102 | +console.log('Hello from simple script'); |
| 103 | +``` |
| 104 | + |
| 105 | +### Complex Scripts (Requiring Bundling) |
| 106 | + |
| 107 | +For complex scenarios requiring dependencies, TypeScript, etc.: |
| 108 | + |
| 109 | +#### 1. Create a Project with the Same Name in packages Directory |
| 110 | + |
| 111 | +``` |
| 112 | +packages/my-skill/ |
| 113 | +├── package.json |
| 114 | +├── rslib.config.ts |
| 115 | +├── tsconfig.json |
| 116 | +└── src/ |
| 117 | + └── index.ts |
| 118 | +``` |
| 119 | + |
| 120 | +#### 2. Configure package.json |
| 121 | + |
| 122 | +```json |
| 123 | +{ |
| 124 | + "name": "@rstackjs/my-skill", |
| 125 | + "version": "0.0.0", |
| 126 | + "type": "module", |
| 127 | + "scripts": { |
| 128 | + "build": "rslib build", |
| 129 | + "test": "rstest" |
| 130 | + }, |
| 131 | + "dependencies": { |
| 132 | + // Your dependencies |
| 133 | + } |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +#### 3. Configure rslib.config.ts |
| 138 | + |
| 139 | +```typescript |
| 140 | +import { basename, join } from 'node:path'; |
| 141 | +import { defineConfig } from '@rslib/core'; |
| 142 | +import { baseConfig } from '@rstackjs/config/rslib.config.ts'; |
| 143 | + |
| 144 | +const pkgName = basename(import.meta.dirname); |
| 145 | + |
| 146 | +export default defineConfig({ |
| 147 | + lib: [ |
| 148 | + { |
| 149 | + ...baseConfig, |
| 150 | + output: { |
| 151 | + distPath: join(import.meta.dirname, `../../skills/${pkgName}/scripts`), |
| 152 | + }, |
| 153 | + }, |
| 154 | + ], |
| 155 | +}); |
| 156 | +``` |
| 157 | + |
| 158 | +#### 4. Configure tsconfig.json |
| 159 | + |
| 160 | +```json |
| 161 | +{ |
| 162 | + "extends": "@rstackjs/config/tsconfig", |
| 163 | + "compilerOptions": {}, |
| 164 | + "include": ["src"] |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +#### 5. Write Source Code |
| 169 | + |
| 170 | +Write code in `src/index.ts`: |
| 171 | + |
| 172 | +```typescript |
| 173 | +export function myFunction() { |
| 174 | + // Your logic |
| 175 | +} |
| 176 | +``` |
| 177 | + |
| 178 | +#### 6. Build Script |
| 179 | + |
| 180 | +```bash |
| 181 | +cd packages/my-skill |
| 182 | +pnpm build |
| 183 | +``` |
| 184 | + |
| 185 | +After building, the bundled files will be automatically output to the `skills/my-skill/scripts/` directory. |
| 186 | + |
| 187 | +### Testing Scripts |
| 188 | + |
| 189 | +Write tests using Rstest: |
| 190 | + |
| 191 | +```typescript |
| 192 | +// packages/my-skill/src/index.test.ts |
| 193 | +import { describe, it, expect } from '@rstest/core'; |
| 194 | +import { myFunction } from './index'; |
| 195 | + |
| 196 | +describe('myFunction', () => { |
| 197 | + it('should work correctly', () => { |
| 198 | + expect(myFunction()).toBe(expected); |
| 199 | + }); |
| 200 | +}); |
| 201 | +``` |
| 202 | + |
| 203 | +Run tests: |
| 204 | + |
| 205 | +```bash |
| 206 | +pnpm test |
| 207 | +``` |
| 208 | + |
| 209 | +## Using Skills |
| 210 | + |
| 211 | +Install a specific Skill: |
| 212 | + |
| 213 | +```bash |
| 214 | +npx skills add rstackjs/agent-skills --skill my-skill |
| 215 | +``` |
| 216 | + |
| 217 | +## References |
| 218 | + |
| 219 | +- [Agent Skills Specification](https://agentskills.io/specification) |
| 220 | +- [Skill Authoring Best Practices](https://platform.claude.com/docs/en/agents-and-tools/agent-skills/best-practices) |
| 221 | +- [Rspack Documentation](https://rspack.rs) |
| 222 | +- [Rslib Documentation](https://rslib.rs) |
| 223 | +- [Rstest Documentation](https://rslib.rs) |
0 commit comments