spawn-skill 1.2.3 → 1.2.5

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 +115 -18
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -481,13 +481,60 @@ 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 (also check for old name 'clawdbot')
496
+ function findMoltbot() {
497
+ if (moltbotPath) return moltbotPath;
498
+
499
+ // Try both names - moltbot and clawdbot (old name)
500
+ const names = ['moltbot', 'clawdbot'];
501
+
502
+ for (const name of names) {
503
+ // Try common locations
504
+ const candidates = [
505
+ name, // In PATH
506
+ path.join(os.homedir(), '.npm-global', 'bin', name),
507
+ path.join(os.homedir(), '.nvm', 'versions', 'node', process.version, 'bin', name),
508
+ '/usr/local/bin/' + name,
509
+ '/opt/homebrew/bin/' + name,
510
+ ];
511
+
512
+ // Also try to get npm prefix
513
+ try {
514
+ const npmPrefix = execSync('npm config get prefix', { encoding: 'utf8', shell: true }).trim();
515
+ candidates.push(path.join(npmPrefix, 'bin', name));
516
+ } catch {}
517
+
518
+ for (const cmd of candidates) {
519
+ try {
520
+ execSync(\`"\${cmd}" --version\`, { stdio: 'pipe', shell: true });
521
+ console.log(\`✓ Found \${name} at:\`, cmd);
522
+ moltbotPath = cmd;
523
+ return cmd;
524
+ } catch {}
525
+ }
526
+
527
+ // Try npx
528
+ try {
529
+ execSync(\`npx \${name} --version\`, { stdio: 'pipe', shell: true });
530
+ console.log(\`✓ Found \${name} via npx\`);
531
+ moltbotPath = \`npx \${name}\`;
532
+ return \`npx \${name}\`;
533
+ } catch {}
534
+ }
535
+
536
+ return null;
537
+ }
491
538
 
492
539
  function send(type, payload) {
493
540
  if (ws?.readyState === WebSocket.OPEN) {
@@ -514,23 +561,41 @@ async function askMoltbot(message) {
514
561
  console.log('📨 Forwarding to Moltbot:', message);
515
562
  updateStatus('thinking', 'Asking Moltbot...');
516
563
 
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
- });
564
+ const cmd = findMoltbot();
565
+ if (!cmd) {
566
+ reject(new Error('Moltbot not found. Install with: npm install -g moltbot@latest'));
567
+ return;
568
+ }
569
+
570
+ // Build command based on whether we're using npx or direct path
571
+ let proc;
572
+ if (cmd.startsWith('npx ')) {
573
+ // npx moltbot or npx clawdbot
574
+ const pkgName = cmd.split(' ')[1];
575
+ proc = spawn('npx', [pkgName, 'agent', '--message', message, '--thinking', 'high'], {
576
+ shell: true,
577
+ env: { ...process.env }
578
+ });
579
+ } else {
580
+ proc = spawn(cmd, ['agent', '--message', message, '--thinking', 'high'], {
581
+ shell: true,
582
+ env: { ...process.env }
583
+ });
584
+ }
585
+
522
586
  let response = '';
523
587
  let error = '';
524
588
 
525
- moltbot.stdout.on('data', (data) => response += data.toString());
526
- moltbot.stderr.on('data', (data) => error += data.toString());
589
+ proc.stdout.on('data', (data) => response += data.toString());
590
+ proc.stderr.on('data', (data) => error += data.toString());
527
591
 
528
- moltbot.on('error', (err) => {
592
+ proc.on('error', (err) => {
529
593
  console.error('✗ Failed to start Moltbot:', err.message);
594
+ moltbotPath = null; // Reset so we try finding again
530
595
  reject(new Error('Moltbot not found. Install with: npm install -g moltbot@latest'));
531
596
  });
532
597
 
533
- moltbot.on('close', (code) => {
598
+ proc.on('close', (code) => {
534
599
  if (code === 0) {
535
600
  console.log('✓ Moltbot responded');
536
601
  resolve(response.trim());
@@ -713,16 +778,48 @@ async function main() {
713
778
 
714
779
  console.log('');
715
780
 
716
- // Check for Moltbot if needed
781
+ // Check for Moltbot if needed (also check old name 'clawdbot')
717
782
  if (useMoltbot) {
718
783
  const moltbotCheck = ora('Checking for Moltbot...').start();
719
- 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 });
723
- moltbotCheck.succeed('Moltbot found');
724
- } catch {
725
- moltbotCheck.warn('Moltbot not found in PATH');
784
+ let moltbotFound = false;
785
+ let foundName = null;
786
+ const { execSync } = await import('child_process');
787
+ const os = await import('os');
788
+
789
+ // Try both names
790
+ const names = ['moltbot', 'clawdbot'];
791
+
792
+ for (const name of names) {
793
+ if (moltbotFound) break;
794
+
795
+ const candidates = [
796
+ `${name} --version`,
797
+ `npx ${name} --version`,
798
+ `"${path.join(os.homedir(), '.npm-global', 'bin', name)}" --version`,
799
+ `/usr/local/bin/${name} --version`,
800
+ `/opt/homebrew/bin/${name} --version`,
801
+ ];
802
+
803
+ // Also try npm prefix
804
+ try {
805
+ const npmPrefix = execSync('npm config get prefix', { encoding: 'utf8', shell: true }).trim();
806
+ candidates.push(`"${path.join(npmPrefix, 'bin', name)}" --version`);
807
+ } catch {}
808
+
809
+ for (const cmd of candidates) {
810
+ try {
811
+ execSync(cmd, { stdio: 'pipe', shell: true });
812
+ moltbotFound = true;
813
+ foundName = name;
814
+ break;
815
+ } catch {}
816
+ }
817
+ }
818
+
819
+ if (moltbotFound) {
820
+ moltbotCheck.succeed(foundName === 'clawdbot' ? 'Found clawdbot (old name for Moltbot)' : 'Moltbot found');
821
+ } else {
822
+ moltbotCheck.warn('Moltbot not found');
726
823
  console.log(dim(' Install with: npm install -g moltbot@latest'));
727
824
  console.log(dim(' Then run: moltbot onboard'));
728
825
  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.5",
4
4
  "description": "Connect your AI agent to Spawn.wtf",
5
5
  "bin": {
6
6
  "spawn-skill": "./bin/cli.js"