@lvce-editor/chat-tool-worker 8.1.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 +165 -29
- package/package.json +1 -1
|
@@ -1146,6 +1146,15 @@ const {
|
|
|
1146
1146
|
const readDirWithFileTypes = async uri => {
|
|
1147
1147
|
return invoke$1('FileSystem.readDirWithFileTypes', uri);
|
|
1148
1148
|
};
|
|
1149
|
+
const readFile$1 = async uri => {
|
|
1150
|
+
return invoke$1('FileSystem.readFile', uri);
|
|
1151
|
+
};
|
|
1152
|
+
const writeFile$1 = async (uri, content) => {
|
|
1153
|
+
return invoke$1('FileSystem.writeFile', uri, content);
|
|
1154
|
+
};
|
|
1155
|
+
const exists = async uri => {
|
|
1156
|
+
return invoke$1('FileSystem.exists', uri);
|
|
1157
|
+
};
|
|
1149
1158
|
|
|
1150
1159
|
const {
|
|
1151
1160
|
invoke,
|
|
@@ -1545,12 +1554,65 @@ const executeGlobTool = async (args, _options) => {
|
|
|
1545
1554
|
}
|
|
1546
1555
|
};
|
|
1547
1556
|
|
|
1548
|
-
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) => {
|
|
1549
1611
|
if (!results || results.length === 0) {
|
|
1550
1612
|
return 'No matches found.';
|
|
1551
1613
|
}
|
|
1552
1614
|
let currentFile = '';
|
|
1553
|
-
const
|
|
1615
|
+
const matches = [];
|
|
1554
1616
|
for (const result of results) {
|
|
1555
1617
|
if (result.type === 1) {
|
|
1556
1618
|
currentFile = result.text;
|
|
@@ -1558,16 +1620,24 @@ const formatSearchProcessResults = results => {
|
|
|
1558
1620
|
}
|
|
1559
1621
|
if (result.type === 2) {
|
|
1560
1622
|
if (currentFile) {
|
|
1561
|
-
|
|
1623
|
+
matches.push({
|
|
1624
|
+
lineNumber: result.lineNumber,
|
|
1625
|
+
path: currentFile,
|
|
1626
|
+
text: result.text
|
|
1627
|
+
});
|
|
1562
1628
|
} else {
|
|
1563
|
-
|
|
1629
|
+
matches.push({
|
|
1630
|
+
lineNumber: result.lineNumber,
|
|
1631
|
+
path: '',
|
|
1632
|
+
text: result.text
|
|
1633
|
+
});
|
|
1564
1634
|
}
|
|
1565
1635
|
}
|
|
1566
1636
|
}
|
|
1567
|
-
if (
|
|
1637
|
+
if (matches.length === 0) {
|
|
1568
1638
|
return 'No matches found.';
|
|
1569
1639
|
}
|
|
1570
|
-
return
|
|
1640
|
+
return formatGrepMatches(matches, outputFormat);
|
|
1571
1641
|
};
|
|
1572
1642
|
|
|
1573
1643
|
const windowsDrivePathRegex = /^[a-zA-Z]:[\\/]/;
|
|
@@ -1639,7 +1709,7 @@ const executeFileGrepSearch = async (workspaceUri, grepSearchArgs) => {
|
|
|
1639
1709
|
});
|
|
1640
1710
|
return {
|
|
1641
1711
|
arguments: grepSearchArgs,
|
|
1642
|
-
result: formatSearchProcessResults(result.results),
|
|
1712
|
+
result: formatSearchProcessResults(result.results, grepSearchArgs.outputFormat),
|
|
1643
1713
|
workspaceUri,
|
|
1644
1714
|
...(result.limitHit ? {
|
|
1645
1715
|
warning: 'Search result limit reached.'
|
|
@@ -1647,19 +1717,25 @@ const executeFileGrepSearch = async (workspaceUri, grepSearchArgs) => {
|
|
|
1647
1717
|
};
|
|
1648
1718
|
};
|
|
1649
1719
|
|
|
1650
|
-
const formatLegacyMemorySearchResults = results => {
|
|
1651
|
-
const
|
|
1720
|
+
const formatLegacyMemorySearchResults = (results, outputFormat) => {
|
|
1721
|
+
const matches = [];
|
|
1652
1722
|
for (const result of results) {
|
|
1653
|
-
const [path,
|
|
1654
|
-
for (const match of
|
|
1723
|
+
const [path, resultMatches] = result;
|
|
1724
|
+
for (const match of resultMatches) {
|
|
1655
1725
|
const preview = typeof match?.preview === 'string' ? match.preview : '';
|
|
1656
|
-
|
|
1726
|
+
matches.push(preview ? {
|
|
1727
|
+
path,
|
|
1728
|
+
text: preview
|
|
1729
|
+
} : {
|
|
1730
|
+
path,
|
|
1731
|
+
text: ''
|
|
1732
|
+
});
|
|
1657
1733
|
}
|
|
1658
1734
|
}
|
|
1659
|
-
if (
|
|
1735
|
+
if (matches.length === 0) {
|
|
1660
1736
|
return 'No matches found.';
|
|
1661
1737
|
}
|
|
1662
|
-
return
|
|
1738
|
+
return formatGrepMatches(matches, outputFormat);
|
|
1663
1739
|
};
|
|
1664
1740
|
|
|
1665
1741
|
const isLegacyMemorySearchResult = value => {
|
|
@@ -1681,7 +1757,7 @@ const executeMemoryGrepSearch = async (workspaceUri, grepSearchArgs, options) =>
|
|
|
1681
1757
|
const result = await invoke('ExtensionHostTextSearch.textSearchMemory2', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
|
|
1682
1758
|
return {
|
|
1683
1759
|
arguments: grepSearchArgs,
|
|
1684
|
-
result: formatLegacyMemorySearchResults(result.results || []),
|
|
1760
|
+
result: formatLegacyMemorySearchResults(result.results || [], grepSearchArgs.outputFormat),
|
|
1685
1761
|
workspaceUri,
|
|
1686
1762
|
...(result.limitHit ? {
|
|
1687
1763
|
warning: 'Search result limit reached.'
|
|
@@ -1691,7 +1767,7 @@ const executeMemoryGrepSearch = async (workspaceUri, grepSearchArgs, options) =>
|
|
|
1691
1767
|
const legacyResults = await invoke('ExtensionHostTextSearch.textSearchMemory', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
|
|
1692
1768
|
return {
|
|
1693
1769
|
arguments: grepSearchArgs,
|
|
1694
|
-
result: isLegacyMemorySearchResult(legacyResults) ? formatLegacyMemorySearchResults(legacyResults) : 'No matches found.',
|
|
1770
|
+
result: isLegacyMemorySearchResult(legacyResults) ? formatLegacyMemorySearchResults(legacyResults, grepSearchArgs.outputFormat) : 'No matches found.',
|
|
1695
1771
|
workspaceUri
|
|
1696
1772
|
};
|
|
1697
1773
|
}
|
|
@@ -1703,6 +1779,7 @@ const getGrepSearchArgs = args => {
|
|
|
1703
1779
|
includePattern,
|
|
1704
1780
|
isRegexp,
|
|
1705
1781
|
maxResults,
|
|
1782
|
+
outputFormat,
|
|
1706
1783
|
query
|
|
1707
1784
|
} = args;
|
|
1708
1785
|
if (typeof query !== 'string' || typeof isRegexp !== 'boolean') {
|
|
@@ -1717,6 +1794,9 @@ const getGrepSearchArgs = args => {
|
|
|
1717
1794
|
if (includeIgnoredFiles !== undefined && typeof includeIgnoredFiles !== 'boolean') {
|
|
1718
1795
|
return undefined;
|
|
1719
1796
|
}
|
|
1797
|
+
if (outputFormat !== undefined && outputFormat !== 'xml' && outputFormat !== 'json') {
|
|
1798
|
+
return undefined;
|
|
1799
|
+
}
|
|
1720
1800
|
return {
|
|
1721
1801
|
...(includeIgnoredFiles === undefined ? {} : {
|
|
1722
1802
|
includeIgnoredFiles
|
|
@@ -1727,12 +1807,15 @@ const getGrepSearchArgs = args => {
|
|
|
1727
1807
|
...(maxResults === undefined ? {} : {
|
|
1728
1808
|
maxResults
|
|
1729
1809
|
}),
|
|
1810
|
+
...(outputFormat === undefined ? {} : {
|
|
1811
|
+
outputFormat
|
|
1812
|
+
}),
|
|
1730
1813
|
isRegexp,
|
|
1731
1814
|
query
|
|
1732
1815
|
};
|
|
1733
1816
|
};
|
|
1734
1817
|
|
|
1735
|
-
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").';
|
|
1736
1819
|
|
|
1737
1820
|
const executeGrepSearchTool = async (args, options) => {
|
|
1738
1821
|
const grepSearchArgs = getGrepSearchArgs(args);
|
|
@@ -1862,8 +1945,6 @@ const executeReadFileTool = async (args, _options) => {
|
|
|
1862
1945
|
}
|
|
1863
1946
|
};
|
|
1864
1947
|
|
|
1865
|
-
/* eslint-disable @cspell/spellchecker */
|
|
1866
|
-
/* eslint-disable e18e/prefer-url-canparse */
|
|
1867
1948
|
const executeRenameTool = async (args, _options) => {
|
|
1868
1949
|
const oldUri = typeof args.oldUri === 'string' ? args.oldUri : '';
|
|
1869
1950
|
const newUri = typeof args.newUri === 'string' ? args.newUri : '';
|
|
@@ -1877,26 +1958,25 @@ const executeRenameTool = async (args, _options) => {
|
|
|
1877
1958
|
error: 'Invalid argument: newUri must be an absolute URI.'
|
|
1878
1959
|
};
|
|
1879
1960
|
}
|
|
1880
|
-
|
|
1881
|
-
new URL(oldUri);
|
|
1882
|
-
new URL(newUri);
|
|
1883
|
-
} catch {
|
|
1961
|
+
if (!URL.canParse(oldUri) || !URL.canParse(newUri)) {
|
|
1884
1962
|
return {
|
|
1885
1963
|
error: 'Invalid argument: invalid URL.'
|
|
1886
1964
|
};
|
|
1887
1965
|
}
|
|
1966
|
+
const oldUrl = new URL(oldUri);
|
|
1967
|
+
const newUrl = new URL(newUri);
|
|
1888
1968
|
try {
|
|
1889
|
-
await invoke('FileSystem.rename',
|
|
1969
|
+
await invoke('FileSystem.rename', oldUrl.toString(), newUrl.toString());
|
|
1890
1970
|
return {
|
|
1891
|
-
newUri,
|
|
1971
|
+
newUri: newUrl.toString(),
|
|
1892
1972
|
ok: true,
|
|
1893
|
-
oldUri
|
|
1973
|
+
oldUri: oldUrl.toString()
|
|
1894
1974
|
};
|
|
1895
1975
|
} catch (error) {
|
|
1896
1976
|
return {
|
|
1897
1977
|
...getToolErrorPayload(error),
|
|
1898
|
-
newUri,
|
|
1899
|
-
oldUri
|
|
1978
|
+
newUri: newUrl.toString(),
|
|
1979
|
+
oldUri: oldUrl.toString()
|
|
1900
1980
|
};
|
|
1901
1981
|
}
|
|
1902
1982
|
};
|
|
@@ -2163,6 +2243,49 @@ const executeUpdateTodoTool = async (args, _options) => {
|
|
|
2163
2243
|
}
|
|
2164
2244
|
};
|
|
2165
2245
|
|
|
2246
|
+
const carriageReturnNewLineRegex = /\r\n/g;
|
|
2247
|
+
const toLines = content => {
|
|
2248
|
+
if (content === '') {
|
|
2249
|
+
return [];
|
|
2250
|
+
}
|
|
2251
|
+
const normalizedContent = content.replaceAll(carriageReturnNewLineRegex, '\n');
|
|
2252
|
+
const lines = normalizedContent.split('\n');
|
|
2253
|
+
if (lines.at(-1) === '') {
|
|
2254
|
+
lines.pop();
|
|
2255
|
+
}
|
|
2256
|
+
return lines;
|
|
2257
|
+
};
|
|
2258
|
+
const getLongestCommonSubsequenceLength = (beforeLines, afterLines) => {
|
|
2259
|
+
if (beforeLines.length === 0 || afterLines.length === 0) {
|
|
2260
|
+
return 0;
|
|
2261
|
+
}
|
|
2262
|
+
const outerLines = beforeLines.length >= afterLines.length ? beforeLines : afterLines;
|
|
2263
|
+
const innerLines = beforeLines.length >= afterLines.length ? afterLines : beforeLines;
|
|
2264
|
+
let previousRow = new Uint32Array(innerLines.length + 1);
|
|
2265
|
+
for (let i = 1; i <= outerLines.length; i++) {
|
|
2266
|
+
const currentRow = new Uint32Array(innerLines.length + 1);
|
|
2267
|
+
const outerLine = outerLines[i - 1];
|
|
2268
|
+
for (let j = 1; j <= innerLines.length; j++) {
|
|
2269
|
+
if (outerLine === innerLines[j - 1]) {
|
|
2270
|
+
currentRow[j] = previousRow[j - 1] + 1;
|
|
2271
|
+
} else {
|
|
2272
|
+
currentRow[j] = Math.max(previousRow[j], currentRow[j - 1]);
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
previousRow = currentRow;
|
|
2276
|
+
}
|
|
2277
|
+
return previousRow[innerLines.length];
|
|
2278
|
+
};
|
|
2279
|
+
const getLineDiffStats = (beforeContent, afterContent) => {
|
|
2280
|
+
const beforeLines = toLines(beforeContent);
|
|
2281
|
+
const afterLines = toLines(afterContent);
|
|
2282
|
+
const longestCommonSubsequenceLength = getLongestCommonSubsequenceLength(beforeLines, afterLines);
|
|
2283
|
+
return {
|
|
2284
|
+
addedLines: afterLines.length - longestCommonSubsequenceLength,
|
|
2285
|
+
removedLines: beforeLines.length - longestCommonSubsequenceLength
|
|
2286
|
+
};
|
|
2287
|
+
};
|
|
2288
|
+
|
|
2166
2289
|
const executeWriteFileTool = async (args, _options) => {
|
|
2167
2290
|
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
2168
2291
|
const content = typeof args.content === 'string' ? args.content : '';
|
|
@@ -2179,9 +2302,17 @@ const executeWriteFileTool = async (args, _options) => {
|
|
|
2179
2302
|
};
|
|
2180
2303
|
}
|
|
2181
2304
|
try {
|
|
2182
|
-
await
|
|
2305
|
+
const exists$1 = await exists(uri);
|
|
2306
|
+
const previousContent = exists$1 ? await readFile$1(uri) : '';
|
|
2307
|
+
const {
|
|
2308
|
+
addedLines,
|
|
2309
|
+
removedLines
|
|
2310
|
+
} = getLineDiffStats(previousContent, content);
|
|
2311
|
+
await writeFile$1(uri, content);
|
|
2183
2312
|
return {
|
|
2313
|
+
addedLines,
|
|
2184
2314
|
ok: true,
|
|
2315
|
+
removedLines,
|
|
2185
2316
|
uri
|
|
2186
2317
|
};
|
|
2187
2318
|
} catch (error) {
|
|
@@ -2386,6 +2517,11 @@ const getGrepSearchTool = () => {
|
|
|
2386
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.",
|
|
2387
2518
|
type: 'number'
|
|
2388
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
|
+
},
|
|
2389
2525
|
query: {
|
|
2390
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.",
|
|
2391
2527
|
type: 'string'
|