fix(ssh): remove remote mcp config via trap when the tile kills ssh

This commit is contained in:
mika kuns
2026-10-02 15:30:12 +02:00
parent 4b1f5c65c3
commit b35755e1f0
2 changed files with 4 additions and 3 deletions
@@ -336,10 +336,11 @@ public sealed class InteractiveLaunchSpecService
// No double quotes anywhere: ConPTY flattens Args into one Windows command line. // No double quotes anywhere: ConPTY flattens Args into one Windows command line.
// ssh runs a non-interactive shell whose .bashrc bails early, so the native installer's ~/.local/bin is added by hand. // ssh runs a non-interactive shell whose .bashrc bails early, so the native installer's ~/.local/bin is added by hand.
// Closing the tile kills ssh → remote shell gets SIGHUP; a trailing "; rm -f" never runs, the trap does.
var remote = var remote =
$"export PATH=$HOME/.local/bin:$PATH && umask 077 && mkdir -p ~/.claudedo && echo {b64} | base64 -d > {cfgFile}" + $"export PATH=$HOME/.local/bin:$PATH && trap 'rm -f {cfgFile}' EXIT HUP TERM && umask 077 && mkdir -p ~/.claudedo && echo {b64} | base64 -d > {cfgFile}" +
$" && cd {SshWorkspace.QuoteRemotePath(ws.RemotePath)}" + $" && cd {SshWorkspace.QuoteRemotePath(ws.RemotePath)}" +
$" && MCP_TOOL_TIMEOUT={McpToolTimeoutMs} claude --mcp-config {cfgFile}; rm -f {cfgFile}"; $" && MCP_TOOL_TIMEOUT={McpToolTimeoutMs} claude --mcp-config {cfgFile}";
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
return new LaunchSpec(home, ssh, return new LaunchSpec(home, ssh,
@@ -1692,7 +1692,7 @@ public sealed class InteractiveLaunchSpecServiceTests : IDisposable
Assert.StartsWith("export PATH=$HOME/.local/bin:$PATH && ", remote); Assert.StartsWith("export PATH=$HOME/.local/bin:$PATH && ", remote);
Assert.Contains("cd ~/'app'", remote); Assert.Contains("cd ~/'app'", remote);
Assert.Contains($"MCP_TOOL_TIMEOUT={InteractiveLaunchSpecService.McpToolTimeoutMs} claude --mcp-config ~/.claudedo/mcp-{paneId}.json", remote); Assert.Contains($"MCP_TOOL_TIMEOUT={InteractiveLaunchSpecService.McpToolTimeoutMs} claude --mcp-config ~/.claudedo/mcp-{paneId}.json", remote);
Assert.EndsWith($"rm -f ~/.claudedo/mcp-{paneId}.json", remote); Assert.Contains($"trap 'rm -f ~/.claudedo/mcp-{paneId}.json' EXIT HUP TERM && ", remote);
var b64 = System.Text.RegularExpressions.Regex.Match(remote, @"echo ([A-Za-z0-9+/=]+) \| base64 -d").Groups[1].Value; var b64 = System.Text.RegularExpressions.Regex.Match(remote, @"echo ([A-Za-z0-9+/=]+) \| base64 -d").Groups[1].Value;
using var json = System.Text.Json.JsonDocument.Parse(Convert.FromBase64String(b64)); using var json = System.Text.Json.JsonDocument.Parse(Convert.FromBase64String(b64));