UNPKG

scai

Version:

> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.

42 lines (41 loc) 1.53 kB
// File: src/commands/WorkflowCmd.ts import chalk from 'chalk'; import { resolveModules } from '../workflow/workflowResolver.js'; import { runWorkflow } from '../workflow/workflowRunner.js'; /** * Runs a workflow pipeline with one or more goals. * Handles both file input (-f) and stdin input (pipe). */ export async function runWorkflowCommand(goals, options) { try { console.log(chalk.cyan('🔁 Pipeline goals:'), goals.join(' → ')); // Resolve module implementations for the given goals const modules = resolveModules(goals); console.log(chalk.green('📋 Modules to run:'), modules.map((m) => m.name).join(' → ')); // Determine input source const input = options.file ? { filepath: options.file } : { inputContent: await readStdin() }; // Run the workflow pipeline await runWorkflow({ goals, modules, ...input }); console.log(chalk.green('✅ Workflow completed successfully.')); } catch (err) { console.error(chalk.red('❌ Pipeline failed:'), err?.message ?? err); process.exit(1); } } /** * Reads from stdin if no file path is provided. */ function readStdin() { return new Promise((resolve) => { if (process.stdin.isTTY) return resolve(''); let data = ''; process.stdin.setEncoding('utf8'); process.stdin.on('data', (chunk) => (data += chunk)); process.stdin.on('end', () => resolve(data)); process.stdin.resume(); }); }