phantomx-tool-client 1.0.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/bin/tool-server.js +16 -0
- package/dist/Services/EditTool.d.ts +86 -0
- package/dist/Services/EditTool.d.ts.map +1 -0
- package/dist/Services/EditTool.js +516 -0
- package/dist/Services/EditTool.js.map +1 -0
- package/dist/Services/Logger.d.ts +32 -0
- package/dist/Services/Logger.d.ts.map +1 -0
- package/dist/Services/Logger.js +185 -0
- package/dist/Services/Logger.js.map +1 -0
- package/dist/Services/ReadFileTool.d.ts +49 -0
- package/dist/Services/ReadFileTool.d.ts.map +1 -0
- package/dist/Services/ReadFileTool.js +239 -0
- package/dist/Services/ReadFileTool.js.map +1 -0
- package/dist/__tests__/__mocks__/tool-server.mock.d.ts +4 -0
- package/dist/__tests__/__mocks__/tool-server.mock.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/tool-server.mock.js +8 -0
- package/dist/__tests__/__mocks__/tool-server.mock.js.map +1 -0
- package/dist/__tests__/toolExecutionService_tempAI.test.d.ts +13 -0
- package/dist/__tests__/toolExecutionService_tempAI.test.d.ts.map +1 -0
- package/dist/__tests__/toolExecutionService_tempAI.test.js +491 -0
- package/dist/__tests__/toolExecutionService_tempAI.test.js.map +1 -0
- package/dist/githubOperationsHanlder.d.ts +274 -0
- package/dist/githubOperationsHanlder.d.ts.map +1 -0
- package/dist/githubOperationsHanlder.js +1487 -0
- package/dist/githubOperationsHanlder.js.map +1 -0
- package/dist/tool-server.d.ts +4 -0
- package/dist/tool-server.d.ts.map +1 -0
- package/dist/tool-server.js +190 -0
- package/dist/tool-server.js.map +1 -0
- package/dist/toolExecutionService.d.ts +28 -0
- package/dist/toolExecutionService.d.ts.map +1 -0
- package/dist/toolExecutionService.js +464 -0
- package/dist/toolExecutionService.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
// Load environment variables from .env if present (works both globally installed and locally)
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
|
|
9
|
+
// Support a .env file placed next to wherever the user runs the command from
|
|
10
|
+
const envPath = path.resolve(process.cwd(), '.env');
|
|
11
|
+
if (fs.existsSync(envPath)) {
|
|
12
|
+
require('dotenv').config({ path: envPath });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Boot the compiled tool-server
|
|
16
|
+
require('../dist/tool-server.js');
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface defining the structure for code editing operations
|
|
3
|
+
*/
|
|
4
|
+
interface CodeEdit {
|
|
5
|
+
filePath: string;
|
|
6
|
+
id: string;
|
|
7
|
+
operation: 'insert' | 'replace' | 'delete';
|
|
8
|
+
locationForInsertion: {
|
|
9
|
+
startLine: number;
|
|
10
|
+
endLine?: number;
|
|
11
|
+
};
|
|
12
|
+
patchToBeEdited: string;
|
|
13
|
+
content?: string;
|
|
14
|
+
reason?: string;
|
|
15
|
+
}
|
|
16
|
+
interface CodeEditEx {
|
|
17
|
+
filePath: string;
|
|
18
|
+
absolutePath: string;
|
|
19
|
+
id: string;
|
|
20
|
+
operation: 'insert' | 'replace' | 'delete';
|
|
21
|
+
locationForInsertion: {
|
|
22
|
+
startLine: string;
|
|
23
|
+
endLine?: string;
|
|
24
|
+
};
|
|
25
|
+
patchToBeEdited: string;
|
|
26
|
+
content?: string;
|
|
27
|
+
reason?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Compare two code lines for semantic equality,
|
|
31
|
+
* ignoring whitespace and escape‐sequence literals.
|
|
32
|
+
*
|
|
33
|
+
* @returns true if, after normalization, the two lines are identical.
|
|
34
|
+
*/
|
|
35
|
+
export declare function compareCodeLines(line1: string, line2: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Class that provides file editing functionality
|
|
38
|
+
*/
|
|
39
|
+
export declare class EditTool {
|
|
40
|
+
/**
|
|
41
|
+
* Constructor for EditTool
|
|
42
|
+
* No longer requires a folderPath parameter as we'll use absolute paths directly
|
|
43
|
+
*/
|
|
44
|
+
constructor();
|
|
45
|
+
applyFinalEdit(edits: CodeEditEx[]): Promise<[string, string][]>;
|
|
46
|
+
applyEdit(edit: CodeEdit): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Validates the edit request to ensure it has all required fields
|
|
49
|
+
* @param edit The edit operation to validate
|
|
50
|
+
* @returns A string with an error message if validation fails, or null if validation passes
|
|
51
|
+
*/
|
|
52
|
+
private validateEdit;
|
|
53
|
+
/**
|
|
54
|
+
* Performs an insert operation
|
|
55
|
+
* @param lines Array of file lines
|
|
56
|
+
* @param startLine Line number where to insert (1-indexed)
|
|
57
|
+
* @param content Content to insert
|
|
58
|
+
* @returns The new file content as a string or an error message
|
|
59
|
+
*/
|
|
60
|
+
private performInsert;
|
|
61
|
+
/**
|
|
62
|
+
* Performs a replace operation
|
|
63
|
+
* @param lines Array of file lines
|
|
64
|
+
* @param startLine Start line number (1-indexed)
|
|
65
|
+
* @param endLine End line number (1-indexed)
|
|
66
|
+
* @param content New content to replace the specified lines
|
|
67
|
+
* @returns The new file content as a string or an error message
|
|
68
|
+
*/
|
|
69
|
+
private performReplace;
|
|
70
|
+
/**
|
|
71
|
+
* Performs a delete operation
|
|
72
|
+
* @param lines Array of file lines
|
|
73
|
+
* @param startLine Start line number (1-indexed)
|
|
74
|
+
* @param endLine End line number (1-indexed)
|
|
75
|
+
* @returns The new file content as a string or an error message
|
|
76
|
+
*/
|
|
77
|
+
private performDelete;
|
|
78
|
+
/**
|
|
79
|
+
* Creates a backup of a file before editing
|
|
80
|
+
* @param filePath Path to the file to backup
|
|
81
|
+
* @returns The path to the backup file or an error message
|
|
82
|
+
*/
|
|
83
|
+
createBackup(filePath: string): Promise<string>;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
86
|
+
//#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B;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAsBrB;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;IA4BtB;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IA2BrB;;;;OAIG;IACU,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAsD7D"}
|
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.EditTool = void 0;
|
|
37
|
+
exports.compareCodeLines = compareCodeLines;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
/**
|
|
40
|
+
* Normalizes a path for the current OS.
|
|
41
|
+
* On Windows: converts Linux-style WSL paths (/mnt/f/...) to Windows paths (F:\...)
|
|
42
|
+
* On Linux/Mac: returns the path as-is.
|
|
43
|
+
*/
|
|
44
|
+
const normalizePath = (inputPath) => {
|
|
45
|
+
if (process.platform !== 'win32') {
|
|
46
|
+
return inputPath; // Linux/Alpine/Mac — no translation needed
|
|
47
|
+
}
|
|
48
|
+
// Match /mnt/<single-letter>/<rest> — WSL mount convention
|
|
49
|
+
const wslMountPattern = /^\/mnt\/([a-zA-Z])(\/.*)?$/;
|
|
50
|
+
const match = inputPath.match(wslMountPattern);
|
|
51
|
+
if (match) {
|
|
52
|
+
const driveLetter = match[1].toUpperCase();
|
|
53
|
+
const rest = match[2] ? match[2].replace(/\//g, '\\') : '\\';
|
|
54
|
+
return `${driveLetter}:${rest}`;
|
|
55
|
+
}
|
|
56
|
+
return inputPath; // already a Windows path or unrecognised format
|
|
57
|
+
};
|
|
58
|
+
function normalizeLine(line) {
|
|
59
|
+
const trimmedLine = line.trim();
|
|
60
|
+
// strip whitespace entirely for comments
|
|
61
|
+
if (trimmedLine.startsWith('//') ||
|
|
62
|
+
trimmedLine.startsWith('/*') ||
|
|
63
|
+
trimmedLine.startsWith('*/') ||
|
|
64
|
+
trimmedLine.includes('/*') ||
|
|
65
|
+
trimmedLine.includes('*/')) {
|
|
66
|
+
return line.replace(/\s+/g, '');
|
|
67
|
+
}
|
|
68
|
+
// Process the line character by character to properly handle regex patterns
|
|
69
|
+
let result = '';
|
|
70
|
+
let segments = [];
|
|
71
|
+
let currentSegment = { text: '', type: 'code' }; // Types: 'code', 'regex', 'string'
|
|
72
|
+
let i = 0;
|
|
73
|
+
let inRegex = false;
|
|
74
|
+
let inString = false;
|
|
75
|
+
let stringDelimiter = '';
|
|
76
|
+
let escaped = false;
|
|
77
|
+
// First pass: Identify segments (regex, strings, code)
|
|
78
|
+
while (i < line.length) {
|
|
79
|
+
const char = line[i];
|
|
80
|
+
const nextChar = i < line.length - 1 ? line[i + 1] : '';
|
|
81
|
+
// Handle string boundaries
|
|
82
|
+
if (!inRegex && !escaped && (char === '"' || char === "'" || char === '`')) {
|
|
83
|
+
if (inString && char === stringDelimiter) {
|
|
84
|
+
// End of string
|
|
85
|
+
currentSegment.text += char;
|
|
86
|
+
segments.push(currentSegment);
|
|
87
|
+
currentSegment = { text: '', type: 'code' };
|
|
88
|
+
inString = false;
|
|
89
|
+
}
|
|
90
|
+
else if (!inString) {
|
|
91
|
+
// Start of string
|
|
92
|
+
if (currentSegment.text) {
|
|
93
|
+
segments.push(currentSegment);
|
|
94
|
+
}
|
|
95
|
+
currentSegment = { text: char, type: 'string' };
|
|
96
|
+
inString = true;
|
|
97
|
+
stringDelimiter = char;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Different string delimiter inside a string
|
|
101
|
+
currentSegment.text += char;
|
|
102
|
+
}
|
|
103
|
+
escaped = false;
|
|
104
|
+
}
|
|
105
|
+
// Handle backslashes
|
|
106
|
+
else if (char === '\\') {
|
|
107
|
+
currentSegment.text += char;
|
|
108
|
+
escaped = !escaped;
|
|
109
|
+
}
|
|
110
|
+
// Potential start of regex literal
|
|
111
|
+
else if (!inString && !escaped && char === '/') {
|
|
112
|
+
const before = line.substring(0, i).trim();
|
|
113
|
+
const isRegexStart = before === '' ||
|
|
114
|
+
/[=\(\[\{:,!&|?;]$/.test(before) ||
|
|
115
|
+
/return\s*$/.test(before) ||
|
|
116
|
+
/case\s*$/.test(before) ||
|
|
117
|
+
/else\s*$/.test(before) ||
|
|
118
|
+
/new\s*$/.test(before) ||
|
|
119
|
+
/throw\s*$/.test(before) ||
|
|
120
|
+
/=>\s*$/.test(before);
|
|
121
|
+
if (isRegexStart && !inRegex) {
|
|
122
|
+
// Start of regex
|
|
123
|
+
if (currentSegment.text) {
|
|
124
|
+
segments.push(currentSegment);
|
|
125
|
+
}
|
|
126
|
+
currentSegment = { text: char, type: 'regex' };
|
|
127
|
+
inRegex = true;
|
|
128
|
+
}
|
|
129
|
+
else if (inRegex && !escaped) {
|
|
130
|
+
// End of regex
|
|
131
|
+
currentSegment.text += char;
|
|
132
|
+
// Consume any regex flags
|
|
133
|
+
let j = i + 1;
|
|
134
|
+
while (j < line.length && /[gimsuy]/.test(line[j])) {
|
|
135
|
+
currentSegment.text += line[j];
|
|
136
|
+
j++;
|
|
137
|
+
}
|
|
138
|
+
segments.push(currentSegment);
|
|
139
|
+
currentSegment = { text: '', type: 'code' };
|
|
140
|
+
inRegex = false;
|
|
141
|
+
i = j - 1;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// Just a slash in code or escaped slash in regex
|
|
145
|
+
currentSegment.text += char;
|
|
146
|
+
}
|
|
147
|
+
escaped = false;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
// Regular character
|
|
151
|
+
currentSegment.text += char;
|
|
152
|
+
escaped = false;
|
|
153
|
+
}
|
|
154
|
+
i++;
|
|
155
|
+
}
|
|
156
|
+
// Add the last segment if it has content
|
|
157
|
+
if (currentSegment.text) {
|
|
158
|
+
segments.push(currentSegment);
|
|
159
|
+
}
|
|
160
|
+
// Second pass: Process each segment according to its type
|
|
161
|
+
for (const segment of segments) {
|
|
162
|
+
if (segment.type === 'regex') {
|
|
163
|
+
// Preserve regex patterns exactly as they are
|
|
164
|
+
result += segment.text;
|
|
165
|
+
}
|
|
166
|
+
else if (segment.type === 'string') {
|
|
167
|
+
// Preserve strings exactly as they are
|
|
168
|
+
result += segment.text;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// For code segments, normalize by removing whitespace and escape sequences
|
|
172
|
+
let normalizedCode = segment.text;
|
|
173
|
+
// Strip all whitespace
|
|
174
|
+
normalizedCode = normalizedCode.replace(/\s+/g, '');
|
|
175
|
+
// Remove escape sequences in code (but not in regex or strings)
|
|
176
|
+
normalizedCode = normalizedCode.replace(/\\(u\{[0-9A-Fa-f]+\}|u[0-9A-Fa-f]{4}|x[0-9A-Fa-f]{2}|[nrtbfv0'"\\])/g, '');
|
|
177
|
+
result += normalizedCode;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Compare two code lines for semantic equality,
|
|
184
|
+
* ignoring whitespace and escape‐sequence literals.
|
|
185
|
+
*
|
|
186
|
+
* @returns true if, after normalization, the two lines are identical.
|
|
187
|
+
*/
|
|
188
|
+
function compareCodeLines(line1, line2) {
|
|
189
|
+
return normalizeLine(line1) === normalizeLine(line2);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Class that provides file editing functionality
|
|
193
|
+
*/
|
|
194
|
+
class EditTool {
|
|
195
|
+
/**
|
|
196
|
+
* Constructor for EditTool
|
|
197
|
+
* No longer requires a folderPath parameter as we'll use absolute paths directly
|
|
198
|
+
*/
|
|
199
|
+
constructor() { }
|
|
200
|
+
async applyFinalEdit(edits) {
|
|
201
|
+
let editResult = [];
|
|
202
|
+
for (let edit of edits) {
|
|
203
|
+
// Normalize path for the current OS (handles Linux /mnt/<drive> paths on Windows)
|
|
204
|
+
let finalPath = normalizePath(edit.absolutePath);
|
|
205
|
+
//finding the line numbers from the line string and passing it to the applyEdit function
|
|
206
|
+
if (!fs.existsSync(finalPath)) {
|
|
207
|
+
editResult.push([edit.id, 'File not found: ' + finalPath]);
|
|
208
|
+
return editResult; //returning since the operation failed...
|
|
209
|
+
}
|
|
210
|
+
// Check and update file permissions if needed
|
|
211
|
+
// const permissionResult = await this.checkAndUpdatePermissions(finalPath);
|
|
212
|
+
// if (permissionResult !== true) {
|
|
213
|
+
// editResult.push([edit.id, `Permission error: ${permissionResult}`]);
|
|
214
|
+
// return editResult; //returning since the operation failed...
|
|
215
|
+
// }
|
|
216
|
+
const fileContent = fs.readFileSync(finalPath, 'utf8');
|
|
217
|
+
const lines = fileContent.split('\n');
|
|
218
|
+
let startLineIndex = 0;
|
|
219
|
+
let endLineIndex = 0;
|
|
220
|
+
if (edit.operation === "insert") {
|
|
221
|
+
//we have to find the startLine only
|
|
222
|
+
let startLines = edit.locationForInsertion.startLine.split('\n');
|
|
223
|
+
let j = 0;
|
|
224
|
+
for (let i = 0; i < lines.length; i++) {
|
|
225
|
+
if (compareCodeLines(startLines[0], lines[i])) //the first line matches let's see if all other lines also match in continuation
|
|
226
|
+
{
|
|
227
|
+
if (startLines.length === 1) {
|
|
228
|
+
//if length is one, then this is the startLine for this
|
|
229
|
+
startLineIndex = i + 1;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
let flag = 0;
|
|
233
|
+
let ii = i;
|
|
234
|
+
ii++;
|
|
235
|
+
for (let j = 1; j < startLines.length && ii < lines.length; j++, ii++) {
|
|
236
|
+
if (!compareCodeLines(startLines[j], lines[ii])) {
|
|
237
|
+
flag = 1;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (flag === 0) {
|
|
242
|
+
startLineIndex = i + startLines.length; // +1 since the lines should be 1 indexed.
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
//if the operation is of delete or replace, we will follow the same logic for this too
|
|
250
|
+
let block = edit.patchToBeEdited.split('\n');
|
|
251
|
+
for (let i = 0; i < lines.length; i++) {
|
|
252
|
+
if (compareCodeLines(block[0], lines[i])) {
|
|
253
|
+
if (block.length === 1) {
|
|
254
|
+
//if the block's length is 1, then the startLineIndexa nd endLineIndex will be the same
|
|
255
|
+
startLineIndex = endLineIndex = i + 1;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
let flag = 0;
|
|
259
|
+
let ii = i;
|
|
260
|
+
ii++;
|
|
261
|
+
for (let j = 1; j < block.length && ii < lines.length; j++, ii++) {
|
|
262
|
+
if (!compareCodeLines(block[j], lines[ii])) {
|
|
263
|
+
flag = 1;
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (flag === 0) {
|
|
268
|
+
startLineIndex = i + 1;
|
|
269
|
+
endLineIndex = i + block.length;
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
editResult.push([edit.id, await this.applyEdit({
|
|
277
|
+
id: edit.id,
|
|
278
|
+
content: edit.content,
|
|
279
|
+
filePath: finalPath,
|
|
280
|
+
operation: edit.operation,
|
|
281
|
+
reason: edit.reason,
|
|
282
|
+
locationForInsertion: {
|
|
283
|
+
startLine: startLineIndex,
|
|
284
|
+
endLine: endLineIndex
|
|
285
|
+
},
|
|
286
|
+
patchToBeEdited: edit.patchToBeEdited
|
|
287
|
+
})]);
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
console.log("Error applying edit:", error);
|
|
291
|
+
editResult.push([edit.id, `Failed to apply edit: ${error} you should try rewriting the entire file`]);
|
|
292
|
+
return editResult;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return editResult;
|
|
296
|
+
}
|
|
297
|
+
async applyEdit(edit) {
|
|
298
|
+
try {
|
|
299
|
+
// Validate the edit request
|
|
300
|
+
const validationError = this.validateEdit(edit);
|
|
301
|
+
if (validationError) {
|
|
302
|
+
throw `Validation failed: ${validationError}`;
|
|
303
|
+
}
|
|
304
|
+
// Check if file exists
|
|
305
|
+
if (!fs.existsSync(edit.filePath)) {
|
|
306
|
+
throw `File not found: ${edit.filePath}`;
|
|
307
|
+
}
|
|
308
|
+
// Check and update file permissions if needed
|
|
309
|
+
// const permissionResult = await this.checkAndUpdatePermissions(edit.filePath);
|
|
310
|
+
// if (permissionResult !== true) {
|
|
311
|
+
// throw `Permission error: ${permissionResult}`;
|
|
312
|
+
// }
|
|
313
|
+
// Read the file content
|
|
314
|
+
const fileContent = await fs.promises.readFile(edit.filePath, 'utf8');
|
|
315
|
+
const lines = fileContent.split('\n');
|
|
316
|
+
// Apply the edit based on operation type
|
|
317
|
+
let newContent;
|
|
318
|
+
switch (edit.operation) {
|
|
319
|
+
case 'insert':
|
|
320
|
+
newContent = this.performInsert(lines, edit.locationForInsertion.startLine, edit.content || '');
|
|
321
|
+
break;
|
|
322
|
+
case 'replace':
|
|
323
|
+
newContent = this.performReplace(lines, edit.locationForInsertion.startLine, edit.locationForInsertion.endLine || edit.locationForInsertion.startLine, edit.content || '');
|
|
324
|
+
break;
|
|
325
|
+
case 'delete':
|
|
326
|
+
newContent = this.performDelete(lines, edit.locationForInsertion.startLine, edit.locationForInsertion.endLine || edit.locationForInsertion.startLine);
|
|
327
|
+
break;
|
|
328
|
+
default:
|
|
329
|
+
throw `Unsupported operation: ${edit.operation}`;
|
|
330
|
+
}
|
|
331
|
+
// Check if the operation returned an error message
|
|
332
|
+
if (newContent.startsWith('ERROR:')) {
|
|
333
|
+
throw newContent + " you should try rewriting the file";
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
// Write the modified content back to the file
|
|
337
|
+
await fs.promises.writeFile(edit.filePath, newContent);
|
|
338
|
+
return `Successfully applied ${edit.operation} operation to ${edit.filePath}`;
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
throw `Failed to write file: ${error}, you should try rewriting the file`;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
throw `Failed to apply edit: ${error}, you should try rewriting the file`;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Validates the edit request to ensure it has all required fields
|
|
350
|
+
* @param edit The edit operation to validate
|
|
351
|
+
* @returns A string with an error message if validation fails, or null if validation passes
|
|
352
|
+
*/
|
|
353
|
+
validateEdit(edit) {
|
|
354
|
+
if (!edit.filePath) {
|
|
355
|
+
return 'File path is required';
|
|
356
|
+
}
|
|
357
|
+
if (!edit.operation) {
|
|
358
|
+
return 'Operation type is required';
|
|
359
|
+
}
|
|
360
|
+
if (!edit.locationForInsertion || typeof edit.locationForInsertion.startLine !== 'number') {
|
|
361
|
+
return 'Start line number is required';
|
|
362
|
+
}
|
|
363
|
+
if (edit.operation !== 'delete' && !edit.content) {
|
|
364
|
+
return 'Content is required for insert and replace operations';
|
|
365
|
+
}
|
|
366
|
+
if ((edit.operation === 'replace' || edit.operation === 'delete') &&
|
|
367
|
+
edit.locationForInsertion.endLine &&
|
|
368
|
+
edit.locationForInsertion.endLine < edit.locationForInsertion.startLine) {
|
|
369
|
+
return 'End line cannot be before start line';
|
|
370
|
+
}
|
|
371
|
+
return null; // Validation passed
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Performs an insert operation
|
|
375
|
+
* @param lines Array of file lines
|
|
376
|
+
* @param startLine Line number where to insert (1-indexed)
|
|
377
|
+
* @param content Content to insert
|
|
378
|
+
* @returns The new file content as a string or an error message
|
|
379
|
+
*/
|
|
380
|
+
performInsert(lines, startLine, content) {
|
|
381
|
+
try {
|
|
382
|
+
// Convert to 0-indexed
|
|
383
|
+
const lineIndex = startLine;
|
|
384
|
+
// Ensure the line index is valid
|
|
385
|
+
if (lineIndex < 0 || lineIndex > lines.length) {
|
|
386
|
+
return `ERROR: Invalid line number: ${startLine}. File has ${lines.length} lines, you should consider rewriting the entire file.`;
|
|
387
|
+
}
|
|
388
|
+
// Insert the content at the specified line
|
|
389
|
+
lines.splice(lineIndex, 0, ...content.split('\n'));
|
|
390
|
+
return lines.join('\n');
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
if (error instanceof Error) {
|
|
394
|
+
return `ERROR: Failed to perform insert: ${error.message}, you should consider rewriting the entire file`;
|
|
395
|
+
}
|
|
396
|
+
return 'ERROR: Failed to perform insert due to an unknown error, you should consider rewriting the entire file';
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Performs a replace operation
|
|
401
|
+
* @param lines Array of file lines
|
|
402
|
+
* @param startLine Start line number (1-indexed)
|
|
403
|
+
* @param endLine End line number (1-indexed)
|
|
404
|
+
* @param content New content to replace the specified lines
|
|
405
|
+
* @returns The new file content as a string or an error message
|
|
406
|
+
*/
|
|
407
|
+
performReplace(lines, startLine, endLine, content) {
|
|
408
|
+
try {
|
|
409
|
+
// Convert to 0-indexed
|
|
410
|
+
const startIndex = startLine - 1;
|
|
411
|
+
const endIndex = endLine - 1;
|
|
412
|
+
// Ensure the line indices are valid
|
|
413
|
+
if (startIndex < 0 || startIndex >= lines.length) {
|
|
414
|
+
return `ERROR: Invalid start line: ${startLine}. File has ${lines.length} lines.`;
|
|
415
|
+
}
|
|
416
|
+
if (endIndex < 0 || endIndex >= lines.length) {
|
|
417
|
+
return `ERROR: Invalid end line: ${endLine}. File has ${lines.length} lines.`;
|
|
418
|
+
}
|
|
419
|
+
// Replace the specified lines with the new content
|
|
420
|
+
const contentLines = content.split('\n');
|
|
421
|
+
lines.splice(startIndex, endIndex - startIndex + 1, ...contentLines);
|
|
422
|
+
return lines.join('\n');
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
if (error instanceof Error) {
|
|
426
|
+
return `ERROR: Failed to perform replace: ${error.message}, you should try to rewrite the entire file`;
|
|
427
|
+
}
|
|
428
|
+
return 'ERROR: Failed to perform replace due to an unknown error, you should try to rewrite the entire file';
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Performs a delete operation
|
|
433
|
+
* @param lines Array of file lines
|
|
434
|
+
* @param startLine Start line number (1-indexed)
|
|
435
|
+
* @param endLine End line number (1-indexed)
|
|
436
|
+
* @returns The new file content as a string or an error message
|
|
437
|
+
*/
|
|
438
|
+
performDelete(lines, startLine, endLine) {
|
|
439
|
+
try {
|
|
440
|
+
// Convert to 0-indexed
|
|
441
|
+
const startIndex = startLine - 1;
|
|
442
|
+
const endIndex = endLine - 1;
|
|
443
|
+
// Ensure the line indices are valid
|
|
444
|
+
if (startIndex < 0 || startIndex >= lines.length) {
|
|
445
|
+
return `ERROR: Invalid start line: ${startLine}. File has ${lines.length} lines.`;
|
|
446
|
+
}
|
|
447
|
+
if (endIndex < 0 || endIndex >= lines.length) {
|
|
448
|
+
return `ERROR: Invalid end line: ${endLine}. File has ${lines.length} lines.`;
|
|
449
|
+
}
|
|
450
|
+
// Delete the specified lines
|
|
451
|
+
lines.splice(startIndex, endIndex - startIndex + 1);
|
|
452
|
+
return lines.join('\n');
|
|
453
|
+
}
|
|
454
|
+
catch (error) {
|
|
455
|
+
if (error instanceof Error) {
|
|
456
|
+
return `ERROR: Failed to perform delete: ${error.message}, you should try to rewrite the entire file`;
|
|
457
|
+
}
|
|
458
|
+
return 'ERROR: Failed to perform delete due to an unknown error';
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Creates a backup of a file before editing
|
|
463
|
+
* @param filePath Path to the file to backup
|
|
464
|
+
* @returns The path to the backup file or an error message
|
|
465
|
+
*/
|
|
466
|
+
async createBackup(filePath) {
|
|
467
|
+
try {
|
|
468
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
469
|
+
const backupPath = `${filePath}.${timestamp}.bak`;
|
|
470
|
+
await fs.promises.copyFile(filePath, backupPath);
|
|
471
|
+
return backupPath;
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
if (error instanceof Error) {
|
|
475
|
+
return `Failed to create backup: ${error.message}`;
|
|
476
|
+
}
|
|
477
|
+
return 'Failed to create backup due to an unknown error';
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
exports.EditTool = EditTool;
|
|
482
|
+
// (async()=>{
|
|
483
|
+
// await EditTool.applyFinalEdit({
|
|
484
|
+
// "filePath": "./src/prompt_library.js",
|
|
485
|
+
// "operation": "replace",
|
|
486
|
+
// "locationForInsertion":{"startLine":""},
|
|
487
|
+
// "patchToBeEdited": " {\n \"name\": \"EditCodeFile\",\n \"description\": \"Edits a code file by inserting, replacing, or deleting content at specific line.This object and all the objects given should be outputted in json format.\",\n \"input_schema\": {\n \"type\": \"object\",\n \"required\": [\"filePath\", \"operation\"],\n \"properties\": {\n \"filePath\": {\n \"type\": \"string\",\n \"description\": \"Path to the file to edit\"\n },\n \"operation\": {\n \"type\": \"string\",\n \"enum\": [\"insert\", \"replace\", \"delete\"],\n \"description\": \"Type of edit operation to perform\"\n },\n \"locationForInsertion\": {\n \"type\": \"object\",\n \"description\": \"this has to be json object, having the startLine only in json as the object.we will require the startLine after which the new patch of code will be added, to identify the startLine, you have to ouptut a set of lines so that we can infer the line number after which the change has to be made.\\\nremember, that the last line you output in startLine set will be the final line and after that line the insertion will happen, i repeat, only the last line in the startLine set.\\\nthe extra lines which you are outputting before the main startLine are used only to identify that one line after which the insertion will take place, so output least number of lines\\\nwhich can uniquely identify the insertion line.\",\n \"required\": [\"startLine\"],\n \"properties\": {\n \"startLine\": {\n \"type\": \"string\",\n \"description\": \"Lines(exact line as in the given code) where to start the edit, in case of insertion, the startLine will be the line after which the new content will be added.\"\n\n }\n }\n },\n \"patchToBeEdited\":\n {\n \"type\": \"string\",\n \"description\": \"this is the patch in the code file which has to be either replaced or deleted. If it has to be replaced, output the new code in content.\"\n },\n \"content\": {\n \"type\": \"string\",\n \"description\": \"New content to insert or replace (not needed for delete operations)\"\n },\n \"reason\": {\n \"type\": \"string\",\n \"description\": \"Optional documentation explaining why this edit is being made\"\n }\n }\n }\n },",
|
|
488
|
+
// "content": " {\n \"name\": \"EditCodeFile\",\n \"description\": \"Edits a code file by inserting, replacing, or deleting content at specific line. This function accepts an array of edit objects.\",\n \"input_schema\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"required\": [\"filePath\", \"operation\"],\n \"properties\": {\n \"filePath\": {\n \"type\": \"string\",\n \"description\": \"Path to the file to edit\"\n },\n \"operation\": {\n \"type\": \"string\",\n \"enum\": [\"insert\", \"replace\", \"delete\"],\n \"description\": \"Type of edit operation to perform\"\n },\n \"locationForInsertion\": {\n \"type\": \"object\",\n \"description\": \"this has to be json object, having the startLine only in json as the object.we will require the startLine after which the new patch of code will be added, to identify the startLine, you have to ouptut a set of lines so that we can infer the line number after which the change has to be made.\\\nremember, that the last line you output in startLine set will be the final line and after that line the insertion will happen, i repeat, only the last line in the startLine set.\\\nthe extra lines which you are outputting before the main startLine are used only to identify that one line after which the insertion will take place, so output least number of lines\\\nwhich can uniquely identify the insertion line.\",\n \"required\": [\"startLine\"],\n \"properties\": {\n \"startLine\": {\n \"type\": \"string\",\n \"description\": \"Lines(exact line as in the given code) where to start the edit, in case of insertion, the startLine will be the line after which the new content will be added.\"\n }\n }\n },\n \"patchToBeEdited\": {\n \"type\": \"string\",\n \"description\": \"this is the patch in the code file which has to be either replaced or deleted. If it has to be replaced, output the new code in content.\"\n },\n \"content\": {\n \"type\": \"string\",\n \"description\": \"New content to insert or replace (not needed for delete operations)\"\n },\n \"reason\": {\n \"type\": \"string\",\n \"description\": \"Optional documentation explaining why this edit is being made\"\n }\n }\n }\n }\n },",
|
|
489
|
+
// "reason": "Changed the EditCodeFile schema to accept an array of edit objects instead of a single object by changing the input_schema type from \"object\" to \"array\" and moving the object properties into the \"items\" property."
|
|
490
|
+
// }
|
|
491
|
+
// );
|
|
492
|
+
// })();
|
|
493
|
+
// Example usage:
|
|
494
|
+
/*
|
|
495
|
+
async function example() {
|
|
496
|
+
try {
|
|
497
|
+
// Optional: Create a backup before editing
|
|
498
|
+
const backupPath = await EditTool.createBackup('/path/to/file.ts');
|
|
499
|
+
console.log(`Backup created at: ${backupPath}`);
|
|
500
|
+
|
|
501
|
+
// Apply an edit
|
|
502
|
+
const result = await EditTool.applyEdit({
|
|
503
|
+
filePath: '/path/to/file.ts',
|
|
504
|
+
operation: 'insert',
|
|
505
|
+
location: { startLine: 10 },
|
|
506
|
+
content: 'console.log("New line inserted");',
|
|
507
|
+
reason: 'Adding debug statement'
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
console.log(result);
|
|
511
|
+
} catch (error) {
|
|
512
|
+
console.error(error);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
*/
|
|
516
|
+
//# sourceMappingURL=EditTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditTool.js","sourceRoot":"","sources":["../../src/Services/EditTool.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuMA,4CAEC;AAzMD,uCAAyB;AAIzB;;;;GAIG;AACH,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAU,EAAE;IAChD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC,CAAC,2CAA2C;IACjE,CAAC;IAED,2DAA2D;IAC3D,MAAM,eAAe,GAAG,4BAA4B,CAAC;IACrD,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAC/C,IAAI,KAAK,EAAE,CAAC;QACR,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC7D,OAAO,GAAG,WAAW,IAAI,IAAI,EAAE,CAAC;IACpC,CAAC;IAED,OAAO,SAAS,CAAC,CAAC,gDAAgD;AACtE,CAAC,CAAC;AAiCF,SAAS,aAAa,CAAC,IAAY;IACjC,M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