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.
- 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 -241
- 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 +0 -20
- package/dist/core/dashboard-launcher.js +3 -53
- 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 -31
- package/dist/core/outlook-launcher.js +194 -248
- 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 +54 -38
- package/dist/core/pure-login-service.js +483 -395
- 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 -548
- 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
- package/dist/core/welcome-offer-service.d.ts +0 -52
- package/dist/core/welcome-offer-service.js +0 -369
package/dist/menu.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 适合中国人习惯的 TUI 终端交互式主菜单
|
|
3
|
-
* 基于 @inquirer/prompts + chalk + boxen 打造
|
|
4
|
-
*/
|
|
5
1
|
import chalk from 'chalk';
|
|
6
2
|
import boxen from 'boxen';
|
|
7
|
-
import { liveMenu, quickSelect, Separator } from './utils/live-menu.js';
|
|
3
|
+
import { liveMenu, quickSelect, Separator, leaveAltScreenIfActive, measureAnsiWidth, computeHudInnerWidth, } from './utils/live-menu.js';
|
|
8
4
|
import { AccountStore } from './core/account-store.js';
|
|
9
5
|
import { resolveCursorPaths, findCursorExecutable } from './core/cursor-paths.js';
|
|
10
6
|
import { ConfigStore } from './core/config-store.js';
|
|
@@ -16,18 +12,22 @@ import { OutlookLauncher } from './core/outlook-launcher.js';
|
|
|
16
12
|
import { OAuthReceiver } from './core/oauth-receiver.js';
|
|
17
13
|
import { TokenParser } from './core/token-parser.js';
|
|
18
14
|
import { generateMachineIds, formatMachineIdSummary } from './core/fingerprint.js';
|
|
19
|
-
import {
|
|
15
|
+
import { applyMachineIdsToCursor, executeAccountSwitch, readLocalCursorAuth, } from './core/switch-orchestrator.js';
|
|
16
|
+
import { applyParsedCredentialToAccount, buildOAuthAccountInfo, upgradeAccountWebTokenOnIngest, } from './core/token-exchange.js';
|
|
20
17
|
import { renderAccountTable } from './utils/table-renderer.js';
|
|
21
18
|
import { getExpiryStatus } from './utils/time-formatter.js';
|
|
22
19
|
import { maskToken } from './utils/security.js';
|
|
23
20
|
import { formatPlanName, formatPlanBadge } from './utils/plan-formatter.js';
|
|
21
|
+
import { printFactualTokenStatus, printIngestUpgradeResult, resolveStaleSwitchWithHealing, } from './utils/token-preflight-ui.js';
|
|
22
|
+
import { copyPreferredAccountCredential, printExtractedCredentialsResult, runInteractiveCopyAccountMenu, } from './utils/credential-bundle-ui.js';
|
|
24
23
|
import { RefundService } from './core/refund-service.js';
|
|
24
|
+
import { ExtractService } from './core/extract-service.js';
|
|
25
|
+
import { handleExtractCheckoutMenu } from './core/extract-menu.js';
|
|
25
26
|
import { PureLoginService } from './core/pure-login-service.js';
|
|
26
27
|
import { OfficialApiClient } from './core/official-api.js';
|
|
27
28
|
import { safeInput, safeConfirm, safeCheckbox, safePressAnyKey } from './utils/prompt-utils.js';
|
|
28
|
-
import { UpdateChecker, CURRENT_VERSION } from './core/update-checker.js';
|
|
29
|
-
import {
|
|
30
|
-
import { WelcomeOfferService } from './core/welcome-offer-service.js';
|
|
29
|
+
import { UpdateChecker, CURRENT_VERSION, IS_PRIVATE_EDITION } from './core/update-checker.js';
|
|
30
|
+
import { importAccountsFromText } from './utils/account-text-importer.js';
|
|
31
31
|
import fs from 'node:fs';
|
|
32
32
|
export async function runInteractiveMenu() {
|
|
33
33
|
const store = new AccountStore();
|
|
@@ -35,19 +35,118 @@ export async function runInteractiveMenu() {
|
|
|
35
35
|
const storage = new StorageBridge(paths.storageJson);
|
|
36
36
|
const sqlite = new SqliteBridge(paths.sqliteDb);
|
|
37
37
|
const updateChecker = new UpdateChecker();
|
|
38
|
-
// 循环运行主菜单,直到用户选择退出
|
|
39
38
|
while (true) {
|
|
40
|
-
console.clear();
|
|
41
39
|
const accounts = store.loadAll();
|
|
42
|
-
const
|
|
40
|
+
const localAuth = await readLocalCursorAuth(storage, sqlite);
|
|
41
|
+
const currentEmail = localAuth.email || '未登录';
|
|
43
42
|
const currentAcc = accounts.find((a) => a.email.toLowerCase() === currentEmail.toLowerCase());
|
|
44
|
-
// 0ms 读取本地版本更新缓存 (若超期则自动在后台静默发起异步检查)
|
|
45
43
|
const updateInfo = await updateChecker.check(false);
|
|
46
44
|
const planType = formatPlanName(currentAcc?.subscription_type);
|
|
47
45
|
const cycleEnd = currentAcc?.current_period_usage?.billingCycleEnd;
|
|
48
46
|
const planBadge = `[${formatPlanBadge(currentAcc?.subscription_type)}]`;
|
|
49
47
|
const devId = currentAcc?.machine_ids ? formatMachineIdSummary(currentAcc.machine_ids) : '--';
|
|
50
|
-
|
|
48
|
+
const menuChoices = [
|
|
49
|
+
{
|
|
50
|
+
name: '1. 切换账号',
|
|
51
|
+
value: 'switch',
|
|
52
|
+
hint: '一键切换登录账号,自动绑定专属防封设备码',
|
|
53
|
+
shortHint: '一键切换登录账号与防封设备码',
|
|
54
|
+
description: '切换 Cursor 登录账号,自动绑定该账号的专属防关联设备码',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: '2. 添加与管理账号',
|
|
58
|
+
value: 'add',
|
|
59
|
+
hint: '添加新账号、粘贴 Token、批量导入或删除',
|
|
60
|
+
shortHint: '添加、批量导入或管理本地账号',
|
|
61
|
+
description: '支持网页登录、粘贴 Token、批量导入或删除本地保存的账号',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: '3. 账号看板与搜索',
|
|
65
|
+
value: 'radar',
|
|
66
|
+
hint: '查看各账号会员级别、剩余用量与到期时间',
|
|
67
|
+
shortHint: '查看各账号会员级别与剩余用量',
|
|
68
|
+
description: '一屏浏览所有本地账号的会员类型、高级请求余量与到期时间',
|
|
69
|
+
},
|
|
70
|
+
new Separator(),
|
|
71
|
+
{
|
|
72
|
+
name: '4. 用 Token 打开 Cursor 官网控制台',
|
|
73
|
+
value: 'dashboard',
|
|
74
|
+
hint: '免密打开当前账号的 Cursor 官网管理后台',
|
|
75
|
+
shortHint: '免密打开当前账号官网后台',
|
|
76
|
+
description: '调起独立浏览器免密登录,直接查看当前账号的官网设置与订阅用量',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: '5. 打开 Outlook 邮箱 (自动登录 · m)',
|
|
80
|
+
value: 'outlook_mail',
|
|
81
|
+
key: 'm',
|
|
82
|
+
hint: '调起独立浏览器并自动填密登录 Outlook (按 m)',
|
|
83
|
+
shortHint: '自动填密登录 Outlook 网页邮箱',
|
|
84
|
+
description: '调起独立浏览器窗口,自动填入邮箱密码登录 Outlook 查收邮件 (按 m 直达)',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: '6. 提取本机或网页 Token',
|
|
88
|
+
value: 'extract',
|
|
89
|
+
hint: '一键读取当前已登 Token,或登录提取新凭据',
|
|
90
|
+
shortHint: '读取本机或浏览器登录提取 Token',
|
|
91
|
+
description: '读取本机 Cursor 当前登录的 Token 凭据,或打开浏览器重新登录提取',
|
|
92
|
+
},
|
|
93
|
+
new Separator(),
|
|
94
|
+
{
|
|
95
|
+
name: '7. Cursor 退款服务',
|
|
96
|
+
value: 'refund',
|
|
97
|
+
hint: '使用退款卡密办理退款,自动退回 Free 免费版',
|
|
98
|
+
shortHint: '使用卡密办理退款并退回免费版',
|
|
99
|
+
description: '输入退款卡密办理自助退款,账号自动解除订阅并退回 Free 免费版',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: '8. 提取老套餐付款链接',
|
|
103
|
+
value: 'extract_checkout',
|
|
104
|
+
hint: '使用提链卡密生成官方老套餐支付宝付款链接',
|
|
105
|
+
shortHint: '使用提链卡密生成老套餐付款链接',
|
|
106
|
+
description: '使用提链卡密生成官方老套餐(支持支付宝)付款直链(成功才扣次)',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: '9. Cursor 纯净代登',
|
|
110
|
+
value: 'pure_login',
|
|
111
|
+
hint: '通过纯净海外网络辅助登录,安全换取 60 天 Token',
|
|
112
|
+
shortHint: '通过纯净代理辅助登录换取 Token',
|
|
113
|
+
description: '在纯净海外网络环境下辅助完成登录与验证码校验,换取 60 天长效 Token',
|
|
114
|
+
},
|
|
115
|
+
new Separator(),
|
|
116
|
+
{
|
|
117
|
+
name: '10. 硬件指纹管理',
|
|
118
|
+
value: 'fingerprint',
|
|
119
|
+
hint: '查看当前设备标识码,或一键重置全新防封硬件码',
|
|
120
|
+
shortHint: '查看或重置本机防封设备硬件码',
|
|
121
|
+
description: '查看当前设备标识码(Machine ID),或一键重置为全新的独立防封硬件指纹',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: '11. 快照安全备份',
|
|
125
|
+
value: 'backup',
|
|
126
|
+
hint: '一键备份或恢复本地账号数据与客户端配置文件',
|
|
127
|
+
shortHint: '一键备份或恢复本地账号与配置',
|
|
128
|
+
description: '为本地账号列表与 Cursor 核心配置文件创建安全备份,支持随时一键还原',
|
|
129
|
+
},
|
|
130
|
+
new Separator(),
|
|
131
|
+
{
|
|
132
|
+
name: updateInfo.hasUpdate
|
|
133
|
+
? `u. 检查更新 / 立即升级 ${chalk.green.bold(`(新版 v${updateInfo.latestVersion})`)}`
|
|
134
|
+
: 'u. 检查更新 / 立即升级',
|
|
135
|
+
value: 'upgrade',
|
|
136
|
+
key: 'u',
|
|
137
|
+
hint: '在线检查最新版本,并支持一键自动更新 (按 u)',
|
|
138
|
+
shortHint: '检查是否有新版本并一键自动更新',
|
|
139
|
+
description: '在线检测最新版本,支持一键平滑自动更新升级 (按 u 直达)',
|
|
140
|
+
},
|
|
141
|
+
new Separator(),
|
|
142
|
+
{
|
|
143
|
+
name: '0. 退出程序',
|
|
144
|
+
value: 'exit',
|
|
145
|
+
hint: '关闭交互式菜单,安全返回系统命令行终端',
|
|
146
|
+
shortHint: '关闭菜单,返回命令行终端',
|
|
147
|
+
description: '退出 Cursor-Switch 交互菜单,安全返回系统终端',
|
|
148
|
+
},
|
|
149
|
+
];
|
|
51
150
|
const getHeader = () => {
|
|
52
151
|
const expiry = getExpiryStatus(cycleEnd);
|
|
53
152
|
const isRunning = ProcessManager.isCursorRunning();
|
|
@@ -56,19 +155,31 @@ export async function runInteractiveMenu() {
|
|
|
56
155
|
? chalk.bgRed.white.bold(` ${expiry.countdownText} `)
|
|
57
156
|
: chalk.cyan(expiry.countdownText);
|
|
58
157
|
const updateNotice = updateInfo.hasUpdate
|
|
59
|
-
? `\n ${chalk.bgYellow.black.bold(' 发现新版 ')}
|
|
158
|
+
? `\n ${chalk.bgYellow.black.bold(' 发现新版 ')} ${chalk.bold.yellow(`v${updateInfo.latestVersion}`)} ${chalk.dim('按 [u] 一键升级')}`
|
|
60
159
|
: '';
|
|
160
|
+
const accLine = ` 当前账号 : ${chalk.bold.white(currentEmail)} ${planBadge}`;
|
|
161
|
+
const expLine = ` 到期时间 : ${chalk.white(expiry.formattedDate)} ${expiryPill}`;
|
|
162
|
+
const fpLine = ` 设备指纹 : ${chalk.cyan(devId)} ${chalk.dim('(独立隔离)')} ${chalk.dim('Cursor:')} ${cursorTag}`;
|
|
163
|
+
const cols = process.stdout.columns || 84;
|
|
164
|
+
const modeBadge = IS_PRIVATE_EDITION
|
|
165
|
+
? `${chalk.green('●')} ${chalk.green('本地私有增强版')}`
|
|
166
|
+
: `${chalk.green('●')} ${chalk.green('纯本地运行 · 离线安全')}`;
|
|
167
|
+
const leftTitle = `${chalk.bold.cyan('CURSOR-SWITCH')} ${chalk.dim('v' + CURRENT_VERSION)}`;
|
|
168
|
+
const minHeaderWidth = measureAnsiWidth(leftTitle) + 2 + measureAnsiWidth(modeBadge);
|
|
169
|
+
const minHudContentWidth = Math.max(minHeaderWidth, measureAnsiWidth(accLine), measureAnsiWidth(expLine), measureAnsiWidth(fpLine));
|
|
170
|
+
const innerWidth = computeHudInnerWidth(menuChoices, cols, minHudContentWidth);
|
|
171
|
+
const titleGap = Math.max(2, innerWidth - measureAnsiWidth(leftTitle) - measureAnsiWidth(modeBadge));
|
|
61
172
|
const bannerText = [
|
|
62
|
-
`${
|
|
63
|
-
chalk.dim('
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
173
|
+
`${leftTitle}${' '.repeat(titleGap)}${modeBadge}`,
|
|
174
|
+
chalk.dim('─'.repeat(innerWidth)),
|
|
175
|
+
accLine,
|
|
176
|
+
expLine,
|
|
177
|
+
fpLine,
|
|
67
178
|
].join('\n') + updateNotice;
|
|
68
179
|
return boxen(bannerText, {
|
|
69
180
|
padding: { top: 0, bottom: 0, left: 1, right: 1 },
|
|
70
181
|
margin: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
71
|
-
borderColor: updateInfo.hasUpdate ? 'yellow' : '
|
|
182
|
+
borderColor: updateInfo.hasUpdate ? 'yellow' : 'cyan',
|
|
72
183
|
borderStyle: 'round',
|
|
73
184
|
});
|
|
74
185
|
};
|
|
@@ -77,73 +188,30 @@ export async function runInteractiveMenu() {
|
|
|
77
188
|
action = await liveMenu({
|
|
78
189
|
getHeader,
|
|
79
190
|
message: '操作菜单:',
|
|
80
|
-
choices:
|
|
81
|
-
|
|
82
|
-
{ name: '2. 添加与管理账号', value: 'add', description: '录入新账号 (Token/代登/截获) 或清理删除已有旧账号' },
|
|
83
|
-
{ name: '3. 账号看板与搜索', value: 'radar', description: '查看额度余量、到期倒计时、模糊检索与账号删除清理' },
|
|
84
|
-
new Separator(),
|
|
85
|
-
{ name: '4. 打开 Cursor 官网控制台 (用 Token 免密直达)', value: 'dashboard', description: '注入当前账号 Token 免密调起独立浏览器,直达 Cursor 官网控制台与设置页' },
|
|
86
|
-
{
|
|
87
|
-
name: '5. 打开 Outlook 邮箱 (独立浏览器自动登录)',
|
|
88
|
-
value: 'outlook_mail',
|
|
89
|
-
key: 'm',
|
|
90
|
-
description: '全新独立隔离浏览器实例,自动登录 Outlook 邮箱,遇辅助邮箱/安全验证自动停下交接 (按 m 快捷直达)',
|
|
91
|
-
},
|
|
92
|
-
{ name: '6. 提取 Token (本地浏览器)', value: 'extract', description: '智能读取本机 Cursor 已登 Token,或调起本地无痕浏览器抓取 Token 凭据' },
|
|
93
|
-
new Separator(),
|
|
94
|
-
{ name: '7. 奥仔退款', value: 'refund', description: '席位退款处理,账号退出并恢复为 Free 免费状态' },
|
|
95
|
-
{ name: '8. 纯净代登', value: 'pure_login', description: '远程调用海外纯净住宅 IP 云端代登,自动过盾收码并秒提 Token' },
|
|
96
|
-
{
|
|
97
|
-
name: '9. 回归资格检测',
|
|
98
|
-
value: 'welcome_offer',
|
|
99
|
-
key: 'o',
|
|
100
|
-
description: '检测老号是否命中 Cursor 回归优惠,支持粘贴 Token 或自动代登复活,免密直达激活 (按 o 快捷直达)',
|
|
101
|
-
},
|
|
102
|
-
new Separator(),
|
|
103
|
-
{ name: '10. 硬件指纹管理', value: 'fingerprint', description: '查看或重置专属防封虚拟硬件码' },
|
|
104
|
-
{ name: '11. 快照安全备份', value: 'backup', description: '安全备份本地配置与 SQLite 数据库' },
|
|
105
|
-
{
|
|
106
|
-
name: 'g. 打开 AI 折腾局官网 (getdoubao.com)',
|
|
107
|
-
value: 'website',
|
|
108
|
-
key: 'g',
|
|
109
|
-
description: '调起浏览器直达 AI 折腾局官网,查看折腾手册、开源工具与卡网服务 (按 g 快捷直达)',
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: 'q. 官方 QQ 交流群 (群号: 1007446249)',
|
|
113
|
-
value: 'qq_group',
|
|
114
|
-
key: 'q',
|
|
115
|
-
description: '加入官方交流群,自动将群号复制到剪贴板,支持答疑、交流与售后 (按 q 快捷直达)',
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
name: updateInfo.hasUpdate
|
|
119
|
-
? `u. 检查更新 / 立即升级 ${chalk.green.bold(`(有新版 v${updateInfo.latestVersion})`)}`
|
|
120
|
-
: 'u. 检查更新 / 立即升级',
|
|
121
|
-
value: 'upgrade',
|
|
122
|
-
key: 'u',
|
|
123
|
-
description: '在线检查新版本,支持从官方及国内镜像全自动一键自更新 (按 u 快捷直达)',
|
|
124
|
-
},
|
|
125
|
-
new Separator(),
|
|
126
|
-
{ name: '0. 退出程序', value: 'exit', description: '结束运行并返回终端' },
|
|
127
|
-
],
|
|
128
|
-
pageSize: 22,
|
|
191
|
+
choices: menuChoices,
|
|
192
|
+
pageSize: 26,
|
|
129
193
|
tickIntervalMs: 1000,
|
|
194
|
+
altScreen: true,
|
|
130
195
|
});
|
|
131
196
|
}
|
|
132
197
|
catch (err) {
|
|
133
198
|
if (err?.name === 'ExitPromptError') {
|
|
199
|
+
leaveAltScreenIfActive();
|
|
134
200
|
process.stdout.write('\x1b[?25h\n');
|
|
135
|
-
console.log(chalk.grey('\n
|
|
136
|
-
console.log(chalk.dim('官方交流群: 1007446249 | 官网: https://getdoubao.com\n'));
|
|
201
|
+
console.log(chalk.grey('\n已退出 Cursor-Switch。\n'));
|
|
137
202
|
process.exit(0);
|
|
138
203
|
}
|
|
139
204
|
throw err;
|
|
140
205
|
}
|
|
141
206
|
if (action === 'exit') {
|
|
207
|
+
leaveAltScreenIfActive();
|
|
142
208
|
process.stdout.write('\x1b[?25h\n');
|
|
143
|
-
console.log(chalk.grey('\n
|
|
144
|
-
console.log(chalk.dim('官方交流群: 1007446249 | 官网: https://getdoubao.com\n'));
|
|
209
|
+
console.log(chalk.grey('\n已退出 Cursor-Switch。\n'));
|
|
145
210
|
process.exit(0);
|
|
146
211
|
}
|
|
212
|
+
if (process.stdout.isTTY) {
|
|
213
|
+
console.clear();
|
|
214
|
+
}
|
|
147
215
|
try {
|
|
148
216
|
if (action === 'switch') {
|
|
149
217
|
await handleSwitchMenu(store, storage, sqlite, paths.executablePath);
|
|
@@ -163,34 +231,29 @@ export async function runInteractiveMenu() {
|
|
|
163
231
|
else if (action === 'refund') {
|
|
164
232
|
await handleRefundMenu(store, currentAcc);
|
|
165
233
|
}
|
|
234
|
+
else if (action === 'extract_checkout') {
|
|
235
|
+
await handleExtractCheckoutMenu(store, currentAcc);
|
|
236
|
+
}
|
|
166
237
|
else if (action === 'pure_login') {
|
|
167
238
|
const pureService = new PureLoginService();
|
|
168
239
|
await pureService.runInteractiveFlow(store, storage, sqlite, paths.executablePath);
|
|
169
240
|
}
|
|
170
|
-
else if (action === 'welcome_offer') {
|
|
171
|
-
await WelcomeOfferService.runInteractiveFlow(store, storage, sqlite, paths.executablePath);
|
|
172
|
-
}
|
|
173
241
|
else if (action === 'extract' || action === 'browser_token' || action === 'capture') {
|
|
174
242
|
await handleSmartExtractAction(store, storage, sqlite, paths.executablePath);
|
|
175
243
|
}
|
|
176
244
|
else if (action === 'fingerprint') {
|
|
177
|
-
await handleFingerprintMenu(storage, currentAcc);
|
|
245
|
+
await handleFingerprintMenu(storage, currentAcc, sqlite);
|
|
178
246
|
}
|
|
179
247
|
else if (action === 'backup') {
|
|
180
248
|
await handleBackupAction(storage, sqlite);
|
|
181
249
|
}
|
|
182
|
-
else if (action === 'website') {
|
|
183
|
-
await handleOpenWebsiteAction();
|
|
184
|
-
}
|
|
185
|
-
else if (action === 'qq_group') {
|
|
186
|
-
await handleQqGroupAction();
|
|
187
|
-
}
|
|
188
250
|
else if (action === 'upgrade') {
|
|
189
251
|
await handleUpgradeMenu(updateChecker);
|
|
190
252
|
}
|
|
191
253
|
}
|
|
192
254
|
catch (err) {
|
|
193
255
|
if (err?.name === 'ExitPromptError') {
|
|
256
|
+
leaveAltScreenIfActive();
|
|
194
257
|
process.stdout.write('\x1b[?25h\n');
|
|
195
258
|
process.exit(0);
|
|
196
259
|
}
|
|
@@ -198,9 +261,6 @@ export async function runInteractiveMenu() {
|
|
|
198
261
|
}
|
|
199
262
|
}
|
|
200
263
|
}
|
|
201
|
-
/**
|
|
202
|
-
* 换号交互子流程
|
|
203
|
-
*/
|
|
204
264
|
async function handleSwitchMenu(store, storage, sqlite, execPath) {
|
|
205
265
|
const accounts = store.loadAll();
|
|
206
266
|
if (accounts.length === 0) {
|
|
@@ -214,33 +274,32 @@ async function handleSwitchMenu(store, storage, sqlite, execPath) {
|
|
|
214
274
|
}
|
|
215
275
|
return;
|
|
216
276
|
}
|
|
217
|
-
// 优先把当前在用的账号排在前面
|
|
218
277
|
const sortedAccounts = [
|
|
219
278
|
...accounts.filter((a) => a.is_current),
|
|
220
279
|
...accounts.filter((a) => !a.is_current),
|
|
221
280
|
];
|
|
222
281
|
const choices = [
|
|
223
|
-
{ name: '0.
|
|
282
|
+
{ name: '0. 返回', value: '__back__' },
|
|
224
283
|
{
|
|
225
|
-
name: 't. 录入 Token
|
|
284
|
+
name: 't. 录入 Token 切换',
|
|
226
285
|
value: '__token_switch__',
|
|
227
286
|
key: 't',
|
|
228
|
-
description: '
|
|
287
|
+
description: '粘贴凭据自动入库并切换',
|
|
229
288
|
},
|
|
230
289
|
];
|
|
231
290
|
if (accounts.length > 10) {
|
|
232
291
|
choices.push({
|
|
233
|
-
name: 's.
|
|
292
|
+
name: 's. 搜索账号',
|
|
234
293
|
value: '__search__',
|
|
235
294
|
key: 's',
|
|
236
|
-
description: '
|
|
295
|
+
description: '按邮箱或套餐筛选',
|
|
237
296
|
});
|
|
238
297
|
}
|
|
239
298
|
choices.push({
|
|
240
|
-
name: 'd.
|
|
299
|
+
name: 'd. 清理账号',
|
|
241
300
|
value: '__cleanup__',
|
|
242
301
|
key: 'd',
|
|
243
|
-
description: '
|
|
302
|
+
description: '删除指定或失效账号',
|
|
244
303
|
});
|
|
245
304
|
choices.push(new Separator());
|
|
246
305
|
sortedAccounts.forEach((acc, index) => {
|
|
@@ -258,7 +317,8 @@ async function handleSwitchMenu(store, storage, sqlite, execPath) {
|
|
|
258
317
|
});
|
|
259
318
|
});
|
|
260
319
|
const selectedEmail = await quickSelect({
|
|
261
|
-
|
|
320
|
+
header: chalk.bold.cyan('● 切换账号'),
|
|
321
|
+
message: '选择账号 (序号 / t / 0):',
|
|
262
322
|
choices,
|
|
263
323
|
pageSize: 12,
|
|
264
324
|
});
|
|
@@ -307,13 +367,10 @@ async function handleSwitchMenu(store, storage, sqlite, execPath) {
|
|
|
307
367
|
return;
|
|
308
368
|
await executeSwitchAccount(store, storage, sqlite, targetAcc, execPath);
|
|
309
369
|
}
|
|
310
|
-
/**
|
|
311
|
-
* 直接录入 Token 极速切换子流程 (Token Fast Switch)
|
|
312
|
-
*/
|
|
313
370
|
async function handleTokenDirectSwitch(store, storage, sqlite, execPath) {
|
|
314
371
|
console.clear();
|
|
315
372
|
console.log(chalk.bold.cyan('\n● 录入 Token 极速换号 (Token Fast Switch)\n'));
|
|
316
|
-
console.log(chalk.grey('支持直接粘贴 user_xxx::eyJ...
|
|
373
|
+
console.log(chalk.grey('支持直接粘贴 一段 (user_xxx::eyJ... / eyJ...) 或 三段完整凭据 (Access----Refresh----Web) (输入 0 或 q 取消)\n'));
|
|
317
374
|
const rawInput = await safeInput({
|
|
318
375
|
message: '请在此粘贴 Token 凭据',
|
|
319
376
|
});
|
|
@@ -323,12 +380,11 @@ async function handleTokenDirectSwitch(store, storage, sqlite, execPath) {
|
|
|
323
380
|
const rawToken = rawInput.trim();
|
|
324
381
|
const parsed = TokenParser.parse(rawToken);
|
|
325
382
|
if (!parsed.isValid) {
|
|
326
|
-
console.log(chalk.red('\n未识别到有效的 Token
|
|
383
|
+
console.log(chalk.red('\n未识别到有效的 Token 格式,支持一段 (user_xxx::eyJ... / eyJ...) 或三段打包串。\n'));
|
|
327
384
|
await pressAnyKey();
|
|
328
385
|
return;
|
|
329
386
|
}
|
|
330
387
|
process.stdout.write(chalk.grey('\n正在连接 Cursor 官方端点同步账号信息... '));
|
|
331
|
-
// 1. 优先尝试从官方 RPC 接口精准获取真实绑定邮箱
|
|
332
388
|
let email;
|
|
333
389
|
try {
|
|
334
390
|
const fetchedEmail = await OfficialApiClient.fetchEmail(parsed.token);
|
|
@@ -348,58 +404,78 @@ async function handleTokenDirectSwitch(store, storage, sqlite, execPath) {
|
|
|
348
404
|
});
|
|
349
405
|
email = inputEmail || fallback;
|
|
350
406
|
}
|
|
351
|
-
// 2. 查询用量与会员订阅
|
|
352
407
|
const usageRes = await OfficialApiClient.fetchUsage(parsed.token);
|
|
353
408
|
const existing = store.getByEmail(email);
|
|
354
|
-
const subType = usageRes.success && usageRes.subscriptionType
|
|
355
|
-
? usageRes.subscriptionType
|
|
356
|
-
: existing?.subscription_type || 'free';
|
|
357
|
-
console.log(chalk.green(`✔ ${email} [${formatPlanName(subType)}]`));
|
|
358
|
-
// 3. 生成专属防封硬件指纹并建档入库
|
|
359
409
|
const machineIds = existing?.machine_ids || generateMachineIds();
|
|
360
|
-
const targetAcc = {
|
|
410
|
+
const targetAcc = applyParsedCredentialToAccount({
|
|
411
|
+
parsed,
|
|
361
412
|
email,
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
413
|
+
existing,
|
|
414
|
+
usageRes,
|
|
415
|
+
machineIds,
|
|
416
|
+
fallbackWorkosToToken: true,
|
|
417
|
+
});
|
|
418
|
+
printFactualTokenStatus(targetAcc.token, targetAcc.refresh_token, targetAcc.workos_cursor_session_token);
|
|
419
|
+
console.log(chalk.green(`✔ ${email} [${formatPlanName(targetAcc.subscription_type)}]`));
|
|
420
|
+
console.log(chalk.cyan('\n正在执行前置校验与换号准备...'));
|
|
421
|
+
const switchedAcc = await executeSwitchAccount(store, storage, sqlite, targetAcc, execPath);
|
|
422
|
+
if (switchedAcc) {
|
|
423
|
+
if (switchedAcc.email === targetAcc.email && switchedAcc.token === targetAcc.token) {
|
|
424
|
+
store.addOrUpdate({ ...switchedAcc, is_current: true });
|
|
425
|
+
}
|
|
426
|
+
await copyPreferredAccountCredential(switchedAcc);
|
|
427
|
+
}
|
|
373
428
|
}
|
|
374
|
-
/**
|
|
375
|
-
* 执行一键换号的核心原子流程
|
|
376
|
-
*/
|
|
377
429
|
async function executeSwitchAccount(store, storage, sqlite, targetAcc, execPath) {
|
|
378
430
|
console.log(chalk.cyan(`\n正在执行换号流程,目标: ${chalk.bold.white(targetAcc.email)} ...`));
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
431
|
+
const paths = resolveCursorPaths();
|
|
432
|
+
const switchRes = await executeAccountSwitch({
|
|
433
|
+
store,
|
|
434
|
+
storage,
|
|
435
|
+
sqlite,
|
|
436
|
+
paths,
|
|
437
|
+
targetAccount: targetAcc,
|
|
438
|
+
resolveStaleTokenAction: (issue, acc) => resolveStaleSwitchWithHealing(issue, acc, {
|
|
439
|
+
store,
|
|
440
|
+
storage,
|
|
441
|
+
sqlite,
|
|
442
|
+
executablePath: execPath,
|
|
443
|
+
interactive: true,
|
|
444
|
+
}),
|
|
445
|
+
onStep: (step, detail) => {
|
|
446
|
+
if (step === 'resolve') {
|
|
447
|
+
console.log(chalk.grey('✔ [0/4] 校验凭据形态与 OAuth 续期链路...'));
|
|
448
|
+
}
|
|
449
|
+
else if (step === 'close') {
|
|
450
|
+
if (detail === 'running') {
|
|
451
|
+
console.log(chalk.grey('✔ [1/4] 检测到 Cursor 运行中 -> 发送退出信号,释放 SQLite 独占锁'));
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
console.log(chalk.grey('✔ [1/4] Cursor 未运行,无需关闭进程'));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
else if (step === 'backup') {
|
|
458
|
+
console.log(chalk.grey('✔ [2/4] 创建本地安全快照备份 (storage.json 与 state.vscdb)'));
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
});
|
|
462
|
+
if (switchRes.aborted) {
|
|
463
|
+
console.log(chalk.yellow('已取消本次切号,本机 Cursor 登录状态与账号库未受任何改动。\n'));
|
|
464
|
+
await pressAnyKey();
|
|
465
|
+
return null;
|
|
383
466
|
}
|
|
384
|
-
|
|
385
|
-
console.log(chalk.
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
console.log(chalk.grey(
|
|
395
|
-
|
|
396
|
-
const token = TokenParser.extractTokenPart(targetAcc.token);
|
|
397
|
-
const refreshToken = targetAcc.workos_cursor_session_token || token;
|
|
398
|
-
storage.writeAuth(targetAcc.email, token, refreshToken);
|
|
399
|
-
await sqlite.injectAuth(targetAcc.email, token, refreshToken);
|
|
400
|
-
store.markCurrent(targetAcc.email);
|
|
401
|
-
console.log(chalk.grey('✔ [4/4] 原子注入 Token 与认证状态到 SQLite 数据库'));
|
|
402
|
-
console.log(chalk.green(`\n✔ 换号成功!当前账号: ${chalk.bold.white(targetAcc.email)}\n`));
|
|
467
|
+
if (switchRes.refreshed) {
|
|
468
|
+
console.log(chalk.green('✔ 已自动完成 OAuth Refresh Token 无感续期'));
|
|
469
|
+
}
|
|
470
|
+
console.log(chalk.grey(`✔ [3/4] 装载专属机器指纹 (JSON + SQLite + machineid): ${formatMachineIdSummary(switchRes.machineIds)}`));
|
|
471
|
+
if (switchRes.sidecarReport.authJsonUpdated || switchRes.sidecarReport.cliConfigUpdated) {
|
|
472
|
+
console.log(chalk.grey('✔ 已同步清理/更新 auth.json 与 cli-config.json 侧车凭据'));
|
|
473
|
+
}
|
|
474
|
+
for (const warn of switchRes.warnings) {
|
|
475
|
+
console.log(chalk.yellow(`! 提示: ${warn}`));
|
|
476
|
+
}
|
|
477
|
+
console.log(chalk.grey('✔ [4/4] 已清旧并原子注入 Token 与认证状态到 SQLite 数据库'));
|
|
478
|
+
console.log(chalk.green(`\n✔ 换号成功!当前账号: ${chalk.bold.white(switchRes.account.email)}\n`));
|
|
403
479
|
let activeExecPath = execPath || findCursorExecutable();
|
|
404
480
|
if (!activeExecPath) {
|
|
405
481
|
const wantSpecify = await safeConfirm({
|
|
@@ -431,23 +507,22 @@ async function executeSwitchAccount(store, storage, sqlite, targetAcc, execPath)
|
|
|
431
507
|
}
|
|
432
508
|
}
|
|
433
509
|
await pressAnyKey();
|
|
510
|
+
return switchRes.account;
|
|
434
511
|
}
|
|
435
|
-
/**
|
|
436
|
-
* 添加账号子流程 (4大方式)
|
|
437
|
-
*/
|
|
438
512
|
async function handleAddMenu(store, storage, sqlite, execPath) {
|
|
439
513
|
const method = await quickSelect({
|
|
440
|
-
|
|
514
|
+
header: chalk.bold.cyan('● 添加与管理账号'),
|
|
515
|
+
message: '账号管理:',
|
|
441
516
|
choices: [
|
|
442
|
-
{ name: '1.
|
|
443
|
-
{ name: '2.
|
|
444
|
-
{ name: '3.
|
|
445
|
-
{ name: '4.
|
|
446
|
-
{ name: '5.
|
|
517
|
+
{ name: '1. 浏览器 OAuth 登录', value: 'oauth', description: '无痕浏览器登录并自动获取 Token' },
|
|
518
|
+
{ name: '2. 提取本机账号', value: 'smart_extract', description: '读取本机登录或跳转浏览器登录' },
|
|
519
|
+
{ name: '3. 纯净代登', value: 'pure_login', description: '通过代理环境辅助登录并获取 Token' },
|
|
520
|
+
{ name: '4. 粘贴 Token 录入', value: 'token', description: '粘贴一段或三段凭据入库' },
|
|
521
|
+
{ name: '5. 批量文件导入', value: 'file', description: '从本地文件批量导入并去重' },
|
|
447
522
|
new Separator(),
|
|
448
|
-
{ name: '6.
|
|
523
|
+
{ name: '6. 清理 / 删除账号', value: 'cleanup', description: '单选、多选删除或清理失效账号' },
|
|
449
524
|
new Separator(),
|
|
450
|
-
{ name: '0.
|
|
525
|
+
{ name: '0. 返回', value: 'back', description: '返回主菜单' },
|
|
451
526
|
],
|
|
452
527
|
pageSize: 12,
|
|
453
528
|
});
|
|
@@ -473,14 +548,14 @@ async function handleAddMenu(store, storage, sqlite, execPath) {
|
|
|
473
548
|
}
|
|
474
549
|
if (method === 'token') {
|
|
475
550
|
const rawInput = await safeInput({
|
|
476
|
-
message: '
|
|
551
|
+
message: '请粘贴一段 (user_xxx::eyJ... / eyJ...) 或三段打包串 (Access----Refresh----Web)',
|
|
477
552
|
});
|
|
478
553
|
if (!rawInput) {
|
|
479
554
|
return;
|
|
480
555
|
}
|
|
481
556
|
const parsed = TokenParser.parse(rawInput);
|
|
482
557
|
if (!parsed.isValid) {
|
|
483
|
-
console.log(chalk.red('\n未识别到有效的 Token
|
|
558
|
+
console.log(chalk.red('\n未识别到有效的 Token 格式,支持一段 (user_xxx::eyJ... / eyJ...) 或三段打包串。\n'));
|
|
484
559
|
}
|
|
485
560
|
else {
|
|
486
561
|
let email = parsed.email;
|
|
@@ -492,12 +567,16 @@ async function handleAddMenu(store, storage, sqlite, execPath) {
|
|
|
492
567
|
});
|
|
493
568
|
email = inputEmail || fallback;
|
|
494
569
|
}
|
|
495
|
-
|
|
570
|
+
printFactualTokenStatus(parsed.token, parsed.refreshToken, parsed.workosSessionToken);
|
|
571
|
+
const ingestRes = await upgradeAccountWebTokenOnIngest({
|
|
496
572
|
email,
|
|
497
573
|
token: parsed.token,
|
|
574
|
+
refresh_token: parsed.refreshToken,
|
|
498
575
|
workos_cursor_session_token: parsed.workosSessionToken,
|
|
499
576
|
});
|
|
500
|
-
|
|
577
|
+
store.addOrUpdate(ingestRes.account);
|
|
578
|
+
printIngestUpgradeResult(ingestRes);
|
|
579
|
+
console.log(chalk.green(`\n✔ 录入成功!账号 ${email} 已加入本地库(${TokenParser.formatCredentialBadge(ingestRes.classification)})\n`));
|
|
501
580
|
}
|
|
502
581
|
}
|
|
503
582
|
else if (method === 'file') {
|
|
@@ -526,18 +605,7 @@ async function handleAddMenu(store, storage, sqlite, execPath) {
|
|
|
526
605
|
}
|
|
527
606
|
}
|
|
528
607
|
else {
|
|
529
|
-
|
|
530
|
-
for (const line of lines) {
|
|
531
|
-
const parsed = TokenParser.parse(line);
|
|
532
|
-
if (parsed.isValid && parsed.email) {
|
|
533
|
-
store.addOrUpdate({
|
|
534
|
-
email: parsed.email,
|
|
535
|
-
token: parsed.token,
|
|
536
|
-
workos_cursor_session_token: parsed.workosSessionToken,
|
|
537
|
-
});
|
|
538
|
-
count++;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
608
|
+
count = importAccountsFromText(content, store);
|
|
541
609
|
}
|
|
542
610
|
console.log(chalk.green(`\n✔ 批量导入成功!共录入 ${count} 个有效账号\n`));
|
|
543
611
|
}
|
|
@@ -548,9 +616,6 @@ async function handleAddMenu(store, storage, sqlite, execPath) {
|
|
|
548
616
|
}
|
|
549
617
|
await pressAnyKey();
|
|
550
618
|
}
|
|
551
|
-
/**
|
|
552
|
-
* 账号清理与移除子菜单 (Account Cleanup & Management)
|
|
553
|
-
*/
|
|
554
619
|
export async function handleAccountCleanupMenu(store, storage, sqlite) {
|
|
555
620
|
while (true) {
|
|
556
621
|
console.clear();
|
|
@@ -563,30 +628,14 @@ export async function handleAccountCleanupMenu(store, storage, sqlite) {
|
|
|
563
628
|
}
|
|
564
629
|
console.log(chalk.grey(`本地库当前共收录了 ${chalk.bold.white(accounts.length)} 个账号。\n`));
|
|
565
630
|
const choice = await quickSelect({
|
|
566
|
-
message: '
|
|
631
|
+
message: '账号清理:',
|
|
567
632
|
choices: [
|
|
568
|
-
{
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
},
|
|
573
|
-
{
|
|
574
|
-
name: '2. 批量多选账号删除',
|
|
575
|
-
value: 'batch',
|
|
576
|
-
description: '使用空格键勾选多个账号,一键批量删除',
|
|
577
|
-
},
|
|
578
|
-
{
|
|
579
|
-
name: '3. 一键清理已失效/已过期账号',
|
|
580
|
-
value: 'expired',
|
|
581
|
-
description: '智能扫描并批量清除所有标记为已失效或已过期的无效账号',
|
|
582
|
-
},
|
|
583
|
-
{
|
|
584
|
-
name: '4. ⚠️ 清空全部账号 (高危重置)',
|
|
585
|
-
value: 'clear_all',
|
|
586
|
-
description: '清空本地 accounts.json 保存的所有账号信息 (需二次确认)',
|
|
587
|
-
},
|
|
633
|
+
{ name: '1. 删除单个账号', value: 'single', description: '挑选并删除指定账号' },
|
|
634
|
+
{ name: '2. 批量勾选删除', value: 'batch', description: '多选批量删除账号' },
|
|
635
|
+
{ name: '3. 清理失效 / 过期账号', value: 'expired', description: '清除所有已失效或过期账号' },
|
|
636
|
+
{ name: '4. 清空全部账号', value: 'clear_all', description: '清空 accounts.json(需确认)' },
|
|
588
637
|
new Separator(),
|
|
589
|
-
{ name: '0.
|
|
638
|
+
{ name: '0. 返回', value: '__back__' },
|
|
590
639
|
],
|
|
591
640
|
});
|
|
592
641
|
if (choice === '__back__' || !choice) {
|
|
@@ -738,7 +787,7 @@ async function handleCleanExpiredAccounts(store) {
|
|
|
738
787
|
const expiredList = [];
|
|
739
788
|
for (const acc of accounts) {
|
|
740
789
|
if (acc.is_current) {
|
|
741
|
-
continue;
|
|
790
|
+
continue;
|
|
742
791
|
}
|
|
743
792
|
if (acc.subscription_type === 'token_expired') {
|
|
744
793
|
expiredList.push({ acc, reason: '官方标记凭据已失效 (Token Expired)' });
|
|
@@ -817,9 +866,6 @@ async function handleClearAllAccounts(store) {
|
|
|
817
866
|
}
|
|
818
867
|
await pressAnyKey();
|
|
819
868
|
}
|
|
820
|
-
/**
|
|
821
|
-
* 账号搜索与匹配规则 (支持邮箱、别名、会员级别、中文计划名、到期状态)
|
|
822
|
-
*/
|
|
823
869
|
function matchesAccount(acc, query) {
|
|
824
870
|
const q = query.toLowerCase().trim();
|
|
825
871
|
if (!q)
|
|
@@ -846,115 +892,22 @@ function matchesAccount(acc, query) {
|
|
|
846
892
|
}
|
|
847
893
|
return false;
|
|
848
894
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
const choices = [];
|
|
857
|
-
if (jwtToken) {
|
|
858
|
-
choices.push({
|
|
859
|
-
name: '1. 复制 Access Token (原生 Bearer JWT 凭据) [推荐]',
|
|
860
|
-
value: 'jwt',
|
|
861
|
-
description: '标准 Bearer JWT,适合各类第三方工具、VSCode 插件或 API 调用 (以 eyJ 开头)',
|
|
862
|
-
});
|
|
863
|
-
}
|
|
864
|
-
if (sessionToken && sessionToken !== jwtToken) {
|
|
865
|
-
choices.push({
|
|
866
|
-
name: '2. 复制 WorkOS Session Token (网页 Session 凭据)',
|
|
867
|
-
value: 'session',
|
|
868
|
-
description: 'WorkOS Cookie 凭据,适合浏览器注入、官网免密登录及奥仔退款 (以 user_ 开头)',
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
choices.push({
|
|
872
|
-
name: sessionToken && sessionToken !== jwtToken ? '3. 一键复制完整账号配置 (JSON 格式)' : '2. 一键复制完整账号配置 (JSON 格式)',
|
|
873
|
-
value: 'full',
|
|
874
|
-
description: '复制包含邮箱、Token 和当前设备指纹的完整配置,便于备份或异地迁移',
|
|
875
|
-
});
|
|
876
|
-
choices.push({
|
|
877
|
-
name: sessionToken && sessionToken !== jwtToken ? '4. 查看凭据完整明文 (终端打印)' : '3. 查看凭据完整明文 (终端打印)',
|
|
878
|
-
value: 'view',
|
|
879
|
-
description: '在终端屏幕上完整输出 Token 明文',
|
|
880
|
-
});
|
|
881
|
-
choices.push(new Separator());
|
|
882
|
-
choices.push({ name: '0. 返回上一级', value: '__back__' });
|
|
883
|
-
const pick = await quickSelect({
|
|
884
|
-
message: `请选择要复制的凭据类型 [${email}]:`,
|
|
885
|
-
choices,
|
|
895
|
+
async function handleCopyTokenAction(email, currentToken, workosToken, machineIds, refreshToken) {
|
|
896
|
+
await runInteractiveCopyAccountMenu({
|
|
897
|
+
email,
|
|
898
|
+
token: currentToken,
|
|
899
|
+
refresh_token: refreshToken,
|
|
900
|
+
workos_cursor_session_token: workosToken,
|
|
901
|
+
machine_ids: machineIds,
|
|
886
902
|
});
|
|
887
|
-
if (pick === '__back__' || !pick)
|
|
888
|
-
return;
|
|
889
|
-
if (pick === 'jwt') {
|
|
890
|
-
const success = await copyToClipboard(jwtToken);
|
|
891
|
-
console.log(boxen([
|
|
892
|
-
chalk.bold.green('✔ Access Token 已成功复制到系统剪贴板!'),
|
|
893
|
-
chalk.dim('────────────────────────────────────────────────'),
|
|
894
|
-
` 账号邮箱 : ${chalk.bold.white(email)}`,
|
|
895
|
-
` 凭据类型 : ${chalk.cyan('原生 Bearer JWT (Access Token)')}`,
|
|
896
|
-
` 凭据预览 : ${chalk.dim(jwtToken.slice(0, 16))}...${chalk.dim(jwtToken.slice(-12))} ${chalk.grey(`(共 ${jwtToken.length} 字符)`)}`,
|
|
897
|
-
` 操作提示 : ${chalk.yellow('已在剪贴板中,随时使用 Ctrl+V (或 Cmd+V) 粘贴即可')}`,
|
|
898
|
-
].join('\n'), { padding: { top: 0, bottom: 0, left: 1, right: 1 }, borderColor: 'green', borderStyle: 'round' }));
|
|
899
|
-
if (!success) {
|
|
900
|
-
console.log(chalk.yellow('提示: 自动写入剪贴板未生效,以下为 Token 明文,可手动选中复制:'));
|
|
901
|
-
console.log(chalk.grey(jwtToken) + '\n');
|
|
902
|
-
}
|
|
903
|
-
await pressAnyKey();
|
|
904
|
-
}
|
|
905
|
-
else if (pick === 'session' && sessionToken) {
|
|
906
|
-
const success = await copyToClipboard(sessionToken);
|
|
907
|
-
console.log(boxen([
|
|
908
|
-
chalk.bold.green('✔ WorkOS Session Token 已成功复制到系统剪贴板!'),
|
|
909
|
-
chalk.dim('────────────────────────────────────────────────'),
|
|
910
|
-
` 账号邮箱 : ${chalk.bold.white(email)}`,
|
|
911
|
-
` 凭据类型 : ${chalk.cyan('WorkOS Session Token')}`,
|
|
912
|
-
` 凭据预览 : ${chalk.dim(sessionToken.slice(0, 20))}...${chalk.dim(sessionToken.slice(-12))} ${chalk.grey(`(共 ${sessionToken.length} 字符)`)}`,
|
|
913
|
-
` 操作提示 : ${chalk.yellow('已在剪贴板中,随时使用 Ctrl+V (或 Cmd+V) 粘贴即可')}`,
|
|
914
|
-
].join('\n'), { padding: { top: 0, bottom: 0, left: 1, right: 1 }, borderColor: 'green', borderStyle: 'round' }));
|
|
915
|
-
if (!success) {
|
|
916
|
-
console.log(chalk.yellow('提示: 自动写入剪贴板未生效,以下为 Token 明文,可手动选中复制:'));
|
|
917
|
-
console.log(chalk.grey(sessionToken) + '\n');
|
|
918
|
-
}
|
|
919
|
-
await pressAnyKey();
|
|
920
|
-
}
|
|
921
|
-
else if (pick === 'full') {
|
|
922
|
-
const fullText = JSON.stringify({
|
|
923
|
-
email,
|
|
924
|
-
token: jwtToken,
|
|
925
|
-
workos_cursor_session_token: sessionToken,
|
|
926
|
-
machine_ids: machineIds,
|
|
927
|
-
}, null, 2);
|
|
928
|
-
const success = await copyToClipboard(fullText);
|
|
929
|
-
console.log(boxen([
|
|
930
|
-
chalk.bold.green('✔ 账号完整配置已成功复制到系统剪贴板 (JSON 格式)!'),
|
|
931
|
-
chalk.dim('────────────────────────────────────────────────'),
|
|
932
|
-
` 账号邮箱 : ${chalk.bold.white(email)}`,
|
|
933
|
-
` 操作提示 : ${chalk.yellow('直接使用 Ctrl + V (或 Cmd + V) 粘贴即可')}`,
|
|
934
|
-
].join('\n'), { padding: { top: 0, bottom: 0, left: 1, right: 1 }, borderColor: 'green', borderStyle: 'round' }));
|
|
935
|
-
if (!success) {
|
|
936
|
-
console.log(chalk.grey(fullText) + '\n');
|
|
937
|
-
}
|
|
938
|
-
await pressAnyKey();
|
|
939
|
-
}
|
|
940
|
-
else if (pick === 'view') {
|
|
941
|
-
console.log(chalk.bold.cyan(`\n● 账号 ${email} 凭据明文详情:\n`));
|
|
942
|
-
console.log(chalk.white('【Access Token (Bearer JWT)】:'));
|
|
943
|
-
console.log(chalk.green(jwtToken) + '\n');
|
|
944
|
-
if (sessionToken && sessionToken !== jwtToken) {
|
|
945
|
-
console.log(chalk.white('【WorkOS Session Token】:'));
|
|
946
|
-
console.log(chalk.cyan(sessionToken) + '\n');
|
|
947
|
-
}
|
|
948
|
-
await pressAnyKey();
|
|
949
|
-
}
|
|
950
903
|
}
|
|
951
|
-
/**
|
|
952
|
-
* 账号余量看板与实时检索流程
|
|
953
|
-
*/
|
|
954
904
|
async function handleRadarMenu(store, storage, sqlite, execPath) {
|
|
955
905
|
let currentFilter = 'default';
|
|
956
906
|
let currentKeyword = '';
|
|
957
907
|
while (true) {
|
|
908
|
+
if (process.stdout.isTTY) {
|
|
909
|
+
console.clear();
|
|
910
|
+
}
|
|
958
911
|
const allAccounts = store.loadAll();
|
|
959
912
|
let displayList = allAccounts;
|
|
960
913
|
let subtitle = '';
|
|
@@ -976,7 +929,6 @@ async function handleRadarMenu(store, storage, sqlite, execPath) {
|
|
|
976
929
|
subtitle = `${chalk.bold.white('全部账号列表')} ${chalk.grey(`(共 ${displayList.length} 个)`)}`;
|
|
977
930
|
}
|
|
978
931
|
else {
|
|
979
|
-
// 默认精简视图:当前在用排在首位,展示前 15 条
|
|
980
932
|
const sorted = [
|
|
981
933
|
...allAccounts.filter((a) => a.is_current),
|
|
982
934
|
...allAccounts.filter((a) => !a.is_current),
|
|
@@ -984,43 +936,47 @@ async function handleRadarMenu(store, storage, sqlite, execPath) {
|
|
|
984
936
|
displayList = sorted.slice(0, 15);
|
|
985
937
|
subtitle = `${chalk.bold.white('常用账号看板')} ${chalk.grey(`(展示前 ${displayList.length} 个,总计 ${allAccounts.length} 个)`)}`;
|
|
986
938
|
}
|
|
939
|
+
const tableText = displayList.length > 0 ? renderAccountTable(displayList) : '';
|
|
987
940
|
console.log(`\n${subtitle}`);
|
|
988
|
-
if (
|
|
989
|
-
console.log(
|
|
941
|
+
if (tableText) {
|
|
942
|
+
console.log(tableText);
|
|
990
943
|
}
|
|
991
944
|
else {
|
|
992
945
|
console.log(chalk.yellow('\n 未找到任何匹配的账号,请尝试搜索其他关键词。\n'));
|
|
993
946
|
}
|
|
947
|
+
const usedAboveRows = 3 + (tableText ? tableText.split(/\r?\n/).length : 3);
|
|
948
|
+
const radarMenuPageSize = Math.max(4, Math.min(12, (process.stdout.rows || 24) - usedAboveRows - 5));
|
|
994
949
|
const actionChoices = [
|
|
995
|
-
{ name: '1. 搜索账号', value: 'search', description: '
|
|
996
|
-
{ name: '2. 仅看可用账号', value: 'active', description: '
|
|
997
|
-
{ name: '3.
|
|
950
|
+
{ name: '1. 搜索账号', value: 'search', description: '按邮箱、域名或套餐筛选' },
|
|
951
|
+
{ name: '2. 仅看可用账号', value: 'active', description: '过滤失效和过期账号' },
|
|
952
|
+
{ name: '3. 默认看板', value: 'default', description: '展示当前及前 15 个账号' },
|
|
998
953
|
];
|
|
999
954
|
if (currentFilter !== 'all' && allAccounts.length > 15) {
|
|
1000
|
-
actionChoices.push({ name: `4.
|
|
955
|
+
actionChoices.push({ name: `4. 查看全部 (${allAccounts.length})`, value: 'all', description: '展示全部本地账号' });
|
|
1001
956
|
}
|
|
1002
957
|
if (displayList.length > 0) {
|
|
1003
958
|
actionChoices.push(new Separator());
|
|
1004
959
|
if (displayList.length <= 50) {
|
|
1005
|
-
actionChoices.push({ name: '5.
|
|
1006
|
-
actionChoices.push({ name: '6.
|
|
1007
|
-
actionChoices.push({ name: '7.
|
|
1008
|
-
actionChoices.push({ name: '8. 打开 Outlook 邮箱', value: 'mail_from_list', description: '
|
|
960
|
+
actionChoices.push({ name: '5. 切换账号', value: 'switch_from_list', description: '从当前列表选号切换' });
|
|
961
|
+
actionChoices.push({ name: '6. 复制 Token', value: 'copy_from_list', description: '复制 Access 或 WorkOS 凭据' });
|
|
962
|
+
actionChoices.push({ name: '7. 打开控制台', value: 'dash_from_list', description: '免密打开网页后台' });
|
|
963
|
+
actionChoices.push({ name: '8. 打开 Outlook 邮箱', value: 'mail_from_list', description: '自动登录对应邮箱' });
|
|
1009
964
|
}
|
|
1010
|
-
actionChoices.push({ name: '9.
|
|
965
|
+
actionChoices.push({ name: '9. 清理账号', value: 'cleanup_from_list', description: '删除或批量清理账号' });
|
|
1011
966
|
}
|
|
1012
967
|
actionChoices.push(new Separator());
|
|
1013
|
-
actionChoices.push({ name: '0.
|
|
968
|
+
actionChoices.push({ name: '0. 返回', value: 'back', description: '返回主菜单' });
|
|
1014
969
|
let action;
|
|
1015
970
|
try {
|
|
1016
971
|
action = await quickSelect({
|
|
1017
972
|
message: '看板操作:',
|
|
1018
973
|
choices: actionChoices,
|
|
1019
|
-
pageSize:
|
|
974
|
+
pageSize: radarMenuPageSize,
|
|
1020
975
|
});
|
|
1021
976
|
}
|
|
1022
977
|
catch (err) {
|
|
1023
978
|
if (err?.name === 'ExitPromptError') {
|
|
979
|
+
leaveAltScreenIfActive();
|
|
1024
980
|
process.stdout.write('\x1b[?25h\n');
|
|
1025
981
|
process.exit(0);
|
|
1026
982
|
}
|
|
@@ -1091,7 +1047,7 @@ async function handleRadarMenu(store, storage, sqlite, execPath) {
|
|
|
1091
1047
|
if (pickEmail !== '__back__' && pickEmail) {
|
|
1092
1048
|
const target = displayList.find((a) => a.email === pickEmail);
|
|
1093
1049
|
if (target) {
|
|
1094
|
-
await handleCopyTokenAction(target.email, target.token, target.workos_cursor_session_token, target.machine_ids);
|
|
1050
|
+
await handleCopyTokenAction(target.email, target.token, target.workos_cursor_session_token, target.machine_ids, target.refresh_token);
|
|
1095
1051
|
}
|
|
1096
1052
|
}
|
|
1097
1053
|
}
|
|
@@ -1155,9 +1111,6 @@ async function handleRadarMenu(store, storage, sqlite, execPath) {
|
|
|
1155
1111
|
}
|
|
1156
1112
|
}
|
|
1157
1113
|
}
|
|
1158
|
-
/**
|
|
1159
|
-
* 官网后台快捷交互 (支持直接录入 Token 免密直达)
|
|
1160
|
-
*/
|
|
1161
1114
|
async function handleDashboardMenu(store, currentAcc) {
|
|
1162
1115
|
const accounts = store.loadAll();
|
|
1163
1116
|
if (accounts.length === 0) {
|
|
@@ -1171,22 +1124,24 @@ async function handleDashboardMenu(store, currentAcc) {
|
|
|
1171
1124
|
}
|
|
1172
1125
|
return;
|
|
1173
1126
|
}
|
|
1174
|
-
// 优先把当前在用的账号排在前面
|
|
1175
1127
|
const sortedAccounts = [
|
|
1176
1128
|
...accounts.filter((a) => a.is_current),
|
|
1177
1129
|
...accounts.filter((a) => !a.is_current),
|
|
1178
1130
|
];
|
|
1179
1131
|
let targetAcc;
|
|
1180
1132
|
while (true) {
|
|
1133
|
+
if (process.stdout.isTTY) {
|
|
1134
|
+
console.clear();
|
|
1135
|
+
}
|
|
1181
1136
|
const choices = [
|
|
1182
|
-
{ name: '0.
|
|
1137
|
+
{ name: '0. 返回', value: '__back__' },
|
|
1183
1138
|
{
|
|
1184
|
-
name: 't. 录入 Token
|
|
1139
|
+
name: 't. 录入 Token 直达',
|
|
1185
1140
|
value: '__token_dash__',
|
|
1186
1141
|
key: 't',
|
|
1187
|
-
description: '
|
|
1142
|
+
description: '粘贴凭据直接打开网页控制台',
|
|
1188
1143
|
},
|
|
1189
|
-
{ name: 's.
|
|
1144
|
+
{ name: 's. 搜索账号', value: '__search__', key: 's', description: '按邮箱搜索账号' },
|
|
1190
1145
|
new Separator(),
|
|
1191
1146
|
];
|
|
1192
1147
|
sortedAccounts.forEach((acc, index) => {
|
|
@@ -1195,11 +1150,12 @@ async function handleDashboardMenu(store, currentAcc) {
|
|
|
1195
1150
|
choices.push({
|
|
1196
1151
|
name: `${index + 1}. ${plan}${acc.email}${isCurrent}`,
|
|
1197
1152
|
value: acc.email,
|
|
1198
|
-
description:
|
|
1153
|
+
description: `打开 ${acc.email} 的 Cursor 网页后台`,
|
|
1199
1154
|
});
|
|
1200
1155
|
});
|
|
1201
1156
|
const chosenEmail = await quickSelect({
|
|
1202
|
-
|
|
1157
|
+
header: chalk.bold.cyan('● 用 Token 打开 Cursor 官网控制台'),
|
|
1158
|
+
message: '选择账号 (序号 / t / s / 0):',
|
|
1203
1159
|
choices,
|
|
1204
1160
|
pageSize: 12,
|
|
1205
1161
|
});
|
|
@@ -1253,9 +1209,6 @@ async function handleDashboardMenu(store, currentAcc) {
|
|
|
1253
1209
|
await DashboardLauncher.openDashboard(targetAcc);
|
|
1254
1210
|
await pressAnyKey();
|
|
1255
1211
|
}
|
|
1256
|
-
/**
|
|
1257
|
-
* 录入 Token 免密直达 Cursor 官网控制台
|
|
1258
|
-
*/
|
|
1259
1212
|
async function handleTokenDirectDashboard(store) {
|
|
1260
1213
|
console.clear();
|
|
1261
1214
|
console.log(chalk.bold.cyan('\n● 录入 Token 免密直达官网控制台 (Token Direct Dashboard)\n'));
|
|
@@ -1269,7 +1222,7 @@ async function handleTokenDirectDashboard(store) {
|
|
|
1269
1222
|
const rawToken = rawInput.trim();
|
|
1270
1223
|
const parsed = TokenParser.parse(rawToken);
|
|
1271
1224
|
if (!parsed.isValid) {
|
|
1272
|
-
console.log(chalk.red('\n未识别到有效的 Token
|
|
1225
|
+
console.log(chalk.red('\n未识别到有效的 Token 格式,支持一段 (user_xxx:: / eyJ...) 或三段打包串。\n'));
|
|
1273
1226
|
await pressAnyKey();
|
|
1274
1227
|
return;
|
|
1275
1228
|
}
|
|
@@ -1288,34 +1241,26 @@ async function handleTokenDirectDashboard(store) {
|
|
|
1288
1241
|
if (!email) {
|
|
1289
1242
|
email = `token_user_${Date.now().toString().slice(-4)}@cursor.sh`;
|
|
1290
1243
|
}
|
|
1291
|
-
// 同步会员与用量信息
|
|
1292
1244
|
const usageRes = await OfficialApiClient.fetchUsage(parsed.token);
|
|
1293
1245
|
const existing = store.getByEmail(email);
|
|
1294
|
-
const
|
|
1295
|
-
|
|
1296
|
-
: existing?.subscription_type || 'free';
|
|
1297
|
-
console.log(chalk.green(`✔ ${email} [${formatPlanName(subType)}]`));
|
|
1298
|
-
const targetAcc = {
|
|
1246
|
+
const targetAcc = applyParsedCredentialToAccount({
|
|
1247
|
+
parsed,
|
|
1299
1248
|
email,
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
};
|
|
1306
|
-
// 顺便录入本地账号库(若尚未保存)
|
|
1249
|
+
existing,
|
|
1250
|
+
usageRes,
|
|
1251
|
+
machineIds: existing?.machine_ids || generateMachineIds(),
|
|
1252
|
+
fallbackWorkosToToken: true,
|
|
1253
|
+
});
|
|
1254
|
+
console.log(chalk.green(`✔ ${email} [${formatPlanName(targetAcc.subscription_type)}]`));
|
|
1307
1255
|
if (!existing) {
|
|
1308
1256
|
store.addOrUpdate(targetAcc);
|
|
1309
1257
|
console.log(chalk.grey('✔ 已自动纳管录入本地多账号库,便于日后极速切换'));
|
|
1310
1258
|
}
|
|
1311
|
-
await
|
|
1259
|
+
await copyPreferredAccountCredential(targetAcc);
|
|
1312
1260
|
console.log(chalk.cyan(`\n正在调起全新独立浏览器并免密直达 Cursor 控制台 (${targetAcc.email})...`));
|
|
1313
1261
|
await DashboardLauncher.openDashboard(targetAcc);
|
|
1314
1262
|
await pressAnyKey();
|
|
1315
1263
|
}
|
|
1316
|
-
/**
|
|
1317
|
-
* 打开 Outlook 邮箱交互式菜单
|
|
1318
|
-
*/
|
|
1319
1264
|
async function handleOutlookMailMenu(store, currentAcc) {
|
|
1320
1265
|
while (true) {
|
|
1321
1266
|
console.clear();
|
|
@@ -1326,22 +1271,22 @@ async function handleOutlookMailMenu(store, currentAcc) {
|
|
|
1326
1271
|
const choices = [];
|
|
1327
1272
|
if (currentEmail) {
|
|
1328
1273
|
const hasPwd = Boolean(currentAcc?.email_password);
|
|
1329
|
-
const pwdTag = hasPwd ? chalk.green('[
|
|
1274
|
+
const pwdTag = hasPwd ? chalk.green('[有密码]') : chalk.yellow('[无密码]');
|
|
1330
1275
|
choices.push({
|
|
1331
|
-
name: `1.
|
|
1276
|
+
name: `1. 当前账号: ${chalk.bold.white(currentEmail)} ${pwdTag}`,
|
|
1332
1277
|
value: '__current__',
|
|
1333
|
-
description: hasPwd ? '
|
|
1278
|
+
description: hasPwd ? '使用已存密码自动登录' : '无密码,打开后手动登录',
|
|
1334
1279
|
});
|
|
1335
1280
|
}
|
|
1336
1281
|
choices.push({
|
|
1337
|
-
name: `2.
|
|
1282
|
+
name: `2. 从账号列表选择 (${accounts.length})`,
|
|
1338
1283
|
value: '__select__',
|
|
1339
|
-
description: '
|
|
1284
|
+
description: '从本地账号中选择并打开邮箱',
|
|
1340
1285
|
}, {
|
|
1341
|
-
name: '3.
|
|
1286
|
+
name: '3. 临时输入邮箱密码',
|
|
1342
1287
|
value: '__manual__',
|
|
1343
|
-
description: '
|
|
1344
|
-
}, new Separator(), { name: '0.
|
|
1288
|
+
description: '粘贴 email----password 临时打开',
|
|
1289
|
+
}, new Separator(), { name: '0. 返回', value: '__back__' });
|
|
1345
1290
|
let pick;
|
|
1346
1291
|
try {
|
|
1347
1292
|
pick = await quickSelect({
|
|
@@ -1432,7 +1377,7 @@ async function handleOutlookMailMenu(store, currentAcc) {
|
|
|
1432
1377
|
}
|
|
1433
1378
|
console.log(chalk.cyan(`\n正在调起全新独立浏览器并自动登录 ${email}...`));
|
|
1434
1379
|
if (openDashboard && cursorToken) {
|
|
1435
|
-
console.log(chalk.green(` [联动] 同时在浏览器新标签页免密打开 Cursor 控制台 (Token: ${cursorToken
|
|
1380
|
+
console.log(chalk.green(` [联动] 同时在浏览器新标签页免密打开 Cursor 控制台 (Token: ${maskToken(cursorToken)})`));
|
|
1436
1381
|
}
|
|
1437
1382
|
const res = await OutlookLauncher.openMailbox({
|
|
1438
1383
|
email,
|
|
@@ -1497,9 +1442,6 @@ async function executeMailboxOpen(store, account) {
|
|
|
1497
1442
|
OutlookLauncher.printResultCard(res);
|
|
1498
1443
|
await pressAnyKey();
|
|
1499
1444
|
}
|
|
1500
|
-
/**
|
|
1501
|
-
* 官方 PKCE OAuth 网页登录流程 (独立无痕浏览器实例 + 官方端点秒级自动回传)
|
|
1502
|
-
*/
|
|
1503
1445
|
async function handleOfficialOAuthAction(store, storage, sqlite, execPath) {
|
|
1504
1446
|
const result = await OAuthReceiver.startOfficialOAuthFlow();
|
|
1505
1447
|
if (!result.success || !result.accessToken) {
|
|
@@ -1509,7 +1451,6 @@ async function handleOfficialOAuthAction(store, storage, sqlite, execPath) {
|
|
|
1509
1451
|
await pressAnyKey();
|
|
1510
1452
|
return;
|
|
1511
1453
|
}
|
|
1512
|
-
// 1. 邮箱确认 (优先使用官方 RPC 接口精准查询到的邮箱)
|
|
1513
1454
|
let email = result.email;
|
|
1514
1455
|
if (!email) {
|
|
1515
1456
|
const fallback = result.authId
|
|
@@ -1521,36 +1462,27 @@ async function handleOfficialOAuthAction(store, storage, sqlite, execPath) {
|
|
|
1521
1462
|
});
|
|
1522
1463
|
email = inputEmail || fallback;
|
|
1523
1464
|
}
|
|
1524
|
-
// 2. 生成全新独立硬件指纹 (确保多账号隔离防封)
|
|
1525
1465
|
const machineIds = generateMachineIds();
|
|
1526
|
-
// 3. 官方同步用量与会员订阅
|
|
1527
1466
|
process.stdout.write(chalk.grey('\n正在向 Cursor 官方同步高速用量与订阅计划... '));
|
|
1528
1467
|
const usageRes = await OfficialApiClient.fetchUsage(result.accessToken);
|
|
1529
1468
|
const existing = store.getByEmail(email);
|
|
1530
|
-
const
|
|
1531
|
-
? usageRes.subscriptionType
|
|
1532
|
-
: existing?.subscription_type || 'free';
|
|
1533
|
-
console.log(chalk.green(`✔ ${formatPlanName(subType)}`));
|
|
1534
|
-
// 4. 入库保存
|
|
1535
|
-
const newAccount = {
|
|
1469
|
+
const newAccount = buildOAuthAccountInfo({
|
|
1536
1470
|
email,
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1471
|
+
accessToken: result.accessToken,
|
|
1472
|
+
refreshToken: result.refreshToken,
|
|
1473
|
+
authId: result.authId,
|
|
1474
|
+
usageRes,
|
|
1475
|
+
existing,
|
|
1476
|
+
machineIds,
|
|
1477
|
+
});
|
|
1478
|
+
console.log(chalk.green(`✔ ${formatPlanName(newAccount.subscription_type)}`));
|
|
1543
1479
|
store.addOrUpdate(newAccount);
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
` 专属指纹 : ${chalk.cyan(formatMachineIdSummary(machineIds))} ${chalk.dim('(独立隔离防封)')}`,
|
|
1551
|
-
` 官方凭据 : ${chalk.grey(newAccount.token.slice(0, 16))}...[已加密归档]`,
|
|
1552
|
-
` 系统剪贴板: ${copied ? chalk.green('✔ Token 已自动复制到系统剪贴板 (可直接粘贴)') : chalk.yellow('○ 请手动复制')}`,
|
|
1553
|
-
].join('\n'), { padding: { top: 0, bottom: 0, left: 1, right: 1 }, borderColor: 'green', borderStyle: 'round' }));
|
|
1480
|
+
await printExtractedCredentialsResult({
|
|
1481
|
+
header: '🎉 官方 OAuth 登录成功!账号已自动收录入库',
|
|
1482
|
+
account: newAccount,
|
|
1483
|
+
machineIds,
|
|
1484
|
+
showPlaintext: false,
|
|
1485
|
+
});
|
|
1554
1486
|
const doSwitch = await safeConfirm({
|
|
1555
1487
|
message: `是否立即切换到该账号 (${newAccount.email}) 并激活专属指纹?`,
|
|
1556
1488
|
default: true,
|
|
@@ -1562,22 +1494,20 @@ async function handleOfficialOAuthAction(store, storage, sqlite, execPath) {
|
|
|
1562
1494
|
await pressAnyKey();
|
|
1563
1495
|
}
|
|
1564
1496
|
}
|
|
1565
|
-
/**
|
|
1566
|
-
* 浏览器提取 Token 流程 (Browser Token Extractor)
|
|
1567
|
-
* 核心哲学:调起浏览器截获官方 Token;若本机 IDE 已登则自动免密秒提,免去开浏览器。
|
|
1568
|
-
*/
|
|
1569
1497
|
async function handleSmartExtractAction(store, storage, sqlite, execPath) {
|
|
1570
1498
|
console.clear();
|
|
1571
1499
|
console.log(chalk.bold.cyan('\n● 浏览器提取 Token (Browser Token Extractor)\n'));
|
|
1572
1500
|
process.stdout.write(chalk.cyan('正在智能探测本机 Cursor 登录凭据... '));
|
|
1573
|
-
const
|
|
1574
|
-
const
|
|
1575
|
-
|
|
1501
|
+
const localAuth = await readLocalCursorAuth(storage, sqlite);
|
|
1502
|
+
const currentEmail = localAuth.email;
|
|
1503
|
+
const currentToken = localAuth.token;
|
|
1504
|
+
if (!currentToken && localAuth.isEncrypted && localAuth.encryptionError) {
|
|
1505
|
+
console.log(chalk.yellow(`\n! 本地检测到新版 safeStorage 加密凭据但解密失败: ${localAuth.encryptionError}`));
|
|
1506
|
+
}
|
|
1576
1507
|
if (currentEmail && currentToken) {
|
|
1577
1508
|
console.log(chalk.green('✔ 已发现已登账号 (免开浏览器!)\n'));
|
|
1578
1509
|
const currentMachineIds = storage.readMachineIds();
|
|
1579
1510
|
const existing = store.getByEmail(currentEmail);
|
|
1580
|
-
// 查询官方会员与额度状态
|
|
1581
1511
|
let subscriptionType = existing?.subscription_type;
|
|
1582
1512
|
let currentPeriodUsage = existing?.current_period_usage;
|
|
1583
1513
|
try {
|
|
@@ -1615,38 +1545,39 @@ async function handleSmartExtractAction(store, storage, sqlite, execPath) {
|
|
|
1615
1545
|
` 本地状态 : ${isSaved ? chalk.green('● 已保存在本地库 (在用中)') : chalk.yellow('○ 尚未归档入库')}`,
|
|
1616
1546
|
].join('\n'), { padding: { top: 0, bottom: 0, left: 1, right: 1 }, borderColor: 'green', borderStyle: 'round' }));
|
|
1617
1547
|
const nextChoice = await quickSelect({
|
|
1618
|
-
message: '
|
|
1548
|
+
message: '选择操作:',
|
|
1619
1549
|
choices: [
|
|
1620
1550
|
{
|
|
1621
|
-
name: '1.
|
|
1551
|
+
name: '1. 复制 Token',
|
|
1622
1552
|
value: 'copy_token',
|
|
1623
|
-
description: '
|
|
1553
|
+
description: '复制 Access 或 WorkOS Token 到剪贴板',
|
|
1624
1554
|
},
|
|
1625
1555
|
{
|
|
1626
|
-
name: isSaved ? '2.
|
|
1556
|
+
name: isSaved ? '2. 刷新额度与用量' : '2. 保存到本地账号库',
|
|
1627
1557
|
value: 'save_or_refresh',
|
|
1628
|
-
description: isSaved ? '
|
|
1558
|
+
description: isSaved ? '同步最新额度与订阅周期' : '保存账号与设备指纹到本地',
|
|
1629
1559
|
},
|
|
1630
1560
|
{
|
|
1631
|
-
name: '3.
|
|
1561
|
+
name: '3. 浏览器登录新账号',
|
|
1632
1562
|
value: 'browser_new',
|
|
1633
|
-
description: '
|
|
1563
|
+
description: '打开浏览器登录提取其他账号',
|
|
1634
1564
|
},
|
|
1635
1565
|
new Separator(),
|
|
1636
|
-
{ name: '0.
|
|
1566
|
+
{ name: '0. 返回', value: '__back__' },
|
|
1637
1567
|
],
|
|
1638
1568
|
});
|
|
1639
1569
|
if (nextChoice === '__back__' || !nextChoice) {
|
|
1640
1570
|
return;
|
|
1641
1571
|
}
|
|
1642
1572
|
if (nextChoice === 'copy_token') {
|
|
1643
|
-
await handleCopyTokenAction(currentEmail, currentToken, existing?.workos_cursor_session_token, currentMachineIds);
|
|
1573
|
+
await handleCopyTokenAction(currentEmail, currentToken, existing?.workos_cursor_session_token, currentMachineIds, localAuth.refreshToken || existing?.refresh_token);
|
|
1644
1574
|
continue;
|
|
1645
1575
|
}
|
|
1646
1576
|
if (nextChoice === 'save_or_refresh') {
|
|
1647
1577
|
const accObj = {
|
|
1648
1578
|
email: currentEmail,
|
|
1649
1579
|
token: currentToken,
|
|
1580
|
+
refresh_token: localAuth.refreshToken || existing?.refresh_token,
|
|
1650
1581
|
workos_cursor_session_token: existing?.workos_cursor_session_token,
|
|
1651
1582
|
machine_ids: currentMachineIds,
|
|
1652
1583
|
subscription_type: subscriptionType || existing?.subscription_type || 'free',
|
|
@@ -1667,24 +1598,23 @@ async function handleSmartExtractAction(store, storage, sqlite, execPath) {
|
|
|
1667
1598
|
else {
|
|
1668
1599
|
console.log(chalk.yellow('○ 本机未登录,将直接调起浏览器打开官网进行登录提取...\n'));
|
|
1669
1600
|
}
|
|
1670
|
-
// 2. 本机未登录,或者用户明确选择录入另一个新账号:
|
|
1671
1601
|
console.clear();
|
|
1672
1602
|
console.log(chalk.bold.cyan('\n● 浏览器提取与录入 Token (Browser Token Extractor)\n'));
|
|
1673
1603
|
const extractChoice = await quickSelect({
|
|
1674
|
-
message: '
|
|
1604
|
+
message: '提取方式:',
|
|
1675
1605
|
choices: [
|
|
1676
1606
|
{
|
|
1677
|
-
name: '1.
|
|
1607
|
+
name: '1. 浏览器 OAuth 登录',
|
|
1678
1608
|
value: 'oauth',
|
|
1679
|
-
description: '
|
|
1609
|
+
description: '无痕浏览器登录并自动截获 Token',
|
|
1680
1610
|
},
|
|
1681
1611
|
{
|
|
1682
|
-
name: '2.
|
|
1612
|
+
name: '2. 手动粘贴 Token',
|
|
1683
1613
|
value: 'paste',
|
|
1684
|
-
description: '
|
|
1614
|
+
description: '粘贴 user_xxx:: 或 eyJ... 凭据入库',
|
|
1685
1615
|
},
|
|
1686
1616
|
new Separator(),
|
|
1687
|
-
{ name: '0.
|
|
1617
|
+
{ name: '0. 返回', value: '__back__' },
|
|
1688
1618
|
],
|
|
1689
1619
|
});
|
|
1690
1620
|
if (extractChoice === '__back__' || !extractChoice) {
|
|
@@ -1694,13 +1624,12 @@ async function handleSmartExtractAction(store, storage, sqlite, execPath) {
|
|
|
1694
1624
|
await handleOfficialOAuthAction(store, storage, sqlite, execPath);
|
|
1695
1625
|
return;
|
|
1696
1626
|
}
|
|
1697
|
-
// 手动粘贴流程
|
|
1698
1627
|
console.log(chalk.white('\n💡 获取 Token 方式(任选其一,均可直接粘贴):'));
|
|
1699
1628
|
console.log(chalk.grey(' • 方式 1: 浏览器登录后,在个人设置或 Cookie 复制 user_xxx:: 或 eyJ... 凭据'));
|
|
1700
|
-
console.log(chalk.grey(' • 方式 2:
|
|
1629
|
+
console.log(chalk.grey(' • 方式 2: 支持直接粘贴三段完整凭据串 (Access----Refresh----Web)\n'));
|
|
1701
1630
|
console.log(chalk.grey(' (输入 0 或按回车取消返回)\n'));
|
|
1702
1631
|
const rawInput = await safeInput({
|
|
1703
|
-
message: '
|
|
1632
|
+
message: '请在此粘贴凭据 (支持一段 user_xxx:: / eyJ... 或三段打包串):',
|
|
1704
1633
|
});
|
|
1705
1634
|
if (!rawInput || rawInput.trim() === '0' || rawInput.trim().toLowerCase() === 'q') {
|
|
1706
1635
|
console.log(chalk.grey('\n已取消提取操作,正在返回...\n'));
|
|
@@ -1710,7 +1639,7 @@ async function handleSmartExtractAction(store, storage, sqlite, execPath) {
|
|
|
1710
1639
|
const rawToken = rawInput.trim();
|
|
1711
1640
|
const parsed = TokenParser.parse(rawToken);
|
|
1712
1641
|
if (!parsed.isValid) {
|
|
1713
|
-
console.log(chalk.red('\n未识别到有效的 Token
|
|
1642
|
+
console.log(chalk.red('\n未识别到有效的 Token 格式,支持一段 (user_xxx:: / eyJ...) 或三段打包串。\n'));
|
|
1714
1643
|
await pressAnyKey();
|
|
1715
1644
|
return;
|
|
1716
1645
|
}
|
|
@@ -1720,25 +1649,25 @@ async function handleSmartExtractAction(store, storage, sqlite, execPath) {
|
|
|
1720
1649
|
const fallbackEmail = parsed.sub ? `${parsed.sub.replace('auth0|', '')}@cursor.sh` : `account_${Date.now().toString().slice(-6)}@cursor.sh`;
|
|
1721
1650
|
const email = parsed.email || fallbackEmail;
|
|
1722
1651
|
const existing = store.getByEmail(email);
|
|
1723
|
-
const
|
|
1652
|
+
const draftAccount = applyParsedCredentialToAccount({
|
|
1653
|
+
parsed,
|
|
1724
1654
|
email,
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1655
|
+
existing,
|
|
1656
|
+
usageRes,
|
|
1657
|
+
machineIds,
|
|
1658
|
+
fallbackWorkosToToken: true,
|
|
1659
|
+
});
|
|
1660
|
+
printFactualTokenStatus(draftAccount.token, draftAccount.refresh_token, draftAccount.workos_cursor_session_token);
|
|
1661
|
+
const ingestRes = await upgradeAccountWebTokenOnIngest(draftAccount);
|
|
1662
|
+
const newAccount = ingestRes.account;
|
|
1731
1663
|
store.addOrUpdate(newAccount);
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
` 官方凭据 : ${chalk.grey(rawToken.slice(0, 16))}...[已加密保护]`,
|
|
1740
|
-
` 系统剪贴板: ${copied ? chalk.green('✔ Token 已自动复制到系统剪贴板 (可直接粘贴)') : chalk.yellow('○ 请手动复制')}`,
|
|
1741
|
-
].join('\n'), { padding: { top: 0, bottom: 0, left: 1, right: 1 }, borderColor: 'green', borderStyle: 'round' }));
|
|
1664
|
+
printIngestUpgradeResult(ingestRes);
|
|
1665
|
+
await printExtractedCredentialsResult({
|
|
1666
|
+
header: '✔ 账号 Token 录入成功!已加入本地多账号库',
|
|
1667
|
+
account: newAccount,
|
|
1668
|
+
machineIds,
|
|
1669
|
+
showPlaintext: false,
|
|
1670
|
+
});
|
|
1742
1671
|
const doSwitch = await safeConfirm({
|
|
1743
1672
|
message: `是否立即切换到该账号 (${newAccount.email}) 并激活专属指纹?`,
|
|
1744
1673
|
default: true,
|
|
@@ -1750,19 +1679,13 @@ async function handleSmartExtractAction(store, storage, sqlite, execPath) {
|
|
|
1750
1679
|
await pressAnyKey();
|
|
1751
1680
|
}
|
|
1752
1681
|
}
|
|
1753
|
-
/**
|
|
1754
|
-
* 兼容性别名
|
|
1755
|
-
*/
|
|
1756
1682
|
async function handleBrowserTokenAction(store, storage, sqlite, execPath) {
|
|
1757
1683
|
return handleSmartExtractAction(store, storage, sqlite, execPath);
|
|
1758
1684
|
}
|
|
1759
1685
|
async function handleCaptureAction(store, storage, sqlite) {
|
|
1760
1686
|
return handleSmartExtractAction(store, storage, sqlite);
|
|
1761
1687
|
}
|
|
1762
|
-
|
|
1763
|
-
* 机器指纹管理
|
|
1764
|
-
*/
|
|
1765
|
-
async function handleFingerprintMenu(storage, currentAcc) {
|
|
1688
|
+
async function handleFingerprintMenu(storage, currentAcc, sqlite) {
|
|
1766
1689
|
const currentIds = storage.readMachineIds();
|
|
1767
1690
|
console.log(chalk.bold.cyan('\n当前设备硬件指纹详情:'));
|
|
1768
1691
|
console.log(chalk.grey(`• devDeviceId : ${chalk.white(currentIds['telemetry.devDeviceId'] || '--')}`));
|
|
@@ -1770,23 +1693,35 @@ async function handleFingerprintMenu(storage, currentAcc) {
|
|
|
1770
1693
|
console.log(chalk.grey(`• macMachineId : ${chalk.white(maskToken(currentIds['telemetry.macMachineId']))}`));
|
|
1771
1694
|
console.log(chalk.grey(`• machineId : ${chalk.white(maskToken(currentIds['telemetry.machineId']))}\n`));
|
|
1772
1695
|
const fpAction = await quickSelect({
|
|
1773
|
-
message: '
|
|
1696
|
+
message: '指纹操作:',
|
|
1774
1697
|
choices: [
|
|
1775
|
-
{ name: '1.
|
|
1776
|
-
{ name: '2.
|
|
1698
|
+
{ name: '1. 重置随机指纹', value: 'reset', description: '生成全新随机设备指纹' },
|
|
1699
|
+
{ name: '2. 备份当前指纹', value: 'backup', description: '创建当前指纹快照' },
|
|
1777
1700
|
new Separator(),
|
|
1778
|
-
{ name: '0.
|
|
1701
|
+
{ name: '0. 返回', value: 'back' },
|
|
1779
1702
|
],
|
|
1780
1703
|
});
|
|
1781
1704
|
if (fpAction === 'back') {
|
|
1782
1705
|
return;
|
|
1783
1706
|
}
|
|
1784
1707
|
if (fpAction === 'reset') {
|
|
1708
|
+
const paths = resolveCursorPaths();
|
|
1709
|
+
const activeSqlite = sqlite || new SqliteBridge(paths.sqliteDb);
|
|
1785
1710
|
const newIds = generateMachineIds();
|
|
1786
1711
|
storage.createBackup();
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1712
|
+
activeSqlite.createBackup();
|
|
1713
|
+
const applied = await applyMachineIdsToCursor({
|
|
1714
|
+
storage,
|
|
1715
|
+
sqlite: activeSqlite,
|
|
1716
|
+
paths,
|
|
1717
|
+
machineIds: newIds,
|
|
1718
|
+
});
|
|
1719
|
+
console.log(chalk.green('\n✔ 机器指纹已全链路重置为全套随机硬件码!旧指纹已安全备份。'));
|
|
1720
|
+
console.log(chalk.grey(`新 devDeviceId: ${newIds['telemetry.devDeviceId']}`));
|
|
1721
|
+
if (applied.sidecarReport.machineIdFileUpdated) {
|
|
1722
|
+
console.log(chalk.grey(`已同步更新 ${paths.machineIdFile}`));
|
|
1723
|
+
}
|
|
1724
|
+
console.log('');
|
|
1790
1725
|
}
|
|
1791
1726
|
else if (fpAction === 'backup') {
|
|
1792
1727
|
const backupPath = storage.createBackup();
|
|
@@ -1794,9 +1729,6 @@ async function handleFingerprintMenu(storage, currentAcc) {
|
|
|
1794
1729
|
}
|
|
1795
1730
|
await pressAnyKey();
|
|
1796
1731
|
}
|
|
1797
|
-
/**
|
|
1798
|
-
* 备份操作
|
|
1799
|
-
*/
|
|
1800
1732
|
async function handleBackupAction(storage, sqlite) {
|
|
1801
1733
|
const b1 = storage.createBackup();
|
|
1802
1734
|
const b2 = sqlite.createBackup();
|
|
@@ -1805,42 +1737,39 @@ async function handleBackupAction(storage, sqlite) {
|
|
|
1805
1737
|
console.log(chalk.grey(`• sqlite 备份 : ${b2}\n`));
|
|
1806
1738
|
await pressAnyKey();
|
|
1807
1739
|
}
|
|
1808
|
-
/**
|
|
1809
|
-
* 奥仔退款 (席位刷新/重置额度) 交互子流程 (极简智能引导版)
|
|
1810
|
-
*/
|
|
1811
1740
|
async function handleRefundMenu(store, currentAcc) {
|
|
1812
1741
|
const refundService = new RefundService();
|
|
1813
1742
|
const config = refundService.getConfigStore();
|
|
1814
1743
|
let cardCode = config.getSeatCardCode();
|
|
1815
1744
|
let cachedAuthInfo = null;
|
|
1745
|
+
let lastAuthError = '';
|
|
1816
1746
|
let lastVerifiedCard = '';
|
|
1817
|
-
// 1. 如果尚未绑定卡密:主动向导,一步到位,绝不让用户在无用菜单中迷失
|
|
1818
1747
|
if (!cardCode) {
|
|
1819
1748
|
console.clear();
|
|
1820
1749
|
console.log(boxen([
|
|
1821
|
-
`${chalk.bold.cyan('CURSOR-SWITCH')} ${chalk.dim('●')} ${chalk.bold.white('
|
|
1822
|
-
chalk.dim('
|
|
1823
|
-
'
|
|
1824
|
-
chalk.dim('•
|
|
1825
|
-
chalk.dim('•
|
|
1750
|
+
`${chalk.bold.cyan('CURSOR-SWITCH')} ${chalk.dim('●')} ${chalk.bold.white('Cursor 退款服务')}`,
|
|
1751
|
+
chalk.dim('────────────────────────────────────────────────────────'),
|
|
1752
|
+
'请输入退款卡密(与 getdoubao.com 通用)。',
|
|
1753
|
+
chalk.dim('• 失败保障 : 退款失败点数自动退还'),
|
|
1754
|
+
chalk.dim('• 取消返回 : 输入 0、q 或直接按回车'),
|
|
1826
1755
|
].join('\n'), {
|
|
1827
1756
|
padding: { top: 0, bottom: 0, left: 1, right: 1 },
|
|
1828
1757
|
borderColor: 'cyan',
|
|
1829
1758
|
borderStyle: 'round',
|
|
1830
1759
|
}));
|
|
1831
|
-
const inputCode = await safeInput({ message: '
|
|
1760
|
+
const inputCode = await safeInput({ message: '请输入卡密' });
|
|
1832
1761
|
if (!inputCode) {
|
|
1833
|
-
return;
|
|
1762
|
+
return;
|
|
1834
1763
|
}
|
|
1835
|
-
process.stdout.write(chalk.cyan('\n
|
|
1764
|
+
process.stdout.write(chalk.cyan('\n正在验证卡密... '));
|
|
1836
1765
|
const testRes = await refundService.getClient().login(inputCode);
|
|
1837
1766
|
if (!testRes.success || !testRes.data) {
|
|
1838
|
-
console.log(chalk.red('✖
|
|
1767
|
+
console.log(chalk.red('✖ 不可用\n'));
|
|
1768
|
+
const { humanHint } = ExtractService.summarizeCardError(testRes.error);
|
|
1839
1769
|
console.log(boxen([
|
|
1840
1770
|
chalk.bold.red('✖ 卡密验证未通过'),
|
|
1841
1771
|
chalk.dim('────────────────────────────────────────────────'),
|
|
1842
|
-
`
|
|
1843
|
-
' 排查建议 : 请检查卡密拼写,确保无多余前后空格。',
|
|
1772
|
+
` 原因 : ${chalk.yellow(humanHint)}`,
|
|
1844
1773
|
].join('\n'), {
|
|
1845
1774
|
padding: { top: 0, bottom: 0, left: 1, right: 1 },
|
|
1846
1775
|
borderColor: 'red',
|
|
@@ -1849,91 +1778,99 @@ async function handleRefundMenu(store, currentAcc) {
|
|
|
1849
1778
|
await pressAnyKey();
|
|
1850
1779
|
return;
|
|
1851
1780
|
}
|
|
1852
|
-
console.log(chalk.green('✔
|
|
1781
|
+
console.log(chalk.green('✔ 验证通过!\n'));
|
|
1853
1782
|
config.setSeatCardCode(inputCode);
|
|
1854
1783
|
cardCode = inputCode;
|
|
1855
1784
|
cachedAuthInfo = testRes.data;
|
|
1785
|
+
lastAuthError = '';
|
|
1856
1786
|
lastVerifiedCard = inputCode;
|
|
1857
1787
|
await new Promise((r) => setTimeout(r, 800));
|
|
1858
1788
|
}
|
|
1859
|
-
// 2. 已有卡密状态下的极简控制面板 (扁平直达,核心操作一目了然)
|
|
1860
1789
|
while (true) {
|
|
1861
|
-
console.clear();
|
|
1862
|
-
// 缓存鉴权状态,避免每次切菜单都发网络请求
|
|
1863
1790
|
if (cardCode && cardCode !== lastVerifiedCard) {
|
|
1864
1791
|
try {
|
|
1865
1792
|
const loginRes = await refundService.getClient().login(cardCode);
|
|
1866
1793
|
if (loginRes.success && loginRes.data) {
|
|
1867
1794
|
cachedAuthInfo = loginRes.data;
|
|
1795
|
+
lastAuthError = '';
|
|
1868
1796
|
lastVerifiedCard = cardCode;
|
|
1869
1797
|
}
|
|
1870
1798
|
else {
|
|
1871
1799
|
cachedAuthInfo = null;
|
|
1800
|
+
lastAuthError = loginRes.error || '卡密无效或已停用';
|
|
1801
|
+
lastVerifiedCard = cardCode;
|
|
1872
1802
|
}
|
|
1873
1803
|
}
|
|
1874
1804
|
catch {
|
|
1875
1805
|
cachedAuthInfo = null;
|
|
1806
|
+
lastAuthError = '网络异常,请重试';
|
|
1876
1807
|
}
|
|
1877
1808
|
}
|
|
1809
|
+
const refundErr = !cachedAuthInfo && lastAuthError ? ExtractService.summarizeCardError(lastAuthError) : null;
|
|
1878
1810
|
const cardInfoDesc = cardCode
|
|
1879
1811
|
? cachedAuthInfo
|
|
1880
|
-
? `${chalk.white(maskToken(cardCode))}
|
|
1881
|
-
:
|
|
1882
|
-
|
|
1883
|
-
|
|
1812
|
+
? `${chalk.white(maskToken(cardCode))} | 剩余: ${chalk.bold.green(cachedAuthInfo.remaining)} 点 (${cachedAuthInfo.pointsPerOp} 点/次)`
|
|
1813
|
+
: refundErr
|
|
1814
|
+
? `${chalk.white(maskToken(cardCode))} | ${chalk.bold.red(`${refundErr.shortTag} (按 3 换卡)`)}`
|
|
1815
|
+
: `${chalk.white(maskToken(cardCode))} ${chalk.dim('[本地已存]')}`
|
|
1816
|
+
: chalk.yellow('未绑定卡密');
|
|
1817
|
+
const currentEmailStr = currentAcc?.email ? chalk.bold.white(currentAcc.email) : chalk.dim('未登录');
|
|
1884
1818
|
const subHeader = boxen([
|
|
1885
|
-
`${chalk.bold.cyan('CURSOR-SWITCH')} ${chalk.dim('●')} ${chalk.bold.white('
|
|
1886
|
-
chalk.dim('
|
|
1887
|
-
`
|
|
1888
|
-
`
|
|
1819
|
+
`${chalk.bold.cyan('CURSOR-SWITCH')} ${chalk.dim('●')} ${chalk.bold.white('Cursor 退款')} ${chalk.green('失败退点')}`,
|
|
1820
|
+
chalk.dim('────────────────────────────────────────────────────────'),
|
|
1821
|
+
` 卡密 : ${cardInfoDesc}`,
|
|
1822
|
+
...(refundErr ? [` 提示 : ${chalk.yellow(refundErr.humanHint)}`] : []),
|
|
1823
|
+
` 账号 : ${currentEmailStr}`,
|
|
1889
1824
|
].join('\n'), {
|
|
1890
1825
|
padding: { top: 0, bottom: 0, left: 1, right: 1 },
|
|
1891
1826
|
margin: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
1892
|
-
borderColor: 'gray',
|
|
1827
|
+
borderColor: refundErr ? 'yellow' : 'gray',
|
|
1893
1828
|
borderStyle: 'round',
|
|
1894
1829
|
});
|
|
1895
1830
|
const targetDesc = currentAcc?.email
|
|
1896
|
-
?
|
|
1897
|
-
: '
|
|
1831
|
+
? `退款 ${currentAcc.email} 并恢复 Free`
|
|
1832
|
+
: '退款当前账号并恢复 Free';
|
|
1898
1833
|
const choices = [
|
|
1899
1834
|
{
|
|
1900
|
-
name: `1.
|
|
1835
|
+
name: `1. 退款当前账号 ${currentAcc?.email ? chalk.dim(`(${currentAcc.email})`) : ''}`.trim(),
|
|
1901
1836
|
value: 'current',
|
|
1902
1837
|
description: targetDesc,
|
|
1903
1838
|
},
|
|
1904
1839
|
{
|
|
1905
|
-
name: '2.
|
|
1840
|
+
name: '2. 选择其他账号 / 粘贴 Token',
|
|
1906
1841
|
value: 'select',
|
|
1907
|
-
description: '
|
|
1842
|
+
description: '从列表选号或粘贴 Token 退款',
|
|
1908
1843
|
},
|
|
1909
1844
|
{
|
|
1910
|
-
name: `3.
|
|
1845
|
+
name: `3. 更换卡密 ${cachedAuthInfo ? chalk.dim(`(剩 ${cachedAuthInfo.remaining} 点)`) : ''}`.trim(),
|
|
1911
1846
|
value: 'rebind',
|
|
1912
|
-
description: '
|
|
1847
|
+
description: '更换退款卡密',
|
|
1913
1848
|
},
|
|
1914
1849
|
{
|
|
1915
|
-
name: '4.
|
|
1850
|
+
name: '4. 使用记录',
|
|
1916
1851
|
value: 'usage',
|
|
1917
|
-
description: '
|
|
1852
|
+
description: '查询退款与扣点记录',
|
|
1918
1853
|
},
|
|
1919
1854
|
new Separator(),
|
|
1920
1855
|
{
|
|
1921
|
-
name: '0.
|
|
1856
|
+
name: '0. 返回',
|
|
1922
1857
|
value: '__back__',
|
|
1923
|
-
description: '
|
|
1858
|
+
description: '返回主菜单',
|
|
1924
1859
|
},
|
|
1925
1860
|
];
|
|
1926
1861
|
let action;
|
|
1927
1862
|
try {
|
|
1928
1863
|
action = await quickSelect({
|
|
1929
1864
|
header: subHeader,
|
|
1930
|
-
message: '
|
|
1865
|
+
message: '选择操作:',
|
|
1931
1866
|
choices,
|
|
1932
1867
|
pageSize: 7,
|
|
1868
|
+
altScreen: true,
|
|
1933
1869
|
});
|
|
1934
1870
|
}
|
|
1935
1871
|
catch (err) {
|
|
1936
1872
|
if (err?.name === 'ExitPromptError') {
|
|
1873
|
+
leaveAltScreenIfActive();
|
|
1937
1874
|
process.stdout.write('\x1b[?25h\n');
|
|
1938
1875
|
process.exit(0);
|
|
1939
1876
|
}
|
|
@@ -1942,7 +1879,6 @@ async function handleRefundMenu(store, currentAcc) {
|
|
|
1942
1879
|
if (action === '__back__' || action === 'exit') {
|
|
1943
1880
|
return;
|
|
1944
1881
|
}
|
|
1945
|
-
// 1. 退款当前账号
|
|
1946
1882
|
if (action === 'current') {
|
|
1947
1883
|
if (!currentAcc) {
|
|
1948
1884
|
console.clear();
|
|
@@ -1964,9 +1900,7 @@ async function handleRefundMenu(store, currentAcc) {
|
|
|
1964
1900
|
});
|
|
1965
1901
|
continue;
|
|
1966
1902
|
}
|
|
1967
|
-
// 2. 选择其他账号退款 (支持本地列表 + 手动粘贴 Token)
|
|
1968
1903
|
if (action === 'select') {
|
|
1969
|
-
console.clear();
|
|
1970
1904
|
const accounts = store.loadAll();
|
|
1971
1905
|
const accChoices = [
|
|
1972
1906
|
{
|
|
@@ -1993,10 +1927,12 @@ async function handleRefundMenu(store, currentAcc) {
|
|
|
1993
1927
|
message: '请选择目标账号或方式 (按键快捷直达):',
|
|
1994
1928
|
choices: accChoices,
|
|
1995
1929
|
pageSize: 12,
|
|
1930
|
+
altScreen: true,
|
|
1996
1931
|
});
|
|
1997
1932
|
}
|
|
1998
1933
|
catch (err) {
|
|
1999
1934
|
if (err?.name === 'ExitPromptError') {
|
|
1935
|
+
leaveAltScreenIfActive();
|
|
2000
1936
|
process.stdout.write('\x1b[?25h\n');
|
|
2001
1937
|
process.exit(0);
|
|
2002
1938
|
}
|
|
@@ -2040,14 +1976,13 @@ async function handleRefundMenu(store, currentAcc) {
|
|
|
2040
1976
|
}
|
|
2041
1977
|
continue;
|
|
2042
1978
|
}
|
|
2043
|
-
// 3. 更换席位卡密 (直接从主菜单进入,扁平快捷)
|
|
2044
1979
|
if (action === 'rebind') {
|
|
2045
1980
|
console.clear();
|
|
2046
1981
|
console.log(boxen([
|
|
2047
|
-
chalk.bold.cyan('●
|
|
1982
|
+
chalk.bold.cyan('● 更换退款卡密'),
|
|
2048
1983
|
chalk.dim('────────────────────────────────────────────────'),
|
|
2049
1984
|
` 当前卡密 : ${cardCode ? chalk.white(maskToken(cardCode)) : chalk.dim('无')} (剩余: ${cachedAuthInfo?.remaining ?? '--'} 点)`,
|
|
2050
|
-
'
|
|
1985
|
+
' 请输入新的 Cursor 退款服务卡密 (验证通过后自动更新本地配置)。',
|
|
2051
1986
|
chalk.dim('• 本地安全 : 仅保存于本地 ~/.cursor-switch/config.json'),
|
|
2052
1987
|
chalk.dim('• 取消方式 : 输入 0、q 或直接按回车可取消返回'),
|
|
2053
1988
|
].join('\n'), {
|
|
@@ -2055,25 +1990,24 @@ async function handleRefundMenu(store, currentAcc) {
|
|
|
2055
1990
|
borderColor: 'cyan',
|
|
2056
1991
|
borderStyle: 'round',
|
|
2057
1992
|
}));
|
|
2058
|
-
const newCode = await safeInput({ message: '
|
|
1993
|
+
const newCode = await safeInput({ message: '新退款卡密' });
|
|
2059
1994
|
if (!newCode || newCode === '0' || newCode.toLowerCase() === 'q') {
|
|
2060
1995
|
continue;
|
|
2061
1996
|
}
|
|
2062
|
-
process.stdout.write(chalk.cyan('\n
|
|
1997
|
+
process.stdout.write(chalk.cyan('\n正在连接 Cursor 退款服务网关验证卡密有效性... '));
|
|
2063
1998
|
const testRes = await refundService.getClient().login(newCode);
|
|
2064
1999
|
if (testRes.success && testRes.data) {
|
|
2065
2000
|
console.log(chalk.green('✔ 验证通过\n'));
|
|
2066
2001
|
config.setSeatCardCode(newCode);
|
|
2067
2002
|
cardCode = newCode;
|
|
2068
2003
|
cachedAuthInfo = testRes.data;
|
|
2004
|
+
lastAuthError = '';
|
|
2069
2005
|
lastVerifiedCard = newCode;
|
|
2070
2006
|
console.log(boxen([
|
|
2071
|
-
chalk.bold.green('✔
|
|
2007
|
+
chalk.bold.green('✔ 退款卡密已更新!'),
|
|
2072
2008
|
chalk.dim('────────────────────────────────────────────────'),
|
|
2073
|
-
`
|
|
2074
|
-
`
|
|
2075
|
-
` 单次费率 : ${chalk.yellow(testRes.data.pointsPerOp)} 点/单`,
|
|
2076
|
-
chalk.dim(' 已永久更新至本地配置,后续打开无需再次输入。'),
|
|
2009
|
+
` 新卡密 : ${chalk.white(maskToken(newCode))}`,
|
|
2010
|
+
` 剩余 : ${chalk.bold.green(testRes.data.remaining)} 点 (${testRes.data.pointsPerOp} 点/次)`,
|
|
2077
2011
|
].join('\n'), {
|
|
2078
2012
|
padding: { top: 0, bottom: 0, left: 1, right: 1 },
|
|
2079
2013
|
borderColor: 'green',
|
|
@@ -2081,12 +2015,13 @@ async function handleRefundMenu(store, currentAcc) {
|
|
|
2081
2015
|
}));
|
|
2082
2016
|
}
|
|
2083
2017
|
else {
|
|
2084
|
-
console.log(chalk.red('✖
|
|
2018
|
+
console.log(chalk.red('✖ 不可用\n'));
|
|
2019
|
+
const { humanHint } = ExtractService.summarizeCardError(testRes.error);
|
|
2085
2020
|
console.log(boxen([
|
|
2086
2021
|
chalk.bold.red('✖ 卡密验证未通过'),
|
|
2087
2022
|
chalk.dim('────────────────────────────────────────────────'),
|
|
2088
|
-
`
|
|
2089
|
-
'
|
|
2023
|
+
` 原因 : ${chalk.yellow(humanHint)}`,
|
|
2024
|
+
' 说明 : 未作更改,仍保留原卡密。',
|
|
2090
2025
|
].join('\n'), {
|
|
2091
2026
|
padding: { top: 0, bottom: 0, left: 1, right: 1 },
|
|
2092
2027
|
borderColor: 'red',
|
|
@@ -2096,16 +2031,12 @@ async function handleRefundMenu(store, currentAcc) {
|
|
|
2096
2031
|
await pressAnyKey();
|
|
2097
2032
|
continue;
|
|
2098
2033
|
}
|
|
2099
|
-
// 4. 查看卡密流水明细 (直接从主菜单进入)
|
|
2100
2034
|
if (action === 'usage') {
|
|
2101
2035
|
await refundService.printUsageHistory(cardCode || undefined);
|
|
2102
2036
|
continue;
|
|
2103
2037
|
}
|
|
2104
2038
|
}
|
|
2105
2039
|
}
|
|
2106
|
-
/**
|
|
2107
|
-
* 版本检查与一键自升级交互子流程
|
|
2108
|
-
*/
|
|
2109
2040
|
async function handleUpgradeMenu(updateChecker) {
|
|
2110
2041
|
console.clear();
|
|
2111
2042
|
console.log(chalk.bold.cyan('\n● 检查更新 / 在线升级 (Online Version Checker & Upgrader)\n'));
|
|
@@ -2135,12 +2066,12 @@ async function handleUpgradeMenu(updateChecker) {
|
|
|
2135
2066
|
let choice;
|
|
2136
2067
|
try {
|
|
2137
2068
|
choice = await quickSelect({
|
|
2138
|
-
message: '
|
|
2069
|
+
message: '升级方式:',
|
|
2139
2070
|
choices: [
|
|
2140
|
-
{ name: '1.
|
|
2141
|
-
{ name: '2.
|
|
2071
|
+
{ name: '1. npm 官方源升级', value: 'npm', description: `使用 ${pm.name} 从官方源升级` },
|
|
2072
|
+
{ name: '2. 国内镜像升级 (npmmirror)', value: 'mirror', description: '使用国内镜像下载升级' },
|
|
2142
2073
|
new Separator(),
|
|
2143
|
-
{ name: '0.
|
|
2074
|
+
{ name: '0. 返回', value: '__back__' },
|
|
2144
2075
|
],
|
|
2145
2076
|
});
|
|
2146
2077
|
}
|
|
@@ -2172,40 +2103,6 @@ async function handleUpgradeMenu(updateChecker) {
|
|
|
2172
2103
|
}
|
|
2173
2104
|
await pressAnyKey();
|
|
2174
2105
|
}
|
|
2175
|
-
/**
|
|
2176
|
-
* 调起默认浏览器打开 AI 折腾局官网
|
|
2177
|
-
*/
|
|
2178
|
-
async function handleOpenWebsiteAction() {
|
|
2179
|
-
const url = 'https://getdoubao.com';
|
|
2180
|
-
console.log(chalk.cyan(`\n正在调起系统默认浏览器打开 AI 折腾局官网: ${chalk.bold.white(url)} ...`));
|
|
2181
|
-
const ok = await openBrowserUrl(url);
|
|
2182
|
-
if (ok) {
|
|
2183
|
-
console.log(chalk.green('✔ 官网已在默认浏览器中打开 (含折腾手册、开源工具、福利与自助服务)\n'));
|
|
2184
|
-
}
|
|
2185
|
-
else {
|
|
2186
|
-
console.log(chalk.yellow(`未能自动唤起浏览器,请手动复制并在浏览器中打开: ${url}\n`));
|
|
2187
|
-
}
|
|
2188
|
-
await pressAnyKey();
|
|
2189
|
-
}
|
|
2190
|
-
/**
|
|
2191
|
-
* 官方 QQ 交流群展示与一键复制
|
|
2192
|
-
*/
|
|
2193
|
-
async function handleQqGroupAction() {
|
|
2194
|
-
const qqGroup = '1007446249';
|
|
2195
|
-
const copied = await copyToClipboard(qqGroup);
|
|
2196
|
-
console.clear();
|
|
2197
|
-
console.log(chalk.bold.cyan('\n● 官方 QQ 交流群 (Community & Support)\n'));
|
|
2198
|
-
console.log(boxen([
|
|
2199
|
-
`${chalk.bold.yellow('🐧 欢迎加入 AI 折腾局官方交流群')}`,
|
|
2200
|
-
chalk.dim('────────────────────────────────────────────────'),
|
|
2201
|
-
` QQ 群号 : ${chalk.bold.green(qqGroup)}`,
|
|
2202
|
-
` 群号复制 : ${copied ? chalk.green('✔ 已自动复制到系统剪贴板 (直接在 QQ 粘贴即可查找加入)') : chalk.yellow('○ 请手动选中群号复制')}`,
|
|
2203
|
-
` 官方网站 : ${chalk.cyan('https://getdoubao.com')}`,
|
|
2204
|
-
` 交流内容 : ${chalk.white('Cursor 技巧分享 · 账号与防封交流 · 脚本升级答疑 · 售后支持')}`,
|
|
2205
|
-
].join('\n'), { padding: { top: 0, bottom: 0, left: 1, right: 1 }, borderColor: 'cyan', borderStyle: 'round' }));
|
|
2206
|
-
console.log(chalk.grey('\n操作提示: 打开 QQ 客户端 -> 点击「添加群聊」-> 粘贴群号即可快速申请加入。\n'));
|
|
2207
|
-
await pressAnyKey();
|
|
2208
|
-
}
|
|
2209
2106
|
async function pressAnyKey() {
|
|
2210
2107
|
await safePressAnyKey('按回车或 Esc 键返回...');
|
|
2211
2108
|
}
|