summaryrefslogtreecommitdiffhomepage
path: root/packages/plugin
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-08-02 18:50:19 -0400
committerDax Raad <[email protected]>2025-08-02 18:50:19 -0400
commitca031278ca9ca30277620e344f7a95c597a8a0de (patch)
tree93af08a56682986262fb7d2c97cfd77d6a973ff7 /packages/plugin
parentae6e47bb42bbfcbb908cda28f4ec028a7335904e (diff)
downloadopencode-ca031278ca9ca30277620e344f7a95c597a8a0de.tar.gz
opencode-ca031278ca9ca30277620e344f7a95c597a8a0de.zip
wip: plugins
Diffstat (limited to 'packages/plugin')
-rw-r--r--packages/plugin/.gitignore1
-rw-r--r--packages/plugin/package.json21
-rw-r--r--packages/plugin/script/publish.ts18
-rw-r--r--packages/plugin/src/example.ts7
-rw-r--r--packages/plugin/src/index.ts56
-rw-r--r--packages/plugin/tsconfig.json16
6 files changed, 119 insertions, 0 deletions
diff --git a/packages/plugin/.gitignore b/packages/plugin/.gitignore
new file mode 100644
index 000000000..1521c8b76
--- /dev/null
+++ b/packages/plugin/.gitignore
@@ -0,0 +1 @@
+dist
diff --git a/packages/plugin/package.json b/packages/plugin/package.json
new file mode 100644
index 000000000..b7e75af1c
--- /dev/null
+++ b/packages/plugin/package.json
@@ -0,0 +1,21 @@
+{
+ "$schema": "https://json.schemastore.org/package.json",
+ "name": "@opencode-ai/plugin",
+ "version": "0.0.0",
+ "type": "module",
+ "scripts": {
+ "typecheck": "tsc --noEmit"
+ },
+ "exports": {
+ ".": "./src/index.ts"
+ },
+ "files": [
+ "dist"
+ ],
+ "devDependencies": {
+ "typescript": "catalog:",
+ "@hey-api/openapi-ts": "0.80.1",
+ "@tsconfig/node22": "catalog:",
+ "@opencode-ai/sdk": "workspace:*"
+ }
+}
diff --git a/packages/plugin/script/publish.ts b/packages/plugin/script/publish.ts
new file mode 100644
index 000000000..b984fd4f4
--- /dev/null
+++ b/packages/plugin/script/publish.ts
@@ -0,0 +1,18 @@
+#!/usr/bin/env bun
+
+const dir = new URL("..", import.meta.url).pathname
+process.chdir(dir)
+
+import { $ } from "bun"
+
+const snapshot = process.env["OPENCODE_SNAPSHOT"] === "true"
+
+await $`bun tsc`
+
+if (snapshot) {
+ await $`bun publish --tag snapshot --access public`
+ await $`git checkout package.json`
+}
+if (!snapshot) {
+ await $`bun publish --access public`
+}
diff --git a/packages/plugin/src/example.ts b/packages/plugin/src/example.ts
new file mode 100644
index 000000000..ac8c0e344
--- /dev/null
+++ b/packages/plugin/src/example.ts
@@ -0,0 +1,7 @@
+import { Plugin } from "./index"
+
+export const ExamplePlugin: Plugin = async ({ app, client }) => {
+ return {
+ permission: {},
+ }
+}
diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts
new file mode 100644
index 000000000..9040fb517
--- /dev/null
+++ b/packages/plugin/src/index.ts
@@ -0,0 +1,56 @@
+import type { Event, createOpencodeClient, App, Model, Provider, Permission, UserMessage, Part } from "@opencode-ai/sdk"
+import { $ } from "bun"
+
+export type PluginInput = {
+ client: ReturnType<typeof createOpencodeClient>
+ app: App
+ $: $
+}
+export type Plugin = (input: PluginInput) => Promise<Hooks>
+
+export interface Hooks {
+ event?: (input: { event: Event }) => Promise<void>
+ chat?: {
+ /**
+ * Called when a new message is received
+ */
+ message?: (input: {}, output: { message: UserMessage; parts: Part[] }) => Promise<void>
+ /**
+ * Modify parameters sent to LLM
+ */
+ params?: (
+ input: { model: Model; provider: Provider; message: UserMessage },
+ output: { temperature: number; topP: number },
+ ) => Promise<void>
+ }
+ permission?: {
+ /**
+ * Called when a permission is asked
+ */
+ ask?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise<void>
+ }
+ tool?: {
+ execute?: {
+ /**
+ * Called before a tool is executed
+ */
+ before?: (
+ input: { tool: string; sessionID: string; callID: string },
+ output: {
+ args: any
+ },
+ ) => Promise<void>
+ /**
+ * Called after a tool is executed
+ */
+ after?: (
+ input: { tool: string; sessionID: string; callID: string },
+ output: {
+ title: string
+ output: string
+ metadata: any
+ },
+ ) => Promise<void>
+ }
+ }
+}
diff --git a/packages/plugin/tsconfig.json b/packages/plugin/tsconfig.json
new file mode 100644
index 000000000..34d4a8718
--- /dev/null
+++ b/packages/plugin/tsconfig.json
@@ -0,0 +1,16 @@
+{
+ "$schema": "https://json.schemastore.org/tsconfig.json",
+ "extends": "@tsconfig/node22/tsconfig.json",
+ "compilerOptions": {
+ "outDir": "dist",
+ "module": "preserve",
+ "declaration": true,
+ "moduleResolution": "bundler",
+ "customConditions": [
+ "development"
+ ]
+ },
+ "include": [
+ "src"
+ ]
+}