refactor(hosts): Simplify the host provider interface for callers (#5057)
* refactor(hosts): Simplify the host provider interface for callers - Streamline API to reduce complexity for consuming code - Update all references across core, controller, and integration modules - Consolidate provider patterns for easier usage - Rename host-providers.ts to host-provider.ts # Conflicts: # src/core/controller/index.ts # src/extension.ts # src/integrations/git/commit-message-generator.ts * Add comment * In the tests, reset the HostProvider to prevent it complaining that it is being reinitialized * Update comment * Fix imports
This commit is contained in:
1 parent
c970b8030e
commit
8d5985c8fd
30 files changed
+223
-172
No files matched your search
@@ -71,11 +71,11 @@ module.exports = createRule({
|
||||
"This provides consistent path handling across different environments.\n" +
|
||||
"Found: {{code}}",
|
||||
useHostBridgeWorkspace:
|
||||
"Use getHostBridgeProvider().workspaceClient.getWorkspacePaths({}) instead of vscode.workspace.workspaceFolders.\n" +
|
||||
"Use HostProvider.workspace.getWorkspacePaths({}) instead of vscode.workspace.workspaceFolders.\n" +
|
||||
"This provides a consistent abstraction across VSCode and standalone environments.\n" +
|
||||
"Found: {{code}}",
|
||||
useHostBridgeShowMessage:
|
||||
"Use getHostBridgeProvider().windowClient.showMessage instead of the vscode.window.showMessage.\n" +
|
||||
"Use HostProvider.window.showMessage instead of the vscode.window.showMessage.\n" +
|
||||
"This provides a consistent abstraction across VSCode and standalone environments.\n" +
|
||||
"Found: {{code}}",
|
||||
useHostBridge:
|
||||
|
||||
@@ -6,8 +6,8 @@ import * as path from "path"
|
||||
import { FileContextTracker } from "./FileContextTracker"
|
||||
import * as diskModule from "@core/storage/disk"
|
||||
import type { TaskMetadata, FileMetadataEntry } from "./ContextTrackerTypes"
|
||||
import type { DiffViewProviderCreator, WebviewProviderCreator } from "@/hosts/host-providers"
|
||||
import * as hostProviders from "@hosts/host-providers"
|
||||
import type { DiffViewProviderCreator, WebviewProviderCreator } from "@/hosts/host-provider"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { vscodeHostBridgeClient } from "@/hosts/vscode/hostbridge/client/host-grpc-client"
|
||||
|
||||
describe("FileContextTracker", () => {
|
||||
@@ -53,7 +53,10 @@ describe("FileContextTracker", () => {
|
||||
mockTaskMetadata = { files_in_context: [], model_usage: [] }
|
||||
getTaskMetadataStub = sandbox.stub(diskModule, "getTaskMetadata").resolves(mockTaskMetadata)
|
||||
saveTaskMetadataStub = sandbox.stub(diskModule, "saveTaskMetadata").resolves()
|
||||
hostProviders.initializeHostProviders(
|
||||
|
||||
// Reset HostProvider before initializing to avoid "already initialized" errors
|
||||
HostProvider.reset()
|
||||
HostProvider.initialize(
|
||||
((_) => {}) as WebviewProviderCreator,
|
||||
(() => {}) as DiffViewProviderCreator,
|
||||
vscodeHostBridgeClient,
|
||||
@@ -66,6 +69,8 @@ describe("FileContextTracker", () => {
|
||||
|
||||
afterEach(() => {
|
||||
sandbox.restore()
|
||||
// Reset HostProvider after each test to ensure clean state
|
||||
HostProvider.reset()
|
||||
})
|
||||
|
||||
it("should add a record when a file is read by a tool", async () => {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getWorkspaceState, updateWorkspaceState } from "@core/storage/state"
|
||||
import { getGlobalState } from "@core/storage/state"
|
||||
import type { FileMetadataEntry } from "./ContextTrackerTypes"
|
||||
import type { ClineMessage } from "@shared/ExtensionMessage"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { getCwd } from "@/utils/path"
|
||||
|
||||
// This class is responsible for tracking file operations that may result in stale context.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { Controller } from ".."
|
||||
import { ClineCheckpointRestore } from "../../../shared/WebviewMessage"
|
||||
import { CheckpointRestoreRequest } from "../../../shared/proto/checkpoints"
|
||||
@@ -15,7 +15,7 @@ export async function checkpointRestore(controller: Controller, request: Checkpo
|
||||
timeout: 3_000,
|
||||
}).catch((error) => {
|
||||
console.log("Failed to init new Cline instance to restore checkpoint", error)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Failed to restore checkpoint",
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as path from "path"
|
||||
import { handleFileServiceRequest } from "./index"
|
||||
import { refreshWorkflowToggles } from "@/core/context/instructions/user-instructions/workflows"
|
||||
import { getCwd, getDesktopDir } from "@/utils/path"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
|
||||
|
||||
/**
|
||||
@@ -44,7 +44,7 @@ export const createRuleFile: FileMethodHandler = async (controller: Controller,
|
||||
|
||||
if (fileExists) {
|
||||
const message = `${fileTypeName} file "${request.filename}" already exists.`
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.WARNING,
|
||||
message,
|
||||
})
|
||||
@@ -61,7 +61,7 @@ export const createRuleFile: FileMethodHandler = async (controller: Controller,
|
||||
await handleFileServiceRequest(controller, "openFile", { value: filePath })
|
||||
|
||||
const message = `Created new ${request.isGlobal ? "global" : "workspace"} ${fileTypeName} file: ${request.filename}`
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message,
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ import { RuleFile, RuleFileRequest } from "@shared/proto/file"
|
||||
import * as path from "path"
|
||||
import { Controller } from ".."
|
||||
import { FileMethodHandler } from "./index"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ export const deleteRuleFile: FileMethodHandler = async (controller: Controller,
|
||||
const fileTypeName = request.type === "workflow" ? "workflow" : "rule"
|
||||
|
||||
const message = `${fileTypeName} file "${fileName}" deleted successfully`
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message,
|
||||
})
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { clineEnvConfig } from "@/config"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { AuthService } from "@/services/auth/AuthService"
|
||||
import { telemetryService } from "@/services/posthog/telemetry/TelemetryService"
|
||||
import { ShowMessageType } from "@/shared/proto/host/window"
|
||||
import { getCwd, getDesktopDir } from "@/utils/path"
|
||||
import { Anthropic } from "@anthropic-ai/sdk"
|
||||
import { buildApiHandler } from "@api/index"
|
||||
import { cleanupLegacyCheckpoints } from "@integrations/checkpoints/CheckpointMigration"
|
||||
import { extractCommitMessage } from "@integrations/git/commit-message-generator"
|
||||
import { downloadTask } from "@integrations/misc/export-markdown"
|
||||
import WorkspaceTracker from "@integrations/workspace/WorkspaceTracker"
|
||||
import { ClineAccountService } from "@services/account/ClineAccountService"
|
||||
@@ -19,7 +22,6 @@ import { TelemetrySetting } from "@shared/TelemetrySetting"
|
||||
import { UserInfo } from "@shared/UserInfo"
|
||||
import { WebviewMessage } from "@shared/WebviewMessage"
|
||||
import { fileExistsAtPath } from "@utils/fs"
|
||||
import { getWorkingState } from "@utils/git"
|
||||
import axios from "axios"
|
||||
import fs from "fs/promises"
|
||||
import { setTimeout as setTimeoutPromise } from "node:timers/promises"
|
||||
@@ -30,13 +32,9 @@ import { ensureMcpServersDirectoryExists, ensureSettingsDirectoryExists, GlobalF
|
||||
import { getAllExtensionState, getGlobalState, getWorkspaceState, storeSecret, updateGlobalState } from "../storage/state"
|
||||
import { Task } from "../task"
|
||||
import { handleGrpcRequest, handleGrpcRequestCancel } from "./grpc-handler"
|
||||
import { sendMcpMarketplaceCatalogEvent } from "./mcp/subscribeToMcpMarketplaceCatalog"
|
||||
import { sendStateUpdate } from "./state/subscribeToState"
|
||||
import { sendAddToInputEvent } from "./ui/subscribeToAddToInput"
|
||||
import { sendMcpMarketplaceCatalogEvent } from "./mcp/subscribeToMcpMarketplaceCatalog"
|
||||
import { AuthService } from "@/services/auth/AuthService"
|
||||
import { ShowMessageType } from "@/shared/proto/host/window"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { clineEnvConfig } from "@/config"
|
||||
|
||||
/*
|
||||
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
|
||||
@@ -118,12 +116,12 @@ export class Controller {
|
||||
updateGlobalState(this.context, "actModeApiProvider", "openrouter"),
|
||||
])
|
||||
await this.postStateToWebview()
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "Successfully logged out of Cline",
|
||||
})
|
||||
} catch (error) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "Logout failed",
|
||||
})
|
||||
@@ -361,7 +359,7 @@ export class Controller {
|
||||
await this.postStateToWebview()
|
||||
} catch (error) {
|
||||
console.error("Failed to handle auth callback:", error)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Failed to log in to Cline",
|
||||
})
|
||||
@@ -399,7 +397,7 @@ export class Controller {
|
||||
console.error("Failed to fetch MCP marketplace:", error)
|
||||
if (!silent) {
|
||||
const errorMessage = error instanceof Error ? error.message : "Failed to fetch MCP marketplace"
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: errorMessage,
|
||||
})
|
||||
@@ -486,7 +484,7 @@ export class Controller {
|
||||
} catch (error) {
|
||||
console.error("Failed to handle cached MCP marketplace:", error)
|
||||
const errorMessage = error instanceof Error ? error.message : "Failed to handle cached MCP marketplace"
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: errorMessage,
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ResetStateRequest } from "../../../shared/proto/state"
|
||||
import { resetGlobalState, resetWorkspaceState } from "../../../core/storage/state"
|
||||
import { sendChatButtonClickedEvent } from "../ui/subscribeToChatButtonClicked"
|
||||
import { ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
|
||||
/**
|
||||
* Resets the extension state to its defaults
|
||||
@@ -15,13 +15,13 @@ import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
export async function resetState(controller: Controller, request: ResetStateRequest): Promise<Empty> {
|
||||
try {
|
||||
if (request.global) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "Resetting global state...",
|
||||
})
|
||||
await resetGlobalState(controller.context)
|
||||
} else {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "Resetting workspace state...",
|
||||
})
|
||||
@@ -33,7 +33,7 @@ export async function resetState(controller: Controller, request: ResetStateRequ
|
||||
controller.task = undefined
|
||||
}
|
||||
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "State reset",
|
||||
})
|
||||
@@ -44,7 +44,7 @@ export async function resetState(controller: Controller, request: ResetStateRequ
|
||||
return Empty.create()
|
||||
} catch (error) {
|
||||
console.error("Error resetting state:", error)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Failed to reset state: ${error instanceof Error ? error.message : String(error)}`,
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Controller } from "../index"
|
||||
import * as proto from "@/shared/proto"
|
||||
import { updateGlobalState } from "../../storage/state"
|
||||
import { TerminalInfo } from "@/integrations/terminal/TerminalRegistry"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
|
||||
|
||||
export async function updateDefaultTerminalProfile(
|
||||
@@ -27,7 +27,7 @@ export async function updateDefaultTerminalProfile(
|
||||
// Show information message if terminals were closed
|
||||
if (closedCount > 0) {
|
||||
const message = `Closed ${closedCount} ${closedCount === 1 ? "terminal" : "terminals"} with different profile.`
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message,
|
||||
})
|
||||
@@ -38,7 +38,7 @@ export async function updateDefaultTerminalProfile(
|
||||
const message =
|
||||
`${busyTerminals.length} busy ${busyTerminals.length === 1 ? "terminal has" : "terminals have"} a different profile. ` +
|
||||
`Close ${busyTerminals.length === 1 ? "it" : "them"} to use the new profile for all commands.`
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.WARNING,
|
||||
message,
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ import { DeleteAllTaskHistoryCount } from "../../../shared/proto/task"
|
||||
import { getGlobalState, updateGlobalState } from "../../storage/state"
|
||||
import { fileExistsAtPath } from "../../../utils/fs"
|
||||
import { ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
|
||||
/**
|
||||
* Deletes all task history, with an option to preserve favorites
|
||||
@@ -23,7 +23,7 @@ export async function deleteAllTaskHistory(controller: Controller): Promise<Dele
|
||||
const totalTasks = taskHistory.length
|
||||
|
||||
const userChoice = (
|
||||
await getHostBridgeProvider().windowClient.showMessage(
|
||||
await HostProvider.window.showMessage(
|
||||
ShowMessageRequest.create({
|
||||
type: ShowMessageType.WARNING,
|
||||
message: "What would you like to delete?",
|
||||
@@ -67,7 +67,7 @@ export async function deleteAllTaskHistory(controller: Controller): Promise<Dele
|
||||
} else {
|
||||
// No favorited tasks found - show warning and ask user what to do
|
||||
const answer = (
|
||||
await getHostBridgeProvider().windowClient.showMessage({
|
||||
await HostProvider.window.showMessage({
|
||||
type: ShowMessageType.WARNING,
|
||||
message: "No favorited tasks found. Would you like to delete all tasks anyway?",
|
||||
options: {
|
||||
@@ -103,7 +103,7 @@ export async function deleteAllTaskHistory(controller: Controller): Promise<Dele
|
||||
await fs.rm(checkpointsDirPath, { recursive: true, force: true })
|
||||
}
|
||||
} catch (error) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Encountered error while deleting task history, there may be some files left behind. Error: ${error instanceof Error ? error.message : String(error)}`,
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Controller } from ".."
|
||||
import { Empty, StringArrayRequest } from "../../../shared/proto/common"
|
||||
import { TaskMethodHandler } from "./index"
|
||||
import { fileExistsAtPath } from "../../../utils/fs"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ export const deleteTasksWithIds: TaskMethodHandler = async (
|
||||
? "Are you sure you want to delete this task? This action cannot be undone."
|
||||
: `Are you sure you want to delete these ${taskCount} tasks? This action cannot be undone.`
|
||||
|
||||
const userChoice = await getHostBridgeProvider().windowClient.showMessage({
|
||||
const userChoice = await HostProvider.window.showMessage({
|
||||
type: ShowMessageType.WARNING,
|
||||
message,
|
||||
options: { modal: true, items: ["Delete"] },
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Controller } from "../index"
|
||||
import { EmptyRequest, Empty, String } from "@shared/proto/common"
|
||||
import * as hostProviders from "@hosts/host-providers"
|
||||
import { EmptyRequest, String } from "@shared/proto/common"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { WebviewProviderType } from "@/shared/webview/types"
|
||||
|
||||
/**
|
||||
@@ -10,7 +10,7 @@ import { WebviewProviderType } from "@/shared/webview/types"
|
||||
* @returns Empty response
|
||||
*/
|
||||
export async function getWebviewHtml(_controller: Controller, _: EmptyRequest): Promise<String> {
|
||||
const webviewProvider = hostProviders.createWebviewProvider(WebviewProviderType.SIDEBAR)
|
||||
const webviewProvider = HostProvider.get().createWebviewProvider(WebviewProviderType.SIDEBAR)
|
||||
|
||||
return Promise.resolve(String.create({ value: webviewProvider.getHtmlContent() }))
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import { getWorkingState } from "@utils/git"
|
||||
import { FileContextTracker } from "../context/context-tracking/FileContextTracker"
|
||||
import { getCwd } from "@/utils/path"
|
||||
import { openExternal } from "@utils/env"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
|
||||
|
||||
export async function openMention(mention?: string): Promise<void> {
|
||||
@@ -78,7 +78,7 @@ export async function parseMentions(
|
||||
await urlContentFetcher.launchBrowser()
|
||||
} catch (error) {
|
||||
launchBrowserError = error
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Error fetching content for ${urlMention}: ${error.message}`,
|
||||
})
|
||||
@@ -98,7 +98,7 @@ export async function parseMentions(
|
||||
const markdown = await urlContentFetcher.urlToMarkdown(mention)
|
||||
result = markdown
|
||||
} catch (error) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Error fetching content for ${mention}: ${error.message}`,
|
||||
})
|
||||
|
||||
@@ -37,7 +37,7 @@ import pWaitFor from "p-wait-for"
|
||||
import * as path from "path"
|
||||
import * as vscode from "vscode"
|
||||
|
||||
import { createDiffViewProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ClineErrorType } from "@/services/error/ClineError"
|
||||
import { ErrorService } from "@/services/error/ErrorService"
|
||||
import { parseAssistantMessageV2, parseAssistantMessageV3, ToolUseName } from "@core/assistant-message"
|
||||
@@ -188,7 +188,7 @@ export class Task {
|
||||
this.urlContentFetcher = new UrlContentFetcher(context)
|
||||
this.browserSession = new BrowserSession(context, browserSettings)
|
||||
this.contextManager = new ContextManager()
|
||||
this.diffViewProvider = createDiffViewProvider()
|
||||
this.diffViewProvider = HostProvider.get().createDiffViewProvider()
|
||||
this.autoApprovalSettings = autoApprovalSettings
|
||||
this.browserSettings = browserSettings
|
||||
this.chatSettings = chatSettings
|
||||
|
||||
@@ -10,7 +10,7 @@ import path from "node:path"
|
||||
import { v4 as uuidv4 } from "uuid"
|
||||
import { Uri } from "vscode"
|
||||
import { ExtensionMessage } from "@/shared/ExtensionMessage"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
|
||||
|
||||
export abstract class WebviewProvider {
|
||||
@@ -264,7 +264,7 @@ export abstract class WebviewProvider {
|
||||
} catch (error) {
|
||||
// Only show the error message if not in development mode.
|
||||
if (!process.env.IS_DEV) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message:
|
||||
"Cline: Local webview dev server is not running, HMR will not work. Please run 'npm run dev:webview' before launching the extension to enable HMR. Using bundled assets.",
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Controller } from "@core/controller"
|
||||
import { HistoryItem } from "@shared/HistoryItem"
|
||||
import { ClineMessage } from "@shared/ExtensionMessage"
|
||||
import { ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
|
||||
/**
|
||||
* Registers development-only commands for task manipulation.
|
||||
@@ -99,7 +99,7 @@ export function registerTaskCommands(context: vscode.ExtensionContext, controlle
|
||||
await controller.postStateToWebview()
|
||||
|
||||
const message = `Created ${tasksCount} test tasks`
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message,
|
||||
})
|
||||
|
||||
+10
-14
@@ -31,14 +31,13 @@ import {
|
||||
|
||||
import { sendFocusChatInputEvent } from "./core/controller/ui/subscribeToFocusChatInput"
|
||||
import { FileContextTracker } from "./core/context/context-tracking/FileContextTracker"
|
||||
import * as hostProviders from "@hosts/host-providers"
|
||||
import { vscodeHostBridgeClient } from "@/hosts/vscode/hostbridge/client/host-grpc-client"
|
||||
import { VscodeWebviewProvider } from "./hosts/vscode/VscodeWebviewProvider"
|
||||
import { ExtensionContext } from "vscode"
|
||||
import { AuthService } from "./services/auth/AuthService"
|
||||
import { writeTextToClipboard, readTextFromClipboard } from "@/utils/env"
|
||||
import { VscodeDiffViewProvider } from "./hosts/vscode/VscodeDiffViewProvider"
|
||||
import { getHostBridgeProvider } from "@hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageType } from "./shared/proto/host/window"
|
||||
import { GitCommitGenerator } from "./integrations/git/commit-message-generator"
|
||||
/*
|
||||
@@ -85,7 +84,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
// Version checking for autoupdate notification
|
||||
const currentVersion = context.extension.packageJSON.version
|
||||
const previousVersion = context.globalState.get<string>("clineVersion")
|
||||
const sidebarWebview = hostProviders.createWebviewProvider(WebviewProviderType.SIDEBAR)
|
||||
const sidebarWebview = HostProvider.get().createWebviewProvider(WebviewProviderType.SIDEBAR)
|
||||
|
||||
const testModeWatchers = await initializeTestMode(sidebarWebview)
|
||||
// Initialize test mode and add disposables to context
|
||||
@@ -110,10 +109,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
const message = `Cline has been updated to v${currentVersion}`
|
||||
await vscode.commands.executeCommand("claude-dev.SidebarProvider.focus")
|
||||
await new Promise((resolve) => setTimeout(resolve, 200))
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message,
|
||||
})
|
||||
HostProvider.window.showMessage({ type: ShowMessageType.INFORMATION, message })
|
||||
// Record that we've shown the popup for this version.
|
||||
await context.globalState.update("clineLastPopupNotificationVersion", currentVersion)
|
||||
}
|
||||
@@ -192,7 +188,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
Logger.log("Opening Cline in new tab")
|
||||
// (this example uses webviewProvider activation event which is necessary to deserialize cached webview, but since we use retainContextWhenHidden, we don't need to use that event)
|
||||
// https://github.com/microsoft/vscode-extension-samples/blob/main/webview-sample/src/extension.ts
|
||||
const tabWebview = hostProviders.createWebviewProvider(WebviewProviderType.TAB)
|
||||
const tabWebview = HostProvider.get().createWebviewProvider(WebviewProviderType.TAB)
|
||||
//const column = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined
|
||||
const lastCol = Math.max(...vscode.window.visibleTextEditors.map((editor) => editor.viewColumn || 0))
|
||||
|
||||
@@ -415,7 +411,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
// Ensure clipboard is restored even if an error occurs
|
||||
await writeTextToClipboard(tempCopyBuffer)
|
||||
console.error("Error getting terminal contents:", error)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Failed to get terminal contents",
|
||||
})
|
||||
@@ -554,7 +550,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
const selectedText = editor.document.getText(range)
|
||||
if (!selectedText.trim()) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "Please select some code to explain.",
|
||||
})
|
||||
@@ -579,7 +575,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
const selectedText = editor.document.getText(range)
|
||||
if (!selectedText.trim()) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "Please select some code to improve.",
|
||||
})
|
||||
@@ -647,7 +643,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
sendFocusChatInputEvent(clientId)
|
||||
} else {
|
||||
console.error("FocusChatInput: Could not find or activate a Cline webview to focus.")
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Could not activate Cline view. Please try opening it manually from the Activity Bar.",
|
||||
})
|
||||
@@ -695,7 +691,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
|
||||
function maybeSetupHostProviders(context: ExtensionContext) {
|
||||
if (!hostProviders.isSetup) {
|
||||
if (!HostProvider.isInitialized()) {
|
||||
console.log("Setting up vscode host providers...")
|
||||
const createWebview = function (type: WebviewProviderType) {
|
||||
return new VscodeWebviewProvider(context, outputChannel, type)
|
||||
@@ -703,7 +699,7 @@ function maybeSetupHostProviders(context: ExtensionContext) {
|
||||
const createDiffView = function () {
|
||||
return new VscodeDiffViewProvider()
|
||||
}
|
||||
hostProviders.initializeHostProviders(createWebview, createDiffView, vscodeHostBridgeClient)
|
||||
HostProvider.initialize(createWebview, createDiffView, vscodeHostBridgeClient)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { DiffViewProvider } from "@/integrations/editor/DiffViewProvider"
|
||||
import { status } from "@grpc/grpc-js"
|
||||
|
||||
@@ -9,7 +9,7 @@ export class ExternalDiffViewProvider extends DiffViewProvider {
|
||||
if (!this.absolutePath) {
|
||||
return
|
||||
}
|
||||
const response = await getHostBridgeProvider().diffClient.openDiff({
|
||||
const response = await HostProvider.diff.openDiff({
|
||||
path: this.absolutePath,
|
||||
content: this.originalContent ?? "",
|
||||
})
|
||||
@@ -24,7 +24,7 @@ export class ExternalDiffViewProvider extends DiffViewProvider {
|
||||
if (!this.activeDiffEditorId) {
|
||||
return
|
||||
}
|
||||
await getHostBridgeProvider().diffClient.replaceText({
|
||||
await HostProvider.diff.replaceText({
|
||||
diffId: this.activeDiffEditorId,
|
||||
content: content,
|
||||
startLine: rangeToReplace.startLine,
|
||||
@@ -36,7 +36,7 @@ export class ExternalDiffViewProvider extends DiffViewProvider {
|
||||
if (!this.activeDiffEditorId) {
|
||||
return
|
||||
}
|
||||
await getHostBridgeProvider().diffClient.truncateDocument({
|
||||
await HostProvider.diff.truncateDocument({
|
||||
diffId: this.activeDiffEditorId,
|
||||
endLine: lineNumber,
|
||||
})
|
||||
@@ -47,7 +47,7 @@ export class ExternalDiffViewProvider extends DiffViewProvider {
|
||||
return false
|
||||
}
|
||||
try {
|
||||
await getHostBridgeProvider().diffClient.saveDocument({ diffId: this.activeDiffEditorId })
|
||||
await HostProvider.diff.saveDocument({ diffId: this.activeDiffEditorId })
|
||||
return true
|
||||
} catch (err: any) {
|
||||
if (err.code === status.NOT_FOUND) {
|
||||
@@ -69,7 +69,7 @@ export class ExternalDiffViewProvider extends DiffViewProvider {
|
||||
if (!this.activeDiffEditorId) {
|
||||
return undefined
|
||||
}
|
||||
return (await getHostBridgeProvider().diffClient.getDocumentText({ diffId: this.activeDiffEditorId })).content
|
||||
return (await HostProvider.diff.getDocumentText({ diffId: this.activeDiffEditorId })).content
|
||||
}
|
||||
|
||||
protected override async getNewDiagnosticProblems(): Promise<string> {
|
||||
@@ -81,7 +81,7 @@ export class ExternalDiffViewProvider extends DiffViewProvider {
|
||||
if (!this.activeDiffEditorId) {
|
||||
return
|
||||
}
|
||||
await getHostBridgeProvider().diffClient.closeDiff({ diffId: this.activeDiffEditorId })
|
||||
await HostProvider.diff.closeDiff({ diffId: this.activeDiffEditorId })
|
||||
this.activeDiffEditorId = undefined
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import { WebviewProvider } from "@core/webview"
|
||||
import { HostBridgeClientProvider } from "./host-provider-types"
|
||||
import { WebviewProviderType } from "@/shared/webview/types"
|
||||
import { DiffViewProvider } from "@/integrations/editor/DiffViewProvider"
|
||||
|
||||
/**
|
||||
* Singleton class that manages host-specific providers for dependency injection.
|
||||
*
|
||||
* This system runs on two different platforms (VSCode extension and cline-core),
|
||||
* so all the host-specific classes and properties are contained in here. The
|
||||
* rest of the codebase can use the host provider interface to access platform-specific
|
||||
* implementations in a platform-agnostic way.
|
||||
*
|
||||
* Usage:
|
||||
* - Initialize once: HostProvider.initialize(webviewCreator, diffCreator, hostBridge)
|
||||
* - Access HostBridge services: HostProvider.window.showMessage()
|
||||
* - Access Host Provider factories: HostProvider.get().createDiffViewProvider()
|
||||
*/
|
||||
export class HostProvider {
|
||||
private static instance: HostProvider | null = null
|
||||
|
||||
createWebviewProvider: WebviewProviderCreator
|
||||
createDiffViewProvider: DiffViewProviderCreator
|
||||
hostBridge: HostBridgeClientProvider
|
||||
|
||||
// Private constructor to enforce singleton pattern
|
||||
private constructor(
|
||||
createWebviewProvider: WebviewProviderCreator,
|
||||
createDiffViewProvider: DiffViewProviderCreator,
|
||||
hostBridge: HostBridgeClientProvider,
|
||||
) {
|
||||
this.createWebviewProvider = createWebviewProvider
|
||||
this.createDiffViewProvider = createDiffViewProvider
|
||||
this.hostBridge = hostBridge
|
||||
}
|
||||
|
||||
public static initialize(
|
||||
webviewProviderCreator: WebviewProviderCreator,
|
||||
diffViewProviderCreator: DiffViewProviderCreator,
|
||||
hostBridgeProvider: HostBridgeClientProvider,
|
||||
): HostProvider {
|
||||
if (HostProvider.instance) {
|
||||
throw new Error("Host providers have already been initialized.")
|
||||
}
|
||||
HostProvider.instance = new HostProvider(webviewProviderCreator, diffViewProviderCreator, hostBridgeProvider)
|
||||
return HostProvider.instance
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the singleton instance
|
||||
*/
|
||||
public static get(): HostProvider {
|
||||
if (!HostProvider.instance) {
|
||||
throw new Error("HostProvider not initialized. Call HostProvider.initialize() first.")
|
||||
}
|
||||
return HostProvider.instance
|
||||
}
|
||||
|
||||
public static isInitialized(): boolean {
|
||||
return !!HostProvider.instance
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the HostProvider instance (primarily for testing)
|
||||
* This allows tests to reinitialize the HostProvider with different configurations
|
||||
*/
|
||||
public static reset(): void {
|
||||
HostProvider.instance = null
|
||||
}
|
||||
|
||||
// Static service accessors for more concise access for callers.
|
||||
public static get watch() {
|
||||
return HostProvider.get().hostBridge.watchServiceClient
|
||||
}
|
||||
|
||||
public static get workspace() {
|
||||
return HostProvider.get().hostBridge.workspaceClient
|
||||
}
|
||||
|
||||
public static get env() {
|
||||
return HostProvider.get().hostBridge.envClient
|
||||
}
|
||||
|
||||
public static get window() {
|
||||
return HostProvider.get().hostBridge.windowClient
|
||||
}
|
||||
|
||||
public static get diff() {
|
||||
return HostProvider.get().hostBridge.diffClient
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A function that creates WebviewProvider instances
|
||||
*/
|
||||
export type WebviewProviderCreator = (providerType: WebviewProviderType) => WebviewProvider
|
||||
|
||||
/**
|
||||
* A function that creates DiffViewProvider instances
|
||||
*/
|
||||
export type DiffViewProviderCreator = () => DiffViewProvider
|
||||
@@ -1,49 +0,0 @@
|
||||
import { WebviewProvider } from "@core/webview"
|
||||
import { HostBridgeClientProvider } from "./host-provider-types"
|
||||
import { WebviewProviderType } from "@/shared/webview/types"
|
||||
import { DiffViewProvider } from "@/integrations/editor/DiffViewProvider"
|
||||
|
||||
/**
|
||||
* A function that creates WebviewProvider instances
|
||||
*/
|
||||
export type WebviewProviderCreator = (providerType: WebviewProviderType) => WebviewProvider
|
||||
|
||||
export type DiffViewProviderCreator = () => DiffViewProvider
|
||||
|
||||
let _webviewProviderCreator: WebviewProviderCreator | undefined
|
||||
let _diffViewProviderCreator: DiffViewProviderCreator | undefined
|
||||
let _hostBridgeProvider: HostBridgeClientProvider | undefined
|
||||
|
||||
export var isSetup: boolean = false
|
||||
|
||||
export function initializeHostProviders(
|
||||
webviewProviderCreator: WebviewProviderCreator,
|
||||
diffViewProviderCreator: DiffViewProviderCreator,
|
||||
hostBridgeProvider: HostBridgeClientProvider,
|
||||
) {
|
||||
_webviewProviderCreator = webviewProviderCreator
|
||||
_diffViewProviderCreator = diffViewProviderCreator
|
||||
_hostBridgeProvider = hostBridgeProvider
|
||||
isSetup = true
|
||||
}
|
||||
|
||||
export function createWebviewProvider(providerType: WebviewProviderType): WebviewProvider {
|
||||
if (!_webviewProviderCreator) {
|
||||
throw Error("Host providers not initialized")
|
||||
}
|
||||
return _webviewProviderCreator(providerType)
|
||||
}
|
||||
|
||||
export function createDiffViewProvider(): DiffViewProvider {
|
||||
if (!_diffViewProviderCreator) {
|
||||
throw Error("Host providers not initialized")
|
||||
}
|
||||
return _diffViewProviderCreator()
|
||||
}
|
||||
|
||||
export function getHostBridgeProvider(): HostBridgeClientProvider {
|
||||
if (!_hostBridgeProvider) {
|
||||
throw Error("Host providers not initialized")
|
||||
}
|
||||
return _hostBridgeProvider
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { formatResponse } from "@core/prompts/responses"
|
||||
import * as diff from "diff"
|
||||
import { detectEncoding } from "../misc/extract-text"
|
||||
import * as iconv from "iconv-lite"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
|
||||
export abstract class DiffViewProvider {
|
||||
editType?: "create" | "modify"
|
||||
@@ -250,7 +250,7 @@ export abstract class DiffViewProvider {
|
||||
// get text after save in case there is any auto-formatting done by the editor
|
||||
const postSaveContent = (await this.getDocumentText()) || ""
|
||||
|
||||
await getHostBridgeProvider().windowClient.showTextDocument({
|
||||
await HostProvider.window.showTextDocument({
|
||||
path: this.absolutePath,
|
||||
options: {
|
||||
preview: false,
|
||||
@@ -327,7 +327,7 @@ export abstract class DiffViewProvider {
|
||||
await this.saveDocument()
|
||||
console.log(`File ${this.absolutePath} has been reverted to its original content.`)
|
||||
if (this.documentWasOpen) {
|
||||
await getHostBridgeProvider().windowClient.showTextDocument({
|
||||
await HostProvider.window.showTextDocument({
|
||||
path: this.absolutePath,
|
||||
options: {
|
||||
preview: false,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as vscode from "vscode"
|
||||
import { writeTextToClipboard } from "@utils/env"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageType, ShowTextDocumentRequest } from "@/shared/proto/host/window"
|
||||
import { buildApiHandler } from "@/api"
|
||||
import { getAllExtensionState } from "@/core/storage/state"
|
||||
@@ -20,7 +20,7 @@ let commitGenerationAbortController: AbortController | undefined = undefined
|
||||
async function generate(context: vscode.ExtensionContext, scm?: vscode.SourceControl) {
|
||||
const cwd = await getCwd()
|
||||
if (!context || !cwd) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "No workspace folder open",
|
||||
})
|
||||
@@ -29,7 +29,7 @@ async function generate(context: vscode.ExtensionContext, scm?: vscode.SourceCon
|
||||
|
||||
const gitDiff = await getWorkingState(cwd)
|
||||
if (gitDiff === "No changes in working directory") {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "No changes in workspace for commit message",
|
||||
})
|
||||
@@ -157,7 +157,7 @@ export function extractCommitMessage(str: string): string {
|
||||
*/
|
||||
export async function copyCommitMessageToClipboard(message: string): Promise<void> {
|
||||
await writeTextToClipboard(message)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "Commit message copied to clipboard",
|
||||
})
|
||||
@@ -173,7 +173,7 @@ export async function showCommitMessageOptions(message: string): Promise<void> {
|
||||
const editAction = "Edit Message"
|
||||
|
||||
const selectedAction = (
|
||||
await getHostBridgeProvider().windowClient.showMessage({
|
||||
await HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "Commit message generated",
|
||||
options: {
|
||||
@@ -214,19 +214,19 @@ async function applyCommitMessageToGitInput(message: string): Promise<void> {
|
||||
if (api && api.repositories.length > 0) {
|
||||
const repo = api.repositories[0]
|
||||
repo.inputBox.value = message
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "Commit message applied to Git input",
|
||||
})
|
||||
} else {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "No Git repositories found",
|
||||
})
|
||||
await copyCommitMessageToClipboard(message)
|
||||
}
|
||||
} else {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Git extension not found",
|
||||
})
|
||||
@@ -244,12 +244,12 @@ async function editCommitMessage(message: string): Promise<void> {
|
||||
language: "markdown",
|
||||
})
|
||||
|
||||
await getHostBridgeProvider().windowClient.showTextDocument(
|
||||
await HostProvider.window.showTextDocument(
|
||||
ShowTextDocumentRequest.create({
|
||||
path: document.uri.fsPath,
|
||||
}),
|
||||
)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "Edit the commit message and copy when ready",
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Anthropic } from "@anthropic-ai/sdk"
|
||||
import os from "os"
|
||||
import * as path from "path"
|
||||
import * as vscode from "vscode"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowTextDocumentRequest, ShowTextDocumentOptions, ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
|
||||
import { writeFile } from "@utils/fs"
|
||||
|
||||
@@ -41,14 +41,14 @@ export async function downloadTask(dateTs: number, conversationHistory: Anthropi
|
||||
try {
|
||||
// Write content to the selected location
|
||||
await writeFile(saveUri.fsPath, markdownContent)
|
||||
await getHostBridgeProvider().windowClient.showTextDocument(
|
||||
await HostProvider.window.showTextDocument(
|
||||
ShowTextDocumentRequest.create({
|
||||
path: saveUri.fsPath,
|
||||
options: ShowTextDocumentOptions.create({ preview: true }),
|
||||
}),
|
||||
)
|
||||
} catch (error) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Failed to save markdown file: ${error instanceof Error ? error.message : String(error)}`,
|
||||
})
|
||||
|
||||
@@ -2,14 +2,14 @@ import * as path from "path"
|
||||
import * as os from "os"
|
||||
import * as vscode from "vscode"
|
||||
import { arePathsEqual } from "@utils/path"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
|
||||
import { writeFile } from "@utils/fs"
|
||||
|
||||
export async function openImage(dataUri: string) {
|
||||
const matches = dataUri.match(/^data:image\/([a-zA-Z]+);base64,(.+)$/)
|
||||
if (!matches) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Invalid data URI format",
|
||||
})
|
||||
@@ -22,7 +22,7 @@ export async function openImage(dataUri: string) {
|
||||
await writeFile(tempFilePath, new Uint8Array(imageBuffer))
|
||||
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(tempFilePath))
|
||||
} catch (error) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Error opening image: ${error}`,
|
||||
})
|
||||
@@ -50,12 +50,12 @@ export async function openFile(absolutePath: string) {
|
||||
}
|
||||
} catch {} // not essential, sometimes tab operations fail
|
||||
|
||||
await getHostBridgeProvider().windowClient.showTextDocument({
|
||||
await HostProvider.window.showTextDocument({
|
||||
path: uri.fsPath,
|
||||
options: { preview: false },
|
||||
})
|
||||
} catch (error) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Could not open file!`,
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as vscode from "vscode"
|
||||
import fs from "fs/promises"
|
||||
import * as path from "path"
|
||||
import sizeOf from "image-size"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageRequest, ShowMessageType, ShowOpenDialogueRequest } from "@/shared/proto/host/window"
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@ export async function selectFiles(imagesAllowed: boolean): Promise<{ images: str
|
||||
const IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "webp"] // supported by anthropic and openrouter
|
||||
const OTHER_FILE_EXTENSIONS = ["xml", "json", "txt", "log", "md", "docx", "ipynb", "pdf", "xlsx", "csv"]
|
||||
|
||||
const showDialogueResponse = await getHostBridgeProvider().windowClient.showOpenDialogue(
|
||||
const showDialogueResponse = await HostProvider.window.showOpenDialogue(
|
||||
ShowOpenDialogueRequest.create({
|
||||
canSelectMany: true,
|
||||
openLabel: "Select",
|
||||
@@ -46,7 +46,7 @@ export async function selectFiles(imagesAllowed: boolean): Promise<{ images: str
|
||||
const dimensions = sizeOf(uint8Array) // Get dimensions from Uint8Array
|
||||
if (dimensions.width! > 7500 || dimensions.height! > 7500) {
|
||||
console.warn(`Image dimensions exceed 7500px, skipping: ${filePath}`)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Image too large: ${path.basename(filePath)} was skipped (dimensions exceed 7500px).`,
|
||||
})
|
||||
@@ -54,7 +54,7 @@ export async function selectFiles(imagesAllowed: boolean): Promise<{ images: str
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error reading file or getting dimensions for ${filePath}:`, error)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Could not read dimensions for ${path.basename(filePath)}, skipping.`,
|
||||
})
|
||||
@@ -72,7 +72,7 @@ export async function selectFiles(imagesAllowed: boolean): Promise<{ images: str
|
||||
const stats = await fs.stat(filePath)
|
||||
if (stats.size > 20 * 1000 * 1024) {
|
||||
console.warn(`File too large, skipping: ${filePath}`)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `File too large: ${path.basename(filePath)} was skipped (size exceeds 20MB).`,
|
||||
})
|
||||
@@ -80,7 +80,7 @@ export async function selectFiles(imagesAllowed: boolean): Promise<{ images: str
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error checking file size for ${filePath}:`, error)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Could not check file size for ${path.basename(filePath)}, skipping.`,
|
||||
})
|
||||
|
||||
+11
-11
@@ -37,7 +37,7 @@ import { ExtensionMessage } from "@shared/ExtensionMessage"
|
||||
import { DEFAULT_REQUEST_TIMEOUT_MS } from "./constants"
|
||||
import { McpConnection, McpServerConfig, Transport } from "./types"
|
||||
import { BaseConfigSchema, ServerConfigSchema, McpSettingsSchema } from "./schemas"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageType } from "@/shared/proto/host/window"
|
||||
export class McpHub {
|
||||
getMcpServersPath: () => Promise<string>
|
||||
@@ -109,7 +109,7 @@ export class McpHub {
|
||||
try {
|
||||
config = JSON.parse(content)
|
||||
} catch (error) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Invalid MCP settings format. Please ensure your settings follow the correct JSON format.",
|
||||
})
|
||||
@@ -119,7 +119,7 @@ export class McpHub {
|
||||
// Validate against schema
|
||||
const result = McpSettingsSchema.safeParse(config)
|
||||
if (!result.success) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Invalid MCP settings schema.",
|
||||
})
|
||||
@@ -138,7 +138,7 @@ export class McpHub {
|
||||
|
||||
// Subscribe to file changes using the gRPC WatchService
|
||||
console.log("[DEBUG] subscribing to mcp file changes")
|
||||
const cancelSubscription = getHostBridgeProvider().watchServiceClient.subscribeToFile(
|
||||
const cancelSubscription = HostProvider.watch.subscribeToFile(
|
||||
SubscribeToFileRequest.create({
|
||||
path: settingsPath,
|
||||
}),
|
||||
@@ -420,7 +420,7 @@ export class McpHub {
|
||||
console.log(`[MCP Fallback Notification] ${name}:`, JSON.stringify(notification, null, 2))
|
||||
|
||||
// Show in VS Code for visibility
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: `MCP ${name}: ${notification.method || "unknown"} - ${JSON.stringify(notification.params || {})}`,
|
||||
})
|
||||
@@ -702,7 +702,7 @@ export class McpHub {
|
||||
const connection = this.connections.find((conn) => conn.server.name === serverName)
|
||||
const config = connection?.server.config
|
||||
if (config) {
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: `Restarting ${serverName} MCP server...`,
|
||||
})
|
||||
@@ -714,13 +714,13 @@ export class McpHub {
|
||||
await this.deleteConnection(serverName)
|
||||
// Try to connect again using existing config
|
||||
await this.connectToServer(serverName, JSON.parse(config), "internal")
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: `${serverName} MCP server connected`,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(`Failed to restart connection for ${serverName}:`, error)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Failed to connect to ${serverName} MCP server`,
|
||||
})
|
||||
@@ -809,7 +809,7 @@ export class McpHub {
|
||||
if (error instanceof Error) {
|
||||
console.error("Error details:", error.message, error.stack)
|
||||
}
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Failed to update server state: ${error instanceof Error ? error.message : String(error)}`,
|
||||
})
|
||||
@@ -969,7 +969,7 @@ export class McpHub {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to update autoApprove settings:", error)
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Failed to update autoApprove settings",
|
||||
})
|
||||
@@ -1090,7 +1090,7 @@ export class McpHub {
|
||||
if (error instanceof Error) {
|
||||
console.error("Error details:", error.message, error.stack)
|
||||
}
|
||||
getHostBridgeProvider().windowClient.showMessage({
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: `Failed to update server timeout: ${error instanceof Error ? error.message : String(error)}`,
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
import { Logger } from "../logging/Logger"
|
||||
import { createTestServer, shutdownTestServer } from "./TestServer"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
|
||||
// State variable
|
||||
let isTestMode = false
|
||||
@@ -34,7 +34,7 @@ export function isInTestMode(): boolean {
|
||||
*/
|
||||
async function checkForTestMode(): Promise<boolean> {
|
||||
// Get all workspace folders
|
||||
const workspaceFolders = await getHostBridgeProvider().workspaceClient.getWorkspacePaths({})
|
||||
const workspaceFolders = await HostProvider.workspace.getWorkspacePaths({})
|
||||
|
||||
// Check each workspace folder for an evals.env file
|
||||
for (const folder of workspaceFolders.paths) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Controller } from "@core/controller"
|
||||
import { ExternalDiffViewProvider } from "@hosts/external/ExternalDiffviewProvider"
|
||||
import { ExternalWebviewProvider } from "@hosts/external/ExternalWebviewProvider"
|
||||
import { ExternalHostBridgeClientManager } from "@hosts/external/host-bridge-client-manager"
|
||||
import * as hostProviders from "@hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { WebviewProviderType } from "@shared/webview/types"
|
||||
import { v4 as uuidv4 } from "uuid"
|
||||
import { log } from "./utils"
|
||||
@@ -16,7 +16,7 @@ async function main() {
|
||||
// Set up global error handlers to prevent process crashes
|
||||
setupGlobalErrorHandlers()
|
||||
|
||||
hostProviders.initializeHostProviders(createWebview, createDiffView, new ExternalHostBridgeClientManager())
|
||||
HostProvider.initialize(createWebview, createDiffView, new ExternalHostBridgeClientManager())
|
||||
activate(extensionContext)
|
||||
const controller = new Controller(extensionContext, outputChannel, postMessage, uuidv4())
|
||||
startProtobusService(controller)
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { StringRequest, EmptyRequest } from "@/shared/proto/common"
|
||||
|
||||
/**
|
||||
@@ -9,7 +9,7 @@ import { StringRequest, EmptyRequest } from "@/shared/proto/common"
|
||||
*/
|
||||
export async function writeTextToClipboard(text: string): Promise<void> {
|
||||
try {
|
||||
await getHostBridgeProvider().envClient.clipboardWriteText(StringRequest.create({ value: text }))
|
||||
await HostProvider.env.clipboardWriteText(StringRequest.create({ value: text }))
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error)
|
||||
throw new Error(`Failed to write to clipboard: ${errorMessage}`)
|
||||
@@ -23,7 +23,7 @@ export async function writeTextToClipboard(text: string): Promise<void> {
|
||||
*/
|
||||
export async function readTextFromClipboard(): Promise<string> {
|
||||
try {
|
||||
const response = await getHostBridgeProvider().envClient.clipboardReadText(EmptyRequest.create({}))
|
||||
const response = await HostProvider.env.clipboardReadText(EmptyRequest.create({}))
|
||||
return response.value
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error)
|
||||
@@ -39,7 +39,7 @@ export async function readTextFromClipboard(): Promise<string> {
|
||||
*/
|
||||
export async function openExternal(url: string): Promise<void> {
|
||||
try {
|
||||
await getHostBridgeProvider().envClient.openExternal(StringRequest.create({ value: url }))
|
||||
await HostProvider.env.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}`)
|
||||
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import os from "os"
|
||||
import * as path from "path"
|
||||
import * as vscode from "vscode"
|
||||
@@ -104,7 +104,7 @@ export function getReadablePath(cwd: string, relPath?: string): string {
|
||||
|
||||
// Returns the path of the first workspace directory, or the defaultCwdPath if there is no workspace open.
|
||||
export async function getCwd(defaultCwd = ""): Promise<string> {
|
||||
const workspacePaths = await getHostBridgeProvider().workspaceClient.getWorkspacePaths({})
|
||||
const workspacePaths = await HostProvider.workspace.getWorkspacePaths({})
|
||||
return workspacePaths.paths.shift() || defaultCwd
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ export async function getWorkspacePath(defaultCwd = ""): Promise<string> {
|
||||
return await getCwd(defaultCwd)
|
||||
}
|
||||
|
||||
const workspacePaths = (await getHostBridgeProvider().workspaceClient.getWorkspacePaths({})).paths
|
||||
const workspacePaths = (await HostProvider.workspace.getWorkspacePaths({})).paths
|
||||
for (const workspacePath of workspacePaths) {
|
||||
if (isLocatedInPath(workspacePath, currentFilePath)) {
|
||||
return workspacePath
|
||||
@@ -130,7 +130,7 @@ export async function getWorkspacePath(defaultCwd = ""): Promise<string> {
|
||||
}
|
||||
|
||||
export async function isLocatedInWorkspace(pathToCheck: string = ""): Promise<boolean> {
|
||||
const workspacePaths = (await getHostBridgeProvider().workspaceClient.getWorkspacePaths({})).paths
|
||||
const workspacePaths = (await HostProvider.workspace.getWorkspacePaths({})).paths
|
||||
for (const workspacePath of workspacePaths) {
|
||||
const resolvedPath = path.resolve(workspacePath, pathToCheck)
|
||||
if (isLocatedInPath(workspacePath, resolvedPath)) {
|
||||
@@ -162,7 +162,7 @@ export function isLocatedInPath(dirPath: string, pathToCheck: string): boolean {
|
||||
}
|
||||
|
||||
export async function asRelativePath(filePath: string): Promise<string> {
|
||||
const workspacePaths = await getHostBridgeProvider().workspaceClient.getWorkspacePaths({})
|
||||
const workspacePaths = await HostProvider.workspace.getWorkspacePaths({})
|
||||
for (const workspacePath of workspacePaths.paths) {
|
||||
if (isLocatedInPath(workspacePath, filePath)) {
|
||||
return path.relative(workspacePath, filePath)
|
||||
|
||||
Reference in new issue
Block a user