opencode-architect 0.2.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -18
- package/agent-loader.ts +98 -0
- package/assets/agents/opencode-agent-designer.md +13 -47
- package/assets/agents/opencode-architect.md +60 -244
- package/assets/agents/opencode-command-crafter.md +9 -27
- package/assets/agents/opencode-extension-auditor.md +25 -36
- package/assets/agents/opencode-mcp-integrator.md +13 -17
- package/assets/agents/opencode-packager.md +31 -203
- package/assets/agents/opencode-plugin-engineer.md +16 -29
- package/assets/agents/opencode-publisher.md +27 -206
- package/assets/agents/opencode-skill-creator.md +15 -35
- package/assets/agents/opencode-tool-builder.md +13 -17
- package/assets/references/agents.md +68 -0
- package/assets/references/commands.md +49 -0
- package/assets/references/config.md +50 -0
- package/assets/references/mcp-servers.md +55 -0
- package/assets/references/opencode-architect-oneshots.md +19 -58
- package/assets/references/plugins.md +76 -0
- package/assets/references/prompt-engineering.md +46 -0
- package/assets/references/skills.md +55 -0
- package/assets/references/tools.md +49 -0
- package/assets/templates/skill-structure.template.md +4 -4
- package/cli.ts +120 -0
- package/index.ts +4 -103
- package/installer.ts +319 -0
- package/package.json +30 -8
- package/assets/templates/package-analysis.template.md +0 -60
- package/commands/sync-docs.ts +0 -9
- package/scripts/fetch-opencode-docs.ts +0 -193
- package/scripts/logger.ts +0 -20
- package/tools/sync-docs.ts +0 -24
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: Creates OpenCode custom tools
|
|
2
|
+
description: Creates OpenCode custom tools in .opencode/tools - Zod schemas and execute logic
|
|
3
3
|
mode: subagent
|
|
4
4
|
tools:
|
|
5
5
|
read: true
|
|
@@ -10,28 +10,24 @@ tools:
|
|
|
10
10
|
bash: false
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Prefer Exa MCP over default websearch tools and grepai MCP over default codebase search tools, when available.
|
|
14
14
|
|
|
15
|
-
You create custom tools in
|
|
15
|
+
You create custom tools in `.opencode/tools/` using TypeScript or JavaScript.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
## Essentials
|
|
18
18
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
- Multiple exports become '<filename>_<exportname>' tool names.
|
|
19
|
+
- Define tools with tool() from '@opencode-ai/plugin'; declare arguments with tool.schema (Zod).
|
|
20
|
+
- Export a default tool or multiple named exports; multiple exports register as '<filename>_<exportname>'.
|
|
21
|
+
- The execution context provides agent, sessionID, messageID, directory, worktree; use context.worktree for repo-root paths.
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
## References usage
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
- Use context.worktree for repo-root paths.
|
|
25
|
+
Bundled reference files are addressed relative to this agent file's own directory:
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
- Use `../references/tools.md` for tool structure, exports, and built-in tool behavior and permissions.
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
- Keep tools narrowly scoped and documented.
|
|
29
|
+
## Live knowledge fallback
|
|
33
30
|
|
|
34
|
-
|
|
31
|
+
For anything beyond the bundled references, query the deepwiki MCP tools (read_wiki_structure, read_wiki_contents, ask_question) against repo 'anomalyco/opencode' when available; otherwise run 'npx defuddle <url>' on the relevant opencode.ai/docs page if you have a way to execute commands. Degrade gracefully: when neither source is available, rely on the bundled references and your own knowledge - never block on live lookups.
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
- Use '~/.cache/opencode/opencode-architect/docs/tools.md' for built-in tool behavior and permissions.
|
|
33
|
+
Done when the tool registers under the expected name, its schema validates every argument, and its scope is narrow: one tool purpose per file.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# OpenCode agents — fundamentals
|
|
2
|
+
|
|
3
|
+
Agents are markdown-defined AI assistants. Locations (plural directory names):
|
|
4
|
+
|
|
5
|
+
- Project: `.opencode/agents/`
|
|
6
|
+
- Global: `~/.config/opencode/agents/`
|
|
7
|
+
|
|
8
|
+
The filename becomes the agent name (`review.md` → `review` agent). The markdown body is the system prompt.
|
|
9
|
+
|
|
10
|
+
## Types
|
|
11
|
+
|
|
12
|
+
- `primary` — main assistant the user interacts with (Tab to cycle).
|
|
13
|
+
- `subagent` — invoked by primary agents via the Task tool or by `@` mention.
|
|
14
|
+
- `all` — both: usable as primary and invokable as subagent (the default mode).
|
|
15
|
+
|
|
16
|
+
## Frontmatter fields
|
|
17
|
+
|
|
18
|
+
| Field | Required | Notes |
|
|
19
|
+
| --- | --- | --- |
|
|
20
|
+
| `description` | yes | What the agent does and when to use it. Drives subagent selection. |
|
|
21
|
+
| `mode` | no | `primary`, `subagent`, or `all` (default `all`). |
|
|
22
|
+
| `model` | no | `provider/model-id` (e.g. `anthropic/claude-sonnet-4-5`). Unset: primary uses the configured global model; subagents inherit the invoking agent's model. |
|
|
23
|
+
| `temperature` | no | 0.0–1.0. Low (0.0–0.2) focused/deterministic; high (0.6+) creative. Model-specific defaults apply if unset. |
|
|
24
|
+
| `steps` | no | Max agentic iterations before forced text-only summary. `maxSteps` is deprecated. |
|
|
25
|
+
| `tools` | no | **Deprecated** boolean map (`write: false`, `bash: false`, `mymcp_*: false`). Prefer `permission`. |
|
|
26
|
+
| `permission` | no | Allow/ask/deny control, per key or per glob pattern (see below). |
|
|
27
|
+
| `hidden` | no | `true` hides a `subagent` from the `@` menu; still invokable via Task tool. |
|
|
28
|
+
| `disable` | no | `true` disables the agent. |
|
|
29
|
+
| `color` | no | Hex (e.g. `#ff6b6b`) or theme color (`primary`, `accent`, ...). |
|
|
30
|
+
| `top_p` | no | Alternative randomness control, 0.0–1.0. |
|
|
31
|
+
| other keys | no | Passed through to the provider as model options (e.g. `reasoningEffort`). |
|
|
32
|
+
|
|
33
|
+
## Permissions
|
|
34
|
+
|
|
35
|
+
Values: `"allow"`, `"ask"`, `"deny"`. Either shorthand or an object of glob/pattern → action.
|
|
36
|
+
|
|
37
|
+
Keys: `read`, `edit`, `glob`, `grep`, `list`, `bash`, `task`, `webfetch`, `websearch`, `external_directory`, `todowrite`, `skill`, `lsp`, `question`, `doom_loop`.
|
|
38
|
+
|
|
39
|
+
- `edit` gates all file modifications: `write`, `edit`, `apply_patch`.
|
|
40
|
+
- `todowrite` gates `todowrite` and `todoread`.
|
|
41
|
+
- Shorthand-only keys: `webfetch`, `websearch`, `external_directory`, `question`, `doom_loop`, `lsp` (also accepts patterns — check schema when in doubt).
|
|
42
|
+
|
|
43
|
+
Bash command scoping (last matching rule wins; put `*` first, specific rules after):
|
|
44
|
+
|
|
45
|
+
```yaml
|
|
46
|
+
permission:
|
|
47
|
+
bash:
|
|
48
|
+
"*": ask
|
|
49
|
+
"git status *": allow
|
|
50
|
+
"git push": ask
|
|
51
|
+
webfetch: deny
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Task (subagent) scoping with globs — denied subagents are removed from the Task tool description:
|
|
55
|
+
|
|
56
|
+
```yaml
|
|
57
|
+
permission:
|
|
58
|
+
task:
|
|
59
|
+
"*": deny
|
|
60
|
+
"orchestrator-*": allow
|
|
61
|
+
"code-reviewer": ask
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Users can always invoke any subagent directly via `@` regardless of task permissions.
|
|
65
|
+
|
|
66
|
+
## JSON alternative
|
|
67
|
+
|
|
68
|
+
Agents can also be configured under the `agent` key in `opencode.json` with the same options plus `prompt` (inline string or `{file:./path}` relative to the config file). Markdown files are preferred for readability.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# OpenCode commands — fundamentals
|
|
2
|
+
|
|
3
|
+
Custom commands are prompt templates invoked as `/name` in the TUI, in addition to built-ins (`/init`, `/undo`, `/redo`, `/share`, `/help`).
|
|
4
|
+
|
|
5
|
+
Locations:
|
|
6
|
+
|
|
7
|
+
- Project: `.opencode/commands/`
|
|
8
|
+
- Global: `~/.config/opencode/commands/`
|
|
9
|
+
|
|
10
|
+
The filename becomes the command name (`test.md` → `/test`).
|
|
11
|
+
|
|
12
|
+
## Markdown format
|
|
13
|
+
|
|
14
|
+
The frontmatter defines properties; the body is the prompt template.
|
|
15
|
+
|
|
16
|
+
```markdown
|
|
17
|
+
---
|
|
18
|
+
description: Run tests with coverage
|
|
19
|
+
agent: build
|
|
20
|
+
model: anthropic/claude-haiku-4-5
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
Run the full test suite with coverage report and show any failures.
|
|
24
|
+
Focus on the failing tests and suggest fixes.
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Frontmatter keys
|
|
28
|
+
|
|
29
|
+
| Key | Required | Notes |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| `description` | no* | Shown in the TUI command list. |
|
|
32
|
+
| `template` | no* | The prompt (JSON config only; in markdown the body is the template). |
|
|
33
|
+
| `agent` | no | Which agent executes it. Defaults to the current agent. |
|
|
34
|
+
| `model` | no | Overrides the default model. |
|
|
35
|
+
| `subtask` | no | `true` forces a subagent invocation (keeps primary context clean), even for `primary`-mode agents. |
|
|
36
|
+
|
|
37
|
+
*In JSON config (`command.<name>` in `opencode.json`), `template` is required and `description` identifies the command.
|
|
38
|
+
|
|
39
|
+
## Template features
|
|
40
|
+
|
|
41
|
+
- `$ARGUMENTS` — full argument string: `/component Button` → `Button`.
|
|
42
|
+
- `$1`, `$2`, `$3` — positional args: `/create-file config.json src "content"` → `$1`=`config.json`, `$2`=`src`, `$3`=`content`.
|
|
43
|
+
- `` !`command` `` — inject shell output into the prompt (runs in the project root), e.g. ``!`git log --oneline -10` ``.
|
|
44
|
+
- `@path/to/file` — include file content in the prompt.
|
|
45
|
+
|
|
46
|
+
## Notes
|
|
47
|
+
|
|
48
|
+
- A custom command with the same name as a built-in overrides it.
|
|
49
|
+
- Keep prompts concise and task-focused; the template is the whole instruction the model receives.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# OpenCode config — fundamentals
|
|
2
|
+
|
|
3
|
+
OpenCode is configured with `opencode.json` (or `.jsonc`). Schema: `https://opencode.ai/config.json`. TUI settings live in a separate `tui.json` (`https://opencode.ai/tui.json`).
|
|
4
|
+
|
|
5
|
+
## Locations and precedence
|
|
6
|
+
|
|
7
|
+
Configs are **merged, not replaced**; later sources override earlier ones only for conflicting keys:
|
|
8
|
+
|
|
9
|
+
1. Remote config (`.well-known/opencode`, organizational defaults)
|
|
10
|
+
2. Global config (`~/.config/opencode/opencode.json`)
|
|
11
|
+
3. Custom config (`OPENCODE_CONFIG` env var)
|
|
12
|
+
4. Project config (`opencode.json` at project root, searched up to the git root)
|
|
13
|
+
5. `.opencode/` directories (agents, commands, plugins, skills, tools)
|
|
14
|
+
6. Inline config (`OPENCODE_CONFIG_CONTENT` env var)
|
|
15
|
+
7. Managed files (`/etc/opencode/`, `%ProgramData%\opencode`, macOS app support) and macOS MDM preferences — highest, not user-overridable
|
|
16
|
+
|
|
17
|
+
So: defaults/remote < global < project; managed settings override everything.
|
|
18
|
+
|
|
19
|
+
## Key schema options
|
|
20
|
+
|
|
21
|
+
| Key | Purpose |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| `model` | Default model, `provider/model-id`. |
|
|
24
|
+
| `small_model` | Cheap model for lightweight tasks (titles, summaries). |
|
|
25
|
+
| `provider` | Provider config; `options` supports `timeout`, `headerTimeout`, `chunkTimeout`. |
|
|
26
|
+
| `enabled_providers` / `disabled_providers` | Provider allowlist/blocklist (`disabled_providers` wins). |
|
|
27
|
+
| `agent` | Inline agent definitions; `default_agent` picks the default primary agent. |
|
|
28
|
+
| `command` | Inline command definitions (`template`, `description`, `agent`, `model`). |
|
|
29
|
+
| `mode` | Inline mode/agent-group definitions. |
|
|
30
|
+
| `mcp` | MCP server config (see mcp-servers reference). |
|
|
31
|
+
| `plugin` | npm plugin packages to load. |
|
|
32
|
+
| `tools` | Global tool enable/disable map with globs (`"write": false`). |
|
|
33
|
+
| `permission` | Global `allow`/`ask`/`deny` map (see agents reference for keys). |
|
|
34
|
+
| `instructions` | Extra instruction files/globs (e.g. `["CONTRIBUTING.md", "docs/rules/*.md"]`). |
|
|
35
|
+
| `lsp` | LSP servers (`true` for defaults, or object with per-server overrides). |
|
|
36
|
+
| `formatter` | Formatters (`true` for defaults, or object; custom: `command`, `extensions`, `environment`). |
|
|
37
|
+
| `keybinds` | TUI shortcuts (in `tui.json`; merged with defaults). |
|
|
38
|
+
| `share` | `"manual"` (default) / `"auto"` / `"disabled"`. |
|
|
39
|
+
| `autoupdate` | `true` / `false` / `"notify"`. |
|
|
40
|
+
| `snapshot` | `false` disables undo snapshots. |
|
|
41
|
+
| `compaction` | `{ auto, prune, reserved }` context compaction behavior. |
|
|
42
|
+
| `watcher` | `{ ignore: [globs] }` file watcher exclusions. |
|
|
43
|
+
| `server` | `port`, `hostname`, `mdns`, `cors` for `opencode serve`/`web`. |
|
|
44
|
+
| `shell` | Shell for interactive terminal and tool calls (e.g. `pwsh`). |
|
|
45
|
+
| `subagent_depth` | Subagent nesting depth (default 1; 0 disables subagents). |
|
|
46
|
+
| `experimental` | Options under active development (e.g. `policies`). |
|
|
47
|
+
|
|
48
|
+
## Directory conventions
|
|
49
|
+
|
|
50
|
+
`.opencode/` and `~/.config/opencode/` use **plural** subdirectory names: `agents/`, `commands/`, `plugins/`, `skills/`, `tools/`, `themes/` (singular accepted for backwards compatibility). Configs are safe to check into git; `prompt` paths in agent config resolve relative to the config file.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# OpenCode MCP servers — fundamentals
|
|
2
|
+
|
|
3
|
+
MCP (Model Context Protocol) servers add external tools alongside built-ins. Configure them under the `mcp` key in `opencode.json` with a unique name per server.
|
|
4
|
+
|
|
5
|
+
Caution: MCP tools add to context — enable only what you need.
|
|
6
|
+
|
|
7
|
+
## Local servers
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"mcp": {
|
|
12
|
+
"my-local-mcp": {
|
|
13
|
+
"type": "local",
|
|
14
|
+
"command": ["npx", "-y", "my-mcp-command"],
|
|
15
|
+
"enabled": true,
|
|
16
|
+
"environment": { "MY_ENV_VAR": "value" }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Options: `type` (required, `"local"`), `command` (required array), `cwd`, `environment`, `enabled`, `timeout` (ms to fetch tools, default 5000).
|
|
23
|
+
|
|
24
|
+
## Remote servers
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"mcp": {
|
|
29
|
+
"my-remote-mcp": {
|
|
30
|
+
"type": "remote",
|
|
31
|
+
"url": "https://mcp.example.com/mcp",
|
|
32
|
+
"enabled": true,
|
|
33
|
+
"headers": { "Authorization": "Bearer {env:MY_API_KEY}" }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Options: `type` (required, `"remote"`), `url` (required), `headers`, `oauth`, `enabled`, `timeout`.
|
|
40
|
+
|
|
41
|
+
## OAuth (remote)
|
|
42
|
+
|
|
43
|
+
- Automatic: OpenCode detects the 401, runs the OAuth flow (dynamic client registration, RFC 7591), and stores tokens. No config needed for most servers.
|
|
44
|
+
- Pre-registered credentials: `"oauth": { "clientId": "...", "clientSecret": "...", "scope": "tools:read" }` (use `{env:VAR}` for secrets).
|
|
45
|
+
- `"oauth": false` disables auto-OAuth (e.g. API-key servers).
|
|
46
|
+
- CLI: `opencode mcp auth <name>`, `opencode mcp list`, `opencode mcp logout <name>`, `opencode mcp debug <name>`.
|
|
47
|
+
|
|
48
|
+
## Tool scoping
|
|
49
|
+
|
|
50
|
+
MCP tools register as `<servername>_<toolname>`, so glob patterns control them like any tool:
|
|
51
|
+
|
|
52
|
+
- Disable globally: `"tools": { "my-mcp*": false }` or via permission `"my-mcp_*": "ask"` (permission patterns match built-ins, custom tools, and MCP tools alike).
|
|
53
|
+
- Enable per agent only: disable globally in `tools`, then set `"tools": { "my-mcp*": true }` inside the agent's config.
|
|
54
|
+
- Glob syntax: `*` (any chars), `?` (one char); last matching permission rule wins.
|
|
55
|
+
- Per-server enable/disable: `"enabled": false` on the server entry hides all its tools without deleting config.
|
|
@@ -34,27 +34,19 @@ Reference examples for routing decisions. Each shows: request → analysis → a
|
|
|
34
34
|
**Execution:**
|
|
35
35
|
1. Single: `opencode-mcp-integrator` - configure server in opencode.json with permission rules
|
|
36
36
|
|
|
37
|
-
**Config produced
|
|
37
|
+
**Config produced** (disable the tools globally, enable them for `build` only):
|
|
38
38
|
```json
|
|
39
39
|
{
|
|
40
40
|
"mcp": {
|
|
41
41
|
"my-company-tools": {
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
"permission": {
|
|
47
|
-
"tool": {
|
|
48
|
-
"deploy-*": "deny"
|
|
42
|
+
"type": "local",
|
|
43
|
+
"command": ["npx", "-y", "@my-company/mcp-server"]
|
|
49
44
|
}
|
|
50
45
|
},
|
|
46
|
+
"tools": { "deploy-*": false },
|
|
51
47
|
"agent": {
|
|
52
48
|
"build": {
|
|
53
|
-
"
|
|
54
|
-
"tool": {
|
|
55
|
-
"deploy-*": "allow"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
49
|
+
"tools": { "deploy-*": true }
|
|
58
50
|
}
|
|
59
51
|
}
|
|
60
52
|
}
|
|
@@ -116,23 +108,18 @@ export const CommitValidatorPlugin = async (ctx) => {
|
|
|
116
108
|
**Execution:**
|
|
117
109
|
1. Single: `opencode-agent-designer` - create agent frontmatter
|
|
118
110
|
|
|
119
|
-
**Agent structure
|
|
111
|
+
**Agent structure** (`.opencode/agents/pr-reviewer.md`; the filename becomes the agent name):
|
|
120
112
|
```markdown
|
|
121
113
|
---
|
|
122
|
-
name: pr-reviewer
|
|
123
114
|
description: Review pull requests with security and quality focus
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
write: false
|
|
127
|
-
edit: false
|
|
128
|
-
github: true
|
|
129
|
-
read: true
|
|
130
|
-
grep: true
|
|
131
|
-
glob: true
|
|
115
|
+
mode: subagent
|
|
116
|
+
model: anthropic/claude-sonnet-4-5
|
|
132
117
|
permission:
|
|
118
|
+
bash: deny
|
|
119
|
+
edit: deny
|
|
120
|
+
"github_*": allow
|
|
133
121
|
skill:
|
|
134
|
-
"git-release":
|
|
135
|
-
model: anthropic/claude-3.5-sonnet
|
|
122
|
+
"git-release": allow
|
|
136
123
|
---
|
|
137
124
|
|
|
138
125
|
## Role
|
|
@@ -144,6 +131,8 @@ Review PRs for code quality, security vulnerabilities, and test coverage.
|
|
|
144
131
|
3. Provide structured feedback
|
|
145
132
|
```
|
|
146
133
|
|
|
134
|
+
`read`/`grep`/`glob` need no entry (tools are enabled by default); `edit` denies `write` and `apply_patch` too.
|
|
135
|
+
|
|
147
136
|
---
|
|
148
137
|
|
|
149
138
|
## Example 5: Multi-Component Plugin Package
|
|
@@ -175,18 +164,14 @@ opencode-devtools/
|
|
|
175
164
|
|
|
176
165
|
---
|
|
177
166
|
|
|
178
|
-
## Example 6: Local-Only Session Notification Plugin (plugin-engineer
|
|
167
|
+
## Example 6: Local-Only Session Notification Plugin (plugin-engineer)
|
|
179
168
|
|
|
180
169
|
**User Request:**
|
|
181
170
|
> Create a plugin that sends a desktop notification when a session completes or errors. This is for my local machine only, not for publishing.
|
|
182
171
|
|
|
183
172
|
**Analysis:**
|
|
184
173
|
- Plugin with event hooks → `opencode-plugin-engineer`
|
|
185
|
-
-
|
|
186
|
-
- No npm distribution needed
|
|
187
|
-
- No skills or commands to bundle
|
|
188
|
-
- Single local plugin file, not a package
|
|
189
|
-
- User explicitly said "local machine only"
|
|
174
|
+
- Local machine only, single plugin file → `opencode-plugin-engineer` (distribution intent is the packager test; see the table below)
|
|
190
175
|
|
|
191
176
|
**Execution:**
|
|
192
177
|
1. Single: `opencode-plugin-engineer` - create local plugin with event hooks
|
|
@@ -214,23 +199,17 @@ export const SessionNotifyPlugin: Plugin = async ({ $ }) => {
|
|
|
214
199
|
| Local-only plugin | Local package for sharing |
|
|
215
200
|
| Event hooks / behavior modification | Bundling skills + commands as assets|
|
|
216
201
|
| Single `.ts`/`.js` file | Full package structure with package.json |
|
|
217
|
-
|
|
|
218
|
-
| Injecting env vars, notifications | Combining multiple opencode artifacts |
|
|
202
|
+
| Single-machine use | Local file:// sharing across projects |
|
|
219
203
|
|
|
220
204
|
---
|
|
221
205
|
|
|
222
|
-
## Example 7: Plugin with Embedded Static Instructions (plugin-engineer
|
|
206
|
+
## Example 7: Plugin with Embedded Static Instructions (plugin-engineer)
|
|
223
207
|
|
|
224
208
|
**User Request:**
|
|
225
209
|
> Create a customer support plugin that injects a "support-agent" prompt into sessions. The prompt should be embedded in the plugin file itself, not as separate files.
|
|
226
210
|
|
|
227
211
|
**Analysis:**
|
|
228
|
-
-
|
|
229
|
-
- **NOT** packager because:
|
|
230
|
-
- Instructions are embedded as string literals in code
|
|
231
|
-
- No separate `.md` files to bundle
|
|
232
|
-
- Content is generated/managed programmatically within the plugin
|
|
233
|
-
- Not a distributable asset package
|
|
212
|
+
- Prompt embedded as a string literal in the plugin file, managed programmatically at runtime → `opencode-plugin-engineer`
|
|
234
213
|
|
|
235
214
|
**Execution:**
|
|
236
215
|
1. Single: `opencode-plugin-engineer` - create plugin with embedded prompt string
|
|
@@ -270,24 +249,6 @@ export const SupportAgentPlugin: Plugin = async ({ client }) => {
|
|
|
270
249
|
| Instructions embedded as string in code | Separate `.md` files as assets |
|
|
271
250
|
| Content generated programmatically | Static markdown files to distribute|
|
|
272
251
|
| Single file contains logic + content | Package structure with multiple files |
|
|
273
|
-
| Runtime-generated prompts | Pre-authored skill/command files |
|
|
274
|
-
| Agent definitions with inline prompts | Skill SKILL.md + command .md bundles |
|
|
275
|
-
|
|
276
|
-
**Real-world pattern (reference):**
|
|
277
|
-
```typescript
|
|
278
|
-
// Agent with embedded prompt - NO separate .md files
|
|
279
|
-
export const agent: AgentConfig = {
|
|
280
|
-
name: "data-analyzer",
|
|
281
|
-
prompt: `
|
|
282
|
-
Analyze data files and produce reports.
|
|
283
|
-
|
|
284
|
-
## Steps
|
|
285
|
-
1. Read input files
|
|
286
|
-
2. Parse and validate
|
|
287
|
-
3. Generate summary statistics
|
|
288
|
-
`
|
|
289
|
-
}
|
|
290
|
-
```
|
|
291
252
|
|
|
292
253
|
---
|
|
293
254
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# OpenCode plugins — fundamentals
|
|
2
|
+
|
|
3
|
+
Plugins are JS/TS modules that hook into OpenCode events and customize behavior.
|
|
4
|
+
|
|
5
|
+
Locations:
|
|
6
|
+
|
|
7
|
+
- Project: `.opencode/plugins/`
|
|
8
|
+
- Global: `~/.config/opencode/plugins/`
|
|
9
|
+
|
|
10
|
+
Files in these directories load automatically at startup. npm packages can be loaded via the `plugin` array in `opencode.json`. Load order: global config → project config → global plugin dir → project plugin dir.
|
|
11
|
+
|
|
12
|
+
## Plugin shape
|
|
13
|
+
|
|
14
|
+
A plugin exports one or more async functions. Each receives a context and returns a hooks object:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import type { Plugin } from "@opencode-ai/plugin"
|
|
18
|
+
|
|
19
|
+
export const MyPlugin: Plugin = async ({ project, client, $, directory, worktree }) => {
|
|
20
|
+
return {
|
|
21
|
+
// hook implementations
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Context: `project` (project info), `directory` (cwd), `worktree` (git worktree root), `client` (opencode SDK client), `$` (Bun shell API).
|
|
27
|
+
|
|
28
|
+
## Config hooks
|
|
29
|
+
|
|
30
|
+
Returning a `tool` object adds custom tools; a plugin tool that shares a built-in tool's name takes precedence:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { type Plugin, tool } from "@opencode-ai/plugin"
|
|
34
|
+
|
|
35
|
+
export const CustomToolsPlugin: Plugin = async (ctx) => {
|
|
36
|
+
return {
|
|
37
|
+
tool: {
|
|
38
|
+
mytool: tool({
|
|
39
|
+
description: "What the tool does",
|
|
40
|
+
args: { foo: tool.schema.string() },
|
|
41
|
+
async execute(args, context) {
|
|
42
|
+
const { directory, worktree } = context
|
|
43
|
+
return `Hello ${args.foo} from ${directory}`
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Event hooks
|
|
52
|
+
|
|
53
|
+
Hooks are named event handlers: `"<event>": async (input, output) => { ... }`.
|
|
54
|
+
|
|
55
|
+
Key events:
|
|
56
|
+
|
|
57
|
+
- Commands: `command.executed`
|
|
58
|
+
- Files: `file.edited`, `file.watcher.updated`
|
|
59
|
+
- Messages: `message.updated`, `message.part.updated`, `message.part.removed`, `message.removed`
|
|
60
|
+
- Permissions: `permission.asked`, `permission.replied`
|
|
61
|
+
- Sessions: `session.created`, `session.idle`, `session.updated`, `session.error`, `session.compacted`, `session.deleted`, `session.diff`, `session.status`
|
|
62
|
+
- Tools: `tool.execute.before`, `tool.execute.after`
|
|
63
|
+
- Shell: `shell.env`
|
|
64
|
+
- TUI: `tui.prompt.append`, `tui.command.execute`, `tui.toast.show`
|
|
65
|
+
- Other: `installation.updated`, `lsp.client.diagnostics`, `lsp.updated`, `server.connected`, `todo.updated`
|
|
66
|
+
|
|
67
|
+
A catch-all `event: async ({ event }) => {...}` hook receives every event (`event.type` switches on it).
|
|
68
|
+
|
|
69
|
+
`tool.execute.before` can inspect/modify `output.args` or throw to block; `shell.env` mutates `output.env`.
|
|
70
|
+
|
|
71
|
+
Compaction hook `experimental.session.compacting` can append via `output.context.push(...)` or fully replace the prompt via `output.prompt`.
|
|
72
|
+
|
|
73
|
+
## Dependencies and logging
|
|
74
|
+
|
|
75
|
+
- Local plugins can use npm packages: add a `package.json` to the config directory (`.opencode/package.json`); OpenCode runs `bun install` at startup.
|
|
76
|
+
- Prefer structured logging via `client.app.log({ body: { service, level, message, extra } })` over `console.log`. Levels: `debug`, `info`, `warn`, `error`.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Prompt engineering — distilled best practices
|
|
2
|
+
|
|
3
|
+
Distilled from Anthropic's Claude prompting best practices and skill-authoring best practices. Apply to agent prompts, skill bodies, and command templates.
|
|
4
|
+
|
|
5
|
+
## Core principles
|
|
6
|
+
|
|
7
|
+
- **Be clear and direct.** State the desired output, format, and constraints explicitly. If you want above-and-beyond behavior, ask for it. The colleague test: could someone with minimal context follow your prompt?
|
|
8
|
+
- **Explain why.** Give context/motivation for rules ("never use ellipses because a TTS engine reads this aloud"). The model generalizes from the explanation.
|
|
9
|
+
- **Sequence matters.** Use numbered steps or bullets when order or completeness matters. Put critical instructions at the end of long prompts.
|
|
10
|
+
- **Give a role.** A one-sentence persona in the system prompt focuses tone and behavior ("You are a code reviewer focused on security...").
|
|
11
|
+
|
|
12
|
+
## Examples and structure
|
|
13
|
+
|
|
14
|
+
- Few-shot examples (3–5) are the most reliable way to steer format, tone, and structure. Make them relevant, diverse, and wrapped in tags (`<example>` inside `<examples>`).
|
|
15
|
+
- Use XML tags to separate instructions, context, documents, and inputs in complex prompts (`<instructions>`, `<context>`, `<documents>`). Consistent, descriptive tag names.
|
|
16
|
+
- Long context: put longform data near the top and the query/instructions at the end; wrap each document in `<document>` tags with metadata; ask the model to quote relevant passages before answering.
|
|
17
|
+
|
|
18
|
+
## Output control
|
|
19
|
+
|
|
20
|
+
- Say what to do, not what not to do ("write flowing prose paragraphs" beats "don't use bullets").
|
|
21
|
+
- Match your prompt's style to the desired output style (markdown-heavy prompts yield markdown-heavy answers).
|
|
22
|
+
- Use structured outputs (JSON/XML schemas) when precise parsing is needed; request verbatim structure with an explicit template.
|
|
23
|
+
|
|
24
|
+
## Tool use and agentic behavior
|
|
25
|
+
|
|
26
|
+
- Models may suggest instead of act. Be explicit: "Change this function" vs "Can you suggest changes". Prompt blocks can set a default-to-action or do-not-act bias.
|
|
27
|
+
- Independent tool calls can run in parallel; this is steerable ("make all independent calls in parallel" / "execute sequentially").
|
|
28
|
+
- Prefer general guidance over aggressive over-prompting ("Use this tool when..." beats "CRITICAL: you MUST..."). Over-instruction causes overtriggering.
|
|
29
|
+
- Self-check: "Before you finish, verify your answer against the criteria" catches errors; ask for it only when quality demands it.
|
|
30
|
+
- Guard rails for agents: confirm before irreversible or shared-system actions; avoid over-engineering (only requested changes, no speculative abstractions); investigate files before answering (never speculate about unread code); write general solutions, don't hardcode to tests.
|
|
31
|
+
- Subagents: use for parallelizable, context-isolated workstreams; work directly for simple sequential tasks.
|
|
32
|
+
|
|
33
|
+
## Skill and instruction authoring
|
|
34
|
+
|
|
35
|
+
- **Concise is key** — the context window is a public good. Only add context the model doesn't already have; make every paragraph justify its tokens.
|
|
36
|
+
- **Set degrees of freedom** to match fragility: high freedom (heuristics) for flexible tasks; low freedom (exact scripts, "do not modify this command") for fragile operations.
|
|
37
|
+
- **Descriptions drive selection**: third person, what it does + when to use it, with specific trigger terms. Avoid vague names (`helper`, `utils`) and vague descriptions.
|
|
38
|
+
- **Progressive disclosure**: overview in the main file; details in separately linked files, one level deep (nested references cause partial reads). Table of contents for files over 100 lines.
|
|
39
|
+
- **Workflows and feedback loops**: numbered steps with copy-paste checklists for complex tasks; validate → fix → repeat loops for quality-critical operations; create verifiable intermediate outputs before destructive or batch operations.
|
|
40
|
+
- **Stability**: no time-sensitive information; consistent terminology (pick one term per concept); avoid Windows-style paths — always forward slashes.
|
|
41
|
+
- **Provide a default, not a menu**: one recommended approach with an escape hatch for exceptions, not five equivalent options.
|
|
42
|
+
|
|
43
|
+
## Iteration
|
|
44
|
+
|
|
45
|
+
- Test with real tasks and observe how the instructions are actually navigated; iterate on observed failures, not assumptions.
|
|
46
|
+
- Build evaluations before extensive documentation: identify gaps, write minimal instructions to close them, measure against baseline.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# OpenCode skills — fundamentals
|
|
2
|
+
|
|
3
|
+
Skills are reusable instruction packages discovered on-demand via the native `skill` tool. Agents see each skill's name and description in `<available_skills>` and load the full SKILL.md only when relevant.
|
|
4
|
+
|
|
5
|
+
Locations (one folder per skill):
|
|
6
|
+
|
|
7
|
+
- Project: `.opencode/skills/<name>/SKILL.md`
|
|
8
|
+
- Global: `~/.config/opencode/skills/<name>/SKILL.md`
|
|
9
|
+
- Compatible paths: `.claude/skills/<name>/SKILL.md`, `.agents/skills/<name>/SKILL.md` (project and home variants)
|
|
10
|
+
|
|
11
|
+
## Frontmatter rules
|
|
12
|
+
|
|
13
|
+
Only these fields are recognized; unknown fields are ignored:
|
|
14
|
+
|
|
15
|
+
| Field | Required | Rules |
|
|
16
|
+
| --- | --- | --- |
|
|
17
|
+
| `name` | yes | 1–64 chars, lowercase alphanumeric with single hyphens (`^[a-z0-9]+(-[a-z0-9]+)*$`), no leading/trailing `-`, no `--`, must match the folder name. |
|
|
18
|
+
| `description` | yes | 1–1024 chars. Third person; state what the skill does AND when to use it. This drives skill selection — be specific and include key trigger terms. |
|
|
19
|
+
| `license` | no | e.g. `MIT`. |
|
|
20
|
+
| `compatibility` | no | e.g. `opencode`. |
|
|
21
|
+
| `metadata` | no | String-to-string map. |
|
|
22
|
+
|
|
23
|
+
If a skill does not show up: verify `SKILL.md` capitalization, required frontmatter, unique names across locations, and that permissions don't `deny` it.
|
|
24
|
+
|
|
25
|
+
## Progressive disclosure
|
|
26
|
+
|
|
27
|
+
- Metadata (name + description) is pre-loaded at startup; the body is read on demand; bundled files are read only as needed — no context penalty until accessed.
|
|
28
|
+
- Keep SKILL.md under ~500 lines; split deeper content into separate files.
|
|
29
|
+
- Default assumption: the model is already smart — only add context it doesn't have.
|
|
30
|
+
|
|
31
|
+
## Co-located references pattern
|
|
32
|
+
|
|
33
|
+
Bundle detail files next to SKILL.md in the skill folder:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
my-skill/
|
|
37
|
+
├── SKILL.md # overview + navigation (loaded when triggered)
|
|
38
|
+
├── reference.md # loaded as needed
|
|
39
|
+
├── examples.md # loaded as needed
|
|
40
|
+
└── scripts/tool.py # executed, not loaded
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- Keep references **one level deep** from SKILL.md — nested references cause partial reads. Link each file directly from SKILL.md.
|
|
44
|
+
- Add a table of contents at the top of reference files over 100 lines.
|
|
45
|
+
- Make execution intent explicit: "Run `scripts/foo.py`" (execute) vs "See `scripts/foo.py`" (read as reference).
|
|
46
|
+
|
|
47
|
+
## Base-directory convention
|
|
48
|
+
|
|
49
|
+
Address co-located files **relative to the skill's own directory** (its base directory), always with **forward slashes** (`reference/guide.md`, not `reference\guide.md` or absolute paths). Forward-slash relative paths work on every platform.
|
|
50
|
+
|
|
51
|
+
## Authoring quick rules
|
|
52
|
+
|
|
53
|
+
- General authoring rules (degrees of freedom, workflows, defaults, terminology): see `prompt-engineering.md`.
|
|
54
|
+
- Gerund names read well (`processing-pdfs`); vague names (`helper`, `utils`) hide the skill from selection.
|
|
55
|
+
- Gate access with `permission.skill` glob patterns (`"internal-*": "deny"`); disable entirely with `tools: { skill: false }`.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# OpenCode tools — fundamentals
|
|
2
|
+
|
|
3
|
+
By default all tools are enabled and need no permission to run. Control them via the `permission` config (global or per agent).
|
|
4
|
+
|
|
5
|
+
## Built-in tools
|
|
6
|
+
|
|
7
|
+
| Tool | Purpose | Permission key |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `bash` | Execute shell commands | `bash` |
|
|
10
|
+
| `read` | Read files (supports line ranges) | `read` |
|
|
11
|
+
| `edit` | Exact string replacement in files | `edit` |
|
|
12
|
+
| `write` | Create/overwrite files | `edit` |
|
|
13
|
+
| `apply_patch` | Apply patch files | `edit` |
|
|
14
|
+
| `grep` | Regex content search | `grep` |
|
|
15
|
+
| `glob` | File pattern matching | `glob` |
|
|
16
|
+
| `skill` | Load a SKILL.md | `skill` |
|
|
17
|
+
| `todowrite` | Task lists (disabled for subagents by default) | `todowrite` |
|
|
18
|
+
| `webfetch` | Fetch a URL | `webfetch` |
|
|
19
|
+
| `websearch` | Web search (provider/env gated) | `websearch` |
|
|
20
|
+
| `question` | Ask the user structured questions | `question` |
|
|
21
|
+
| `lsp` | LSP intelligence (experimental) | `lsp` |
|
|
22
|
+
|
|
23
|
+
`edit`, `write`, and `apply_patch` share the single `edit` permission. `grep`/`glob` use ripgrep and respect `.gitignore` (a `.ignore` file can re-include paths). Hooks must check `input.tool === "apply_patch"` and use `output.args.patchText` (paths embedded in marker lines).
|
|
24
|
+
|
|
25
|
+
## Custom tools
|
|
26
|
+
|
|
27
|
+
Defined in `.opencode/tools/` (project) or `~/.config/opencode/tools/` (global). The filename becomes the tool name (`database.ts` → `database` tool).
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { tool } from "@opencode-ai/plugin"
|
|
31
|
+
|
|
32
|
+
export default tool({
|
|
33
|
+
description: "Query the project database",
|
|
34
|
+
args: {
|
|
35
|
+
query: tool.schema.string().describe("SQL query to execute"),
|
|
36
|
+
},
|
|
37
|
+
async execute(args, context) {
|
|
38
|
+
return `Executed: ${args.query}`
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Key API points:
|
|
44
|
+
|
|
45
|
+
- `tool.schema` is Zod (`tool.schema.string()`, `.number()`, `.describe(...)`); or import `zod` directly and export a plain object.
|
|
46
|
+
- `execute(args, context)` — context provides `agent`, `sessionID`, `messageID`, `directory` (session cwd), `worktree` (git worktree root). Use `context.worktree` for repo-root paths.
|
|
47
|
+
- Multiple named exports in one file become separate tools named `<filename>_<exportname>` (`math_add`, `math_multiply`).
|
|
48
|
+
- A custom tool with a built-in tool's name overrides it (prefer unique names; use permissions to just disable).
|
|
49
|
+
- The definition is TS/JS, but `execute` can invoke scripts in any language (e.g. via `Bun.$`).
|