cursor-switch 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -75
- package/SECURITY.md +22 -19
- package/bin/cswitch.js +31 -8
- package/dist/cli.d.ts +0 -4
- package/dist/cli.js +404 -225
- package/dist/core/account-store.d.ts +0 -7
- package/dist/core/account-store.js +22 -28
- package/dist/core/cdp-engine.d.ts +11 -49
- package/dist/core/cdp-engine.js +155 -110
- package/dist/core/config-store.d.ts +7 -6
- package/dist/core/config-store.js +33 -12
- package/dist/core/cursor-paths.d.ts +8 -18
- package/dist/core/cursor-paths.js +18 -37
- package/dist/core/dashboard-launcher.d.ts +2 -22
- package/dist/core/dashboard-launcher.js +10 -60
- package/dist/core/extract-client.d.ts +57 -0
- package/dist/core/extract-client.js +219 -0
- package/dist/core/extract-menu.d.ts +3 -0
- package/dist/core/extract-menu.js +360 -0
- package/dist/core/extract-service.d.ts +64 -0
- package/dist/core/extract-service.js +435 -0
- package/dist/core/fingerprint.d.ts +0 -4
- package/dist/core/fingerprint.js +0 -6
- package/dist/core/oauth-receiver.d.ts +1 -11
- package/dist/core/oauth-receiver.js +509 -527
- package/dist/core/official-api.d.ts +0 -17
- package/dist/core/official-api.js +4 -23
- package/dist/core/outlook-launcher.d.ts +0 -27
- package/dist/core/outlook-launcher.js +235 -261
- package/dist/core/process-manager.d.ts +0 -14
- package/dist/core/process-manager.js +7 -22
- package/dist/core/pure-login-service.d.ts +64 -28
- package/dist/core/pure-login-service.js +527 -346
- package/dist/core/refund-client.d.ts +0 -22
- package/dist/core/refund-client.js +7 -27
- package/dist/core/refund-service.d.ts +0 -16
- package/dist/core/refund-service.js +8 -34
- package/dist/core/safe-storage.d.ts +27 -0
- package/dist/core/safe-storage.js +284 -0
- package/dist/core/sqlite-bridge.d.ts +10 -11
- package/dist/core/sqlite-bridge.js +112 -47
- package/dist/core/storage-bridge.d.ts +14 -5
- package/dist/core/storage-bridge.js +84 -24
- package/dist/core/switch-orchestrator.d.ts +96 -0
- package/dist/core/switch-orchestrator.js +341 -0
- package/dist/core/token-exchange.d.ts +81 -0
- package/dist/core/token-exchange.js +275 -0
- package/dist/core/token-parser.d.ts +56 -20
- package/dist/core/token-parser.js +354 -43
- package/dist/core/update-checker.d.ts +1 -29
- package/dist/core/update-checker.js +28 -43
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/menu.d.ts +0 -7
- package/dist/menu.js +445 -538
- package/dist/types.d.ts +12 -4
- package/dist/types.js +0 -4
- package/dist/utils/account-text-importer.d.ts +9 -0
- package/dist/utils/account-text-importer.js +96 -0
- package/dist/utils/browser-utils.d.ts +0 -24
- package/dist/utils/browser-utils.js +0 -57
- package/dist/utils/clipboard.d.ts +0 -4
- package/dist/utils/clipboard.js +0 -5
- package/dist/utils/credential-bundle-ui.d.ts +36 -0
- package/dist/utils/credential-bundle-ui.js +246 -0
- package/dist/utils/live-menu.d.ts +37 -9
- package/dist/utils/live-menu.js +510 -81
- package/dist/utils/plan-formatter.d.ts +0 -26
- package/dist/utils/plan-formatter.js +10 -44
- package/dist/utils/prompt-utils.d.ts +0 -18
- package/dist/utils/prompt-utils.js +0 -23
- package/dist/utils/proxy-bootstrap.d.ts +12 -0
- package/dist/utils/proxy-bootstrap.js +141 -0
- package/dist/utils/security.d.ts +2 -4
- package/dist/utils/security.js +36 -4
- package/dist/utils/table-renderer.d.ts +0 -4
- package/dist/utils/table-renderer.js +24 -8
- package/dist/utils/time-formatter.d.ts +0 -4
- package/dist/utils/time-formatter.js +0 -8
- package/dist/utils/token-preflight-ui.d.ts +28 -0
- package/dist/utils/token-preflight-ui.js +222 -0
- package/dist/utils/window-focus.d.ts +3 -0
- package/dist/utils/window-focus.js +106 -0
- package/package.json +12 -5
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cursor 进程生命周期与安全互锁管理器
|
|
3
|
-
* 切换前检测进程,释放 SQLite 文件锁,切完后支持后台唤醒
|
|
4
|
-
*/
|
|
5
1
|
export declare class ProcessManager {
|
|
6
2
|
private static cachedRunning;
|
|
7
3
|
private static lastCheckTime;
|
|
8
4
|
private static isChecking;
|
|
9
5
|
private static readonly CACHE_TTL_MS;
|
|
10
|
-
/**
|
|
11
|
-
* 检查 Cursor 进程当前是否正在运行
|
|
12
|
-
* @param forceFresh 是否强制同步检测 (如换号杀进程校验时使用),默认 false 走 0ms 高性能缓存
|
|
13
|
-
*/
|
|
14
6
|
static isCursorRunning(forceFresh?: boolean): boolean;
|
|
15
7
|
private static checkSync;
|
|
16
8
|
private static triggerAsyncCheck;
|
|
17
|
-
/**
|
|
18
|
-
* 优雅或强制关闭 Cursor 进程,释放文件独占锁
|
|
19
|
-
*/
|
|
20
9
|
static closeCursor(): Promise<boolean>;
|
|
21
|
-
/**
|
|
22
|
-
* 在后台独立拉起 Cursor IDE 进程
|
|
23
|
-
*/
|
|
24
10
|
static launchCursor(executablePath?: string): boolean;
|
|
25
11
|
}
|
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cursor 进程生命周期与安全互锁管理器
|
|
3
|
-
* 切换前检测进程,释放 SQLite 文件锁,切完后支持后台唤醒
|
|
4
|
-
*/
|
|
5
1
|
import { execSync, spawn } from 'node:child_process';
|
|
6
2
|
export class ProcessManager {
|
|
7
3
|
static cachedRunning = false;
|
|
8
4
|
static lastCheckTime = 0;
|
|
9
5
|
static isChecking = false;
|
|
10
|
-
static CACHE_TTL_MS = 60000;
|
|
11
|
-
/**
|
|
12
|
-
* 检查 Cursor 进程当前是否正在运行
|
|
13
|
-
* @param forceFresh 是否强制同步检测 (如换号杀进程校验时使用),默认 false 走 0ms 高性能缓存
|
|
14
|
-
*/
|
|
6
|
+
static CACHE_TTL_MS = 60000;
|
|
15
7
|
static isCursorRunning(forceFresh = false) {
|
|
16
8
|
const now = Date.now();
|
|
17
|
-
// 1. 如果缓存尚未过期且不强制刷新,立即 0ms 返回缓存结果
|
|
18
9
|
if (!forceFresh && now - this.lastCheckTime < this.CACHE_TTL_MS) {
|
|
19
10
|
return this.cachedRunning;
|
|
20
11
|
}
|
|
21
|
-
// 2. 缓存已过 TTL 但非强制:先立即返回上次状态,同时在后台异步刷新,绝不阻塞 UI 渲染
|
|
22
12
|
if (!forceFresh && this.lastCheckTime > 0) {
|
|
23
13
|
if (!this.isChecking) {
|
|
24
14
|
this.triggerAsyncCheck();
|
|
25
15
|
}
|
|
26
16
|
return this.cachedRunning;
|
|
27
17
|
}
|
|
28
|
-
// 3. 首次冷启动或显式要求强制检测时同步执行
|
|
29
18
|
return this.checkSync();
|
|
30
19
|
}
|
|
31
20
|
static checkSync() {
|
|
@@ -40,7 +29,6 @@ export class ProcessManager {
|
|
|
40
29
|
this.cachedRunning = stdout.toLowerCase().includes('cursor.exe');
|
|
41
30
|
}
|
|
42
31
|
else {
|
|
43
|
-
// macOS / Linux: 严格使用 -x 精确匹配进程名,避免误杀或误判 cursor-switch 自身
|
|
44
32
|
const stdout = execSync('pgrep -x Cursor || pgrep -x cursor || true', {
|
|
45
33
|
encoding: 'utf8',
|
|
46
34
|
stdio: ['ignore', 'pipe', 'ignore'],
|
|
@@ -61,7 +49,9 @@ export class ProcessManager {
|
|
|
61
49
|
stdio: ['ignore', 'pipe', 'ignore'],
|
|
62
50
|
windowsHide: true,
|
|
63
51
|
})
|
|
64
|
-
: spawn('
|
|
52
|
+
: spawn('sh', ['-c', 'pgrep -x Cursor || pgrep -x cursor || true'], {
|
|
53
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
54
|
+
});
|
|
65
55
|
let stdout = '';
|
|
66
56
|
cmd.stdout?.on('data', (chunk) => {
|
|
67
57
|
stdout += chunk.toString();
|
|
@@ -81,9 +71,6 @@ export class ProcessManager {
|
|
|
81
71
|
this.isChecking = false;
|
|
82
72
|
});
|
|
83
73
|
}
|
|
84
|
-
/**
|
|
85
|
-
* 优雅或强制关闭 Cursor 进程,释放文件独占锁
|
|
86
|
-
*/
|
|
87
74
|
static async closeCursor() {
|
|
88
75
|
if (!this.isCursorRunning(true)) {
|
|
89
76
|
this.cachedRunning = false;
|
|
@@ -95,10 +82,8 @@ export class ProcessManager {
|
|
|
95
82
|
execSync('taskkill /F /IM Cursor.exe /T', { stdio: 'ignore' });
|
|
96
83
|
}
|
|
97
84
|
else {
|
|
98
|
-
// macOS / Linux: 严格精确匹配,禁止使用 pkill -i cursor 导致自杀
|
|
99
85
|
execSync('pkill -9 -x Cursor 2>/dev/null || pkill -9 -x cursor 2>/dev/null || true', { stdio: 'ignore' });
|
|
100
86
|
}
|
|
101
|
-
// 等待进程完全释放文件句柄
|
|
102
87
|
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
103
88
|
const running = this.isCursorRunning(true);
|
|
104
89
|
this.cachedRunning = running;
|
|
@@ -109,17 +94,17 @@ export class ProcessManager {
|
|
|
109
94
|
return false;
|
|
110
95
|
}
|
|
111
96
|
}
|
|
112
|
-
/**
|
|
113
|
-
* 在后台独立拉起 Cursor IDE 进程
|
|
114
|
-
*/
|
|
115
97
|
static launchCursor(executablePath) {
|
|
116
98
|
if (!executablePath) {
|
|
117
99
|
return false;
|
|
118
100
|
}
|
|
119
101
|
try {
|
|
102
|
+
const cleanEnv = { ...process.env };
|
|
103
|
+
delete cleanEnv.ELECTRON_RUN_AS_NODE;
|
|
120
104
|
const child = spawn(executablePath, [], {
|
|
121
105
|
detached: true,
|
|
122
106
|
stdio: 'ignore',
|
|
107
|
+
env: cleanEnv,
|
|
123
108
|
});
|
|
124
109
|
child.unref();
|
|
125
110
|
this.cachedRunning = true;
|
|
@@ -1,27 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
* Cursor 动态纯净住宅 IP 自动代登与 Token 提取服务
|
|
3
|
-
* 直连海外 S 级原生家宽代理集群与 Rust Worker 算力节点
|
|
4
|
-
* 支持智能解构多段式格式、Turnstile 极速解盾、收件箱自动取码、Token 秒提与换号无缝联动
|
|
5
|
-
*/
|
|
1
|
+
import { ConfigStore } from './config-store.js';
|
|
6
2
|
import { AccountStore } from './account-store.js';
|
|
7
3
|
import { StorageBridge } from './storage-bridge.js';
|
|
8
4
|
import { SqliteBridge } from './sqlite-bridge.js';
|
|
5
|
+
import { generateMachineIds } from './fingerprint.js';
|
|
6
|
+
import type { AccountInfo } from '../types.js';
|
|
9
7
|
export interface ParsedAccount {
|
|
10
8
|
email: string;
|
|
11
9
|
emailPassword: string;
|
|
12
10
|
cursorPassword: string;
|
|
13
11
|
}
|
|
12
|
+
export type NeedCodeOutcome = {
|
|
13
|
+
action: 'token';
|
|
14
|
+
token: string;
|
|
15
|
+
email?: string;
|
|
16
|
+
accessToken?: string;
|
|
17
|
+
refreshToken?: string;
|
|
18
|
+
} | {
|
|
19
|
+
action: 'wait_sse';
|
|
20
|
+
} | {
|
|
21
|
+
action: 'abort';
|
|
22
|
+
error?: string;
|
|
23
|
+
};
|
|
24
|
+
export interface TaskStreamResult {
|
|
25
|
+
ok: boolean;
|
|
26
|
+
token?: string;
|
|
27
|
+
accessToken?: string;
|
|
28
|
+
refreshToken?: string;
|
|
29
|
+
email?: string;
|
|
30
|
+
error?: string;
|
|
31
|
+
isPhoneChallenge?: boolean;
|
|
32
|
+
remaining?: number;
|
|
33
|
+
}
|
|
14
34
|
export declare class PureLoginService {
|
|
15
35
|
private configStore;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
36
|
+
private customApiBase?;
|
|
37
|
+
constructor(customApiBase?: string);
|
|
38
|
+
private getApiBase;
|
|
39
|
+
getConfigStore(): ConfigStore;
|
|
40
|
+
private splitAccountParts;
|
|
41
|
+
parseEmailCredentials(raw: string): {
|
|
42
|
+
email: string;
|
|
43
|
+
emailPassword: string;
|
|
44
|
+
};
|
|
21
45
|
parseAccountString(raw: string): ParsedAccount;
|
|
22
|
-
/**
|
|
23
|
-
* 校验卡密有效性与剩余可用次数
|
|
24
|
-
*/
|
|
25
46
|
checkKey(code: string): Promise<{
|
|
26
47
|
valid: boolean;
|
|
27
48
|
max_uses?: number;
|
|
@@ -29,15 +50,11 @@ export declare class PureLoginService {
|
|
|
29
50
|
remaining?: number;
|
|
30
51
|
detail?: string;
|
|
31
52
|
}>;
|
|
32
|
-
/**
|
|
33
|
-
* 启动纯净代登任务
|
|
34
|
-
*/
|
|
35
53
|
startTask(params: {
|
|
36
54
|
code: string;
|
|
37
55
|
email: string;
|
|
38
56
|
emailPassword?: string;
|
|
39
57
|
cursorPassword?: string;
|
|
40
|
-
rawAccount?: string;
|
|
41
58
|
}): Promise<{
|
|
42
59
|
ok: boolean;
|
|
43
60
|
taskId?: string;
|
|
@@ -45,24 +62,43 @@ export declare class PureLoginService {
|
|
|
45
62
|
remaining?: number;
|
|
46
63
|
detail?: string;
|
|
47
64
|
}>;
|
|
48
|
-
/**
|
|
49
|
-
* 提交 6 位邮箱验证码或短信验证码
|
|
50
|
-
*/
|
|
51
65
|
submitOtp(taskId: string, cardCode: string, otpCode: string): Promise<{
|
|
52
66
|
ok: boolean;
|
|
53
67
|
token?: string;
|
|
68
|
+
accessToken?: string;
|
|
69
|
+
refreshToken?: string;
|
|
54
70
|
email?: string;
|
|
55
71
|
detail?: string;
|
|
56
72
|
canRetry?: boolean;
|
|
57
73
|
needsSmsCode?: boolean;
|
|
58
74
|
phoneMask?: string;
|
|
59
75
|
}>;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
resendCode(taskId: string, cardCode: string, email: string): Promise<{
|
|
77
|
+
ok: boolean;
|
|
78
|
+
message: string;
|
|
79
|
+
}>;
|
|
80
|
+
cancelTask(taskId: string, cardCode: string): Promise<void>;
|
|
81
|
+
saveExtractedAccount(store: AccountStore, params: {
|
|
82
|
+
email: string;
|
|
83
|
+
token: string;
|
|
84
|
+
accessToken?: string;
|
|
85
|
+
refreshToken?: string;
|
|
86
|
+
emailPassword?: string;
|
|
87
|
+
cursorPassword?: string;
|
|
88
|
+
checkoutLinks?: AccountInfo['checkout_links'];
|
|
89
|
+
}): Promise<{
|
|
90
|
+
account: AccountInfo;
|
|
91
|
+
machineIds: ReturnType<typeof generateMachineIds>;
|
|
92
|
+
}>;
|
|
93
|
+
streamTaskEvents(params: {
|
|
94
|
+
taskId: string;
|
|
95
|
+
taskToken?: string;
|
|
96
|
+
onStatus?: (step: string, msg: string) => void;
|
|
97
|
+
onNeedCode: (data: any, abortSignal: AbortSignal) => Promise<NeedCodeOutcome>;
|
|
98
|
+
onNeedSmsCode?: (data: any, abortSignal: AbortSignal) => Promise<NeedCodeOutcome>;
|
|
99
|
+
}): Promise<TaskStreamResult>;
|
|
100
|
+
runInteractiveFlow(store: AccountStore, storage: StorageBridge, sqlite: SqliteBridge, executablePath?: string, options?: {
|
|
101
|
+
prefilledInput?: string;
|
|
102
|
+
skipSwitchPrompt?: boolean;
|
|
103
|
+
}): Promise<AccountInfo | null>;
|
|
68
104
|
}
|