fix: fixing claude and cursor login defaulting to the previously opened shell

This commit is contained in:
simosmik
2025-12-17 12:18:40 +00:00
parent d822a96818
commit 6bf3696991
3 changed files with 26 additions and 2 deletions

View File

@@ -827,9 +827,31 @@ function handleShellConnection(ws) {
const initialCommand = data.initialCommand;
const isPlainShell = data.isPlainShell || (!!initialCommand && !hasSession) || provider === 'plain-shell';
ptySessionKey = `${projectPath}_${sessionId || 'default'}`;
// Login commands (Claude/Cursor auth) should never reuse cached sessions
const isLoginCommand = initialCommand && (
initialCommand.includes('setup-token') ||
initialCommand.includes('cursor-agent login') ||
initialCommand.includes('auth login')
);
const existingSession = ptySessionsMap.get(ptySessionKey);
// Include command hash in session key so different commands get separate sessions
const commandSuffix = isPlainShell && initialCommand
? `_cmd_${Buffer.from(initialCommand).toString('base64').slice(0, 16)}`
: '';
ptySessionKey = `${projectPath}_${sessionId || 'default'}${commandSuffix}`;
// Kill any existing login session before starting fresh
if (isLoginCommand) {
const oldSession = ptySessionsMap.get(ptySessionKey);
if (oldSession) {
console.log('🧹 Cleaning up existing login session:', ptySessionKey);
if (oldSession.timeoutId) clearTimeout(oldSession.timeoutId);
if (oldSession.pty && oldSession.pty.kill) oldSession.pty.kill();
ptySessionsMap.delete(ptySessionKey);
}
}
const existingSession = isLoginCommand ? null : ptySessionsMap.get(ptySessionKey);
if (existingSession) {
console.log('♻️ Reconnecting to existing PTY session:', ptySessionKey);
shellProcess = existingSession.pty;

View File

@@ -575,6 +575,7 @@ const Onboarding = ({ onComplete }) => {
{/* Login Modal */}
{showLoginModal && (
<LoginModal
key={loginProvider}
isOpen={showLoginModal}
onClose={() => setShowLoginModal(false)}
provider={loginProvider}

View File

@@ -2149,6 +2149,7 @@ function Settings({ isOpen, onClose, projects = [], initialTab = 'tools' }) {
{/* Login Modal */}
<LoginModal
key={loginProvider}
isOpen={showLoginModal}
onClose={() => setShowLoginModal(false)}
provider={loginProvider}