wait for terminal ready after running each setup comand
This commit is contained in:
parent
8b18f47902
commit
2d97d3171a
88
main.ts
88
main.ts
|
|
@ -22,6 +22,33 @@ function getPersistedSessions(): PersistedSession[] {
|
||||||
return (store as any).get("sessions", []);
|
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[]) {
|
function savePersistedSessions(sessions: PersistedSession[]) {
|
||||||
(store as any).set("sessions", sessions);
|
(store as any).set("sessions", sessions);
|
||||||
}
|
}
|
||||||
|
|
@ -220,6 +247,9 @@ function spawnSessionPty(
|
||||||
activePtyProcesses.set(sessionId, ptyProcess);
|
activePtyProcesses.set(sessionId, ptyProcess);
|
||||||
|
|
||||||
let terminalReady = false;
|
let terminalReady = false;
|
||||||
|
let readyChecksCompleted = 0;
|
||||||
|
let lastReadyCheckPos = 0;
|
||||||
|
let setupCommandsIdx = 0;
|
||||||
let dataBuffer = "";
|
let dataBuffer = "";
|
||||||
|
|
||||||
ptyProcess.onData((data) => {
|
ptyProcess.onData((data) => {
|
||||||
|
|
@ -232,44 +262,34 @@ function spawnSessionPty(
|
||||||
if (!terminalReady) {
|
if (!terminalReady) {
|
||||||
dataBuffer += data;
|
dataBuffer += data;
|
||||||
|
|
||||||
// Method 1: Look for bracketed paste mode enable sequence
|
if (isTerminalReady(dataBuffer, lastReadyCheckPos)) {
|
||||||
// Method 2: Fallback - look for common prompt indicators
|
readyChecksCompleted++;
|
||||||
const isReady = dataBuffer.includes("\x1b[?2004h") ||
|
lastReadyCheckPos = dataBuffer.length;
|
||||||
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 (isReady) {
|
if (config.setupCommands && setupCommandsIdx < config.setupCommands.length) {
|
||||||
terminalReady = true;
|
ptyProcess.write(config.setupCommands[setupCommandsIdx] + "\r");
|
||||||
|
setupCommandsIdx++;
|
||||||
|
} else {
|
||||||
|
terminalReady = true;
|
||||||
|
|
||||||
// Run setup commands if provided
|
// Auto-run the selected coding agent
|
||||||
if (config.setupCommands && config.setupCommands.length > 0) {
|
if (config.codingAgent === "claude") {
|
||||||
config.setupCommands.forEach(cmd => {
|
const sessionFlag = isNewSession
|
||||||
ptyProcess.write(cmd + "\r");
|
? `--session-id ${sessionUuid}`
|
||||||
});
|
: `--resume ${sessionUuid}`;
|
||||||
}
|
const skipPermissionsFlag = config.skipPermissions ? "--dangerously-skip-permissions" : "";
|
||||||
|
const mcpConfigFlag = mcpConfigPath ? `--mcp-config ${mcpConfigPath}` : "";
|
||||||
|
const flags = [sessionFlag, skipPermissionsFlag, mcpConfigFlag].filter(f => f).join(" ");
|
||||||
|
const claudeCmd = `claude ${flags}\r`;
|
||||||
|
ptyProcess.write(claudeCmd);
|
||||||
|
|
||||||
// Auto-run the selected coding agent
|
// Start MCP poller immediately (auth is handled by shell environment)
|
||||||
if (config.codingAgent === "claude") {
|
if (!mcpPollerPtyProcesses.has(sessionId) && projectDir) {
|
||||||
const sessionFlag = isNewSession
|
spawnMcpPoller(sessionId, projectDir);
|
||||||
? `--session-id ${sessionUuid}`
|
}
|
||||||
: `--resume ${sessionUuid}`;
|
} else if (config.codingAgent === "codex") {
|
||||||
const skipPermissionsFlag = config.skipPermissions ? "--dangerously-skip-permissions" : "";
|
ptyProcess.write("codex\r");
|
||||||
const mcpConfigFlag = mcpConfigPath ? `--mcp-config ${mcpConfigPath}` : "";
|
|
||||||
const flags = [sessionFlag, skipPermissionsFlag, mcpConfigFlag].filter(f => f).join(" ");
|
|
||||||
const claudeCmd = `claude ${flags}\r`;
|
|
||||||
ptyProcess.write(claudeCmd);
|
|
||||||
|
|
||||||
// Start MCP poller immediately (auth is handled by shell environment)
|
|
||||||
if (!mcpPollerPtyProcesses.has(sessionId) && projectDir) {
|
|
||||||
spawnMcpPoller(sessionId, projectDir);
|
|
||||||
}
|
}
|
||||||
} else if (config.codingAgent === "codex") {
|
|
||||||
ptyProcess.write("codex\r");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue