Skip to content

Commit 545cb2a

Browse files
authored
Support thinking in cli integration (#1350)
* Support thinking in cli integration * use CopilotCLIToolNames enum.
1 parent 841a738 commit 545cb2a

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

src/extension/agents/copilotcli/node/copilotcliAgentManager.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import { IWorkspaceService } from '../../../../platform/workspace/common/workspa
1313
import { CancellationToken } from '../../../../util/vs/base/common/cancellation';
1414
import { Disposable } from '../../../../util/vs/base/common/lifecycle';
1515
import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation';
16-
import { LanguageModelTextPart } from '../../../../vscodeTypes';
16+
import { ChatResponseThinkingProgressPart, LanguageModelTextPart } from '../../../../vscodeTypes';
1717
import { ToolName } from '../../../tools/common/toolNames';
1818
import { IToolsService } from '../../../tools/common/toolsService';
1919
import { ICopilotCLISessionService } from './copilotcliSessionService';
20-
import { createCopilotCLIToolInvocation, PermissionRequest } from './copilotcliToolInvocationFormatter';
20+
import { CopilotCLIToolNames, createCopilotCLIToolInvocation, PermissionRequest } from './copilotcliToolInvocationFormatter';
2121
import { ensureNodePtyShim } from './nodePtyShim';
2222

2323
export class CopilotCLIAgentManager extends Disposable {
@@ -187,6 +187,15 @@ export class CopilotCLISession extends Disposable {
187187
}
188188
case 'tool_result': {
189189
const toolCallId = event.toolCallId;
190+
191+
if (event.toolName === CopilotCLIToolNames.Think) {
192+
const sessionLog = event.result.sessionLog;
193+
if (sessionLog && typeof sessionLog === 'string') {
194+
stream.push(new ChatResponseThinkingProgressPart(sessionLog));
195+
}
196+
break;
197+
}
198+
190199
let invocation = toolCallId ? this._pendingToolInvocations.get(toolCallId) : undefined;
191200

192201
if (!invocation) {

src/extension/agents/copilotcli/node/copilotcliToolInvocationFormatter.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import * as l10n from '@vscode/l10n';
88
import type { ChatCompletionMessageParam } from 'openai/resources/chat/completions';
99
import type { ExtendedChatResponsePart } from 'vscode';
1010
import { URI } from '../../../../util/vs/base/common/uri';
11-
import { ChatRequestTurn2, ChatResponseMarkdownPart, ChatResponseTurn2, ChatToolInvocationPart, MarkdownString } from '../../../../vscodeTypes';
11+
import { ChatRequestTurn2, ChatResponseMarkdownPart, ChatResponseThinkingProgressPart, ChatResponseTurn2, ChatToolInvocationPart, MarkdownString } from '../../../../vscodeTypes';
1212

1313
/**
1414
* CopilotCLI tool names
1515
*/
16-
const enum CopilotCLIToolNames {
16+
export const enum CopilotCLIToolNames {
1717
StrReplaceEditor = 'str_replace_editor',
18-
Bash = 'bash'
18+
Bash = 'bash',
19+
Think = 'think'
1920
}
2021

2122
interface StrReplaceEditorArgs {
@@ -145,13 +146,22 @@ export function buildChatHistoryFromEvents(events: readonly SDKEvent[]): (ChatRe
145146
currentResponseParts.push(toolInvocation);
146147
}
147148
} else if (event.type === 'tool_result') {
148-
// Update the pending tool invocation with the result
149-
if (event.toolCallId) {
150-
const invocation = pendingToolInvocations.get(event.toolCallId);
151-
if (invocation) {
152-
invocation.isConfirmed = event.result.resultType !== 'rejected' && event.result.resultType !== 'denied';
153-
invocation.isError = event.result.resultType === 'failure';
154-
pendingToolInvocations.delete(event.toolCallId);
149+
if (event.toolName === CopilotCLIToolNames.Think) {
150+
const sessionLog = event.result.sessionLog;
151+
if (sessionLog && typeof sessionLog === 'string') {
152+
currentResponseParts.push(
153+
new ChatResponseThinkingProgressPart(sessionLog)
154+
);
155+
}
156+
} else {
157+
// Update the pending tool invocation with the result
158+
if (event.toolCallId) {
159+
const invocation = pendingToolInvocations.get(event.toolCallId);
160+
if (invocation) {
161+
invocation.isConfirmed = event.result.resultType !== 'rejected' && event.result.resultType !== 'denied';
162+
invocation.isError = event.result.resultType === 'failure';
163+
pendingToolInvocations.delete(event.toolCallId);
164+
}
155165
}
156166
}
157167
// Tool results themselves are not displayed - they update the invocation state

0 commit comments

Comments
 (0)