cursor-switch 1.0.7 → 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 (86) 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 -241
  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 +0 -20
  15. package/dist/core/dashboard-launcher.js +3 -53
  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 -31
  29. package/dist/core/outlook-launcher.js +194 -248
  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 +54 -38
  33. package/dist/core/pure-login-service.js +483 -395
  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 -548
  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
  85. package/dist/core/welcome-offer-service.d.ts +0 -52
  86. package/dist/core/welcome-offer-service.js +0 -369
@@ -1,22 +1,25 @@
1
- /**
2
- * 用户本地偏好配置仓库
3
- * 存储路径: ~/.cursor-switch/config.json
4
- * 用于记忆常用卡密、接口地址与个性化选项
5
- */
6
1
  import fs from 'node:fs';
7
2
  import path from 'node:path';
8
3
  import os from 'node:os';
4
+ import { ensureSecureDirSync, writeSecureFileSync } from '../utils/security.js';
9
5
  export class ConfigStore {
10
6
  configDir;
11
7
  configPath;
12
- constructor() {
13
- this.configDir = path.join(os.homedir(), '.cursor-switch');
14
- this.configPath = path.join(this.configDir, 'config.json');
8
+ constructor(customPath) {
9
+ if (customPath) {
10
+ this.configPath = customPath;
11
+ this.configDir = path.dirname(customPath);
12
+ }
13
+ else {
14
+ this.configDir = path.join(os.homedir(), '.cursor-switch');
15
+ this.configPath = path.join(this.configDir, 'config.json');
16
+ }
15
17
  }
16
18
  ensureDir() {
17
- if (!fs.existsSync(this.configDir)) {
18
- fs.mkdirSync(this.configDir, { recursive: true });
19
+ try {
20
+ ensureSecureDirSync(this.configDir);
19
21
  }
22
+ catch { }
20
23
  }
21
24
  load() {
22
25
  this.ensureDir();
@@ -34,7 +37,7 @@ export class ConfigStore {
34
37
  save(config) {
35
38
  this.ensureDir();
36
39
  try {
37
- fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), 'utf8');
40
+ writeSecureFileSync(this.configPath, JSON.stringify(config, null, 2));
38
41
  }
39
42
  catch { }
40
43
  }
@@ -56,9 +59,18 @@ export class ConfigStore {
56
59
  cfg.token_card_code = code.trim();
57
60
  this.save(cfg);
58
61
  }
62
+ getExtractCardCode() {
63
+ const cfg = this.load();
64
+ return cfg.extract_card_code || null;
65
+ }
66
+ setExtractCardCode(code) {
67
+ const cfg = this.load();
68
+ cfg.extract_card_code = code.trim();
69
+ this.save(cfg);
70
+ }
59
71
  getSeatApiBase() {
60
72
  const cfg = this.load();
61
- const envVal = process.env.VITE_SEAT_API_BASE || process.env.CSWITCH_SEAT_API;
73
+ const envVal = process.env.CSWITCH_API_BASE || process.env.CSWITCH_SEAT_API;
62
74
  return (envVal || cfg.seat_api_base || 'https://getdoubao.com').replace(/\/+$/, '');
63
75
  }
64
76
  setSeatApiBase(url) {
@@ -97,4 +109,13 @@ export class ConfigStore {
97
109
  cfg.custom_data_dir = dirStr.trim();
98
110
  this.save(cfg);
99
111
  }
112
+ getPreferredCopyFormat() {
113
+ const cfg = this.load();
114
+ return cfg.preferred_copy_format === 'triple' ? 'triple' : 'single';
115
+ }
116
+ setPreferredCopyFormat(format) {
117
+ const cfg = this.load();
118
+ cfg.preferred_copy_format = format === 'triple' ? 'triple' : 'single';
119
+ this.save(cfg);
120
+ }
100
121
  }
@@ -1,22 +1,12 @@
1
- /**
2
- * 全平台智能 Cursor 路径探测与解析引擎 (Windows / macOS / Linux)
3
- * 具备 5 级弹性降级机制与零配置自愈能力:
4
- * 1. 显式参数 / 环境变量 (CURSOR_PATH, CURSOR_DATA_DIR)
5
- * 2. 本地用户偏好配置 (~/.cursor-switch/config.json)
6
- * 3. 极速文件系统 / 多盘符扫描 (C..Z 盘符、scoop、chocolatey、/Applications 等,1-2ms)
7
- * 4. 系统 PATH 命令反查与 CLI wrapper 溯源 (where.exe / which,10-20ms)
8
- * 5. 运行中进程嗅探与操作系统索引检索 (PowerShell Get-Process / macOS Spotlight mdfind)
9
- */
10
1
  import type { ResolvedCursorPaths } from '../types.js';
11
- /**
12
- * 智能探测 Cursor 可执行文件路径
13
- */
14
2
  export declare function findCursorExecutable(customExecutablePath?: string): string | undefined;
15
- /**
16
- * 智能探测 Cursor 用户数据与存储目录 (包含 storage.json 与 state.vscdb)
17
- */
18
3
  export declare function findCursorDataDir(customDataPath?: string, executablePath?: string): string;
19
- /**
20
- * 完整解析所有 Cursor 关键路径
21
- */
4
+ export declare function resolveSidecarPaths(storageOrDbPath: string, homeDir?: string): {
5
+ globalStorageDir: string;
6
+ userDataDir: string;
7
+ machineIdFile: string;
8
+ authJson: string;
9
+ localStateFile: string;
10
+ cliConfigJson: string;
11
+ };
22
12
  export declare function resolveCursorPaths(customPath?: string, customExecPath?: string): ResolvedCursorPaths;
@@ -1,20 +1,8 @@
1
- /**
2
- * 全平台智能 Cursor 路径探测与解析引擎 (Windows / macOS / Linux)
3
- * 具备 5 级弹性降级机制与零配置自愈能力:
4
- * 1. 显式参数 / 环境变量 (CURSOR_PATH, CURSOR_DATA_DIR)
5
- * 2. 本地用户偏好配置 (~/.cursor-switch/config.json)
6
- * 3. 极速文件系统 / 多盘符扫描 (C..Z 盘符、scoop、chocolatey、/Applications 等,1-2ms)
7
- * 4. 系统 PATH 命令反查与 CLI wrapper 溯源 (where.exe / which,10-20ms)
8
- * 5. 运行中进程嗅探与操作系统索引检索 (PowerShell Get-Process / macOS Spotlight mdfind)
9
- */
10
1
  import os from 'node:os';
11
2
  import path from 'node:path';
12
3
  import fs from 'node:fs';
13
4
  import { execSync } from 'node:child_process';
14
5
  import { ConfigStore } from './config-store.js';
15
- /**
16
- * 从 VSCode / Cursor 的 CLI 启动脚本 (如 resources/app/bin/cursor) 溯源主程序绝对路径
17
- */
18
6
  function resolveExeFromCliScript(scriptPath) {
19
7
  try {
20
8
  const real = fs.realpathSync(scriptPath);
@@ -44,27 +32,20 @@ function resolveExeFromCliScript(scriptPath) {
44
32
  catch { }
45
33
  return null;
46
34
  }
47
- /**
48
- * 智能探测 Cursor 可执行文件路径
49
- */
50
35
  export function findCursorExecutable(customExecutablePath) {
51
36
  const config = new ConfigStore();
52
- // 1. 显式入参
53
37
  if (customExecutablePath && fs.existsSync(customExecutablePath)) {
54
38
  return customExecutablePath;
55
39
  }
56
- // 2. 环境变量 (方便 CI/CD 或终端用户自设)
57
40
  const envPath = process.env.CURSOR_PATH || process.env.CURSOR_BIN || process.env.CURSOR_EXEC_PATH;
58
41
  if (envPath && fs.existsSync(envPath)) {
59
42
  return envPath;
60
43
  }
61
- // 3. 用户偏好配置缓存 (0ms)
62
44
  const cachedPath = config.getCustomExecutablePath();
63
45
  if (cachedPath && fs.existsSync(cachedPath)) {
64
46
  return cachedPath;
65
47
  }
66
48
  const platform = process.platform;
67
- // 4. 极速文件系统 / 多盘符扫描 (< 2ms)
68
49
  if (platform === 'win32') {
69
50
  const localAppData = process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local');
70
51
  const directCandidates = [
@@ -79,7 +60,6 @@ export function findCursorExecutable(customExecutablePath) {
79
60
  return cand;
80
61
  }
81
62
  }
82
- // 扫描 Windows 所有可用盘符 (支持 D/E/F/G 等非系统盘或外接扩展盘)
83
63
  const driveLetters = ['C', 'D', 'E', 'F', 'G', 'H', 'X', 'Y', 'Z'];
84
64
  for (const d of driveLetters) {
85
65
  const root = `${d}:\\`;
@@ -121,7 +101,6 @@ export function findCursorExecutable(customExecutablePath) {
121
101
  }
122
102
  }
123
103
  else {
124
- // Linux
125
104
  const linuxCandidates = [
126
105
  '/usr/bin/cursor',
127
106
  '/usr/local/bin/cursor',
@@ -138,7 +117,6 @@ export function findCursorExecutable(customExecutablePath) {
138
117
  }
139
118
  }
140
119
  }
141
- // 5. 系统 PATH 命令反查 (`where.exe cursor` / `which cursor`)
142
120
  try {
143
121
  const cmd = platform === 'win32' ? 'where.exe cursor' : 'which cursor';
144
122
  const stdout = execSync(cmd, {
@@ -165,7 +143,6 @@ export function findCursorExecutable(customExecutablePath) {
165
143
  }
166
144
  }
167
145
  catch { }
168
- // 6. macOS Spotlight 检索 (针对用户自定义存放在 ~/Downloads、移动硬盘等非标准位置)
169
146
  if (platform === 'darwin') {
170
147
  try {
171
148
  const stdout = execSync('mdfind "kMDItemFSName == \'Cursor.app\'"', {
@@ -184,7 +161,6 @@ export function findCursorExecutable(customExecutablePath) {
184
161
  }
185
162
  catch { }
186
163
  }
187
- // 7. 运行中进程反查 (若用户当前已打开 Cursor,从活动句柄直接捕获路径)
188
164
  try {
189
165
  if (platform === 'win32') {
190
166
  const stdout = execSync('powershell -NoProfile -NonInteractive -Command "(Get-Process Cursor -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Path -First 1)"', {
@@ -202,21 +178,15 @@ export function findCursorExecutable(customExecutablePath) {
202
178
  catch { }
203
179
  return undefined;
204
180
  }
205
- /**
206
- * 智能探测 Cursor 用户数据与存储目录 (包含 storage.json 与 state.vscdb)
207
- */
208
181
  export function findCursorDataDir(customDataPath, executablePath) {
209
182
  const config = new ConfigStore();
210
- // 1. 显式入参
211
183
  if (customDataPath && fs.existsSync(customDataPath)) {
212
184
  return customDataPath;
213
185
  }
214
- // 2. 环境变量
215
186
  const envData = process.env.CURSOR_DATA_DIR || process.env.CURSOR_STORAGE_DIR;
216
187
  if (envData && fs.existsSync(envData)) {
217
188
  return envData;
218
189
  }
219
- // 3. 用户偏好配置缓存
220
190
  const cachedDir = config.getCustomDataDir();
221
191
  if (cachedDir && fs.existsSync(cachedDir)) {
222
192
  return cachedDir;
@@ -237,7 +207,6 @@ export function findCursorDataDir(customDataPath, executablePath) {
237
207
  if (fs.existsSync(standardDir)) {
238
208
  return standardDir;
239
209
  }
240
- // 4. 便携版模式探测: 如果 Cursor 为绿色便携版,数据存储在可执行文件同级的 data/ 目录
241
210
  if (executablePath) {
242
211
  const exeDir = path.dirname(executablePath);
243
212
  const portableCandidates = [
@@ -252,7 +221,6 @@ export function findCursorDataDir(customDataPath, executablePath) {
252
221
  }
253
222
  }
254
223
  }
255
- // 5. Scoop 便携数据持久化目录
256
224
  if (platform === 'win32') {
257
225
  const scoopData = path.join(os.homedir(), 'scoop', 'persist', 'cursor', 'data', 'User', 'globalStorage');
258
226
  if (fs.existsSync(scoopData)) {
@@ -260,7 +228,6 @@ export function findCursorDataDir(customDataPath, executablePath) {
260
228
  return scoopData;
261
229
  }
262
230
  }
263
- // 6. Linux Snap 数据目录
264
231
  if (platform === 'linux') {
265
232
  const snapData = path.join(os.homedir(), 'snap', 'cursor', 'current', '.config', 'Cursor', 'User', 'globalStorage');
266
233
  if (fs.existsSync(snapData)) {
@@ -268,20 +235,34 @@ export function findCursorDataDir(customDataPath, executablePath) {
268
235
  return snapData;
269
236
  }
270
237
  }
271
- // 默认返回标准目录 (如果首次启动尚未生成,后续 StorageBridge 会自动 mkdirSync)
272
238
  return standardDir;
273
239
  }
274
- /**
275
- * 完整解析所有 Cursor 关键路径
276
- */
240
+ export function resolveSidecarPaths(storageOrDbPath, homeDir = process.env.CURSOR_SWITCH_HOME || os.homedir()) {
241
+ const globalStorageDir = path.dirname(storageOrDbPath);
242
+ const parentDir = path.dirname(globalStorageDir);
243
+ const userDataDir = path.basename(globalStorageDir).toLowerCase() === 'globalstorage' &&
244
+ path.basename(parentDir).toLowerCase() === 'user'
245
+ ? path.dirname(parentDir)
246
+ : globalStorageDir;
247
+ return {
248
+ globalStorageDir,
249
+ userDataDir,
250
+ machineIdFile: path.join(userDataDir, 'machineid'),
251
+ authJson: path.join(userDataDir, 'auth.json'),
252
+ localStateFile: path.join(userDataDir, 'Local State'),
253
+ cliConfigJson: path.join(homeDir, '.cursor', 'cli-config.json'),
254
+ };
255
+ }
277
256
  export function resolveCursorPaths(customPath, customExecPath) {
278
257
  const executablePath = findCursorExecutable(customExecPath);
279
258
  const dataDir = findCursorDataDir(customPath, executablePath);
280
259
  const storageJson = path.join(dataDir, 'storage.json');
281
260
  const sqliteDb = path.join(dataDir, 'state.vscdb');
261
+ const sidecars = resolveSidecarPaths(storageJson);
282
262
  return {
283
263
  storageJson,
284
264
  sqliteDb,
285
265
  executablePath,
266
+ ...sidecars,
286
267
  };
287
268
  }
@@ -1,8 +1,3 @@
1
- /**
2
- * 官网后台 (Cursor Dashboard) 免密直通模块
3
- * 原生 CDP 零依赖免密直通 (系统 Chrome/Edge/Chromium + CDP Cookie 物理注入)
4
- * 智能支持在当前已有独立浏览器实例 (如 Outlook) 中开新标签页,或开启全新独立隔离浏览器实例
5
- */
6
1
  import type { AccountInfo } from '../types.js';
7
2
  export interface DashboardOpenOptions {
8
3
  account?: AccountInfo;
@@ -11,24 +6,9 @@ export interface DashboardOpenOptions {
11
6
  cdpPort?: number;
12
7
  }
13
8
  export declare class DashboardLauncher {
14
- /**
15
- * 获取 Cursor 控制台专用独立隔离 Profile 目录
16
- */
17
9
  static getDashboardProfileDir(email: string): string;
18
- /**
19
- * 打开指定账号的 Cursor 官网后台 (免密直达)
20
- */
21
10
  static openDashboard(account: AccountInfo, options?: Partial<DashboardOpenOptions>): Promise<boolean>;
22
- /**
23
- * 直接通过 Token 凭据免密打开 Cursor 官网后台或指定页面
24
- */
25
11
  static openDashboardWithToken(token: string, email?: string, cdpPort?: number, targetUrl?: string): Promise<boolean>;
26
- /**
27
- * 核心逻辑:优先使用原生 CDP 独立浏览器免密注入,优雅降级到 Python 或默认浏览器
28
- */
29
12
  private static openWithCdpOrFallback;
30
- /**
31
- * 使用原生 CDP 启动独立 Chromium 浏览器并注入 Cookie 直达后台或指定页面
32
- */
33
13
  static openWithCdp(token: string, email: string, existingCdpPort?: number, targetUrl?: string): Promise<boolean>;
34
14
  }
@@ -1,19 +1,12 @@
1
- /**
2
- * 官网后台 (Cursor Dashboard) 免密直通模块
3
- * 原生 CDP 零依赖免密直通 (系统 Chrome/Edge/Chromium + CDP Cookie 物理注入)
4
- * 智能支持在当前已有独立浏览器实例 (如 Outlook) 中开新标签页,或开启全新独立隔离浏览器实例
5
- */
6
1
  import fs from 'node:fs';
7
2
  import path from 'node:path';
8
3
  import { spawn } from 'node:child_process';
9
4
  import chalk from 'chalk';
10
5
  import boxen from 'boxen';
11
6
  import { CdpEngine } from './cdp-engine.js';
12
- import { findInstalledBrowsers, openBrowserUrl, findPythonDashboardScript, getCookieInjectionSnippet } from '../utils/browser-utils.js';
7
+ import { TokenParser } from './token-parser.js';
8
+ import { findInstalledBrowsers, openBrowserUrl, getCookieInjectionSnippet } from '../utils/browser-utils.js';
13
9
  export class DashboardLauncher {
14
- /**
15
- * 获取 Cursor 控制台专用独立隔离 Profile 目录
16
- */
17
10
  static getDashboardProfileDir(email) {
18
11
  const safeName = email
19
12
  .trim()
@@ -29,9 +22,6 @@ export class DashboardLauncher {
29
22
  }
30
23
  return profileDir;
31
24
  }
32
- /**
33
- * 打开指定账号的 Cursor 官网后台 (免密直达)
34
- */
35
25
  static async openDashboard(account, options = {}) {
36
26
  const sessionToken = options.token ||
37
27
  account.workos_cursor_session_token ||
@@ -40,19 +30,12 @@ export class DashboardLauncher {
40
30
  const email = options.email || account.email || 'Cursor User';
41
31
  return this.openWithCdpOrFallback(sessionToken, email, options.cdpPort);
42
32
  }
43
- /**
44
- * 直接通过 Token 凭据免密打开 Cursor 官网后台或指定页面
45
- */
46
33
  static async openDashboardWithToken(token, email = 'Token User', cdpPort, targetUrl = 'https://cursor.com/cn/dashboard') {
47
34
  return this.openWithCdpOrFallback(token.trim(), email, cdpPort, targetUrl);
48
35
  }
49
- /**
50
- * 核心逻辑:优先使用原生 CDP 独立浏览器免密注入,优雅降级到 Python 或默认浏览器
51
- */
52
36
  static async openWithCdpOrFallback(sessionToken, email, cdpPort, targetUrl = 'https://cursor.com/cn/dashboard') {
53
37
  const dashboardUrl = targetUrl;
54
- const cleanToken = (sessionToken || '').trim().replace(/["\r\n]/g, '');
55
- // 1. 优先尝试:使用原生 CDP 引擎免密直达 (纯 Node.js,零依赖,秒开)
38
+ const cleanToken = TokenParser.extractWebSessionToken(sessionToken).replace(/["\r\n]/g, '');
56
39
  if (cleanToken) {
57
40
  try {
58
41
  const cdpSuccess = await this.openWithCdp(cleanToken, email, cdpPort, targetUrl);
@@ -61,34 +44,8 @@ export class DashboardLauncher {
61
44
  }
62
45
  }
63
46
  catch {
64
- // CDP 尝试失败,优雅降级至备选通道
65
47
  }
66
48
  }
67
- // 2. 备选通道:动态探测本地 Python 注入脚本
68
- const pyScript = findPythonDashboardScript();
69
- if (pyScript && cleanToken) {
70
- try {
71
- if (pyScript.endsWith('.cmd')) {
72
- const child = spawn('cmd.exe', ['/c', pyScript, '--token', cleanToken], {
73
- detached: true,
74
- stdio: 'ignore',
75
- });
76
- child.unref();
77
- return true;
78
- }
79
- else if (pyScript.endsWith('.py')) {
80
- const pyCmd = process.platform === 'win32' ? 'python' : 'python3';
81
- const child = spawn(pyCmd, [pyScript, '--token', cleanToken], {
82
- detached: true,
83
- stdio: 'ignore',
84
- });
85
- child.unref();
86
- return true;
87
- }
88
- }
89
- catch { }
90
- }
91
- // 3. 最终兜底:调起系统默认浏览器 + 打印 1 行 Console 快速注入指令
92
49
  const opened = await openBrowserUrl(dashboardUrl);
93
50
  if (cleanToken) {
94
51
  const snippet = getCookieInjectionSnippet(cleanToken);
@@ -112,9 +69,6 @@ export class DashboardLauncher {
112
69
  }
113
70
  return opened;
114
71
  }
115
- /**
116
- * 使用原生 CDP 启动独立 Chromium 浏览器并注入 Cookie 直达后台或指定页面
117
- */
118
72
  static async openWithCdp(token, email, existingCdpPort, targetUrl = 'https://cursor.com/cn/dashboard') {
119
73
  const installed = findInstalledBrowsers();
120
74
  const chrome = installed.find((b) => b.name.includes('Chrome'));
@@ -156,7 +110,6 @@ export class DashboardLauncher {
156
110
  });
157
111
  child.unref();
158
112
  }
159
- // 等待并连接 CDP
160
113
  const target = await CdpEngine.waitForPageTarget(cdpPort, 12000);
161
114
  if (!target || !target.webSocketDebuggerUrl) {
162
115
  return false;
@@ -165,7 +118,6 @@ export class DashboardLauncher {
165
118
  await cdp.connect(8000);
166
119
  await cdp.send('Page.enable');
167
120
  await cdp.send('Network.enable');
168
- // 1. 物理注入 Cursor Session Token Cookie (长期有效)
169
121
  await cdp.send('Network.setCookie', {
170
122
  name: 'WorkosCursorSessionToken',
171
123
  value: token,
@@ -176,7 +128,6 @@ export class DashboardLauncher {
176
128
  sameSite: 'Lax',
177
129
  expires: Math.floor(Date.now() / 1000) + 365 * 86400,
178
130
  });
179
- // 2. 注入默认中文语言环境
180
131
  await cdp.send('Network.setCookie', {
181
132
  name: 'NEXT_LOCALE',
182
133
  value: 'zh-CN',
@@ -184,7 +135,6 @@ export class DashboardLauncher {
184
135
  path: '/',
185
136
  expires: Math.floor(Date.now() / 1000) + 365 * 86400,
186
137
  });
187
- // 3. 导航到 Dashboard (若为已有浏览器实例,则新开标签页)
188
138
  if (isNewInstance) {
189
139
  await cdp.navigate(dashboardUrl);
190
140
  }
@@ -0,0 +1,57 @@
1
+ export type ExtractTier = 'pro' | 'pro_plus' | 'ultra' | 'team';
2
+ export declare function normalizeExtractTier(raw?: string): ExtractTier;
3
+ export interface ExtractOptions {
4
+ token: string;
5
+ tier?: ExtractTier;
6
+ cardCode: string;
7
+ yearly?: boolean;
8
+ portal?: boolean;
9
+ mock?: boolean;
10
+ apiBase?: string;
11
+ timeoutMs?: number;
12
+ }
13
+ export interface ExtractResult {
14
+ success: boolean;
15
+ tier?: string;
16
+ tierName?: string;
17
+ yearly?: boolean;
18
+ checkoutUrl?: string;
19
+ sessionId?: string;
20
+ customerId?: string;
21
+ accountEmail?: string;
22
+ remaining?: number;
23
+ used?: number;
24
+ maxUses?: number;
25
+ dedup?: boolean;
26
+ mode?: string;
27
+ latencyMs?: number;
28
+ status?: string;
29
+ error?: string;
30
+ suggestion?: string;
31
+ rawResponse?: any;
32
+ }
33
+ export interface ExtractKeyCheckResult {
34
+ valid: boolean;
35
+ max_uses?: number;
36
+ used_count?: number;
37
+ remaining?: number;
38
+ service_type?: string;
39
+ detail?: string;
40
+ }
41
+ export interface LinkVerifyResult {
42
+ valid: boolean;
43
+ httpStatus?: number;
44
+ isExpired?: boolean;
45
+ sessionUrl?: string;
46
+ status?: 'active' | 'expired' | 'invalid';
47
+ error?: string;
48
+ }
49
+ export declare function cleanCursorToken(rawToken: string): string;
50
+ export declare class ExtractClient {
51
+ private apiBase?;
52
+ constructor(apiBase?: string);
53
+ private static extractCsId;
54
+ checkKey(code: string, customApiBase?: string): Promise<ExtractKeyCheckResult>;
55
+ extractCheckoutLink(options: ExtractOptions): Promise<ExtractResult>;
56
+ verifyCheckoutLink(url: string, timeoutMs?: number): Promise<LinkVerifyResult>;
57
+ }