From 3e1565da59cbe8ce14dbdd841de9e43e84ce39d7 Mon Sep 17 00:00:00 2001 From: Sarah Fortune Date: Mon, 23 Jun 2025 11:35:09 -0700 Subject: [PATCH] In the reflection output the standalone service should only show the Protobus services (#4339) * The standalone service should only show the Protobus services in the reflection output. The proto descriptor set is including all the proto services, allowlist the services in the cline and health packages. * Remove debug code * Fix variable name --- src/standalone/standalone.ts | 21 ++++++++++++++++++--- src/standalone/utils.ts | 4 ++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/standalone/standalone.ts b/src/standalone/standalone.ts index bf00e588..01559fd3 100644 --- a/src/standalone/standalone.ts +++ b/src/standalone/standalone.ts @@ -20,6 +20,10 @@ async function main() { hostProviders.initializeHostProviders(createWebview, new ExternalHostBridgeClientManager()) activate(extensionContext) const controller = new Controller(extensionContext, outputChannel, postMessage, uuidv4()) + startProtobusService(controller) +} + +function startProtobusService(controller: Controller) { const server = new grpc.Server() // Set up health check. @@ -29,12 +33,15 @@ async function main() { // Add all the handlers for the ProtoBus services to the server. addProtobusServices(server, controller, wrapHandler, wrapStreamingResponseHandler) - // Set up reflection. - const reflection = new ReflectionService(getPackageDefinition()) + // Create reflection service with protobus service names + const packageDefinition = getPackageDefinition() + const reflection = new ReflectionService(packageDefinition, { + services: getProtobusServiceNames(packageDefinition), + }) reflection.addToServer(server) // Start the server. - const host = "127.0.0.1:50051" + const host = process.env.PROTOBUS_ADDRESS || "127.0.0.1:50051" server.bindAsync(host, grpc.ServerCredentials.createInsecure(), (err) => { if (err) { log(`Error: Failed to bind to ${host}, port may be unavailable. ${err.message}`) @@ -45,6 +52,14 @@ async function main() { }) } +function getProtobusServiceNames(packageDefinition: { [x: string]: any }): string[] { + // Filter service names to only include cline services + const protobusServiceNames = Object.keys(packageDefinition).filter( + (name) => name.startsWith("cline.") || name.startsWith("grpc.health"), + ) + return protobusServiceNames +} + const createWebview = () => { return new ExternalWebviewProvider(extensionContext, outputChannel, WebviewProviderType.SIDEBAR) } diff --git a/src/standalone/utils.ts b/src/standalone/utils.ts index 83defef0..feab17aa 100644 --- a/src/standalone/utils.ts +++ b/src/standalone/utils.ts @@ -11,9 +11,9 @@ const log = (...args: unknown[]) => { function getPackageDefinition() { // Load service definitions. const descriptorSet = fs.readFileSync("proto/descriptor_set.pb") - const clineDef = protoLoader.loadFileDescriptorSetFromBuffer(descriptorSet) + const descriptorDefs = protoLoader.loadFileDescriptorSetFromBuffer(descriptorSet) const healthDef = protoLoader.loadSync(health.protoPath) - const packageDefinition = { ...clineDef, ...healthDef } + const packageDefinition = { ...descriptorDefs, ...healthDef } return packageDefinition }