33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { Disposable , MutableDisposable } from '../../../../../../base/common/lifecycle.js' ;
6+ import { Disposable , DisposableStore , MutableDisposable } from '../../../../../../base/common/lifecycle.js' ;
77import { localize } from '../../../../../../nls.js' ;
8- import { IAgentHostService } from '../../../../../../platform/agentHost/common/agentService.js' ;
8+ import { AgentHostEnabledSettingId , IAgentHostService } from '../../../../../../platform/agentHost/common/agentService.js' ;
9+ import { IConfigurationService } from '../../../../../../platform/configuration/common/configuration.js' ;
910import { IInstantiationService } from '../../../../../../platform/instantiation/common/instantiation.js' ;
1011import { IWorkbenchContribution } from '../../../../../../workbench/common/contributions.js' ;
1112import { LoggingAgentConnection } from '../../../../../../workbench/contrib/chat/browser/agentSessions/agentHost/loggingAgentConnection.js' ;
@@ -14,22 +15,45 @@ import { IAgentHostTerminalService } from '../../../../../../workbench/contrib/t
1415/**
1516 * Registers local agent host terminal entries with
1617 * {@link IAgentHostTerminalService} so they appear in the terminal dropdown.
18+ *
19+ * Gated on the `chat.agentHost.enabled` setting.
1720 */
1821export class AgentHostTerminalContribution extends Disposable implements IWorkbenchContribution {
1922 static readonly ID = 'workbench.contrib.agentHostTerminal' ;
2023
2124 private readonly _localEntry = this . _register ( new MutableDisposable ( ) ) ;
25+ private readonly _conditionalListeners = this . _register ( new MutableDisposable < DisposableStore > ( ) ) ;
2226
2327 constructor (
2428 @IAgentHostService private readonly _agentHostService : IAgentHostService ,
2529 @IAgentHostTerminalService private readonly _agentHostTerminalService : IAgentHostTerminalService ,
2630 @IInstantiationService private readonly _instantiationService : IInstantiationService ,
31+ @IConfigurationService private readonly _configurationService : IConfigurationService ,
2732 ) {
2833 super ( ) ;
2934
30- this . _register ( this . _agentHostService . onAgentHostStart ( ( ) => this . _reconcile ( ) ) ) ;
31- this . _register ( this . _agentHostService . onAgentHostExit ( ( ) => this . _reconcile ( ) ) ) ;
32- this . _reconcile ( ) ;
35+ this . _register ( this . _configurationService . onDidChangeConfiguration ( e => {
36+ if ( e . affectsConfiguration ( AgentHostEnabledSettingId ) ) {
37+ this . _updateEnabled ( ) ;
38+ }
39+ } ) ) ;
40+
41+ this . _updateEnabled ( ) ;
42+ }
43+
44+ private _updateEnabled ( ) : void {
45+ if ( this . _configurationService . getValue < boolean > ( AgentHostEnabledSettingId ) ) {
46+ if ( ! this . _conditionalListeners . value ) {
47+ const store = new DisposableStore ( ) ;
48+ store . add ( this . _agentHostService . onAgentHostStart ( ( ) => this . _reconcile ( ) ) ) ;
49+ store . add ( this . _agentHostService . onAgentHostExit ( ( ) => this . _reconcile ( ) ) ) ;
50+ this . _conditionalListeners . value = store ;
51+ this . _reconcile ( ) ;
52+ }
53+ } else {
54+ this . _conditionalListeners . value = undefined ;
55+ this . _localEntry . value = undefined ;
56+ }
3357 }
3458
3559 private _reconcile ( ) : void {
0 commit comments