cursor-switch 1.0.4 → 1.0.6

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.
@@ -53,6 +53,7 @@ export declare class PureLoginService {
53
53
  token?: string;
54
54
  email?: string;
55
55
  detail?: string;
56
+ canRetry?: boolean;
56
57
  needsSmsCode?: boolean;
57
58
  phoneMask?: string;
58
59
  }>;
@@ -165,14 +165,17 @@ export class PureLoginService {
165
165
  detail: data.message || '检测到手机短信二次验证',
166
166
  };
167
167
  }
168
+ const canRetry = Boolean(data.canRetry || data.can_retry || res.status === 400);
168
169
  return {
169
170
  ok: false,
171
+ canRetry,
170
172
  detail: data.error || data.detail || data.message || '验证码提交未通过或已超时',
171
173
  };
172
174
  }
173
175
  catch (err) {
174
176
  return {
175
177
  ok: false,
178
+ canRetry: true,
176
179
  detail: `网络连接异常: ${err.message}`,
177
180
  };
178
181
  }
@@ -389,13 +392,23 @@ export class PureLoginService {
389
392
  console.log(chalk.yellow(`本地浏览器唤起异常 (${e.message}),转入终端手动输入`));
390
393
  }
391
394
  }
392
- // 3. 兜底人工录入
393
- if (!otpToSubmit) {
394
- otpToSubmit = (await safeInput({
395
- message: '请输入收到的 6 位邮箱验证码:',
396
- })) || '';
397
- }
398
- if (otpToSubmit) {
395
+ // 3. 提交验证码(带严格受控的 3 次重试保护,杜绝无限死循环)
396
+ let submitAttempts = 0;
397
+ const MAX_ATTEMPTS = 3;
398
+ while (submitAttempts < MAX_ATTEMPTS) {
399
+ if (!otpToSubmit) {
400
+ otpToSubmit = (await safeInput({
401
+ message: submitAttempts === 0
402
+ ? '请输入收到的 6 位邮箱验证码:'
403
+ : `请重新输入 6 位验证码 (剩余 ${MAX_ATTEMPTS - submitAttempts} 次重试机会):`,
404
+ })) || '';
405
+ }
406
+ if (!otpToSubmit) {
407
+ console.log(chalk.red('\n未输入验证码,代登已终止。\n'));
408
+ await safePressAnyKey();
409
+ return;
410
+ }
411
+ submitAttempts++;
399
412
  console.log(chalk.cyan('正在提交验证码并生成官方登录凭证...'));
400
413
  const submitRes = await this.submitOtp(taskId, activeKey, otpToSubmit);
401
414
  if (submitRes.ok) {
@@ -406,6 +419,7 @@ export class PureLoginService {
406
419
  finishedEmail = submitRes.email;
407
420
  break;
408
421
  }
422
+ break;
409
423
  }
410
424
  else if (submitRes.needsSmsCode) {
411
425
  console.log(chalk.yellow(`\n📱 检测到手机二次短信验证 (${submitRes.phoneMask || '••••'})`));
@@ -422,18 +436,35 @@ export class PureLoginService {
422
436
  break;
423
437
  }
424
438
  }
439
+ break;
440
+ }
441
+ else if (submitRes.canRetry && submitAttempts < MAX_ATTEMPTS) {
442
+ console.log(chalk.yellow(`\n⚠️ 验证码未通过: ${submitRes.detail || '验证码有误或网络抖动'}`));
443
+ const shouldRetry = await safeConfirm({
444
+ message: `当前代登会话仍有效,是否重新输入验证码?(还可重试 ${MAX_ATTEMPTS - submitAttempts} 次)`,
445
+ default: true,
446
+ });
447
+ if (shouldRetry) {
448
+ otpToSubmit = '';
449
+ continue;
450
+ }
451
+ else {
452
+ console.log(chalk.grey('\n用户主动取消重试,代登已终止。\n'));
453
+ await safePressAnyKey();
454
+ return;
455
+ }
425
456
  }
426
457
  else {
427
- console.log(chalk.red(`\n✖ 验证码提交未通过: ${submitRes.detail || '验证码错误或会话已过期'}\n`));
458
+ if (submitAttempts >= MAX_ATTEMPTS) {
459
+ console.log(chalk.red(`\n✖ 连续 ${MAX_ATTEMPTS} 次验证未通过,为防止账号触发官方风控已主动终止。\n`));
460
+ }
461
+ else {
462
+ console.log(chalk.red(`\n✖ 验证码提交未通过: ${submitRes.detail || '验证码错误或会话已过期'}\n`));
463
+ }
428
464
  await safePressAnyKey();
429
465
  return;
430
466
  }
431
467
  }
432
- else {
433
- console.log(chalk.red('\n未输入验证码,代登已终止。\n'));
434
- await safePressAnyKey();
435
- return;
436
- }
437
468
  }
438
469
  else if (currentEvent === 'need_sms_code') {
439
470
  console.log(chalk.yellow(`\n📱 检测到手机二次短信验证 (${data.phoneMask || '••••'})`));
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "cursor-switch",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "极速、安全、纯本地运行的 Cursor IDE 多账号管理与防封虚拟机器指纹切换纯命令行工具",
5
5
  "author": "aozai",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "./dist/index.js",
9
9
  "bin": {
10
+ "switch": "bin/cswitch.js",
10
11
  "cswitch": "bin/cswitch.js",
11
12
  "cursor-switch": "bin/cswitch.js"
12
13
  },