editcodewithai 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +12 -0
- package/dist/prompt.d.ts +1 -0
- package/dist/prompt.js +3 -3
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -23,7 +23,11 @@ npm install editcodewithai
|
|
|
23
23
|
Here's a basic example of how to use `performAiEdit` to update a file:
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
performAiEdit,
|
|
28
|
+
FORMAT_INSTRUCTIONS,
|
|
29
|
+
LlmFunction,
|
|
30
|
+
} from "editcodewithai";
|
|
27
31
|
import { VizFiles } from "@vizhub/viz-types";
|
|
28
32
|
|
|
29
33
|
// Your function to call the LLM
|
|
@@ -102,6 +106,45 @@ The library handles several file operations automatically:
|
|
|
102
106
|
- **Creating new files**: When the AI suggests new files to add
|
|
103
107
|
- **Deleting files**: When the AI returns empty content for a file
|
|
104
108
|
|
|
109
|
+
## Format Instructions
|
|
110
|
+
|
|
111
|
+
The library exports `FORMAT_INSTRUCTIONS` which contains the exact prompt instructions used for each edit format. This can be useful if you want to:
|
|
112
|
+
|
|
113
|
+
- Use the formatting instructions in your own custom prompts
|
|
114
|
+
- Understand exactly what instructions are sent to the LLM for each format
|
|
115
|
+
- Build your own AI editing tools using the same proven prompt patterns
|
|
116
|
+
|
|
117
|
+
### Usage
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { FORMAT_INSTRUCTIONS } from "editcodewithai";
|
|
121
|
+
|
|
122
|
+
// Access instructions for a specific format
|
|
123
|
+
console.log(FORMAT_INSTRUCTIONS.diff);
|
|
124
|
+
console.log(FORMAT_INSTRUCTIONS.whole);
|
|
125
|
+
console.log(FORMAT_INSTRUCTIONS["diff-fenced"]);
|
|
126
|
+
console.log(FORMAT_INSTRUCTIONS.udiff);
|
|
127
|
+
|
|
128
|
+
// Use in your own prompts
|
|
129
|
+
const customPrompt = `
|
|
130
|
+
${FORMAT_INSTRUCTIONS.diff}
|
|
131
|
+
|
|
132
|
+
Please update the following code to add error handling:
|
|
133
|
+
${yourCodeHere}
|
|
134
|
+
`;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Available Formats
|
|
138
|
+
|
|
139
|
+
The `FORMAT_INSTRUCTIONS` object contains instructions for these edit formats:
|
|
140
|
+
|
|
141
|
+
- **`whole`**: Instructions for returning complete file contents
|
|
142
|
+
- **`diff`**: Instructions for search-and-replace blocks
|
|
143
|
+
- **`diff-fenced`**: Instructions for search-and-replace blocks with file paths inside code fences
|
|
144
|
+
- **`udiff`**: Instructions for unified diff format
|
|
145
|
+
|
|
146
|
+
Each 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.
|
|
147
|
+
|
|
105
148
|
## Similar Projects
|
|
106
149
|
|
|
107
150
|
- **Aider**: An AI pair programming tool that integrates with your terminal to assist in code editing within your local git repository. [https://aider.chat/](https://aider.chat/)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { PerformAiEditParams, PerformAiEditResult } from "./types";
|
|
2
|
+
import { PROMPT_TEMPLATE_VERSION, assembleFullPrompt, FORMAT_INSTRUCTIONS } from "./prompt";
|
|
3
|
+
import { getGenerationMetadata } from "./metadata";
|
|
4
|
+
import { prepareFilesForPrompt, mergeFileChanges, parseDiffs, applyDiffs, parseDiffFenced, parseUdiffs, applyUdiffs } from "./fileUtils";
|
|
2
5
|
export type { LlmFunction, PerformAiEditParams, PerformAiEditResult, EditFormat, } from "./types";
|
|
6
|
+
export { FORMAT_INSTRUCTIONS, mergeFileChanges, prepareFilesForPrompt, parseDiffs, applyDiffs, parseDiffFenced, parseUdiffs, applyUdiffs, assembleFullPrompt, getGenerationMetadata, PROMPT_TEMPLATE_VERSION, };
|
|
3
7
|
/**
|
|
4
8
|
* Core AI logic for:
|
|
5
9
|
* - Building the prompt (including context)
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROMPT_TEMPLATE_VERSION = exports.getGenerationMetadata = exports.assembleFullPrompt = exports.applyUdiffs = exports.parseUdiffs = exports.parseDiffFenced = exports.applyDiffs = exports.parseDiffs = exports.prepareFilesForPrompt = exports.mergeFileChanges = exports.FORMAT_INSTRUCTIONS = void 0;
|
|
3
4
|
exports.performAiEdit = performAiEdit;
|
|
4
5
|
const llm_code_format_1 = require("llm-code-format");
|
|
5
6
|
const prompt_1 = require("./prompt");
|
|
7
|
+
Object.defineProperty(exports, "PROMPT_TEMPLATE_VERSION", { enumerable: true, get: function () { return prompt_1.PROMPT_TEMPLATE_VERSION; } });
|
|
8
|
+
Object.defineProperty(exports, "assembleFullPrompt", { enumerable: true, get: function () { return prompt_1.assembleFullPrompt; } });
|
|
9
|
+
Object.defineProperty(exports, "FORMAT_INSTRUCTIONS", { enumerable: true, get: function () { return prompt_1.FORMAT_INSTRUCTIONS; } });
|
|
6
10
|
const metadata_1 = require("./metadata");
|
|
11
|
+
Object.defineProperty(exports, "getGenerationMetadata", { enumerable: true, get: function () { return metadata_1.getGenerationMetadata; } });
|
|
7
12
|
const fileUtils_1 = require("./fileUtils");
|
|
13
|
+
Object.defineProperty(exports, "prepareFilesForPrompt", { enumerable: true, get: function () { return fileUtils_1.prepareFilesForPrompt; } });
|
|
14
|
+
Object.defineProperty(exports, "mergeFileChanges", { enumerable: true, get: function () { return fileUtils_1.mergeFileChanges; } });
|
|
15
|
+
Object.defineProperty(exports, "parseDiffs", { enumerable: true, get: function () { return fileUtils_1.parseDiffs; } });
|
|
16
|
+
Object.defineProperty(exports, "applyDiffs", { enumerable: true, get: function () { return fileUtils_1.applyDiffs; } });
|
|
17
|
+
Object.defineProperty(exports, "parseDiffFenced", { enumerable: true, get: function () { return fileUtils_1.parseDiffFenced; } });
|
|
18
|
+
Object.defineProperty(exports, "parseUdiffs", { enumerable: true, get: function () { return fileUtils_1.parseUdiffs; } });
|
|
19
|
+
Object.defineProperty(exports, "applyUdiffs", { enumerable: true, get: function () { return fileUtils_1.applyUdiffs; } });
|
|
8
20
|
const debug = false;
|
|
9
21
|
/**
|
|
10
22
|
* Core AI logic for:
|
package/dist/prompt.d.ts
CHANGED
package/dist/prompt.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PROMPT_TEMPLATE_VERSION = void 0;
|
|
3
|
+
exports.FORMAT_INSTRUCTIONS = exports.PROMPT_TEMPLATE_VERSION = void 0;
|
|
4
4
|
exports.assembleFullPrompt = assembleFullPrompt;
|
|
5
5
|
// Versions of the prompt template.
|
|
6
6
|
exports.PROMPT_TEMPLATE_VERSION = 1;
|
|
7
7
|
// Template pieces
|
|
8
8
|
const TASK = (prompt) => `## Your Task\n\n${prompt}`;
|
|
9
9
|
const FILES = (filesContext) => `## Original Files\n\n${filesContext}`;
|
|
10
|
-
|
|
10
|
+
exports.FORMAT_INSTRUCTIONS = {
|
|
11
11
|
whole: [
|
|
12
12
|
"## Formatting Instructions\n\n",
|
|
13
13
|
"Suggest changes to the original files using this exact format:\n\n",
|
|
@@ -64,6 +64,6 @@ const FORMAT_INSTRUCTIONS = {
|
|
|
64
64
|
* Assembles the full prompt by combining task, files context, and formatting instructions
|
|
65
65
|
*/
|
|
66
66
|
function assembleFullPrompt({ filesContext, prompt, editFormat = "whole", }) {
|
|
67
|
-
const FORMAT = FORMAT_INSTRUCTIONS[editFormat];
|
|
67
|
+
const FORMAT = exports.FORMAT_INSTRUCTIONS[editFormat];
|
|
68
68
|
return [TASK(prompt), FILES(filesContext), FORMAT].join("\n\n");
|
|
69
69
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "editcodewithai",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Edit Code With AI",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,20 +40,20 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/vizhub-core/editcodewithai#readme",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@vizhub/viz-types": "^0.
|
|
44
|
-
"@vizhub/viz-utils": "^1.
|
|
45
|
-
"dotenv": "^17.0
|
|
43
|
+
"@vizhub/viz-types": "^0.3.0",
|
|
44
|
+
"@vizhub/viz-utils": "^1.3.0",
|
|
45
|
+
"dotenv": "^17.2.0",
|
|
46
46
|
"llm-code-format": "^2.0.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@langchain/core": "^0.3.
|
|
50
|
-
"@langchain/openai": "^0.
|
|
51
|
-
"langchain": "^0.3.
|
|
49
|
+
"@langchain/core": "^0.3.66",
|
|
50
|
+
"@langchain/openai": "^0.6.2",
|
|
51
|
+
"langchain": "^0.3.30",
|
|
52
52
|
"cors": "^2.8.5",
|
|
53
53
|
"express": "^5.1.0",
|
|
54
54
|
"npm-check-updates": "^18.0.1",
|
|
55
55
|
"prettier": "^3.6.2",
|
|
56
|
-
"puppeteer": "^24.
|
|
56
|
+
"puppeteer": "^24.14.0",
|
|
57
57
|
"ts-node": "^10.9.2",
|
|
58
58
|
"typescript": "^5.8.3",
|
|
59
59
|
"vitest": "^3.2.4"
|