UNPKG

editcodewithai

Version:
72 lines (71 loc) 3.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FORMAT_INSTRUCTIONS = exports.PROMPT_TEMPLATE_VERSION = void 0; exports.assembleFullPrompt = assembleFullPrompt; // Versions of the prompt template. exports.PROMPT_TEMPLATE_VERSION = 1; // Template pieces const TASK = (prompt) => `## Your Task\n\n${prompt}`; const FILES = (filesContext) => `## Original Files\n\n${filesContext}`; exports.FORMAT_INSTRUCTIONS = { whole: [ "## Formatting Instructions\n\n", "Suggest changes to the original files using this exact format:\n\n", "**fileA.js**\n\n```js\n// Entire updated code for fileA\n```\n\n", "**fileB.js**\n\n```js\n// Entire updated code for fileB\n```\n\n", "Only include the files that need to be updated or created.\n\n", "To suggest changes you MUST include the ENTIRE content of the updated file.\n\n", 'NEVER leave out sections as in "... rest of the code remain the same ...".\n\n', "Refactor large files into smaller files in the same directory.\n\n", "Delete all unused files, but we need to keep `README.md`. ", "Files can be deleted by setting their content to empty, for example:\n\n", "**fileToDelete.js**\n\n```\n```\n\n", "For D3 logic, make sure it remains idempotent (use data joins), ", "and prefer function signatures like `someFunction(selection, options)` ", "where `selection` is a D3 selection and `options` is an object. ", 'Only import from the top-level `"d3"` module, not from submodules ', '(e.g. imports from `"d3-scale"` or `"d3-shape"` are not supported).\n\n', ].join(""), diff: [ "## Formatting Instructions\n\n", "Suggest changes to the original files using this search/replace block format:\n\n", "path/to/filename.ext\n", "```\n", "<<<<<<< SEARCH\n", "// code to be replaced\n", "=======\n", "// new code\n", ">>>>>>> REPLACE\n", "```\n", ].join(""), "diff-fenced": [ "## Formatting Instructions\n\n", "Suggest changes to the original files using this search/replace block format with the file path inside the fence:\n\n", "```\n", "path/to/filename.ext\n", "<<<<<<< SEARCH\n", "// code to be replaced\n", "=======\n", "// new code\n", ">>>>>>> REPLACE\n", "```\n", ].join(""), udiff: [ "## Formatting Instructions\n\n", "Suggest changes to the original files using the unified diff format:\n\n", "```diff\n", "--- path/to/filename.ext\n", "+++ path/to/filename.ext\n", "@@ ... @@\n", "-// line to be removed\n", "+// line to be added\n", "```\n", ].join(""), }; /** * Assembles the full prompt by combining task, files context, and formatting instructions */ function assembleFullPrompt({ filesContext, prompt, editFormat = "whole", }) { const FORMAT = exports.FORMAT_INSTRUCTIONS[editFormat]; return [TASK(prompt), FILES(filesContext), FORMAT].join("\n\n"); }