From c555559ac1b94910b769eebaa595b2b8822efa14 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Sun, 20 Sep 2026 11:36:19 -0500 Subject: [PATCH] refactor(plugin): name tool execution context (#50195) --- .../core/test/plugin/promise-tool.test.ts | 6 ++--- packages/plugin/src/promise/adapter.ts | 24 +++++++++---------- .../src/docs/content/build/plugins/index.mdx | 12 +++++----- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/core/test/plugin/promise-tool.test.ts b/packages/core/test/plugin/promise-tool.test.ts index b312b348d16..09d39d553f5 100644 --- a/packages/core/test/plugin/promise-tool.test.ts +++ b/packages/core/test/plugin/promise-tool.test.ts @@ -26,10 +26,10 @@ it.live("Promise tool executors receive interruption through their AbortSignal", description: "Wait until cancelled", input: { type: "object", properties: {}, additionalProperties: false }, options: { codemode: false }, - execute: (_input, tool) => + execute: (_input, context) => new Promise((_resolve, reject) => { - tool.signal.addEventListener("abort", () => reject(new Error("cancelled")), { once: true }) - Effect.runSync(Deferred.succeed(started, tool.signal)) + context.signal.addEventListener("abort", () => reject(new Error("cancelled")), { once: true }) + Effect.runSync(Deferred.succeed(started, context.signal)) }), }), ) diff --git a/packages/plugin/src/promise/adapter.ts b/packages/plugin/src/promise/adapter.ts index 39f33866383..15ccb58a0d0 100644 --- a/packages/plugin/src/promise/adapter.ts +++ b/packages/plugin/src/promise/adapter.ts @@ -237,26 +237,26 @@ export function fromPromise(plugin: Plugin) { const VcsEndpoints = ClientApi.groups["server.vcs"].endpoints const WebSearchEndpoints = ClientApi.groups["server.websearch"].endpoints const WorktreeEndpoints = ClientApi.groups["server.worktree"].endpoints - const context = yield* Effect.context() + const runtime = yield* Effect.context() const streams = yield* makeStreams() // Run a hook registration on the plugin scope and resolve once it is registered. const register = (effect: Effect.Effect): Promise => - Effect.runPromiseWith(context)(effect).then((registration) => ({ - dispose: () => Effect.runPromiseWith(context)(registration.dispose), + Effect.runPromiseWith(runtime)(effect).then((registration) => ({ + dispose: () => Effect.runPromiseWith(runtime)(registration.dispose), })) - const run = (effect: Effect.Effect) => Effect.runPromiseWith(context)(effect) + const run = (effect: Effect.Effect) => Effect.runPromiseWith(runtime)(effect) const promiseExecutor = (execute: Tool.Info["execute"]): Info["execute"] => - (input, tool) => - Effect.runPromiseWith(context)( + (input, context) => + Effect.runPromiseWith(runtime)( execute(input, { - ...tool, - progress: (update) => Effect.promise(() => tool.progress(update)), + ...context, + progress: (update) => Effect.promise(() => context.progress(update)), }), - { signal: tool.signal }, + { signal: context.signal }, ) const adaptApiMethod = ( @@ -274,7 +274,7 @@ export function fromPromise(plugin: Plugin) { const result = yield* method(Object.assign({}, ...decoded) as never) if (compiled.noContent) return undefined return yield* compiled.encode(result) - }).pipe(Effect.runPromiseWith(context))) as PromiseMethod + }).pipe(Effect.runPromiseWith(runtime))) as PromiseMethod } const transform = @@ -425,8 +425,8 @@ export function fromPromise(plugin: Plugin) { ), reload: () => run(host.integration.reload()), connection: { - active: (id) => Effect.runPromiseWith(context)(host.integration.connection.active(id)), - resolve: (connection) => Effect.runPromiseWith(context)(host.integration.connection.resolve(connection)), + active: (id) => Effect.runPromiseWith(runtime)(host.integration.connection.active(id)), + resolve: (connection) => Effect.runPromiseWith(runtime)(host.integration.connection.resolve(connection)), }, }, mcp: { diff --git a/services/www/src/docs/content/build/plugins/index.mdx b/services/www/src/docs/content/build/plugins/index.mdx index 8a1507c9dbe..fa81169d4bc 100644 --- a/services/www/src/docs/content/build/plugins/index.mdx +++ b/services/www/src/docs/content/build/plugins/index.mdx @@ -919,20 +919,20 @@ const registration = await ctx.tool.transform((editor) => { additionalProperties: false, }, options: { namespace: "acme", codemode: true }, - execute: async (input, tool) => { - await tool.progress({ status: "greeting" }) + execute: async (input, context) => { + await context.progress({ status: "greeting" }) return { content: `Hello ${(input as { name: string }).name}!` } }, }) }) ``` -Promise tool executors receive `tool.signal`. Pass it to cancellable work such as `fetch` so stopping the Session also -stops the underlying operation. +Promise tool executors receive `context.signal`. Pass it to cancellable work such as `fetch` so stopping the Session +also stops the underlying operation. ```ts -execute: async ({ url }, tool) => { - const response = await fetch(url, { signal: tool.signal }) +execute: async ({ url }, context) => { + const response = await fetch(url, { signal: context.signal }) return { content: await response.text() } } ```