spawn-skill 1.2.3 → 1.2.4

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 +97 -15
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -481,13 +481,55 @@ function getMoltbotBridge(token, agentName) {
481
481
  */
482
482
 
483
483
  import WebSocket from 'ws';
484
- import { spawn } from 'child_process';
484
+ import { spawn, execSync } from 'child_process';
485
+ import path from 'path';
486
+ import os from 'os';
485
487
 
486
488
  const TOKEN = '${token}';
487
489
  const NAME = '${agentName}';
488
490
  const RELAY = 'wss://spawn-relay.ngvsqdjj5r.workers.dev/v1/agent';
489
491
 
490
492
  let ws;
493
+ let moltbotPath = null;
494
+
495
+ // Find moltbot executable
496
+ function findMoltbot() {
497
+ if (moltbotPath) return moltbotPath;
498
+
499
+ // Try common locations
500
+ const candidates = [
501
+ 'moltbot', // In PATH
502
+ path.join(os.homedir(), '.npm-global', 'bin', 'moltbot'),
503
+ path.join(os.homedir(), '.nvm', 'versions', 'node', process.version, 'bin', 'moltbot'),
504
+ '/usr/local/bin/moltbot',
505
+ '/opt/homebrew/bin/moltbot',
506
+ ];
507
+
508
+ // Also try to get npm prefix
509
+ try {
510
+ const npmPrefix = execSync('npm config get prefix', { encoding: 'utf8', shell: true }).trim();
511
+ candidates.push(path.join(npmPrefix, 'bin', 'moltbot'));
512
+ } catch {}
513
+
514
+ for (const cmd of candidates) {
515
+ try {
516
+ execSync(\`"\${cmd}" --version\`, { stdio: 'pipe', shell: true });
517
+ console.log('✓ Found moltbot at:', cmd);
518
+ moltbotPath = cmd;
519
+ return cmd;
520
+ } catch {}
521
+ }
522
+
523
+ // Last resort: npx
524
+ try {
525
+ execSync('npx moltbot --version', { stdio: 'pipe', shell: true });
526
+ console.log('✓ Found moltbot via npx');
527
+ moltbotPath = 'npx moltbot';
528
+ return 'npx moltbot';
529
+ } catch {}
530
+
531
+ return null;
532
+ }
491
533
 
492
534
  function send(type, payload) {
493
535
  if (ws?.readyState === WebSocket.OPEN) {
@@ -514,23 +556,39 @@ async function askMoltbot(message) {
514
556
  console.log('📨 Forwarding to Moltbot:', message);
515
557
  updateStatus('thinking', 'Asking Moltbot...');
516
558
 
517
- // Use npx to find moltbot regardless of PATH
518
- const moltbot = spawn('npx', ['moltbot', 'agent', '--message', message, '--thinking', 'high'], {
519
- shell: true,
520
- env: { ...process.env }
521
- });
559
+ const cmd = findMoltbot();
560
+ if (!cmd) {
561
+ reject(new Error('Moltbot not found. Install with: npm install -g moltbot@latest'));
562
+ return;
563
+ }
564
+
565
+ // Build command based on whether we're using npx or direct path
566
+ let proc;
567
+ if (cmd === 'npx moltbot') {
568
+ proc = spawn('npx', ['moltbot', 'agent', '--message', message, '--thinking', 'high'], {
569
+ shell: true,
570
+ env: { ...process.env }
571
+ });
572
+ } else {
573
+ proc = spawn(cmd, ['agent', '--message', message, '--thinking', 'high'], {
574
+ shell: true,
575
+ env: { ...process.env }
576
+ });
577
+ }
578
+
522
579
  let response = '';
523
580
  let error = '';
524
581
 
525
- moltbot.stdout.on('data', (data) => response += data.toString());
526
- moltbot.stderr.on('data', (data) => error += data.toString());
582
+ proc.stdout.on('data', (data) => response += data.toString());
583
+ proc.stderr.on('data', (data) => error += data.toString());
527
584
 
528
- moltbot.on('error', (err) => {
585
+ proc.on('error', (err) => {
529
586
  console.error('✗ Failed to start Moltbot:', err.message);
587
+ moltbotPath = null; // Reset so we try finding again
530
588
  reject(new Error('Moltbot not found. Install with: npm install -g moltbot@latest'));
531
589
  });
532
590
 
533
- moltbot.on('close', (code) => {
591
+ proc.on('close', (code) => {
534
592
  if (code === 0) {
535
593
  console.log('✓ Moltbot responded');
536
594
  resolve(response.trim());
@@ -716,13 +774,37 @@ async function main() {
716
774
  // Check for Moltbot if needed
717
775
  if (useMoltbot) {
718
776
  const moltbotCheck = ora('Checking for Moltbot...').start();
777
+ let moltbotFound = false;
778
+ const { execSync } = await import('child_process');
779
+ const os = await import('os');
780
+
781
+ // Try multiple locations
782
+ const candidates = [
783
+ 'moltbot --version',
784
+ 'npx moltbot --version',
785
+ `"${path.join(os.homedir(), '.npm-global', 'bin', 'moltbot')}" --version`,
786
+ '/usr/local/bin/moltbot --version',
787
+ '/opt/homebrew/bin/moltbot --version',
788
+ ];
789
+
790
+ // Also try npm prefix
719
791
  try {
720
- const { execSync } = await import('child_process');
721
- // Use npx to find moltbot regardless of PATH
722
- execSync('npx moltbot --version', { stdio: 'pipe', shell: true });
792
+ const npmPrefix = execSync('npm config get prefix', { encoding: 'utf8', shell: true }).trim();
793
+ candidates.push(`"${path.join(npmPrefix, 'bin', 'moltbot')}" --version`);
794
+ } catch {}
795
+
796
+ for (const cmd of candidates) {
797
+ try {
798
+ execSync(cmd, { stdio: 'pipe', shell: true });
799
+ moltbotFound = true;
800
+ break;
801
+ } catch {}
802
+ }
803
+
804
+ if (moltbotFound) {
723
805
  moltbotCheck.succeed('Moltbot found');
724
- } catch {
725
- moltbotCheck.warn('Moltbot not found in PATH');
806
+ } else {
807
+ moltbotCheck.warn('Moltbot not found');
726
808
  console.log(dim(' Install with: npm install -g moltbot@latest'));
727
809
  console.log(dim(' Then run: moltbot onboard'));
728
810
  console.log('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spawn-skill",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Connect your AI agent to Spawn.wtf",
5
5
  "bin": {
6
6
  "spawn-skill": "./bin/cli.js"