import { UpdateSettingsRequest } from "@shared/proto/cline/state"
import { memo, type ReactNode, useCallback } from "react"
import { useTranslation } from "react-i18next"
import { Label } from "@/components/ui/label"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Switch } from "@/components/ui/switch"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
import { useExtensionState } from "@/context/ExtensionStateContext"
import Section from "../Section"
import SettingsSlider from "../SettingsSlider"
import { updateSetting } from "../utils/settingsHandlers"
// Reusable checkbox component for feature settings
interface FeatureCheckboxProps {
checked: boolean | undefined
onChange: (checked: boolean) => void
label: string
description: ReactNode
disabled?: boolean
isRemoteLocked?: boolean
remoteTooltip?: string
isVisible?: boolean
}
// Interface for feature toggle configuration
interface FeatureToggle {
id: string
label: string
description: ReactNode
settingKey: keyof UpdateSettingsRequest
stateKey: string
/** If set, the setting value is nested with this key (e.g., "enabled" -> { enabled: checked }) */
nestedKey?: string
}
const agentFeatures: FeatureToggle[] = [
{
id: "subagents",
label: "Subagents",
description: "Let Cline run focused subagents in parallel to explore the codebase for you.",
stateKey: "subagentsEnabled",
settingKey: "subagentsEnabled",
},
{
id: "native-tool-call",
label: "Native Tool Call",
description: "Use native function calling when available",
stateKey: "nativeToolCallSetting",
settingKey: "nativeToolCallEnabled",
},
{
id: "parallel-tool-calling",
label: "Parallel Tool Calling",
description: "Execute multiple tool calls simultaneously",
stateKey: "enableParallelToolCalling",
settingKey: "enableParallelToolCalling",
},
{
id: "strict-plan-mode",
label: "Strict Plan Mode",
description: "Prevents file edits while in Plan mode",
stateKey: "strictPlanModeEnabled",
settingKey: "strictPlanModeEnabled",
},
{
id: "auto-compact",
label: "Auto Compact",
description: "Automatically compress conversation history.",
stateKey: "useAutoCondense",
settingKey: "useAutoCondense",
},
{
id: "focus-chain",
label: "Focus Chain",
description: "Maintain context focus across interactions",
stateKey: "focusChainEnabled",
settingKey: "focusChainSettings",
nestedKey: "enabled",
},
]
const editorFeatures: FeatureToggle[] = [
{
id: "show-feature-tips",
label: "Feature Tips",
description: "Show rotating tips during the thinking phase to help you discover Cline features.",
stateKey: "showFeatureTips",
settingKey: "showFeatureTips",
},
{
id: "background-edit",
label: "Background Edit",
description: "Allow edits without stealing editor focus",
stateKey: "backgroundEditEnabled",
settingKey: "backgroundEditEnabled",
},
{
id: "checkpoints",
label: "Checkpoints",
description: "Save progress at key points for easy rollback",
stateKey: "enableCheckpointsSetting",
settingKey: "enableCheckpointsSetting",
},
{
id: "cline-web-tools",
label: "Cline Web Tools",
description: "Access web browsing and search capabilities",
stateKey: "clineWebToolsEnabled",
settingKey: "clineWebToolsEnabled",
},
{
id: "worktrees",
label: "Worktrees",
description: "Enables git worktree management for running parallel Cline tasks.",
stateKey: "worktreesEnabled",
settingKey: "worktreesEnabled",
},
]
const experimentalFeatures: FeatureToggle[] = [
{
id: "yolo",
label: "Yolo Mode",
description:
"Execute tasks without user's confirmation. Auto-switches from Plan to Act mode and disables the ask question tool. Use with extreme caution.",
stateKey: "yoloModeToggled",
settingKey: "yoloModeToggled",
},
{
id: "double-check-completion",
label: "Double-Check Completion",
description:
"Rejects the first completion attempt and asks the model to re-verify its work against the original task requirements before accepting.",
stateKey: "doubleCheckCompletionEnabled",
settingKey: "doubleCheckCompletionEnabled",
},
{
id: "lazy-teammate",
label: "Lazy Teammate Mode",
description: "Sometimes Cline just isn't feeling it today. For entertainment purposes only.",
stateKey: "lazyTeammateModeEnabled",
settingKey: "lazyTeammateModeEnabled",
},
]
const advancedFeatures: FeatureToggle[] = [
{
id: "hooks",
label: "Hooks",
description: "Enable lifecycle and tool hooks during task execution.",
stateKey: "hooksEnabled",
settingKey: "hooksEnabled",
},
]
const FeatureRow = memo(
({
checked = false,
onChange,
label,
description,
disabled,
isRemoteLocked,
isVisible = true,
remoteTooltip,
}: FeatureCheckboxProps) => {
if (!isVisible) {
return null
}
const checkbox = (
{label}
{isRemoteLocked && }
)
return (
{isRemoteLocked ? (
{checkbox}
{remoteTooltip}
) : (
checkbox
)}
{description}
)
},
)
interface FeatureSettingsSectionProps {
renderSectionHeader: (tabId: string) => JSX.Element | null
}
const FeatureSettingsSection = ({ renderSectionHeader }: FeatureSettingsSectionProps) => {
const { t } = useTranslation("settings")
const featureTranslations: Record = {
subagents: { label: t("featureSettings.subagents"), description: t("featureSettings.subagentsDescription") },
"native-tool-call": {
label: t("featureSettings.nativeToolCall"),
description: t("featureSettings.nativeToolCallDescription"),
},
"parallel-tool-calling": {
label: t("featureSettings.parallelToolCalling"),
description: t("featureSettings.parallelToolCallingDescription"),
},
"strict-plan-mode": {
label: t("featureSettings.strictPlanMode"),
description: t("featureSettings.strictPlanModeDescription"),
},
"auto-compact": { label: t("featureSettings.autoCompact"), description: t("featureSettings.autoCompactDescription") },
"focus-chain": { label: t("featureSettings.focusChain"), description: t("featureSettings.focusChainDescription") },
"show-feature-tips": {
label: t("featureSettings.featureTips"),
description: t("featureSettings.featureTipsDescription"),
},
"background-edit": {
label: t("featureSettings.backgroundEdit"),
description: t("featureSettings.backgroundEditDescription"),
},
checkpoints: { label: t("featureSettings.checkpoints"), description: t("featureSettings.checkpointsDescription") },
"cline-web-tools": {
label: t("featureSettings.clineWebTools"),
description: t("featureSettings.clineWebToolsDescription"),
},
worktrees: { label: t("featureSettings.worktrees"), description: t("featureSettings.worktreesDescription") },
yolo: { label: t("featureSettings.yoloMode"), description: t("featureSettings.yoloModeDescription") },
"double-check-completion": {
label: t("featureSettings.doubleCheckCompletion"),
description: t("featureSettings.doubleCheckCompletionDescription"),
},
"lazy-teammate": {
label: t("featureSettings.lazyTeammateMode"),
description: t("featureSettings.lazyTeammateModeDescription"),
},
hooks: { label: t("featureSettings.hooks"), description: t("featureSettings.hooksDescription") },
}
const {
enableCheckpointsSetting,
hooksEnabled,
mcpDisplayMode,
strictPlanModeEnabled,
yoloModeToggled,
useAutoCondense,
subagentsEnabled,
clineWebToolsEnabled,
worktreesEnabled,
focusChainSettings,
remoteConfigSettings,
nativeToolCallSetting,
enableParallelToolCalling,
backgroundEditEnabled,
doubleCheckCompletionEnabled,
lazyTeammateModeEnabled,
showFeatureTips,
} = useExtensionState()
const handleFocusChainIntervalChange = useCallback(
(value: number) => {
updateSetting("focusChainSettings", { ...focusChainSettings, remindClineInterval: value })
},
[focusChainSettings],
)
const isYoloRemoteLocked = remoteConfigSettings?.yoloModeToggled !== undefined
// State lookup for mapped features
const featureState: Record = {
showFeatureTips,
enableCheckpointsSetting,
strictPlanModeEnabled,
hooksEnabled,
nativeToolCallSetting,
focusChainEnabled: focusChainSettings?.enabled,
useAutoCondense,
subagentsEnabled,
clineWebToolsEnabled: clineWebToolsEnabled?.user,
worktreesEnabled: worktreesEnabled?.user,
enableParallelToolCalling,
backgroundEditEnabled,
doubleCheckCompletionEnabled,
lazyTeammateModeEnabled,
yoloModeToggled: isYoloRemoteLocked ? remoteConfigSettings?.yoloModeToggled : yoloModeToggled,
}
// Visibility lookup for features with feature flags
const featureVisibility: Record = {
clineWebToolsEnabled: clineWebToolsEnabled?.featureFlag,
worktreesEnabled: worktreesEnabled?.featureFlag,
}
// Handler for feature toggle changes, supports nested settings like focusChainSettings
const handleFeatureChange = useCallback(
(feature: FeatureToggle, checked: boolean) => {
if (feature.nestedKey) {
// For nested settings, spread the existing value and set the nested key
let currentValue = {}
if (feature.settingKey === "focusChainSettings") {
currentValue = focusChainSettings ?? {}
}
updateSetting(feature.settingKey, { ...currentValue, [feature.nestedKey]: checked })
} else {
updateSetting(feature.settingKey, checked)
}
},
[focusChainSettings],
)
return (
{renderSectionHeader("features")}
{/* Core features */}
{t("featureSettings.agent")}
{agentFeatures.map((feature) => (
feature.nestedKey === "enabled"
? handleFeatureChange(feature, checked)
: updateSetting(feature.settingKey, checked)
}
/>
{feature.id === "focus-chain" && featureState[feature.stateKey] && (
)}
))}
{/* Editor features */}
{t("featureSettings.editor")}
{editorFeatures.map((feature) => (
handleFeatureChange(feature, checked)}
/>
))}
{/* Experimental features */}
{t("featureSettings.experimental")}
{experimentalFeatures.map((feature) => (
handleFeatureChange(feature, checked)}
remoteTooltip={t("remoteConfig.settingsManagedByOrg")}
/>
))}
{/* Advanced */}
{t("featureSettings.advanced")}
{advancedFeatures.map((feature) => (
handleFeatureChange(feature, checked)}
/>
))}
{/* MCP Display Mode */}
{t("featureSettings.mcpDisplayModeDescription")}
)
}
export default memo(FeatureSettingsSection)