From 8683980c90e8955fd5e755d2ab1df358dbb406d7 Mon Sep 17 00:00:00 2001 From: Sarah Fortune Date: Tue, 15 Jul 2025 16:12:48 -0700 Subject: [PATCH] Move the vscode hostbridge handlers into their own package (#4945) * Move the generated files for the host bridge into the 'src/generated' directory Move the generated index.ts and methods.ts files for the host bridge into the 'src/generated' directory I'm doing this because when all the generated files are one in location its a) easier to see from the import statement that the code is generated, b) it's easier to change the package(s) of the generated files, and c) easier to reset/clean the build state. * Update import path * Move the hostbridge handlers in the a hostbridge packge. Move the hostbridge handlers out of the top level of the vscode package into their own subpackage. I have to move all the vscode specific code into the `hosts/vscode` package, and I want the hostbridge handlers to be grouped together, not mixed in with things like the VscodeDiffViewProvider, VscodeWebviewProvider etc. --- scripts/build-proto.mjs | 14 ++++++++------ .../context-tracking/FileContextTracker.test.ts | 2 +- src/extension.ts | 2 +- ...-grpc-handler.ts => hostbridge-grpc-handler.ts} | 0 ...-grpc-service.ts => hostbridge-grpc-service.ts} | 2 +- .../client/host-grpc-client-base.ts | 2 +- .../{ => hostbridge}/client/host-grpc-client.ts | 2 +- src/hosts/vscode/{ => hostbridge}/diff/openDiff.ts | 0 .../{ => hostbridge}/env/clipboardReadText.ts | 0 .../{ => hostbridge}/env/clipboardWriteText.ts | 0 .../vscode/{ => hostbridge}/env/openExternal.ts | 0 .../{ => hostbridge}/watch/subscribeToFile.ts | 4 ++-- .../vscode/{ => hostbridge}/window/showMessage.ts | 0 .../{ => hostbridge}/window/showOpenDialogue.ts | 0 .../{ => hostbridge}/window/showTextDocument.ts | 0 .../workspace/getWorkspacePaths.ts | 0 16 files changed, 15 insertions(+), 13 deletions(-) rename src/hosts/vscode/{host-grpc-handler.ts => hostbridge-grpc-handler.ts} (100%) rename src/hosts/vscode/{host-grpc-service.ts => hostbridge-grpc-service.ts} (98%) rename src/hosts/vscode/{ => hostbridge}/client/host-grpc-client-base.ts (98%) rename src/hosts/vscode/{ => hostbridge}/client/host-grpc-client.ts (85%) rename src/hosts/vscode/{ => hostbridge}/diff/openDiff.ts (100%) rename src/hosts/vscode/{ => hostbridge}/env/clipboardReadText.ts (100%) rename src/hosts/vscode/{ => hostbridge}/env/clipboardWriteText.ts (100%) rename src/hosts/vscode/{ => hostbridge}/env/openExternal.ts (100%) rename src/hosts/vscode/{ => hostbridge}/watch/subscribeToFile.ts (97%) rename src/hosts/vscode/{ => hostbridge}/window/showMessage.ts (100%) rename src/hosts/vscode/{ => hostbridge}/window/showOpenDialogue.ts (100%) rename src/hosts/vscode/{ => hostbridge}/window/showTextDocument.ts (100%) rename src/hosts/vscode/{ => hostbridge}/workspace/getWorkspacePaths.ts (100%) diff --git a/scripts/build-proto.mjs b/scripts/build-proto.mjs index 8d13827bcb..a072beb6fd 100755 --- a/scripts/build-proto.mjs +++ b/scripts/build-proto.mjs @@ -14,7 +14,7 @@ import { serviceNameMap, hostServiceNameMap } from "./build-proto-config.mjs" const require = createRequire(import.meta.url) const PROTOC = path.join(require.resolve("grpc-tools"), "../bin/protoc") -const SCRIPT_NAME = fileURLToPath(import.meta.url) +const SCRIPT_NAME = path.relative(process.cwd(), fileURLToPath(import.meta.url)) const PROTO_DIR = path.resolve("proto") const TS_OUT_DIR = path.resolve("src/shared/proto") @@ -426,7 +426,9 @@ service ${serviceClassName} { async function generateHostBridgeMethodRegistrations() { log_verbose(chalk.cyan("Generating host method registration files...")) // Host service directories derived from imported hostServiceNameMap - const hostServiceDirs = Object.keys(hostServiceNameMap).map((serviceKey) => path.join("src/hosts/vscode", serviceKey)) + const hostServiceDirs = Object.keys(hostServiceNameMap).map((serviceKey) => + path.join("src/hosts/vscode/hostbridge", serviceKey), + ) // Parse proto files for streaming methods const hostProtoFiles = await globby("*.proto", { cwd: path.join(PROTO_DIR, "host") }) @@ -456,7 +458,7 @@ import { registerMethod } from "./index"\n` // Import implementations directly for (const file of implementationFiles) { const baseName = path.basename(file, ".ts") - methodsContent += `import { ${baseName} } from "@hosts/vscode/${serviceName}/${baseName}"\n` + methodsContent += `import { ${baseName} } from "@hosts/vscode/hostbridge/${serviceName}/${baseName}"\n` } // Add streaming methods information @@ -499,8 +501,8 @@ export function registerAllMethods(): void { const indexContent = `// AUTO-GENERATED FILE - DO NOT MODIFY DIRECTLY // Generated by ${SCRIPT_NAME} -import { createServiceRegistry, ServiceMethodHandler, StreamingMethodHandler } from "@hosts/vscode/host-grpc-service" -import { StreamingResponseHandler } from "@hosts/vscode/host-grpc-handler" +import { createServiceRegistry, ServiceMethodHandler, StreamingMethodHandler } from "@hosts/vscode/hostbridge-grpc-service" +import { StreamingResponseHandler } from "@hosts/vscode/hostbridge-grpc-handler" import { registerAllMethods } from "./methods" // Create ${serviceName} service registry @@ -553,7 +555,7 @@ async function generateHostBridgeServiceConfig() { const content = `// AUTO-GENERATED FILE - DO NOT MODIFY DIRECTLY // Generated by ${SCRIPT_NAME} -import { StreamingResponseHandler } from "@/hosts/vscode/host-grpc-handler" +import { StreamingResponseHandler } from "@/hosts/vscode/hostbridge-grpc-handler" ${serviceImports.join("\n")} /** diff --git a/src/core/context/context-tracking/FileContextTracker.test.ts b/src/core/context/context-tracking/FileContextTracker.test.ts index fd54484772..d12b46eb57 100644 --- a/src/core/context/context-tracking/FileContextTracker.test.ts +++ b/src/core/context/context-tracking/FileContextTracker.test.ts @@ -8,7 +8,7 @@ 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 { vscodeHostBridgeClient } from "@/hosts/vscode/client/host-grpc-client" +import { vscodeHostBridgeClient } from "@/hosts/vscode/hostbridge/client/host-grpc-client" describe("FileContextTracker", () => { let sandbox: sinon.SinonSandbox diff --git a/src/extension.ts b/src/extension.ts index 7a29f45f8e..37a5940652 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -32,7 +32,7 @@ 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/client/host-grpc-client" +import { vscodeHostBridgeClient } from "@/hosts/vscode/hostbridge/client/host-grpc-client" import { VscodeWebviewProvider } from "./core/webview/VscodeWebviewProvider" import { ExtensionContext } from "vscode" import { AuthService } from "./services/auth/AuthService" diff --git a/src/hosts/vscode/host-grpc-handler.ts b/src/hosts/vscode/hostbridge-grpc-handler.ts similarity index 100% rename from src/hosts/vscode/host-grpc-handler.ts rename to src/hosts/vscode/hostbridge-grpc-handler.ts diff --git a/src/hosts/vscode/host-grpc-service.ts b/src/hosts/vscode/hostbridge-grpc-service.ts similarity index 98% rename from src/hosts/vscode/host-grpc-service.ts rename to src/hosts/vscode/hostbridge-grpc-service.ts index f4733a4fa7..19ccd1ed38 100644 --- a/src/hosts/vscode/host-grpc-service.ts +++ b/src/hosts/vscode/hostbridge-grpc-service.ts @@ -1,4 +1,4 @@ -import { StreamingResponseHandler } from "./host-grpc-handler" +import { StreamingResponseHandler } from "./hostbridge-grpc-handler" /** * Generic type for service method handlers diff --git a/src/hosts/vscode/client/host-grpc-client-base.ts b/src/hosts/vscode/hostbridge/client/host-grpc-client-base.ts similarity index 98% rename from src/hosts/vscode/client/host-grpc-client-base.ts rename to src/hosts/vscode/hostbridge/client/host-grpc-client-base.ts index fcf993e3d2..0ca7fbaa75 100644 --- a/src/hosts/vscode/client/host-grpc-client-base.ts +++ b/src/hosts/vscode/hostbridge/client/host-grpc-client-base.ts @@ -1,5 +1,5 @@ import { v4 as uuidv4 } from "uuid" -import { GrpcHandler } from "../host-grpc-handler" +import { GrpcHandler } from "@/hosts/vscode/hostbridge-grpc-handler" import { StreamingCallbacks } from "@/hosts/host-provider-types" // Generic type for any protobuf service definition diff --git a/src/hosts/vscode/client/host-grpc-client.ts b/src/hosts/vscode/hostbridge/client/host-grpc-client.ts similarity index 85% rename from src/hosts/vscode/client/host-grpc-client.ts rename to src/hosts/vscode/hostbridge/client/host-grpc-client.ts index eb7baa62e7..f78bf58cae 100644 --- a/src/hosts/vscode/client/host-grpc-client.ts +++ b/src/hosts/vscode/hostbridge/client/host-grpc-client.ts @@ -1,4 +1,4 @@ -import { createGrpcClient } from "@hosts/vscode/client/host-grpc-client-base" +import { createGrpcClient } from "@hosts/vscode/hostbridge/client/host-grpc-client-base" import { HostBridgeClientProvider } from "@/hosts/host-provider-types" import * as host from "@shared/proto/index.host" diff --git a/src/hosts/vscode/diff/openDiff.ts b/src/hosts/vscode/hostbridge/diff/openDiff.ts similarity index 100% rename from src/hosts/vscode/diff/openDiff.ts rename to src/hosts/vscode/hostbridge/diff/openDiff.ts diff --git a/src/hosts/vscode/env/clipboardReadText.ts b/src/hosts/vscode/hostbridge/env/clipboardReadText.ts similarity index 100% rename from src/hosts/vscode/env/clipboardReadText.ts rename to src/hosts/vscode/hostbridge/env/clipboardReadText.ts diff --git a/src/hosts/vscode/env/clipboardWriteText.ts b/src/hosts/vscode/hostbridge/env/clipboardWriteText.ts similarity index 100% rename from src/hosts/vscode/env/clipboardWriteText.ts rename to src/hosts/vscode/hostbridge/env/clipboardWriteText.ts diff --git a/src/hosts/vscode/env/openExternal.ts b/src/hosts/vscode/hostbridge/env/openExternal.ts similarity index 100% rename from src/hosts/vscode/env/openExternal.ts rename to src/hosts/vscode/hostbridge/env/openExternal.ts diff --git a/src/hosts/vscode/watch/subscribeToFile.ts b/src/hosts/vscode/hostbridge/watch/subscribeToFile.ts similarity index 97% rename from src/hosts/vscode/watch/subscribeToFile.ts rename to src/hosts/vscode/hostbridge/watch/subscribeToFile.ts index 26549daa56..436b18b4c9 100644 --- a/src/hosts/vscode/watch/subscribeToFile.ts +++ b/src/hosts/vscode/hostbridge/watch/subscribeToFile.ts @@ -1,7 +1,7 @@ import * as fs from "fs/promises" import * as fsSync from "fs" -import { SubscribeToFileRequest, FileChangeEvent, FileChangeEvent_ChangeType } from "@shared/proto/host/watch" -import { StreamingResponseHandler, getRequestRegistry } from "../host-grpc-handler" +import { SubscribeToFileRequest, FileChangeEvent_ChangeType } from "@shared/proto/host/watch" +import { StreamingResponseHandler, getRequestRegistry } from "@/hosts/vscode/hostbridge-grpc-handler" // Debounce configuration const DEBOUNCE_DELAY = 100 // ms diff --git a/src/hosts/vscode/window/showMessage.ts b/src/hosts/vscode/hostbridge/window/showMessage.ts similarity index 100% rename from src/hosts/vscode/window/showMessage.ts rename to src/hosts/vscode/hostbridge/window/showMessage.ts diff --git a/src/hosts/vscode/window/showOpenDialogue.ts b/src/hosts/vscode/hostbridge/window/showOpenDialogue.ts similarity index 100% rename from src/hosts/vscode/window/showOpenDialogue.ts rename to src/hosts/vscode/hostbridge/window/showOpenDialogue.ts diff --git a/src/hosts/vscode/window/showTextDocument.ts b/src/hosts/vscode/hostbridge/window/showTextDocument.ts similarity index 100% rename from src/hosts/vscode/window/showTextDocument.ts rename to src/hosts/vscode/hostbridge/window/showTextDocument.ts diff --git a/src/hosts/vscode/workspace/getWorkspacePaths.ts b/src/hosts/vscode/hostbridge/workspace/getWorkspacePaths.ts similarity index 100% rename from src/hosts/vscode/workspace/getWorkspacePaths.ts rename to src/hosts/vscode/hostbridge/workspace/getWorkspacePaths.ts