feat: fix CLI authentication detection to prevent unnecessary browser prompts

- Fix Claude, Codex, and Cursor auth handlers to check if CLI is already authenticated
- Use same detection logic as each provider's internal checkAuth/codexAuthIndicators()
- For Codex: Check for API keys and auth files before requiring manual login
- For Cursor: Check for env var and credentials files before requiring manual auth
- For Claude: Check for cached auth tokens, settings, and credentials files
- If CLI is already authenticated: Just reconnect by removing disconnected marker
- If CLI needs auth: Tell user to manually run login command
- This prevents timeout errors when login commands can't run in non-interactive mode
This commit is contained in:
DhanushSantosh
2026-01-09 21:34:14 +05:30
parent 33d02d1df8
commit 1452232409
17 changed files with 741 additions and 30 deletions

View File

@@ -1073,6 +1073,14 @@ export class HttpApiClient implements ElectronAPI {
output?: string;
}> => this.post('/api/setup/auth-claude'),
deauthClaude: (): Promise<{
success: boolean;
requiresManualDeauth?: boolean;
command?: string;
message?: string;
error?: string;
}> => this.post('/api/setup/deauth-claude'),
storeApiKey: (
provider: string,
apiKey: string
@@ -1139,6 +1147,24 @@ export class HttpApiClient implements ElectronAPI {
error?: string;
}> => this.get('/api/setup/cursor-status'),
authCursor: (): Promise<{
success: boolean;
token?: string;
requiresManualAuth?: boolean;
terminalOpened?: boolean;
command?: string;
message?: string;
output?: string;
}> => this.post('/api/setup/auth-cursor'),
deauthCursor: (): Promise<{
success: boolean;
requiresManualDeauth?: boolean;
command?: string;
message?: string;
error?: string;
}> => this.post('/api/setup/deauth-cursor'),
getCursorConfig: (
projectPath: string
): Promise<{
@@ -1281,6 +1307,14 @@ export class HttpApiClient implements ElectronAPI {
output?: string;
}> => this.post('/api/setup/auth-codex'),
deauthCodex: (): Promise<{
success: boolean;
requiresManualDeauth?: boolean;
command?: string;
message?: string;
error?: string;
}> => this.post('/api/setup/deauth-codex'),
verifyCodexAuth: (
authMethod: 'cli' | 'api_key',
apiKey?: string