migrated custom tools to V2 plugin
This commit is contained in:
@@ -11,7 +11,7 @@ OpenCode uses three component types:
|
||||
| Component | Location | Purpose | Example |
|
||||
|-----------|----------|---------|---------|
|
||||
| **Skills** | `.opencode/skills/` | Reference knowledge | `issue-writing` knows how to structure good issues |
|
||||
| **Tools** | `.opencode/tools/` | Custom functions | `spawn_issues` implements multiple issues in parallel |
|
||||
| **Tools** | `.opencode/plugins/` | Custom functions, provided by plugins | `tools` registers the `tea-*` Gitea CLI tools |
|
||||
| **Agents** | `.opencode/agents/` | Specialized subagents | `code-reviewer` handles PR reviews |
|
||||
|
||||
## Quick Start
|
||||
@@ -29,7 +29,7 @@ make install
|
||||
|
||||
This creates symlinks at:
|
||||
- `~/.config/opencode/skills/` → `.opencode/skills/`
|
||||
- `~/.config/opencode/tools/` → `.opencode/tools/`
|
||||
- `~/.config/opencode/plugins/` → `.opencode/plugins/`
|
||||
- `~/.config/opencode/agents/` → `.opencode/agents/`
|
||||
|
||||
### Uninstallation
|
||||
@@ -67,7 +67,7 @@ architecture/
|
||||
│
|
||||
├── .opencode/ # OpenCode configuration
|
||||
│ ├── skills/ # Reference knowledge (SKILL.md files)
|
||||
│ ├── tools/ # Custom tools (TypeScript/JS)
|
||||
│ ├── plugins/ # Plugins registering custom tools (TypeScript)
|
||||
│ └── agents/ # Specialized subagents (AGENT.md files)
|
||||
│
|
||||
├── Makefile # Symlink management
|
||||
@@ -96,24 +96,42 @@ Skills are auto-discovered by OpenCode and available via the `skill` tool.
|
||||
|
||||
### Tools
|
||||
|
||||
Create `.opencode/tools/<name>.ts`:
|
||||
Tools are registered by plugins under `.opencode/plugins/`. Create `.opencode/plugins/<name>/index.ts`:
|
||||
|
||||
```typescript
|
||||
import { tool } from "@opencode-ai/plugin"
|
||||
import { Plugin } from "@opencode/plugin"
|
||||
|
||||
export default tool({
|
||||
import type { Info } from "@opencode/plugin/promise/tool"
|
||||
|
||||
const example: Info = {
|
||||
name: "example",
|
||||
description: "What this tool does",
|
||||
args: {
|
||||
param: tool.schema.string().describe("Parameter description"),
|
||||
input: {
|
||||
type: "object",
|
||||
properties: {
|
||||
param: { type: "string", description: "Parameter description" },
|
||||
},
|
||||
required: ["param"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
async execute(args) {
|
||||
async execute(input) {
|
||||
const { param } = input as { param: string }
|
||||
// Your implementation
|
||||
return "result"
|
||||
return { content: `result for ${param}` }
|
||||
},
|
||||
}
|
||||
|
||||
export default Plugin.define({
|
||||
id: "example",
|
||||
async setup(ctx) {
|
||||
await ctx.tool.transform((editor) => {
|
||||
editor.add(example)
|
||||
})
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
Tools are auto-discovered and available to the LLM.
|
||||
Tool input schemas are plain JSON Schema, and execution returns structured content. Plugins under `.opencode/plugins/` are auto-discovered and their tools are available to the LLM.
|
||||
|
||||
### Agents
|
||||
|
||||
|
||||
Reference in New Issue
Block a user