jiva-core 0.3.3-dev.dc3cf03 → 0.3.4-dev.3c78d8b
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 +232 -570
- package/dist/code/agent.d.ts +105 -0
- package/dist/code/agent.d.ts.map +1 -0
- package/dist/code/agent.js +697 -0
- package/dist/code/agent.js.map +1 -0
- package/dist/code/file-lock.d.ts +15 -0
- package/dist/code/file-lock.d.ts.map +1 -0
- package/dist/code/file-lock.js +36 -0
- package/dist/code/file-lock.js.map +1 -0
- package/dist/code/lsp/client.d.ts +30 -0
- package/dist/code/lsp/client.d.ts.map +1 -0
- package/dist/code/lsp/client.js +181 -0
- package/dist/code/lsp/client.js.map +1 -0
- package/dist/code/lsp/language.d.ts +12 -0
- package/dist/code/lsp/language.d.ts.map +1 -0
- package/dist/code/lsp/language.js +145 -0
- package/dist/code/lsp/language.js.map +1 -0
- package/dist/code/lsp/manager.d.ts +39 -0
- package/dist/code/lsp/manager.d.ts.map +1 -0
- package/dist/code/lsp/manager.js +108 -0
- package/dist/code/lsp/manager.js.map +1 -0
- package/dist/code/lsp/server.d.ts +15 -0
- package/dist/code/lsp/server.d.ts.map +1 -0
- package/dist/code/lsp/server.js +78 -0
- package/dist/code/lsp/server.js.map +1 -0
- package/dist/code/tools/bash.d.ts +3 -0
- package/dist/code/tools/bash.d.ts.map +1 -0
- package/dist/code/tools/bash.js +110 -0
- package/dist/code/tools/bash.js.map +1 -0
- package/dist/code/tools/edit.d.ts +11 -0
- package/dist/code/tools/edit.d.ts.map +1 -0
- package/dist/code/tools/edit.js +459 -0
- package/dist/code/tools/edit.js.map +1 -0
- package/dist/code/tools/glob.d.ts +3 -0
- package/dist/code/tools/glob.d.ts.map +1 -0
- package/dist/code/tools/glob.js +62 -0
- package/dist/code/tools/glob.js.map +1 -0
- package/dist/code/tools/grep.d.ts +3 -0
- package/dist/code/tools/grep.d.ts.map +1 -0
- package/dist/code/tools/grep.js +147 -0
- package/dist/code/tools/grep.js.map +1 -0
- package/dist/code/tools/index.d.ts +31 -0
- package/dist/code/tools/index.d.ts.map +1 -0
- package/dist/code/tools/index.js +9 -0
- package/dist/code/tools/index.js.map +1 -0
- package/dist/code/tools/read.d.ts +3 -0
- package/dist/code/tools/read.d.ts.map +1 -0
- package/dist/code/tools/read.js +120 -0
- package/dist/code/tools/read.js.map +1 -0
- package/dist/code/tools/spawn.d.ts +3 -0
- package/dist/code/tools/spawn.d.ts.map +1 -0
- package/dist/code/tools/spawn.js +49 -0
- package/dist/code/tools/spawn.js.map +1 -0
- package/dist/code/tools/write.d.ts +3 -0
- package/dist/code/tools/write.d.ts.map +1 -0
- package/dist/code/tools/write.js +82 -0
- package/dist/code/tools/write.js.map +1 -0
- package/dist/core/agent-interface.d.ts +54 -0
- package/dist/core/agent-interface.d.ts.map +1 -0
- package/dist/core/agent-interface.js +8 -0
- package/dist/core/agent-interface.js.map +1 -0
- package/dist/core/client-agent.d.ts.map +1 -1
- package/dist/core/client-agent.js +26 -3
- package/dist/core/client-agent.js.map +1 -1
- package/dist/core/config.d.ts +144 -17
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +25 -1
- package/dist/core/config.js.map +1 -1
- package/dist/core/conversation-manager.d.ts +4 -1
- package/dist/core/conversation-manager.d.ts.map +1 -1
- package/dist/core/conversation-manager.js +47 -17
- package/dist/core/conversation-manager.js.map +1 -1
- package/dist/core/dual-agent.d.ts +3 -10
- package/dist/core/dual-agent.d.ts.map +1 -1
- package/dist/core/dual-agent.js +53 -119
- package/dist/core/dual-agent.js.map +1 -1
- package/dist/core/manager-agent.d.ts +30 -0
- package/dist/core/manager-agent.d.ts.map +1 -1
- package/dist/core/manager-agent.js +114 -14
- package/dist/core/manager-agent.js.map +1 -1
- package/dist/core/worker-agent.d.ts +12 -2
- package/dist/core/worker-agent.d.ts.map +1 -1
- package/dist/core/worker-agent.js +254 -67
- package/dist/core/worker-agent.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/cli/index.js +146 -25
- package/dist/interfaces/cli/index.js.map +1 -1
- package/dist/interfaces/cli/repl.d.ts +8 -2
- package/dist/interfaces/cli/repl.d.ts.map +1 -1
- package/dist/interfaces/cli/repl.js +39 -3
- package/dist/interfaces/cli/repl.js.map +1 -1
- package/dist/interfaces/cli/setup-wizard.d.ts.map +1 -1
- package/dist/interfaces/cli/setup-wizard.js +92 -0
- package/dist/interfaces/cli/setup-wizard.js.map +1 -1
- package/dist/interfaces/http/routes/chat.js +2 -2
- package/dist/interfaces/http/routes/chat.js.map +1 -1
- package/dist/interfaces/http/session-manager.d.ts +7 -4
- package/dist/interfaces/http/session-manager.d.ts.map +1 -1
- package/dist/interfaces/http/session-manager.js +56 -15
- package/dist/interfaces/http/session-manager.js.map +1 -1
- package/dist/models/base.d.ts +8 -0
- package/dist/models/base.d.ts.map +1 -1
- package/dist/models/harmony.d.ts +7 -1
- package/dist/models/harmony.d.ts.map +1 -1
- package/dist/models/harmony.js +21 -3
- package/dist/models/harmony.js.map +1 -1
- package/dist/models/krutrim.d.ts +31 -1
- package/dist/models/krutrim.d.ts.map +1 -1
- package/dist/models/krutrim.js +55 -11
- package/dist/models/krutrim.js.map +1 -1
- package/dist/models/orchestrator.d.ts +24 -0
- package/dist/models/orchestrator.d.ts.map +1 -1
- package/dist/models/orchestrator.js +40 -6
- package/dist/models/orchestrator.js.map +1 -1
- package/package.json +8 -5
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edit tool — multi-strategy text replacement with LSP diagnostics.
|
|
3
|
+
*
|
|
4
|
+
* The replacement strategies are ported from opencode (https://github.com/sst/opencode),
|
|
5
|
+
* which in turn sourced them from cline and gemini-cli.
|
|
6
|
+
*/
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import { createTwoFilesPatch, diffLines } from 'diff';
|
|
10
|
+
import { fileLock } from '../file-lock.js';
|
|
11
|
+
const MAX_DIAGNOSTICS = 20;
|
|
12
|
+
export const EditFileTool = {
|
|
13
|
+
name: 'edit_file',
|
|
14
|
+
description: `Replace an exact string in a file with a new string.
|
|
15
|
+
|
|
16
|
+
REQUIRED PARAMETERS — ALL THREE are mandatory, never omit any:
|
|
17
|
+
• file_path — absolute path to the file to edit
|
|
18
|
+
• old_string — the EXACT text to find (must match the file exactly)
|
|
19
|
+
• new_string — the REPLACEMENT text (what replaces old_string)
|
|
20
|
+
|
|
21
|
+
IMPORTANT: You MUST provide BOTH old_string AND new_string in every call.
|
|
22
|
+
Omitting new_string will fail with a validation error. new_string is never optional —
|
|
23
|
+
it is the text that replaces old_string in the file.
|
|
24
|
+
|
|
25
|
+
Rules:
|
|
26
|
+
- ALWAYS read the file with read_file before editing — never edit blindly.
|
|
27
|
+
- old_string must exactly match the file content (whitespace, indentation, line endings).
|
|
28
|
+
- Include enough surrounding context in old_string to make the match unique.
|
|
29
|
+
- If old_string is empty (""), the file is created with new_string as its content.
|
|
30
|
+
- The edit FAILS if old_string is not found in the file — check the content first.
|
|
31
|
+
- Use replace_all: true to replace every occurrence of old_string at once.
|
|
32
|
+
- Prefer small, targeted edits over rewriting large sections.
|
|
33
|
+
- LSP errors (if any) are reported after the edit so you can fix them immediately.
|
|
34
|
+
|
|
35
|
+
Returns a diff of the changes made, plus any LSP errors detected.`,
|
|
36
|
+
parameters: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
file_path: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
description: 'Absolute path to the file to edit',
|
|
42
|
+
},
|
|
43
|
+
old_string: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
description: 'The exact text to replace (empty string to create a new file)',
|
|
46
|
+
},
|
|
47
|
+
new_string: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
description: 'The replacement text',
|
|
50
|
+
},
|
|
51
|
+
replace_all: {
|
|
52
|
+
type: 'boolean',
|
|
53
|
+
description: 'Replace all occurrences of old_string (default: false)',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
required: ['file_path', 'old_string', 'new_string'],
|
|
57
|
+
},
|
|
58
|
+
async execute(args, ctx) {
|
|
59
|
+
const rawPath = args.file_path;
|
|
60
|
+
const filePath = path.isAbsolute(rawPath) ? rawPath : path.resolve(ctx.workspaceDir, rawPath);
|
|
61
|
+
const oldString = args.old_string;
|
|
62
|
+
const newString = args.new_string;
|
|
63
|
+
const replaceAll = args.replace_all ?? false;
|
|
64
|
+
if (oldString === newString) {
|
|
65
|
+
return 'Error: old_string and new_string are identical — no change made.';
|
|
66
|
+
}
|
|
67
|
+
return fileLock.withLock(filePath, async () => {
|
|
68
|
+
let contentBefore = '';
|
|
69
|
+
let contentAfter = '';
|
|
70
|
+
if (oldString === '') {
|
|
71
|
+
// Create / overwrite file
|
|
72
|
+
contentAfter = newString;
|
|
73
|
+
try {
|
|
74
|
+
const dir = path.dirname(filePath);
|
|
75
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
76
|
+
fs.writeFileSync(filePath, newString, 'utf-8');
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
return `Error writing file: ${e instanceof Error ? e.message : String(e)}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Read existing file
|
|
84
|
+
try {
|
|
85
|
+
contentBefore = fs.readFileSync(filePath, 'utf-8');
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return `Error: File not found: ${filePath}`;
|
|
89
|
+
}
|
|
90
|
+
// Normalize line endings for matching
|
|
91
|
+
const ending = detectLineEnding(contentBefore);
|
|
92
|
+
const normalizedOld = convertLineEnding(normalizeLineEndings(oldString), ending);
|
|
93
|
+
const normalizedNew = convertLineEnding(normalizeLineEndings(newString), ending);
|
|
94
|
+
let result;
|
|
95
|
+
try {
|
|
96
|
+
result = replace(contentBefore, normalizedOld, normalizedNew, replaceAll);
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
return `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
100
|
+
}
|
|
101
|
+
contentAfter = result;
|
|
102
|
+
try {
|
|
103
|
+
fs.writeFileSync(filePath, contentAfter, 'utf-8');
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
return `Error writing file: ${e instanceof Error ? e.message : String(e)}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Build diff
|
|
110
|
+
const diff = trimDiff(createTwoFilesPatch(filePath, filePath, normalizeLineEndings(contentBefore), normalizeLineEndings(contentAfter)));
|
|
111
|
+
// Count changes
|
|
112
|
+
let additions = 0;
|
|
113
|
+
let deletions = 0;
|
|
114
|
+
for (const change of diffLines(contentBefore, contentAfter)) {
|
|
115
|
+
if (change.added)
|
|
116
|
+
additions += change.count ?? 0;
|
|
117
|
+
if (change.removed)
|
|
118
|
+
deletions += change.count ?? 0;
|
|
119
|
+
}
|
|
120
|
+
// Notify LSP and collect diagnostics
|
|
121
|
+
let diagnosticsOutput = '';
|
|
122
|
+
try {
|
|
123
|
+
await ctx.lsp.touchFile(filePath);
|
|
124
|
+
const errors = ctx.lsp.getErrorsForFile(filePath);
|
|
125
|
+
if (errors) {
|
|
126
|
+
diagnosticsOutput = `\n\nLSP errors detected — please fix:\n<diagnostics file="${filePath}">\n${errors}\n</diagnostics>`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// LSP errors should not block the edit result
|
|
131
|
+
}
|
|
132
|
+
const relPath = path.relative(ctx.workspaceDir, filePath);
|
|
133
|
+
return `Edit applied to ${relPath} (+${additions}/-${deletions} lines).\n\n${diff}${diagnosticsOutput}`;
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
function levenshtein(a, b) {
|
|
138
|
+
if (a === '' || b === '')
|
|
139
|
+
return Math.max(a.length, b.length);
|
|
140
|
+
const matrix = Array.from({ length: a.length + 1 }, (_, i) => Array.from({ length: b.length + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)));
|
|
141
|
+
for (let i = 1; i <= a.length; i++) {
|
|
142
|
+
for (let j = 1; j <= b.length; j++) {
|
|
143
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
144
|
+
matrix[i][j] = Math.min(matrix[i - 1][j] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j - 1] + cost);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return matrix[a.length][b.length];
|
|
148
|
+
}
|
|
149
|
+
const SimpleReplacer = function* (_content, find) {
|
|
150
|
+
yield find;
|
|
151
|
+
};
|
|
152
|
+
const LineTrimmedReplacer = function* (content, find) {
|
|
153
|
+
const originalLines = content.split('\n');
|
|
154
|
+
const searchLines = find.split('\n');
|
|
155
|
+
if (searchLines[searchLines.length - 1] === '')
|
|
156
|
+
searchLines.pop();
|
|
157
|
+
for (let i = 0; i <= originalLines.length - searchLines.length; i++) {
|
|
158
|
+
let matches = true;
|
|
159
|
+
for (let j = 0; j < searchLines.length; j++) {
|
|
160
|
+
if (originalLines[i + j].trim() !== searchLines[j].trim()) {
|
|
161
|
+
matches = false;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (matches) {
|
|
166
|
+
let start = 0;
|
|
167
|
+
for (let k = 0; k < i; k++)
|
|
168
|
+
start += originalLines[k].length + 1;
|
|
169
|
+
let end = start;
|
|
170
|
+
for (let k = 0; k < searchLines.length; k++) {
|
|
171
|
+
end += originalLines[i + k].length;
|
|
172
|
+
if (k < searchLines.length - 1)
|
|
173
|
+
end += 1;
|
|
174
|
+
}
|
|
175
|
+
yield content.substring(start, end);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const SINGLE_CANDIDATE_THRESHOLD = 0.0;
|
|
180
|
+
const MULTIPLE_CANDIDATES_THRESHOLD = 0.3;
|
|
181
|
+
const BlockAnchorReplacer = function* (content, find) {
|
|
182
|
+
const originalLines = content.split('\n');
|
|
183
|
+
const searchLines = find.split('\n');
|
|
184
|
+
if (searchLines.length < 3)
|
|
185
|
+
return;
|
|
186
|
+
if (searchLines[searchLines.length - 1] === '')
|
|
187
|
+
searchLines.pop();
|
|
188
|
+
const firstLine = searchLines[0].trim();
|
|
189
|
+
const lastLine = searchLines[searchLines.length - 1].trim();
|
|
190
|
+
const candidates = [];
|
|
191
|
+
for (let i = 0; i < originalLines.length; i++) {
|
|
192
|
+
if (originalLines[i].trim() !== firstLine)
|
|
193
|
+
continue;
|
|
194
|
+
for (let j = i + 2; j < originalLines.length; j++) {
|
|
195
|
+
if (originalLines[j].trim() === lastLine) {
|
|
196
|
+
candidates.push({ startLine: i, endLine: j });
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (candidates.length === 0)
|
|
202
|
+
return;
|
|
203
|
+
const computeSimilarity = (startLine, endLine) => {
|
|
204
|
+
const actualSize = endLine - startLine + 1;
|
|
205
|
+
const linesToCheck = Math.min(searchLines.length - 2, actualSize - 2);
|
|
206
|
+
if (linesToCheck <= 0)
|
|
207
|
+
return 1.0;
|
|
208
|
+
let sim = 0;
|
|
209
|
+
for (let j = 1; j < searchLines.length - 1 && j < actualSize - 1; j++) {
|
|
210
|
+
const orig = originalLines[startLine + j].trim();
|
|
211
|
+
const srch = searchLines[j].trim();
|
|
212
|
+
const maxLen = Math.max(orig.length, srch.length);
|
|
213
|
+
if (maxLen === 0)
|
|
214
|
+
continue;
|
|
215
|
+
sim += (1 - levenshtein(orig, srch) / maxLen) / linesToCheck;
|
|
216
|
+
if (sim >= SINGLE_CANDIDATE_THRESHOLD)
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
return sim;
|
|
220
|
+
};
|
|
221
|
+
const extractMatch = (startLine, endLine) => {
|
|
222
|
+
let start = 0;
|
|
223
|
+
for (let k = 0; k < startLine; k++)
|
|
224
|
+
start += originalLines[k].length + 1;
|
|
225
|
+
let end = start;
|
|
226
|
+
for (let k = startLine; k <= endLine; k++) {
|
|
227
|
+
end += originalLines[k].length;
|
|
228
|
+
if (k < endLine)
|
|
229
|
+
end += 1;
|
|
230
|
+
}
|
|
231
|
+
return content.substring(start, end);
|
|
232
|
+
};
|
|
233
|
+
if (candidates.length === 1) {
|
|
234
|
+
const { startLine, endLine } = candidates[0];
|
|
235
|
+
if (computeSimilarity(startLine, endLine) >= SINGLE_CANDIDATE_THRESHOLD) {
|
|
236
|
+
yield extractMatch(startLine, endLine);
|
|
237
|
+
}
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
let best = null;
|
|
241
|
+
let maxSim = -1;
|
|
242
|
+
for (const { startLine, endLine } of candidates) {
|
|
243
|
+
const sim = computeSimilarity(startLine, endLine);
|
|
244
|
+
if (sim > maxSim) {
|
|
245
|
+
maxSim = sim;
|
|
246
|
+
best = { startLine, endLine };
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (maxSim >= MULTIPLE_CANDIDATES_THRESHOLD && best) {
|
|
250
|
+
yield extractMatch(best.startLine, best.endLine);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const WhitespaceNormalizedReplacer = function* (content, find) {
|
|
254
|
+
const norm = (t) => t.replace(/\s+/g, ' ').trim();
|
|
255
|
+
const normalizedFind = norm(find);
|
|
256
|
+
const lines = content.split('\n');
|
|
257
|
+
for (const line of lines) {
|
|
258
|
+
if (norm(line) === normalizedFind) {
|
|
259
|
+
yield line;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const normLine = norm(line);
|
|
263
|
+
if (normLine.includes(normalizedFind)) {
|
|
264
|
+
const words = find.trim().split(/\s+/);
|
|
265
|
+
if (words.length > 0) {
|
|
266
|
+
const pattern = words.map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('\\s+');
|
|
267
|
+
try {
|
|
268
|
+
const m = line.match(new RegExp(pattern));
|
|
269
|
+
if (m)
|
|
270
|
+
yield m[0];
|
|
271
|
+
}
|
|
272
|
+
catch { /* invalid regex */ }
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const findLines = find.split('\n');
|
|
277
|
+
if (findLines.length > 1) {
|
|
278
|
+
for (let i = 0; i <= lines.length - findLines.length; i++) {
|
|
279
|
+
const block = lines.slice(i, i + findLines.length);
|
|
280
|
+
if (norm(block.join('\n')) === normalizedFind)
|
|
281
|
+
yield block.join('\n');
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
const IndentationFlexibleReplacer = function* (content, find) {
|
|
286
|
+
const removeIndent = (text) => {
|
|
287
|
+
const lines = text.split('\n');
|
|
288
|
+
const nonEmpty = lines.filter((l) => l.trim().length > 0);
|
|
289
|
+
if (nonEmpty.length === 0)
|
|
290
|
+
return text;
|
|
291
|
+
const min = Math.min(...nonEmpty.map((l) => { const m = l.match(/^(\s*)/); return m ? m[1].length : 0; }));
|
|
292
|
+
return lines.map((l) => (l.trim().length === 0 ? l : l.slice(min))).join('\n');
|
|
293
|
+
};
|
|
294
|
+
const normalizedFind = removeIndent(find);
|
|
295
|
+
const contentLines = content.split('\n');
|
|
296
|
+
const findLines = find.split('\n');
|
|
297
|
+
for (let i = 0; i <= contentLines.length - findLines.length; i++) {
|
|
298
|
+
const block = contentLines.slice(i, i + findLines.length).join('\n');
|
|
299
|
+
if (removeIndent(block) === normalizedFind)
|
|
300
|
+
yield block;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const EscapeNormalizedReplacer = function* (content, find) {
|
|
304
|
+
const unescape = (s) => s.replace(/\\(n|t|r|'|"|`|\\|\n|\$)/g, (_, c) => {
|
|
305
|
+
switch (c) {
|
|
306
|
+
case 'n': return '\n';
|
|
307
|
+
case 't': return '\t';
|
|
308
|
+
case 'r': return '\r';
|
|
309
|
+
case '\\': return '\\';
|
|
310
|
+
case '\n': return '\n';
|
|
311
|
+
default: return c;
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
const unescapedFind = unescape(find);
|
|
315
|
+
if (content.includes(unescapedFind)) {
|
|
316
|
+
yield unescapedFind;
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const lines = content.split('\n');
|
|
320
|
+
const findLines = unescapedFind.split('\n');
|
|
321
|
+
for (let i = 0; i <= lines.length - findLines.length; i++) {
|
|
322
|
+
const block = lines.slice(i, i + findLines.length).join('\n');
|
|
323
|
+
if (unescape(block) === unescapedFind)
|
|
324
|
+
yield block;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
const TrimmedBoundaryReplacer = function* (content, find) {
|
|
328
|
+
const trimmedFind = find.trim();
|
|
329
|
+
if (trimmedFind === find)
|
|
330
|
+
return;
|
|
331
|
+
if (content.includes(trimmedFind)) {
|
|
332
|
+
yield trimmedFind;
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const lines = content.split('\n');
|
|
336
|
+
const findLines = find.split('\n');
|
|
337
|
+
for (let i = 0; i <= lines.length - findLines.length; i++) {
|
|
338
|
+
const block = lines.slice(i, i + findLines.length).join('\n');
|
|
339
|
+
if (block.trim() === trimmedFind)
|
|
340
|
+
yield block;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
const ContextAwareReplacer = function* (content, find) {
|
|
344
|
+
const findLines = find.split('\n');
|
|
345
|
+
if (findLines.length < 3)
|
|
346
|
+
return;
|
|
347
|
+
if (findLines[findLines.length - 1] === '')
|
|
348
|
+
findLines.pop();
|
|
349
|
+
const contentLines = content.split('\n');
|
|
350
|
+
const firstLine = findLines[0].trim();
|
|
351
|
+
const lastLine = findLines[findLines.length - 1].trim();
|
|
352
|
+
for (let i = 0; i < contentLines.length; i++) {
|
|
353
|
+
if (contentLines[i].trim() !== firstLine)
|
|
354
|
+
continue;
|
|
355
|
+
for (let j = i + 2; j < contentLines.length; j++) {
|
|
356
|
+
if (contentLines[j].trim() !== lastLine)
|
|
357
|
+
continue;
|
|
358
|
+
const blockLines = contentLines.slice(i, j + 1);
|
|
359
|
+
if (blockLines.length !== findLines.length)
|
|
360
|
+
break;
|
|
361
|
+
let matching = 0;
|
|
362
|
+
let total = 0;
|
|
363
|
+
for (let k = 1; k < blockLines.length - 1; k++) {
|
|
364
|
+
const b = blockLines[k].trim();
|
|
365
|
+
const f = findLines[k].trim();
|
|
366
|
+
if (b.length > 0 || f.length > 0) {
|
|
367
|
+
total++;
|
|
368
|
+
if (b === f)
|
|
369
|
+
matching++;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (total === 0 || matching / total >= 0.5) {
|
|
373
|
+
yield blockLines.join('\n');
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
const MultiOccurrenceReplacer = function* (content, find) {
|
|
381
|
+
let start = 0;
|
|
382
|
+
while (true) {
|
|
383
|
+
const idx = content.indexOf(find, start);
|
|
384
|
+
if (idx === -1)
|
|
385
|
+
break;
|
|
386
|
+
yield find;
|
|
387
|
+
start = idx + find.length;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
/** Apply the first matching replacement strategy. */
|
|
391
|
+
export function replace(content, oldString, newString, replaceAll = false) {
|
|
392
|
+
if (oldString === newString)
|
|
393
|
+
throw new Error('No changes: old_string and new_string are identical.');
|
|
394
|
+
let notFound = true;
|
|
395
|
+
for (const replacer of [
|
|
396
|
+
SimpleReplacer,
|
|
397
|
+
LineTrimmedReplacer,
|
|
398
|
+
BlockAnchorReplacer,
|
|
399
|
+
WhitespaceNormalizedReplacer,
|
|
400
|
+
IndentationFlexibleReplacer,
|
|
401
|
+
EscapeNormalizedReplacer,
|
|
402
|
+
TrimmedBoundaryReplacer,
|
|
403
|
+
ContextAwareReplacer,
|
|
404
|
+
MultiOccurrenceReplacer,
|
|
405
|
+
]) {
|
|
406
|
+
for (const search of replacer(content, oldString)) {
|
|
407
|
+
const idx = content.indexOf(search);
|
|
408
|
+
if (idx === -1)
|
|
409
|
+
continue;
|
|
410
|
+
notFound = false;
|
|
411
|
+
if (replaceAll)
|
|
412
|
+
return content.replaceAll(search, newString);
|
|
413
|
+
const lastIdx = content.lastIndexOf(search);
|
|
414
|
+
if (idx !== lastIdx)
|
|
415
|
+
continue; // ambiguous match
|
|
416
|
+
return content.substring(0, idx) + newString + content.substring(idx + search.length);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (notFound) {
|
|
420
|
+
throw new Error('Could not find old_string in the file. It must match exactly (whitespace, indentation, line endings).');
|
|
421
|
+
}
|
|
422
|
+
throw new Error('Found multiple matches for old_string. Provide more surrounding context to make it unique.');
|
|
423
|
+
}
|
|
424
|
+
// ─── Utilities ────────────────────────────────────────────────────────────────
|
|
425
|
+
function normalizeLineEndings(text) {
|
|
426
|
+
return text.replaceAll('\r\n', '\n');
|
|
427
|
+
}
|
|
428
|
+
function detectLineEnding(text) {
|
|
429
|
+
return text.includes('\r\n') ? '\r\n' : '\n';
|
|
430
|
+
}
|
|
431
|
+
function convertLineEnding(text, ending) {
|
|
432
|
+
return ending === '\n' ? text : text.replaceAll('\n', '\r\n');
|
|
433
|
+
}
|
|
434
|
+
function trimDiff(diff) {
|
|
435
|
+
const lines = diff.split('\n');
|
|
436
|
+
const contentLines = lines.filter((l) => (l.startsWith('+') || l.startsWith('-') || l.startsWith(' ')) &&
|
|
437
|
+
!l.startsWith('---') && !l.startsWith('+++'));
|
|
438
|
+
if (contentLines.length === 0)
|
|
439
|
+
return diff;
|
|
440
|
+
let min = Infinity;
|
|
441
|
+
for (const line of contentLines) {
|
|
442
|
+
const content = line.slice(1);
|
|
443
|
+
if (content.trim().length > 0) {
|
|
444
|
+
const m = content.match(/^(\s*)/);
|
|
445
|
+
if (m)
|
|
446
|
+
min = Math.min(min, m[1].length);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
if (min === Infinity || min === 0)
|
|
450
|
+
return diff;
|
|
451
|
+
return lines.map((line) => {
|
|
452
|
+
if ((line.startsWith('+') || line.startsWith('-') || line.startsWith(' ')) &&
|
|
453
|
+
!line.startsWith('---') && !line.startsWith('+++')) {
|
|
454
|
+
return line[0] + line.slice(1 + min);
|
|
455
|
+
}
|
|
456
|
+
return line;
|
|
457
|
+
}).join('\n');
|
|
458
|
+
}
|
|
459
|
+
//# sourceMappingURL=edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/code/tools/edit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,CAAC,MAAM,YAAY,GAAc;IACrC,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;kEAqBmD;IAEhE,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,SAAS,EAAE;gBACT,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,mCAAmC;aACjD;YACD,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,+DAA+D;aAC7E;YACD,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,sBAAsB;aACpC;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,wDAAwD;aACtE;SACF;QACD,QAAQ,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC;KACpD;IAED,KAAK,CAAC,OAAO,CAAC,I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AAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IACD,IAAI,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAE/C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACxB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACtE,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YACvD,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../../src/code/tools/glob.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,YAAY,CAAC;AAE7D,eAAO,MAAM,QAAQ,EAAE,SA8DtB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
export const GlobTool = {
|
|
4
|
+
name: 'glob',
|
|
5
|
+
description: `Find files matching a glob pattern.
|
|
6
|
+
|
|
7
|
+
Examples:
|
|
8
|
+
- "**/*.ts" — all TypeScript files
|
|
9
|
+
- "src/**/*.test.ts" — all test files under src/
|
|
10
|
+
- "*.json" — JSON files in the workspace root
|
|
11
|
+
|
|
12
|
+
Returns file paths relative to the workspace directory, sorted by modification time (newest first).`,
|
|
13
|
+
parameters: {
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
pattern: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: 'Glob pattern to match (e.g. "**/*.ts", "src/**/*.js")',
|
|
19
|
+
},
|
|
20
|
+
cwd: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'Directory to search in (default: workspace root)',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
required: ['pattern'],
|
|
26
|
+
},
|
|
27
|
+
async execute(args, ctx) {
|
|
28
|
+
const pattern = args.pattern;
|
|
29
|
+
const cwd = args.cwd
|
|
30
|
+
? (path.isAbsolute(args.cwd) ? args.cwd : path.resolve(ctx.workspaceDir, args.cwd))
|
|
31
|
+
: ctx.workspaceDir;
|
|
32
|
+
try {
|
|
33
|
+
// Use Node.js built-in glob (available in Node 22+) or fall back to manual walk
|
|
34
|
+
const { glob } = await import('glob');
|
|
35
|
+
const matches = await glob(pattern, {
|
|
36
|
+
cwd,
|
|
37
|
+
nodir: false,
|
|
38
|
+
ignore: ['**/node_modules/**', '**/.git/**', '**/dist/**', '**/.next/**'],
|
|
39
|
+
});
|
|
40
|
+
if (matches.length === 0) {
|
|
41
|
+
return `No files found matching pattern: ${pattern}`;
|
|
42
|
+
}
|
|
43
|
+
// Sort by mtime (newest first)
|
|
44
|
+
const withMtime = matches
|
|
45
|
+
.map((f) => {
|
|
46
|
+
try {
|
|
47
|
+
const stat = fs.statSync(path.join(cwd, f));
|
|
48
|
+
return { file: f, mtime: stat.mtimeMs };
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return { file: f, mtime: 0 };
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
.sort((a, b) => b.mtime - a.mtime);
|
|
55
|
+
return withMtime.map((f) => f.file).join('\n');
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
return `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|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