@lvce-editor/chat-tool-worker 9.5.0 → 9.7.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 +183 -117
- package/package.json +1 -1
|
@@ -1169,6 +1169,9 @@ const readFile$1 = async uri => {
|
|
|
1169
1169
|
const writeFile$1 = async (uri, content) => {
|
|
1170
1170
|
return invoke$2('FileSystem.writeFile', uri, content);
|
|
1171
1171
|
};
|
|
1172
|
+
const mkdir = async uri => {
|
|
1173
|
+
return invoke$2('FileSystem.mkdir', uri);
|
|
1174
|
+
};
|
|
1172
1175
|
const exists = async uri => {
|
|
1173
1176
|
return invoke$2('FileSystem.exists', uri);
|
|
1174
1177
|
};
|
|
@@ -1261,10 +1264,9 @@ const executeCreateDirectoryTool = async (args, _options) => {
|
|
|
1261
1264
|
return getInvalidUrlErrorPayload();
|
|
1262
1265
|
}
|
|
1263
1266
|
try {
|
|
1264
|
-
await
|
|
1267
|
+
await mkdir(uri);
|
|
1265
1268
|
return {
|
|
1266
|
-
ok: true
|
|
1267
|
-
uri
|
|
1269
|
+
ok: true
|
|
1268
1270
|
};
|
|
1269
1271
|
} catch (error) {
|
|
1270
1272
|
return {
|
|
@@ -1366,6 +1368,27 @@ const MULTIPLE_SLASHES_REGEX$1 = /\/+/g;
|
|
|
1366
1368
|
const escapeRegExp = str => {
|
|
1367
1369
|
return str.replaceAll(REGEX_SPECIAL_CHARS_REGEX, '\\$&');
|
|
1368
1370
|
};
|
|
1371
|
+
const getCharacterClassRegex = (classContents, negated) => {
|
|
1372
|
+
if (negated) {
|
|
1373
|
+
return `[^${escapeRegExp(classContents)}]`;
|
|
1374
|
+
}
|
|
1375
|
+
return `[${classContents.replaceAll('\\', '\\\\')}]`;
|
|
1376
|
+
};
|
|
1377
|
+
const readCharacterClass = (segment, index) => {
|
|
1378
|
+
let classIndex = index + 1;
|
|
1379
|
+
const negated = segment[classIndex] === '!';
|
|
1380
|
+
if (negated) {
|
|
1381
|
+
classIndex++;
|
|
1382
|
+
}
|
|
1383
|
+
const closingIndex = segment.indexOf(']', classIndex);
|
|
1384
|
+
if (closingIndex === -1) {
|
|
1385
|
+
return undefined;
|
|
1386
|
+
}
|
|
1387
|
+
return {
|
|
1388
|
+
nextIndex: closingIndex + 1,
|
|
1389
|
+
regex: getCharacterClassRegex(segment.slice(classIndex, closingIndex), negated)
|
|
1390
|
+
};
|
|
1391
|
+
};
|
|
1369
1392
|
|
|
1370
1393
|
/*
|
|
1371
1394
|
* Convert a glob pattern to a regex, but only for segments between separators
|
|
@@ -1375,60 +1398,58 @@ const segmentToRegex = segment => {
|
|
|
1375
1398
|
let i = 0;
|
|
1376
1399
|
while (i < segment.length) {
|
|
1377
1400
|
const char = segment[i];
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
i++;
|
|
1383
|
-
break;
|
|
1384
|
-
}
|
|
1385
|
-
case '[':
|
|
1386
|
-
{
|
|
1387
|
-
let j = i + 1;
|
|
1388
|
-
let negated = false;
|
|
1389
|
-
if (j < segment.length && segment[j] === '!') {
|
|
1390
|
-
negated = true;
|
|
1391
|
-
j++;
|
|
1392
|
-
}
|
|
1393
|
-
let classStr = '';
|
|
1394
|
-
while (j < segment.length && segment[j] !== ']') {
|
|
1395
|
-
classStr += segment[j];
|
|
1396
|
-
j++;
|
|
1397
|
-
}
|
|
1398
|
-
if (j < segment.length) {
|
|
1399
|
-
if (negated) {
|
|
1400
|
-
regexStr += `[^${escapeRegExp(classStr)}]`;
|
|
1401
|
-
} else {
|
|
1402
|
-
regexStr += `[${classStr.replaceAll('\\', '\\\\')}]`;
|
|
1403
|
-
}
|
|
1404
|
-
i = j + 1;
|
|
1405
|
-
} else {
|
|
1406
|
-
regexStr += escapeRegExp(char);
|
|
1407
|
-
i++;
|
|
1408
|
-
}
|
|
1409
|
-
break;
|
|
1410
|
-
}
|
|
1411
|
-
case '*':
|
|
1412
|
-
{
|
|
1413
|
-
regexStr += '[^/]*';
|
|
1414
|
-
i++;
|
|
1415
|
-
break;
|
|
1416
|
-
}
|
|
1417
|
-
default:
|
|
1418
|
-
{
|
|
1419
|
-
regexStr += escapeRegExp(char);
|
|
1420
|
-
i++;
|
|
1421
|
-
}
|
|
1401
|
+
if (char === '?') {
|
|
1402
|
+
regexStr += '[^/]';
|
|
1403
|
+
i++;
|
|
1404
|
+
continue;
|
|
1422
1405
|
}
|
|
1406
|
+
if (char === '*') {
|
|
1407
|
+
regexStr += '[^/]*';
|
|
1408
|
+
i++;
|
|
1409
|
+
continue;
|
|
1410
|
+
}
|
|
1411
|
+
if (char === '[') {
|
|
1412
|
+
const characterClass = readCharacterClass(segment, i);
|
|
1413
|
+
if (characterClass) {
|
|
1414
|
+
regexStr += characterClass.regex;
|
|
1415
|
+
i = characterClass.nextIndex;
|
|
1416
|
+
continue;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
regexStr += escapeRegExp(char);
|
|
1420
|
+
i++;
|
|
1423
1421
|
}
|
|
1424
1422
|
return new RegExp(`^${regexStr}$`);
|
|
1425
1423
|
};
|
|
1426
|
-
const
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1424
|
+
const normalizePath = path => {
|
|
1425
|
+
return path.replaceAll('\\', '/').replaceAll(LEADING_DOT_SLASH_REGEX$1, '');
|
|
1426
|
+
};
|
|
1427
|
+
const normalizePattern$1 = pattern => {
|
|
1428
|
+
const normalizedPattern = pattern.replaceAll('\\', '/').replaceAll(LEADING_DOT_SLASH_REGEX$1, '').replaceAll(MULTIPLE_SLASHES_REGEX$1, '/');
|
|
1429
|
+
if (!normalizedPattern.endsWith('/')) {
|
|
1430
|
+
return normalizedPattern;
|
|
1431
1431
|
}
|
|
1432
|
+
return normalizedPattern.slice(0, -1) + '/*';
|
|
1433
|
+
};
|
|
1434
|
+
const matchesSinglePatternPart = (pathPart, patternPart) => {
|
|
1435
|
+
return segmentToRegex(patternPart).test(pathPart);
|
|
1436
|
+
};
|
|
1437
|
+
const matchesEmbeddedDoubleStarPattern = (pathParts, patternParts, pathIdx, patternIdx) => {
|
|
1438
|
+
const patternPart = patternParts[patternIdx];
|
|
1439
|
+
const pathPart = pathParts[pathIdx];
|
|
1440
|
+
return matchesSinglePatternPart(pathPart, patternPart.replace('**', '')) && matchesPatternParts(pathParts, patternParts, pathIdx + 1, patternIdx + 1);
|
|
1441
|
+
};
|
|
1442
|
+
const matchesDoubleStarPattern = (pathParts, patternParts, pathIdx, patternIdx) => {
|
|
1443
|
+
for (let i = pathIdx; i <= pathParts.length; i++) {
|
|
1444
|
+
if (matchesPatternParts(pathParts, patternParts, i, patternIdx + 1)) {
|
|
1445
|
+
return true;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
return false;
|
|
1449
|
+
};
|
|
1450
|
+
const matchesGlobPattern = (path, pattern) => {
|
|
1451
|
+
const normalizedPath = normalizePath(path);
|
|
1452
|
+
const normalizedPattern = normalizePattern$1(pattern);
|
|
1432
1453
|
const patternParts = normalizedPattern.split('/');
|
|
1433
1454
|
const pathParts = normalizedPath.split('/');
|
|
1434
1455
|
return matchesPatternParts(pathParts, patternParts, 0, 0);
|
|
@@ -1441,34 +1462,17 @@ const matchesPatternParts = (pathParts, patternParts, pathIdx, patternIdx) => {
|
|
|
1441
1462
|
return false;
|
|
1442
1463
|
}
|
|
1443
1464
|
const patternPart = patternParts[patternIdx];
|
|
1444
|
-
if (patternPart === undefined) {
|
|
1445
|
-
return false;
|
|
1446
|
-
}
|
|
1447
1465
|
if (patternPart === '**') {
|
|
1448
|
-
|
|
1449
|
-
if (matchesPatternParts(pathParts, patternParts, i, patternIdx + 1)) {
|
|
1450
|
-
return true;
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
return false;
|
|
1466
|
+
return matchesDoubleStarPattern(pathParts, patternParts, pathIdx, patternIdx);
|
|
1454
1467
|
}
|
|
1455
1468
|
if (pathIdx === pathParts.length) {
|
|
1456
1469
|
return false;
|
|
1457
1470
|
}
|
|
1458
1471
|
if (patternPart.includes('**')) {
|
|
1459
|
-
|
|
1460
|
-
const pathPart = pathParts[pathIdx];
|
|
1461
|
-
if (pathPart !== undefined && regex.test(pathPart)) {
|
|
1462
|
-
return matchesPatternParts(pathParts, patternParts, pathIdx + 1, patternIdx + 1);
|
|
1463
|
-
}
|
|
1464
|
-
return false;
|
|
1472
|
+
return matchesEmbeddedDoubleStarPattern(pathParts, patternParts, pathIdx, patternIdx);
|
|
1465
1473
|
}
|
|
1466
|
-
const regex = segmentToRegex(patternPart);
|
|
1467
1474
|
const pathPart = pathParts[pathIdx];
|
|
1468
|
-
|
|
1469
|
-
return matchesPatternParts(pathParts, patternParts, pathIdx + 1, patternIdx + 1);
|
|
1470
|
-
}
|
|
1471
|
-
return false;
|
|
1475
|
+
return matchesSinglePatternPart(pathPart, patternPart) && matchesPatternParts(pathParts, patternParts, pathIdx + 1, patternIdx + 1);
|
|
1472
1476
|
};
|
|
1473
1477
|
|
|
1474
1478
|
// cspell:ignore venv
|
|
@@ -1540,59 +1544,99 @@ const joinUri = (baseUri, path) => {
|
|
|
1540
1544
|
}
|
|
1541
1545
|
return baseUri.endsWith('/') ? `${baseUri}${path}` : `${baseUri}/${path}`;
|
|
1542
1546
|
};
|
|
1543
|
-
const
|
|
1547
|
+
const isPlaceholderWorkspaceUri = baseUri => {
|
|
1548
|
+
return baseUri === PLACEHOLDER_WORKSPACE_URI || baseUri.startsWith(`${PLACEHOLDER_WORKSPACE_URI}/`);
|
|
1549
|
+
};
|
|
1550
|
+
const getPattern = args => {
|
|
1544
1551
|
const pattern = typeof args.pattern === 'string' ? args.pattern : '';
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1552
|
+
return pattern || undefined;
|
|
1553
|
+
};
|
|
1554
|
+
const getBaseUri = args => {
|
|
1555
|
+
const baseUri = typeof args.baseUri === 'string' ? args.baseUri : '';
|
|
1556
|
+
if (!baseUri || !isAbsoluteUri(baseUri) || isPlaceholderWorkspaceUri(baseUri)) {
|
|
1557
|
+
return undefined;
|
|
1549
1558
|
}
|
|
1559
|
+
return baseUri;
|
|
1560
|
+
};
|
|
1561
|
+
const getBaseUriError = args => {
|
|
1550
1562
|
const baseUri = typeof args.baseUri === 'string' ? args.baseUri : '';
|
|
1551
1563
|
if (!baseUri || !isAbsoluteUri(baseUri)) {
|
|
1552
1564
|
return getInvalidUriErrorPayload('baseUri');
|
|
1553
1565
|
}
|
|
1554
|
-
if (baseUri
|
|
1566
|
+
if (isPlaceholderWorkspaceUri(baseUri)) {
|
|
1555
1567
|
return {
|
|
1556
1568
|
baseUri,
|
|
1557
1569
|
error: 'Invalid argument: baseUri must be a real workspace folder URI. Call getWorkspaceUri first and use the returned workspaceUri value.'
|
|
1558
1570
|
};
|
|
1559
1571
|
}
|
|
1572
|
+
return undefined;
|
|
1573
|
+
};
|
|
1574
|
+
const getDirectoryMatches = async (baseUri, globPart) => {
|
|
1575
|
+
const dirUri = joinUri(baseUri, globPart);
|
|
1576
|
+
const entries = await readDirWithFileTypes(dirUri);
|
|
1577
|
+
return entries.map(entry => globPart ? `${globPart}/${entry.name}` : entry.name);
|
|
1578
|
+
};
|
|
1579
|
+
const getRecursiveMatches = async (baseUri, baseDir, normalizedPattern) => {
|
|
1580
|
+
const matches = [];
|
|
1581
|
+
const baseDirUri = joinUri(baseUri, baseDir);
|
|
1582
|
+
await traverseDirectory(baseDirUri, '', async (relativePath, entry) => {
|
|
1583
|
+
if (entry.type !== File) {
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1586
|
+
const fullPath = baseDir ? `${baseDir}/${relativePath}` : relativePath;
|
|
1587
|
+
if (matchesGlobPattern(fullPath, normalizedPattern)) {
|
|
1588
|
+
matches.push(fullPath);
|
|
1589
|
+
}
|
|
1590
|
+
});
|
|
1591
|
+
return matches;
|
|
1592
|
+
};
|
|
1593
|
+
const getDirectMatches = async (baseUri, baseDir, normalizedPattern) => {
|
|
1594
|
+
const dirUri = joinUri(baseUri, baseDir);
|
|
1595
|
+
const entries = await readDirWithFileTypes(dirUri);
|
|
1596
|
+
const matches = [];
|
|
1597
|
+
for (const entry of entries) {
|
|
1598
|
+
const fullPath = baseDir ? `${baseDir}/${entry.name}` : entry.name;
|
|
1599
|
+
if (matchesGlobPattern(fullPath, normalizedPattern)) {
|
|
1600
|
+
matches.push(fullPath);
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
return matches;
|
|
1604
|
+
};
|
|
1605
|
+
const getMatches = async (baseUri, pattern) => {
|
|
1560
1606
|
const normalizedPattern = normalizeInputPattern(pattern);
|
|
1561
1607
|
const {
|
|
1562
1608
|
baseDir,
|
|
1563
1609
|
globPart,
|
|
1564
1610
|
matchDirectories
|
|
1565
1611
|
} = normalizePattern(pattern);
|
|
1566
|
-
|
|
1612
|
+
if (matchDirectories) {
|
|
1613
|
+
return getDirectoryMatches(baseUri, globPart);
|
|
1614
|
+
}
|
|
1615
|
+
if (globPart.includes('**')) {
|
|
1616
|
+
return getRecursiveMatches(baseUri, baseDir, normalizedPattern);
|
|
1617
|
+
}
|
|
1618
|
+
return getDirectMatches(baseUri, baseDir, normalizedPattern);
|
|
1619
|
+
};
|
|
1620
|
+
const sortMatches = matches => {
|
|
1621
|
+
return matches.toSorted((left, right) => left.localeCompare(right));
|
|
1622
|
+
};
|
|
1623
|
+
const executeGlobTool = async (args, _options) => {
|
|
1624
|
+
const pattern = getPattern(args);
|
|
1625
|
+
if (!pattern) {
|
|
1626
|
+
return {
|
|
1627
|
+
error: 'Invalid argument: pattern must be a non-empty string.'
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
const baseUriError = getBaseUriError(args);
|
|
1631
|
+
if (baseUriError) {
|
|
1632
|
+
return baseUriError;
|
|
1633
|
+
}
|
|
1634
|
+
const baseUri = getBaseUri(args);
|
|
1635
|
+
if (!baseUri) {
|
|
1636
|
+
return getInvalidUriErrorPayload('baseUri');
|
|
1637
|
+
}
|
|
1567
1638
|
try {
|
|
1568
|
-
|
|
1569
|
-
const dirUri = joinUri(baseUri, globPart);
|
|
1570
|
-
const entries = await readDirWithFileTypes(dirUri);
|
|
1571
|
-
for (const entry of entries) {
|
|
1572
|
-
matches.push(globPart ? `${globPart}/${entry.name}` : entry.name);
|
|
1573
|
-
}
|
|
1574
|
-
} else if (globPart.includes('**')) {
|
|
1575
|
-
const baseDirUri = joinUri(baseUri, baseDir);
|
|
1576
|
-
await traverseDirectory(baseDirUri, '', async (relativePath, entry) => {
|
|
1577
|
-
if (entry.type !== File) {
|
|
1578
|
-
return;
|
|
1579
|
-
}
|
|
1580
|
-
const fullPath = baseDir ? `${baseDir}/${relativePath}` : relativePath;
|
|
1581
|
-
if (matchesGlobPattern(fullPath, normalizedPattern)) {
|
|
1582
|
-
matches.push(fullPath);
|
|
1583
|
-
}
|
|
1584
|
-
});
|
|
1585
|
-
} else {
|
|
1586
|
-
const dirUri = joinUri(baseUri, baseDir);
|
|
1587
|
-
const entries = await readDirWithFileTypes(dirUri);
|
|
1588
|
-
for (const entry of entries) {
|
|
1589
|
-
const fullPath = baseDir ? `${baseDir}/${entry.name}` : entry.name;
|
|
1590
|
-
if (matchesGlobPattern(fullPath, normalizedPattern)) {
|
|
1591
|
-
matches.push(fullPath);
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
matches.sort();
|
|
1639
|
+
const matches = sortMatches(await getMatches(baseUri, pattern));
|
|
1596
1640
|
return {
|
|
1597
1641
|
paths: matches,
|
|
1598
1642
|
pattern
|
|
@@ -1645,10 +1689,7 @@ const formatJsonMatches = matches => {
|
|
|
1645
1689
|
matchesFound: matches.length > 0
|
|
1646
1690
|
};
|
|
1647
1691
|
};
|
|
1648
|
-
const
|
|
1649
|
-
if (outputFormat === 'json') {
|
|
1650
|
-
return formatJsonMatches(matches);
|
|
1651
|
-
}
|
|
1692
|
+
const formatStringMatches = (matches, outputFormat) => {
|
|
1652
1693
|
if (matches.length === 0) {
|
|
1653
1694
|
return 'No matches found.';
|
|
1654
1695
|
}
|
|
@@ -1659,6 +1700,16 @@ const formatGrepMatches = (matches, outputFormat) => {
|
|
|
1659
1700
|
return formatTextMatches(matches);
|
|
1660
1701
|
}
|
|
1661
1702
|
};
|
|
1703
|
+
const getMatchesFormatter = outputFormat => {
|
|
1704
|
+
if (outputFormat === 'json') {
|
|
1705
|
+
return formatJsonMatches;
|
|
1706
|
+
}
|
|
1707
|
+
return matches => formatStringMatches(matches, outputFormat);
|
|
1708
|
+
};
|
|
1709
|
+
const formatGrepMatches = (matches, outputFormat) => {
|
|
1710
|
+
const formatter = getMatchesFormatter(outputFormat);
|
|
1711
|
+
return formatter(matches);
|
|
1712
|
+
};
|
|
1662
1713
|
|
|
1663
1714
|
const formatSearchProcessResults = (results, outputFormat) => {
|
|
1664
1715
|
if (!results || results.length === 0) {
|
|
@@ -1831,6 +1882,21 @@ const executeMemoryGrepSearch = async (workspaceUri, grepSearchArgs, options) =>
|
|
|
1831
1882
|
}
|
|
1832
1883
|
};
|
|
1833
1884
|
|
|
1885
|
+
const isBoolean = value => {
|
|
1886
|
+
return typeof value === 'boolean';
|
|
1887
|
+
};
|
|
1888
|
+
const isNumber = value => {
|
|
1889
|
+
return typeof value === 'number';
|
|
1890
|
+
};
|
|
1891
|
+
const isString = value => {
|
|
1892
|
+
return typeof value === 'string';
|
|
1893
|
+
};
|
|
1894
|
+
const isOptional = (value, predicate) => {
|
|
1895
|
+
return value === undefined || predicate(value);
|
|
1896
|
+
};
|
|
1897
|
+
const isOutputFormat = value => {
|
|
1898
|
+
return value === 'xml' || value === 'json';
|
|
1899
|
+
};
|
|
1834
1900
|
const getGrepSearchArgs = args => {
|
|
1835
1901
|
const {
|
|
1836
1902
|
includeIgnoredFiles,
|
|
@@ -1841,22 +1907,22 @@ const getGrepSearchArgs = args => {
|
|
|
1841
1907
|
query,
|
|
1842
1908
|
useDefaultExcludes
|
|
1843
1909
|
} = args;
|
|
1844
|
-
if (
|
|
1910
|
+
if (!isString(query) || !isBoolean(isRegexp)) {
|
|
1845
1911
|
return undefined;
|
|
1846
1912
|
}
|
|
1847
|
-
if (includePattern
|
|
1913
|
+
if (!isOptional(includePattern, isString)) {
|
|
1848
1914
|
return undefined;
|
|
1849
1915
|
}
|
|
1850
|
-
if (maxResults
|
|
1916
|
+
if (!isOptional(maxResults, isNumber)) {
|
|
1851
1917
|
return undefined;
|
|
1852
1918
|
}
|
|
1853
|
-
if (includeIgnoredFiles
|
|
1919
|
+
if (!isOptional(includeIgnoredFiles, isBoolean)) {
|
|
1854
1920
|
return undefined;
|
|
1855
1921
|
}
|
|
1856
|
-
if (useDefaultExcludes
|
|
1922
|
+
if (!isOptional(useDefaultExcludes, isBoolean)) {
|
|
1857
1923
|
return undefined;
|
|
1858
1924
|
}
|
|
1859
|
-
if (outputFormat
|
|
1925
|
+
if (!isOptional(outputFormat, isOutputFormat)) {
|
|
1860
1926
|
return undefined;
|
|
1861
1927
|
}
|
|
1862
1928
|
return {
|