#!/usr/bin/env npx tsx
/**
 * Generate the behavior interpreter module for app-demo.
 *
 * Usage:
 *   npx tsx generate-interpreter.ts -o ../../specverse-app-demo/src/runtime/engine/generated-behaviors.ts
 *   npx tsx generate-interpreter.ts  (outputs to stdout)
 */

import { generateInterpreterModule } from './step-conventions-memory.js';

const args = process.argv.slice(2);
const outputIdx = args.indexOf('-o');

const source = generateInterpreterModule();

if (outputIdx !== -1 && args[outputIdx + 1]) {
  const { writeFileSync } = await import('fs');
  const { resolve } = await import('path');
  const outPath = resolve(args[outputIdx + 1]);
  writeFileSync(outPath, source, 'utf8');
  console.log(`Generated ${outPath} (${source.split('\n').length} lines)`);
} else {
  console.log(source);
}
