Download packages/web/src/content/docs/ko/plugins.mdx from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 10.5 kB
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/web/src/content/docs/ko/plugins.mdx
- Command line
-
hf download hf://SaylorTwift/opencode/packages/web/src/content/docs/ko/plugins.mdx
-
curl -L -o plugins.mdx https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/web/src/content/docs/ko/plugins.mdx
10.5 kB
| title: ํ๋ฌ๊ทธ์ธ | |
| description: OpenCode๋ฅผ ํ์ฅํ๊ธฐ ์ํด ์์ ๋ง์ ํ๋ฌ๊ทธ์ธ์ ์์ฑํ์ธ์. | |
| ํ๋ฌ๊ทธ์ธ์ ๋ค์ํ ์ด๋ฒคํธ์ ์ฌ์ฉ์ ์ ์ ํ๋์ผ๋ก ํํนํ์ฌ opencode๋ฅผ ํ์ฅ ํ ์ ์์ต๋๋ค. ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ์ฌ ์๋ก์ด ๊ธฐ๋ฅ์ ์ถ๊ฐํ๊ฑฐ๋, ์ธ๋ถ ์๋น์ค์ ํตํฉํ๊ฑฐ๋, opencode์ ๊ธฐ๋ณธ ๋์์ ์์ ํ ์ ์์ต๋๋ค. | |
| ์๋ฅผ ๋ค์ด, ์ปค๋ฎค๋ํฐ์ ์ํด ์์ฑ ๋ [plugins](/docs/ecosystem#plugins)๋ฅผ ํ์ธํ์ญ์์ค. | |
| ## ํ๋ฌ๊ทธ์ธ ์ฌ์ฉ | |
| ํ๋ฌ๊ทธ์ธ์ ๋ก๋ํ๋ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. | |
| ### ๋ก์ปฌ ํ์ผ์์ | |
| ํ๋ฌ๊ทธ์ธ ๋๋ ํ ๋ฆฌ์ JavaScript ๋๋ TypeScript ํ์ผ์ ๋ฐฐ์นํฉ๋๋ค. | |
| - `.opencode/plugins/` - ํ๋ก์ ํธ ๋ ๋ฒจ ํ๋ฌ๊ทธ์ธ | |
| - `~/.config/opencode/plugins/` - ๊ธ๋ก๋ฒ ํ๋ฌ๊ทธ์ธ | |
| ์ด ๋๋ ํ ๋ฆฌ์ ํ์ผ์ ์์ ์ ์๋์ผ๋ก ๋ก๋๋ฉ๋๋ค. | |
| ### npm์์ | |
| config ํ์ผ์ npm ํจํค์ง๋ฅผ ์ง์ ํฉ๋๋ค. | |
| ```json title="opencode.json" | |
| { | |
| "$schema": "https://opencode.ai/config.json", | |
| "plugin": ["opencode-helicone-session", "opencode-wakatime", "@my-org/custom-plugin"] | |
| } | |
| ``` | |
| ์ผ๋ฐ ํจํค์ง ๋ฐ ์ค์ฝํ npm ํจํค์ง ๋ชจ๋ ์ง์๋ฉ๋๋ค. | |
| [ecosystem](/docs/ecosystem#plugins)์์ ์ฌ์ฉํ ์ ์๋ ํ๋ฌ๊ทธ์ธ์ ์ฐพ์๋ณด์ธ์. | |
| ### ํ๋ฌ๊ทธ์ธ์ด ์ค์น๋๋ ๋ฐฉ๋ฒ | |
| **npm ํ๋ฌ๊ทธ์ธ**์ ์์์ Bun์ ์ฌ์ฉํ์ฌ ์๋์ผ๋ก ์ค์น๋ฉ๋๋ค. ํจํค์ง์ ๊ทธ ์์กด์ฑ์ `~/.cache/opencode/node_modules/`์ ์บ์๋ฉ๋๋ค. | |
| **๋ก์ปฌ ํ๋ฌ๊ทธ์ธ**์ ํ๋ฌ๊ทธ์ธ ๋๋ ํ ๋ฆฌ์์ ์ง์ ๋ก๋๋ฉ๋๋ค. ์ธ๋ถ ํจํค์ง๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ๊ตฌ์ฑ ๋๋ ํ ๋ฆฌ ๋ด์ `package.json`์ ์์ฑํด์ผ ํ๊ฑฐ๋([์์กด์ฑ](#์์กด์ฑ) ์ฐธ์กฐ), ํ๋ฌ๊ทธ์ธ์ npm์ ๊ฒ์ํ๊ณ [config์ ์ถ๊ฐ](/docs/config#plugins)ํด์ผ ํฉ๋๋ค. | |
| ### ๋ก๋ ์์ | |
| ํ๋ฌ๊ทธ์ธ์ ๋ชจ๋ ์์ค์์ ๋ก๋๋๋ฉฐ ๋ชจ๋ ํํฌ๋ ์์๋๋ก ์คํ๋ฉ๋๋ค. ๋ก๋ ์์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
| 1. ๊ธ๋ก๋ฒ ๊ตฌ์ฑ (`~/.config/opencode/opencode.json`) | |
| 2. ํ๋ก์ ํธ ๊ตฌ์ฑ (`opencode.json`) | |
| 3. ๊ธ๋ก๋ฒ ํ๋ฌ๊ทธ์ธ ๋๋ ํ ๋ฆฌ (`~/.config/opencode/plugins/`) | |
| 4. ํ๋ก์ ํธ ํ๋ฌ๊ทธ์ธ ๋๋ ํ ๋ฆฌ (`.opencode/plugins/`) | |
| ์ค๋ณต๋ ์ด๋ฆ๊ณผ ๋ฒ์ ์ npm ํจํค์ง๋ ํ ๋ฒ๋ง ๋ก๋๋ฉ๋๋ค. ํ์ง๋ง ๋ก์ปฌ ํ๋ฌ๊ทธ์ธ๊ณผ npm ํ๋ฌ๊ทธ์ธ์ ์ด๋ฆ์ด ๋น์ทํ๋๋ผ๋ ๋ ๋ค ๋ณ๋๋ก ๋ก๋๋ฉ๋๋ค. | |
| ## ํ๋ฌ๊ทธ์ธ ๋ง๋ค๊ธฐ | |
| ํ๋ฌ๊ทธ์ธ์ ํ๋ ์ด์์ ํ๋ฌ๊ทธ์ธ ํจ์๋ฅผ ๋ด๋ณด๋ด๋ **JavaScript/TypeScript ๋ชจ๋**์ ๋๋ค. ๊ฐ ํจ์๋ context ๊ฐ์ฒด๋ฅผ ์์ ํ๊ณ hooks ๊ฐ์ฒด๋ฅผ ๋ฐํํฉ๋๋ค. | |
| ### ์์กด์ฑ | |
| ๋ก์ปฌ ํ๋ฌ๊ทธ์ธ ๋ฐ ์ฌ์ฉ์ ์ ์ ๋๊ตฌ๋ ์ธ๋ถ npm ํจํค์ง๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. config ๋๋ ํ ๋ฆฌ์ `package.json`์ ์ถ๊ฐํ๊ณ ํ์ํ ์์กด์ฑ์ ๋ช ์ํ์ญ์์ค. | |
| ```json title=".opencode/package.json" | |
| { | |
| "dependencies": { | |
| "shescape": "^2.1.0" | |
| } | |
| } | |
| ``` | |
| opencode๋ ์์ ์ `bun install`์ ์คํํ์ฌ ์ด๋ฅผ ์ค์นํฉ๋๋ค. ์ดํ ํ๋ฌ๊ทธ์ธ ๋ฐ ๋๊ตฌ์์ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค. | |
| ```ts title=".opencode/plugins/my-plugin.ts" | |
| import { escape } from "shescape" | |
| export const MyPlugin = async (ctx) => { | |
| return { | |
| "tool.execute.before": async (input, output) => { | |
| if (input.tool === "bash") { | |
| output.args.command = escape(output.args.command) | |
| } | |
| }, | |
| } | |
| } | |
| ``` | |
| ### ๊ธฐ๋ณธ ๊ตฌ์กฐ | |
| ```js title=".opencode/plugins/example.js" | |
| export const MyPlugin = async ({ project, client, $, directory, worktree }) => { | |
| console.log("Plugin initialized!") | |
| return { | |
| // Hook implementations go here | |
| } | |
| } | |
| ``` | |
| ํ๋ฌ๊ทธ์ธ ํจ์๊ฐ ๋ฐ๋ ์ธ์: | |
| - `project`: ํ์ฌ ํ๋ก์ ํธ ์ ๋ณด. | |
| - `directory`: ํ์ฌ ์์ ๋๋ ํ ๋ฆฌ. | |
| - `worktree`: git worktree ๊ฒฝ๋ก. | |
| - `client`: AI์ ์ํธ ์์ฉ์ ์ํ opencode SDK ํด๋ผ์ด์ธํธ. | |
| - `$`: ๋ช ๋ น์ด๋ฅผ ์คํํ๊ธฐ ์ํ Bun์ [shell API](https://bun.com/docs/runtime/shell). | |
| ### TypeScript ์ง์ | |
| TypeScript ํ๋ฌ๊ทธ์ธ์ ๊ฒฝ์ฐ ํ๋ฌ๊ทธ์ธ ํจํค์ง์์ ํ์ ์ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค. | |
| ```ts title="my-plugin.ts" {1} | |
| import type { Plugin } from "@opencode-ai/plugin" | |
| export const MyPlugin: Plugin = async ({ project, client, $, directory, worktree }) => { | |
| return { | |
| // Type-safe hook implementations | |
| } | |
| } | |
| ``` | |
| ### ์ด๋ฒคํธ | |
| ํ๋ฌ๊ทธ์ธ์ ์๋ ์์ ์น์ ์์ ๋ณผ ์ ์๋ฏ์ด ์ด๋ฒคํธ๋ฅผ ๊ตฌ๋ ํ ์ ์์ต๋๋ค. ์ฌ์ฉ ๊ฐ๋ฅํ ์ด๋ฒคํธ ๋ชฉ๋ก์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. | |
| #### ๋ช ๋ น์ด ์ด๋ฒคํธ | |
| - `command.executed` | |
| #### ํ์ผ ์ด๋ฒคํธ | |
| - `file.edited` | |
| - `file.watcher.updated` | |
| #### ์ค์น ์ด๋ฒคํธ | |
| - `installation.updated` | |
| #### LSP ์ด๋ฒคํธ | |
| - `lsp.client.diagnostics` | |
| - `lsp.updated` | |
| #### ๋ฉ์์ง ์ด๋ฒคํธ | |
| - `message.part.removed` | |
| - `message.part.updated` | |
| - `message.removed` | |
| - `message.updated` | |
| #### ๊ถํ ์ด๋ฒคํธ | |
| - `permission.asked` | |
| - `permission.replied` | |
| #### ์๋ฒ ์ด๋ฒคํธ | |
| - `server.connected` | |
| #### ์ธ์ ์ด๋ฒคํธ | |
| - `session.created` | |
| - `session.compacted` | |
| - `session.deleted` | |
| - `session.diff` | |
| - `session.error` | |
| - `session.idle` | |
| - `session.status` | |
| - `session.updated` | |
| #### Todo ์ด๋ฒคํธ | |
| - `todo.updated` | |
| #### ์ ธ ์ด๋ฒคํธ | |
| - `shell.env` | |
| #### ๋๊ตฌ ์ด๋ฒคํธ | |
| - `tool.execute.after` | |
| - `tool.execute.before` | |
| #### TUI ์ด๋ฒคํธ | |
| - `tui.prompt.append` | |
| - `tui.command.execute` | |
| - `tui.toast.show` | |
| ## ์์ | |
| opencode๋ฅผ ํ์ฅํ๊ธฐ ์ํด ์ฌ์ฉํ ์ ์๋ ํ๋ฌ๊ทธ์ธ ์์ ์ ๋๋ค. | |
| ### ์๋ฆผ ๋ณด๋ด๊ธฐ | |
| ํน์ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ ๋ ์๋ฆผ์ ์ ์ก: | |
| ```js title=".opencode/plugins/notification.js" | |
| export const NotificationPlugin = async ({ project, client, $, directory, worktree }) => { | |
| return { | |
| event: async ({ event }) => { | |
| // Send notification on session completion | |
| if (event.type === "session.idle") { | |
| await $`osascript -e 'display notification "Session completed!" with title "opencode"'` | |
| } | |
| }, | |
| } | |
| } | |
| ``` | |
| macOS์์ AppleScript๋ฅผ ์คํํ๊ธฐ ์ํด `osascript`๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ์ฌ๊ธฐ์๋ ์๋ฆผ์ ๋ณด๋ด๋ ๋ฐ ์ฌ์ฉํฉ๋๋ค. | |
| :::note | |
| opencode ๋ฐ์คํฌํฑ ์ฑ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์๋ต์ด ์ค๋น๋์ด ์๊ฑฐ๋ ์ธ์ ์ค๋ฅ๊ฐ ์์ ๋ ์์คํ ์๋ฆผ์ ์๋์ผ๋ก ๋ณด๋ผ ์ ์์ต๋๋ค. | |
| ::: | |
| ### .env ๋ณดํธ | |
| opencode๊ฐ `.env` ํ์ผ์ ์ฝ์ง ๋ชปํ๋๋ก ๋ฐฉ์ง: | |
| ```javascript title=".opencode/plugins/env-protection.js" | |
| export const EnvProtection = async ({ project, client, $, directory, worktree }) => { | |
| return { | |
| "tool.execute.before": async (input, output) => { | |
| if (input.tool === "read" && output.args.filePath.includes(".env")) { | |
| throw new Error("Do not read .env files") | |
| } | |
| }, | |
| } | |
| } | |
| ``` | |
| ### Inject ํ๊ฒฝ ๋ณ์ | |
| ๋ชจ๋ shell ์คํ(AI ๋๊ตฌ ๋ฐ ์ฌ์ฉ์ terminal)์ ํ๊ฒฝ ๋ณ์ ์ฃผ์ : | |
| ```javascript title=".opencode/plugins/inject-env.js" | |
| export const InjectEnvPlugin = async () => { | |
| return { | |
| "shell.env": async (input, output) => { | |
| output.env.MY_API_KEY = "secret" | |
| output.env.PROJECT_ROOT = input.cwd | |
| }, | |
| } | |
| } | |
| ``` | |
| ### ์ฌ์ฉ์ ์ ์ ๋๊ตฌ | |
| ํ๋ฌ๊ทธ์ธ์ opencode์ ์ฌ์ฉ์ ์ ์ ๋๊ตฌ๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค: | |
| ```ts title=".opencode/plugins/custom-tools.ts" | |
| import { type Plugin, tool } from "@opencode-ai/plugin" | |
| export const CustomToolsPlugin: Plugin = async (ctx) => { | |
| return { | |
| tool: { | |
| mytool: tool({ | |
| description: "This is a custom tool", | |
| args: { | |
| foo: tool.schema.string(), | |
| }, | |
| async execute(args, context) { | |
| const { directory, worktree } = context | |
| return `Hello ${args.foo} from ${directory} (worktree: ${worktree})` | |
| }, | |
| }), | |
| }, | |
| } | |
| } | |
| ``` | |
| `tool` helper๋ opencode๊ฐ ํธ์ถํ ์ ์๋ ์ฌ์ฉ์ ์ ์ ๋๊ตฌ๋ฅผ ๋ง๋ญ๋๋ค. Zod ์คํค๋ง ํจ์๋ฅผ ๋ฐ๊ณ ๋ค์์ ํฌํจํ๋ ๋๊ตฌ ์ ์๋ฅผ ๋ฐํํฉ๋๋ค: | |
| - `description`: ๋๊ตฌ๊ฐ ํ๋ ์ผ | |
| - `args`: ๋๊ตฌ์ ์ธ์์ ๋ํ Zod ์คํค๋ง | |
| - `execute`: ๋๊ตฌ๊ฐ ํธ์ถ๋ ๋ ์คํ๋๋ ํจ์ | |
| ์ฌ์ฉ์ ์ ์ ๋๊ตฌ๋ ๋ด์ฅ ๋๊ตฌ์ ํจ๊ป opencode์์ ์ฌ์ฉํ ์ ์์ต๋๋ค. | |
| :::note | |
| ํ๋ฌ๊ทธ์ธ ๋๊ตฌ๊ฐ ๋ด์ฅ ๋๊ตฌ์ ๊ฐ์ ์ด๋ฆ์ ์ฌ์ฉํ๋ฉด ํ๋ฌ๊ทธ์ธ ๋๊ตฌ๊ฐ ์ฐ์ ์์๋ฅผ ๊ฐ์ต๋๋ค. | |
| ::: | |
| ### ๋ก๊น | |
| ๊ตฌ์กฐํ๋ ๋ก๊น ์ ์ํด `console.log` ๋์ `client.app.log()`๋ฅผ ์ฌ์ฉํ์ญ์์ค: | |
| ```ts title=".opencode/plugins/my-plugin.ts" | |
| export const MyPlugin = async ({ client }) => { | |
| await client.app.log({ | |
| body: { | |
| service: "my-plugin", | |
| level: "info", | |
| message: "Plugin initialized", | |
| extra: { foo: "bar" }, | |
| }, | |
| }) | |
| } | |
| ``` | |
| ๋ ๋ฒจ: `debug`, `info`, `warn`, `error`. [SDK ๋ฌธ์](https://opencode.ai/docs/sdk)๋ฅผ ์ฐธ๊ณ ํ์ธ์. | |
| ### Compaction ํ | |
| ์ธ์ ์ด ์์ถ๋ ๋ ํฌํจ๋๋ ์ปจํ ์คํธ๋ฅผ ์ฌ์ฉ์ ์ง์ ํ ์ ์์ต๋๋ค: | |
| ```ts title=".opencode/plugins/compaction.ts" | |
| import type { Plugin } from "@opencode-ai/plugin" | |
| export const CompactionPlugin: Plugin = async (ctx) => { | |
| return { | |
| "experimental.session.compacting": async (input, output) => { | |
| // Inject additional context into the compaction prompt | |
| output.context.push(` | |
| ## Custom Context | |
| Include any state that should persist across compaction: | |
| - Current task status | |
| - Important decisions made | |
| - Files being actively worked on | |
| `) | |
| }, | |
| } | |
| } | |
| ``` | |
| `experimental.session.compacting` ํ ์ LLM์ด ์ฐ์ ์์ฝ์ ์์ฑํ๊ธฐ ์ ์ ์คํ๋ฉ๋๋ค. ๊ธฐ๋ณธ ์์ถ ํ๋กฌํํธ๊ฐ ๋์น ์ ์๋ ๋๋ฉ์ธ๋ณ ์ปจํ ์คํธ๋ฅผ ์ฃผ์ ํ๋ ๋ฐ ์ฌ์ฉํ์ธ์. | |
| ๋ํ `output.prompt`๋ฅผ ์ค์ ํ์ฌ ์์ถ ํ๋กฌํํธ๋ฅผ ์์ ํ ๋์ฒดํ ์๋ ์์ต๋๋ค: | |
| ```ts title=".opencode/plugins/custom-compaction.ts" | |
| import type { Plugin } from "@opencode-ai/plugin" | |
| export const CustomCompactionPlugin: Plugin = async (ctx) => { | |
| return { | |
| "experimental.session.compacting": async (input, output) => { | |
| // Replace the entire compaction prompt | |
| output.prompt = ` | |
| You are generating a continuation prompt for a multi-agent swarm session. | |
| Summarize: | |
| 1. The current task and its status | |
| 2. Which files are being modified and by whom | |
| 3. Any blockers or dependencies between agents | |
| 4. The next steps to complete the work | |
| Format as a structured prompt that a new agent can use to resume work. | |
| ` | |
| }, | |
| } | |
| } | |
| ``` | |
| `output.prompt`๊ฐ ์ค์ ๋๋ฉด ๊ธฐ๋ณธ ์์ถ ํ๋กฌํํธ๋ฅผ ์์ ํ ๋์ฒดํฉ๋๋ค. ์ด ๊ฒฝ์ฐ `output.context` ๋ฐฐ์ด์ ๋ฌด์๋ฉ๋๋ค. | |