Skip to content

Commit 6a2c3e9

Browse files
authored
feat(plugin): add typed rpc and custom events (#46105)
1 parent 4afd8e8 commit 6a2c3e9

107 files changed

Lines changed: 6036 additions & 521 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Examples: `fix(tui): simplify thinking toggle styling`, `docs: update contributi
4646
### General Principles
4747

4848
- Keep things in one function unless composable or reusable
49+
- Validate unknown values once at the boundary that owns them. Pass typed values inward instead of repeating `typeof value === "object"` and property-existence checks. Do not defensively revalidate values already guaranteed by a schema, constructor, or internal type.
4950
- Do not extract single-use helpers preemptively. Inline the logic at the call site unless the helper is reused, hides a genuinely complex boundary, or has a clear independent name that improves the caller.
5051
- Before adding complexity for a speculative or vanishingly unlikely race or security edge case, explain the concrete failure mode, likelihood, and complexity cost to the user and get their buy-in. Do not silently expand scope for theoretical robustness.
5152
- Avoid `try`/`catch` where possible

‎bun.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/app/e2e/regression/project-extensions.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ test("project Extensions stays inside settings while plugins load", async ({ pag
6565
data: (project ? ["shared-plugin", "project-plugin"] : ["shared-plugin"]).map((id) => ({
6666
id,
6767
source: { type: "package", package: id },
68-
status: "active",
69-
tui: false,
68+
state: { status: "active" },
69+
features: { server: true },
7070
})),
7171
},
7272
})

‎packages/app/e2e/regression/settings-loading.spec.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ test("extensions opens without waiting for MCPs or plugins", async ({ page }) =>
8383
json: {
8484
location: { directory },
8585
data: [
86-
{ id: "demo-plugin", source: { type: "package", package: "demo-plugin" }, status: "active", tui: false },
86+
{
87+
id: "demo-plugin",
88+
source: { type: "package", package: "demo-plugin" },
89+
state: { status: "active" },
90+
features: { server: true },
91+
},
8792
],
8893
},
8994
})

‎packages/app/src/providers/catalog/plugin.test.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ import { pluginLabels } from "./plugin"
55
describe("pluginLabels", () => {
66
test("omits built-in plugins", () => {
77
const plugins: PluginInfo[] = [
8-
{ id: "opencode.internal", source: { type: "builtin" }, status: "active", tui: false },
9-
{ id: "package-plugin", source: { type: "package", package: "example" }, status: "active", tui: false },
10-
{ id: "local-plugin", source: { type: "local", path: "/tmp/plugin.ts" }, status: "active", tui: false },
11-
{ id: "sdk-plugin", source: { type: "sdk" }, status: "active", tui: false },
8+
{ id: "opencode.internal", source: { type: "builtin" }, state: { status: "active" }, features: { server: true } },
9+
{
10+
id: "package-plugin",
11+
source: { type: "package", package: "example" },
12+
state: { status: "active" },
13+
features: { server: true },
14+
},
15+
{
16+
id: "local-plugin",
17+
source: { type: "local", path: "/tmp/plugin.ts" },
18+
state: { status: "active" },
19+
features: { server: true },
20+
},
21+
{ id: "sdk-plugin", source: { type: "sdk" }, state: { status: "active" }, features: { server: true } },
1222
]
1323

1424
expect(pluginLabels(plugins)).toEqual(["package-plugin", "local-plugin", "sdk-plugin"])

‎packages/cli/src/commands/handlers/plugin/list.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EOL } from "node:os"
2+
import path from "node:path"
23
import { Effect } from "effect"
34
import { OpenCode, type PluginInfo } from "@opencode-ai/client"
45
import { Service } from "@opencode-ai/client/effect/service"
@@ -7,7 +8,7 @@ import { Runtime } from "../../../framework/runtime"
78
import { ServiceConfig } from "../../../services/service-config"
89
import { Config } from "../../../config"
910
import { Global } from "@opencode-ai/util/global"
10-
import { discoverTuiPlugins, tuiPluginDirectories } from "@opencode-ai/tui/plugin/discovery"
11+
import { discoverTuiPlugins, localPluginDirectories } from "@opencode-ai/tui/plugin/discovery"
1112

1213
export default Runtime.handler(
1314
Commands.commands.plugin.commands.list,
@@ -19,7 +20,7 @@ export default Runtime.handler(
1920
const global = yield* Global.Service
2021
const info = yield* config.get()
2122
const discovered = yield* Effect.promise(() =>
22-
tuiPluginDirectories(process.cwd(), global.config).then(discoverTuiPlugins),
23+
localPluginDirectories(process.cwd(), global.config).then(discoverTuiPlugins),
2324
)
2425
const output = format(
2526
response.data,
@@ -48,11 +49,15 @@ export function format(
4849
const server = plugins
4950
.filter((plugin) => builtin || plugin.source.type !== "builtin")
5051
.toSorted((a, b) => name(a).localeCompare(name(b)))
51-
.map((plugin) => `${name(plugin)} (${plugin.status})`)
52+
.map((plugin) => `${name(plugin)} (${plugin.state.status})`)
5253
const advertised = plugins.flatMap((plugin) =>
53-
plugin.status === "active" && plugin.tui && plugin.source.type === "package"
54-
? [{ target: plugin.source.package, source: "advertised" as const }]
55-
: [],
54+
plugin.state.status !== "active" || !plugin.features.tui
55+
? []
56+
: plugin.source.type === "package"
57+
? [{ target: plugin.source.package, source: "advertised" as const }]
58+
: plugin.source.type === "local"
59+
? [{ target: path.dirname(plugin.source.path), source: "advertised" as const }]
60+
: [],
5661
)
5762
const targets = [...tui, ...advertised]
5863
.filter((plugin, index, all) => all.findIndex((candidate) => candidate.target === plugin.target) === index)

‎packages/cli/test/plugin-list.test.ts‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@ test("formats server and TUI plugins in sections without builtins", () => {
66
expect(
77
format(
88
[
9-
{ id: "opencode.agent", source: { type: "builtin" }, status: "active", tui: false },
9+
{ id: "opencode.agent", source: { type: "builtin" }, state: { status: "active" }, features: { server: true } },
1010
{
1111
id: "acme.dual",
1212
source: { type: "package", package: "[email protected]" },
13-
status: "active",
14-
tui: true,
13+
state: { status: "active" },
14+
features: { server: true, tui: true },
1515
},
1616
{
1717
source: { type: "package", package: "broken-plugin" },
18-
status: "failed",
19-
error: "broken",
20-
tui: false,
18+
state: { status: "failed", error: "broken" },
19+
features: { server: true },
20+
},
21+
{
22+
id: "local.dual",
23+
source: { type: "local", path: "/tmp/local/index.ts" },
24+
state: { status: "active" },
25+
features: { server: true, tui: true },
2126
},
2227
],
2328
[
@@ -28,19 +33,32 @@ test("formats server and TUI plugins in sections without builtins", () => {
2833
).toBe(
2934
[
3035
"TUI",
36+
"/tmp/local (advertised)",
3137
"/tmp/local.ts (discovered)",
3238
"[email protected] (advertised)",
3339
"tui-only (configured)",
3440
"",
3541
"Server",
3642
"acme.dual (active)",
3743
"broken-plugin (failed)",
44+
"local.dual (active)",
3845
].join(EOL),
3946
)
4047
})
4148

4249
test("includes builtins when requested", () => {
4350
expect(
44-
format([{ id: "opencode.agent", source: { type: "builtin" }, status: "active", tui: false }], [], true),
51+
format(
52+
[
53+
{
54+
id: "opencode.agent",
55+
source: { type: "builtin" },
56+
state: { status: "active" },
57+
features: { server: true },
58+
},
59+
],
60+
[],
61+
true,
62+
),
4563
).toBe(["Server", "opencode.agent (active)"].join(EOL))
4664
})

‎packages/client/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"@types/bun": "catalog:",
5656
"@typescript/native-preview": "catalog:",
5757
"effect": "catalog:",
58-
"solid-js": "catalog:"
58+
"solid-js": "catalog:",
59+
"zod": "catalog:"
5960
}
6061
}

‎packages/client/src/effect/api.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { ModelApi, ProviderApi, WebsearchApi } from "./api/api.js"
22

3+
export type { RpcApi, RpcClient } from "./rpc.js"
4+
35
export type * from "./api/api.js"
46

57
export type WebSearchApi<E = never> = WebsearchApi<E>

‎packages/client/src/effect/api/api.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,19 @@ export interface SkillApi<E = never> {
15731573
readonly list: SkillListOperation<E>
15741574
}
15751575

1576+
export type RpcCallInput = {
1577+
readonly rpcID: string
1578+
readonly method: string
1579+
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
1580+
readonly input?: unknown | undefined
1581+
}
1582+
export type RpcCallOutput = { readonly output?: unknown }
1583+
export type RpcCallOperation<E = never> = (input: RpcCallInput) => Effect.Effect<RpcCallOutput, E>
1584+
1585+
export interface RpcApi<E = never> {
1586+
readonly call: RpcCallOperation<E>
1587+
}
1588+
15761589
export type EventSubscribeOutput = OpenCodeEvent
15771590
export type EventSubscribeOperation<E = never> = () => Stream.Stream<EventSubscribeOutput, E>
15781591

@@ -2073,6 +2086,7 @@ export interface AppApi<E = never> {
20732086
readonly file: FileApi<E>
20742087
readonly command: CommandApi<E>
20752088
readonly skill: SkillApi<E>
2089+
readonly rpc: RpcApi<E>
20762090
readonly event: EventApi<E>
20772091
readonly pty: PtyApi<E>
20782092
readonly experimental: ExperimentalApi<E>

0 commit comments

Comments
 (0)