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