feat: add openclaw-plugin-dev skill
Plugin development reference and workflows based on real development experience (Dirigent, ContractorAgent, PrismFacet). Docs: structure, entry-point, hooks, tools, state, config, debugging Workflows: create-plugin, add-hook Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
40
openclaw-plugin-dev/workflows/add-hook.md
Normal file
40
openclaw-plugin-dev/workflows/add-hook.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Add Hook
|
||||
|
||||
When adding a new hook handler to an existing plugin.
|
||||
|
||||
> See `{baseDir}/docs/hooks.md` for available hooks and dedup patterns.
|
||||
|
||||
## Process
|
||||
|
||||
### 1. Create Hook File
|
||||
|
||||
Add `plugin/hooks/<hook-name>.ts`. Export a registration function:
|
||||
|
||||
```typescript
|
||||
export function registerMyHook(api, config) {
|
||||
// Set up dedup on globalThis
|
||||
// api.on("<hook-name>", handler)
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Add Dedup
|
||||
|
||||
Choose the right dedup pattern:
|
||||
- `before_model_resolve`, `before_prompt_build` → WeakSet on event object
|
||||
- `agent_end` → Set on runId with size cap (500)
|
||||
- `gateway_start/stop` → globalThis flag (in index.ts, not in hook file)
|
||||
|
||||
### 3. Register in index.ts
|
||||
|
||||
Import and call the registration function in the `register()` method.
|
||||
|
||||
Hooks that need to run every register() call (agent-scoped): put outside the lifecycle guard.
|
||||
Hooks that should run once (gateway-scoped): put inside the lifecycle guard.
|
||||
|
||||
### 4. If Prompt Injection
|
||||
|
||||
If the hook returns `prependSystemContext` or `appendSystemContext`, ensure `allowPromptInjection: true` is set in the plugin's config entry and in the install script.
|
||||
|
||||
### 5. Test
|
||||
|
||||
Reinstall, restart gateway, verify via logs.
|
||||
72
openclaw-plugin-dev/workflows/create-plugin.md
Normal file
72
openclaw-plugin-dev/workflows/create-plugin.md
Normal file
@@ -0,0 +1,72 @@
|
||||
# Create Plugin
|
||||
|
||||
When creating a new OpenClaw plugin from scratch.
|
||||
|
||||
> See `{baseDir}/docs/structure.md` for directory layout and conventions.
|
||||
|
||||
## Process
|
||||
|
||||
### 1. Scaffold
|
||||
|
||||
Create the project structure:
|
||||
|
||||
```
|
||||
my-plugin/
|
||||
plugin/
|
||||
index.ts
|
||||
openclaw.plugin.json
|
||||
package.json
|
||||
core/
|
||||
hooks/
|
||||
tools/
|
||||
scripts/
|
||||
install.mjs
|
||||
routers/ # if applicable
|
||||
package.json # dev dependencies (typescript, @types/node)
|
||||
tsconfig.plugin.json
|
||||
.gitignore
|
||||
```
|
||||
|
||||
### 2. Define Config Schema
|
||||
|
||||
Write `plugin/openclaw.plugin.json` with `additionalProperties: false`. Only include fields the plugin actually uses.
|
||||
|
||||
### 3. Implement Entry Point
|
||||
|
||||
Follow the pattern in `{baseDir}/docs/entry-point.md`:
|
||||
- `export default { id, name, register }`
|
||||
- globalThis lifecycle protection
|
||||
- Hooks in separate files under `hooks/`
|
||||
- Tools in separate files under `tools/`
|
||||
- Business logic in `core/` (no plugin-sdk imports)
|
||||
|
||||
### 4. Implement Hooks
|
||||
|
||||
Follow dedup patterns in `{baseDir}/docs/hooks.md`. Each hook gets its own file.
|
||||
|
||||
### 5. Implement Tools
|
||||
|
||||
Follow the interface in `{baseDir}/docs/tools.md`: `inputSchema` + `execute`.
|
||||
|
||||
### 6. Write Install Script
|
||||
|
||||
Follow `{baseDir}/docs/config.md` for install/uninstall conventions.
|
||||
|
||||
### 7. Build & Test
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
node scripts/install.mjs --install
|
||||
openclaw gateway restart
|
||||
# Test via Discord or openclaw agent CLI
|
||||
```
|
||||
|
||||
### 8. Push
|
||||
|
||||
Create a git repository and push:
|
||||
|
||||
```bash
|
||||
git-ctrl repo create <plugin-name>
|
||||
git add -A && git commit -m "init: <plugin-name>"
|
||||
git push -u origin main
|
||||
```
|
||||
Reference in New Issue
Block a user