Add Windsurf in edit tool to modify changes, if installed (#853)

This commit is contained in:
Eddie Santos 2025-06-09 16:01:06 -07:00 committed by GitHub
parent 5c9e526f0e
commit 6484dc9008
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 92 additions and 15 deletions

View File

@ -98,6 +98,24 @@ export const ToolConfirmationMessage: React.FC<
}); });
} }
if (
checkHasEditor('windsurf') &&
notUsingSandbox &&
externalEditorsEnabled
) {
options.push({
label: 'Modify with Windsurf',
value: ToolConfirmationOutcome.ModifyWindsurf,
});
}
if (checkHasEditor('cursor') && notUsingSandbox && externalEditorsEnabled) {
options.push({
label: 'Modify with Cursor',
value: ToolConfirmationOutcome.ModifyCursor,
});
}
if (checkHasEditor('vim') && externalEditorsEnabled) { if (checkHasEditor('vim') && externalEditorsEnabled) {
options.push({ options.push({
label: 'Modify with vim', label: 'Modify with vim',

View File

@ -486,6 +486,8 @@ export class CoreToolScheduler {
); );
} else if ( } else if (
outcome === ToolConfirmationOutcome.ModifyVSCode || outcome === ToolConfirmationOutcome.ModifyVSCode ||
outcome === ToolConfirmationOutcome.ModifyWindsurf ||
outcome === ToolConfirmationOutcome.ModifyCursor ||
outcome === ToolConfirmationOutcome.ModifyVim outcome === ToolConfirmationOutcome.ModifyVim
) { ) {
const waitingToolCall = toolCall as WaitingToolCall; const waitingToolCall = toolCall as WaitingToolCall;

View File

@ -25,6 +25,7 @@ import { ensureCorrectEdit } from '../utils/editCorrector.js';
import { DEFAULT_DIFF_OPTIONS } from './diffOptions.js'; import { DEFAULT_DIFF_OPTIONS } from './diffOptions.js';
import { openDiff } from '../utils/editor.js'; import { openDiff } from '../utils/editor.js';
import { ReadFileTool } from './read-file.js'; import { ReadFileTool } from './read-file.js';
import { EditorType } from '../utils/editor.js';
/** /**
* Parameters for the Edit tool * Parameters for the Edit tool
@ -467,6 +468,19 @@ Expectation for required parameters:
} }
} }
async getEditor(outcome: ToolConfirmationOutcome): Promise<EditorType> {
switch (outcome) {
case ToolConfirmationOutcome.ModifyVSCode:
return 'vscode';
case ToolConfirmationOutcome.ModifyWindsurf:
return 'windsurf';
case ToolConfirmationOutcome.ModifyCursor:
return 'cursor';
default:
return 'vim';
}
}
/** /**
* Creates temp files for the current and proposed file contents and opens a diff tool. * Creates temp files for the current and proposed file contents and opens a diff tool.
* When the diff tool is closed, the tool will check if the file has been modified and provide the updated params. * When the diff tool is closed, the tool will check if the file has been modified and provide the updated params.
@ -483,11 +497,9 @@ Expectation for required parameters:
this.tempOldDiffPath = oldPath; this.tempOldDiffPath = oldPath;
this.tempNewDiffPath = newPath; this.tempNewDiffPath = newPath;
await openDiff( const editor = await this.getEditor(outcome);
this.tempOldDiffPath,
this.tempNewDiffPath, await openDiff(this.tempOldDiffPath, this.tempNewDiffPath, editor);
outcome === ToolConfirmationOutcome.ModifyVSCode ? 'vscode' : 'vim',
);
return await this.getUpdatedParamsIfModified(params, _abortSignal); return await this.getUpdatedParamsIfModified(params, _abortSignal);
} }

View File

@ -233,6 +233,8 @@ export enum ToolConfirmationOutcome {
ProceedAlwaysServer = 'proceed_always_server', ProceedAlwaysServer = 'proceed_always_server',
ProceedAlwaysTool = 'proceed_always_tool', ProceedAlwaysTool = 'proceed_always_tool',
ModifyVSCode = 'modify_vscode', ModifyVSCode = 'modify_vscode',
ModifyWindsurf = 'modify_windsurf',
ModifyCursor = 'modify_cursor',
ModifyVim = 'modify_vim', ModifyVim = 'modify_vim',
Cancel = 'cancel', Cancel = 'cancel',
} }

View File

@ -35,6 +35,36 @@ describe('checkHasEditor', () => {
expect(checkHasEditor('vscode')).toBe(false); expect(checkHasEditor('vscode')).toBe(false);
}); });
it('should return true for windsurf if "windsurf" command exists', () => {
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/windsurf'));
expect(checkHasEditor('windsurf')).toBe(true);
expect(execSync).toHaveBeenCalledWith('command -v windsurf', {
stdio: 'ignore',
});
});
it('should return false for windsurf if "windsurf" command does not exist', () => {
(execSync as Mock).mockImplementation(() => {
throw new Error();
});
expect(checkHasEditor('windsurf')).toBe(false);
});
it('should return true for cursor if "cursor" command exists', () => {
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/cursor'));
expect(checkHasEditor('cursor')).toBe(true);
expect(execSync).toHaveBeenCalledWith('command -v cursor', {
stdio: 'ignore',
});
});
it('should return false for cursor if "cursor" command does not exist', () => {
(execSync as Mock).mockImplementation(() => {
throw new Error();
});
expect(checkHasEditor('cursor')).toBe(false);
});
it('should return true for vim if "vim" command exists', () => { it('should return true for vim if "vim" command exists', () => {
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/vim')); (execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/vim'));
expect(checkHasEditor('vim')).toBe(true); expect(checkHasEditor('vim')).toBe(true);
@ -71,7 +101,7 @@ describe('getDiffCommand', () => {
it('should return null for an unsupported editor', () => { it('should return null for an unsupported editor', () => {
// @ts-expect-error Testing unsupported editor // @ts-expect-error Testing unsupported editor
const command = getDiffCommand('old.txt', 'new.txt', 'nano'); const command = getDiffCommand('old.txt', 'new.txt', 'foobar');
expect(command).toBeNull(); expect(command).toBeNull();
}); });
}); });

View File

@ -6,7 +6,7 @@
import { execSync, spawn } from 'child_process'; import { execSync, spawn } from 'child_process';
type EditorType = 'vscode' | 'vim'; export type EditorType = 'vscode' | 'windsurf' | 'cursor' | 'vim';
interface DiffCommand { interface DiffCommand {
command: string; command: string;
@ -25,15 +25,18 @@ function commandExists(cmd: string): boolean {
} }
} }
const editorCommands: Record<EditorType, { win32: string; default: string }> = {
vscode: { win32: 'code.cmd', default: 'code' },
windsurf: { win32: 'windsurf', default: 'windsurf' },
cursor: { win32: 'cursor', default: 'cursor' },
vim: { win32: 'vim', default: 'vim' },
};
export function checkHasEditor(editor: EditorType): boolean { export function checkHasEditor(editor: EditorType): boolean {
if (editor === 'vscode') { const commandConfig = editorCommands[editor];
return process.platform === 'win32' const command =
? commandExists('code.cmd') process.platform === 'win32' ? commandConfig.win32 : commandConfig.default;
: commandExists('code'); return commandExists(command);
} else if (editor === 'vim') {
return commandExists('vim');
}
return false;
} }
/** /**
@ -50,6 +53,16 @@ export function getDiffCommand(
command: 'code', command: 'code',
args: ['--wait', '--diff', oldPath, newPath], args: ['--wait', '--diff', oldPath, newPath],
}; };
case 'windsurf':
return {
command: 'windsurf',
args: ['--wait', '--diff', oldPath, newPath],
};
case 'cursor':
return {
command: 'cursor',
args: ['--wait', '--diff', oldPath, newPath],
};
case 'vim': case 'vim':
return { return {
command: 'vim', command: 'vim',