diff --git a/DevProxy.Abstractions/Proxy/ProxyEvents.cs b/DevProxy.Abstractions/Proxy/ProxyEvents.cs index a69c2834..249685cd 100644 --- a/DevProxy.Abstractions/Proxy/ProxyEvents.cs +++ b/DevProxy.Abstractions/Proxy/ProxyEvents.cs @@ -45,6 +45,13 @@ public class ProxyResponseArgs(SessionEventArgs session, ResponseState responseS public class InitArgs { public required IServiceProvider ServiceProvider { get; init; } + /// + /// Indicates whether the proxy command (root command) is being invoked. + /// When false, a CLI subcommand is being executed and plugins should + /// skip initialization that is only relevant for proxy operation + /// (e.g., opening browsers, starting listeners). + /// + public bool IsProxyCommand { get; init; } = true; } public class OptionsLoadedArgs(ParseResult parseResult) diff --git a/DevProxy.Plugins/Inspection/DevToolsPlugin.cs b/DevProxy.Plugins/Inspection/DevToolsPlugin.cs index 0cf6cd44..7e270648 100644 --- a/DevProxy.Plugins/Inspection/DevToolsPlugin.cs +++ b/DevProxy.Plugins/Inspection/DevToolsPlugin.cs @@ -78,10 +78,17 @@ public sealed class DevToolsPlugin( public override async Task InitializeAsync(InitArgs e, CancellationToken cancellationToken) { + ArgumentNullException.ThrowIfNull(e); + _cancellationToken = cancellationToken; await base.InitializeAsync(e, cancellationToken); + if (!e.IsProxyCommand) + { + return; + } + InitInspector(); } diff --git a/DevProxy.Plugins/Inspection/OpenAITelemetryPlugin.cs b/DevProxy.Plugins/Inspection/OpenAITelemetryPlugin.cs index c9eb1351..8e9ff527 100644 --- a/DevProxy.Plugins/Inspection/OpenAITelemetryPlugin.cs +++ b/DevProxy.Plugins/Inspection/OpenAITelemetryPlugin.cs @@ -76,6 +76,11 @@ public override async Task InitializeAsync(InitArgs e, CancellationToken cancell await base.InitializeAsync(e, cancellationToken); + if (!e.IsProxyCommand) + { + return; + } + if (Configuration.IncludeCosts) { Configuration.PricesFile = ProxyUtils.GetFullPath(Configuration.PricesFile, ProxyConfiguration.ConfigFile); diff --git a/DevProxy/Plugins/PluginServiceExtensions.cs b/DevProxy/Plugins/PluginServiceExtensions.cs index 12afa104..90f48b23 100644 --- a/DevProxy/Plugins/PluginServiceExtensions.cs +++ b/DevProxy/Plugins/PluginServiceExtensions.cs @@ -181,7 +181,7 @@ private static void RegisterPlugin( // stage is synchronous, but if the implementation changes // in the future then we won't need to change the interface #pragma warning disable VSTHRD002 - plugin.InitializeAsync(new() { ServiceProvider = sp }, CancellationToken.None).Wait(); + plugin.InitializeAsync(new() { ServiceProvider = sp, IsProxyCommand = DevProxyCommand.IsRootCommand }, CancellationToken.None).Wait(); #pragma warning restore VSTHRD002 return plugin; }); @@ -200,7 +200,7 @@ private static void RegisterPlugin( // stage is synchronous, but if the implementation changes // in the future then we won't need to change the interface #pragma warning disable VSTHRD002 - plugin.InitializeAsync(new() { ServiceProvider = sp }, CancellationToken.None).Wait(); + plugin.InitializeAsync(new() { ServiceProvider = sp, IsProxyCommand = DevProxyCommand.IsRootCommand }, CancellationToken.None).Wait(); #pragma warning restore VSTHRD002 return plugin; });