@opencode/plugin 2.2.7 → 2.3.0

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.
@@ -14,6 +14,7 @@ export { Provider } from "@opencode/schema/provider";
14
14
  export { Reference } from "@opencode/schema/reference";
15
15
  export { Rpc } from "@opencode/schema/rpc";
16
16
  export { Skill } from "@opencode/schema/skill";
17
+ export { Tool } from "@opencode/schema/tool";
17
18
  export { Vcs } from "@opencode/schema/vcs";
18
19
  export { WebSearch } from "@opencode/schema/websearch";
19
20
  export { Worktree } from "@opencode/schema/worktree";
@@ -13,6 +13,7 @@ export { Provider } from "@opencode/schema/provider";
13
13
  export { Reference } from "@opencode/schema/reference";
14
14
  export { Rpc } from "@opencode/schema/rpc";
15
15
  export { Skill } from "@opencode/schema/skill";
16
+ export { Tool } from "@opencode/schema/tool";
16
17
  export { Vcs } from "@opencode/schema/vcs";
17
18
  export { WebSearch } from "@opencode/schema/websearch";
18
19
  export { Worktree } from "@opencode/schema/worktree";
@@ -44,6 +44,11 @@ export type IntegrationOAuthAuthorization = {
44
44
  } & ({
45
45
  readonly mode: "auto";
46
46
  readonly callback: Effect.Effect<Credential.OAuth, unknown>;
47
+ /**
48
+ * Accepts the redirect URL a user pasted when the browser could not reach this machine, and settles `callback`
49
+ * with it. Check the URL's `state` as the browser path does; a failure rejects only this paste.
50
+ */
51
+ readonly submit?: (redirect: string) => Effect.Effect<void, unknown>;
47
52
  } | {
48
53
  readonly mode: "code";
49
54
  readonly callback: (code: string) => Effect.Effect<Credential.OAuth, unknown>;
@@ -19,6 +19,10 @@ export interface SessionPrompt {
19
19
  }
20
20
  /** Request overrides. Typed keys are generation settings; any other key is a provider option. */
21
21
  export type SessionRequestOptions = Types.DeepMutable<GenerationOptionsFields> & Record<string, unknown>;
22
+ /** A request message. `metadata` is the stored Session message's metadata, for reading only; it is not sent to the model. */
23
+ export type SessionRequestMessage = Message & {
24
+ readonly metadata?: Record<string, unknown>;
25
+ };
22
26
  export interface SessionRequest {
23
27
  readonly sessionID: Session.ID;
24
28
  readonly model: Model.Ref;
@@ -27,7 +31,7 @@ export interface SessionRequest {
27
31
  * not updated when a hook edits `text`. Experimental.
28
32
  */
29
33
  system: Array<SystemPart>;
30
- messages: Array<Message>;
34
+ messages: Array<SessionRequestMessage>;
31
35
  options: SessionRequestOptions;
32
36
  }
33
37
  export interface SessionContext extends SessionRequest {
@@ -181,6 +185,9 @@ export interface SessionIdle {
181
185
  readonly background: ReadonlyArray<SessionIdleBackground>;
182
186
  }
183
187
  export interface SessionHooks {
188
+ readonly fork: {
189
+ readonly sessionID: Session.ID;
190
+ };
184
191
  readonly prompt: SessionPrompt;
185
192
  readonly context: SessionContext;
186
193
  readonly compaction: SessionCompaction;
@@ -641,7 +641,7 @@ export interface Composer {
641
641
  */
642
642
  focused(): boolean;
643
643
  }
644
- /** Work the session moved to the background. */
644
+ /** A running subagent or background shell command of the session. */
645
645
  export interface BackgroundTask {
646
646
  /** The task's id. */
647
647
  id: string;
@@ -690,7 +690,7 @@ export interface MountedSession extends SessionRef {
690
690
  readonly directory: string;
691
691
  /** The session runs in the project root rather than a worktree. Reactive. */
692
692
  readonly local: boolean;
693
- /** Shell commands and subagents the session moved to the background; empty once another session is routed. */
693
+ /** Running subagents and background shell commands of the session; empty once another session is routed. */
694
694
  readonly background: readonly BackgroundTask[];
695
695
  }
696
696
  /**
@@ -1,2 +1,2 @@
1
1
  /** An icon from the app's catalog, for SDK fields such as `SessionPanelMenuItem.icon`. */
2
- export type IconName = "align-right" | "appearance" | "archive" | "arrow-down-to-line" | "arrow-left" | "arrow-right" | "arrow-undo-down" | "arrow-up" | "arrow-up-right" | "brain" | "branch" | "branch-out" | "bubble-5" | "bullet-list" | "check" | "check-small" | "checklist" | "chevron-double-right" | "chevron-down" | "chevron-grabber-vertical" | "chevron-left" | "chevron-right" | "circle-ban-sign" | "circle-check" | "circle-exclamation" | "circle-x" | "circle-xmark" | "close" | "close-small" | "cloud-upload" | "code" | "code-lines" | "code-slash" | "collapse" | "comment" | "console" | "copy" | "cube" | "dash" | "discord" | "dot-grid" | "download" | "edit" | "edit-small-2" | "enter" | "expand" | "extensions" | "eye" | "file-document" | "file-tree" | "file-tree-active" | "filetree" | "fill-triangle-down" | "flask" | "folder" | "folder-add-left" | "fork" | "github" | "glasses" | "globe" | "graduation-cap" | "grid-plus" | "help" | "info" | "keyboard" | "layout-bottom" | "layout-bottom-full" | "layout-bottom-partial" | "layout-left" | "layout-left-full" | "layout-left-partial" | "layout-right" | "layout-right-full" | "layout-right-partial" | "link" | "lock" | "magnifying-glass" | "magnifying-glass-menu" | "mcp" | "menu" | "minus" | "models" | "monitor" | "new-session" | "new-session-active" | "notifications" | "open-file" | "outline-arrow-left" | "outline-arrow-right" | "outline-arrow-to-corner-top-right" | "outline-arrow-up-right" | "outline-audio" | "outline-brain" | "outline-browser-annotate" | "outline-chevron-down" | "outline-chevron-right" | "outline-code-brackets" | "outline-console" | "outline-cookie" | "outline-copy" | "outline-dots" | "outline-expand" | "outline-eye" | "outline-eye-slash" | "outline-globe" | "outline-globe-plus" | "outline-hexagonal-warning" | "outline-list-changelog" | "outline-magnifier-minus" | "outline-magnifier-plus" | "outline-pair" | "outline-photo" | "outline-quote" | "outline-reset" | "outline-rotate-clockwise" | "outline-share" | "outline-sliders" | "outline-square-arrow" | "outline-steer" | "outline-text" | "outline-trash" | "outline-undo" | "outline-video" | "outline-wave-audio" | "outline-worktree" | "outline-xmark" | "pencil-line" | "photo" | "plus" | "plus-small" | "post-skill" | "prompt" | "providers" | "refresh" | "reset" | "review" | "review-active" | "select-element" | "selector" | "server" | "settings-gear" | "share" | "shield" | "sidebar" | "sidebar-active" | "sliders" | "speech-bubble" | "split" | "square-arrow-top-right" | "status" | "status-active" | "stop" | "task" | "terminal" | "terminal-active" | "trash" | "unified" | "warning" | "waveform" | "window-analytics" | "window-cursor" | "workspace" | "workspace-isolated" | "workspace-new" | "xmark-small";
2
+ export type IconName = "align-right" | "appearance" | "archive" | "arrow-down-to-line" | "arrow-left" | "arrow-right" | "arrow-undo-down" | "arrow-up" | "arrow-up-right" | "brain" | "branch" | "branch-out" | "bubble-5" | "bullet-list" | "check" | "check-small" | "checklist" | "chevron-double-right" | "chevron-down" | "chevron-grabber-vertical" | "chevron-left" | "chevron-right" | "circle-ban-sign" | "circle-check" | "circle-exclamation" | "circle-x" | "circle-xmark" | "close" | "close-small" | "cloud-upload" | "code" | "code-lines" | "code-slash" | "collapse" | "comment" | "console" | "copy" | "cube" | "dash" | "discord" | "dot-grid" | "download" | "edit" | "edit-small-2" | "enter" | "expand" | "extensions" | "eye" | "file-document" | "file-tree" | "file-tree-active" | "filetree" | "fill-triangle-down" | "flask" | "folder" | "folder-add-left" | "fork" | "github" | "glasses" | "globe" | "graduation-cap" | "grid-plus" | "help" | "info" | "keyboard" | "layout-bottom" | "layout-bottom-full" | "layout-bottom-partial" | "layout-left" | "layout-left-full" | "layout-left-partial" | "layout-right" | "layout-right-full" | "layout-right-partial" | "link" | "lock" | "magnifying-glass" | "magnifying-glass-menu" | "mcp" | "menu" | "minus" | "models" | "monitor" | "new-session" | "new-session-active" | "notifications" | "open-file" | "outline-arrow-left" | "outline-arrow-right" | "outline-arrow-to-corner-top-right" | "outline-arrow-up-right" | "outline-audio" | "outline-brain" | "outline-browser-annotate" | "outline-chevron-down" | "outline-chevron-right" | "outline-code-brackets" | "outline-console" | "outline-cookie" | "outline-copy" | "outline-dots" | "outline-expand" | "outline-eye" | "outline-eye-slash" | "outline-globe" | "outline-globe-plus" | "outline-hexagonal-warning" | "outline-list-changelog" | "outline-magnifier-minus" | "outline-magnifier-plus" | "outline-maximize" | "outline-pair" | "outline-photo" | "outline-quote" | "outline-reset" | "outline-rotate-clockwise" | "outline-share" | "outline-sliders" | "outline-square-arrow" | "outline-steer" | "outline-text" | "outline-trash" | "outline-undo" | "outline-video" | "outline-wave-audio" | "outline-worktree" | "outline-xmark" | "pencil-line" | "photo" | "plus" | "plus-small" | "post-skill" | "prompt" | "providers" | "refresh" | "reset" | "review" | "review-active" | "select-element" | "selector" | "server" | "settings-gear" | "share" | "shield" | "sidebar" | "sidebar-active" | "sliders" | "speech-bubble" | "split" | "square-arrow-top-right" | "status" | "status-active" | "stop" | "task" | "terminal" | "terminal-active" | "trash" | "unified" | "warning" | "waveform" | "window-analytics" | "window-cursor" | "workspace" | "workspace-isolated" | "workspace-new" | "xmark-small";
@@ -304,15 +304,22 @@ export function fromPromise(plugin) {
304
304
  const refresh = input.refresh;
305
305
  editor.method.update({
306
306
  ...input,
307
- authorize: (answer) => Effect.promise(() => input.authorize(answer)).pipe(Effect.map((authorization) => authorization.mode === "auto"
308
- ? {
307
+ authorize: (answer) => Effect.promise(() => input.authorize(answer)).pipe(Effect.map((authorization) => {
308
+ if (authorization.mode === "code")
309
+ return {
310
+ ...authorization,
311
+ callback: (code) => Effect.promise(() => authorization.callback(code)),
312
+ };
313
+ const submit = authorization.submit;
314
+ return {
309
315
  ...authorization,
310
316
  callback: Effect.promise(() => authorization.callback),
311
- }
312
- : {
313
- ...authorization,
314
- callback: (code) => Effect.promise(() => authorization.callback(code)),
315
- })),
317
+ // A rejected paste keeps its own error, which the dialog shows as is.
318
+ submit: submit
319
+ ? (redirect) => Effect.tryPromise({ try: () => submit(redirect), catch: (error) => error })
320
+ : undefined,
321
+ };
322
+ })),
316
323
  refresh: refresh === undefined
317
324
  ? undefined
318
325
  : (credential) => Effect.promise(() => refresh(credential)),
@@ -382,6 +389,7 @@ export function fromPromise(plugin) {
382
389
  update(value);
383
390
  Object.assign(tool, value, {
384
391
  output: value.output,
392
+ freeform: value.freeform,
385
393
  options: value.options,
386
394
  execute: (input, context) => executePromiseTool(value, input, context),
387
395
  });
@@ -479,7 +487,9 @@ export function fromPromise(plugin) {
479
487
  hook: (name, callback) => register(host.shell.hook(name, (event) => Effect.promise(() => Promise.resolve(callback(event))))),
480
488
  },
481
489
  };
482
- yield* Effect.acquireRelease(Effect.promise(() => Promise.resolve(plugin.setup(context2))), (cleanup) => (cleanup ? Effect.promise(() => Promise.resolve(cleanup())) : Effect.void));
490
+ yield* Effect.acquireRelease(Effect.promise(() => Promise.resolve(plugin.setup(context2))),
491
+ // JavaScript plugins may return anything, such as a v1-style hooks object; only a function is a cleanup.
492
+ (cleanup) => (typeof cleanup === "function" ? Effect.promise(() => Promise.resolve(cleanup())) : Effect.void));
483
493
  }),
484
494
  });
485
495
  }
@@ -495,10 +505,29 @@ const toolHook = {
495
505
  "execute.after": (run) => Effect.promise(run),
496
506
  };
497
507
  const executePromiseTool = (tool, input, context) => Effect.tryPromise({
498
- try: (signal) => tool.execute(input, {
499
- ...context,
500
- signal,
501
- progress: (update) => Effect.runPromise(context.progress(update), { signal }),
502
- }),
508
+ try: (interrupted) => {
509
+ // `signal` aborts when the call is interrupted, and also when the user stops the call once the tool has read
510
+ // it. Reading it awaits `cancel`, which tells the step this tool stops on its own instead of being interrupted.
511
+ const stopped = new AbortController();
512
+ const finished = new AbortController();
513
+ const signal = AbortSignal.any([interrupted, stopped.signal]);
514
+ // `cancel` stays out of the promise context; promise tools stop through `signal`.
515
+ const { cancel, ...rest } = context;
516
+ let listening = false;
517
+ const listen = () => {
518
+ if (listening || !cancel)
519
+ return;
520
+ listening = true;
521
+ Effect.runPromise(cancel, { signal: AbortSignal.any([interrupted, finished.signal]) }).then(() => stopped.abort(), () => { });
522
+ };
523
+ return Promise.resolve(tool.execute(input, {
524
+ ...rest,
525
+ get signal() {
526
+ listen();
527
+ return signal;
528
+ },
529
+ progress: (update) => Effect.runPromise(context.progress(update), { signal: interrupted }),
530
+ })).finally(() => finished.abort());
531
+ },
503
532
  catch: toolError,
504
533
  });
@@ -43,6 +43,11 @@ export type IntegrationOAuthAuthorization = {
43
43
  } & ({
44
44
  readonly mode: "auto";
45
45
  readonly callback: Promise<Credential.OAuth>;
46
+ /**
47
+ * Accepts the redirect URL a user pasted when the browser could not reach this machine, and settles `callback`
48
+ * with it. Check the URL's `state` as the browser path does; a rejection rejects only this paste.
49
+ */
50
+ readonly submit?: (redirect: string) => Promise<void>;
46
51
  } | {
47
52
  readonly mode: "code";
48
53
  readonly callback: (code: string) => Promise<Credential.OAuth>;
@@ -19,6 +19,10 @@ export interface SessionPrompt {
19
19
  }
20
20
  /** Request overrides. Typed keys are generation settings; any other key is a provider option. */
21
21
  export type SessionRequestOptions = Types.DeepMutable<GenerationOptionsFields> & Record<string, unknown>;
22
+ /** A request message. `metadata` is the stored Session message's metadata, for reading only; it is not sent to the model. */
23
+ export type SessionRequestMessage = Message & {
24
+ readonly metadata?: Record<string, unknown>;
25
+ };
22
26
  export interface SessionRequest {
23
27
  readonly sessionID: Session.ID;
24
28
  readonly model: Model.Ref;
@@ -27,7 +31,7 @@ export interface SessionRequest {
27
31
  * not updated when a hook edits `text`. Experimental.
28
32
  */
29
33
  system: Array<SystemPart>;
30
- messages: Array<Message>;
34
+ messages: Array<SessionRequestMessage>;
31
35
  options: SessionRequestOptions;
32
36
  }
33
37
  export interface SessionContext extends SessionRequest {
@@ -181,6 +185,9 @@ export interface SessionIdle {
181
185
  readonly background: ReadonlyArray<SessionIdleBackground>;
182
186
  }
183
187
  export interface SessionHooks {
188
+ readonly fork: {
189
+ readonly sessionID: Session.ID;
190
+ };
184
191
  readonly prompt: SessionPrompt;
185
192
  readonly context: SessionContext;
186
193
  readonly compaction: SessionCompaction;
@@ -6,7 +6,13 @@ import type { Session } from "@opencode/schema/session";
6
6
  import type { SessionMessage } from "@opencode/schema/session-message";
7
7
  import type { Types } from "effect";
8
8
  import type { Hooks, Transform } from "./registration.js";
9
- export interface ToolContext extends Omit<Tool.Context, "progress"> {
9
+ export interface ToolContext extends Omit<Tool.Context, "progress" | "cancel"> {
10
+ /**
11
+ * Aborted when the call is interrupted, and when the user stops the call if the tool has read this property.
12
+ * Reading it (spreading the context reads it too) opts the tool into a cooperative stop: on the user's stop the
13
+ * signal aborts and whatever the tool then returns or throws is still reported as the call's result. A tool
14
+ * that never reads it, or does not settle soon after the stop, is interrupted.
15
+ */
10
16
  readonly signal: AbortSignal;
11
17
  readonly progress: (update: Tool.Metadata) => Promise<void>;
12
18
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/plugin",
4
- "version": "2.2.7",
4
+ "version": "2.3.0",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -78,17 +78,17 @@
78
78
  ],
79
79
  "dependencies": {
80
80
  "@ai-sdk/provider": "3.0.8",
81
- "@opencode/ai": "2.2.7",
82
- "@opencode/client": "2.2.7",
83
- "@opencode/protocol": "2.2.7",
84
- "@opencode/schema": "2.2.7",
85
- "@opencode/util": "2.2.7",
81
+ "@opencode/ai": "2.3.0",
82
+ "@opencode/client": "2.3.0",
83
+ "@opencode/protocol": "2.3.0",
84
+ "@opencode/schema": "2.3.0",
85
+ "@opencode/util": "2.3.0",
86
86
  "effect": "4.1.0"
87
87
  },
88
88
  "peerDependencies": {
89
- "@opencode/theme": "2.2.7",
90
- "@opentui/core": ">=0.8.1",
91
- "@opentui/solid": ">=0.8.1",
89
+ "@opencode/theme": "2.3.0",
90
+ "@opentui/core": ">=0.8.4",
91
+ "@opentui/solid": ">=0.8.4",
92
92
  "electron": "*",
93
93
  "solid-js": ">=1.9.0",
94
94
  "vite": ">=6",
@@ -118,9 +118,9 @@
118
118
  }
119
119
  },
120
120
  "devDependencies": {
121
- "@opencode/theme": "2.2.7",
122
- "@opentui/core": "0.8.1",
123
- "@opentui/solid": "0.8.1",
121
+ "@opencode/theme": "2.3.0",
122
+ "@opentui/core": "0.8.4",
123
+ "@opentui/solid": "0.8.4",
124
124
  "@tsconfig/bun": "1.0.9",
125
125
  "@types/bun": "1.4.3",
126
126
  "@types/node": "24.12.2",