UNPKG

mnemos-coder

Version:

CLI-based coding agent with graph-based execution loop and terminal UI

131 lines 4.13 kB
/** * Output Contract System for Subagents * Based on qwen-code's OutputConfig pattern * Ensures subagents return expected structured outputs */ export var TerminationReason; (function (TerminationReason) { TerminationReason["GOAL_ACHIEVED"] = "GOAL_ACHIEVED"; TerminationReason["MAX_ITERATIONS"] = "MAX_ITERATIONS"; TerminationReason["TIMEOUT"] = "TIMEOUT"; TerminationReason["ERROR"] = "ERROR"; TerminationReason["USER_CANCELLED"] = "USER_CANCELLED"; })(TerminationReason || (TerminationReason = {})); /** * Validates subagent outputs against contract */ export class OutputValidator { static validate(outputs, contract) { const errors = []; // Check required outputs for (const [key, spec] of Object.entries(contract.required)) { if (!(key in outputs)) { errors.push(`Missing required output: ${key}`); continue; } const value = outputs[key]; // Type check if (!this.checkType(value, spec.type)) { errors.push(`Output ${key} has wrong type. Expected ${spec.type}, got ${typeof value}`); } // Custom validation if (spec.validation && !spec.validation(value)) { errors.push(`Output ${key} failed validation: ${spec.description}`); } } return { valid: errors.length === 0, errors }; } static checkType(value, expectedType) { switch (expectedType) { case 'string': return typeof value === 'string'; case 'number': return typeof value === 'number'; case 'boolean': return typeof value === 'boolean'; case 'object': return typeof value === 'object' && value !== null && !Array.isArray(value); case 'array': return Array.isArray(value); default: return false; } } } /** * Example contracts for common subagent types */ export const CommonContracts = { DEBUGGER: { required: { errorCause: { type: 'string', description: 'Root cause of the error' }, solution: { type: 'string', description: 'Applied solution or fix' }, fixed: { type: 'boolean', description: 'Whether the error was successfully fixed' } }, optional: { stackTrace: { type: 'string', description: 'Analyzed stack trace' }, preventionTips: { type: 'array', description: 'Tips to prevent similar errors' } } }, API_BUILDER: { required: { endpoints: { type: 'array', description: 'List of created API endpoints' }, mainFile: { type: 'string', description: 'Path to main API file' }, dependencies: { type: 'object', description: 'Required dependencies and versions' } }, optional: { documentation: { type: 'string', description: 'API documentation' }, testCommand: { type: 'string', description: 'Command to test the API' } } }, REFACTORING: { required: { filesModified: { type: 'array', description: 'List of files that were modified' }, improvements: { type: 'array', description: 'List of improvements made' }, metricsImproved: { type: 'object', description: 'Metrics that were improved (complexity, duplication, etc.)' } } } }; //# sourceMappingURL=OutputContract.js.map