#!/usr/bin/env node /** * @claude-flow/codex - CLI * * Command-line interface for Codex integration * Part of the coflow rebranding initiative */ import { Command } from 'commander'; import chalk from 'chalk'; import { CodexInitializer } from './initializer.js'; import { validateAgentsMd, validateSkillMd, validateConfigToml } from './validators/index.js'; import { migrateFromClaudeCode, analyzeClaudeMd, generateMigrationReport } from './migrations/index.js'; import { listTemplates, BUILT_IN_SKILLS } from './templates/index.js'; import { generateSkillMd } from './generators/skill-md.js'; import { VERSION, PACKAGE_INFO } from './index.js'; import fs from 'fs-extra'; import path from 'path'; const program = new Command(); // Custom error handler for better output function handleError(error, message) { const errorMessage = error instanceof Error ? error.message : String(error); console.error(chalk.red.bold('\nError:'), chalk.red(message ?? errorMessage)); if (error instanceof Error && error.stack && process.env.DEBUG) { console.error(chalk.gray('\nStack trace:')); console.error(chalk.gray(error.stack)); } process.exit(1); } // Validate project path exists and is accessible async function validatePath(projectPath) { const resolvedPath = path.resolve(projectPath); try { const stats = await fs.stat(resolvedPath); if (!stats.isDirectory()) { throw new Error(`Path is not a directory: ${resolvedPath}`); } return resolvedPath; } catch (error) { if (error.code === 'ENOENT') { // Directory doesn't exist, try to create it console.log(chalk.yellow(`Creating directory: ${resolvedPath}`)); await fs.ensureDir(resolvedPath); return resolvedPath; } throw error; } } // Validate skill name format function validateSkillName(name) { const validPattern = /^[a-z][a-z0-9-]*$/; return validPattern.test(name); } // Print banner function printBanner() { console.log(chalk.cyan.bold('\n Claude Flow Codex')); console.log(chalk.gray(' OpenAI Codex integration for Claude Flow')); console.log(chalk.gray(' ----------------------------------------\n')); } program .name('claude-flow-codex') .description('OpenAI Codex integration for Claude Flow - Part of the coflow ecosystem') .version(VERSION, '-v, --version', 'Display version number') .option('--debug', 'Enable debug mode', false) .hook('preAction', (thisCommand) => { if (thisCommand.opts().debug) { process.env.DEBUG = 'true'; } }); // Init command program .command('init') .description('Initialize a new Codex project with AGENTS.md and skills') .option('-t, --template