Skip to content

Commit 6d45f36

Browse files
committed
fix checking ready for setup commands
1 parent 917edcf commit 6d45f36

File tree

1 file changed

+5
-36
lines changed

1 file changed

+5
-36
lines changed

main.ts

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,8 @@ function getPersistedSessions(): PersistedSession[] {
2424

2525
function isTerminalReady(buffer: string, startPos: number = 0): boolean {
2626
const searchBuffer = buffer.slice(startPos);
27-
const promptSymbols = ["$ ", "% ", "> ", "➜ ", "➜ ", "✗ ", "✓ "];
28-
const endSymbols = ["$", "%", ">", "➜", "✗", "✓"];
2927

30-
// Check for bracketed paste mode
31-
if (searchBuffer.includes("\x1b[?2004h")) {
32-
return true;
33-
}
34-
35-
// Check for prompt symbols
36-
for (const symbol of promptSymbols) {
37-
if (searchBuffer.includes(symbol)) {
38-
return true;
39-
}
40-
}
41-
42-
// Check for end symbols
43-
for (const symbol of endSymbols) {
44-
if (searchBuffer.endsWith(symbol)) {
45-
return true;
46-
}
47-
}
48-
49-
return false;
28+
return searchBuffer.includes("\x1b[?2004h", startPos);
5029
}
5130

5231
function savePersistedSessions(sessions: PersistedSession[]) {
@@ -107,7 +86,6 @@ function writeMcpConfigFile(projectDir: string, mcpServers: any): string | null
10786

10887
// Spawn headless PTY for MCP polling
10988
function spawnMcpPoller(sessionId: string, projectDir: string) {
110-
console.log(`[MCP Poller] Spawning for session ${sessionId}, project dir: ${projectDir}`);
11189
const shell = os.platform() === "darwin" ? "zsh" : "bash";
11290
const ptyProcess = pty.spawn(shell, ["-l"], {
11391
name: "xterm-color",
@@ -125,30 +103,25 @@ function spawnMcpPoller(sessionId: string, projectDir: string) {
125103
ptyProcess.onData((data) => {
126104
// Accumulate output without displaying it
127105
outputBuffer += data;
128-
console.log(`[MCP Poller ${sessionId}] Data:`, data.substring(0, 100));
129106

130107
// Parse output whenever we have MCP server entries
131108
// Match lines like: "servername: url (type) - ✓ Connected" or "servername: command (stdio) - ✓ Connected"
132109
// Pattern handles SSE, stdio, and HTTP types
133110
const mcpServerLineRegex = /^[\w-]+:.+\((?:SSE|stdio|HTTP)\)\s+-\s+[]/m;
134111

135112
if (mcpServerLineRegex.test(data) || data.includes("No MCP servers configured")) {
136-
console.log(`[MCP Poller ${sessionId}] MCP output detected, parsing...`);
137113
try {
138114
const servers = parseMcpOutput(outputBuffer);
139-
console.log(`[MCP Poller ${sessionId}] Parsed servers:`, servers);
140115

141116
// Merge servers into the map (upsert by name)
142117
servers.forEach(server => {
143118
serverMap.set(server.name, server);
144119
});
145120

146121
const allServers = Array.from(serverMap.values());
147-
console.log(`[MCP Poller ${sessionId}] Total servers:`, allServers);
148122

149123
if (mainWindow && !mainWindow.isDestroyed()) {
150124
mainWindow.webContents.send("mcp-servers-updated", sessionId, allServers);
151-
console.log(`[MCP Poller ${sessionId}] Sent mcp-servers-updated event`);
152125
}
153126
} catch (error) {
154127
console.error(`[MCP Poller ${sessionId}] Error parsing:`, error);
@@ -158,13 +131,11 @@ function spawnMcpPoller(sessionId: string, projectDir: string) {
158131
// Clear buffer when we see the shell prompt (command finished)
159132
if ((data.includes("% ") || data.includes("$ ") || data.includes("➜ ")) &&
160133
outputBuffer.includes("claude mcp list")) {
161-
console.log(`[MCP Poller ${sessionId}] Command complete, clearing buffer`);
162134
outputBuffer = "";
163135
}
164136
});
165137

166138
// Start polling immediately and then every 60 seconds
167-
console.log(`[MCP Poller ${sessionId}] Starting polling loop`);
168139
const pollMcp = () => {
169140
if (mcpPollerPtyProcesses.has(sessionId)) {
170141
// Notify renderer that polling is starting
@@ -173,11 +144,8 @@ function spawnMcpPoller(sessionId: string, projectDir: string) {
173144
}
174145

175146
const command = `claude mcp list`;
176-
console.log(`[MCP Poller ${sessionId}] Running command: ${command}`);
177147
ptyProcess.write(command + "\r");
178148
setTimeout(pollMcp, 60000);
179-
} else {
180-
console.log(`[MCP Poller ${sessionId}] No longer active, stopping`);
181149
}
182150
};
183151

@@ -267,7 +235,8 @@ function spawnSessionPty(
267235
lastReadyCheckPos = dataBuffer.length;
268236

269237
if (config.setupCommands && setupCommandsIdx < config.setupCommands.length) {
270-
ptyProcess.write(config.setupCommands[setupCommandsIdx] + "\r");
238+
const cmd = config.setupCommands[setupCommandsIdx];
239+
ptyProcess.write(cmd + "\r");
271240
setupCommandsIdx++;
272241
} else {
273242
terminalReady = true;
@@ -280,8 +249,8 @@ function spawnSessionPty(
280249
const skipPermissionsFlag = config.skipPermissions ? "--dangerously-skip-permissions" : "";
281250
const mcpConfigFlag = mcpConfigPath ? `--mcp-config ${mcpConfigPath}` : "";
282251
const flags = [sessionFlag, skipPermissionsFlag, mcpConfigFlag].filter(f => f).join(" ");
283-
const claudeCmd = `claude ${flags}\r`;
284-
ptyProcess.write(claudeCmd);
252+
const claudeCmd = `claude ${flags}`;
253+
ptyProcess.write(claudeCmd + "\r");
285254

286255
// Start MCP poller immediately (auth is handled by shell environment)
287256
if (!mcpPollerPtyProcesses.has(sessionId) && projectDir) {

0 commit comments

Comments
 (0)