@lvce-editor/chat-tool-worker 7.12.0 → 8.0.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 +288 -8
- package/package.json +1 -1
|
@@ -1282,6 +1282,190 @@ const executeGetWorkspaceUriTool = async (_args, _options) => {
|
|
|
1282
1282
|
}
|
|
1283
1283
|
};
|
|
1284
1284
|
|
|
1285
|
+
/**
|
|
1286
|
+
* Matches a string against a glob pattern
|
|
1287
|
+
* Supported patterns:
|
|
1288
|
+
* - * matches any characters except /
|
|
1289
|
+
* - ? matches a single character except /
|
|
1290
|
+
* - ** matches any characters including /
|
|
1291
|
+
* - [abc] matches a, b, or c
|
|
1292
|
+
* - [!abc] matches any character except a, b, c
|
|
1293
|
+
* - [a-z] matches any character between a and z
|
|
1294
|
+
*/
|
|
1295
|
+
|
|
1296
|
+
const REGEX_SPECIAL_CHARS_REGEX = /[.*+?^${}()|[\]\\]/g;
|
|
1297
|
+
const LEADING_DOT_SLASH_REGEX$1 = /^\.\//g;
|
|
1298
|
+
const MULTIPLE_SLASHES_REGEX$1 = /\/+/g;
|
|
1299
|
+
const escapeRegExp = str => {
|
|
1300
|
+
return str.replaceAll(REGEX_SPECIAL_CHARS_REGEX, '\\$&');
|
|
1301
|
+
};
|
|
1302
|
+
|
|
1303
|
+
/*
|
|
1304
|
+
* Convert a glob pattern to a regex, but only for segments between separators
|
|
1305
|
+
*/
|
|
1306
|
+
const segmentToRegex = segment => {
|
|
1307
|
+
let regexStr = '';
|
|
1308
|
+
let i = 0;
|
|
1309
|
+
while (i < segment.length) {
|
|
1310
|
+
const char = segment[i];
|
|
1311
|
+
switch (char) {
|
|
1312
|
+
case '?':
|
|
1313
|
+
{
|
|
1314
|
+
regexStr += '[^/]';
|
|
1315
|
+
i++;
|
|
1316
|
+
break;
|
|
1317
|
+
}
|
|
1318
|
+
case '[':
|
|
1319
|
+
{
|
|
1320
|
+
let j = i + 1;
|
|
1321
|
+
let negated = false;
|
|
1322
|
+
if (j < segment.length && segment[j] === '!') {
|
|
1323
|
+
negated = true;
|
|
1324
|
+
j++;
|
|
1325
|
+
}
|
|
1326
|
+
let classStr = '';
|
|
1327
|
+
while (j < segment.length && segment[j] !== ']') {
|
|
1328
|
+
classStr += segment[j];
|
|
1329
|
+
j++;
|
|
1330
|
+
}
|
|
1331
|
+
if (j < segment.length) {
|
|
1332
|
+
if (negated) {
|
|
1333
|
+
regexStr += `[^${escapeRegExp(classStr)}]`;
|
|
1334
|
+
} else {
|
|
1335
|
+
regexStr += `[${classStr.replaceAll('\\', '\\\\')}]`;
|
|
1336
|
+
}
|
|
1337
|
+
i = j + 1;
|
|
1338
|
+
} else {
|
|
1339
|
+
regexStr += escapeRegExp(char);
|
|
1340
|
+
i++;
|
|
1341
|
+
}
|
|
1342
|
+
break;
|
|
1343
|
+
}
|
|
1344
|
+
case '*':
|
|
1345
|
+
{
|
|
1346
|
+
regexStr += '[^/]*';
|
|
1347
|
+
i++;
|
|
1348
|
+
break;
|
|
1349
|
+
}
|
|
1350
|
+
default:
|
|
1351
|
+
{
|
|
1352
|
+
regexStr += escapeRegExp(char);
|
|
1353
|
+
i++;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
return new RegExp(`^${regexStr}$`);
|
|
1358
|
+
};
|
|
1359
|
+
const matchesGlobPattern = (path, pattern) => {
|
|
1360
|
+
const normalizedPath = path.replaceAll('\\', '/').replaceAll(LEADING_DOT_SLASH_REGEX$1, '');
|
|
1361
|
+
let normalizedPattern = pattern.replaceAll('\\', '/').replaceAll(LEADING_DOT_SLASH_REGEX$1, '').replaceAll(MULTIPLE_SLASHES_REGEX$1, '/');
|
|
1362
|
+
if (normalizedPattern.endsWith('/')) {
|
|
1363
|
+
normalizedPattern = normalizedPattern.slice(0, -1) + '/*';
|
|
1364
|
+
}
|
|
1365
|
+
const patternParts = normalizedPattern.split('/');
|
|
1366
|
+
const pathParts = normalizedPath.split('/');
|
|
1367
|
+
return matchesPatternParts(pathParts, patternParts, 0, 0);
|
|
1368
|
+
};
|
|
1369
|
+
const matchesPatternParts = (pathParts, patternParts, pathIdx, patternIdx) => {
|
|
1370
|
+
if (patternIdx === patternParts.length) {
|
|
1371
|
+
return pathIdx === pathParts.length;
|
|
1372
|
+
}
|
|
1373
|
+
if (pathIdx > pathParts.length) {
|
|
1374
|
+
return false;
|
|
1375
|
+
}
|
|
1376
|
+
const patternPart = patternParts[patternIdx];
|
|
1377
|
+
if (patternPart === undefined) {
|
|
1378
|
+
return false;
|
|
1379
|
+
}
|
|
1380
|
+
if (patternPart === '**') {
|
|
1381
|
+
for (let i = pathIdx; i <= pathParts.length; i++) {
|
|
1382
|
+
if (matchesPatternParts(pathParts, patternParts, i, patternIdx + 1)) {
|
|
1383
|
+
return true;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
return false;
|
|
1387
|
+
}
|
|
1388
|
+
if (pathIdx === pathParts.length) {
|
|
1389
|
+
return false;
|
|
1390
|
+
}
|
|
1391
|
+
if (patternPart.includes('**')) {
|
|
1392
|
+
const regex = segmentToRegex(patternPart.replace('**', ''));
|
|
1393
|
+
const pathPart = pathParts[pathIdx];
|
|
1394
|
+
if (pathPart !== undefined && regex.test(pathPart)) {
|
|
1395
|
+
return matchesPatternParts(pathParts, patternParts, pathIdx + 1, patternIdx + 1);
|
|
1396
|
+
}
|
|
1397
|
+
return false;
|
|
1398
|
+
}
|
|
1399
|
+
const regex = segmentToRegex(patternPart);
|
|
1400
|
+
const pathPart = pathParts[pathIdx];
|
|
1401
|
+
if (pathPart !== undefined && regex.test(pathPart)) {
|
|
1402
|
+
return matchesPatternParts(pathParts, patternParts, pathIdx + 1, patternIdx + 1);
|
|
1403
|
+
}
|
|
1404
|
+
return false;
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
// cspell:ignore venv
|
|
1408
|
+
const DEFAULT_EXCLUDE_DIRS = new Set(['.git', 'node_modules', '.cache', '.venv', 'dist', 'build', '.next', '.nuxt']);
|
|
1409
|
+
const shouldExcludeDir = dirName => {
|
|
1410
|
+
return DEFAULT_EXCLUDE_DIRS.has(dirName);
|
|
1411
|
+
};
|
|
1412
|
+
const traverseDirectory = async (baseUri, currentPath, onEntry, visited = new Set()) => {
|
|
1413
|
+
const uri = currentPath === '' ? baseUri : `${baseUri}/${currentPath}`;
|
|
1414
|
+
if (visited.has(uri)) {
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
visited.add(uri);
|
|
1418
|
+
try {
|
|
1419
|
+
const entries = await invoke('FileSystem.readDirWithFileTypes', uri);
|
|
1420
|
+
for (const entry of entries) {
|
|
1421
|
+
const entryPath = currentPath === '' ? entry.name : `${currentPath}/${entry.name}`;
|
|
1422
|
+
await onEntry(entryPath, entry);
|
|
1423
|
+
if (entry.isDirectory() && !entry.isSymbolicLink() && !shouldExcludeDir(entry.name)) {
|
|
1424
|
+
await traverseDirectory(baseUri, entryPath, onEntry, visited);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
} catch {
|
|
1428
|
+
// Ignore unreadable directories and continue with other matches.
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1432
|
+
const MULTIPLE_SLASHES_REGEX = /\/+/g;
|
|
1433
|
+
const LEADING_DOT_SLASH_REGEX = /^\.\//g;
|
|
1434
|
+
const PLACEHOLDER_WORKSPACE_URI = 'file:///workspace';
|
|
1435
|
+
const hasGlobCharacters = part => {
|
|
1436
|
+
return part.includes('*') || part.includes('?') || part.includes('[');
|
|
1437
|
+
};
|
|
1438
|
+
const normalizeInputPattern = pattern => {
|
|
1439
|
+
return pattern.trim().replaceAll('\\', '/').replaceAll(LEADING_DOT_SLASH_REGEX, '').replaceAll(MULTIPLE_SLASHES_REGEX, '/');
|
|
1440
|
+
};
|
|
1441
|
+
const normalizePattern = pattern => {
|
|
1442
|
+
const normalized = normalizeInputPattern(pattern);
|
|
1443
|
+
const matchDirectories = normalized.endsWith('/');
|
|
1444
|
+
const patternToParse = matchDirectories ? normalized.slice(0, -1) : normalized;
|
|
1445
|
+
const parts = patternToParse.split('/');
|
|
1446
|
+
let firstGlobIndex = -1;
|
|
1447
|
+
for (let i = 0; i < parts.length; i++) {
|
|
1448
|
+
const part = parts[i];
|
|
1449
|
+
if (part && hasGlobCharacters(part)) {
|
|
1450
|
+
firstGlobIndex = i;
|
|
1451
|
+
break;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
const globPartIndex = firstGlobIndex === -1 ? Math.max(parts.length - 1, 0) : firstGlobIndex;
|
|
1455
|
+
const baseDir = parts.slice(0, globPartIndex).join('/');
|
|
1456
|
+
const globPart = parts.slice(globPartIndex).join('/');
|
|
1457
|
+
return {
|
|
1458
|
+
baseDir,
|
|
1459
|
+
globPart,
|
|
1460
|
+
matchDirectories
|
|
1461
|
+
};
|
|
1462
|
+
};
|
|
1463
|
+
const joinUri = (baseUri, path) => {
|
|
1464
|
+
if (!path) {
|
|
1465
|
+
return baseUri;
|
|
1466
|
+
}
|
|
1467
|
+
return baseUri.endsWith('/') ? `${baseUri}${path}` : `${baseUri}/${path}`;
|
|
1468
|
+
};
|
|
1285
1469
|
const executeGlobTool = async (args, _options) => {
|
|
1286
1470
|
const pattern = typeof args.pattern === 'string' ? args.pattern : '';
|
|
1287
1471
|
if (!pattern) {
|
|
@@ -1289,11 +1473,65 @@ const executeGlobTool = async (args, _options) => {
|
|
|
1289
1473
|
error: 'Invalid argument: pattern must be a non-empty string.'
|
|
1290
1474
|
};
|
|
1291
1475
|
}
|
|
1292
|
-
const
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1476
|
+
const baseUri = typeof args.baseUri === 'string' ? args.baseUri : '';
|
|
1477
|
+
if (!baseUri || !isAbsoluteUri(baseUri)) {
|
|
1478
|
+
return {
|
|
1479
|
+
error: 'Invalid argument: baseUri must be an absolute URI.'
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
if (baseUri === PLACEHOLDER_WORKSPACE_URI || baseUri.startsWith(`${PLACEHOLDER_WORKSPACE_URI}/`)) {
|
|
1483
|
+
return {
|
|
1484
|
+
baseUri,
|
|
1485
|
+
error: 'Invalid argument: baseUri must be a real workspace folder URI. Call getWorkspaceUri first and use the returned workspaceUri value.'
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
const normalizedPattern = normalizeInputPattern(pattern);
|
|
1489
|
+
const {
|
|
1490
|
+
baseDir,
|
|
1491
|
+
globPart,
|
|
1492
|
+
matchDirectories
|
|
1493
|
+
} = normalizePattern(pattern);
|
|
1494
|
+
const matches = [];
|
|
1495
|
+
try {
|
|
1496
|
+
if (matchDirectories) {
|
|
1497
|
+
const dirUri = joinUri(baseUri, globPart);
|
|
1498
|
+
const entries = await invoke('FileSystem.readDirWithFileTypes', dirUri);
|
|
1499
|
+
for (const entry of entries) {
|
|
1500
|
+
matches.push(globPart ? `${globPart}/${entry.name}` : entry.name);
|
|
1501
|
+
}
|
|
1502
|
+
} else if (globPart.includes('**')) {
|
|
1503
|
+
const baseDirUri = joinUri(baseUri, baseDir);
|
|
1504
|
+
const visited = new Set();
|
|
1505
|
+
await traverseDirectory(baseDirUri, '', async (relativePath, entry) => {
|
|
1506
|
+
if (!entry.isFile()) {
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
const fullPath = baseDir ? `${baseDir}/${relativePath}` : relativePath;
|
|
1510
|
+
if (matchesGlobPattern(fullPath, normalizedPattern)) {
|
|
1511
|
+
matches.push(fullPath);
|
|
1512
|
+
}
|
|
1513
|
+
}, visited);
|
|
1514
|
+
} else {
|
|
1515
|
+
const dirUri = joinUri(baseUri, baseDir);
|
|
1516
|
+
const entries = await invoke('FileSystem.readDirWithFileTypes', dirUri);
|
|
1517
|
+
for (const entry of entries) {
|
|
1518
|
+
const fullPath = baseDir ? `${baseDir}/${entry.name}` : entry.name;
|
|
1519
|
+
if (matchesGlobPattern(fullPath, normalizedPattern)) {
|
|
1520
|
+
matches.push(fullPath);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
matches.sort();
|
|
1525
|
+
return {
|
|
1526
|
+
paths: matches,
|
|
1527
|
+
pattern
|
|
1528
|
+
};
|
|
1529
|
+
} catch (error) {
|
|
1530
|
+
return {
|
|
1531
|
+
error: `Failed to glob: ${error instanceof Error ? error.message : String(error)}`,
|
|
1532
|
+
pattern
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1297
1535
|
};
|
|
1298
1536
|
|
|
1299
1537
|
const formatSearchProcessResults = results => {
|
|
@@ -1793,6 +2031,21 @@ const executeSearchTextTool = async (args, _options) => {
|
|
|
1793
2031
|
};
|
|
1794
2032
|
};
|
|
1795
2033
|
|
|
2034
|
+
const placeholderResponse = 'Hello From Sub agent - not yet implemented';
|
|
2035
|
+
const executeSpawnSubagentTool = async (args, _options) => {
|
|
2036
|
+
const prompt = typeof args.prompt === 'string' ? args.prompt : '';
|
|
2037
|
+
if (!prompt) {
|
|
2038
|
+
return {
|
|
2039
|
+
error: 'Missing required argument: prompt'
|
|
2040
|
+
};
|
|
2041
|
+
}
|
|
2042
|
+
return {
|
|
2043
|
+
ok: true,
|
|
2044
|
+
prompt,
|
|
2045
|
+
response: placeholderResponse
|
|
2046
|
+
};
|
|
2047
|
+
};
|
|
2048
|
+
|
|
1796
2049
|
const todoDbName = 'chat-tool-worker';
|
|
1797
2050
|
const todoStoreName = 'state';
|
|
1798
2051
|
const todoKey = 'todoList';
|
|
@@ -1960,6 +2213,8 @@ const executeChatTool = async (name, rawArguments, options) => {
|
|
|
1960
2213
|
return executeRunInTerminalTool(args);
|
|
1961
2214
|
case 'search_text':
|
|
1962
2215
|
return executeSearchTextTool(args);
|
|
2216
|
+
case 'spawn_subagent':
|
|
2217
|
+
return executeSpawnSubagentTool(args);
|
|
1963
2218
|
case 'update_todo':
|
|
1964
2219
|
return executeUpdateTodoTool(args);
|
|
1965
2220
|
case 'write_file':
|
|
@@ -2058,17 +2313,21 @@ const getGetWorkspaceUriTool = () => {
|
|
|
2058
2313
|
const getGlobTool = () => {
|
|
2059
2314
|
return {
|
|
2060
2315
|
function: {
|
|
2061
|
-
description: 'Find files by glob pattern and return matching relative paths.',
|
|
2316
|
+
description: 'Find files by glob pattern under a specific workspace folder URI and return matching relative paths. If you do not already have a real workspace URI, call getWorkspaceUri first and then pass that returned workspaceUri as baseUri.',
|
|
2062
2317
|
name: 'glob',
|
|
2063
2318
|
parameters: {
|
|
2064
2319
|
additionalProperties: false,
|
|
2065
2320
|
properties: {
|
|
2321
|
+
baseUri: {
|
|
2322
|
+
description: 'Absolute folder URI for the workspace root or subfolder where the glob search should start. If unknown, call getWorkspaceUri first and pass the returned workspaceUri value.',
|
|
2323
|
+
type: 'string'
|
|
2324
|
+
},
|
|
2066
2325
|
pattern: {
|
|
2067
2326
|
description: 'Glob pattern to match files, for example `packages/e2e/src/*.ts`.',
|
|
2068
2327
|
type: 'string'
|
|
2069
2328
|
}
|
|
2070
2329
|
},
|
|
2071
|
-
required: ['pattern'],
|
|
2330
|
+
required: ['baseUri', 'pattern'],
|
|
2072
2331
|
type: 'object'
|
|
2073
2332
|
}
|
|
2074
2333
|
},
|
|
@@ -2357,6 +2616,27 @@ const getSearchTextTool = () => {
|
|
|
2357
2616
|
};
|
|
2358
2617
|
};
|
|
2359
2618
|
|
|
2619
|
+
const getSpawnSubagentTool = () => {
|
|
2620
|
+
return {
|
|
2621
|
+
function: {
|
|
2622
|
+
description: 'Spawn a subagent for a focused subtask. For now this tool is a stub and returns a fixed placeholder response while the integration is being built.',
|
|
2623
|
+
name: 'spawn_subagent',
|
|
2624
|
+
parameters: {
|
|
2625
|
+
additionalProperties: false,
|
|
2626
|
+
properties: {
|
|
2627
|
+
prompt: {
|
|
2628
|
+
description: 'Short task prompt to send to the subagent.',
|
|
2629
|
+
type: 'string'
|
|
2630
|
+
}
|
|
2631
|
+
},
|
|
2632
|
+
required: ['prompt'],
|
|
2633
|
+
type: 'object'
|
|
2634
|
+
}
|
|
2635
|
+
},
|
|
2636
|
+
type: 'function'
|
|
2637
|
+
};
|
|
2638
|
+
};
|
|
2639
|
+
|
|
2360
2640
|
const getUpdateTodoTool = () => {
|
|
2361
2641
|
return {
|
|
2362
2642
|
function: {
|
|
@@ -2404,7 +2684,7 @@ const getWriteFileTool = () => {
|
|
|
2404
2684
|
};
|
|
2405
2685
|
|
|
2406
2686
|
const getBasicChatTools = () => {
|
|
2407
|
-
return [getReadFileTool(), getWriteFileTool(), getRenameTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRgTool(), getGrepSearchTool(), getRunInTerminalTool(), getCreateDirectoryTool(), getGlobTool(), getUpdateTodoTool()];
|
|
2687
|
+
return [getReadFileTool(), getWriteFileTool(), getRenameTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRgTool(), getGrepSearchTool(), getRunInTerminalTool(), getSpawnSubagentTool(), getCreateDirectoryTool(), getGlobTool(), getUpdateTodoTool()];
|
|
2408
2688
|
};
|
|
2409
2689
|
|
|
2410
2690
|
const handleMessagePort = async port => {
|