Skip to content
Draft
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
4 changes: 4 additions & 0 deletions packages/types/src/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export const toolNames = [
"skill",
"generate_image",
"custom_tool",
"go_to_definition",
"find_references",
"workspace_symbols",
"document_symbols",
] as const

export const toolNamesSchema = z.enum(toolNames)
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/vscode-extension-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,10 @@ export interface ClineSayTool {
| "runSlashCommand"
| "updateTodoList"
| "skill"
| "goToDefinition"
| "findReferences"
| "workspaceSymbols"
| "documentSymbols"
path?: string
// For readCommandOutput
readStart?: number
Expand Down
72 changes: 72 additions & 0 deletions src/core/assistant-message/NativeToolCallParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,42 @@ export class NativeToolCallParser {
}
break

case "go_to_definition":
if (partialArgs.path !== undefined || partialArgs.line !== undefined) {
nativeArgs = {
path: partialArgs.path,
line: partialArgs.line,
character: partialArgs.character,
}
}
break

case "find_references":
if (partialArgs.path !== undefined || partialArgs.line !== undefined) {
nativeArgs = {
path: partialArgs.path,
line: partialArgs.line,
character: partialArgs.character,
}
}
break

case "workspace_symbols":
if (partialArgs.query !== undefined) {
nativeArgs = {
query: partialArgs.query,
}
}
break

case "document_symbols":
if (partialArgs.path !== undefined) {
nativeArgs = {
path: partialArgs.path,
}
}
break

case "switch_mode":
if (partialArgs.mode_slug !== undefined || partialArgs.reason !== undefined) {
nativeArgs = {
Expand Down Expand Up @@ -874,6 +910,42 @@ export class NativeToolCallParser {
}
break

case "go_to_definition":
if (args.path !== undefined && args.line !== undefined && args.character !== undefined) {
nativeArgs = {
path: args.path,
line: args.line,
character: args.character,
} as NativeArgsFor<TName>
}
break

case "find_references":
if (args.path !== undefined && args.line !== undefined && args.character !== undefined) {
nativeArgs = {
path: args.path,
line: args.line,
character: args.character,
} as NativeArgsFor<TName>
}
break

case "workspace_symbols":
if (args.query !== undefined) {
nativeArgs = {
query: args.query,
} as NativeArgsFor<TName>
}
break

case "document_symbols":
if (args.path !== undefined) {
nativeArgs = {
path: args.path,
} as NativeArgsFor<TName>
}
break

case "switch_mode":
if (args.mode_slug !== undefined && args.reason !== undefined) {
nativeArgs = {
Expand Down
40 changes: 40 additions & 0 deletions src/core/assistant-message/presentAssistantMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import { generateImageTool } from "../tools/GenerateImageTool"
import { applyDiffTool as applyDiffToolClass } from "../tools/ApplyDiffTool"
import { isValidToolName, validateToolUse } from "../tools/validateToolUse"
import { codebaseSearchTool } from "../tools/CodebaseSearchTool"
import { goToDefinitionTool } from "../tools/GoToDefinitionTool"
import { findReferencesTool } from "../tools/FindReferencesTool"
import { workspaceSymbolsTool } from "../tools/WorkspaceSymbolsTool"
import { documentSymbolsTool } from "../tools/DocumentSymbolsTool"

import { formatResponse } from "../prompts/responses"
import { sanitizeToolUseId } from "../../utils/tool-id"
Expand Down Expand Up @@ -383,6 +387,14 @@ export async function presentAssistantMessage(cline: Task) {
return `[${block.name} for '${block.params.skill}'${block.params.args ? ` with args: ${block.params.args}` : ""}]`
case "generate_image":
return `[${block.name} for '${block.params.path}']`
case "go_to_definition":
return `[${block.name} for '${block.params.path}:${block.params.line}:${block.params.character}']`
case "find_references":
return `[${block.name} for '${block.params.path}:${block.params.line}:${block.params.character}']`
case "workspace_symbols":
return `[${block.name} for '${block.params.query}']`
case "document_symbols":
return `[${block.name} for '${block.params.path}']`
default:
return `[${block.name}]`
}
Expand Down Expand Up @@ -761,6 +773,34 @@ export async function presentAssistantMessage(cline: Task) {
pushToolResult,
})
break
case "go_to_definition":
await goToDefinitionTool.handle(cline, block as ToolUse<"go_to_definition">, {
askApproval,
handleError,
pushToolResult,
})
break
case "find_references":
await findReferencesTool.handle(cline, block as ToolUse<"find_references">, {
askApproval,
handleError,
pushToolResult,
})
break
case "workspace_symbols":
await workspaceSymbolsTool.handle(cline, block as ToolUse<"workspace_symbols">, {
askApproval,
handleError,
pushToolResult,
})
break
case "document_symbols":
await documentSymbolsTool.handle(cline, block as ToolUse<"document_symbols">, {
askApproval,
handleError,
pushToolResult,
})
break
case "execute_command":
await executeCommandTool.handle(cline, block as ToolUse<"execute_command">, {
askApproval,
Expand Down
29 changes: 29 additions & 0 deletions src/core/prompts/tools/native-tools/document_symbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type OpenAI from "openai"

const DOCUMENT_SYMBOLS_DESCRIPTION = `Request to list all symbols defined in a specific file. Uses the VS Code language server to enumerate all functions, classes, methods, variables, types, and other symbols in the document. Returns a flat list of symbols with their names, kinds, and line ranges.

Parameters:
- path: (required) The file path (relative to the current workspace directory) to analyze.

Example: Listing all symbols in a TypeScript file
{ "path": "src/services/auth.ts" }`

export default {
type: "function",
function: {
name: "document_symbols",
description: DOCUMENT_SYMBOLS_DESCRIPTION,
strict: true,
parameters: {
type: "object",
properties: {
path: {
type: "string",
description: "File path relative to the workspace to analyze",
},
},
required: ["path"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
39 changes: 39 additions & 0 deletions src/core/prompts/tools/native-tools/find_references.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type OpenAI from "openai"

const FIND_REFERENCES_DESCRIPTION = `Request to find all references to a symbol at a given position in a file. Uses the VS Code language server to locate every place a symbol (function, class, variable, type, etc.) is referenced across the workspace. Returns a list of file paths and positions. Results are capped at 50 locations to keep context size reasonable.

Parameters:
- path: (required) The file path (relative to the current workspace directory) containing the symbol.
- line: (required) The 1-based line number of the symbol.
- character: (required) The 0-based character offset of the symbol on the line.

Example: Finding all references to a function at line 10, character 15
{ "path": "src/services/user.ts", "line": 10, "character": 15 }`

export default {
type: "function",
function: {
name: "find_references",
description: FIND_REFERENCES_DESCRIPTION,
strict: true,
parameters: {
type: "object",
properties: {
path: {
type: "string",
description: "File path relative to the workspace containing the symbol",
},
line: {
type: "number",
description: "1-based line number of the symbol",
},
character: {
type: "number",
description: "0-based character offset of the symbol on the line",
},
},
required: ["path", "line", "character"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
39 changes: 39 additions & 0 deletions src/core/prompts/tools/native-tools/go_to_definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type OpenAI from "openai"

const GO_TO_DEFINITION_DESCRIPTION = `Request to find the definition of a symbol at a given position in a file. Uses the VS Code language server to locate where a symbol (function, class, variable, type, etc.) is defined. Returns the file path and position of the definition.

Parameters:
- path: (required) The file path (relative to the current workspace directory) containing the symbol.
- line: (required) The 1-based line number of the symbol.
- character: (required) The 0-based character offset of the symbol on the line.

Example: Finding the definition of a function call at line 15, character 8
{ "path": "src/utils/auth.ts", "line": 15, "character": 8 }`

export default {
type: "function",
function: {
name: "go_to_definition",
description: GO_TO_DEFINITION_DESCRIPTION,
strict: true,
parameters: {
type: "object",
properties: {
path: {
type: "string",
description: "File path relative to the workspace containing the symbol",
},
line: {
type: "number",
description: "1-based line number of the symbol",
},
character: {
type: "number",
description: "0-based character offset of the symbol on the line",
},
},
required: ["path", "line", "character"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
8 changes: 8 additions & 0 deletions src/core/prompts/tools/native-tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import searchFiles from "./search_files"
import switchMode from "./switch_mode"
import updateTodoList from "./update_todo_list"
import writeToFile from "./write_to_file"
import goToDefinition from "./go_to_definition"
import findReferences from "./find_references"
import workspaceSymbols from "./workspace_symbols"
import documentSymbols from "./document_symbols"

export { getMcpServerTools } from "./mcp_server"
export { convertOpenAIToolToAnthropic, convertOpenAIToolsToAnthropic } from "./converters"
Expand Down Expand Up @@ -68,6 +72,10 @@ export function getNativeTools(options: NativeToolsOptions = {}): OpenAI.Chat.Ch
switchMode,
updateTodoList,
writeToFile,
goToDefinition,
findReferences,
workspaceSymbols,
documentSymbols,
] satisfies OpenAI.Chat.ChatCompletionTool[]
}

Expand Down
29 changes: 29 additions & 0 deletions src/core/prompts/tools/native-tools/workspace_symbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type OpenAI from "openai"

const WORKSPACE_SYMBOLS_DESCRIPTION = `Request to search for symbols across the entire workspace by name. Uses the VS Code language server to find classes, functions, variables, types, and other symbols that match a query string. Returns up to 100 matching symbols with their names, kinds, file paths, and positions.

Parameters:
- query: (required) The search query to match symbol names against. Can be a partial name (e.g., "User" will match "UserService", "getUser", etc.).

Example: Searching for all symbols containing "Payment"
{ "query": "Payment" }`

export default {
type: "function",
function: {
name: "workspace_symbols",
description: WORKSPACE_SYMBOLS_DESCRIPTION,
strict: true,
parameters: {
type: "object",
properties: {
query: {
type: "string",
description: "Search query to match symbol names against",
},
},
required: ["query"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
Loading
Loading