suparank 1.0.0 → 1.2.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 (3) hide show
  1. package/bin/suparank.js +82 -0
  2. package/mcp-client.js +1043 -127
  3. package/package.json +1 -1
package/bin/suparank.js CHANGED
@@ -10,6 +10,7 @@
10
10
  * npx suparank test - Test API connection
11
11
  * npx suparank session - View current session state
12
12
  * npx suparank clear - Clear session state
13
+ * npx suparank update - Check for updates and install latest version
13
14
  */
14
15
 
15
16
  import * as fs from 'fs'
@@ -513,6 +514,82 @@ function showVersion() {
513
514
  log('https://suparank.io', 'dim')
514
515
  }
515
516
 
517
+ async function checkForUpdates(showCurrent = false) {
518
+ const packageJson = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'))
519
+ const currentVersion = packageJson.version
520
+
521
+ if (showCurrent) {
522
+ log(`Current version: ${currentVersion}`, 'dim')
523
+ }
524
+
525
+ try {
526
+ const response = await fetch('https://registry.npmjs.org/suparank/latest')
527
+ if (response.ok) {
528
+ const data = await response.json()
529
+ return { current: currentVersion, latest: data.version }
530
+ }
531
+ } catch (e) {
532
+ // Ignore fetch errors
533
+ }
534
+ return { current: currentVersion, latest: null }
535
+ }
536
+
537
+ async function runUpdate() {
538
+ logHeader('Suparank Update')
539
+
540
+ log('Checking for updates...', 'yellow')
541
+ const { current, latest } = await checkForUpdates(true)
542
+
543
+ if (!latest) {
544
+ log('Could not check for updates. Please try again later.', 'red')
545
+ return
546
+ }
547
+
548
+ log(`Latest version: ${latest}`, 'dim')
549
+ console.log()
550
+
551
+ if (current === latest) {
552
+ log('You are already on the latest version!', 'green')
553
+ return
554
+ }
555
+
556
+ // Show what will be preserved
557
+ log('Your data is safe:', 'cyan')
558
+ log(' ~/.suparank/config.json (API key, project)', 'dim')
559
+ log(' ~/.suparank/credentials.json (WordPress, Ghost, etc.)', 'dim')
560
+ log(' ~/.suparank/session.json (Current session)', 'dim')
561
+ log(' ~/.suparank/content/ (Saved articles)', 'dim')
562
+ console.log()
563
+
564
+ log(`Updating from v${current} to v${latest}...`, 'yellow')
565
+ console.log()
566
+
567
+ // Clear npx cache and reinstall
568
+ const { execSync } = await import('child_process')
569
+
570
+ try {
571
+ // Clear the npx cache for suparank
572
+ log('Clearing cache...', 'dim')
573
+ execSync('npx clear-npx-cache 2>/dev/null || true', { stdio: 'pipe' })
574
+
575
+ // Force npx to fetch the latest version
576
+ log('Downloading latest version...', 'dim')
577
+ execSync('npm cache clean --force 2>/dev/null || true', { stdio: 'pipe' })
578
+
579
+ console.log()
580
+ log(`Updated to v${latest}!`, 'green')
581
+ console.log()
582
+ log('Run "npx suparank@latest" to use the new version.', 'cyan')
583
+ log('Or restart your AI client to pick up changes.', 'dim')
584
+ } catch (e) {
585
+ log(`Update failed: ${e.message}`, 'red')
586
+ console.log()
587
+ log('Try manually:', 'dim')
588
+ log(' npm cache clean --force', 'cyan')
589
+ log(' npx suparank@latest', 'cyan')
590
+ }
591
+ }
592
+
516
593
  function runMCP() {
517
594
  const config = loadConfig()
518
595
 
@@ -581,6 +658,10 @@ switch (command) {
581
658
  case 'clear':
582
659
  clearSession()
583
660
  break
661
+ case 'update':
662
+ case 'upgrade':
663
+ runUpdate()
664
+ break
584
665
  case 'version':
585
666
  case '-v':
586
667
  case '--version':
@@ -601,6 +682,7 @@ switch (command) {
601
682
  log(' test Test API connection', 'dim')
602
683
  log(' session View current session state', 'dim')
603
684
  log(' clear Clear session state', 'dim')
685
+ log(' update Check for updates and install latest', 'dim')
604
686
  log(' version Show version', 'dim')
605
687
  log(' help Show this help message', 'dim')
606
688
  console.log()