Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/core/webview/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const ALLOWED_VSCODE_SETTINGS = new Set(["terminal.integrated.inheritEnv"])
import { MarketplaceManager, MarketplaceItemType } from "../../services/marketplace"
import { setPendingTodoList } from "../tools/updateTodoListTool"

// Cache for condense-related settings to prevent unnecessary re-evaluation
const condenseSettingsCache = new Map<string, any>()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condenseSettingsCache Map grows indefinitely without cleanup. Should we clear it when tasks are disposed or the provider is reset? This could become a memory leak in long-running sessions.


export const webviewMessageHandler = async (
provider: ClineProvider,
message: WebviewMessage,
Expand All @@ -70,6 +73,21 @@ export const webviewMessageHandler = async (
const updateGlobalState = async <K extends keyof GlobalState>(key: K, value: GlobalState[K]) =>
await provider.contextProxy.setValue(key, value)

// Helper function to check if a condense-related setting has actually changed
const hasCondenseSettingChanged = (key: string, value: any): boolean => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? The hasCondenseSettingChanged helper function lacks test coverage. Consider adding tests to ensure the caching logic works correctly, especially for edge cases like undefined values.

const cachedValue = condenseSettingsCache.get(key)
if (cachedValue === undefined) {
// First time setting this value
condenseSettingsCache.set(key, value)
return true
}
const changed = JSON.stringify(cachedValue) !== JSON.stringify(value)
if (changed) {
condenseSettingsCache.set(key, value)
}
return changed
}

const getCurrentCwd = () => {
return provider.getCurrentTask()?.cwd || provider.cwd
}
Expand Down Expand Up @@ -581,12 +599,18 @@ export const webviewMessageHandler = async (
provider.getCurrentTask()?.handleWebviewAskResponse(message.askResponse!, message.text, message.images)
break
case "autoCondenseContext":
await updateGlobalState("autoCondenseContext", message.bool)
await provider.postStateToWebview()
// Only update if the value has actually changed to prevent unnecessary context re-evaluation
if (hasCondenseSettingChanged("autoCondenseContext", message.bool)) {
await updateGlobalState("autoCondenseContext", message.bool)
await provider.postStateToWebview()
}
break
case "autoCondenseContextPercent":
await updateGlobalState("autoCondenseContextPercent", message.value)
await provider.postStateToWebview()
// Only update if the value has actually changed to prevent unnecessary context re-evaluation
if (hasCondenseSettingChanged("autoCondenseContextPercent", message.value)) {
await updateGlobalState("autoCondenseContextPercent", message.value)
await provider.postStateToWebview()
}
break
case "terminalOperation":
if (message.terminalOperation) {
Expand Down Expand Up @@ -1650,8 +1674,11 @@ export const webviewMessageHandler = async (
await provider.postStateToWebview()
break
case "profileThresholds":
await updateGlobalState("profileThresholds", message.values)
await provider.postStateToWebview()
// Only update if the value has actually changed to prevent unnecessary context re-evaluation
if (hasCondenseSettingChanged("profileThresholds", message.values)) {
await updateGlobalState("profileThresholds", message.values)
await provider.postStateToWebview()
}
break
case "autoApprovalEnabled":
await updateGlobalState("autoApprovalEnabled", message.bool ?? false)
Expand Down
Loading
Loading