Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/chatSessions/copilotcli/vscode-node/tools/closeDiff.ts
13406 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 type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
7
import { z } from 'zod';
8
import { DiffStateManager } from '../diffState';
9
import { makeTextResult } from './utils';
10
import { ILogger } from '../../../../../platform/log/common/logService';
11
12
export function registerCloseDiffTool(server: McpServer, logger: ILogger, diffState: DiffStateManager): void {
13
const schema = {
14
tab_name: z.string().describe('The tab name of the diff to close (must match the tab_name used when opening the diff)'),
15
};
16
server.registerTool(
17
'close_diff',
18
{
19
description: 'Closes a diff tab by its tab name. Use this when the client rejects an edit to close the corresponding diff view.',
20
inputSchema: schema,
21
},
22
// @ts-ignore - TS2589: zod type instantiation too deep for server.tool() generics
23
async (args: { tab_name: string }) => {
24
const { tab_name } = args;
25
logger.debug(`Closing diff: ${tab_name}`);
26
const diff = diffState.getByTabName(tab_name);
27
28
if (!diff) {
29
logger.debug(`No active diff found with tab name: ${tab_name}`);
30
return makeTextResult({
31
success: true,
32
already_closed: true,
33
tab_name: tab_name,
34
message: `No active diff found with tab name "${tab_name}" (may already be closed)`,
35
});
36
}
37
38
// Trigger the rejection flow which will clean up and close the tab
39
diff.resolve({ status: 'REJECTED', trigger: 'closed_via_tool' });
40
logger.info(`Diff closed via tool: ${tab_name}`);
41
42
return makeTextResult({
43
success: true,
44
already_closed: false,
45
tab_name: tab_name,
46
message: `Diff "${tab_name}" closed successfully`,
47
});
48
}
49
);
50
}
51
52