cc-goto-work 0.8.2 → 0.9.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 (2) hide show
  1. package/bin/cli.js +125 -11
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -69,7 +69,8 @@ function printMenu() {
69
69
  print(` ${colors.cyan}2${colors.reset} - 仅下载二进制文件`);
70
70
  print(` ${colors.cyan}3${colors.reset} - 仅配置 API 设置`);
71
71
  print(` ${colors.cyan}4${colors.reset} - 仅配置 Claude Code Hook`);
72
- print(` ${colors.cyan}5${colors.reset} - ${colors.red}卸载 cc-goto-work${colors.reset}`);
72
+ print(` ${colors.cyan}5${colors.reset} - ${colors.blue}检查更新${colors.reset}`);
73
+ print(` ${colors.cyan}6${colors.reset} - ${colors.red}卸载 cc-goto-work${colors.reset}`);
73
74
  print(` ${colors.cyan}0${colors.reset} - 退出`);
74
75
  print('');
75
76
  }
@@ -197,6 +198,10 @@ async function downloadBinary(version, platformStr) {
197
198
  fs.chmodSync(destPath, 0o755);
198
199
  }
199
200
 
201
+ // Save version info
202
+ const versionFile = path.join(INSTALL_DIR, '.version');
203
+ fs.writeFileSync(versionFile, version);
204
+
200
205
  printSuccess(`二进制文件已下载到: ${destPath}`);
201
206
  return destPath;
202
207
  }
@@ -209,14 +214,11 @@ function createConfig(apiBase, apiKey, model) {
209
214
  const configContent = `# cc-goto-work configuration
210
215
  # https://github.com/${REPO}
211
216
 
212
- # OpenAI compatible API base URL
213
- api_base: ${apiBase}
214
-
215
- # API key for authentication
216
- api_key: ${apiKey}
217
-
218
- # Model name to use
219
- model: ${model}
217
+ providers:
218
+ - api_base: ${apiBase}
219
+ api_key: ${apiKey}
220
+ models:
221
+ - ${model}
220
222
 
221
223
  # Request timeout in seconds (optional)
222
224
  timeout: 30
@@ -417,6 +419,115 @@ async function configureHookOnly(rl) {
417
419
  return true;
418
420
  }
419
421
 
422
+ // ============================================================================
423
+ // Update
424
+ // ============================================================================
425
+
426
+ const VERSION_FILE = path.join(INSTALL_DIR, '.version');
427
+
428
+ function getInstalledVersion() {
429
+ try {
430
+ if (fs.existsSync(VERSION_FILE)) {
431
+ return fs.readFileSync(VERSION_FILE, 'utf8').trim();
432
+ }
433
+ } catch (e) {
434
+ // Ignore
435
+ }
436
+ return null;
437
+ }
438
+
439
+ function saveInstalledVersion(version) {
440
+ try {
441
+ fs.mkdirSync(INSTALL_DIR, { recursive: true });
442
+ fs.writeFileSync(VERSION_FILE, version);
443
+ } catch (e) {
444
+ // Ignore
445
+ }
446
+ }
447
+
448
+ function compareVersions(v1, v2) {
449
+ // Remove 'v' prefix if present
450
+ const normalize = (v) => v.replace(/^v/, '').split('.').map(Number);
451
+ const parts1 = normalize(v1);
452
+ const parts2 = normalize(v2);
453
+
454
+ for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
455
+ const p1 = parts1[i] || 0;
456
+ const p2 = parts2[i] || 0;
457
+ if (p1 > p2) return 1;
458
+ if (p1 < p2) return -1;
459
+ }
460
+ return 0;
461
+ }
462
+
463
+ async function checkUpdate(rl) {
464
+ printStep('检查更新...');
465
+ print('');
466
+
467
+ const platformStr = detectPlatform();
468
+ if (!platformStr) {
469
+ printError(`不支持的平台: ${os.platform()} ${os.arch()}`);
470
+ return false;
471
+ }
472
+
473
+ const binaryName = getBinaryName(platformStr);
474
+ const binaryPath = path.join(INSTALL_DIR, binaryName);
475
+
476
+ if (!fs.existsSync(binaryPath)) {
477
+ printWarning('未检测到安装,请先安装');
478
+ return false;
479
+ }
480
+
481
+ // Get installed version
482
+ const installedVersion = getInstalledVersion();
483
+ if (installedVersion) {
484
+ print(` 当前版本: ${installedVersion}`);
485
+ } else {
486
+ print(` 当前版本: ${colors.yellow}未知${colors.reset}`);
487
+ }
488
+
489
+ // Get latest version
490
+ printStep('获取最新版本...');
491
+ let latestVersion;
492
+ try {
493
+ latestVersion = await getLatestVersion();
494
+ print(` 最新版本: ${latestVersion}`);
495
+ } catch (e) {
496
+ printError(`获取版本失败: ${e.message}`);
497
+ return false;
498
+ }
499
+
500
+ print('');
501
+
502
+ // Compare versions
503
+ if (installedVersion && compareVersions(installedVersion, latestVersion) >= 0) {
504
+ printSuccess('已是最新版本,无需更新');
505
+ return true;
506
+ }
507
+
508
+ // Ask to update
509
+ const updateMsg = installedVersion
510
+ ? `发现新版本!是否从 ${installedVersion} 更新到 ${latestVersion}?`
511
+ : `是否更新到 ${latestVersion}?`;
512
+
513
+ if (!(await promptConfirm(rl, updateMsg))) {
514
+ print('更新已取消');
515
+ return false;
516
+ }
517
+
518
+ // Download new version
519
+ print('');
520
+ try {
521
+ await downloadBinary(latestVersion, platformStr);
522
+ saveInstalledVersion(latestVersion);
523
+ printSuccess(`已更新到 ${latestVersion}`);
524
+ return true;
525
+ } catch (e) {
526
+ printError(`更新失败: ${e.message}`);
527
+ return false;
528
+ }
529
+ }
530
+
420
531
  // ============================================================================
421
532
  // Uninstall
422
533
  // ============================================================================
@@ -537,7 +648,7 @@ async function main() {
537
648
  while (true) {
538
649
  printMenu();
539
650
 
540
- const choice = await question(rl, '请输入选项 (0-5): ');
651
+ const choice = await question(rl, '请输入选项 (0-6): ');
541
652
 
542
653
  let success = false;
543
654
 
@@ -555,6 +666,9 @@ async function main() {
555
666
  success = await configureHookOnly(rl);
556
667
  break;
557
668
  case '5':
669
+ success = await checkUpdate(rl);
670
+ break;
671
+ case '6':
558
672
  success = await uninstall(rl);
559
673
  break;
560
674
  case '0':
@@ -565,7 +679,7 @@ async function main() {
565
679
  rl.close();
566
680
  return;
567
681
  default:
568
- printError('无效选项,请输入 0-5');
682
+ printError('无效选项,请输入 0-6');
569
683
  continue;
570
684
  }
571
685
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-goto-work",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "让 Claude Code 自动继续未完成的工作",
5
5
  "bin": {
6
6
  "cc-goto-work": "./bin/cli.js"