This commit is contained in:
Innei
2026-02-10 18:36:13 +08:00
committed by arvinxx
parent 6016299ad1
commit a33cf6c8c6
49 changed files with 1997 additions and 229 deletions

View File

@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { App } from '@/core/App';
import { type App } from '@/core/App';
import LocalFileCtr from '../LocalFileCtr';
@@ -408,7 +408,7 @@ describe('LocalFileCtr', () => {
const result = await localFileCtr.handleGlobFiles({
pattern: '*.txt',
path: '/test',
scope: '/test',
});
expect(result.success).toBe(true);
@@ -416,7 +416,7 @@ describe('LocalFileCtr', () => {
expect(result.total_files).toBe(2);
expect(mockSearchService.glob).toHaveBeenCalledWith({
pattern: '*.txt',
path: '/test',
scope: '/test',
});
});

View File

@@ -1,16 +1,17 @@
/* eslint-disable unicorn/no-array-push-push */
import { GlobFilesParams, GlobFilesResult } from '@lobechat/electron-client-ipc';
import { execa } from 'execa';
import fg from 'fast-glob';
import { Stats } from 'node:fs';
import { type Stats } from 'node:fs';
import { stat } from 'node:fs/promises';
import * as os from 'node:os';
import { ToolDetectorManager } from '@/core/infrastructure/ToolDetectorManager';
import { type GlobFilesParams, type GlobFilesResult } from '@lobechat/electron-client-ipc';
import { execa } from 'execa';
import fg from 'fast-glob';
import { type ToolDetectorManager } from '@/core/infrastructure/ToolDetectorManager';
import { createLogger } from '@/utils/logger';
import { BaseFileSearch } from '../base';
import { FileResult, SearchOptions } from '../types';
import { type FileResult, type SearchOptions } from '../types';
const logger = createLogger('module:FileSearch:unix');
@@ -190,10 +191,7 @@ export abstract class UnixFileSearch extends BaseFileSearch {
logger.debug('Performing find search', { keywords: options.keywords, searchDir });
try {
const args: string[] = [searchDir];
// Limit depth and exclude common directories
args.push(
const args: string[] = [searchDir,
'-maxdepth',
'10',
'-type',
@@ -209,8 +207,9 @@ export abstract class UnixFileSearch extends BaseFileSearch {
'*/*cache*/*',
')',
'-prune',
'-o',
);
'-o'];
// Limit depth and exclude common directories
// Pattern matching
if (options.keywords) {
@@ -337,7 +336,7 @@ export abstract class UnixFileSearch extends BaseFileSearch {
* @returns Glob results
*/
protected async globWithFd(params: GlobFilesParams): Promise<GlobFilesResult> {
const searchPath = params.path || process.cwd();
const searchPath = params.scope || process.cwd();
const logPrefix = `[glob:fd: ${params.pattern}]`;
logger.debug(`${logPrefix} Starting fd glob`, { searchPath });
@@ -393,7 +392,7 @@ export abstract class UnixFileSearch extends BaseFileSearch {
* @returns Glob results
*/
protected async globWithFind(params: GlobFilesParams): Promise<GlobFilesResult> {
const searchPath = params.path || process.cwd();
const searchPath = params.scope || process.cwd();
const logPrefix = `[glob:find: ${params.pattern}]`;
logger.debug(`${logPrefix} Starting find glob`, { searchPath });
@@ -455,7 +454,7 @@ export abstract class UnixFileSearch extends BaseFileSearch {
* @returns Glob results
*/
protected async globWithFastGlob(params: GlobFilesParams): Promise<GlobFilesResult> {
const searchPath = params.path || process.cwd();
const searchPath = params.scope || process.cwd();
const logPrefix = `[glob:fast-glob: ${params.pattern}]`;
logger.debug(`${logPrefix} Starting fast-glob`, { searchPath });

View File

@@ -1,16 +1,17 @@
/* eslint-disable unicorn/no-array-push-push */
import { GlobFilesParams, GlobFilesResult } from '@lobechat/electron-client-ipc';
import { execa } from 'execa';
import fg from 'fast-glob';
import { Stats } from 'node:fs';
import { type Stats } from 'node:fs';
import { stat } from 'node:fs/promises';
import * as os from 'node:os';
import { ToolDetectorManager } from '@/core/infrastructure/ToolDetectorManager';
import { type GlobFilesParams, type GlobFilesResult } from '@lobechat/electron-client-ipc';
import { execa } from 'execa';
import fg from 'fast-glob';
import { type ToolDetectorManager } from '@/core/infrastructure/ToolDetectorManager';
import { createLogger } from '@/utils/logger';
import { BaseFileSearch } from '../base';
import { FileResult, SearchOptions } from '../types';
import { type FileResult, type SearchOptions } from '../types';
const logger = createLogger('module:FileSearch:windows');
@@ -335,7 +336,7 @@ export class WindowsSearchServiceImpl extends BaseFileSearch {
* @returns Glob results
*/
private async globWithFd(params: GlobFilesParams): Promise<GlobFilesResult> {
const searchPath = params.path || process.cwd();
const searchPath = params.scope || process.cwd();
const logPrefix = `[glob:fd: ${params.pattern}]`;
logger.debug(`${logPrefix} Starting fd glob`, { searchPath });
@@ -390,7 +391,7 @@ export class WindowsSearchServiceImpl extends BaseFileSearch {
* @returns Glob results
*/
private async globWithFastGlob(params: GlobFilesParams): Promise<GlobFilesResult> {
const searchPath = params.path || process.cwd();
const searchPath = params.scope || process.cwd();
const logPrefix = `[glob:fast-glob: ${params.pattern}]`;
logger.debug(`${logPrefix} Starting fast-glob`, { searchPath });