@@ -14,13 +14,13 @@ public class PowerShellTools
1414 /// <summary>
1515 /// Finds a ready pipe. Delegates to PipeDiscoveryService.
1616 /// </summary>
17- private static async Task < ( string ? readyPipeName , bool consoleSwitched , string ? allPipesStatusInfo ) > FindReadyPipeAsync (
17+ private static async Task < ( string ? readyPipeName , bool consoleSwitched , IReadOnlyList < string > closedConsoleMessages , string ? allPipesStatusInfo ) > FindReadyPipeAsync (
1818 IPipeDiscoveryService pipeDiscoveryService ,
1919 string agentId ,
2020 CancellationToken cancellationToken )
2121 {
2222 var result = await pipeDiscoveryService . FindReadyPipeAsync ( agentId , cancellationToken ) ;
23- return ( result . ReadyPipeName , result . ConsoleSwitched , result . AllPipesStatusInfo ) ;
23+ return ( result . ReadyPipeName , result . ConsoleSwitched , result . ClosedConsoleMessages , result . AllPipesStatusInfo ) ;
2424 }
2525
2626 private static string FormatBusyStatus ( GetStatusResponse status )
@@ -97,7 +97,7 @@ public static async Task<string> GetCurrentLocation(
9797 return error ;
9898
9999 // Find a ready pipe
100- var ( readyPipeName , _, allPipesStatusInfo ) = await FindReadyPipeAsync ( pipeDiscoveryService , agentId , cancellationToken ) ;
100+ var ( readyPipeName , _, closedConsoleMessages , allPipesStatusInfo ) = await FindReadyPipeAsync ( pipeDiscoveryService , agentId , cancellationToken ) ;
101101
102102 if ( readyPipeName == null )
103103 {
@@ -114,8 +114,13 @@ public static async Task<string> GetCurrentLocation(
114114 // Collect completed outputs and busy status info from other pipes
115115 var ( completedOutputs , busyStatusInfo ) = await CollectAllCachedOutputsAsync ( pipeDiscoveryService , agentId , readyPipeName , cancellationToken ) ;
116116
117- // Build response: busyStatusInfo + completedOutputs + agentId info + result
117+ // Build response: closedConsoles + busyStatusInfo + completedOutputs + agentId info + result
118118 var response = new StringBuilder ( ) ;
119+ if ( closedConsoleMessages . Count > 0 )
120+ {
121+ response . AppendLine ( string . Join ( "\n " , closedConsoleMessages ) ) ;
122+ response . AppendLine ( ) ;
123+ }
119124 if ( busyStatusInfo . Length > 0 )
120125 {
121126 response . Append ( busyStatusInfo ) ;
@@ -206,7 +211,7 @@ public static async Task<string> InvokeExpression(
206211
207212 var sessionManager = ConsoleSessionManager . Instance ;
208213 // Find a ready pipe
209- var ( readyPipeName , consoleSwitched , allPipesStatusInfo ) = await FindReadyPipeAsync ( pipeDiscoveryService , agentId , cancellationToken ) ;
214+ var ( readyPipeName , consoleSwitched , closedConsoleMessages , allPipesStatusInfo ) = await FindReadyPipeAsync ( pipeDiscoveryService , agentId , cancellationToken ) ;
210215
211216 if ( readyPipeName == null )
212217 {
@@ -232,8 +237,13 @@ public static async Task<string> InvokeExpression(
232237 // Extract PID from pipe name (format: PSMCP.{PID})
233238 var pid = GetPidString ( newPipeName ) ;
234239
235- // Build response: busy status first + message + location + completedOutputs
240+ // Build response: closedConsoles + busy status first + message + location + completedOutputs
236241 var response = new StringBuilder ( ) ;
242+ if ( closedConsoleMessages . Count > 0 )
243+ {
244+ response . AppendLine ( string . Join ( "\n " , closedConsoleMessages ) ) ;
245+ response . AppendLine ( ) ;
246+ }
237247 if ( busyStatusInfo . Length > 0 )
238248 {
239249 response . Append ( busyStatusInfo ) ;
@@ -267,8 +277,13 @@ public static async Task<string> InvokeExpression(
267277 // Extract PID from pipe name (format: PSMCP.{PID})
268278 var pid = GetPidString ( readyPipeName ) ;
269279
270- // Build response: busy status first + closedConsoleInfo + message + locationResult + completedOutputs
280+ // Build response: closedConsoles + busy status + message + locationResult + completedOutputs
271281 var response = new StringBuilder ( ) ;
282+ if ( closedConsoleMessages . Count > 0 )
283+ {
284+ response . AppendLine ( string . Join ( "\n " , closedConsoleMessages ) ) ;
285+ response . AppendLine ( ) ;
286+ }
272287 if ( busyStatusInfo . Length > 0 )
273288 {
274289 response . Append ( busyStatusInfo ) ;
@@ -455,6 +470,11 @@ public static async Task<string> InvokeExpression(
455470 }
456471
457472 var successResponse = new StringBuilder ( ) ;
473+ if ( closedConsoleMessages . Count > 0 )
474+ {
475+ successResponse . AppendLine ( string . Join ( "\n " , closedConsoleMessages ) ) ;
476+ successResponse . AppendLine ( ) ;
477+ }
458478 if ( busyStatusInfo . Length > 0 )
459479 {
460480 successResponse . Append ( busyStatusInfo ) ;
0 commit comments