Skip to content
Closed
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
24 changes: 24 additions & 0 deletions src/extension/agents/copilotcli/common/copilotcliTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@

import { URI } from '../../../../util/vs/base/common/uri';

/**
* Arguments for the Copilot CLI str_replace_editor tool.
* This tool is used by Copilot CLI to perform file editing operations.
*/
interface StrReplaceEditorArgs {
/** The edit command to execute */
command: 'view' | 'str_replace' | 'insert' | 'create' | 'undo_edit';
/** The file path to operate on */
path: string;
}

/**
* Type guard to check if a tool call is a Copilot CLI edit operation.
* This function validates that the tool is the str_replace_editor and that it's
* performing an actual edit operation (not just viewing).
*
* @param toolName - The name of the tool being invoked
* @param toolArgs - The arguments passed to the tool
* @returns true if this is a Copilot CLI edit tool call (excludes 'view' commands)
*/
export function isCopilotCliEditToolCall(toolName: string, toolArgs: unknown): toolArgs is StrReplaceEditorArgs {
return toolName === 'str_replace_editor'
&& typeof toolArgs === 'object'
Expand All @@ -18,6 +33,15 @@ export function isCopilotCliEditToolCall(toolName: string, toolArgs: unknown): t
&& toolArgs.command !== 'view';
}

/**
* Extracts the list of file URIs that will be affected by a Copilot CLI edit tool call.
* This is used to track which files are being modified during a Copilot CLI session.
*
* @param toolName - The name of the tool being invoked
* @param toolArgs - The arguments passed to the tool
* @returns An array of URIs for files that will be affected by the edit operation.
* Returns an empty array if the tool is not an edit operation or has no path.
*/
export function getAffectedUrisForEditTool(toolName: string, toolArgs: unknown): URI[] {
if (isCopilotCliEditToolCall(toolName, toolArgs) && toolArgs.path) {
return [URI.file(toolArgs.path)];
Expand Down