UNPKG

sf-agent-framework

Version:

AI Agent Orchestration Framework for Salesforce Development - Two-phase architecture with 70% context reduction

50 lines (41 loc) 1.6 kB
#!/usr/bin/env node /** * SF-Agent Framework CLI - Direct execution wrapper for npx * This file ensures proper execution when run via npx from NPM */ const { execSync } = require('child_process'); const path = require('path'); const fs = require('fs'); // Check if we're running in an npx temporary directory const isNpxExecution = __dirname.includes('_npx') || __dirname.includes('.npm') || __dirname.includes('node_modules'); // Determine the proper script path const installerPath = path.join(__dirname, 'installer', 'bin', 'sf-agent.js'); const cliPath = path.join(__dirname, 'cli.js'); // For npx execution, prefer the installer for install command, CLI for others const scriptToRun = process.argv[2] === 'install' ? installerPath : cliPath; // Verify the file exists if (!fs.existsSync(scriptToRun)) { console.error('Error: Could not find script at', scriptToRun); console.error('Current directory:', __dirname); console.error('Looking for:', process.argv[2] === 'install' ? 'installer' : 'CLI'); process.exit(1); } // Execute with proper working directory try { const args = process.argv.slice(2).join(' '); const cmd = `node "${scriptToRun}" ${args}`; execSync(cmd, { stdio: 'inherit', cwd: process.cwd(), // Use current working directory where user ran npx env: { ...process.env, SF_AGENT_NPX: 'true', SF_AGENT_ROOT: path.dirname(__dirname), }, }); } catch (error) { // execSync will throw if the command exits with non-zero // But the stdio is inherited, so the error is already displayed process.exit(error.status || 1); }