@lvce-editor/chat-tool-worker 9.9.0 → 9.10.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/dist/chatToolWorkerMain.js +179 -19
- package/package.json +1 -1
|
@@ -1538,7 +1538,7 @@ const normalizePattern = pattern => {
|
|
|
1538
1538
|
matchDirectories
|
|
1539
1539
|
};
|
|
1540
1540
|
};
|
|
1541
|
-
const joinUri = (baseUri, path) => {
|
|
1541
|
+
const joinUri$1 = (baseUri, path) => {
|
|
1542
1542
|
if (!path) {
|
|
1543
1543
|
return baseUri;
|
|
1544
1544
|
}
|
|
@@ -1572,13 +1572,13 @@ const getBaseUriError = args => {
|
|
|
1572
1572
|
return undefined;
|
|
1573
1573
|
};
|
|
1574
1574
|
const getDirectoryMatches = async (baseUri, globPart) => {
|
|
1575
|
-
const dirUri = joinUri(baseUri, globPart);
|
|
1575
|
+
const dirUri = joinUri$1(baseUri, globPart);
|
|
1576
1576
|
const entries = await readDirWithFileTypes(dirUri);
|
|
1577
1577
|
return entries.map(entry => globPart ? `${globPart}/${entry.name}` : entry.name);
|
|
1578
1578
|
};
|
|
1579
1579
|
const getRecursiveMatches = async (baseUri, baseDir, normalizedPattern) => {
|
|
1580
1580
|
const matches = [];
|
|
1581
|
-
const baseDirUri = joinUri(baseUri, baseDir);
|
|
1581
|
+
const baseDirUri = joinUri$1(baseUri, baseDir);
|
|
1582
1582
|
await traverseDirectory(baseDirUri, '', async (relativePath, entry) => {
|
|
1583
1583
|
if (entry.type !== File) {
|
|
1584
1584
|
return;
|
|
@@ -1591,7 +1591,7 @@ const getRecursiveMatches = async (baseUri, baseDir, normalizedPattern) => {
|
|
|
1591
1591
|
return matches;
|
|
1592
1592
|
};
|
|
1593
1593
|
const getDirectMatches = async (baseUri, baseDir, normalizedPattern) => {
|
|
1594
|
-
const dirUri = joinUri(baseUri, baseDir);
|
|
1594
|
+
const dirUri = joinUri$1(baseUri, baseDir);
|
|
1595
1595
|
const entries = await readDirWithFileTypes(dirUri);
|
|
1596
1596
|
const matches = [];
|
|
1597
1597
|
for (const entry of entries) {
|
|
@@ -2199,6 +2199,152 @@ const executeRunInTerminalTool = async (args, _options) => {
|
|
|
2199
2199
|
}
|
|
2200
2200
|
};
|
|
2201
2201
|
|
|
2202
|
+
const WORD_CHARACTER_REGEX = /\w/;
|
|
2203
|
+
const isWholeWordMatch = (text, startIndex, matchLength) => {
|
|
2204
|
+
const beforeChar = startIndex > 0 ? text[startIndex - 1] : ' ';
|
|
2205
|
+
const afterChar = startIndex + matchLength < text.length ? text[startIndex + matchLength] : ' ';
|
|
2206
|
+
return !WORD_CHARACTER_REGEX.test(beforeChar) && !WORD_CHARACTER_REGEX.test(afterChar);
|
|
2207
|
+
};
|
|
2208
|
+
const createSearchResult = (uri, lineNumber, column, text) => {
|
|
2209
|
+
return {
|
|
2210
|
+
column,
|
|
2211
|
+
line: lineNumber,
|
|
2212
|
+
text,
|
|
2213
|
+
uri
|
|
2214
|
+
};
|
|
2215
|
+
};
|
|
2216
|
+
const searchPlainText = (text, uri, options) => {
|
|
2217
|
+
const results = [];
|
|
2218
|
+
const lines = text.split('\n');
|
|
2219
|
+
const needle = options.matchCase ? options.value : options.value.toLowerCase();
|
|
2220
|
+
if (needle === '') {
|
|
2221
|
+
return results;
|
|
2222
|
+
}
|
|
2223
|
+
for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
|
|
2224
|
+
const lineText = lines[lineNumber];
|
|
2225
|
+
const searchLineText = options.matchCase ? lineText : lineText.toLowerCase();
|
|
2226
|
+
let searchStartIndex = 0;
|
|
2227
|
+
while (searchStartIndex <= searchLineText.length) {
|
|
2228
|
+
const matchIndex = searchLineText.indexOf(needle, searchStartIndex);
|
|
2229
|
+
if (matchIndex === -1) {
|
|
2230
|
+
break;
|
|
2231
|
+
}
|
|
2232
|
+
if (!options.matchWholeWord || isWholeWordMatch(lineText, matchIndex, needle.length)) {
|
|
2233
|
+
results.push(createSearchResult(uri, lineNumber + 1, matchIndex + 1, lineText));
|
|
2234
|
+
}
|
|
2235
|
+
searchStartIndex = matchIndex + needle.length;
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
return results;
|
|
2239
|
+
};
|
|
2240
|
+
const searchRegExp = (text, uri, options) => {
|
|
2241
|
+
const results = [];
|
|
2242
|
+
const lines = text.split('\n');
|
|
2243
|
+
const flags = options.matchCase ? 'g' : 'gi';
|
|
2244
|
+
const regex = new RegExp(options.value, flags);
|
|
2245
|
+
for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
|
|
2246
|
+
const lineText = lines[lineNumber];
|
|
2247
|
+
regex.lastIndex = 0;
|
|
2248
|
+
let match;
|
|
2249
|
+
while ((match = regex.exec(lineText)) !== null) {
|
|
2250
|
+
const matchedText = match[0];
|
|
2251
|
+
if (matchedText !== '' && (!options.matchWholeWord || isWholeWordMatch(lineText, match.index, matchedText.length))) {
|
|
2252
|
+
results.push(createSearchResult(uri, lineNumber + 1, match.index + 1, lineText));
|
|
2253
|
+
}
|
|
2254
|
+
if (matchedText === '') {
|
|
2255
|
+
regex.lastIndex++;
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
return results;
|
|
2260
|
+
};
|
|
2261
|
+
const searchInText = (text, uri, options) => {
|
|
2262
|
+
if (options.isRegex) {
|
|
2263
|
+
return searchRegExp(text, uri, options);
|
|
2264
|
+
}
|
|
2265
|
+
return searchPlainText(text, uri, options);
|
|
2266
|
+
};
|
|
2267
|
+
|
|
2268
|
+
const joinUri = (baseUri, path) => {
|
|
2269
|
+
if (!path) {
|
|
2270
|
+
return baseUri;
|
|
2271
|
+
}
|
|
2272
|
+
return baseUri.endsWith('/') ? `${baseUri}${path}` : `${baseUri}/${path}`;
|
|
2273
|
+
};
|
|
2274
|
+
const isExcludedPath = (path, exclude) => {
|
|
2275
|
+
return exclude.some(pattern => matchesGlobPattern(path, pattern));
|
|
2276
|
+
};
|
|
2277
|
+
const readDirEntries = async (uri, relativePath) => {
|
|
2278
|
+
try {
|
|
2279
|
+
return await readDirWithFileTypes(uri);
|
|
2280
|
+
} catch (error) {
|
|
2281
|
+
if (relativePath === '') {
|
|
2282
|
+
throw error;
|
|
2283
|
+
}
|
|
2284
|
+
return undefined;
|
|
2285
|
+
}
|
|
2286
|
+
};
|
|
2287
|
+
const searchFileContents = async (entryUri, searchOptions) => {
|
|
2288
|
+
try {
|
|
2289
|
+
const content = await readFile$1(entryUri);
|
|
2290
|
+
return searchInText(content, entryUri, searchOptions);
|
|
2291
|
+
} catch {
|
|
2292
|
+
// Ignore unreadable files and continue with remaining matches.
|
|
2293
|
+
return [];
|
|
2294
|
+
}
|
|
2295
|
+
};
|
|
2296
|
+
const visitDirEntry = async (uri, relativePath, dirent, searchOptions, visit) => {
|
|
2297
|
+
const entryPath = relativePath ? `${relativePath}/${dirent.name}` : dirent.name;
|
|
2298
|
+
if (isExcludedPath(entryPath, searchOptions.exclude)) {
|
|
2299
|
+
return [];
|
|
2300
|
+
}
|
|
2301
|
+
const entryUri = joinUri(uri, dirent.name);
|
|
2302
|
+
if (dirent.type === Directory) {
|
|
2303
|
+
if (!shouldExcludeDir(dirent.name)) {
|
|
2304
|
+
await visit(entryUri, entryPath);
|
|
2305
|
+
}
|
|
2306
|
+
return [];
|
|
2307
|
+
}
|
|
2308
|
+
if (dirent.type === File) {
|
|
2309
|
+
return searchFileContents(entryUri, searchOptions);
|
|
2310
|
+
}
|
|
2311
|
+
return [];
|
|
2312
|
+
};
|
|
2313
|
+
const sortSearchResults = results => {
|
|
2314
|
+
return results.toSorted((left, right) => {
|
|
2315
|
+
const uriComparison = left.uri.localeCompare(right.uri);
|
|
2316
|
+
if (uriComparison !== 0) {
|
|
2317
|
+
return uriComparison;
|
|
2318
|
+
}
|
|
2319
|
+
if (left.line !== right.line) {
|
|
2320
|
+
return left.line - right.line;
|
|
2321
|
+
}
|
|
2322
|
+
if (left.column !== right.column) {
|
|
2323
|
+
return left.column - right.column;
|
|
2324
|
+
}
|
|
2325
|
+
return left.text.localeCompare(right.text);
|
|
2326
|
+
});
|
|
2327
|
+
};
|
|
2328
|
+
const searchTextManual = async (workspaceUri, searchOptions) => {
|
|
2329
|
+
const results = [];
|
|
2330
|
+
const visited = new Set();
|
|
2331
|
+
const visit = async (uri, relativePath) => {
|
|
2332
|
+
if (visited.has(uri)) {
|
|
2333
|
+
return;
|
|
2334
|
+
}
|
|
2335
|
+
visited.add(uri);
|
|
2336
|
+
const dirents = await readDirEntries(uri, relativePath);
|
|
2337
|
+
if (!dirents) {
|
|
2338
|
+
return;
|
|
2339
|
+
}
|
|
2340
|
+
for (const dirent of dirents) {
|
|
2341
|
+
results.push(...(await visitDirEntry(uri, relativePath, dirent, searchOptions, visit)));
|
|
2342
|
+
}
|
|
2343
|
+
};
|
|
2344
|
+
await visit(workspaceUri, '');
|
|
2345
|
+
return sortSearchResults(results);
|
|
2346
|
+
};
|
|
2347
|
+
|
|
2202
2348
|
const getSearchOptions = args => {
|
|
2203
2349
|
const {
|
|
2204
2350
|
options
|
|
@@ -2228,6 +2374,17 @@ const getSearchOptions = args => {
|
|
|
2228
2374
|
value
|
|
2229
2375
|
};
|
|
2230
2376
|
};
|
|
2377
|
+
const validateRegex = searchOptions => {
|
|
2378
|
+
if (!searchOptions.isRegex) {
|
|
2379
|
+
return undefined;
|
|
2380
|
+
}
|
|
2381
|
+
try {
|
|
2382
|
+
new RegExp(searchOptions.value);
|
|
2383
|
+
return undefined;
|
|
2384
|
+
} catch {
|
|
2385
|
+
return 'Invalid argument: options.value must be a valid regular expression.';
|
|
2386
|
+
}
|
|
2387
|
+
};
|
|
2231
2388
|
const executeSearchTextTool = async (args, _options) => {
|
|
2232
2389
|
const searchOptions = getSearchOptions(args);
|
|
2233
2390
|
if (!searchOptions) {
|
|
@@ -2235,21 +2392,21 @@ const executeSearchTextTool = async (args, _options) => {
|
|
|
2235
2392
|
error: 'Invalid argument: options must include value (string), isRegex (boolean), matchCase (boolean), matchWholeWord (boolean), and exclude (string[]).'
|
|
2236
2393
|
};
|
|
2237
2394
|
}
|
|
2238
|
-
const
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
}
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
}
|
|
2395
|
+
const regexError = validateRegex(searchOptions);
|
|
2396
|
+
if (regexError) {
|
|
2397
|
+
return {
|
|
2398
|
+
error: regexError
|
|
2399
|
+
};
|
|
2400
|
+
}
|
|
2401
|
+
try {
|
|
2402
|
+
const workspaceUri = await getWorkspacePath();
|
|
2403
|
+
const results = await searchTextManual(workspaceUri, searchOptions);
|
|
2404
|
+
return {
|
|
2405
|
+
results
|
|
2406
|
+
};
|
|
2407
|
+
} catch (error) {
|
|
2408
|
+
return getToolErrorPayload(error);
|
|
2409
|
+
}
|
|
2253
2410
|
};
|
|
2254
2411
|
|
|
2255
2412
|
const placeholderResponse = 'Hello From Sub agent - not yet implemented';
|
|
@@ -2432,6 +2589,9 @@ const executeWriteFileTool = async (args, _options) => {
|
|
|
2432
2589
|
};
|
|
2433
2590
|
|
|
2434
2591
|
const parseToolArguments = rawArguments => {
|
|
2592
|
+
if (typeof rawArguments !== 'string' && (!rawArguments || typeof rawArguments !== 'object')) {
|
|
2593
|
+
return {};
|
|
2594
|
+
}
|
|
2435
2595
|
if (typeof rawArguments !== 'string') {
|
|
2436
2596
|
return rawArguments;
|
|
2437
2597
|
}
|