1
>
/*---------------------------------------------------------------------------------------------
copilotToolDisplay.ts
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 type { PermissionRequest } from '@github/copilot-sdk';
7
>
import { hasKey } from '../../../../base/common/types.js';
8
>
import { URI } from '../../../../base/common/uri.js';
9
>
import { appendEscapedMarkdownInlineCode, escapeMarkdownLinkLabel, MarkdownString } from '../../../../base/common/htmlContent.js';
10
>
import { hash } from '../../../../base/common/hash.js';
11
>
import { localize } from '../../../../nls.js';
12
>
import type { IAgentToolPendingConfirmationSignal } from '../../common/agentService.js';
13
>
import { stripRedundantCdPrefix } from '../../common/commandLineHelpers.js';
14
>
import { StringOrMarkdown } from '../../common/state/protocol/state.js';
15
>
import { basename } from '../../../../base/common/resources.js';
16
>
import { getServerToolDisplay } from '../shared/serverToolGroups.js';
17
>
18
>
// =============================================================================
19
>
// Copilot CLI built-in tool interfaces
20
>
//
21
>
// The Copilot CLI (via @github/copilot-sdk) exposes these built-in tools. Tool names
22
>
// and parameter shapes are not typed in the SDK -- they come from the CLI server
23
>
// as plain strings. These interfaces are derived from observing the CLI's actual
24
>
// tool events and the Copilot Chat extension's CLI display table.
25
>
//
26
>
// Shell tool names follow a pattern per ShellConfig:
27
>
// shellToolName, readShellToolName, writeShellToolName,
28
>
// stopShellToolName, listShellsToolName
29
>
// For bash: bash, read_bash, write_bash, stop_bash/bash_shutdown, list_bash
30
>
// For powershell: powershell, read_powershell, write_powershell, stop_powershell/powershell_shutdown, list_powershell
31
>
// =============================================================================
32
>
33
>
/**
34
>
* Known Copilot CLI tool names. These are the `toolName` values that appear
35
>
* in `tool.execution_start` events from the SDK.
36
>
*/
37
>
const enum CopilotToolName {
38
>
StrReplaceEditor = 'str_replace_editor',
39
>
StrReplace = 'str_replace',
40
>
Insert = 'insert',
41
>
42
>
Bash = 'bash',
43
>
ReadBash = 'read_bash',
44
>
WriteBash = 'write_bash',
45
>
StopBash = 'stop_bash',
46
>
BashShutdown = 'bash_shutdown',
47
>
ListBash = 'list_bash',
48
>
49
>
PowerShell = 'powershell',
50
>
ReadPowerShell = 'read_powershell',
51
>
WritePowerShell = 'write_powershell',
52
>
StopPowerShell = 'stop_powershell',
53
>
PowerShellShutdown = 'powershell_shutdown',
54
>
ListPowerShell = 'list_powershell',
55
>
56
>
View = 'view',
57
>
Edit = 'edit',
58
>
Create = 'create',
59
>
Grep = 'grep',
60
>
Rg = 'rg',
61
>
Glob = 'glob',
62
>
SearchCodeSubagent = 'search_code_subagent',
63
>
ReplyToComment = 'reply_to_comment',
64
>
CodeReview = 'code_review',
65
>
ApplyPatch = 'apply_patch',
66
>
GitApplyPatch = 'git_apply_patch',
67
>
WebSearch = 'web_search',
68
>
WebFetch = 'web_fetch',
69
>
AskUser = 'ask_user',
70
>
ReportIntent = 'report_intent',
71
>
Think = 'think',
72
>
ReportProgress = 'report_progress',
73
>
UpdateTodo = 'update_todo',
74
>
ShowFile = 'show_file',
75
>
FetchCopilotCliDocumentation = 'fetch_copilot_cli_documentation',
76
>
ProposeWork = 'propose_work',
77
>
TaskComplete = 'task_complete',
78
>
Skill = 'skill',
79
>
Task = 'task',
80
>
ListAgents = 'list_agents',
81
>
ReadAgent = 'read_agent',
82
>
ExitPlanMode = 'exit_plan_mode',
83
>
Sql = 'sql',
84
>
Lsp = 'lsp',
85
>
CreatePullRequest = 'create_pull_request',
86
>
GhAdvisoryDatabase = 'gh-advisory-database',
87
>
StoreMemory = 'store_memory',
88
>
ParallelValidation = 'parallel_validation',
89
>
WriteAgent = 'write_agent',
90
>
McpReload = 'mcp_reload',
91
>
McpValidate = 'mcp_validate',
92
>
ToolSearchToolRegex = 'tool_search_tool_regex',
93
>
CodeqlChecker = 'codeql_checker',
94
>
}
95
>
96
>
/** Parameters for the `bash` / `powershell` shell tools. */
97
>
interface ICopilotShellToolArgs {
98
>
command: string;
99
>
timeout?: number;
100
>
}
101
>
102
>
/** Parameters for file tools (`view`, `edit`, `create`). */
103
>
interface ICopilotFileToolArgs {
104
>
path: string;
105
>
}
106
>
107
>
/**
108
>
* Parameters for the `view` tool. The Copilot CLI accepts an optional
109
>
* `view_range: [startLine, endLine]` (1-based, inclusive). `endLine` may be
110
>
* `-1` to mean "to end of file".
111
>
*/
112
>
interface ICopilotViewToolArgs extends ICopilotFileToolArgs {
113
>
view_range?: number[];
114
>
}
115
>
116
>
/**
117
>
* Normalizes a `view_range` array. Returns `undefined` unless the array has
118
>
* exactly two integer elements with `startLine >= 0`. `endLine === -1` is
119
>
* preserved as the "to end of file" sentinel; otherwise `endLine` must be
120
>
* `>= startLine`.
121
>
*/
122
function formatViewRange(view_range: number[] | undefined): { startLine: number; endLine: number } | undefined {
123
if (!Array.isArray(view_range) || view_range.length !== 2) {