fix: launch presets wait for shell prompt before sending command
All checks were successful
Build & Sign Wraith / Build Windows + Sign (push) Successful in 3m3s
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:
parent
c507c515ef
commit
f9c4e2af35
@ -156,11 +156,30 @@ async function launchPreset(preset: LaunchPreset): Promise<void> {
|
||||
if (!shell) return;
|
||||
selectedShell.value = shell;
|
||||
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) {
|
||||
setTimeout(() => {
|
||||
invoke("pty_write", { sessionId, data: preset.command + "\n" }).catch(() => {});
|
||||
}, 300);
|
||||
const maxWait = 5000;
|
||||
const start = Date.now();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user