#!/usr/bin/env node
/**
* Global wrapper for mimir-execute command
* Usage: mimir-execute chain-output.md
*
* Note: This file uses ES modules to match the project setup.
*/
import { spawn } from 'child_process';
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Path to the GRAPH-RAG-TODO-main installation
const INSTALL_DIR = path.resolve(__dirname, '..');
const EXECUTOR_SCRIPT = path.join(INSTALL_DIR, 'build', 'orchestrator', 'task-executor.js');
const AGENTS_DIR = path.join(INSTALL_DIR, 'docs', 'agents');
// Get the chain output file from command line args
const chainOutputFile = process.argv[2] || 'chain-output.md';
const absoluteChainPath = path.resolve(process.cwd(), chainOutputFile);
if (!fs.existsSync(absoluteChainPath)) {
console.error(`❌ Error: Chain output file not found: ${absoluteChainPath}`);
console.error('Usage: mimir-execute [chain-output.md]');
process.exit(1);
}
console.log(`⚙️ Running Mimir Executor from: ${INSTALL_DIR}`);
console.log(`📄 Chain file: ${absoluteChainPath}`);
console.log(`📂 Working directory: ${process.cwd()}`);
console.log(`📝 Execution report will be saved to: ${process.cwd()}/execution-report.md\n`);
// Run the executor script
const child = spawn('node', [EXECUTOR_SCRIPT, absoluteChainPath], {
cwd: process.cwd(), // Run in user's current directory
env: {
...process.env,
MIMIR_INSTALL_DIR: INSTALL_DIR, // Pass install dir as env var
MIMIR_AGENTS_DIR: AGENTS_DIR // Pass agents dir as env var
},
stdio: 'inherit'
});
child.on('exit', (code) => {
process.exit(code);
});