UNPKG

agentic-qe

Version:

Agentic Quality Engineering Fleet System - AI-driven quality management platform

138 lines • 6.53 kB
"use strict"; /** * Config Import Command - Import configuration from file */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigImportCommand = void 0; const fs = __importStar(require("fs-extra")); const path = __importStar(require("path")); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const ajv_1 = __importDefault(require("ajv")); const yaml = __importStar(require("yaml")); const schema_1 = require("./schema"); class ConfigImportCommand { static async execute(options) { const spinner = (0, ora_1.default)('Importing configuration...').start(); try { // Check if input file exists if (!(await fs.pathExists(options.input))) { throw new Error(`File not found: ${options.input}`); } // Read and parse input file const importedConfig = await this.readConfigFile(options.input); // Extract actual config if it has metadata wrapper const config = importedConfig.config || importedConfig; // Validate imported configuration if (options.validate !== false) { const ajv = new ajv_1.default({ allErrors: true, strictTypes: false }); const validate = ajv.compile(schema_1.AQEConfigSchema); const valid = validate(config); if (!valid) { const errors = validate.errors ?.map((err) => `${err.instancePath}: ${err.message}`) .join(', '); throw new Error(`Configuration validation failed: ${errors}`); } } // Check if target config exists const targetExists = await fs.pathExists(this.DEFAULT_CONFIG_PATH); if (targetExists && !options.force && !options.merge) { throw new Error('Configuration already exists. Use --force to overwrite or --merge to merge'); } // Prepare final configuration let finalConfig = config; if (options.merge && targetExists) { spinner.text = 'Merging configurations...'; const existingConfig = await fs.readJson(this.DEFAULT_CONFIG_PATH); finalConfig = this.deepMerge(existingConfig, config); } // Ensure directory exists await fs.ensureDir(path.dirname(this.DEFAULT_CONFIG_PATH)); // Write configuration await fs.writeJson(this.DEFAULT_CONFIG_PATH, finalConfig, { spaces: 2 }); spinner.succeed(chalk_1.default.green('Configuration imported successfully!')); console.log(chalk_1.default.blue('\nšŸ“„ Import Details:')); console.log(chalk_1.default.gray(` Source: ${options.input}`)); console.log(chalk_1.default.gray(` Target: ${this.DEFAULT_CONFIG_PATH}`)); console.log(chalk_1.default.gray(` Mode: ${options.merge ? 'Merge' : 'Overwrite'}`)); console.log(chalk_1.default.gray(` Validated: ${options.validate !== false ? 'Yes' : 'No'}`)); console.log(chalk_1.default.blue('\nšŸ“Š Configuration Summary:')); console.log(chalk_1.default.gray(` Version: ${finalConfig.version}`)); console.log(chalk_1.default.gray(` Topology: ${finalConfig.fleet.topology}`)); console.log(chalk_1.default.gray(` Max Agents: ${finalConfig.fleet.maxAgents}`)); console.log(chalk_1.default.yellow('\nšŸ’” Next Steps:')); console.log(chalk_1.default.gray(' 1. Review configuration: aqe config get')); console.log(chalk_1.default.gray(' 2. Validate configuration: aqe config validate')); } catch (error) { spinner.fail(chalk_1.default.red('Failed to import configuration')); throw error; } } static async readConfigFile(filePath) { const ext = path.extname(filePath).toLowerCase(); if (ext === '.json') { return await fs.readJson(filePath); } else if (ext === '.yaml' || ext === '.yml') { const content = await fs.readFile(filePath, 'utf-8'); return yaml.parse(content); } else { // Try to parse as JSON by default return await fs.readJson(filePath); } } static deepMerge(target, source) { const output = { ...target }; if (this.isObject(target) && this.isObject(source)) { Object.keys(source).forEach((key) => { if (this.isObject(source[key])) { if (!(key in target)) { Object.assign(output, { [key]: source[key] }); } else { output[key] = this.deepMerge(target[key], source[key]); } } else { Object.assign(output, { [key]: source[key] }); } }); } return output; } static isObject(item) { return item && typeof item === 'object' && !Array.isArray(item); } } exports.ConfigImportCommand = ConfigImportCommand; ConfigImportCommand.DEFAULT_CONFIG_PATH = '.agentic-qe/config/aqe.config.json'; //# sourceMappingURL=import.js.map