@@ -10,7 +10,7 @@ import { URI } from '../../../../base/common/uri.js';
1010import * as nls from '../../../../nls.js' ;
1111import { agentHostAuthority } from '../../../../platform/agentHost/common/agentHostUri.js' ;
1212import { type AgentProvider , type IAgentConnection } from '../../../../platform/agentHost/common/agentService.js' ;
13- import { IRemoteAgentHostConnectionInfo , IRemoteAgentHostEntry , IRemoteAgentHostService , RemoteAgentHostConnectionStatus , RemoteAgentHostEntryType , RemoteAgentHostsEnabledSettingId , RemoteAgentHostsSettingId , getEntryAddress } from '../../../../platform/agentHost/common/remoteAgentHostService.js' ;
13+ import { IRemoteAgentHostConnectionInfo , IRemoteAgentHostEntry , IRemoteAgentHostService , RemoteAgentHostAutoConnectSettingId , RemoteAgentHostConnectionStatus , RemoteAgentHostEntryType , RemoteAgentHostsEnabledSettingId , RemoteAgentHostsSettingId , getEntryAddress } from '../../../../platform/agentHost/common/remoteAgentHostService.js' ;
1414import { TunnelAgentHostsSettingId } from '../../../../platform/agentHost/common/tunnelAgentHost.js' ;
1515import { type IProtectedResourceMetadata , type URI as ProtocolURI } from '../../../../platform/agentHost/common/state/protocol/state.js' ;
1616import { type IAgentInfo , type ICustomizationRef , type IRootState } from '../../../../platform/agentHost/common/state/sessionState.js' ;
@@ -102,7 +102,7 @@ export class RemoteAgentHostContribution extends Disposable implements IWorkbenc
102102
103103 // Reconcile providers when configured entries change
104104 this . _register ( this . _configurationService . onDidChangeConfiguration ( e => {
105- if ( e . affectsConfiguration ( RemoteAgentHostsSettingId ) || e . affectsConfiguration ( RemoteAgentHostsEnabledSettingId ) ) {
105+ if ( e . affectsConfiguration ( RemoteAgentHostsSettingId ) || e . affectsConfiguration ( RemoteAgentHostsEnabledSettingId ) || e . affectsConfiguration ( RemoteAgentHostAutoConnectSettingId ) ) {
106106 this . _reconcile ( ) ;
107107 }
108108 } ) ) ;
@@ -194,6 +194,7 @@ export class RemoteAgentHostContribution extends Disposable implements IWorkbenc
194194 * sshConfigHost but no active connection.
195195 */
196196 private _reconnectSSHEntries ( ) : void {
197+ const autoConnect = this . _configurationService . getValue < boolean > ( RemoteAgentHostAutoConnectSettingId ) ;
197198 const entries = this . _remoteAgentHostService . configuredEntries ;
198199 for ( const entry of entries ) {
199200 if ( entry . connection . type !== RemoteAgentHostEntryType . SSH || ! entry . connection . sshConfigHost ) {
@@ -208,6 +209,9 @@ export class RemoteAgentHostContribution extends Disposable implements IWorkbenc
208209 if ( hasConnection || this . _pendingSSHReconnects . has ( sshConfigHost ) ) {
209210 continue ;
210211 }
212+ if ( ! autoConnect ) {
213+ continue ;
214+ }
211215 this . _pendingSSHReconnects . add ( sshConfigHost ) ;
212216 this . _logService . info ( `[RemoteAgentHost] Re-establishing SSH tunnel for ${ sshConfigHost } ` ) ;
213217 this . _sshService . reconnect ( sshConfigHost , entry . name ) . then ( ( ) => {
@@ -216,6 +220,10 @@ export class RemoteAgentHostContribution extends Disposable implements IWorkbenc
216220 } ) . catch ( err => {
217221 this . _pendingSSHReconnects . delete ( sshConfigHost ) ;
218222 this . _logService . error ( `[RemoteAgentHost] SSH reconnect failed for ${ sshConfigHost } ` , err ) ;
223+ // Host is unreachable — unpublish any cached sessions we
224+ // were showing so the UI doesn't list stale entries for a
225+ // host we cannot currently reach.
226+ this . _providerInstances . get ( address ) ?. unpublishCachedSessions ( ) ;
219227 } ) ;
220228 }
221229 }
@@ -590,6 +598,13 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).regis
590598 scope : ConfigurationScope . APPLICATION ,
591599 tags : [ 'experimental' , 'advanced' ] ,
592600 } ,
601+ [ RemoteAgentHostAutoConnectSettingId ] : {
602+ type : 'boolean' ,
603+ description : nls . localize ( 'chat.remoteAgentHosts.autoConnect' , "Automatically connect to online dev tunnel and SSH-configured remote agent hosts on startup. When disabled, cached sessions are still shown but connections are established only on demand." ) ,
604+ default : true ,
605+ scope : ConfigurationScope . APPLICATION ,
606+ tags : [ 'experimental' , 'advanced' ] ,
607+ } ,
593608 'chat.sshRemoteAgentHostCommand' : {
594609 type : 'string' ,
595610 description : nls . localize ( 'chat.sshRemoteAgentHostCommand' , "For development: Override the command used to start the remote agent host over SSH. When set, skips automatic CLI installation and runs this command instead. The command must print a WebSocket URL matching ws://127.0.0.1:PORT (optionally with ?tkn=TOKEN) to stdout or stderr./" ) ,
0 commit comments