#!/usr/bin/env node // ============================================================================ // @mintel/estimation-engine — CLI Entry Point // ============================================================================ import { Command } from "commander"; import * as path from "node:path"; import * as fs from "node:fs/promises"; import { existsSync } from "node:fs"; import { config as dotenvConfig } from "dotenv"; import { EstimationPipeline } from "./pipeline.js"; import type { ProjectConcept } from "@mintel/concept-engine"; // Load .env from monorepo root dotenvConfig({ path: path.resolve(process.cwd(), "../../.env") }); dotenvConfig({ path: path.resolve(process.cwd(), ".env") }); const program = new Command(); program .name("estimate") .description("AI-powered project estimation engine") .version("1.0.0"); program .command("run") .description("Run the financial estimation pipeline from a concept file") .argument("", "Path to the ProjectConcept JSON file") .option("--budget ", "Budget constraint (e.g. '15.000 €')") .option("--output ", "Output directory", "../../out/estimations") .action(async (conceptFile: string, options: any) => { const openrouterKey = process.env.OPENROUTER_API_KEY || process.env.OPENROUTER_KEY; if (!openrouterKey) { console.error("āŒ OPENROUTER_API_KEY not found in environment."); process.exit(1); } const filePath = path.resolve(process.cwd(), conceptFile); if (!existsSync(filePath)) { console.error(`āŒ Concept file not found: ${filePath}`); process.exit(1); } console.log(`šŸ“„ Loading concept from: ${filePath}`); const rawConcept = await fs.readFile(filePath, "utf8"); const concept = JSON.parse(rawConcept) as ProjectConcept; const pipeline = new EstimationPipeline( { openrouterKey, outputDir: path.resolve(process.cwd(), options.output), crawlDir: "", // No longer needed here }, { onStepStart: (_id, _name) => {}, onStepComplete: (_id, _result) => {}, }, ); try { const result = await pipeline.run({ concept, budget: options.budget, }); console.log("\n✨ Estimation complete!"); if (result.validationResult && !result.validationResult.passed) { console.log( `\nāš ļø ${result.validationResult.errors.length} validation issues found.`, ); console.log(" Review the output JSON and re-run problematic steps."); } } catch (err) { console.error(`\nāŒ Pipeline failed: ${(err as Error).message}`); process.exit(1); } }); program.parse();