wait for terminal ready after running each setup comand
This commit is contained in:
parent
8b18f47902
commit
2d97d3171a
56
main.ts
56
main.ts
|
|
@ -22,6 +22,33 @@ function getPersistedSessions(): PersistedSession[] {
|
|||
return (store as any).get("sessions", []);
|
||||
}
|
||||
|
||||
function isTerminalReady(buffer: string, startPos: number = 0): boolean {
|
||||
const searchBuffer = buffer.slice(startPos);
|
||||
const promptSymbols = ["$ ", "% ", "> ", "➜ ", "➜ ", "✗ ", "✓ "];
|
||||
const endSymbols = ["$", "%", ">", "➜", "✗", "✓"];
|
||||
|
||||
// Check for bracketed paste mode
|
||||
if (searchBuffer.includes("\x1b[?2004h")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for prompt symbols
|
||||
for (const symbol of promptSymbols) {
|
||||
if (searchBuffer.includes(symbol)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for end symbols
|
||||
for (const symbol of endSymbols) {
|
||||
if (searchBuffer.endsWith(symbol)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function savePersistedSessions(sessions: PersistedSession[]) {
|
||||
(store as any).set("sessions", sessions);
|
||||
}
|
||||
|
|
@ -220,6 +247,9 @@ function spawnSessionPty(
|
|||
activePtyProcesses.set(sessionId, ptyProcess);
|
||||
|
||||
let terminalReady = false;
|
||||
let readyChecksCompleted = 0;
|
||||
let lastReadyCheckPos = 0;
|
||||
let setupCommandsIdx = 0;
|
||||
let dataBuffer = "";
|
||||
|
||||
ptyProcess.onData((data) => {
|
||||
|
|
@ -232,27 +262,16 @@ function spawnSessionPty(
|
|||
if (!terminalReady) {
|
||||
dataBuffer += data;
|
||||
|
||||
// Method 1: Look for bracketed paste mode enable sequence
|
||||
// Method 2: Fallback - look for common prompt indicators
|
||||
const isReady = dataBuffer.includes("\x1b[?2004h") ||
|
||||
dataBuffer.includes("$ ") || dataBuffer.includes("% ") ||
|
||||
dataBuffer.includes("> ") || dataBuffer.includes("➜ ") ||
|
||||
dataBuffer.includes("➜ ") || dataBuffer.includes("✗ ") ||
|
||||
dataBuffer.includes("✓ ") || dataBuffer.endsWith("$") ||
|
||||
dataBuffer.endsWith("%") || dataBuffer.endsWith(">") ||
|
||||
dataBuffer.endsWith("➜") || dataBuffer.endsWith("✗") ||
|
||||
dataBuffer.endsWith("✓");
|
||||
if (isTerminalReady(dataBuffer, lastReadyCheckPos)) {
|
||||
readyChecksCompleted++;
|
||||
lastReadyCheckPos = dataBuffer.length;
|
||||
|
||||
if (isReady) {
|
||||
if (config.setupCommands && setupCommandsIdx < config.setupCommands.length) {
|
||||
ptyProcess.write(config.setupCommands[setupCommandsIdx] + "\r");
|
||||
setupCommandsIdx++;
|
||||
} else {
|
||||
terminalReady = true;
|
||||
|
||||
// Run setup commands if provided
|
||||
if (config.setupCommands && config.setupCommands.length > 0) {
|
||||
config.setupCommands.forEach(cmd => {
|
||||
ptyProcess.write(cmd + "\r");
|
||||
});
|
||||
}
|
||||
|
||||
// Auto-run the selected coding agent
|
||||
if (config.codingAgent === "claude") {
|
||||
const sessionFlag = isNewSession
|
||||
|
|
@ -273,6 +292,7 @@ function spawnSessionPty(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return ptyProcess;
|
||||
|
|
|
|||
Loading…
Reference in a new issue