@lvce-editor/chat-tool-worker 8.2.0 → 8.3.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 +104 -28
- package/package.json +1 -1
|
@@ -1554,12 +1554,65 @@ const executeGlobTool = async (args, _options) => {
|
|
|
1554
1554
|
}
|
|
1555
1555
|
};
|
|
1556
1556
|
|
|
1557
|
-
const
|
|
1557
|
+
const escapeXml = value => {
|
|
1558
|
+
return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
|
1559
|
+
};
|
|
1560
|
+
const formatTextMatches = matches => {
|
|
1561
|
+
const lines = [];
|
|
1562
|
+
for (const match of matches) {
|
|
1563
|
+
if (typeof match.lineNumber === 'number') {
|
|
1564
|
+
lines.push(`${match.path}:${match.lineNumber}:${match.text}`);
|
|
1565
|
+
} else {
|
|
1566
|
+
lines.push(`${match.path}: ${match.text}`);
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
return lines.join('\n');
|
|
1570
|
+
};
|
|
1571
|
+
const formatXmlMatches = matches => {
|
|
1572
|
+
const lines = [`${matches.length} matches`];
|
|
1573
|
+
for (const match of matches) {
|
|
1574
|
+
const attributes = [`path="${escapeXml(match.path)}"`];
|
|
1575
|
+
if (typeof match.lineNumber === 'number') {
|
|
1576
|
+
attributes.push(`line="${match.lineNumber}"`);
|
|
1577
|
+
}
|
|
1578
|
+
lines.push(`<match ${attributes.join(' ')}>`);
|
|
1579
|
+
lines.push(escapeXml(match.text));
|
|
1580
|
+
lines.push('</match>');
|
|
1581
|
+
}
|
|
1582
|
+
return lines.join('\n');
|
|
1583
|
+
};
|
|
1584
|
+
const formatJsonMatches = matches => {
|
|
1585
|
+
return JSON.stringify({
|
|
1586
|
+
count: matches.length,
|
|
1587
|
+
matches: matches.map(match => ({
|
|
1588
|
+
...(typeof match.lineNumber === 'number' ? {
|
|
1589
|
+
line: match.lineNumber
|
|
1590
|
+
} : {}),
|
|
1591
|
+
path: match.path,
|
|
1592
|
+
text: match.text
|
|
1593
|
+
}))
|
|
1594
|
+
}, undefined, 2);
|
|
1595
|
+
};
|
|
1596
|
+
const formatGrepMatches = (matches, outputFormat) => {
|
|
1597
|
+
if (matches.length === 0) {
|
|
1598
|
+
return 'No matches found.';
|
|
1599
|
+
}
|
|
1600
|
+
switch (outputFormat) {
|
|
1601
|
+
case 'json':
|
|
1602
|
+
return formatJsonMatches(matches);
|
|
1603
|
+
case 'xml':
|
|
1604
|
+
return formatXmlMatches(matches);
|
|
1605
|
+
default:
|
|
1606
|
+
return formatTextMatches(matches);
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1609
|
+
|
|
1610
|
+
const formatSearchProcessResults = (results, outputFormat) => {
|
|
1558
1611
|
if (!results || results.length === 0) {
|
|
1559
1612
|
return 'No matches found.';
|
|
1560
1613
|
}
|
|
1561
1614
|
let currentFile = '';
|
|
1562
|
-
const
|
|
1615
|
+
const matches = [];
|
|
1563
1616
|
for (const result of results) {
|
|
1564
1617
|
if (result.type === 1) {
|
|
1565
1618
|
currentFile = result.text;
|
|
@@ -1567,16 +1620,24 @@ const formatSearchProcessResults = results => {
|
|
|
1567
1620
|
}
|
|
1568
1621
|
if (result.type === 2) {
|
|
1569
1622
|
if (currentFile) {
|
|
1570
|
-
|
|
1623
|
+
matches.push({
|
|
1624
|
+
lineNumber: result.lineNumber,
|
|
1625
|
+
path: currentFile,
|
|
1626
|
+
text: result.text
|
|
1627
|
+
});
|
|
1571
1628
|
} else {
|
|
1572
|
-
|
|
1629
|
+
matches.push({
|
|
1630
|
+
lineNumber: result.lineNumber,
|
|
1631
|
+
path: '',
|
|
1632
|
+
text: result.text
|
|
1633
|
+
});
|
|
1573
1634
|
}
|
|
1574
1635
|
}
|
|
1575
1636
|
}
|
|
1576
|
-
if (
|
|
1637
|
+
if (matches.length === 0) {
|
|
1577
1638
|
return 'No matches found.';
|
|
1578
1639
|
}
|
|
1579
|
-
return
|
|
1640
|
+
return formatGrepMatches(matches, outputFormat);
|
|
1580
1641
|
};
|
|
1581
1642
|
|
|
1582
1643
|
const windowsDrivePathRegex = /^[a-zA-Z]:[\\/]/;
|
|
@@ -1648,7 +1709,7 @@ const executeFileGrepSearch = async (workspaceUri, grepSearchArgs) => {
|
|
|
1648
1709
|
});
|
|
1649
1710
|
return {
|
|
1650
1711
|
arguments: grepSearchArgs,
|
|
1651
|
-
result: formatSearchProcessResults(result.results),
|
|
1712
|
+
result: formatSearchProcessResults(result.results, grepSearchArgs.outputFormat),
|
|
1652
1713
|
workspaceUri,
|
|
1653
1714
|
...(result.limitHit ? {
|
|
1654
1715
|
warning: 'Search result limit reached.'
|
|
@@ -1656,19 +1717,25 @@ const executeFileGrepSearch = async (workspaceUri, grepSearchArgs) => {
|
|
|
1656
1717
|
};
|
|
1657
1718
|
};
|
|
1658
1719
|
|
|
1659
|
-
const formatLegacyMemorySearchResults = results => {
|
|
1660
|
-
const
|
|
1720
|
+
const formatLegacyMemorySearchResults = (results, outputFormat) => {
|
|
1721
|
+
const matches = [];
|
|
1661
1722
|
for (const result of results) {
|
|
1662
|
-
const [path,
|
|
1663
|
-
for (const match of
|
|
1723
|
+
const [path, resultMatches] = result;
|
|
1724
|
+
for (const match of resultMatches) {
|
|
1664
1725
|
const preview = typeof match?.preview === 'string' ? match.preview : '';
|
|
1665
|
-
|
|
1726
|
+
matches.push(preview ? {
|
|
1727
|
+
path,
|
|
1728
|
+
text: preview
|
|
1729
|
+
} : {
|
|
1730
|
+
path,
|
|
1731
|
+
text: ''
|
|
1732
|
+
});
|
|
1666
1733
|
}
|
|
1667
1734
|
}
|
|
1668
|
-
if (
|
|
1735
|
+
if (matches.length === 0) {
|
|
1669
1736
|
return 'No matches found.';
|
|
1670
1737
|
}
|
|
1671
|
-
return
|
|
1738
|
+
return formatGrepMatches(matches, outputFormat);
|
|
1672
1739
|
};
|
|
1673
1740
|
|
|
1674
1741
|
const isLegacyMemorySearchResult = value => {
|
|
@@ -1690,7 +1757,7 @@ const executeMemoryGrepSearch = async (workspaceUri, grepSearchArgs, options) =>
|
|
|
1690
1757
|
const result = await invoke('ExtensionHostTextSearch.textSearchMemory2', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
|
|
1691
1758
|
return {
|
|
1692
1759
|
arguments: grepSearchArgs,
|
|
1693
|
-
result: formatLegacyMemorySearchResults(result.results || []),
|
|
1760
|
+
result: formatLegacyMemorySearchResults(result.results || [], grepSearchArgs.outputFormat),
|
|
1694
1761
|
workspaceUri,
|
|
1695
1762
|
...(result.limitHit ? {
|
|
1696
1763
|
warning: 'Search result limit reached.'
|
|
@@ -1700,7 +1767,7 @@ const executeMemoryGrepSearch = async (workspaceUri, grepSearchArgs, options) =>
|
|
|
1700
1767
|
const legacyResults = await invoke('ExtensionHostTextSearch.textSearchMemory', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
|
|
1701
1768
|
return {
|
|
1702
1769
|
arguments: grepSearchArgs,
|
|
1703
|
-
result: isLegacyMemorySearchResult(legacyResults) ? formatLegacyMemorySearchResults(legacyResults) : 'No matches found.',
|
|
1770
|
+
result: isLegacyMemorySearchResult(legacyResults) ? formatLegacyMemorySearchResults(legacyResults, grepSearchArgs.outputFormat) : 'No matches found.',
|
|
1704
1771
|
workspaceUri
|
|
1705
1772
|
};
|
|
1706
1773
|
}
|
|
@@ -1712,6 +1779,7 @@ const getGrepSearchArgs = args => {
|
|
|
1712
1779
|
includePattern,
|
|
1713
1780
|
isRegexp,
|
|
1714
1781
|
maxResults,
|
|
1782
|
+
outputFormat,
|
|
1715
1783
|
query
|
|
1716
1784
|
} = args;
|
|
1717
1785
|
if (typeof query !== 'string' || typeof isRegexp !== 'boolean') {
|
|
@@ -1726,6 +1794,9 @@ const getGrepSearchArgs = args => {
|
|
|
1726
1794
|
if (includeIgnoredFiles !== undefined && typeof includeIgnoredFiles !== 'boolean') {
|
|
1727
1795
|
return undefined;
|
|
1728
1796
|
}
|
|
1797
|
+
if (outputFormat !== undefined && outputFormat !== 'xml' && outputFormat !== 'json') {
|
|
1798
|
+
return undefined;
|
|
1799
|
+
}
|
|
1729
1800
|
return {
|
|
1730
1801
|
...(includeIgnoredFiles === undefined ? {} : {
|
|
1731
1802
|
includeIgnoredFiles
|
|
@@ -1736,12 +1807,15 @@ const getGrepSearchArgs = args => {
|
|
|
1736
1807
|
...(maxResults === undefined ? {} : {
|
|
1737
1808
|
maxResults
|
|
1738
1809
|
}),
|
|
1810
|
+
...(outputFormat === undefined ? {} : {
|
|
1811
|
+
outputFormat
|
|
1812
|
+
}),
|
|
1739
1813
|
isRegexp,
|
|
1740
1814
|
query
|
|
1741
1815
|
};
|
|
1742
1816
|
};
|
|
1743
1817
|
|
|
1744
|
-
const grepSearchArgumentError = 'Invalid argument: grep_search requires query (string), isRegexp (boolean), optional includePattern (string), optional maxResults (number),
|
|
1818
|
+
const grepSearchArgumentError = 'Invalid argument: grep_search requires query (string), isRegexp (boolean), optional includePattern (string), optional maxResults (number), optional includeIgnoredFiles (boolean), and optional outputFormat ("xml" | "json").';
|
|
1745
1819
|
|
|
1746
1820
|
const executeGrepSearchTool = async (args, options) => {
|
|
1747
1821
|
const grepSearchArgs = getGrepSearchArgs(args);
|
|
@@ -1871,8 +1945,6 @@ const executeReadFileTool = async (args, _options) => {
|
|
|
1871
1945
|
}
|
|
1872
1946
|
};
|
|
1873
1947
|
|
|
1874
|
-
/* eslint-disable @cspell/spellchecker */
|
|
1875
|
-
/* eslint-disable e18e/prefer-url-canparse */
|
|
1876
1948
|
const executeRenameTool = async (args, _options) => {
|
|
1877
1949
|
const oldUri = typeof args.oldUri === 'string' ? args.oldUri : '';
|
|
1878
1950
|
const newUri = typeof args.newUri === 'string' ? args.newUri : '';
|
|
@@ -1886,26 +1958,25 @@ const executeRenameTool = async (args, _options) => {
|
|
|
1886
1958
|
error: 'Invalid argument: newUri must be an absolute URI.'
|
|
1887
1959
|
};
|
|
1888
1960
|
}
|
|
1889
|
-
|
|
1890
|
-
new URL(oldUri);
|
|
1891
|
-
new URL(newUri);
|
|
1892
|
-
} catch {
|
|
1961
|
+
if (!URL.canParse(oldUri) || !URL.canParse(newUri)) {
|
|
1893
1962
|
return {
|
|
1894
1963
|
error: 'Invalid argument: invalid URL.'
|
|
1895
1964
|
};
|
|
1896
1965
|
}
|
|
1966
|
+
const oldUrl = new URL(oldUri);
|
|
1967
|
+
const newUrl = new URL(newUri);
|
|
1897
1968
|
try {
|
|
1898
|
-
await invoke('FileSystem.rename',
|
|
1969
|
+
await invoke('FileSystem.rename', oldUrl.toString(), newUrl.toString());
|
|
1899
1970
|
return {
|
|
1900
|
-
newUri,
|
|
1971
|
+
newUri: newUrl.toString(),
|
|
1901
1972
|
ok: true,
|
|
1902
|
-
oldUri
|
|
1973
|
+
oldUri: oldUrl.toString()
|
|
1903
1974
|
};
|
|
1904
1975
|
} catch (error) {
|
|
1905
1976
|
return {
|
|
1906
1977
|
...getToolErrorPayload(error),
|
|
1907
|
-
newUri,
|
|
1908
|
-
oldUri
|
|
1978
|
+
newUri: newUrl.toString(),
|
|
1979
|
+
oldUri: oldUrl.toString()
|
|
1909
1980
|
};
|
|
1910
1981
|
}
|
|
1911
1982
|
};
|
|
@@ -2446,6 +2517,11 @@ const getGrepSearchTool = () => {
|
|
|
2446
2517
|
description: "The maximum number of results to return. Do not use this unless necessary, it can slow things down. By default, only some matches are returned. If you use this and don't see what you're looking for, you can try again with a more specific query or a larger maxResults.",
|
|
2447
2518
|
type: 'number'
|
|
2448
2519
|
},
|
|
2520
|
+
outputFormat: {
|
|
2521
|
+
description: 'Optional structured output format. Use "xml" for match tags or "json" for machine-readable JSON. When omitted, grep_search returns plain text lines.',
|
|
2522
|
+
enum: ['xml', 'json'],
|
|
2523
|
+
type: 'string'
|
|
2524
|
+
},
|
|
2449
2525
|
query: {
|
|
2450
2526
|
description: "The pattern to search for in files in the workspace. Use regex with alternation (e.g., 'word1|word2|word3') or character classes to find multiple potential words in a single search. Be sure to set the isRegexp property properly to declare whether it's a regex or plain text pattern. Is case-insensitive.",
|
|
2451
2527
|
type: 'string'
|