mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-03 16:16:29 +00:00
fix(cursor): save credentials after auto-detect and fix signal hang
- handleAuth() now calls saveCredentials() after successful auto-detect - Handle code === null (signal kill) in daemon exit handler to prevent promise from hanging indefinitely - Remove unnecessary await on synchronous functions
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
autoDetectTokens,
|
autoDetectTokens,
|
||||||
|
saveCredentials,
|
||||||
checkAuthStatus,
|
checkAuthStatus,
|
||||||
startDaemon,
|
startDaemon,
|
||||||
stopDaemon,
|
stopDaemon,
|
||||||
@@ -86,9 +87,15 @@ async function handleAuth(): Promise<number> {
|
|||||||
|
|
||||||
// Try auto-detection first
|
// Try auto-detection first
|
||||||
console.log(info('Attempting auto-detection...'));
|
console.log(info('Attempting auto-detection...'));
|
||||||
const autoResult = await autoDetectTokens();
|
const autoResult = autoDetectTokens();
|
||||||
|
|
||||||
if (autoResult.found && autoResult.accessToken && autoResult.machineId) {
|
if (autoResult.found && autoResult.accessToken && autoResult.machineId) {
|
||||||
|
saveCredentials({
|
||||||
|
accessToken: autoResult.accessToken,
|
||||||
|
machineId: autoResult.machineId,
|
||||||
|
authMethod: 'auto-detect',
|
||||||
|
importedAt: new Date().toISOString(),
|
||||||
|
});
|
||||||
console.log(ok('Auto-detected Cursor credentials'));
|
console.log(ok('Auto-detected Cursor credentials'));
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log('Next steps:');
|
console.log('Next steps:');
|
||||||
@@ -123,7 +130,7 @@ async function handleStatus(): Promise<number> {
|
|||||||
// TODO: Load from unified config when #521 is complete
|
// TODO: Load from unified config when #521 is complete
|
||||||
const cursorConfig = DEFAULT_CURSOR_CONFIG;
|
const cursorConfig = DEFAULT_CURSOR_CONFIG;
|
||||||
|
|
||||||
const authStatus = await checkAuthStatus();
|
const authStatus = checkAuthStatus();
|
||||||
const daemonStatus = await getDaemonStatus(cursorConfig.port);
|
const daemonStatus = await getDaemonStatus(cursorConfig.port);
|
||||||
|
|
||||||
console.log('Cursor IDE Status');
|
console.log('Cursor IDE Status');
|
||||||
@@ -203,7 +210,7 @@ async function handleStart(): Promise<number> {
|
|||||||
const cursorConfig = DEFAULT_CURSOR_CONFIG;
|
const cursorConfig = DEFAULT_CURSOR_CONFIG;
|
||||||
|
|
||||||
// Check auth first
|
// Check auth first
|
||||||
const authStatus = await checkAuthStatus();
|
const authStatus = checkAuthStatus();
|
||||||
if (!authStatus.authenticated) {
|
if (!authStatus.authenticated) {
|
||||||
console.error(fail('Not authenticated. Run: ccs cursor auth'));
|
console.error(fail('Not authenticated. Run: ccs cursor auth'));
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -207,9 +207,14 @@ export async function startDaemon(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
proc.on('exit', (code) => {
|
proc.on('exit', (code, signal) => {
|
||||||
clearInterval(checkInterval);
|
clearInterval(checkInterval);
|
||||||
if (code === 0) {
|
if (code === null) {
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
error: `Daemon process was killed by signal ${signal}`,
|
||||||
|
});
|
||||||
|
} else if (code === 0) {
|
||||||
resolve({
|
resolve({
|
||||||
success: false,
|
success: false,
|
||||||
error: 'Daemon process exited unexpectedly with code 0',
|
error: 'Daemon process exited unexpectedly with code 0',
|
||||||
|
|||||||
Reference in New Issue
Block a user