Path: blob/main/extensions/copilot/src/extension/chatSessions/claude/common/claudeTools.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import {6AgentInput,7AskUserQuestionInput,8BashInput,9FileEditInput,10FileReadInput,11FileWriteInput,12GlobInput,13GrepInput,14NotebookEditInput,15ExitPlanModeInput as SDKExitPlanModeInput,16TaskOutputInput,17TaskStopInput,18TodoWriteInput,19WebFetchInput,20WebSearchInput,21} from '@anthropic-ai/claude-agent-sdk/sdk-tools';22import { URI } from '../../../../util/vs/base/common/uri';2324/**25* Extended ExitPlanModeInput that includes the plan property sent by the actual tool.26* The SDK type only has allowedPrompts, but the tool also sends plan.27*/28export interface ExitPlanModeInput extends SDKExitPlanModeInput {29readonly plan?: string;30}3132/**33* EnterPlanMode tool input - empty as the tool takes no parameters34*/35export interface EnterPlanModeInput {36// EnterPlanMode takes no input parameters37}3839// TODO: How can we verify these when we bump the SDK version?40export enum ClaudeToolNames {41Agent = 'Agent',42Task = 'Task',43Bash = 'Bash',44Glob = 'Glob',45Grep = 'Grep',46LS = 'LS',47EnterPlanMode = 'EnterPlanMode',48ExitPlanMode = 'ExitPlanMode',49Read = 'Read',50Edit = 'Edit',51MultiEdit = 'MultiEdit',52Write = 'Write',53NotebookEdit = 'NotebookEdit',54WebFetch = 'WebFetch',55TodoWrite = 'TodoWrite',56WebSearch = 'WebSearch',57BashOutput = 'BashOutput',58KillBash = 'KillBash',59AskUserQuestion = 'AskUserQuestion',60}61626364/**65* LS tool input - not defined in SDK66*/67export interface LSInput {68readonly path: string;69}7071/**72* Maps ClaudeToolNames to their SDK input types73*/74export interface ClaudeToolInputMap {75[ClaudeToolNames.Agent]: AgentInput;76[ClaudeToolNames.Task]: AgentInput;77[ClaudeToolNames.Bash]: BashInput;78[ClaudeToolNames.Glob]: GlobInput;79[ClaudeToolNames.Grep]: GrepInput;80[ClaudeToolNames.LS]: LSInput;81[ClaudeToolNames.EnterPlanMode]: EnterPlanModeInput;82[ClaudeToolNames.ExitPlanMode]: ExitPlanModeInput;83[ClaudeToolNames.Read]: FileReadInput;84[ClaudeToolNames.Edit]: FileEditInput;85[ClaudeToolNames.MultiEdit]: FileEditInput;86[ClaudeToolNames.Write]: FileWriteInput;87[ClaudeToolNames.NotebookEdit]: NotebookEditInput;88[ClaudeToolNames.WebFetch]: WebFetchInput;89[ClaudeToolNames.TodoWrite]: TodoWriteInput;90[ClaudeToolNames.WebSearch]: WebSearchInput;91[ClaudeToolNames.BashOutput]: TaskOutputInput;92[ClaudeToolNames.KillBash]: TaskStopInput;93[ClaudeToolNames.AskUserQuestion]: AskUserQuestionInput;94}9596export const claudeEditTools: readonly string[] = [ClaudeToolNames.Edit, ClaudeToolNames.MultiEdit, ClaudeToolNames.Write, ClaudeToolNames.NotebookEdit];9798export function getAffectedUrisForEditTool(toolName: string, toolInput: unknown): URI[] {99switch (toolName) {100case ClaudeToolNames.Edit:101case ClaudeToolNames.MultiEdit:102return [URI.file((toolInput as FileEditInput).file_path)];103case ClaudeToolNames.Write:104return [URI.file((toolInput as FileWriteInput).file_path)];105case ClaudeToolNames.NotebookEdit:106return [URI.file((toolInput as NotebookEditInput).notebook_path)];107default:108return [];109}110}111112113