@@ -126,10 +126,6 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
126
126
// Immutable window state
127
127
protected readonly _osBackend : Promise < OperatingSystem > ;
128
128
129
- // HACK: Per-tool call state, saved globally
130
- // TODO: These should not be part of the state as different sessions could get confused https://github.com/microsoft/vscode/issues/255889
131
- private _alternativeRecommendation ?: IToolResult ;
132
-
133
129
private static readonly _backgroundExecutions = new Map < string , BackgroundTerminalExecution > ( ) ;
134
130
public static getBackgroundOutput ( id : string ) : string {
135
131
const backgroundExecution = RunInTerminalTool . _backgroundExecutions . get ( id ) ;
@@ -176,8 +172,8 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
176
172
async prepareToolInvocation ( context : IToolInvocationPreparationContext , token : CancellationToken ) : Promise < IPreparedToolInvocation | undefined > {
177
173
const args = context . parameters as IRunInTerminalInputParams ;
178
174
179
- this . _alternativeRecommendation = getRecommendedToolsOverRunInTerminal ( args . command , this . _languageModelToolsService ) ;
180
- const presentation = this . _alternativeRecommendation ? 'hidden' : undefined ;
175
+ const alternativeRecommendation = getRecommendedToolsOverRunInTerminal ( args . command , this . _languageModelToolsService ) ;
176
+ const presentation = alternativeRecommendation ? 'hidden' : undefined ;
181
177
182
178
const os = await this . _osBackend ;
183
179
const shell = await this . _terminalProfileResolverService . getDefaultShell ( {
@@ -193,7 +189,7 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
193
189
}
194
190
195
191
let confirmationMessages : IToolConfirmationMessages | undefined ;
196
- if ( this . _alternativeRecommendation ) {
192
+ if ( alternativeRecommendation ) {
197
193
confirmationMessages = undefined ;
198
194
} else {
199
195
const actualCommand = toolEditedCommand ?? args . command ;
@@ -250,23 +246,27 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
250
246
toolEdited : toolEditedCommand
251
247
} ,
252
248
language,
249
+ alternativeRecommendation,
253
250
}
254
251
} ;
255
252
}
256
253
257
254
async invoke ( invocation : IToolInvocation , _countTokens : CountTokensCallback , _progress : ToolProgress , token : CancellationToken ) : Promise < IToolResult > {
258
- if ( this . _alternativeRecommendation ) {
259
- return this . _alternativeRecommendation ;
260
- }
261
-
262
- const args = invocation . parameters as IRunInTerminalInputParams ;
263
-
264
- this . _logService . debug ( `RunInTerminalTool: Invoking with options ${ JSON . stringify ( args ) } ` ) ;
265
-
266
255
const toolSpecificData = invocation . toolSpecificData as IChatTerminalToolInvocationData | undefined ;
267
256
if ( ! toolSpecificData ) {
268
257
throw new Error ( 'toolSpecificData must be provided for this tool' ) ;
269
258
}
259
+ if ( toolSpecificData . alternativeRecommendation ) {
260
+ return {
261
+ content : [ {
262
+ kind : 'text' ,
263
+ value : toolSpecificData . alternativeRecommendation
264
+ } ]
265
+ } ;
266
+ }
267
+
268
+ const args = invocation . parameters as IRunInTerminalInputParams ;
269
+ this . _logService . debug ( `RunInTerminalTool: Invoking with options ${ JSON . stringify ( args ) } ` ) ;
270
270
let toolResultMessage : string | IMarkdownString | undefined ;
271
271
272
272
const chatSessionId = invocation . context ?. sessionId ?? 'no-chat-session' ;
0 commit comments