polydev-ai 1.8.79 → 1.8.81

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.
@@ -479,16 +479,12 @@ class StdioMCPWrapper {
479
479
 
480
480
  console.error(`[Polydev] Opening browser for authentication: ${authUrl}`);
481
481
 
482
- // Open browser - use spawn with detached for better reliability in stdio context
483
- const platform = process.platform;
484
-
485
- if (platform === 'darwin') {
486
- spawn('open', [authUrl], { detached: true, stdio: 'ignore' }).unref();
487
- } else if (platform === 'win32') {
488
- spawn('cmd', ['/c', 'start', '', authUrl], { detached: true, stdio: 'ignore', shell: true }).unref();
489
- } else {
490
- spawn('xdg-open', [authUrl], { detached: true, stdio: 'ignore' }).unref();
491
- }
482
+ // Best-in-class browser opening using 'open' package (cross-platform)
483
+ // Falls back to platform-specific commands if package fails
484
+ this.openBrowser(authUrl).catch(() => {
485
+ console.error('[Polydev] All browser open methods failed');
486
+ console.error('[Polydev] Please open this URL manually:', authUrl);
487
+ });
492
488
 
493
489
  // Timeout after 5 minutes
494
490
  setTimeout(() => {
@@ -595,6 +591,64 @@ class StdioMCPWrapper {
595
591
  }
596
592
  }
597
593
 
594
+ /**
595
+ * Open URL in browser - best-in-class cross-platform implementation
596
+ * Uses 'open' npm package with fallbacks for reliability in MCP/stdio context
597
+ */
598
+ async openBrowser(url) {
599
+ // Try the 'open' package first (ESM, requires dynamic import)
600
+ try {
601
+ const open = await import('open');
602
+ await open.default(url);
603
+ console.error('[Polydev] Browser opened successfully');
604
+ return;
605
+ } catch (openError) {
606
+ console.error('[Polydev] open package failed:', openError.message);
607
+ }
608
+
609
+ // Fallback 1: Platform-specific commands with exec
610
+ const { exec } = require('child_process');
611
+ const platform = process.platform;
612
+
613
+ return new Promise((resolve, reject) => {
614
+ let command;
615
+ if (platform === 'darwin') {
616
+ // macOS: try osascript first (more reliable in headless contexts)
617
+ command = `osascript -e 'open location "${url}"'`;
618
+ } else if (platform === 'win32') {
619
+ command = `start "" "${url}"`;
620
+ } else {
621
+ command = `xdg-open "${url}"`;
622
+ }
623
+
624
+ exec(command, (error) => {
625
+ if (error) {
626
+ console.error('[Polydev] exec command failed:', error.message);
627
+
628
+ // Fallback 2: spawn with detached
629
+ const { spawn } = require('child_process');
630
+ try {
631
+ if (platform === 'darwin') {
632
+ spawn('open', [url], { detached: true, stdio: 'ignore' }).unref();
633
+ } else if (platform === 'win32') {
634
+ spawn('cmd', ['/c', 'start', '', url], { detached: true, stdio: 'ignore', shell: true }).unref();
635
+ } else {
636
+ spawn('xdg-open', [url], { detached: true, stdio: 'ignore' }).unref();
637
+ }
638
+ console.error('[Polydev] Browser opened via spawn fallback');
639
+ resolve();
640
+ } catch (spawnError) {
641
+ console.error('[Polydev] spawn fallback failed:', spawnError.message);
642
+ reject(new Error('All browser open methods failed'));
643
+ }
644
+ } else {
645
+ console.error('[Polydev] Browser opened via exec');
646
+ resolve();
647
+ }
648
+ });
649
+ });
650
+ }
651
+
598
652
  /**
599
653
  * Save token to shell config files
600
654
  */
@@ -2098,21 +2152,12 @@ class StdioMCPWrapper {
2098
2152
  console.error(authUrl);
2099
2153
  console.error('');
2100
2154
 
2101
- // Open browser - use spawn with detached for better reliability in stdio context
2102
- const platform = process.platform;
2103
- let cmd, args;
2104
- if (platform === 'darwin') {
2105
- cmd = 'open';
2106
- args = [authUrl];
2107
- } else if (platform === 'win32') {
2108
- cmd = 'cmd';
2109
- args = ['/c', 'start', '', authUrl];
2110
- } else {
2111
- cmd = 'xdg-open';
2112
- args = [authUrl];
2113
- }
2114
-
2115
- spawn(cmd, args, { detached: true, stdio: 'ignore' }).unref();
2155
+ // Best-in-class browser opening using 'open' package (cross-platform)
2156
+ // Falls back to platform-specific commands if package fails
2157
+ this.openBrowser(authUrl).catch(() => {
2158
+ console.error('[Polydev] All browser open methods failed');
2159
+ console.error('[Polydev] Please open this URL manually:', authUrl);
2160
+ });
2116
2161
 
2117
2162
  // Don't block forever - resolve after timeout
2118
2163
  setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polydev-ai",
3
- "version": "1.8.79",
3
+ "version": "1.8.81",
4
4
  "engines": {
5
5
  "node": ">=20.x <=22.x"
6
6
  },
@@ -73,6 +73,7 @@
73
73
  "lucide-react": "^0.542.0",
74
74
  "marked": "^16.2.1",
75
75
  "next": "^15.5.7",
76
+ "open": "^11.0.0",
76
77
  "polydev-ai": "^1.8.42",
77
78
  "posthog-js": "^1.157.2",
78
79
  "prismjs": "^1.30.0",