fix: launch presets wait for shell prompt before sending command
All checks were successful
Build & Sign Wraith / Build Windows + Sign (push) Successful in 3m3s

Was sending the command after a blind 300ms delay with \n — too early
for PowerShell startup banner, and \n caused a blank line before the
command.

Fix: poll mcp_terminal_read every 200ms until a prompt is detected
($, #, %, >, PS>), then send the command with \r (carriage return,
not newline). Falls back to sending after 5s timeout.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vantz Stockwell 2026-03-25 00:37:35 -04:00
parent c507c515ef
commit f9c4e2af35

View File

@ -156,11 +156,30 @@ async function launchPreset(preset: LaunchPreset): Promise<void> {
if (!shell) return; if (!shell) return;
selectedShell.value = shell; selectedShell.value = shell;
await launch(); await launch();
// After shell spawns, send the preset command // Wait for the shell prompt before sending the command.
// Poll the scrollback for a prompt indicator (PS>, $, #, %, >)
if (sessionId && connected.value) { if (sessionId && connected.value) {
setTimeout(() => { const maxWait = 5000;
invoke("pty_write", { sessionId, data: preset.command + "\n" }).catch(() => {}); const start = Date.now();
}, 300); const poll = setInterval(async () => {
if (Date.now() - start > maxWait) {
clearInterval(poll);
// Send anyway after timeout
invoke("pty_write", { sessionId, data: preset.command + "\r" }).catch(() => {});
return;
}
try {
const lines = await invoke<string>("mcp_terminal_read", { sessionId, lines: 3 });
const lastLine = lines.split("\n").pop()?.trim() || "";
// Detect common shell prompts
if (lastLine.endsWith("$") || lastLine.endsWith("#") || lastLine.endsWith("%") || lastLine.endsWith(">") || lastLine.endsWith("PS>")) {
clearInterval(poll);
invoke("pty_write", { sessionId, data: preset.command + "\r" }).catch(() => {});
}
} catch {
// Scrollback not ready yet, keep polling
}
}, 200);
} }
} }