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.
Files changed (84) hide show
  1. package/README.md +76 -75
  2. package/SECURITY.md +22 -19
  3. package/bin/cswitch.js +31 -8
  4. package/dist/cli.d.ts +0 -4
  5. package/dist/cli.js +404 -225
  6. package/dist/core/account-store.d.ts +0 -7
  7. package/dist/core/account-store.js +22 -28
  8. package/dist/core/cdp-engine.d.ts +11 -49
  9. package/dist/core/cdp-engine.js +155 -110
  10. package/dist/core/config-store.d.ts +7 -6
  11. package/dist/core/config-store.js +33 -12
  12. package/dist/core/cursor-paths.d.ts +8 -18
  13. package/dist/core/cursor-paths.js +18 -37
  14. package/dist/core/dashboard-launcher.d.ts +2 -22
  15. package/dist/core/dashboard-launcher.js +10 -60
  16. package/dist/core/extract-client.d.ts +57 -0
  17. package/dist/core/extract-client.js +219 -0
  18. package/dist/core/extract-menu.d.ts +3 -0
  19. package/dist/core/extract-menu.js +360 -0
  20. package/dist/core/extract-service.d.ts +64 -0
  21. package/dist/core/extract-service.js +435 -0
  22. package/dist/core/fingerprint.d.ts +0 -4
  23. package/dist/core/fingerprint.js +0 -6
  24. package/dist/core/oauth-receiver.d.ts +1 -11
  25. package/dist/core/oauth-receiver.js +509 -527
  26. package/dist/core/official-api.d.ts +0 -17
  27. package/dist/core/official-api.js +4 -23
  28. package/dist/core/outlook-launcher.d.ts +0 -27
  29. package/dist/core/outlook-launcher.js +235 -261
  30. package/dist/core/process-manager.d.ts +0 -14
  31. package/dist/core/process-manager.js +7 -22
  32. package/dist/core/pure-login-service.d.ts +64 -28
  33. package/dist/core/pure-login-service.js +527 -346
  34. package/dist/core/refund-client.d.ts +0 -22
  35. package/dist/core/refund-client.js +7 -27
  36. package/dist/core/refund-service.d.ts +0 -16
  37. package/dist/core/refund-service.js +8 -34
  38. package/dist/core/safe-storage.d.ts +27 -0
  39. package/dist/core/safe-storage.js +284 -0
  40. package/dist/core/sqlite-bridge.d.ts +10 -11
  41. package/dist/core/sqlite-bridge.js +112 -47
  42. package/dist/core/storage-bridge.d.ts +14 -5
  43. package/dist/core/storage-bridge.js +84 -24
  44. package/dist/core/switch-orchestrator.d.ts +96 -0
  45. package/dist/core/switch-orchestrator.js +341 -0
  46. package/dist/core/token-exchange.d.ts +81 -0
  47. package/dist/core/token-exchange.js +275 -0
  48. package/dist/core/token-parser.d.ts +56 -20
  49. package/dist/core/token-parser.js +354 -43
  50. package/dist/core/update-checker.d.ts +1 -29
  51. package/dist/core/update-checker.js +28 -43
  52. package/dist/index.d.ts +1 -3
  53. package/dist/index.js +1 -3
  54. package/dist/menu.d.ts +0 -7
  55. package/dist/menu.js +445 -538
  56. package/dist/types.d.ts +12 -4
  57. package/dist/types.js +0 -4
  58. package/dist/utils/account-text-importer.d.ts +9 -0
  59. package/dist/utils/account-text-importer.js +96 -0
  60. package/dist/utils/browser-utils.d.ts +0 -24
  61. package/dist/utils/browser-utils.js +0 -57
  62. package/dist/utils/clipboard.d.ts +0 -4
  63. package/dist/utils/clipboard.js +0 -5
  64. package/dist/utils/credential-bundle-ui.d.ts +36 -0
  65. package/dist/utils/credential-bundle-ui.js +246 -0
  66. package/dist/utils/live-menu.d.ts +37 -9
  67. package/dist/utils/live-menu.js +510 -81
  68. package/dist/utils/plan-formatter.d.ts +0 -26
  69. package/dist/utils/plan-formatter.js +10 -44
  70. package/dist/utils/prompt-utils.d.ts +0 -18
  71. package/dist/utils/prompt-utils.js +0 -23
  72. package/dist/utils/proxy-bootstrap.d.ts +12 -0
  73. package/dist/utils/proxy-bootstrap.js +141 -0
  74. package/dist/utils/security.d.ts +2 -4
  75. package/dist/utils/security.js +36 -4
  76. package/dist/utils/table-renderer.d.ts +0 -4
  77. package/dist/utils/table-renderer.js +24 -8
  78. package/dist/utils/time-formatter.d.ts +0 -4
  79. package/dist/utils/time-formatter.js +0 -8
  80. package/dist/utils/token-preflight-ui.d.ts +28 -0
  81. package/dist/utils/token-preflight-ui.js +222 -0
  82. package/dist/utils/window-focus.d.ts +3 -0
  83. package/dist/utils/window-focus.js +106 -0
  84. 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; // 60 秒超长缓存,绝不频繁唤起系统控制台子进程
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('pgrep', ['-x', 'Cursor'], { stdio: ['ignore', 'pipe', 'ignore'] });
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
- constructor();
17
- /**
18
- * 智能解析账号输入串 (支持 ----, ---, --, |, \t, 双空格, 逗号 等各类分隔符)
19
- * 严格遵循规则:两段式第二段 100% 映射为邮箱密码用于自动收信取码
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
- * 自动从用户邮箱中提取最新 6 位数字验证码 (多轮自动拉取)
62
- */
63
- autoFetchMailCode(email: string, emailPassword: string, cursorPassword?: string): Promise<string | null>;
64
- /**
65
- * 交互式运行纯净代登全流程 (终端交互式 TUI)
66
- */
67
- runInteractiveFlow(store: AccountStore, storage: StorageBridge, sqlite: SqliteBridge, executablePath?: string): Promise<void>;
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
  }