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,153 @@
1
+ /**
2
+ * 会员计划名称官方规范化映射工具
3
+ * 输出 Cursor 官方英文标准等级名称 (Free / Pro / Pro+ / Ultra / Team / Enterprise / Expired 等)
4
+ *
5
+ * 官方全档位体系矩阵:
6
+ * 👑 Ultra → Ultra
7
+ * ⚡ Pro+ → Pro+
8
+ * ⚡ Pro → Pro
9
+ * 👥 Team → Team
10
+ * 🏢 Enterprise → Enterprise
11
+ * 🎓 Student → Student
12
+ * 🎁 Trial → Trial
13
+ * 🆓 Free → Free
14
+ * ⚠️ Past Due → Past Due
15
+ * ❌ Expired → Expired
16
+ */
17
+ import chalk from 'chalk';
18
+ /**
19
+ * 将原始计划字符串解析为规范的标准档位
20
+ */
21
+ export function parsePlanTier(rawPlan) {
22
+ if (!rawPlan)
23
+ return 'free';
24
+ const clean = rawPlan.trim().toLowerCase();
25
+ const compact = clean.replace(/[\s_\-:]+/g, '');
26
+ if (clean === 'token_expired' || clean.includes('expired')) {
27
+ return 'token_expired';
28
+ }
29
+ if (clean.includes('past_due') || clean.includes('unpaid')) {
30
+ return 'past_due';
31
+ }
32
+ // Ultra 档位(最高个人档)
33
+ if (compact.includes('ultra')) {
34
+ return 'ultra';
35
+ }
36
+ // ⚠️ 极其关键:必须在 includes('pro') 之前判断 pro+ / pro_plus,否则会被抢先匹配为 Pro
37
+ if (compact.includes('proplus') ||
38
+ compact.includes('pro+') ||
39
+ compact === 'pro+' ||
40
+ clean.includes('pro_plus') ||
41
+ clean.includes('pro-plus')) {
42
+ return 'pro_plus';
43
+ }
44
+ // 团队 / 商业档位
45
+ if (compact.startsWith('team') || clean.includes('team') || clean.includes('business')) {
46
+ return 'team';
47
+ }
48
+ // 企业定制档位
49
+ if (clean.includes('enterprise')) {
50
+ return 'enterprise';
51
+ }
52
+ // 学生 / 教师教育档位
53
+ if (clean.includes('student') || clean.includes('edu')) {
54
+ return 'student';
55
+ }
56
+ // 试用档位
57
+ if (clean.includes('trial')) {
58
+ return 'trial';
59
+ }
60
+ // 标准 Pro 档位
61
+ if (compact.includes('pro') || compact === 'individualpro') {
62
+ return 'pro';
63
+ }
64
+ // 免费档位
65
+ if (clean.includes('free')) {
66
+ return 'free';
67
+ }
68
+ return 'free';
69
+ }
70
+ /**
71
+ * 会员计划名称格式化工具
72
+ * 输出 Cursor 官方英文规范等级名称 (Pro / Pro+ / Ultra / Team / Enterprise / Free 等)
73
+ */
74
+ export function formatPlanName(rawPlan, trialDays) {
75
+ if (!rawPlan)
76
+ return 'Free';
77
+ const tier = parsePlanTier(rawPlan);
78
+ const raw = rawPlan.trim();
79
+ let name = '';
80
+ switch (tier) {
81
+ case 'ultra':
82
+ name = 'Ultra';
83
+ break;
84
+ case 'pro_plus':
85
+ name = 'Pro+';
86
+ break;
87
+ case 'pro':
88
+ name = 'Pro';
89
+ break;
90
+ case 'team':
91
+ if (raw.toUpperCase().includes('ENTERPRISE')) {
92
+ name = 'Enterprise';
93
+ }
94
+ else {
95
+ name = 'Team';
96
+ }
97
+ break;
98
+ case 'enterprise':
99
+ name = 'Enterprise';
100
+ break;
101
+ case 'student':
102
+ name = 'Student';
103
+ break;
104
+ case 'trial':
105
+ name = 'Trial';
106
+ break;
107
+ case 'free':
108
+ name = 'Free';
109
+ break;
110
+ case 'past_due':
111
+ name = 'Past Due';
112
+ break;
113
+ case 'token_expired':
114
+ name = 'Expired';
115
+ break;
116
+ default:
117
+ name = raw;
118
+ }
119
+ if (typeof trialDays === 'number' && !Number.isNaN(trialDays) && trialDays > 0) {
120
+ return `${name} (${trialDays}d)`;
121
+ }
122
+ return name;
123
+ }
124
+ /**
125
+ * 具有专业色彩阶梯的终端高亮格式化
126
+ */
127
+ export function formatPlanBadge(rawPlan, trialDays) {
128
+ const tier = parsePlanTier(rawPlan);
129
+ const name = formatPlanName(rawPlan, trialDays);
130
+ switch (tier) {
131
+ case 'ultra':
132
+ return chalk.hex('#F59E0B').bold(name); // 金黄色尊享
133
+ case 'pro_plus':
134
+ return chalk.hex('#A855F7').bold(name); // 高贵紫进阶
135
+ case 'pro':
136
+ return chalk.hex('#3B82F6').bold(name); // 经典蓝专业
137
+ case 'team':
138
+ return chalk.hex('#10B981').bold(name); // 翡翠绿团队
139
+ case 'enterprise':
140
+ return chalk.hex('#EC4899').bold(name); // 玫瑰红企业
141
+ case 'student':
142
+ return chalk.hex('#06B6D4').bold(name); // 青蓝教育
143
+ case 'trial':
144
+ return chalk.hex('#818CF8')(name); // 试用靛蓝
145
+ case 'past_due':
146
+ return chalk.hex('#F97316')(name); // 警示橙
147
+ case 'token_expired':
148
+ return chalk.hex('#EF4444')(name); // 告警红
149
+ case 'free':
150
+ default:
151
+ return chalk.dim(name); // 极简灰
152
+ }
153
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 终端交互安全输入工具 (Safe Input Prompts)
3
+ * 统一提供 0、q、Esc 与直接回车一键返回能力,杜绝用户在任何输入框被卡死
4
+ */
5
+ export interface SafeInputOptions {
6
+ message: string;
7
+ default?: string;
8
+ canCancel?: boolean;
9
+ cancelHint?: string;
10
+ }
11
+ /**
12
+ * 安全文本输入:统一支持输入 0、q 或直接按回车取消并返回
13
+ * 若用户按 Ctrl+C,安全退出整个进程,绝不吞掉退出信号导致终端卡死
14
+ * 返回用户输入的有效字符串;用户取消时返回 null
15
+ */
16
+ export declare function safeInput(options: SafeInputOptions): Promise<string | null>;
17
+ /**
18
+ * 安全布尔确认输入:用户按 Ctrl+C 时确保立即退出并还原光标
19
+ */
20
+ export declare function safeConfirm(options: {
21
+ message: string;
22
+ default?: boolean;
23
+ }): Promise<boolean>;
24
+ /**
25
+ * 安全多选复选框输入:用户按 Ctrl+C 时确保立即退出并还原光标
26
+ */
27
+ export declare function safeCheckbox<T>(options: {
28
+ message: string;
29
+ choices: Array<{
30
+ name: string;
31
+ value: T;
32
+ checked?: boolean;
33
+ disabled?: boolean | string;
34
+ }>;
35
+ pageSize?: number;
36
+ }): Promise<T[]>;
37
+ /**
38
+ * 原生安全单键等待:按任意键或回车立即返回,自动擦除提示行,绝不污染终端历史
39
+ */
40
+ export declare function safePressAnyKey(message?: string): Promise<void>;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * 终端交互安全输入工具 (Safe Input Prompts)
3
+ * 统一提供 0、q、Esc 与直接回车一键返回能力,杜绝用户在任何输入框被卡死
4
+ */
5
+ import { input, confirm, checkbox } from '@inquirer/prompts';
6
+ import { createPrompt, useState, useKeypress } from '@inquirer/core';
7
+ import chalk from 'chalk';
8
+ /**
9
+ * 安全文本输入:统一支持输入 0、q 或直接按回车取消并返回
10
+ * 若用户按 Ctrl+C,安全退出整个进程,绝不吞掉退出信号导致终端卡死
11
+ * 返回用户输入的有效字符串;用户取消时返回 null
12
+ */
13
+ export async function safeInput(options) {
14
+ const { message, default: defaultVal, canCancel = true, cancelHint } = options;
15
+ const tip = canCancel ? chalk.dim(` (${cancelHint || '输入 0、q 或直接回车返回'})`) : '';
16
+ const promptMessage = `${message}${tip}:`;
17
+ try {
18
+ const answer = await input({
19
+ message: promptMessage,
20
+ default: defaultVal,
21
+ });
22
+ const trimmed = (answer || '').trim();
23
+ if (!trimmed || trimmed === '0' || trimmed.toLowerCase() === 'q') {
24
+ return null;
25
+ }
26
+ return trimmed;
27
+ }
28
+ catch (err) {
29
+ if (err?.name === 'ExitPromptError') {
30
+ process.stdout.write('\x1b[?25h\n');
31
+ process.exit(0);
32
+ }
33
+ throw err;
34
+ }
35
+ }
36
+ /**
37
+ * 安全布尔确认输入:用户按 Ctrl+C 时确保立即退出并还原光标
38
+ */
39
+ export async function safeConfirm(options) {
40
+ try {
41
+ return await confirm(options);
42
+ }
43
+ catch (err) {
44
+ if (err?.name === 'ExitPromptError') {
45
+ process.stdout.write('\x1b[?25h\n');
46
+ process.exit(0);
47
+ }
48
+ throw err;
49
+ }
50
+ }
51
+ /**
52
+ * 安全多选复选框输入:用户按 Ctrl+C 时确保立即退出并还原光标
53
+ */
54
+ export async function safeCheckbox(options) {
55
+ try {
56
+ return await checkbox(options);
57
+ }
58
+ catch (err) {
59
+ if (err?.name === 'ExitPromptError') {
60
+ process.stdout.write('\x1b[?25h\n');
61
+ process.exit(0);
62
+ }
63
+ throw err;
64
+ }
65
+ }
66
+ /**
67
+ * 内部基于 Inquirer 核心生命周期的按键监听器
68
+ * 绝不手动调用 process.stdin.setRawMode / data 事件,彻底终结 Windows 控制台 TTY 失活假死
69
+ */
70
+ const pressKeyPrompt = createPrompt((config, done) => {
71
+ const { message = '按回车或 Esc 键返回...' } = config;
72
+ const [status, setStatus] = useState('idle');
73
+ useKeypress((key) => {
74
+ if (status !== 'idle')
75
+ return;
76
+ // 无论何时敲击 Ctrl+C,瞬间恢复光标秒退进程
77
+ if (key.ctrl && key.name === 'c') {
78
+ process.stdout.write('\x1b[?25h\n');
79
+ process.exit(0);
80
+ }
81
+ setStatus('done');
82
+ done();
83
+ });
84
+ if (status === 'done') {
85
+ return '\x1b[?25h';
86
+ }
87
+ return `\n ${chalk.dim(message)}\x1b[?25l`;
88
+ });
89
+ /**
90
+ * 原生安全单键等待:按任意键或回车立即返回,自动擦除提示行,绝不污染终端历史
91
+ */
92
+ export async function safePressAnyKey(message = '按回车或 Esc 键返回...') {
93
+ if (!process.stdin.isTTY) {
94
+ return;
95
+ }
96
+ try {
97
+ await pressKeyPrompt({ message });
98
+ }
99
+ catch (err) {
100
+ if (err?.name === 'ExitPromptError') {
101
+ process.stdout.write('\x1b[?25h\n');
102
+ process.exit(0);
103
+ }
104
+ }
105
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 敏感信息脱敏与安全工具
3
+ * 终端打印 Token 时自动打码,防止录屏与截屏泄露隐私
4
+ */
5
+ export declare function maskToken(token: string | null | undefined): string;
6
+ export declare function maskEmail(email: string | null | undefined): string;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 敏感信息脱敏与安全工具
3
+ * 终端打印 Token 时自动打码,防止录屏与截屏泄露隐私
4
+ */
5
+ export function maskToken(token) {
6
+ if (!token)
7
+ return '--';
8
+ const trimmed = token.trim();
9
+ if (trimmed.length <= 16) {
10
+ return '***';
11
+ }
12
+ const prefix = trimmed.slice(0, 10);
13
+ const suffix = trimmed.slice(-6);
14
+ return `${prefix}...[已脱敏]...${suffix}`;
15
+ }
16
+ export function maskEmail(email) {
17
+ if (!email)
18
+ return '--';
19
+ const parts = email.split('@');
20
+ if (parts.length !== 2)
21
+ return email;
22
+ const [local, domain] = parts;
23
+ if (local.length <= 3) {
24
+ return `${local[0]}***@${domain}`;
25
+ }
26
+ return `${local.slice(0, 2)}***${local.slice(-1)}@${domain}`;
27
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 终端高颜值 ASCII 看板渲染器 (cli-table3 + chalk)
3
+ * 支持毫秒级解析、状态着色、进度条与 1 小时重订保护期醒目标注
4
+ */
5
+ import type { AccountInfo } from '../types.js';
6
+ export declare function renderProgressBar(usedPercent?: number, width?: number): string;
7
+ export declare function renderAccountTable(accounts: AccountInfo[]): string;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * 终端高颜值 ASCII 看板渲染器 (cli-table3 + chalk)
3
+ * 支持毫秒级解析、状态着色、进度条与 1 小时重订保护期醒目标注
4
+ */
5
+ import Table from 'cli-table3';
6
+ import chalk from 'chalk';
7
+ import { getExpiryStatus } from './time-formatter.js';
8
+ import { formatMachineIdSummary } from '../core/fingerprint.js';
9
+ import { formatPlanBadge } from './plan-formatter.js';
10
+ export function renderProgressBar(usedPercent = 0, width = 10) {
11
+ const safePercent = Math.max(0, Math.min(100, usedPercent));
12
+ const filled = Math.round((safePercent / 100) * width);
13
+ const empty = width - filled;
14
+ const bar = '█'.repeat(filled) + '░'.repeat(empty);
15
+ if (safePercent >= 90)
16
+ return chalk.red(`[${bar}]`);
17
+ if (safePercent >= 70)
18
+ return chalk.yellow(`[${bar}]`);
19
+ return chalk.green(`[${bar}]`);
20
+ }
21
+ export function renderAccountTable(accounts) {
22
+ if (!accounts || accounts.length === 0) {
23
+ return chalk.grey(' (暂无账号记录,可通过添加账号或收录本机快速录入)\n');
24
+ }
25
+ const table = new Table({
26
+ head: [
27
+ chalk.grey('序号'),
28
+ chalk.grey('状态'),
29
+ chalk.grey('账号邮箱'),
30
+ chalk.grey('会员级别'),
31
+ chalk.grey('请求余量'),
32
+ chalk.grey('到期时间'),
33
+ chalk.grey('状态 / 倒计时'),
34
+ chalk.grey('硬件指纹'),
35
+ ],
36
+ style: {
37
+ head: [],
38
+ border: ['grey'],
39
+ },
40
+ });
41
+ let hasGoldenWindow = false;
42
+ accounts.forEach((acc, index) => {
43
+ const isCurrent = !!acc.is_current;
44
+ const statusText = isCurrent ? chalk.green('● 在用') : chalk.grey('○ 空闲');
45
+ // 邮箱与别名
46
+ let emailDisplay = isCurrent ? chalk.bold.white(acc.email) : chalk.white(acc.email);
47
+ if (acc.username) {
48
+ emailDisplay += chalk.grey(` (${acc.username})`);
49
+ }
50
+ // 会员级别 (全档位专业色彩阶梯)
51
+ const planBadge = formatPlanBadge(acc.subscription_type);
52
+ // 用量
53
+ const usageObj = acc.current_period_usage?.planUsage;
54
+ const totalPercent = usageObj?.totalPercentUsed ?? 0;
55
+ const bar = renderProgressBar(totalPercent, 8);
56
+ const limit = usageObj?.limit ?? 500;
57
+ const remain = usageObj?.remaining ?? Math.round(limit * (1 - totalPercent / 100));
58
+ const usageDisplay = `${bar} ${remain}/${limit}`;
59
+ // 到期时间与状态
60
+ const cycleEnd = acc.current_period_usage?.billingCycleEnd;
61
+ const expiry = getExpiryStatus(cycleEnd);
62
+ let countdownDisplay = chalk.blue(expiry.countdownText);
63
+ if (expiry.isInRenewalWindow) {
64
+ hasGoldenWindow = true;
65
+ countdownDisplay = chalk.bgRed.white.bold(` ${expiry.countdownText} `);
66
+ }
67
+ else if (expiry.isExpired) {
68
+ countdownDisplay = chalk.grey(expiry.countdownText);
69
+ }
70
+ const machineSummary = formatMachineIdSummary(acc.machine_ids);
71
+ table.push([
72
+ chalk.grey(String(index + 1)),
73
+ statusText,
74
+ emailDisplay,
75
+ planBadge,
76
+ usageDisplay,
77
+ chalk.grey(expiry.formattedDate),
78
+ countdownDisplay,
79
+ chalk.magenta(machineSummary),
80
+ ]);
81
+ });
82
+ let output = '';
83
+ if (hasGoldenWindow) {
84
+ output += chalk.bgYellow.black.bold(' 提示 ') + chalk.yellow(' 发现账号正处于「1小时黄金重订保护期」,请及时续订以保留权益\n\n');
85
+ }
86
+ output += table.toString() + '\n';
87
+ return output;
88
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 时间与倒计时工具
3
+ * 精确到秒,支持 Cursor 订阅到期「1小时重订黄金窗口期」智能判定
4
+ */
5
+ export interface ExpiryStatus {
6
+ formattedDate: string;
7
+ countdownText: string;
8
+ isInRenewalWindow: boolean;
9
+ isExpired: boolean;
10
+ statusBadge: string;
11
+ }
12
+ export declare function formatTimestamp(ts: number | string | undefined | null): string;
13
+ export declare function getExpiryStatus(cycleEnd: number | string | undefined | null): ExpiryStatus;
@@ -0,0 +1,83 @@
1
+ /**
2
+ * 时间与倒计时工具
3
+ * 精确到秒,支持 Cursor 订阅到期「1小时重订黄金窗口期」智能判定
4
+ */
5
+ export function formatTimestamp(ts) {
6
+ if (!ts)
7
+ return '--';
8
+ const num = typeof ts === 'string' ? Number(ts) : ts;
9
+ if (isNaN(num) || num <= 0)
10
+ return '--';
11
+ // 处理秒级和毫秒级时间戳
12
+ const date = new Date(num < 1e11 ? num * 1000 : num);
13
+ if (isNaN(date.getTime()))
14
+ return '--';
15
+ const Y = date.getFullYear();
16
+ const M = String(date.getMonth() + 1).padStart(2, '0');
17
+ const D = String(date.getDate()).padStart(2, '0');
18
+ const h = String(date.getHours()).padStart(2, '0');
19
+ const m = String(date.getMinutes()).padStart(2, '0');
20
+ const s = String(date.getSeconds()).padStart(2, '0');
21
+ return `${Y}-${M}-${D} ${h}:${m}:${s}`;
22
+ }
23
+ export function getExpiryStatus(cycleEnd) {
24
+ if (!cycleEnd) {
25
+ return {
26
+ formattedDate: '--',
27
+ countdownText: '无订阅记录',
28
+ isInRenewalWindow: false,
29
+ isExpired: false,
30
+ statusBadge: '○ 未知',
31
+ };
32
+ }
33
+ const num = typeof cycleEnd === 'string' ? Number(cycleEnd) : cycleEnd;
34
+ const targetMs = num < 1e11 ? num * 1000 : num;
35
+ const formattedDate = formatTimestamp(targetMs);
36
+ const nowMs = Date.now();
37
+ const diffMs = targetMs - nowMs;
38
+ const ONE_HOUR_MS = 60 * 60 * 1000;
39
+ // 1. 尚未到期
40
+ if (diffMs > 0) {
41
+ const totalSeconds = Math.floor(diffMs / 1000);
42
+ const days = Math.floor(totalSeconds / 86400);
43
+ const hours = Math.floor((totalSeconds % 86400) / 3600);
44
+ const minutes = Math.floor((totalSeconds % 3600) / 60);
45
+ const seconds = totalSeconds % 60;
46
+ const pad = (n) => String(n).padStart(2, '0');
47
+ let text = `剩余 `;
48
+ if (days > 0)
49
+ text += `${days}天 `;
50
+ text += `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
51
+ return {
52
+ formattedDate,
53
+ countdownText: text,
54
+ isInRenewalWindow: false,
55
+ isExpired: false,
56
+ statusBadge: '● 正常',
57
+ };
58
+ }
59
+ // 2. 处于到期后 1 小时内(黄金重订窗口期)
60
+ if (diffMs <= 0 && diffMs >= -ONE_HOUR_MS) {
61
+ const passedSeconds = Math.abs(Math.floor(diffMs / 1000));
62
+ const passedMin = Math.floor(passedSeconds / 60);
63
+ const passedSec = passedSeconds % 60;
64
+ const remainWindowSec = 3600 - passedSeconds;
65
+ const remainWindowMin = Math.floor(remainWindowSec / 60);
66
+ return {
67
+ formattedDate,
68
+ countdownText: `重订保护期 (逾期 ${passedMin}分,剩 ${remainWindowMin}分)`,
69
+ isInRenewalWindow: true,
70
+ isExpired: true,
71
+ statusBadge: '● 保护期',
72
+ };
73
+ }
74
+ // 3. 超过 1 小时已完全失效
75
+ const passedDays = Math.floor(Math.abs(diffMs) / (86400 * 1000));
76
+ return {
77
+ formattedDate,
78
+ countdownText: `已失效 (逾期 ${passedDays > 0 ? passedDays + '天' : '数小时'})`,
79
+ isInRenewalWindow: false,
80
+ isExpired: true,
81
+ statusBadge: '○ 已失效',
82
+ };
83
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "cursor-switch",
3
+ "version": "1.0.0",
4
+ "description": "极速、安全、纯本地运行的 Cursor IDE 多账号管理与防封虚拟机器指纹切换纯命令行工具",
5
+ "author": "aozai",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "bin": {
10
+ "cswitch": "bin/cswitch.js",
11
+ "cursor-switch": "bin/cswitch.js"
12
+ },
13
+ "files": [
14
+ "bin",
15
+ "dist",
16
+ "README.md",
17
+ "SECURITY.md",
18
+ "LICENSE"
19
+ ],
20
+ "keywords": [
21
+ "cursor",
22
+ "cursor-ai",
23
+ "cursor-ide",
24
+ "cursor-switch",
25
+ "account-manager",
26
+ "machine-id",
27
+ "cli",
28
+ "local-first",
29
+ "pure-cli"
30
+ ],
31
+ "engines": {
32
+ "node": ">=18.0.0"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc",
36
+ "watch": "tsc --watch",
37
+ "start": "node ./bin/cswitch.js",
38
+ "prepublishOnly": "npm run build"
39
+ },
40
+ "dependencies": {
41
+ "@inquirer/core": "^10.3.2",
42
+ "@inquirer/prompts": "^7.2.1",
43
+ "boxen": "^8.0.1",
44
+ "chalk": "^5.4.1",
45
+ "cli-table3": "^0.6.5",
46
+ "commander": "^13.1.0",
47
+ "open": "^10.1.0"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^24.0.0",
51
+ "typescript": "^5.7.3"
52
+ }
53
+ }