Skip to content

Commit 330171a

Browse files
yotsudaclaude
andcommitted
Surface dead console detection in invoke_expression and get_current_location
Previously closedConsoleMessages from PipeDiscoveryService were only reported in wait_for_completion. Now all response paths in invoke_expression and get_current_location include closed console warnings so agents are immediately aware when a console has died. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6ee1497 commit 330171a

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

PowerShell.MCP.Proxy/PowerShell.MCP.Proxy.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8-
<Version>1.7.1.0</Version>
8+
<Version>1.7.2.0</Version>
99
<NoWarn>$(NoWarn);NETSDK1206</NoWarn>
1010

1111
<!-- Single File デプロイ設定 -->

PowerShell.MCP.Proxy/Tools/PowerShellTools.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

PowerShell.MCP/PowerShell.MCP.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>1.7.1.0</Version>
7+
<Version>1.7.2.0</Version>
88
<NoWarn>$(NoWarn);NETSDK1206</NoWarn>
99
</PropertyGroup>
1010

Staging/PowerShell.MCP.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'PowerShell.MCP.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.7.1'
15+
ModuleVersion = '1.7.2'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = @('Core')

0 commit comments

Comments
 (0)