Skip to content

Commit 5596614

Browse files
committed
Cleaner approach to prompt checkboxes
1 parent 2c2d184 commit 5596614

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

src/core/__tests__/mode-validator.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ describe("mode-validator", () => {
99
it("allows all code mode tools", () => {
1010
const mode = getModeConfig(codeMode)
1111
// Code mode has all groups
12-
Object.entries(TOOL_GROUPS).forEach(([_, tools]) => {
13-
tools.forEach((tool) => {
12+
Object.entries(TOOL_GROUPS).forEach(([_, config]) => {
13+
config.tools.forEach((tool: string) => {
1414
expect(isToolAllowedForMode(tool, codeMode, [])).toBe(true)
1515
})
1616
})
@@ -25,7 +25,11 @@ describe("mode-validator", () => {
2525
it("allows configured tools", () => {
2626
const mode = getModeConfig(architectMode)
2727
// Architect mode has read, browser, and mcp groups
28-
const architectTools = [...TOOL_GROUPS.read, ...TOOL_GROUPS.browser, ...TOOL_GROUPS.mcp]
28+
const architectTools = [
29+
...TOOL_GROUPS.read.tools,
30+
...TOOL_GROUPS.browser.tools,
31+
...TOOL_GROUPS.mcp.tools,
32+
]
2933
architectTools.forEach((tool) => {
3034
expect(isToolAllowedForMode(tool, architectMode, [])).toBe(true)
3135
})
@@ -36,7 +40,7 @@ describe("mode-validator", () => {
3640
it("allows configured tools", () => {
3741
const mode = getModeConfig(askMode)
3842
// Ask mode has read, browser, and mcp groups
39-
const askTools = [...TOOL_GROUPS.read, ...TOOL_GROUPS.browser, ...TOOL_GROUPS.mcp]
43+
const askTools = [...TOOL_GROUPS.read.tools, ...TOOL_GROUPS.browser.tools, ...TOOL_GROUPS.mcp.tools]
4044
askTools.forEach((tool) => {
4145
expect(isToolAllowedForMode(tool, askMode, [])).toBe(true)
4246
})

src/core/prompts/tools/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function getToolDescriptionsForMode(
6666
const groupName = getGroupName(groupEntry)
6767
const toolGroup = TOOL_GROUPS[groupName]
6868
if (toolGroup) {
69-
toolGroup.forEach((tool) => {
69+
toolGroup.tools.forEach((tool) => {
7070
if (isToolAllowedForMode(tool as ToolName, mode, customModes ?? [], experiments ?? {})) {
7171
tools.add(tool)
7272
}

src/shared/modes.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export function getToolsForMode(groups: readonly GroupEntry[]): string[] {
5959
// Add tools from each group
6060
groups.forEach((group) => {
6161
const groupName = getGroupName(group)
62-
TOOL_GROUPS[groupName].forEach((tool) => tools.add(tool))
62+
const groupConfig = TOOL_GROUPS[groupName]
63+
groupConfig.tools.forEach((tool: string) => tools.add(tool))
6364
})
6465

6566
// Always add required tools
@@ -190,8 +191,10 @@ export function isToolAllowedForMode(
190191
const groupName = getGroupName(group)
191192
const options = getGroupOptions(group)
192193

193-
// If the tool isn't in this group, continue to next group
194-
if (!TOOL_GROUPS[groupName].includes(tool)) {
194+
const groupConfig = TOOL_GROUPS[groupName]
195+
196+
// If the tool isn't in this group's tools, continue to next group
197+
if (!groupConfig.tools.includes(tool)) {
195198
continue
196199
}
197200

src/shared/tool-groups.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
// Define tool group values
2-
export type ToolGroupValues = readonly string[]
1+
// Define tool group configuration
2+
export type ToolGroupConfig = {
3+
tools: readonly string[]
4+
alwaysAvailable?: boolean // Whether this group is always available and shouldn't show in prompts view
5+
}
36

47
// Map of tool slugs to their display names
58
export const TOOL_DISPLAY_NAMES = {
@@ -20,13 +23,26 @@ export const TOOL_DISPLAY_NAMES = {
2023
} as const
2124

2225
// Define available tool groups
23-
export const TOOL_GROUPS: Record<string, ToolGroupValues> = {
24-
read: ["read_file", "search_files", "list_files", "list_code_definition_names"],
25-
edit: ["write_to_file", "apply_diff", "insert_content", "search_and_replace"],
26-
browser: ["browser_action"],
27-
command: ["execute_command"],
28-
mcp: ["use_mcp_tool", "access_mcp_resource"],
29-
modes: ["switch_mode", "new_task"],
26+
export const TOOL_GROUPS: Record<string, ToolGroupConfig> = {
27+
read: {
28+
tools: ["read_file", "search_files", "list_files", "list_code_definition_names"],
29+
},
30+
edit: {
31+
tools: ["write_to_file", "apply_diff", "insert_content", "search_and_replace"],
32+
},
33+
browser: {
34+
tools: ["browser_action"],
35+
},
36+
command: {
37+
tools: ["execute_command"],
38+
},
39+
mcp: {
40+
tools: ["use_mcp_tool", "access_mcp_resource"],
41+
},
42+
modes: {
43+
tools: ["switch_mode", "new_task"],
44+
alwaysAvailable: true,
45+
},
3046
}
3147

3248
export type ToolGroup = keyof typeof TOOL_GROUPS

webview-ui/src/components/prompts/PromptsView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import {
2626
import { TOOL_GROUPS, GROUP_DISPLAY_NAMES, ToolGroup } from "../../../../src/shared/tool-groups"
2727
import { vscode } from "../../utils/vscode"
2828

29-
// Get all available groups from GROUP_DISPLAY_NAMES (excluding 'modes')
30-
const availableGroups = (Object.keys(TOOL_GROUPS) as ToolGroup[]).filter((group) => group !== "modes")
29+
// Get all available groups that should show in prompts view
30+
const availableGroups = (Object.keys(TOOL_GROUPS) as ToolGroup[]).filter((group) => !TOOL_GROUPS[group].alwaysAvailable)
3131

3232
type PromptsViewProps = {
3333
onDone: () => void

0 commit comments

Comments
 (0)