Skip to content

Commit 0985612

Browse files
committed
Fix response element ordering for consistency across all cases
1 parent 39a28ea commit 0985612

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

PowerShell.MCP.Proxy/Tools/PowerShellTools.cs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,17 @@ public static async Task<string> GetCurrentLocation(
213213
// Collect completed outputs and busy status info from other pipes
214214
var (completedOutputs, busyStatusInfo) = await CollectAllCachedOutputsAsync(powerShellService, readyPipeName, cancellationToken);
215215

216-
// Build response: completed outputs + busyStatusInfo + result
216+
// Build response: busyStatusInfo + completedOutputs + result
217217
var response = new StringBuilder();
218-
if (completedOutputs.Length > 0)
219-
{
220-
response.AppendLine(completedOutputs);
221-
response.AppendLine();
222-
}
223218
if (busyStatusInfo.Length > 0)
224219
{
225220
response.Append(busyStatusInfo);
226221
response.AppendLine();
227222
}
223+
if (completedOutputs.Length > 0)
224+
{
225+
response.Append(completedOutputs);
226+
}
228227
response.Append(result);
229228
return response.ToString();
230229
}
@@ -470,12 +469,23 @@ public static async Task<string> InvokeExpression(
470469

471470
case "completed":
472471
// Result was cached - return status
472+
// Collect busy status from other pipes
473+
var (cachedCompletedOutput, cachedBusyStatusInfo) = await CollectAllCachedOutputsAsync(powerShellService, readyPipeName, cancellationToken);
474+
473475
var cachedResponse = new StringBuilder();
476+
if (cachedBusyStatusInfo.Length > 0)
477+
{
478+
cachedResponse.Append(cachedBusyStatusInfo);
479+
}
474480
if (!string.IsNullOrEmpty(allPipesStatusInfo))
475481
{
476482
cachedResponse.AppendLine(allPipesStatusInfo);
477483
cachedResponse.AppendLine();
478484
}
485+
if (cachedCompletedOutput.Length > 0)
486+
{
487+
cachedResponse.Append(cachedCompletedOutput);
488+
}
479489
cachedResponse.AppendLine($"✓ Pipeline executed successfully | pwsh PID: {jsonResponse.Pid} | Status: Completed | Pipeline: {jsonResponse.Pipeline} | Duration: {jsonResponse.Duration:F2}s");
480490
cachedResponse.AppendLine();
481491
cachedResponse.Append("Result cached. Will be returned on next tool call.");
@@ -494,15 +504,16 @@ public static async Task<string> InvokeExpression(
494504
{
495505
successResponse.AppendLine(allPipesStatusInfo);
496506
}
497-
if (!string.IsNullOrEmpty(scopeWarning))
498-
{
499-
successResponse.AppendLine(scopeWarning);
500-
}
501507
if (completedOutput.Length > 0)
502508
{
503509
successResponse.Append(completedOutput);
504510
}
505-
if (successResponse.Length > 0)
511+
if (!string.IsNullOrEmpty(scopeWarning))
512+
{
513+
successResponse.AppendLine(scopeWarning);
514+
successResponse.AppendLine();
515+
}
516+
if (successResponse.Length > 0 && string.IsNullOrEmpty(scopeWarning))
506517
{
507518
successResponse.AppendLine();
508519
}
@@ -724,20 +735,22 @@ public static async Task<string> StartPowershellConsole(
724735
var newPipeName = sessionManager.ActivePipeName;
725736
var (completedOutput, busyStatusInfo) = await CollectAllCachedOutputsAsync(powerShellService, newPipeName, cancellationToken);
726737

727-
// Build response: busy status first + completed output + start message + location
738+
// Build response: busy status first + start message + location + completed output
728739
var response = new StringBuilder();
729740
if (busyStatusInfo.Length > 0)
730741
{
731742
response.Append(busyStatusInfo);
732743
response.AppendLine();
733744
}
745+
response.AppendLine("PowerShell console started successfully with PowerShell.MCP module imported.");
746+
response.AppendLine();
747+
response.Append(locationResult);
734748
if (completedOutput.Length > 0)
735749
{
750+
response.AppendLine();
751+
response.AppendLine();
736752
response.Append(completedOutput);
737753
}
738-
response.AppendLine("PowerShell console started successfully with PowerShell.MCP module imported.");
739-
response.AppendLine();
740-
response.Append(locationResult);
741754
return response.ToString();
742755
}
743756

0 commit comments

Comments
 (0)