Skip to content

Commit

Permalink
add onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
hitesh-1997 committed Jan 6, 2025
1 parent 5eebf42 commit ab63f60
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 45 deletions.
2 changes: 1 addition & 1 deletion lib/shared/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ interface RawClientConfiguration {
experimentalSupercompletions: boolean
experimentalAutoeditsRendererTesting: boolean
experimentalAutoeditsConfigOverride: AutoEditsModelConfig | undefined
experimentalAutoeditsEnabled: boolean | undefined
experimentalAutoeditsEnabled: boolean
experimentalCommitMessage: boolean
experimentalNoodle: boolean
experimentalMinionAnthropicKey: string | undefined
Expand Down
109 changes: 65 additions & 44 deletions vscode/src/autoedits/autoedit-onboarding.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,89 @@
import {
FeatureFlag,
currentAuthStatus,
currentResolvedConfig,
currentUserProductSubscription,
featureFlagProvider,
isDotComAuthed,
isS2,
storeLastValue,
} from '@sourcegraph/cody-shared'
import * as vscode from 'vscode'
import { isRunningInsideAgent } from './../jsonrpc/isRunningInsideAgent'
import { localStorage } from '../services/LocalStorageProvider'
import { isUserEligibleForAutoeditsFeature } from './create-autoedits-provider'

export async function showAutoeditOnboardingIfEligible(): Promise<void> {
// Determine if we should show the onboarding popup
if (!shouldShowAutoeditsOnboardingPopup()) {
return
}
export class AutoeditsOnboarding implements vscode.Disposable {
private readonly MAX_AUTO_EDITS_ONBOARDING_NOTIFICATIONS = 3

const selection = await vscode.window.showInformationMessage(
'✨ Try Cody Autoedits - experimental feature which suggest smarter code edits as you type.',
'Enable Autoedits'
private featureFlagAutoeditsExperimental = storeLastValue(
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.CodyAutoeditExperimentEnabledFeatureFlag)
)

if (selection === 'Enable Autoedits') {
// Enable the setting programmatically
await vscode.workspace
.getConfiguration()
.update('cody.experimental.autoedits.enabled', true, vscode.ConfigurationTarget.Global)
private async showAutoeditOnboardingIfEligible(): Promise<void> {

Check failure on line 20 in vscode/src/autoedits/autoedit-onboarding.ts

View workflow job for this annotation

GitHub Actions / build

'showAutoeditOnboardingIfEligible' is declared but its value is never read.

Check failure on line 20 in vscode/src/autoedits/autoedit-onboarding.ts

View workflow job for this annotation

GitHub Actions / test-unit (ubuntu, 20)

'showAutoeditOnboardingIfEligible' is declared but its value is never read.

Check failure on line 20 in vscode/src/autoedits/autoedit-onboarding.ts

View workflow job for this annotation

GitHub Actions / test-unit (ubuntu, 18)

'showAutoeditOnboardingIfEligible' is declared but its value is never read.

Check failure on line 20 in vscode/src/autoedits/autoedit-onboarding.ts

View workflow job for this annotation

GitHub Actions / JetBrains tests

'showAutoeditOnboardingIfEligible' is declared but its value is never read.

Check failure on line 20 in vscode/src/autoedits/autoedit-onboarding.ts

View workflow job for this annotation

GitHub Actions / test-unit (windows, 20)

'showAutoeditOnboardingIfEligible' is declared but its value is never read.
const shouldShowOnboardingPopup = await this.shouldShowAutoeditsOnboardingPopup()
if (shouldShowOnboardingPopup) {
await this.showAutoeditsOnboardingPopup()
await this.incrementAutoEditsOnboardingNotificationCount()
}
}

// Open VS Code settings UI and focus on the Cody Autoedits setting
await vscode.commands.executeCommand(
'workbench.action.openSettings',
'cody.experimental.autoedits'
private async showAutoeditsOnboardingPopup(): Promise<void> {
const selection = await vscode.window.showInformationMessage(
'✨ Try Cody auto-edits. Experimental feature which suggests advanced context-aware code edits as you navigate the codebase',
'Enable auto-edits'
)

if (selection === 'Enable auto-edits') {
// Enable the setting programmatically
await vscode.workspace
.getConfiguration()
.update('cody.suggestions.mode', true, vscode.ConfigurationTarget.Global)

// Open VS Code settings UI and focus on the Cody Autoedits setting
await vscode.commands.executeCommand(
'workbench.action.openSettings',
'cody.suggestions.mode'
)
}
}

private async shouldShowAutoeditsOnboardingPopup(): Promise<boolean> {
const isUserEligible = await this.isUserEligibleForAutoeditsOnboarding()
const isAutoeditsDisabled = await this.isAutoeditsDisabled()
const isUnderNotificationLimit =
(await this.getAutoEditsOnboardingNotificationCount()) <
this.MAX_AUTO_EDITS_ONBOARDING_NOTIFICATIONS
return isUserEligible && isAutoeditsDisabled && isUnderNotificationLimit
}
}

function shouldShowAutoeditsOnboardingPopup(): boolean {
const isAutoeditsConfigEnabled = vscode.workspace
.getConfiguration()
.get<boolean>('cody.experimental.autoedits.enabled', false)
private async incrementAutoEditsOnboardingNotificationCount(): Promise<void> {
const count = await this.getAutoEditsOnboardingNotificationCount()
await localStorage.setAutoEditsOnboardingNotificationCount(count + 1)
}

// Do not show the onboarding popup if the feature is already enabled or any other editor than vscode.
if (isRunningInsideAgent() || isAutoeditsConfigEnabled) {
return false
private async isAutoeditsDisabled(): Promise<boolean> {
const config = await currentResolvedConfig()
return !config.configuration.experimentalAutoeditsEnabled
}

if (isDotComAuthed()) {
return shouldShowAutoeditsOnboardingPopupForDotComUser()
private async getAutoEditsOnboardingNotificationCount(): Promise<number> {
return localStorage.getAutoEditsOnboardingNotificationCount()
}

const authStatus = currentAuthStatus()
if (isS2(authStatus)) {
// All the S2 users should see the onboarding popup for dogfooding
return true
private async isUserEligibleForAutoeditsOnboarding(): Promise<boolean> {
const authStatus = currentAuthStatus()
const productSubsubscription = await currentUserProductSubscription()
const autoeditsFeatureFlag = this.isAutoeditsFeatureFlagEnabled()
return isUserEligibleForAutoeditsFeature(
autoeditsFeatureFlag,
authStatus,
productSubsubscription
)
}

// Decide later if we want to show the pop-up for the enterprise
return false
}
private isAutoeditsFeatureFlagEnabled(): boolean {
return !!this.featureFlagAutoeditsExperimental.value.last
}

function shouldShowAutoeditsOnboardingPopupForDotComUser(): boolean {
const isUserEligibleForFeature = featureFlagProvider.evaluatedFeatureFlag(
FeatureFlag.CodyAutoeditExperimentEnabledFeatureFlag
)
if (!isUserEligibleForFeature) {
return false
dispose(): void {
this.featureFlagAutoeditsExperimental.subscription.unsubscribe()
}
return true
}
11 changes: 11 additions & 0 deletions vscode/src/services/LocalStorageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class LocalStorage implements LocalStorageForModelPreferences {
public readonly LAST_USED_ENDPOINT = 'SOURCEGRAPH_CODY_ENDPOINT'
private readonly MODEL_PREFERENCES_KEY = 'cody-model-preferences'
private readonly CODY_CHAT_MEMORY = 'cody-chat-memory'
private readonly AUTO_EDITS_ONBOARDING_NOTIFICATION_COUNT =
'cody-auto-edits-onboarding-notification-count'

public readonly keys = {
// LLM waitlist for the 09/12/2024 openAI o1 models
waitlist_o1: 'CODY_WAITLIST_LLM_09122024',
Expand Down Expand Up @@ -238,6 +241,14 @@ class LocalStorage implements LocalStorageForModelPreferences {
}
}

public async getAutoEditsOnboardingNotificationCount(): Promise<number> {
return this.get(this.AUTO_EDITS_ONBOARDING_NOTIFICATION_COUNT) ?? 0
}

public async setAutoEditsOnboardingNotificationCount(count: number): Promise<void> {
await this.set(this.AUTO_EDITS_ONBOARDING_NOTIFICATION_COUNT, count)
}

public async setGitHubRepoAccessibility(data: GitHubDotComRepoMetaData[]): Promise<void> {
await this.set(this.GIT_REPO_ACCESSIBILITY_KEY, data)
}
Expand Down

0 comments on commit ab63f60

Please sign in to comment.