Skip to content

Commit f5f28ca

Browse files
committed
feat: update tool settings to show individual toggles dynamically
- Remove grouped display of tools - Show all tools as individual toggles in a flat list - Make tool list dynamic based on global TOOL_GROUPS configuration - Separate disableable tools from always-available tools - Add translation for "Always available tools" section
1 parent 7267fe0 commit f5f28ca

File tree

2 files changed

+81
-33
lines changed

2 files changed

+81
-33
lines changed

webview-ui/src/components/settings/ToolSettings.tsx

Lines changed: 79 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type ToolSettingsProps = HTMLAttributes<HTMLDivElement> & {
1313
setCachedStateField: SetCachedStateField<"disabledTools">
1414
}
1515

16+
// Import the constants from shared/tools.ts
1617
// Tool display names mapping
1718
const TOOL_DISPLAY_NAMES: Record<string, string> = {
1819
execute_command: "Run commands",
@@ -45,20 +46,30 @@ const ALWAYS_AVAILABLE_TOOLS = [
4546
"update_todo_list",
4647
]
4748

48-
// Tool groups for better organization
49-
const TOOL_GROUPS = {
50-
"File Operations": [
51-
"read_file",
52-
"write_to_file",
53-
"search_files",
54-
"list_files",
55-
"list_code_definition_names",
56-
"codebase_search",
57-
],
58-
"Code Editing": ["apply_diff", "insert_content", "search_and_replace"],
59-
System: ["execute_command", "browser_action"],
60-
MCP: ["use_mcp_tool", "access_mcp_resource"],
61-
Other: ["fetch_instructions"],
49+
// Tool groups configuration
50+
const TOOL_GROUPS: Record<string, { tools: readonly string[] }> = {
51+
read: {
52+
tools: [
53+
"read_file",
54+
"fetch_instructions",
55+
"search_files",
56+
"list_files",
57+
"list_code_definition_names",
58+
"codebase_search",
59+
],
60+
},
61+
edit: {
62+
tools: ["apply_diff", "write_to_file", "insert_content", "search_and_replace"],
63+
},
64+
browser: {
65+
tools: ["browser_action"],
66+
},
67+
command: {
68+
tools: ["execute_command"],
69+
},
70+
mcp: {
71+
tools: ["use_mcp_tool", "access_mcp_resource"],
72+
},
6273
}
6374

6475
export const ToolSettings = ({ disabledTools = [], setCachedStateField, ...props }: ToolSettingsProps) => {
@@ -79,13 +90,35 @@ export const ToolSettings = ({ disabledTools = [], setCachedStateField, ...props
7990

8091
const isToolEnabled = (toolName: string) => !disabledTools.includes(toolName)
8192

82-
const toolGroups = useMemo(() => {
83-
return Object.entries(TOOL_GROUPS).map(([groupName, tools]) => ({
84-
name: groupName,
85-
tools: tools.filter((tool) => !ALWAYS_AVAILABLE_TOOLS.includes(tool)),
86-
}))
93+
// Get all available tools dynamically from the global tools configuration
94+
const allTools = useMemo(() => {
95+
const tools = new Set<string>()
96+
97+
// Add all tools from tool groups
98+
Object.values(TOOL_GROUPS).forEach((group) => {
99+
group.tools.forEach((tool) => tools.add(tool))
100+
})
101+
102+
// Add always available tools
103+
ALWAYS_AVAILABLE_TOOLS.forEach((tool) => tools.add(tool))
104+
105+
// Convert to array and sort alphabetically
106+
return Array.from(tools).sort((a, b) => {
107+
const nameA = TOOL_DISPLAY_NAMES[a as keyof typeof TOOL_DISPLAY_NAMES] || a
108+
const nameB = TOOL_DISPLAY_NAMES[b as keyof typeof TOOL_DISPLAY_NAMES] || b
109+
return nameA.localeCompare(nameB)
110+
})
87111
}, [])
88112

113+
// Separate tools into disableable and always-available
114+
const disableableTools = useMemo(() => {
115+
return allTools.filter((tool) => !ALWAYS_AVAILABLE_TOOLS.includes(tool as any))
116+
}, [allTools])
117+
118+
const alwaysAvailableTools = useMemo(() => {
119+
return allTools.filter((tool) => ALWAYS_AVAILABLE_TOOLS.includes(tool as any))
120+
}, [allTools])
121+
89122
return (
90123
<div {...props}>
91124
<SectionHeader>
@@ -98,21 +131,35 @@ export const ToolSettings = ({ disabledTools = [], setCachedStateField, ...props
98131
<Section>
99132
<div className="text-vscode-descriptionForeground text-sm mb-3">{t("settings:tools.description")}</div>
100133

101-
<div className="space-y-4">
102-
{toolGroups.map(({ name, tools }) => (
103-
<div key={name}>
104-
<h4 className="font-medium mb-2">{name}</h4>
105-
<div className="space-y-1 pl-3">
106-
{tools.map((tool) => (
107-
<VSCodeCheckbox
108-
key={tool}
109-
checked={isToolEnabled(tool)}
110-
onChange={(e: any) => handleToolToggle(tool, e.target.checked)}>
111-
<span className="text-sm">{TOOL_DISPLAY_NAMES[tool] || tool}</span>
112-
</VSCodeCheckbox>
113-
))}
134+
<div className="space-y-2">
135+
{/* Disableable tools */}
136+
{disableableTools.map((tool) => (
137+
<VSCodeCheckbox
138+
key={tool}
139+
checked={isToolEnabled(tool)}
140+
onChange={(e: any) => handleToolToggle(tool, e.target.checked)}>
141+
<span className="text-sm">
142+
{TOOL_DISPLAY_NAMES[tool as keyof typeof TOOL_DISPLAY_NAMES] || tool}
143+
</span>
144+
</VSCodeCheckbox>
145+
))}
146+
147+
{/* Separator */}
148+
{alwaysAvailableTools.length > 0 && (
149+
<div className="border-t border-vscode-panel-border my-3 pt-3">
150+
<div className="text-vscode-descriptionForeground text-xs mb-2">
151+
{t("settings:tools.alwaysAvailable")}
114152
</div>
115153
</div>
154+
)}
155+
156+
{/* Always available tools (disabled checkboxes) */}
157+
{alwaysAvailableTools.map((tool) => (
158+
<VSCodeCheckbox key={tool} checked={true} disabled={true}>
159+
<span className="text-sm opacity-75">
160+
{TOOL_DISPLAY_NAMES[tool as keyof typeof TOOL_DISPLAY_NAMES] || tool}
161+
</span>
162+
</VSCodeCheckbox>
116163
))}
117164
</div>
118165

webview-ui/src/i18n/locales/en/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@
722722
"includeMaxOutputTokensDescription": "Send max output tokens parameter in API requests. Some providers may not support this.",
723723
"tools": {
724724
"description": "Disable specific tools to reduce token usage. Disabled tools won't be included in the system prompt.",
725-
"note": "Note: Some tools are always available and cannot be disabled (ask questions, complete tasks, switch modes, create new task, update todo list)."
725+
"note": "Note: Some tools are always available and cannot be disabled (ask questions, complete tasks, switch modes, create new task, update todo list).",
726+
"alwaysAvailable": "Always available tools"
726727
}
727728
}

0 commit comments

Comments
 (0)