@opencode/plugin 2.1.4 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/effect/event.d.ts +8 -2
  2. package/dist/effect/plugin.d.ts +5 -2
  3. package/dist/effect/session.d.ts +41 -3
  4. package/dist/effect/vcs.d.ts +1 -0
  5. package/dist/gui/browser.d.ts +36 -0
  6. package/dist/gui/browser.js +3 -0
  7. package/dist/gui/context.d.ts +271 -0
  8. package/dist/gui/context.js +0 -0
  9. package/dist/gui/core.d.ts +560 -0
  10. package/dist/gui/core.js +86 -0
  11. package/dist/gui/declarations.d.ts +24 -0
  12. package/dist/gui/declarations.js +0 -0
  13. package/dist/gui/file.d.ts +122 -0
  14. package/dist/gui/file.js +7 -0
  15. package/dist/gui/host-apis.d.ts +1925 -0
  16. package/dist/gui/host-apis.js +0 -0
  17. package/dist/gui/icon-name.d.ts +2 -0
  18. package/dist/gui/icon-name.js +1 -0
  19. package/dist/gui/index.d.ts +7 -0
  20. package/dist/gui/index.js +6 -0
  21. package/dist/gui/internal.d.ts +44 -0
  22. package/dist/gui/internal.js +33 -0
  23. package/dist/gui/main.d.ts +279 -0
  24. package/dist/gui/main.js +20 -0
  25. package/dist/gui/modules.d.ts +15 -0
  26. package/dist/gui/modules.js +30 -0
  27. package/dist/gui/plugin.d.ts +86 -0
  28. package/dist/gui/plugin.js +9 -0
  29. package/dist/gui/reactive.d.ts +93 -0
  30. package/dist/gui/reactive.js +130 -0
  31. package/dist/gui/registries.d.ts +801 -0
  32. package/dist/gui/registries.js +110 -0
  33. package/dist/gui/review.d.ts +73 -0
  34. package/dist/gui/review.js +3 -0
  35. package/dist/gui/scope.d.ts +64 -0
  36. package/dist/gui/scope.js +85 -0
  37. package/dist/gui/solid.d.ts +99 -0
  38. package/dist/gui/solid.js +74 -0
  39. package/dist/gui/vite.d.ts +24 -0
  40. package/dist/gui/vite.js +49 -0
  41. package/dist/host.d.ts +12 -1
  42. package/dist/host.js +34 -2
  43. package/dist/promise/adapter.js +13 -1
  44. package/dist/promise/event.d.ts +6 -2
  45. package/dist/promise/plugin.d.ts +5 -2
  46. package/dist/promise/session.d.ts +41 -3
  47. package/dist/runtime-modules.js +3 -1
  48. package/package.json +66 -17
@@ -1,3 +1,9 @@
1
- import type { EventApi } from "@opencode/client/effect/api";
2
- export interface EventDomain extends Pick<EventApi<unknown>, "subscribe"> {
1
+ import type { EventSubscribeInput, EventSubscribeOutput, SelectedEvent } from "@opencode/client/effect/api";
2
+ import type { Stream } from "effect";
3
+ type EventType = NonNullable<EventSubscribeInput["types"]>[number];
4
+ export interface EventDomain {
5
+ readonly subscribe: <Type extends EventType = EventType>(input?: {
6
+ readonly types?: ReadonlyArray<Type>;
7
+ }) => Stream.Stream<SelectedEvent<EventSubscribeOutput, Type>, unknown>;
3
8
  }
9
+ export {};
@@ -1,4 +1,4 @@
1
- import type { CredentialApi, ExperimentalApi, GenerateApi, PluginApi } from "@opencode/client/effect/api";
1
+ import type { CredentialApi, ExperimentalApi, ExperimentalGenerateApi, PluginApi } from "@opencode/client/effect/api";
2
2
  import type { Location } from "@opencode/schema/location";
3
3
  import type { Effect, Scope } from "effect";
4
4
  import type { PluginOptions } from "../options.js";
@@ -33,11 +33,14 @@ export interface Context {
33
33
  readonly event: EventDomain;
34
34
  readonly experimental: {
35
35
  readonly terminal: Pick<ExperimentalApi<unknown>["persistentPty"], "read">;
36
+ /** Stateless generation with a model and a prompt: no session, history or tools. */
37
+ readonly generate: ExperimentalGenerateApi<unknown>;
36
38
  };
37
39
  readonly integration: IntegrationDomain;
38
40
  readonly mcp: MCPDomain;
39
41
  readonly model: ModelDomain;
40
- readonly generate: GenerateApi<unknown>;
42
+ /** @deprecated Use `experimental.generate.text`. */
43
+ readonly generate: Pick<ExperimentalGenerateApi<unknown>, "text">;
41
44
  readonly permission: PermissionDomain;
42
45
  readonly plugin: Pick<PluginApi<unknown>, "list">;
43
46
  readonly provider: ProviderDomain;
@@ -1,5 +1,5 @@
1
- import type { SessionApi } from "@opencode/client/effect/api";
2
- import type { GenerationOptionsFields, Message, SystemPart } from "@opencode/ai";
1
+ import type { ExperimentalSessionApi, SessionApi } from "@opencode/client/effect/api";
2
+ import type { GenerationOptionsFields, Message, SystemPart } from "@opencode/ai/effect";
3
3
  import type { Agent } from "@opencode/schema/agent";
4
4
  import type { Model } from "@opencode/schema/model";
5
5
  import type { PromptInput } from "@opencode/schema/prompt-input";
@@ -127,6 +127,43 @@ export interface SessionRetry {
127
127
  readonly attempt: number;
128
128
  decision: SessionRetryDecision;
129
129
  }
130
+ /**
131
+ * Background work still running for the idle Session or one of its descendants. `sessionID` is
132
+ * the Session that owns the job: the idle Session itself, or a descendant such as a subagent child.
133
+ */
134
+ export type SessionIdleBackground = {
135
+ readonly kind: "shell";
136
+ readonly sessionID: Session.ID;
137
+ readonly shellID: string;
138
+ readonly command: string;
139
+ } | {
140
+ readonly kind: "subagent";
141
+ readonly sessionID: Session.ID;
142
+ readonly childSessionID: Session.ID;
143
+ readonly agent: string;
144
+ readonly description: string;
145
+ } | {
146
+ readonly kind: "image";
147
+ readonly sessionID: Session.ID;
148
+ readonly path: string;
149
+ readonly model: string;
150
+ };
151
+ /**
152
+ * Runs when a Session finishes model work and has no pending input, just before it goes idle.
153
+ * It does not run after interruption, failure, or control-only work such as a manual compaction.
154
+ * Input admitted by the hook, such as a synthetic message, runs in the same execution instead
155
+ * of the Session going idle.
156
+ *
157
+ * `background` lists work that is still running. When the Session's own shell or subagent finishes,
158
+ * its notice wakes the Session and the hook runs again, so a plugin that waits for that work can
159
+ * simply return. Work a descendant owns, such as a shell a subagent left running, wakes that
160
+ * descendant instead, so it is listed for information only. Notices admitted with `resume: false`,
161
+ * such as those recovered after a restart, wait for the next wake. Experimental.
162
+ */
163
+ export interface SessionIdle {
164
+ readonly sessionID: Session.ID;
165
+ readonly background: ReadonlyArray<SessionIdleBackground>;
166
+ }
130
167
  export interface SessionHooks {
131
168
  readonly prompt: SessionPrompt;
132
169
  readonly context: SessionContext;
@@ -140,7 +177,8 @@ export interface SessionHooks {
140
177
  readonly "experimental.ws.send": SessionWebSocketSend;
141
178
  readonly "experimental.ws.receive": SessionWebSocketReceive;
142
179
  readonly retry: SessionRetry;
180
+ readonly "experimental.idle": SessionIdle;
143
181
  }
144
- export type SessionDomain = Pick<SessionApi<unknown>, "list" | "create" | "get" | "remove" | "switchAgent" | "switchModel" | "prompt" | "generate" | "command" | "compact" | "synthetic" | "interrupt" | "update" | "move" | "wait" | "context"> & {
182
+ export type SessionDomain = Pick<SessionApi<unknown>, "list" | "create" | "get" | "remove" | "switchAgent" | "switchModel" | "prompt" | "generate" | "command" | "compact" | "synthetic" | "interrupt" | "update" | "move" | "context"> & Pick<ExperimentalSessionApi<unknown>, "wait" | "instructions"> & {
145
183
  readonly hook: ModelHooks<SessionHooks>;
146
184
  };
@@ -18,6 +18,7 @@ export interface VcsDiffInput extends VcsScope {
18
18
  readonly base?: string;
19
19
  readonly context: number;
20
20
  readonly maxOutputBytes: number;
21
+ readonly untracked?: Vcs.Untracked;
21
22
  }
22
23
  export interface VcsDefinition {
23
24
  readonly id: string;
@@ -0,0 +1,36 @@
1
+ import { Contract } from "./core.js";
2
+ import type { SessionRef } from "./host-apis.js";
3
+ /** What the built-in browser offers other plugins: a session's desktop browser pane. Read it with `ctx.use(Browser)`. */
4
+ export interface Browser {
5
+ /**
6
+ * The desktop browser pane exists for this session (the session is attached to a pane).
7
+ *
8
+ * @param session - The session to check.
9
+ * @returns True when the session has a pane.
10
+ */
11
+ attached(session: SessionRef): boolean;
12
+ /**
13
+ * A workspace file (relative path) or http(s) URL can open in the pane for this session.
14
+ *
15
+ * @param session - The session whose pane would open it.
16
+ * @param path - A workspace-relative file path or an http(s) URL; omit it to ask whether the pane can open anything.
17
+ * @returns True when `open` or `openFile` would succeed.
18
+ */
19
+ canOpen(session: SessionRef, path?: string): boolean;
20
+ /**
21
+ * Opens a URL (http(s) or file://) as a browser tab in the session's side panel.
22
+ *
23
+ * @param session - The session whose pane opens it.
24
+ * @param url - The URL to open.
25
+ */
26
+ open(session: SessionRef, url: string): void;
27
+ /**
28
+ * Opens a workspace file (relative path) as a file:// browser tab. Check `canOpen(session, path)` first.
29
+ *
30
+ * @param session - The session whose pane opens it.
31
+ * @param path - The workspace-relative file path.
32
+ */
33
+ openFile(session: SessionRef, path: string): void;
34
+ }
35
+ /** The browser plugin provides this on desktop. Inactive on web or while the plugin is off. */
36
+ export declare const Browser: Contract<Browser, "browser">;
@@ -0,0 +1,3 @@
1
+ import { Contract } from "./core.js";
2
+ /** The browser plugin provides this on desktop. Inactive on web or while the plugin is off. */
3
+ export const Browser = Contract.define("browser");
@@ -0,0 +1,271 @@
1
+ import type { Accessor } from "solid-js";
2
+ import type { BaseContext, App, Cleanup, Contract, DeclaredStores, Ipc, IpcClient, IpcSpec, Live, Persisted, StoreDeclaration, Token, TokenValue } from "./core.js";
3
+ import type { Appearance, Attention, Commands, Desktop, Dialogs, Embeds, Keybinds, Layout, Links, Locale, Router, Screen, Servers, SessionRef, Sessions, Storage, System, Tabs, Toasts, Ui, Workspaces } from "./host-apis.js";
4
+ /**
5
+ * What every window entry gets. Contracts are provided and read at runtime: `ctx.provide` for your own, `ctx.use` for
6
+ * other plugins', `ctx.main` for your main process. The APIs the host always provides are properties, each created
7
+ * on first read.
8
+ * Setup runs under the plugin's root owner: Solid's `onCleanup` in setup runs when the plugin goes away.
9
+ * `usePlugin()` returns the same object inside contributions.
10
+ */
11
+ export interface Context extends BaseContext {
12
+ /**
13
+ * Provides an in-process contract. Withdrawn with the current owner, else with the plugin. Throws for a contract
14
+ * whose id is not your plugin's id or under it (`<id>.<name>`), and for an Ipc token: Ipcs are provided by the main
15
+ * entry.
16
+ *
17
+ * @param token - The contract.
18
+ * @param impl - Its implementation.
19
+ * @returns Withdraws the contract early.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * ctx.provide(Changes, { diffs, open })
24
+ * ```
25
+ */
26
+ provide<C extends Contract<unknown>>(token: C, impl: TokenValue<C>): Cleanup;
27
+ /**
28
+ * Follows a contract or an Ipc that another plugin provides. Returns a `Live` accessor: pending while its provider
29
+ * loads, active with its value, inactive while it is turned off or failed. The plugin must keep working while it is
30
+ * inactive. Branch on it, or follow it with `createKeyed`. The provider is the plugin whose id the token's id names.
31
+ *
32
+ * @param token - The contract or Ipc.
33
+ * @returns The provider as a `Live` accessor; the same accessor for every call with the token.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * createKeyed(ctx.use(Changes), (changes) => changes.watch(screen, "files"))
38
+ * ```
39
+ */
40
+ use<T extends Token>(token: T): Accessor<Live<TokenValue<T>>>;
41
+ /**
42
+ * The client of an Ipc your own main entry provides. A call waits while the main entry starts, and rejects when it
43
+ * cannot answer: on the web, while the plugin's main entry is off or failed, or when main throws. A call waits
44
+ * indefinitely when the plugin has no main entry. `state` and `on`
45
+ * follow the main entry across restarts. Throws for an Ipc whose id is not your plugin's id or under it.
46
+ *
47
+ * @param token - The Ipc.
48
+ * @returns Its client; the same client for every call with the token.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * const awake = ctx.main(KeepAwake)
53
+ * ctx.add(Command, { id: "awake", title: ctx.t("awake"), run: () => void awake.set(true) })
54
+ * ```
55
+ */
56
+ main<S extends IpcSpec>(token: Ipc<S>): IpcClient<S>;
57
+ /**
58
+ * Side panel tabs, scroll offsets, and the settings and project dialogs.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * ctx.layout.open(`${ctx.id}:main`, session, { background: true })
63
+ * ```
64
+ */
65
+ readonly layout: Layout;
66
+ /**
67
+ * The sessions of open shell tabs, and the mounted one.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const session = ctx.sessions.current()
72
+ * ```
73
+ */
74
+ readonly sessions: Sessions;
75
+ /**
76
+ * The mounted session screen and its route-following files, comments and composer. Read it where you act, so an
77
+ * action targets the session routed at that moment; a `MountedSession` carries no such actions.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const screen = ctx.screen.current()
82
+ * if (screen) screen.composer.attach({ type: "file", path })
83
+ * ```
84
+ */
85
+ readonly screen: Screen;
86
+ /**
87
+ * Stores for keys only known at runtime, and window-local memory. Declare `stores` for keys known up front.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const recent = ctx.storage.store(`recent.${server}`, { schema: Recent, initial: { paths: [] } })
92
+ * ```
93
+ */
94
+ readonly storage: Storage;
95
+ /**
96
+ * The clipboard, saving files, and opening URLs in the system browser. Works on every platform.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * await ctx.system.copy(url)
101
+ * ```
102
+ */
103
+ readonly system: System;
104
+ /**
105
+ * Desktop-only abilities; undefined on the web.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * if (!ctx.desktop) return
110
+ * void ctx.desktop.reveal(path)
111
+ * ```
112
+ */
113
+ readonly desktop: Desktop | undefined;
114
+ /**
115
+ * Dialogs that close with the owner that opened them, else when the plugin goes away.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * ctx.dialogs.open((dialog) => <ConfirmDialog onDone={dialog.close} />)
120
+ * ```
121
+ */
122
+ readonly dialogs: Dialogs;
123
+ /**
124
+ * Short messages in a corner of the window. A plugin's toasts close when it goes away.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * const saving = ctx.toast.show({ title: ctx.t("saving"), variant: "loading", persistent: true })
129
+ * await save()
130
+ * saving.dismiss()
131
+ * ```
132
+ */
133
+ readonly toast: Toasts;
134
+ /**
135
+ * The shell's tab strip: open, show, move and close session tabs.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * const first = (key: string) => ctx.tabs.move(key, 0)
140
+ * ```
141
+ */
142
+ readonly tabs: Tabs;
143
+ /**
144
+ * System notifications and sounds that follow the user's notification settings, for when they look elsewhere.
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * void ctx.attention.notify({ title: ctx.t("tests.done"), session: { server: session.server.id, id: session.id } })
149
+ * ```
150
+ */
151
+ readonly attention: Attention;
152
+ /**
153
+ * Runs published plugin commands and the app's own, as the command palette does.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * if (!ctx.commands.run("terminal.toggle")) ctx.toast.show({ title: ctx.t("terminal.unavailable") })
158
+ * ```
159
+ */
160
+ readonly commands: Commands;
161
+ /**
162
+ * Routes local links to the plugins that handle them.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * ctx.links.open({ href: path, session, exact: true })
167
+ * ```
168
+ */
169
+ readonly links: Links;
170
+ /**
171
+ * Shows the web pages the main entry created.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * <ctx.embeds.View id={embed()} visible={visible()} />
176
+ * ```
177
+ */
178
+ readonly embeds: Embeds;
179
+ /**
180
+ * The app's own components: icons, buttons, tooltips, menus, the loading indicator, the dialog frame, switches,
181
+ * text fields, keybind chips, Markdown and highlighted code.
182
+ *
183
+ * @example
184
+ * ```tsx
185
+ * <ctx.ui.Button icon="check" onClick={apply}>{ctx.t("apply")}</ctx.ui.Button>
186
+ * ```
187
+ */
188
+ readonly ui: Ui;
189
+ /**
190
+ * The running app: its version, release channel and platform, as `ctx.app` in server and TUI plugins.
191
+ *
192
+ * @example
193
+ * ```ts
194
+ * if (ctx.app.channel === "dev") showDebug()
195
+ * ```
196
+ */
197
+ readonly app: App;
198
+ /**
199
+ * The interface language and its writing direction.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * new Intl.NumberFormat(ctx.locale.locale()).format(count)
204
+ * ```
205
+ */
206
+ readonly locale: Locale;
207
+ /**
208
+ * The user's appearance settings.
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * terminal.options.fontFamily = ctx.appearance.font("mono")
213
+ * ```
214
+ */
215
+ readonly appearance: Appearance;
216
+ /**
217
+ * The app's route.
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * const onSettings = () => ctx.router.path().startsWith("/settings")
222
+ * ```
223
+ */
224
+ readonly router: Router;
225
+ /**
226
+ * The effective keybinds of published commands.
227
+ *
228
+ * @example
229
+ * ```ts
230
+ * const keys = () => ctx.keybinds.keybind(`${ctx.id}.toggle`)
231
+ * ```
232
+ */
233
+ readonly keybinds: Keybinds;
234
+ /**
235
+ * The servers the app lists: their ids, and each one's live `ServerRef`.
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * const known = () => new Set(ctx.servers.list())
240
+ * const server = (id: string) => ctx.servers.get(id)
241
+ * ```
242
+ */
243
+ readonly servers: Servers;
244
+ /**
245
+ * Workspace lifecycle events.
246
+ *
247
+ * @example
248
+ * ```ts
249
+ * ctx.workspaces.on("remove", (value) => forget(value.server, value.directory))
250
+ * ```
251
+ */
252
+ readonly workspaces: Workspaces;
253
+ }
254
+ type Handle<S> = S extends StoreDeclaration<infer Schema, infer Scope> ? Scope extends "global" ? Persisted<Schema["Type"], Schema["Type"]> : (session: SessionRef) => Persisted<Schema["Type"]> : never;
255
+ /** The context `Plugin.Setup<typeof definition>` receives: the host's members, and the definition's declared stores. */
256
+ export interface SetupContext<D> extends Context {
257
+ /**
258
+ * Each declared store, by its name in `stores`. A global store is a `Persisted` that has loaded before setup; a
259
+ * session store is a function of the session whose `value` is undefined until that session's store loads.
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * const shown = () => ctx.stores.prefs.value.shown
264
+ * const open = (session: SessionRef) => ctx.stores.view(session).value?.open ?? []
265
+ * ```
266
+ */
267
+ readonly stores: {
268
+ readonly [K in keyof DeclaredStores<D>]: Handle<DeclaredStores<D>[K]>;
269
+ };
270
+ }
271
+ export {};
File without changes