|
@@ -53,6 +53,8 @@ import { Cline, ClineOptions } from "../Cline"
|
|
|
import { openMention } from "../mentions"
|
|
import { openMention } from "../mentions"
|
|
|
import { getNonce } from "./getNonce"
|
|
import { getNonce } from "./getNonce"
|
|
|
import { getUri } from "./getUri"
|
|
import { getUri } from "./getUri"
|
|
|
|
|
+import { telemetryService } from "../../services/telemetry/TelemetryService"
|
|
|
|
|
+import { TelemetrySetting } from "../../shared/TelemetrySetting"
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
|
|
* https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
|
|
@@ -82,6 +84,10 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
this.outputChannel.appendLine("ClineProvider instantiated")
|
|
this.outputChannel.appendLine("ClineProvider instantiated")
|
|
|
this.contextProxy = new ContextProxy(context)
|
|
this.contextProxy = new ContextProxy(context)
|
|
|
ClineProvider.activeInstances.add(this)
|
|
ClineProvider.activeInstances.add(this)
|
|
|
|
|
+
|
|
|
|
|
+ // Register this provider with the telemetry service to enable it to add properties like mode and provider
|
|
|
|
|
+ telemetryService.setProvider(this)
|
|
|
|
|
+
|
|
|
this.workspaceTracker = new WorkspaceTracker(this)
|
|
this.workspaceTracker = new WorkspaceTracker(this)
|
|
|
this.configManager = new ConfigManager(this.context)
|
|
this.configManager = new ConfigManager(this.context)
|
|
|
this.customModesManager = new CustomModesManager(this.context, async () => {
|
|
this.customModesManager = new CustomModesManager(this.context, async () => {
|
|
@@ -620,8 +626,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
`font-src ${webview.cspSource}`,
|
|
`font-src ${webview.cspSource}`,
|
|
|
`style-src ${webview.cspSource} 'unsafe-inline' https://* http://${localServerUrl} http://0.0.0.0:${localPort}`,
|
|
`style-src ${webview.cspSource} 'unsafe-inline' https://* http://${localServerUrl} http://0.0.0.0:${localPort}`,
|
|
|
`img-src ${webview.cspSource} data:`,
|
|
`img-src ${webview.cspSource} data:`,
|
|
|
- `script-src 'unsafe-eval' https://* http://${localServerUrl} http://0.0.0.0:${localPort} 'nonce-${nonce}'`,
|
|
|
|
|
- `connect-src https://* ws://${localServerUrl} ws://0.0.0.0:${localPort} http://${localServerUrl} http://0.0.0.0:${localPort}`,
|
|
|
|
|
|
|
+ `script-src 'unsafe-eval' https://* https://*.posthog.com http://${localServerUrl} http://0.0.0.0:${localPort} 'nonce-${nonce}'`,
|
|
|
|
|
+ `connect-src https://* https://*.posthog.com ws://${localServerUrl} ws://0.0.0.0:${localPort} http://${localServerUrl} http://0.0.0.0:${localPort}`,
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
return /*html*/ `
|
|
return /*html*/ `
|
|
@@ -710,7 +716,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
<meta charset="utf-8">
|
|
<meta charset="utf-8">
|
|
|
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
|
|
|
<meta name="theme-color" content="#000000">
|
|
<meta name="theme-color" content="#000000">
|
|
|
- <meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource}; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} data:; script-src 'nonce-${nonce}';">
|
|
|
|
|
|
|
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource}; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} data:; script-src 'nonce-${nonce}' https://us-assets.i.posthog.com; connect-src https://us.i.posthog.com https://us-assets.i.posthog.com;">
|
|
|
<link rel="stylesheet" type="text/css" href="${stylesUri}">
|
|
<link rel="stylesheet" type="text/css" href="${stylesUri}">
|
|
|
<link href="${codiconsUri}" rel="stylesheet" />
|
|
<link href="${codiconsUri}" rel="stylesheet" />
|
|
|
<title>Roo Code</title>
|
|
<title>Roo Code</title>
|
|
@@ -925,6 +931,13 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
),
|
|
),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ // If user already opted in to telemetry, enable telemetry service
|
|
|
|
|
+ this.getStateToPostToWebview().then((state) => {
|
|
|
|
|
+ const { telemetrySetting } = state
|
|
|
|
|
+ const isOptedIn = telemetrySetting === "enabled"
|
|
|
|
|
+ telemetryService.updateTelemetryState(isOptedIn)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
this.isViewLaunched = true
|
|
this.isViewLaunched = true
|
|
|
break
|
|
break
|
|
|
case "newTask":
|
|
case "newTask":
|
|
@@ -1776,6 +1789,15 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
break
|
|
break
|
|
|
|
|
+
|
|
|
|
|
+ case "telemetrySetting": {
|
|
|
|
|
+ const telemetrySetting = message.text as TelemetrySetting
|
|
|
|
|
+ await this.updateGlobalState("telemetrySetting", telemetrySetting)
|
|
|
|
|
+ const isOptedIn = telemetrySetting === "enabled"
|
|
|
|
|
+ telemetryService.updateTelemetryState(isOptedIn)
|
|
|
|
|
+ await this.postStateToWebview()
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
null,
|
|
null,
|
|
@@ -1835,6 +1857,12 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
* @param newMode The mode to switch to
|
|
* @param newMode The mode to switch to
|
|
|
*/
|
|
*/
|
|
|
public async handleModeSwitch(newMode: Mode) {
|
|
public async handleModeSwitch(newMode: Mode) {
|
|
|
|
|
+ // Capture mode switch telemetry event
|
|
|
|
|
+ const currentTaskId = this.getCurrentCline()?.taskId
|
|
|
|
|
+ if (currentTaskId) {
|
|
|
|
|
+ telemetryService.captureModeSwitch(currentTaskId, newMode)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
await this.updateGlobalState("mode", newMode)
|
|
await this.updateGlobalState("mode", newMode)
|
|
|
|
|
|
|
|
// Load the saved API config for the new mode if it exists
|
|
// Load the saved API config for the new mode if it exists
|
|
@@ -2172,7 +2200,10 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
experiments,
|
|
experiments,
|
|
|
maxOpenTabsContext,
|
|
maxOpenTabsContext,
|
|
|
browserToolEnabled,
|
|
browserToolEnabled,
|
|
|
|
|
+ telemetrySetting,
|
|
|
} = await this.getState()
|
|
} = await this.getState()
|
|
|
|
|
+ const telemetryKey = process.env.POSTHOG_API_KEY
|
|
|
|
|
+ const machineId = vscode.env.machineId
|
|
|
|
|
|
|
|
const allowedCommands = vscode.workspace.getConfiguration("roo-cline").get<string[]>("allowedCommands") || []
|
|
const allowedCommands = vscode.workspace.getConfiguration("roo-cline").get<string[]>("allowedCommands") || []
|
|
|
|
|
|
|
@@ -2200,7 +2231,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
diffEnabled: diffEnabled ?? true,
|
|
diffEnabled: diffEnabled ?? true,
|
|
|
enableCheckpoints: enableCheckpoints ?? true,
|
|
enableCheckpoints: enableCheckpoints ?? true,
|
|
|
checkpointStorage: checkpointStorage ?? "task",
|
|
checkpointStorage: checkpointStorage ?? "task",
|
|
|
- shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId,
|
|
|
|
|
|
|
+ shouldShowAnnouncement:
|
|
|
|
|
+ telemetrySetting !== "unset" && lastShownAnnouncementId !== this.latestAnnouncementId,
|
|
|
allowedCommands,
|
|
allowedCommands,
|
|
|
soundVolume: soundVolume ?? 0.5,
|
|
soundVolume: soundVolume ?? 0.5,
|
|
|
browserViewportSize: browserViewportSize ?? "900x600",
|
|
browserViewportSize: browserViewportSize ?? "900x600",
|
|
@@ -2225,8 +2257,11 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
experiments: experiments ?? experimentDefault,
|
|
experiments: experiments ?? experimentDefault,
|
|
|
mcpServers: this.mcpHub?.getAllServers() ?? [],
|
|
mcpServers: this.mcpHub?.getAllServers() ?? [],
|
|
|
maxOpenTabsContext: maxOpenTabsContext ?? 20,
|
|
maxOpenTabsContext: maxOpenTabsContext ?? 20,
|
|
|
- cwd: cwd,
|
|
|
|
|
|
|
+ cwd,
|
|
|
browserToolEnabled: browserToolEnabled ?? true,
|
|
browserToolEnabled: browserToolEnabled ?? true,
|
|
|
|
|
+ telemetrySetting,
|
|
|
|
|
+ telemetryKey,
|
|
|
|
|
+ machineId,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2405,6 +2440,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
maxOpenTabsContext: stateValues.maxOpenTabsContext ?? 20,
|
|
maxOpenTabsContext: stateValues.maxOpenTabsContext ?? 20,
|
|
|
openRouterUseMiddleOutTransform: stateValues.openRouterUseMiddleOutTransform ?? true,
|
|
openRouterUseMiddleOutTransform: stateValues.openRouterUseMiddleOutTransform ?? true,
|
|
|
browserToolEnabled: stateValues.browserToolEnabled ?? true,
|
|
browserToolEnabled: stateValues.browserToolEnabled ?? true,
|
|
|
|
|
+ telemetrySetting: stateValues.telemetrySetting || "unset",
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2483,4 +2519,27 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|
|
public getMcpHub(): McpHub | undefined {
|
|
public getMcpHub(): McpHub | undefined {
|
|
|
return this.mcpHub
|
|
return this.mcpHub
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Returns properties to be included in every telemetry event
|
|
|
|
|
+ * This method is called by the telemetry service to get context information
|
|
|
|
|
+ * like the current mode, API provider, etc.
|
|
|
|
|
+ */
|
|
|
|
|
+ public async getTelemetryProperties(): Promise<Record<string, any>> {
|
|
|
|
|
+ const { mode, apiConfiguration } = await this.getState()
|
|
|
|
|
+
|
|
|
|
|
+ const properties: Record<string, any> = {}
|
|
|
|
|
+
|
|
|
|
|
+ // Add current mode
|
|
|
|
|
+ if (mode) {
|
|
|
|
|
+ properties.mode = mode
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Add API provider
|
|
|
|
|
+ if (apiConfiguration?.apiProvider) {
|
|
|
|
|
+ properties.apiProvider = apiConfiguration.apiProvider
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return properties
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|