/**
 * Exec Agent
 * Handles: exec (arbitrary command execution)
 */
import { execSync } from 'child_process';

export default {
  name: 'exec',
  actions: {
    'exec': async (params) => {
      const { command, timeout: cmdTimeout = 60000, cwd } = params;
      if (!command) throw new Error('No command provided');

      try {
        const output = execSync(command, {
          encoding: 'utf8',
          timeout: cmdTimeout,
          cwd: cwd || process.cwd(),
          stdio: ['pipe', 'pipe', 'pipe'],
        });
        return { output, exitCode: 0 };
      } catch (execErr) {
        return {
          output: execErr.stdout || '',
          stderr: execErr.stderr || '',
          exitCode: execErr.status || 1,
        };
      }
    },
  },
};
