From ff4bab22fbf16a968bc911b65c74ad8412eb39db Mon Sep 17 00:00:00 2001 From: canvrno <46584286+canvrno@users.noreply.github.com> Date: Tue, 8 Jul 2025 10:47:12 -0700 Subject: [PATCH] host bridge migration - openExternal (#4502) --- .changeset/gorgeous-apes-fry.md | 5 +++++ proto/host/env.proto | 3 +++ .../controller/account/accountLoginClicked.ts | 3 ++- src/core/controller/web/openInBrowser.ts | 4 ++-- src/core/mentions/index.ts | 3 ++- src/hosts/vscode/env/openExternal.ts | 8 ++++++++ src/integrations/editor/detect-omission.ts | 7 +++---- src/utils/env.ts | 15 +++++++++++++++ src/utils/github-url-utils.ts | 13 ++++++------- 9 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 .changeset/gorgeous-apes-fry.md create mode 100644 src/hosts/vscode/env/openExternal.ts diff --git a/.changeset/gorgeous-apes-fry.md b/.changeset/gorgeous-apes-fry.md new file mode 100644 index 00000000..e35440ca --- /dev/null +++ b/.changeset/gorgeous-apes-fry.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +host bridge migration - openExternal diff --git a/proto/host/env.proto b/proto/host/env.proto index 9d769c1e..00248900 100644 --- a/proto/host/env.proto +++ b/proto/host/env.proto @@ -13,4 +13,7 @@ service EnvService { // Reads text from the system clipboard. rpc clipboardReadText(cline.EmptyRequest) returns (cline.String); + + // Opens a URL in the user's default browser or application. + rpc openExternal(cline.StringRequest) returns (cline.Empty); } diff --git a/src/core/controller/account/accountLoginClicked.ts b/src/core/controller/account/accountLoginClicked.ts index 11648c18..0938d1ff 100644 --- a/src/core/controller/account/accountLoginClicked.ts +++ b/src/core/controller/account/accountLoginClicked.ts @@ -3,6 +3,7 @@ import crypto from "crypto" import { Controller } from "../index" import { storeSecret } from "../../storage/state" import { EmptyRequest, String } from "../../../shared/proto/common" +import { openExternal } from "@utils/env" /** * Handles the user clicking the login link in the UI. @@ -26,7 +27,7 @@ export async function accountLoginClicked(controller: Controller, _: EmptyReques const authUrl = vscode.Uri.parse( `https://app.cline.bot/auth?state=${encodeURIComponent(nonce)}&callback_url=${encodeURIComponent(`${uriScheme || "vscode"}://saoudrizwan.claude-dev/auth`)}`, ) - await vscode.env.openExternal(authUrl) + await openExternal(authUrl.toString()) return String.create({ value: authUrl.toString(), }) diff --git a/src/core/controller/web/openInBrowser.ts b/src/core/controller/web/openInBrowser.ts index e31d86d6..24216ada 100644 --- a/src/core/controller/web/openInBrowser.ts +++ b/src/core/controller/web/openInBrowser.ts @@ -1,6 +1,6 @@ -import * as vscode from "vscode" import { Controller } from ".." import { Empty, StringRequest } from "../../../shared/proto/common" +import { openExternal } from "@utils/env" /** * Opens a URL in the user's default browser @@ -11,7 +11,7 @@ import { Empty, StringRequest } from "../../../shared/proto/common" export async function openInBrowser(controller: Controller, request: StringRequest): Promise { try { if (request.value) { - await vscode.env.openExternal(vscode.Uri.parse(request.value)) + await openExternal(request.value) } return Empty.create() } catch (error) { diff --git a/src/core/mentions/index.ts b/src/core/mentions/index.ts index 6a8bbb01..623248e4 100644 --- a/src/core/mentions/index.ts +++ b/src/core/mentions/index.ts @@ -12,6 +12,7 @@ import { getCommitInfo } from "@utils/git" import { getWorkingState } from "@utils/git" import { FileContextTracker } from "../context/context-tracking/FileContextTracker" import { getCwd } from "@/utils/path" +import { openExternal } from "@utils/env" export async function openMention(mention?: string): Promise { if (!mention) { @@ -36,7 +37,7 @@ export async function openMention(mention?: string): Promise { } else if (mention === "terminal") { vscode.commands.executeCommand("workbench.action.terminal.focus") } else if (mention.startsWith("http")) { - vscode.env.openExternal(vscode.Uri.parse(mention)) + await openExternal(mention) } } diff --git a/src/hosts/vscode/env/openExternal.ts b/src/hosts/vscode/env/openExternal.ts new file mode 100644 index 00000000..73a90e3a --- /dev/null +++ b/src/hosts/vscode/env/openExternal.ts @@ -0,0 +1,8 @@ +import { Empty, StringRequest } from "@/shared/proto/common" +import * as vscode from "vscode" + +export async function openExternal(request: StringRequest): Promise { + console.log("openExternal called with request:", request) + await vscode.env.openExternal(vscode.Uri.parse(request.value)) + return Empty.create() +} diff --git a/src/integrations/editor/detect-omission.ts b/src/integrations/editor/detect-omission.ts index 32de0aac..8d6afefb 100644 --- a/src/integrations/editor/detect-omission.ts +++ b/src/integrations/editor/detect-omission.ts @@ -1,4 +1,5 @@ import * as vscode from "vscode" +import { openExternal } from "@utils/env" /** * Detects potential AI-generated code omissions in the given file content. @@ -47,10 +48,8 @@ export function showOmissionWarning(originalFileContent: string, newFileContent: ) .then((selection) => { if (selection === "Follow this guide to fix the issue") { - vscode.env.openExternal( - vscode.Uri.parse( - "https://github.com/cline/cline/wiki/Troubleshooting-%E2%80%90-Cline-Deleting-Code-with-%22Rest-of-Code-Here%22-Comments", - ), + openExternal( + "https://github.com/cline/cline/wiki/Troubleshooting-%E2%80%90-Cline-Deleting-Code-with-%22Rest-of-Code-Here%22-Comments", ) } }) diff --git a/src/utils/env.ts b/src/utils/env.ts index 832f049b..15d55f77 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -30,3 +30,18 @@ export async function readTextFromClipboard(): Promise { throw new Error(`Failed to read from clipboard: ${errorMessage}`) } } + +/** + * Opens an external URL in the default browser + * @param url The URL to open + * @returns Promise that resolves when the operation is complete + * @throws Error if the operation fails + */ +export async function openExternal(url: string): Promise { + try { + await getHostBridgeProvider().envClient.openExternal(StringRequest.create({ value: url })) + } catch (error) { + const errorMessage = error instanceof Error ? error.message : String(error) + throw new Error(`Failed to open external URL: ${errorMessage}`) + } +} diff --git a/src/utils/github-url-utils.ts b/src/utils/github-url-utils.ts index 9ef4a96a..2e6f3727 100644 --- a/src/utils/github-url-utils.ts +++ b/src/utils/github-url-utils.ts @@ -17,7 +17,7 @@ import * as vscode from "vscode" import * as cp from "child_process" import * as os from "os" import * as util from "util" -import { writeTextToClipboard } from "@/utils/env" +import { writeTextToClipboard, openExternal } from "@/utils/env" /** * Creates a properly encoded GitHub issue URL. @@ -141,16 +141,15 @@ export async function openUrlInBrowser(url: string): Promise { } catch (error) { console.error(`OS commands failed: ${error}`) - // First fallback: Try VS Code's openExternal + // First fallback: Try openExternal utility // Note: This will likely have encoding issues per https://github.com/microsoft/vscode/issues/85930 // but we include it as a fallback in case OS commands completely fail try { - // The 'true' parameter might help preserve some encodings, but this is not guaranteed - await vscode.env.openExternal(vscode.Uri.parse(url, true)) - console.log("Opened URL with vscode.env.openExternal (note: URL encoding may be affected)") + await openExternal(url) + console.log("Opened URL with openExternal utility (note: URL encoding may be affected)") return - } catch (vscodeError) { - console.error(`Error with vscode.env.openExternal: ${vscodeError}`) + } catch (openExternalError) { + console.error(`Error with openExternal utility: ${openExternalError}`) // Last fallback: Show a message with instructions vscode.window