fix(desktop): confirm before clearing the entire Enabled Toolsets list (#73319)

Config settings auto-save on a 550ms debounce with no undo. The
'Enabled Toolsets' list is rendered by the generic ConfigField with no
destructive-change guard, so a stray select-all + Backspace (or any edit
that empties the list) is persisted the moment Settings closes —
silently disabling memory, terminal, web search, delegation, and most
tools. Recovery required CLI intervention.

Guard the one destructive transition: when the enabled-toolsets list
goes from non-empty to empty, window.confirm() before applying it (the
same pattern env-var removal already uses in toolset-config-panel.tsx).
Every other edit passes through untouched.

The decision is a pure helper (clearsEnabledToolsets) so it is unit
tested directly rather than through a full settings render. New i18n key
toolsetsWipeConfirm added to en + zh; partial locales inherit the
English string via defineLocale fallback.

Fixes #73319
This commit is contained in:
PRATHAMESH75
2026-07-28 18:34:20 +05:30
committed by Teknium
parent 7d34d7d8d1
commit 8e35ff0a62
6 changed files with 80 additions and 1 deletions
@@ -28,7 +28,7 @@ import { useOnProfileSwitch } from '../hooks/use-on-profile-switch'
import { PanelEmpty } from '../overlays/panel'
import { ConfigField } from './config-field'
import { enumOptionsFor, getNested, isExternalMemoryProvider, sectionFieldEntries, setNested } from './helpers'
import { clearsEnabledToolsets, enumOptionsFor, getNested, isExternalMemoryProvider, sectionFieldEntries, setNested } from './helpers'
import { MemoryConnect } from './memory/connect'
import { ProviderConfigPanel } from './memory/provider-config-panel'
import { ModelSettings, ModelSettingsSkeleton } from './model-settings'
@@ -183,6 +183,15 @@ export function ConfigSettings({
}, [config, onConfigSaved, saveVersion])
const updateConfig = (next: HermesConfigRecord) => {
// Guard the single most destructive config edit: clearing the entire
// "Enabled Toolsets" list silently disables memory, terminal, web search,
// delegation, and most tools, and a stray select-all + Backspace can do it.
// Auto-save is debounced with no undo, so confirm a non-empty → empty
// transition before applying it. Every other edit passes through untouched.
if (config && clearsEnabledToolsets(config, next) && !window.confirm(c.toolsetsWipeConfirm)) {
return
}
saveVersionRef.current += 1
setConfig(next)
setSaveVersion(saveVersionRef.current)
@@ -5,6 +5,7 @@ import type { HermesConfigRecord } from '@/types/hermes'
import { FIELD_DESCRIPTIONS, FIELD_LABELS, SECTIONS } from './constants'
import { defineFieldCopy, fieldCopyForSchemaKey, schemaKeyToFieldCopyKey } from './field-copy'
import {
clearsEnabledToolsets,
enumOptionsFor,
getNested,
isExternalMemoryProvider,
@@ -363,4 +364,44 @@ describe('settings helpers', () => {
expect(sectionFieldEntries({}, {}).get('memory') ?? []).toHaveLength(0)
})
})
describe('clearsEnabledToolsets', () => {
it('flags a non-empty → empty transition', () => {
const prev: HermesConfigRecord = { toolsets: ['memory', 'terminal', 'web_search'] }
const next: HermesConfigRecord = { toolsets: [] }
expect(clearsEnabledToolsets(prev, next)).toBe(true)
})
it('does not flag a non-empty → missing transition (deep-merge preserves the key)', () => {
// PUT /api/config deep-merges the override onto the stored config, so an
// import that omits `toolsets` keeps the existing list — no wipe happens,
// so there is nothing to confirm.
const prev: HermesConfigRecord = { toolsets: ['memory'] }
const next: HermesConfigRecord = {}
expect(clearsEnabledToolsets(prev, next)).toBe(false)
})
it('does not flag when at least one toolset remains', () => {
const prev: HermesConfigRecord = { toolsets: ['memory', 'terminal'] }
const next: HermesConfigRecord = { toolsets: ['memory'] }
expect(clearsEnabledToolsets(prev, next)).toBe(false)
})
it('does not flag when the list was already empty', () => {
const prev: HermesConfigRecord = { toolsets: [] }
const next: HermesConfigRecord = { toolsets: [] }
expect(clearsEnabledToolsets(prev, next)).toBe(false)
})
it('does not flag an unrelated edit that never touched toolsets', () => {
const prev: HermesConfigRecord = { model: 'a', toolsets: ['memory'] }
const next: HermesConfigRecord = { model: 'b', toolsets: ['memory'] }
expect(clearsEnabledToolsets(prev, next)).toBe(false)
})
})
})
+25
View File
@@ -97,6 +97,31 @@ export function getNested(obj: HermesConfigRecord, path: string): unknown {
return cur
}
/**
* True when an edit clears the entire "Enabled Toolsets" list — i.e. the
* previous config had a non-empty toolsets array and the next one is an
* explicit empty array.
*
* A *missing* toolsets key is deliberately NOT a clear: `PUT /api/config`
* deep-merges the override onto the stored config (`_deep_merge` preserves base
* keys absent from the override), so an import that omits `toolsets` leaves the
* existing toolsets intact. Prompting there would warn about a wipe that never
* happens. Only an explicit `[]` actually empties the list.
*
* Clearing every toolset silently disables memory, terminal, web search,
* delegation, and most tools, and config auto-saves with no undo, so callers
* use this to confirm the destructive transition before applying it. Any edit
* that keeps at least one toolset — or that never had one — returns false.
*/
export function clearsEnabledToolsets(prev: HermesConfigRecord, next: HermesConfigRecord): boolean {
const prevToolsets = getNested(prev, 'toolsets')
const nextToolsets = getNested(next, 'toolsets')
const hadToolsets = Array.isArray(prevToolsets) && prevToolsets.length > 0
const clearsToolsets = Array.isArray(nextToolsets) && nextToolsets.length === 0
return hadToolsets && clearsToolsets
}
export function inferFieldSchema(value: unknown): ConfigFieldSchema {
if (typeof value === 'boolean') {
return { type: 'boolean' }
+2
View File
@@ -584,6 +584,8 @@ export const en: Translations = {
autosaveFailed: 'Autosave failed',
imported: 'Config imported',
invalidJson: 'Invalid config JSON',
toolsetsWipeConfirm:
'Remove all enabled toolsets? This disables memory, terminal, web search, delegation, and most other tools until you re-enable them.',
keepAwakeTitle: 'Keep computer awake',
keepAwakeDesc: 'Stop this machine from sleeping so long or overnight runs keep going. The display can still dim.',
attachmentSizeTitle: 'Max preview / image load size',
+1
View File
@@ -480,6 +480,7 @@ export interface Translations {
autosaveFailed: string
imported: string
invalidJson: string
toolsetsWipeConfirm: string
keepAwakeTitle: string
keepAwakeDesc: string
attachmentSizeTitle: string
+1
View File
@@ -792,6 +792,7 @@ export const zh: Translations = {
autosaveFailed: '自动保存失败',
imported: '配置已导入',
invalidJson: '配置 JSON 无效',
toolsetsWipeConfirm: '确定移除所有已启用的工具集吗?这将禁用记忆、终端、网络搜索、委派以及大多数其他工具,直到你重新启用它们。',
keepAwakeTitle: '保持电脑唤醒',
keepAwakeDesc: '阻止本机休眠,让长时间或通宵运行继续进行。屏幕仍可变暗。',
attachmentSizeTitle: '预览 / 图片加载大小上限',