cursor-switch 1.0.0

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +161 -0
  3. package/SECURITY.md +38 -0
  4. package/bin/cswitch.js +35 -0
  5. package/dist/cli.d.ts +6 -0
  6. package/dist/cli.js +850 -0
  7. package/dist/core/account-store.d.ts +25 -0
  8. package/dist/core/account-store.js +182 -0
  9. package/dist/core/cdp-engine.d.ts +75 -0
  10. package/dist/core/cdp-engine.js +320 -0
  11. package/dist/core/config-store.d.ts +38 -0
  12. package/dist/core/config-store.js +100 -0
  13. package/dist/core/cursor-paths.d.ts +22 -0
  14. package/dist/core/cursor-paths.js +287 -0
  15. package/dist/core/dashboard-launcher.d.ts +34 -0
  16. package/dist/core/dashboard-launcher.js +210 -0
  17. package/dist/core/fingerprint.d.ts +7 -0
  18. package/dist/core/fingerprint.js +34 -0
  19. package/dist/core/oauth-receiver.d.ts +31 -0
  20. package/dist/core/oauth-receiver.js +849 -0
  21. package/dist/core/official-api.d.ts +29 -0
  22. package/dist/core/official-api.js +205 -0
  23. package/dist/core/outlook-launcher.d.ts +54 -0
  24. package/dist/core/outlook-launcher.js +671 -0
  25. package/dist/core/process-manager.d.ts +25 -0
  26. package/dist/core/process-manager.js +133 -0
  27. package/dist/core/pure-login-service.d.ts +67 -0
  28. package/dist/core/pure-login-service.js +550 -0
  29. package/dist/core/refund-client.d.ts +102 -0
  30. package/dist/core/refund-client.js +221 -0
  31. package/dist/core/refund-service.d.ts +39 -0
  32. package/dist/core/refund-service.js +384 -0
  33. package/dist/core/sqlite-bridge.d.ts +23 -0
  34. package/dist/core/sqlite-bridge.js +207 -0
  35. package/dist/core/storage-bridge.d.ts +18 -0
  36. package/dist/core/storage-bridge.js +99 -0
  37. package/dist/core/token-parser.d.ts +35 -0
  38. package/dist/core/token-parser.js +106 -0
  39. package/dist/core/update-checker.d.ts +62 -0
  40. package/dist/core/update-checker.js +231 -0
  41. package/dist/index.d.ts +17 -0
  42. package/dist/index.js +17 -0
  43. package/dist/menu.d.ts +12 -0
  44. package/dist/menu.js +2201 -0
  45. package/dist/types.d.ts +60 -0
  46. package/dist/types.js +5 -0
  47. package/dist/utils/browser-utils.d.ts +31 -0
  48. package/dist/utils/browser-utils.js +283 -0
  49. package/dist/utils/clipboard.d.ts +5 -0
  50. package/dist/utils/clipboard.js +48 -0
  51. package/dist/utils/live-menu.d.ts +26 -0
  52. package/dist/utils/live-menu.js +169 -0
  53. package/dist/utils/plan-formatter.d.ts +30 -0
  54. package/dist/utils/plan-formatter.js +153 -0
  55. package/dist/utils/prompt-utils.d.ts +40 -0
  56. package/dist/utils/prompt-utils.js +105 -0
  57. package/dist/utils/security.d.ts +6 -0
  58. package/dist/utils/security.js +27 -0
  59. package/dist/utils/table-renderer.d.ts +7 -0
  60. package/dist/utils/table-renderer.js +88 -0
  61. package/dist/utils/time-formatter.d.ts +13 -0
  62. package/dist/utils/time-formatter.js +83 -0
  63. package/package.json +53 -0
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Cursor 进程生命周期与安全互锁管理器
3
+ * 切换前检测进程,释放 SQLite 文件锁,切完后支持后台唤醒
4
+ */
5
+ export declare class ProcessManager {
6
+ private static cachedRunning;
7
+ private static lastCheckTime;
8
+ private static isChecking;
9
+ private static readonly CACHE_TTL_MS;
10
+ /**
11
+ * 检查 Cursor 进程当前是否正在运行
12
+ * @param forceFresh 是否强制同步检测 (如换号杀进程校验时使用),默认 false 走 0ms 高性能缓存
13
+ */
14
+ static isCursorRunning(forceFresh?: boolean): boolean;
15
+ private static checkSync;
16
+ private static triggerAsyncCheck;
17
+ /**
18
+ * 优雅或强制关闭 Cursor 进程,释放文件独占锁
19
+ */
20
+ static closeCursor(): Promise<boolean>;
21
+ /**
22
+ * 在后台独立拉起 Cursor IDE 进程
23
+ */
24
+ static launchCursor(executablePath?: string): boolean;
25
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Cursor 进程生命周期与安全互锁管理器
3
+ * 切换前检测进程,释放 SQLite 文件锁,切完后支持后台唤醒
4
+ */
5
+ import { execSync, spawn } from 'node:child_process';
6
+ export class ProcessManager {
7
+ static cachedRunning = false;
8
+ static lastCheckTime = 0;
9
+ static isChecking = false;
10
+ static CACHE_TTL_MS = 60000; // 60 秒超长缓存,绝不频繁唤起系统控制台子进程
11
+ /**
12
+ * 检查 Cursor 进程当前是否正在运行
13
+ * @param forceFresh 是否强制同步检测 (如换号杀进程校验时使用),默认 false 走 0ms 高性能缓存
14
+ */
15
+ static isCursorRunning(forceFresh = false) {
16
+ const now = Date.now();
17
+ // 1. 如果缓存尚未过期且不强制刷新,立即 0ms 返回缓存结果
18
+ if (!forceFresh && now - this.lastCheckTime < this.CACHE_TTL_MS) {
19
+ return this.cachedRunning;
20
+ }
21
+ // 2. 缓存已过 TTL 但非强制:先立即返回上次状态,同时在后台异步刷新,绝不阻塞 UI 渲染
22
+ if (!forceFresh && this.lastCheckTime > 0) {
23
+ if (!this.isChecking) {
24
+ this.triggerAsyncCheck();
25
+ }
26
+ return this.cachedRunning;
27
+ }
28
+ // 3. 首次冷启动或显式要求强制检测时同步执行
29
+ return this.checkSync();
30
+ }
31
+ static checkSync() {
32
+ this.lastCheckTime = Date.now();
33
+ try {
34
+ if (process.platform === 'win32') {
35
+ const stdout = execSync('tasklist /FI "IMAGENAME eq Cursor.exe"', {
36
+ encoding: 'utf8',
37
+ stdio: ['ignore', 'pipe', 'ignore'],
38
+ windowsHide: true,
39
+ });
40
+ this.cachedRunning = stdout.toLowerCase().includes('cursor.exe');
41
+ }
42
+ else {
43
+ // macOS / Linux: 严格使用 -x 精确匹配进程名,避免误杀或误判 cursor-switch 自身
44
+ const stdout = execSync('pgrep -x Cursor || pgrep -x cursor || true', {
45
+ encoding: 'utf8',
46
+ stdio: ['ignore', 'pipe', 'ignore'],
47
+ });
48
+ const pids = stdout.trim().split('\n').map((p) => p.trim()).filter(Boolean);
49
+ this.cachedRunning = pids.some((pid) => Number(pid) !== process.pid);
50
+ }
51
+ }
52
+ catch {
53
+ this.cachedRunning = false;
54
+ }
55
+ return this.cachedRunning;
56
+ }
57
+ static triggerAsyncCheck() {
58
+ this.isChecking = true;
59
+ const cmd = process.platform === 'win32'
60
+ ? spawn('tasklist', ['/FI', 'IMAGENAME eq Cursor.exe'], {
61
+ stdio: ['ignore', 'pipe', 'ignore'],
62
+ windowsHide: true,
63
+ })
64
+ : spawn('pgrep', ['-x', 'Cursor'], { stdio: ['ignore', 'pipe', 'ignore'] });
65
+ let stdout = '';
66
+ cmd.stdout?.on('data', (chunk) => {
67
+ stdout += chunk.toString();
68
+ });
69
+ cmd.on('close', (code) => {
70
+ this.isChecking = false;
71
+ this.lastCheckTime = Date.now();
72
+ if (process.platform === 'win32') {
73
+ this.cachedRunning = stdout.toLowerCase().includes('cursor.exe');
74
+ }
75
+ else {
76
+ const pids = stdout.trim().split('\n').map((p) => p.trim()).filter(Boolean);
77
+ this.cachedRunning = pids.some((pid) => Number(pid) !== process.pid);
78
+ }
79
+ });
80
+ cmd.on('error', () => {
81
+ this.isChecking = false;
82
+ });
83
+ }
84
+ /**
85
+ * 优雅或强制关闭 Cursor 进程,释放文件独占锁
86
+ */
87
+ static async closeCursor() {
88
+ if (!this.isCursorRunning(true)) {
89
+ this.cachedRunning = false;
90
+ this.lastCheckTime = Date.now();
91
+ return true;
92
+ }
93
+ try {
94
+ if (process.platform === 'win32') {
95
+ execSync('taskkill /F /IM Cursor.exe /T', { stdio: 'ignore' });
96
+ }
97
+ else {
98
+ // macOS / Linux: 严格精确匹配,禁止使用 pkill -i cursor 导致自杀
99
+ execSync('pkill -9 -x Cursor 2>/dev/null || pkill -9 -x cursor 2>/dev/null || true', { stdio: 'ignore' });
100
+ }
101
+ // 等待进程完全释放文件句柄
102
+ await new Promise((resolve) => setTimeout(resolve, 300));
103
+ const running = this.isCursorRunning(true);
104
+ this.cachedRunning = running;
105
+ this.lastCheckTime = Date.now();
106
+ return !running;
107
+ }
108
+ catch {
109
+ return false;
110
+ }
111
+ }
112
+ /**
113
+ * 在后台独立拉起 Cursor IDE 进程
114
+ */
115
+ static launchCursor(executablePath) {
116
+ if (!executablePath) {
117
+ return false;
118
+ }
119
+ try {
120
+ const child = spawn(executablePath, [], {
121
+ detached: true,
122
+ stdio: 'ignore',
123
+ });
124
+ child.unref();
125
+ this.cachedRunning = true;
126
+ this.lastCheckTime = Date.now();
127
+ return true;
128
+ }
129
+ catch {
130
+ return false;
131
+ }
132
+ }
133
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Cursor 动态纯净住宅 IP 自动代登与 Token 提取服务
3
+ * 直连海外 S 级原生家宽代理集群与 Rust Worker 算力节点
4
+ * 支持智能解构多段式格式、Turnstile 极速解盾、收件箱自动取码、Token 秒提与换号无缝联动
5
+ */
6
+ import { AccountStore } from './account-store.js';
7
+ import { StorageBridge } from './storage-bridge.js';
8
+ import { SqliteBridge } from './sqlite-bridge.js';
9
+ export interface ParsedAccount {
10
+ email: string;
11
+ emailPassword: string;
12
+ cursorPassword: string;
13
+ }
14
+ export declare class PureLoginService {
15
+ private configStore;
16
+ constructor();
17
+ /**
18
+ * 智能解析账号输入串 (支持 ----, ---, --, |, \t, 双空格, 逗号 等各类分隔符)
19
+ * 严格遵循规则:两段式第二段 100% 映射为邮箱密码用于自动收信取码
20
+ */
21
+ parseAccountString(raw: string): ParsedAccount;
22
+ /**
23
+ * 校验卡密有效性与剩余可用次数
24
+ */
25
+ checkKey(code: string): Promise<{
26
+ valid: boolean;
27
+ max_uses?: number;
28
+ used_count?: number;
29
+ remaining?: number;
30
+ detail?: string;
31
+ }>;
32
+ /**
33
+ * 启动纯净代登任务
34
+ */
35
+ startTask(params: {
36
+ code: string;
37
+ email: string;
38
+ emailPassword?: string;
39
+ cursorPassword?: string;
40
+ rawAccount?: string;
41
+ }): Promise<{
42
+ ok: boolean;
43
+ taskId?: string;
44
+ taskToken?: string;
45
+ remaining?: number;
46
+ detail?: string;
47
+ }>;
48
+ /**
49
+ * 提交 6 位邮箱验证码或短信验证码
50
+ */
51
+ submitOtp(taskId: string, cardCode: string, otpCode: string): Promise<{
52
+ ok: boolean;
53
+ token?: string;
54
+ email?: string;
55
+ detail?: string;
56
+ needsSmsCode?: boolean;
57
+ phoneMask?: string;
58
+ }>;
59
+ /**
60
+ * 自动从用户邮箱中提取最新 6 位数字验证码 (多轮自动拉取)
61
+ */
62
+ autoFetchMailCode(email: string, emailPassword: string, cursorPassword?: string): Promise<string | null>;
63
+ /**
64
+ * 交互式运行纯净代登全流程 (终端交互式 TUI)
65
+ */
66
+ runInteractiveFlow(store: AccountStore, storage: StorageBridge, sqlite: SqliteBridge, executablePath?: string): Promise<void>;
67
+ }