@@ -22,13 +22,12 @@ import { ITerminalLogService } from '../../../../../../platform/terminal/common/
22
22
import { IWorkspaceContextService } from '../../../../../../platform/workspace/common/workspace.js' ;
23
23
import { IRemoteAgentService } from '../../../../../services/remote/common/remoteAgentService.js' ;
24
24
import { IChatService , type IChatTerminalToolInvocationData } from '../../../../chat/common/chatService.js' ;
25
- import { ILanguageModelsService } from '../../../../chat/common/languageModels.js' ;
26
25
import { CountTokensCallback , ILanguageModelToolsService , IPreparedToolInvocation , IToolData , IToolImpl , IToolInvocation , IToolInvocationPreparationContext , IToolResult , ToolDataSource , ToolProgress , type IToolConfirmationAction , type IToolConfirmationMessages } from '../../../../chat/common/languageModelToolsService.js' ;
27
26
import { ITerminalService , type ITerminalInstance } from '../../../../terminal/browser/terminal.js' ;
28
27
import type { XtermTerminal } from '../../../../terminal/browser/xterm/xtermTerminal.js' ;
29
28
import { ITerminalProfileResolverService } from '../../../../terminal/common/terminal.js' ;
30
29
import { getRecommendedToolsOverRunInTerminal } from '../alternativeRecommendation.js' ;
31
- import { getOutput , pollForOutputAndIdle , promptForMorePolling , racePollingOrPrompt } from '../bufferOutputPolling.js' ;
30
+ import { getOutput } from '../bufferOutputPolling.js' ;
32
31
import { CommandLineAutoApprover , type ICommandApprovalResultWithReason } from '../commandLineAutoApprover.js' ;
33
32
import { BasicExecuteStrategy } from '../executeStrategy/basicExecuteStrategy.js' ;
34
33
import type { ITerminalExecuteStrategy } from '../executeStrategy/executeStrategy.js' ;
@@ -38,6 +37,7 @@ import { isPowerShell } from '../runInTerminalHelpers.js';
38
37
import { extractInlineSubCommands , splitCommandLineIntoSubCommands } from '../subCommands.js' ;
39
38
import { ShellIntegrationQuality , ToolTerminalCreator , type IToolTerminal } from '../toolTerminalCreator.js' ;
40
39
import { Codicon } from '../../../../../../base/common/codicons.js' ;
40
+ import { OutputMonitor } from '../outputMonitor.js' ;
41
41
import type { TerminalNewAutoApproveButtonData } from '../../../../chat/browser/chatContentParts/toolInvocationParts/chatTerminalToolSubPart.js' ;
42
42
43
43
const TERMINAL_SESSION_STORAGE_KEY = 'chat.terminalSessions' ;
@@ -159,7 +159,6 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
159
159
@IRemoteAgentService private readonly _remoteAgentService : IRemoteAgentService ,
160
160
@IChatService private readonly _chatService : IChatService ,
161
161
@IWorkspaceContextService private readonly _workspaceContextService : IWorkspaceContextService ,
162
- @ILanguageModelsService private readonly _languageModelsService : ILanguageModelsService
163
162
) {
164
163
super ( ) ;
165
164
@@ -414,31 +413,21 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
414
413
415
414
if ( args . isBackground ) {
416
415
let outputAndIdle : { terminalExecutionIdleBeforeTimeout : boolean ; output : string ; pollDurationMs ?: number ; modelOutputEvalResponse ?: string } | undefined = undefined ;
416
+ let outputMonitor : OutputMonitor | undefined = undefined ;
417
417
try {
418
418
this . _logService . debug ( `RunInTerminalTool: Starting background execution \`${ command } \`` ) ;
419
419
420
420
const execution = new BackgroundTerminalExecution ( toolTerminal . instance , xterm , command ) ;
421
421
RunInTerminalTool . _backgroundExecutions . set ( termId , execution ) ;
422
422
423
- outputAndIdle = await pollForOutputAndIdle ( execution , false , token , this . _languageModelsService ) ;
423
+ outputMonitor = this . _instantiationService . createInstance ( OutputMonitor , execution ) ;
424
+ store . add ( outputMonitor ) ;
425
+
426
+ outputAndIdle = await outputMonitor . startMonitoring ( this . _chatService , command , invocation . context ! , token ) ;
424
427
if ( token . isCancellationRequested ) {
425
428
throw new CancellationError ( ) ;
426
429
}
427
430
428
- if ( ! outputAndIdle . terminalExecutionIdleBeforeTimeout ) {
429
- outputAndIdle = await racePollingOrPrompt (
430
- ( ) => pollForOutputAndIdle ( execution , true , token , this . _languageModelsService ) ,
431
- ( ) => promptForMorePolling ( command , token , invocation . context ! , this . _chatService ) ,
432
- outputAndIdle ,
433
- token ,
434
- this . _languageModelsService ,
435
- execution
436
- ) ;
437
- if ( token . isCancellationRequested ) {
438
- throw new CancellationError ( ) ;
439
- }
440
- }
441
-
442
431
let resultText = (
443
432
didUserEditCommand
444
433
? `Note: The user manually edited the command to \`${ command } \`, and that command is now running in terminal with ID=${ termId } `
0 commit comments