@lvce-editor/chat-tool-worker 7.12.0 → 7.13.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.
@@ -1282,6 +1282,183 @@ 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 hasGlobCharacters = part => {
1435
+ return part.includes('*') || part.includes('?') || part.includes('[');
1436
+ };
1437
+ const normalizeInputPattern = pattern => {
1438
+ return pattern.trim().replaceAll('\\', '/').replaceAll(LEADING_DOT_SLASH_REGEX, '').replaceAll(MULTIPLE_SLASHES_REGEX, '/');
1439
+ };
1440
+ const normalizePattern = pattern => {
1441
+ const normalized = normalizeInputPattern(pattern);
1442
+ const matchDirectories = normalized.endsWith('/');
1443
+ const patternToParse = matchDirectories ? normalized.slice(0, -1) : normalized;
1444
+ const parts = patternToParse.split('/');
1445
+ let firstGlobIndex = -1;
1446
+ for (let i = 0; i < parts.length; i++) {
1447
+ const part = parts[i];
1448
+ if (part && hasGlobCharacters(part)) {
1449
+ firstGlobIndex = i;
1450
+ break;
1451
+ }
1452
+ }
1453
+ const globPartIndex = firstGlobIndex === -1 ? Math.max(parts.length - 1, 0) : firstGlobIndex;
1454
+ const baseDir = parts.slice(0, globPartIndex).join('/');
1455
+ const globPart = parts.slice(globPartIndex).join('/');
1456
+ return {
1457
+ baseDir,
1458
+ globPart,
1459
+ matchDirectories
1460
+ };
1461
+ };
1285
1462
  const executeGlobTool = async (args, _options) => {
1286
1463
  const pattern = typeof args.pattern === 'string' ? args.pattern : '';
1287
1464
  if (!pattern) {
@@ -1289,11 +1466,54 @@ const executeGlobTool = async (args, _options) => {
1289
1466
  error: 'Invalid argument: pattern must be a non-empty string.'
1290
1467
  };
1291
1468
  }
1292
- const paths = ['./src/main.ts', './src/utils/search.ts', './test/Main.test.ts'];
1293
- return {
1294
- paths,
1295
- pattern
1296
- };
1469
+ const normalizedPattern = normalizeInputPattern(pattern);
1470
+ const {
1471
+ baseDir,
1472
+ globPart,
1473
+ matchDirectories
1474
+ } = normalizePattern(pattern);
1475
+ const baseUri = 'file:///workspace';
1476
+ const matches = [];
1477
+ try {
1478
+ if (matchDirectories) {
1479
+ const dirUri = globPart ? `${baseUri}/${globPart}` : baseUri;
1480
+ const entries = await invoke('FileSystem.readDirWithFileTypes', dirUri);
1481
+ for (const entry of entries) {
1482
+ matches.push(globPart ? `${globPart}/${entry.name}` : entry.name);
1483
+ }
1484
+ } else if (globPart.includes('**')) {
1485
+ const baseDirUri = baseDir ? `${baseUri}/${baseDir}` : baseUri;
1486
+ const visited = new Set();
1487
+ await traverseDirectory(baseDirUri, '', async (relativePath, entry) => {
1488
+ if (!entry.isFile()) {
1489
+ return;
1490
+ }
1491
+ const fullPath = baseDir ? `${baseDir}/${relativePath}` : relativePath;
1492
+ if (matchesGlobPattern(fullPath, normalizedPattern)) {
1493
+ matches.push(fullPath);
1494
+ }
1495
+ }, visited);
1496
+ } else {
1497
+ const dirUri = baseDir ? `${baseUri}/${baseDir}` : baseUri;
1498
+ const entries = await invoke('FileSystem.readDirWithFileTypes', dirUri);
1499
+ for (const entry of entries) {
1500
+ const fullPath = baseDir ? `${baseDir}/${entry.name}` : entry.name;
1501
+ if (matchesGlobPattern(fullPath, normalizedPattern)) {
1502
+ matches.push(fullPath);
1503
+ }
1504
+ }
1505
+ }
1506
+ matches.sort();
1507
+ return {
1508
+ paths: matches,
1509
+ pattern
1510
+ };
1511
+ } catch (error) {
1512
+ return {
1513
+ error: `Failed to glob: ${error instanceof Error ? error.message : String(error)}`,
1514
+ pattern
1515
+ };
1516
+ }
1297
1517
  };
1298
1518
 
1299
1519
  const formatSearchProcessResults = results => {
@@ -1793,6 +2013,21 @@ const executeSearchTextTool = async (args, _options) => {
1793
2013
  };
1794
2014
  };
1795
2015
 
2016
+ const placeholderResponse = 'Hello From Sub agent - not yet implemented';
2017
+ const executeSpawnSubagentTool = async (args, _options) => {
2018
+ const prompt = typeof args.prompt === 'string' ? args.prompt : '';
2019
+ if (!prompt) {
2020
+ return {
2021
+ error: 'Missing required argument: prompt'
2022
+ };
2023
+ }
2024
+ return {
2025
+ ok: true,
2026
+ prompt,
2027
+ response: placeholderResponse
2028
+ };
2029
+ };
2030
+
1796
2031
  const todoDbName = 'chat-tool-worker';
1797
2032
  const todoStoreName = 'state';
1798
2033
  const todoKey = 'todoList';
@@ -1960,6 +2195,8 @@ const executeChatTool = async (name, rawArguments, options) => {
1960
2195
  return executeRunInTerminalTool(args);
1961
2196
  case 'search_text':
1962
2197
  return executeSearchTextTool(args);
2198
+ case 'spawn_subagent':
2199
+ return executeSpawnSubagentTool(args);
1963
2200
  case 'update_todo':
1964
2201
  return executeUpdateTodoTool(args);
1965
2202
  case 'write_file':
@@ -2357,6 +2594,27 @@ const getSearchTextTool = () => {
2357
2594
  };
2358
2595
  };
2359
2596
 
2597
+ const getSpawnSubagentTool = () => {
2598
+ return {
2599
+ function: {
2600
+ 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.',
2601
+ name: 'spawn_subagent',
2602
+ parameters: {
2603
+ additionalProperties: false,
2604
+ properties: {
2605
+ prompt: {
2606
+ description: 'Short task prompt to send to the subagent.',
2607
+ type: 'string'
2608
+ }
2609
+ },
2610
+ required: ['prompt'],
2611
+ type: 'object'
2612
+ }
2613
+ },
2614
+ type: 'function'
2615
+ };
2616
+ };
2617
+
2360
2618
  const getUpdateTodoTool = () => {
2361
2619
  return {
2362
2620
  function: {
@@ -2404,7 +2662,7 @@ const getWriteFileTool = () => {
2404
2662
  };
2405
2663
 
2406
2664
  const getBasicChatTools = () => {
2407
- return [getReadFileTool(), getWriteFileTool(), getRenameTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRgTool(), getGrepSearchTool(), getRunInTerminalTool(), getCreateDirectoryTool(), getGlobTool(), getUpdateTodoTool()];
2665
+ return [getReadFileTool(), getWriteFileTool(), getRenameTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRgTool(), getGrepSearchTool(), getRunInTerminalTool(), getSpawnSubagentTool(), getCreateDirectoryTool(), getGlobTool(), getUpdateTodoTool()];
2408
2666
  };
2409
2667
 
2410
2668
  const handleMessagePort = async port => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/chat-tool-worker",
3
- "version": "7.12.0",
3
+ "version": "7.13.0",
4
4
  "description": "Chat Tool Worker",
5
5
  "repository": {
6
6
  "type": "git",