UNPKG

@2501-ai/cli

Version:

[![npm version](https://img.shields.io/npm/v/@2501-ai/cli.svg)](https://www.npmjs.com/package/@2501-ai/cli) [![HumanEval Score](https://img.shields.io/badge/HumanEval-96.95%25-brightgreen.svg)](https://www.2501.ai/research/full-humaneval-benchmark) [![Lic

37 lines (36 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.modifyCodeSections = void 0; const normalizeEscapes = (content) => { return content .replace(/\r\n/g, '\\n') .replace(/\\\\n/g, '\\n'); }; function modifyCodeSections({ originalContent, diffSections, }) { let result = originalContent; for (const diffSection of diffSections) { const oldContentMatch = diffSection.match(/<PREVIOUS_SECTION>([\s\S]*?)<\/PREVIOUS_SECTION>/); const newContentMatch = diffSection.match(/<NEW_SECTION>([\s\S]*?)<\/NEW_SECTION>/); if (!oldContentMatch || !newContentMatch) { throw new Error('Invalid diff section format'); } const oldContent = oldContentMatch[1]; const newContent = newContentMatch[1]; if (oldContent.trim() === '') { result = newContent + result; continue; } const normalizedOldContent = normalizeEscapes(oldContent); const normalizedNewContent = normalizeEscapes(newContent); const index = result.indexOf(normalizedOldContent); if (index === -1) { throw new Error('Old content not found in existing content'); } result = result.slice(0, index) + normalizedNewContent + result.slice(index + normalizedOldContent.length); } return result; } exports.modifyCodeSections = modifyCodeSections;