import { WorkflowRunner } from './runner.js';
import { formatDryRunReport } from './dry-run-format.js';
export async function runWorkflow(yamlPath, options = {}) {
    const runner = new WorkflowRunner({
        cwd: options.cwd,
        relay: options.relay,
    });
    const config = await runner.parseYamlFile(yamlPath);
    // Allow programmatic trajectory override
    if (options.trajectories !== undefined) {
        config.trajectories = options.trajectories;
    }
    // Auto-detect DRY_RUN env var so existing scripts get dry-run for free
    const isDryRun = options.dryRun ?? !!process.env.DRY_RUN;
    if (isDryRun) {
        const report = runner.dryRun(config, options.workflow, options.vars);
        console.log(formatDryRunReport(report));
        return report;
    }
    if (options.onEvent) {
        runner.on(options.onEvent);
    }
    // Resume a previous run if requested
    const resumeRunId = options.resume ?? process.env.RESUME_RUN_ID;
    if (resumeRunId) {
        return runner.resume(resumeRunId, options.vars);
    }
    const startFrom = options.startFrom ?? process.env.START_FROM;
    const previousRunId = options.previousRunId ?? process.env.PREVIOUS_RUN_ID;
    const executeOptions = startFrom ? { startFrom, previousRunId } : undefined;
    return runner.execute(config, options.workflow, options.vars, executeOptions);
}
//# sourceMappingURL=run.js.map