Register commands and view to use centralized ExtensionRegistryInfo (#6153)

* Register commands and view to use centralized ExtensionRegistryInfo

Replace hardcoded package.json imports and string literals with a centralized
ExtensionRegistryInfo object that provides extension name and command
definitions. This improves maintainability and ensures consistency across
the codebase.

* update view id

* Fix environment variable serialization in vite config

Wrap all process.env values with JSON.stringify to ensure proper
string serialization and prevent undefined values from breaking
the build configuration.
This commit is contained in:
Bee authored and GitHub committed 2025-09-11 20:35:16 -07:00
1 parent 6b9dbccfd2
commit 1530cfe034
8 files changed
+75 -46

No files matched your search

+5 -2
View File
@@ -1,8 +1,8 @@
import type { EmptyRequest } from "@shared/proto/cline/common"
import { Empty } from "@shared/proto/cline/common"
import * as vscode from "vscode"
import { ExtensionRegistryInfo } from "@/registry"
import { telemetryService } from "@/services/telemetry"
import { name as pkgName } from "../../../../package.json"
import type { Controller } from "../index"
/**
@@ -13,7 +13,10 @@ import type { Controller } from "../index"
*/
export async function openWalkthrough(_controller: Controller, _request: EmptyRequest): Promise<Empty> {
try {
await vscode.commands.executeCommand("workbench.action.openWalkthrough", `saoudrizwan.${pkgName}#ClineWalkthrough`)
await vscode.commands.executeCommand(
"workbench.action.openWalkthrough",
`saoudrizwan.${ExtensionRegistryInfo.name}#ClineWalkthrough`,
)
telemetryService.captureButtonClick("webview_openWalkthrough")
return Empty.create({})
} catch (error) {
+6 -6
View File
@@ -35,7 +35,7 @@ import { focusChatInput, getContextForCommand } from "./hosts/vscode/commandUtil
import { VscodeDiffViewProvider } from "./hosts/vscode/VscodeDiffViewProvider"
import { VscodeWebviewProvider } from "./hosts/vscode/VscodeWebviewProvider"
import { GitCommitGenerator } from "./integrations/git/commit-message-generator"
import { getClineCommands } from "./registry"
import { ExtensionRegistryInfo } from "./registry"
import { AuthService } from "./services/auth/AuthService"
import { telemetryService } from "./services/telemetry"
import { SharedUriHandler } from "./services/uri/SharedUriHandler"
@@ -71,7 +71,7 @@ export async function activate(context: vscode.ExtensionContext) {
}),
)
const commands = getClineCommands(context.extension.packageJSON.name)
const { commands } = ExtensionRegistryInfo
context.subscriptions.push(
vscode.commands.registerCommand(commands.PlusButton, async (webview: any) => {
@@ -339,7 +339,7 @@ export async function activate(context: vscode.ExtensionContext) {
// Add to Cline (Always available)
const addAction = new vscode.CodeAction("Add to Cline", vscode.CodeActionKind.QuickFix)
addAction.command = {
command: "cline.addToChat",
command: commands.AddToChat,
title: "Add to Cline",
arguments: [expandedRange, context.diagnostics],
}
@@ -348,7 +348,7 @@ export async function activate(context: vscode.ExtensionContext) {
// Explain with Cline (Always available)
const explainAction = new vscode.CodeAction("Explain with Cline", vscode.CodeActionKind.RefactorExtract) // Using a refactor kind
explainAction.command = {
command: "cline.explainCode",
command: commands.ExplainCode,
title: "Explain with Cline",
arguments: [expandedRange],
}
@@ -357,7 +357,7 @@ export async function activate(context: vscode.ExtensionContext) {
// Improve with Cline (Always available)
const improveAction = new vscode.CodeAction("Improve with Cline", vscode.CodeActionKind.RefactorRewrite) // Using a refactor kind
improveAction.command = {
command: "cline.improveCode",
command: commands.ImproveCode,
title: "Improve with Cline",
arguments: [expandedRange],
}
@@ -368,7 +368,7 @@ export async function activate(context: vscode.ExtensionContext) {
const fixAction = new vscode.CodeAction("Fix with Cline", vscode.CodeActionKind.QuickFix)
fixAction.isPreferred = true
fixAction.command = {
command: "cline.fixWithCline",
command: commands.FixWithCline,
title: "Fix with Cline",
arguments: [expandedRange, context.diagnostics],
}
+3 -3
View File
@@ -4,10 +4,10 @@ import type { Uri } from "vscode"
import * as vscode from "vscode"
import { handleGrpcRequest, handleGrpcRequestCancel } from "@/core/controller/grpc-handler"
import { HostProvider } from "@/hosts/host-provider"
import { ExtensionRegistryInfo } from "@/registry"
import type { ExtensionMessage } from "@/shared/ExtensionMessage"
import { WebviewMessage } from "@/shared/WebviewMessage"
import type { WebviewProviderType } from "@/shared/webview/types"
import { name as pkgName } from "../../../package.json"
/*
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
@@ -17,8 +17,8 @@ https://github.com/KumarVariable/vscode-extension-sidebar-html/blob/master/src/c
export class VscodeWebviewProvider extends WebviewProvider implements vscode.WebviewViewProvider {
// Used in package.json as the view's id. This value cannot be changed due to how vscode caches
// views based on their id, and updating the id would break existing instances of the extension.
public static readonly SIDEBAR_ID = `${pkgName}.SidebarProvider`
public static readonly TAB_PANEL_ID = `${pkgName}.TabPanelProvider`
public static readonly SIDEBAR_ID = ExtensionRegistryInfo.views.Sidebar
public static readonly TAB_PANEL_ID = ExtensionRegistryInfo.views.TabPanel
private webview?: vscode.WebviewView | vscode.WebviewPanel
private disposables: vscode.Disposable[] = []
+2 -1
View File
@@ -1,5 +1,6 @@
import pWaitFor from "p-wait-for"
import * as vscode from "vscode"
import { ExtensionRegistryInfo } from "@/registry"
import { CommandContext } from "@/shared/proto/index.cline"
import { Controller } from "../../core/controller"
import { WebviewProvider } from "../../core/webview"
@@ -50,7 +51,7 @@ export async function getContextForCommand(
}
export async function focusChatInput(): Promise<WebviewProvider | undefined> {
await vscode.commands.executeCommand("cline.focusChatInput")
await vscode.commands.executeCommand(ExtensionRegistryInfo.commands.FocusChatInput)
// Wait for a webview instance to become available after focusing
await pWaitFor(() => !!WebviewProvider.getLastActiveInstance())
@@ -1,8 +1,8 @@
import * as vscode from "vscode"
import { ExtensionRegistryInfo } from "@/registry"
import { OpenClineSidebarPanelRequest, OpenClineSidebarPanelResponse } from "@/shared/proto/index.host"
import { name as pkgName } from "../../../../../package.json"
export async function openClineSidebarPanel(_: OpenClineSidebarPanelRequest): Promise<OpenClineSidebarPanelResponse> {
await vscode.commands.executeCommand(`${pkgName}.SidebarProvider.focus`)
await vscode.commands.executeCommand(`${ExtensionRegistryInfo.views.Sidebar}.focus`)
return {}
}
+47 -22
View File
@@ -1,25 +1,50 @@
import { name, publisher, version } from "../package.json"
const prefix = name === "claude-dev" ? "cline" : name
/**
* Generate and export command identifiers based on the extension name.
* This allows for flexibility if the extension is published with a different name.
* List of commands with the name of the extension they are registered under.
* These should match the command IDs defined in package.json.
* For Nightly build, the publish script has updated all the commands to use the extension name as prefix.
* In production, all commands are registered under "cline" for consistency.
*/
export function getClineCommands(extensionName: string) {
const prefix = extensionName === "claude-dev" ? "cline" : extensionName
return {
PlusButton: prefix + ".plusButtonClicked",
McpButton: prefix + ".mcpButtonClicked",
PopoutButton: prefix + ".popoutButtonClicked",
OpenInNewTab: prefix + ".openInNewTab",
SettingsButton: prefix + ".settingsButtonClicked",
HistoryButton: prefix + ".historyButtonClicked",
AccountButton: prefix + ".accountButtonClicked",
TerminalOutput: prefix + ".addTerminalOutputToChat",
AddToChat: prefix + ".addToChat",
FixWithCline: prefix + ".fixWithCline",
ExplainCode: prefix + ".explainCode",
ImproveCode: prefix + ".improveCode",
FocusChatInput: prefix + ".focusChatInput",
Walkthrough: prefix + ".openWalkthrough",
GenerateCommit: prefix + ".generateGitCommitMessage",
AbortCommit: prefix + ".abortGitCommitMessage",
}
const ClineCommands = {
PlusButton: prefix + ".plusButtonClicked",
McpButton: prefix + ".mcpButtonClicked",
PopoutButton: prefix + ".popoutButtonClicked",
OpenInNewTab: prefix + ".openInNewTab",
SettingsButton: prefix + ".settingsButtonClicked",
HistoryButton: prefix + ".historyButtonClicked",
AccountButton: prefix + ".accountButtonClicked",
TerminalOutput: prefix + ".addTerminalOutputToChat",
AddToChat: prefix + ".addToChat",
FixWithCline: prefix + ".fixWithCline",
ExplainCode: prefix + ".explainCode",
ImproveCode: prefix + ".improveCode",
FocusChatInput: prefix + ".focusChatInput",
Walkthrough: prefix + ".openWalkthrough",
GenerateCommit: prefix + ".generateGitCommitMessage",
AbortCommit: prefix + ".abortGitCommitMessage",
}
/**
* IDs for the views registered by the extension.
* These should match the name + view IDs defined in package.json.
*/
const ClineViewIds = {
Sidebar: name + ".SidebarProvider",
TabPanel: name + ".TabPanelProvider",
}
/**
* The registry info for the extension, including its ID, name, version, commands, and views
* registered for the current host.
*/
export const ExtensionRegistryInfo = {
id: publisher + "." + name,
name,
version,
publisher,
commands: ClineCommands,
views: ClineViewIds,
}
+3 -3
View File
@@ -9,8 +9,8 @@ import * as http from "http"
import * as path from "path"
import * as vscode from "vscode"
import { Controller } from "@/core/controller"
import { ExtensionRegistryInfo } from "@/registry"
import { getCwd } from "@/utils/path"
import { name as pkgName } from "../../../package.json"
import { calculateToolSuccessRate, getFileChanges, initializeGitRepository, validateWorkspacePath } from "./GitHelper"
/**
@@ -88,10 +88,10 @@ async function updateAutoApprovalSettings(_context: vscode.ExtensionContext, con
export function createTestServer(controller: Controller): http.Server {
// Try to show the Cline sidebar
Logger.log("[createTestServer] Opening Cline in sidebar...")
vscode.commands.executeCommand(`workbench.view.${pkgName}-ActivityBar`)
vscode.commands.executeCommand(`workbench.view.${ExtensionRegistryInfo.name}-ActivityBar`)
// Then ensure the webview is focused/loaded
vscode.commands.executeCommand(`${pkgName}.SidebarProvider.focus`)
vscode.commands.executeCommand(`${ExtensionRegistryInfo.views.Sidebar}.focus`)
// Update auto approval settings is available
updateAutoApprovalSettings(controller.context, controller)
+7 -7
View File
@@ -91,14 +91,14 @@ export default defineConfig({
__PLATFORM__: JSON.stringify(platform),
process: JSON.stringify({
env: {
NODE_ENV: process?.env?.IS_DEV ? "development" : "production",
CLINE_ENVIRONMENT: process?.env?.CLINE_ENVIRONMENT ?? "production",
IS_DEV: process?.env?.IS_DEV === "true",
IS_TEST: process?.env?.IS_TEST === "true",
CI: process?.env?.CI === "true",
NODE_ENV: JSON.stringify(process?.env?.IS_DEV ? "development" : "production"),
CLINE_ENVIRONMENT: JSON.stringify(process?.env?.CLINE_ENVIRONMENT ?? "production"),
IS_DEV: JSON.stringify(process?.env?.IS_DEV),
IS_TEST: JSON.stringify(process?.env?.IS_TEST),
CI: JSON.stringify(process?.env?.CI),
// PostHog environment variables
TELEMETRY_SERVICE_API_KEY: process?.env?.TELEMETRY_SERVICE_API_KEY,
ERROR_SERVICE_API_KEY: process?.env?.ERROR_SERVICE_API_KEY,
TELEMETRY_SERVICE_API_KEY: JSON.stringify(process?.env?.TELEMETRY_SERVICE_API_KEY),
ERROR_SERVICE_API_KEY: JSON.stringify(process?.env?.ERROR_SERVICE_API_KEY),
},
}),
},