Skip to content
This repository was archived by the owner on Oct 19, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ No ESLint or Prettier configuration exists. When adding:
### Imports

```typescript
// Use type-only imports for types
import type { Plugin } from "@opencode-ai/plugin"
// Use type-only imports or Plugin from @opencode/plugin
import { Plugin } from "@opencode/plugin"

// ESM module syntax only (no CommonJS)
export const AutoTitle: Plugin = async ({ client }) => { ... }
export const plugin = Plugin.define({
id: "autotitle",
async setup(ctx) { ... }
})
export const AutoTitle = plugin
export default AutoTitle
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"node": ">=18.0.0"
},
"devDependencies": {
"@opencode-ai/plugin": "^1.0.0",
"@opencode/plugin": "^2.0.32",
"@types/node": "^20.0.0",
"typescript": "^5.0.0",
"vitest": "^4.0.18"
Expand Down
46 changes: 46 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,49 @@ describe("CHEAP_MODEL_PATTERNS", () => {
expect(fastPattern?.test("fast")).toBe(true)
})
})

describe("OpenCode V2 Plugin Integration", () => {
it("exports a valid V2 plugin definition with id 'autotitle'", async () => {
const { default: AutoTitlePlugin, AutoTitle, plugin } = await import("./index")
expect(plugin.id).toBe("autotitle")
expect(typeof plugin.setup).toBe("function")
expect(AutoTitle.id).toBe("autotitle")
expect(typeof AutoTitle.setup).toBe("function")
expect(AutoTitlePlugin.id).toBe("autotitle")
})

it("subscribes to events in V2 setup context", async () => {
const { AutoTitle } = await import("./index")
let subscribed = false
const mockCtx = {
session: {
get: vi.fn().mockResolvedValue({ title: "2026-03-27" }),
update: vi.fn().mockResolvedValue({}),
messages: vi.fn().mockResolvedValue([]),
},
event: {
subscribe: vi.fn().mockImplementation(() => {
subscribed = true
return (async function* () {})()
}),
},
}

await AutoTitle.setup(mockCtx as any)
expect(mockCtx.event.subscribe).toHaveBeenCalled()
expect(subscribed).toBe(true)
})

it("supports V1 backward-compatible invocation", async () => {
const { AutoTitle } = await import("./index")
const mockClient = {
session: {
get: vi.fn().mockResolvedValue({ title: "2026-03-27" }),
update: vi.fn().mockResolvedValue({}),
},
}

const instance = await AutoTitle({ client: mockClient })
expect(typeof instance.event).toBe("function")
})
})
Loading