Skip to content

Commit 29313d4

Browse files
committed
fix: restore installed SDK imports for local GitHub tools
1 parent 3410224 commit 29313d4

3 files changed

Lines changed: 71 additions & 1 deletion

File tree

‎.opencode/README.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# OpenCode local tools
2+
3+
This directory contains project-local OpenCode configuration and tools. Its
4+
installed SDK dependency is `@opencode-ai/plugin` 1.18.3. The GitHub tools use
5+
the legacy tool helper exported by `@opencode-ai/plugin/tool`.
6+
7+
The monorepo's workspace package `@opencode/plugin` is a different SDK surface
8+
and does not provide this `tool` export. Keep these project tools bound to the
9+
installed SDK import; changing it to the workspace package prevents OpenCode
10+
from loading the tools.
11+
12+
Run the offline tool contract regression checks from this directory with:
13+
14+
```sh
15+
bun test ./test/tool-sdk.test.ts
16+
```
17+
18+
The checks load both tools, validate their argument schemas and defaults, and
19+
convert the schemas to JSON Schema. They do not call the tools' `execute`
20+
functions or contact GitHub.

‎.opencode/test/tool-sdk.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { expect, test } from "bun:test"
2+
import { tool } from "@opencode-ai/plugin/tool"
3+
import githubPrSearch from "../tool/github-pr-search.ts"
4+
import githubTriage from "../tool/github-triage.ts"
5+
6+
test("GitHub tools load with the installed OpenCode tool SDK", () => {
7+
expect(githubPrSearch.description).toContain("search GitHub pull requests")
8+
expect(githubPrSearch.args.query).toBeInstanceOf(tool.schema.ZodString)
9+
expect(githubPrSearch.execute).toBeFunction()
10+
11+
expect(githubTriage.description).toContain("assign a GitHub issue")
12+
expect(githubTriage.args.team).toBeInstanceOf(tool.schema.ZodEnum)
13+
expect(githubTriage.execute).toBeFunction()
14+
})
15+
16+
test("GitHub triage arguments validate and convert to JSON Schema", () => {
17+
const schema = tool.schema.object(githubTriage.args)
18+
expect(schema.parse({ team: "core" })).toEqual({ team: "core" })
19+
expect(schema.safeParse({ team: "not-a-team" }).success).toBe(false)
20+
21+
expect(tool.schema.toJSONSchema(schema, { io: "input" })).toMatchObject({
22+
type: "object",
23+
properties: {
24+
team: { enum: ["tui", "desktop_web", "core", "inference", "windows"] },
25+
},
26+
required: ["team"],
27+
})
28+
})
29+
30+
test("GitHub PR search arguments validate defaults and convert to JSON Schema", () => {
31+
const schema = tool.schema.object(githubPrSearch.args)
32+
expect(schema.parse({ query: "quota" })).toEqual({ query: "quota", limit: 10, offset: 0 })
33+
expect(schema.parse({ query: "quota", limit: 5, offset: 10 })).toEqual({
34+
query: "quota",
35+
limit: 5,
36+
offset: 10,
37+
})
38+
expect(schema.safeParse({ query: 7 }).success).toBe(false)
39+
expect(schema.safeParse({ query: "quota", limit: "10" }).success).toBe(false)
40+
41+
expect(tool.schema.toJSONSchema(schema, { io: "input" })).toMatchObject({
42+
type: "object",
43+
properties: {
44+
query: { type: "string" },
45+
limit: { type: "number", default: 10 },
46+
offset: { type: "number", default: 0 },
47+
},
48+
required: ["query"],
49+
})
50+
})

‎.opencode/tool/github-pr-search.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// <reference path="../env.d.ts" />
2-
import { tool } from "@opencode/plugin"
2+
import { tool } from "@opencode-ai/plugin/tool"
33
async function githubFetch(endpoint: string, options: RequestInit = {}) {
44
const response = await fetch(`https://api.github.com${endpoint}`, {
55
...options,

0 commit comments

Comments
 (0)