
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
editcodewithai
Advanced tools
A lightweight, flexible library for AI-powered code editing.
See also vizhub-benchmarks.
editcodewithai is a JavaScript/TypeScript library that enables AI-powered code editing in your applications. It provides a simple interface to send code files and instructions to an LLM (Large Language Model) and receive edited code in return.
The library is designed to be model-agnostic, allowing you to use any LLM provider while handling the prompt engineering, file parsing, and response processing for you.
Edit formats inspired by Aider. See Aider: Edit Formats for details.
npm install editcodewithai
Here's a basic example of how to use performAiEdit to update a file:
import {
performAiEdit,
FORMAT_INSTRUCTIONS,
LlmFunction,
} from "editcodewithai";
import { VizFiles } from "@vizhub/viz-types";
// Your function to call the LLM
const myLlmFunction: LlmFunction = async (prompt: string) => {
// ... call your LLM API with the prompt
const llmResponse = "...";
return {
content: llmResponse, // The raw string response from the LLM
generationId: "some-generation-id", // Optional, for cost tracking with OpenRouter
};
};
const files: VizFiles = {
file1: {
name: "index.js",
text: 'console.log("Hello, World!");',
},
};
const prompt = 'Change the greeting to "Hello, Universe!"';
async function main() {
const result = await performAiEdit({
prompt,
files,
llmFunction: myLlmFunction,
editFormat: "diff", // Specify the desired edit format
});
console.log(result.changedFiles["file1"].text);
// Expected output: console.log("Hello, Universe!");
}
main();
This library supports several "edit formats" that instruct the LLM on how to specify file changes. Different models may perform better with different formats. You can specify the format using the editFormat parameter in performAiEdit.
whole (default)The LLM returns the complete, updated content for each file that needs changes. This is simple but can be inefficient for large files with small changes.
Example:
index.js
```js
console.log("Hello, Universe!");
```
diffThe LLM returns a series of search-and-replace blocks. This is efficient as it only includes the changed portions of the files.
Example:
index.js
```
<<<<<<< SEARCH
console.log("Hello, World!");
=======
console.log("Hello, Universe!");
>>>>>>> REPLACE
```
The library handles several file operations automatically:
The library exports FORMAT_INSTRUCTIONS which contains the exact prompt instructions used for each edit format. This can be useful if you want to:
import { FORMAT_INSTRUCTIONS } from "editcodewithai";
// Access instructions for a specific format
console.log(FORMAT_INSTRUCTIONS.diff);
console.log(FORMAT_INSTRUCTIONS.whole);
console.log(FORMAT_INSTRUCTIONS["diff-fenced"]);
console.log(FORMAT_INSTRUCTIONS.udiff);
// Use in your own prompts
const customPrompt = `
${FORMAT_INSTRUCTIONS.diff}
Please update the following code to add error handling:
${yourCodeHere}
`;
The FORMAT_INSTRUCTIONS object contains instructions for these edit formats:
whole: Instructions for returning complete file contentsdiff: Instructions for search-and-replace blocksdiff-fenced: Instructions for search-and-replace blocks with file paths inside code fencesudiff: Instructions for unified diff formatEach instruction set is a string containing detailed formatting guidelines that help ensure the LLM produces properly structured output that can be parsed by the library.
Aider: An AI pair programming tool that integrates with your terminal to assist in code editing within your local git repository. https://aider.chat/
Bolt.new / Bolt.diy: A platform that allows users to prompt, run, edit, and deploy full-stack web and mobile applications. https://bolt.new/
Cline: An AI-powered code assistant designed to help developers write and debug code more efficiently. https://cline.ai/
Cerebras Coder: A code generation tool developed by Cerebras Systems, leveraging advanced AI models to assist in coding tasks. https://www.cerebras.net/
Pear AI: An open-source AI code editor that accelerates the development process by integrating features like AI chat, code generation, and debugging assistance. https://trypear.ai/
Void: An open-source alternative to proprietary AI code editors, offering AI-assisted coding features while prioritizing user privacy and control. https://void.dev/
Cody: An advanced AI coding assistant developed by Sourcegraph, integrating seamlessly with popular IDEs to provide features like AI-driven chat, code autocompletion, and inline editing. https://github.com/sourcegraph/cody
To contribute to this project:
# Clone the repository
git clone https://github.com/yourusername/editcodewithai.git
# Navigate to project directory
cd editcodewithai
# Install dependencies
npm install
Run tests to ensure everything is working correctly:
npm test
Please submit pull requests with clear descriptions of changes and ensure all tests pass. Protocol for wrapping up a PR:
npm test
npm run typecheck
npm run prettier
# Verify the README is up to date
Please create an issue first before creating a PR to discuss the changes you want to make. This helps ensure that your contributions align with the project's goals and vision.
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
Edit Code With AI
The npm package editcodewithai receives a total of 40 weekly downloads. As such, editcodewithai popularity was classified as not popular.
We found that editcodewithai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.