Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(local-file-shell): auto-enable hidden matching for dot-prefixed patterns (#14965)

Arvin Xucf16737668cf
diff --git a/apps/desktop/src/main/modules/contentSearch/__tests__/base.test.ts b/apps/desktop/src/main/modules/contentSearch/__tests__/base.test.ts
index 8c5401e7e02..24562f089ab 100644
--- a/apps/desktop/src/main/modules/contentSearch/__tests__/base.test.ts
+++ b/apps/desktop/src/main/modules/contentSearch/__tests__/base.test.ts
@@ -143,6 +143,30 @@ describe('BaseContentSearch', () => {
expect(args).toContain('*.ts');
});
+ it('should add --hidden when glob references a dot-prefixed segment', () => {
+ const params: GrepContentParams = {
+ glob: '.github/workflows/*.yml',
+ pattern: 'jobs',
+ };
+
+ const args = contentSearch.testBuildGrepArgs('rg', params);
+
+ expect(args).toContain('--hidden');
+ expect(args).toContain('-g');
+ expect(args).toContain('.github/workflows/*.yml');
+ });
+
+ it('should not add --hidden for a normal glob', () => {
+ const params: GrepContentParams = {
+ glob: '*.ts',
+ pattern: 'test',
+ };
+
+ const args = contentSearch.testBuildGrepArgs('rg', params);
+
+ expect(args).not.toContain('--hidden');
+ });
+
it('should build rg args with type filter', () => {
const params: GrepContentParams = {
pattern: 'test',
@@ -205,6 +229,17 @@ describe('BaseContentSearch', () => {
expect(args).toContain('*.tsx');
});
+ it('should add --hidden when glob references a dot-prefixed segment', () => {
+ const params: GrepContentParams = {
+ glob: '.github/workflows/*.yml',
+ pattern: 'jobs',
+ };
+
+ const args = contentSearch.testBuildGrepArgs('ag', params);
+
+ expect(args).toContain('--hidden');
+ });
+
it('should build ag args for count mode', () => {
const params: GrepContentParams = {
output_mode: 'count',
diff --git a/apps/desktop/src/main/modules/contentSearch/base.ts b/apps/desktop/src/main/modules/contentSearch/base.ts
index cde5524cad3..00326f76c50 100644
--- a/apps/desktop/src/main/modules/contentSearch/base.ts
+++ b/apps/desktop/src/main/modules/contentSearch/base.ts
@@ -65,6 +65,12 @@ export abstract class BaseContentSearch {
const { pattern, output_mode = 'files_with_matches' } = params;
const args: string[] = [];
+ // When the caller's glob references a dot-prefixed segment (e.g.
+ // `.github/workflows/*.yml`), rg and ag both default to skipping hidden
+ // paths and would silently return zero results. `.git/` is still excluded
+ // explicitly below.
+ const wantsHidden = !!params.glob && /(?:^|\/)\.[^./]/.test(params.glob);
+
switch (tool) {
case 'rg': {
// ripgrep arguments
@@ -74,6 +80,7 @@ export abstract class BaseContentSearch {
if (params['-B']) args.push('-B', String(params['-B']));
if (params['-C']) args.push('-C', String(params['-C']));
if (params.multiline) args.push('-U');
+ if (wantsHidden) args.push('--hidden');
if (params.glob) args.push('-g', params.glob);
if (params.type) args.push('-t', params.type);
@@ -100,6 +107,7 @@ export abstract class BaseContentSearch {
if (params['-A']) args.push('-A', String(params['-A']));
if (params['-B']) args.push('-B', String(params['-B']));
if (params['-C']) args.push('-C', String(params['-C']));
+ if (wantsHidden) args.push('--hidden');
if (params.glob) args.push('-G', params.glob);
// Output mode
diff --git a/packages/local-file-shell/src/file/__tests__/file.test.ts b/packages/local-file-shell/src/file/__tests__/file.test.ts
index 6154cf4c025..602b8e90afb 100644
--- a/packages/local-file-shell/src/file/__tests__/file.test.ts
+++ b/packages/local-file-shell/src/file/__tests__/file.test.ts
@@ -515,6 +515,38 @@ describe('file operations', () => {
expect(result.files).toEqual(['src.ts']);
});
+
+ it('should auto-enable hidden matching when pattern contains a dot-prefixed segment', async () => {
+ await mkdir(path.join(tmpDir, '.github', 'workflows'), { recursive: true });
+ await writeFile(path.join(tmpDir, '.github', 'workflows', 'ci.yml'), 'name: ci');
+ await writeFile(path.join(tmpDir, '.github', 'workflows', 'release.yaml'), 'name: release');
+
+ const result = await globLocalFiles({
+ cwd: tmpDir,
+ pattern: '.github/workflows/*.{yml,yaml}',
+ });
+
+ expect(result.files).toHaveLength(2);
+ expect(result.files).toContain('.github/workflows/ci.yml');
+ expect(result.files).toContain('.github/workflows/release.yaml');
+ expect(result.hint).toContain('hidden');
+ });
+
+ it('should not return a hint when pattern has no dot-prefixed segment', async () => {
+ await writeFile(path.join(tmpDir, 'a.ts'), 'a');
+
+ const result = await globLocalFiles({ cwd: tmpDir, pattern: '*.ts' });
+
+ expect(result.hint).toBeUndefined();
+ });
+
+ it('should treat ./ and ../ as relative path indicators, not hidden segments', async () => {
+ await writeFile(path.join(tmpDir, 'a.ts'), 'a');
+
+ const result = await globLocalFiles({ cwd: tmpDir, pattern: './*.ts' });
+
+ expect(result.hint).toBeUndefined();
+ });
});
// ─── grepContent ───
@@ -535,6 +567,29 @@ describe('file operations', () => {
const result = await grepContent({ cwd: tmpDir, pattern: 'xyz_not_found' });
expect(result.matches).toEqual([]);
});
+
+ it('should return a hidden-matching hint when filePattern contains a dot-prefixed segment', async () => {
+ // The hint is set regardless of whether rg is installed on the host β€”
+ // it signals to the agent why we're auto-enabling --hidden so a zero
+ // match doesn't look like a silent failure.
+ const result = await grepContent({
+ cwd: tmpDir,
+ filePattern: '.github/workflows/*.yml',
+ pattern: 'jobs',
+ });
+
+ expect(result.hint).toContain('hidden');
+ });
+
+ it('should not return a hint for a normal filePattern', async () => {
+ const result = await grepContent({
+ cwd: tmpDir,
+ filePattern: '*.ts',
+ pattern: 'jobs',
+ });
+
+ expect(result.hint).toBeUndefined();
+ });
});
// ─── searchLocalFiles ───
@@ -573,5 +628,17 @@ describe('file operations', () => {
expect(result).toEqual([]);
});
+
+ it('should find dot-prefixed files when keywords starts with a dot', async () => {
+ await writeFile(path.join(tmpDir, '.env'), 'A=1');
+ await writeFile(path.join(tmpDir, '.envrc'), 'export A=1');
+ await writeFile(path.join(tmpDir, 'env.txt'), 'unrelated');
+
+ const result = await searchLocalFiles({ directory: tmpDir, keywords: '.env' });
+
+ const names = result.map((r) => r.name);
+ expect(names).toContain('.env');
+ expect(names).toContain('.envrc');
+ });
});
});
diff --git a/packages/local-file-shell/src/file/glob.ts b/packages/local-file-shell/src/file/glob.ts
index d09ad9990d2..13fa316b2eb 100644
--- a/packages/local-file-shell/src/file/glob.ts
+++ b/packages/local-file-shell/src/file/glob.ts
@@ -2,14 +2,28 @@ import fg from 'fast-glob';
import type { GlobFilesParams, GlobFilesResult } from '../types';
import { expandTilde } from './expandTilde';
+import { hasHiddenSegment } from './hasHiddenSegment';
export async function globLocalFiles({ pattern, cwd }: GlobFilesParams): Promise<GlobFilesResult> {
try {
+ // When the pattern explicitly references a dot-prefixed segment (e.g.
+ // `.github/workflows/*.yml`), the caller clearly wants to traverse a
+ // hidden directory β€” auto-enable hidden matching so it doesn't silently
+ // return zero results.
+ const wantsHidden = hasHiddenSegment(pattern);
+
const files = await fg(pattern, {
cwd: expandTilde(cwd) || process.cwd(),
- dot: false,
+ dot: wantsHidden,
ignore: ['**/node_modules/**', '**/.git/**'],
});
+
+ if (wantsHidden) {
+ return {
+ files,
+ hint: `Auto-enabled hidden-file matching because pattern contains a dot-prefixed segment.`,
+ };
+ }
return { files };
} catch (error) {
return { error: (error as Error).message, files: [] };
diff --git a/packages/local-file-shell/src/file/grep.ts b/packages/local-file-shell/src/file/grep.ts
index 510b3c0db7f..5256a5db7e6 100644
--- a/packages/local-file-shell/src/file/grep.ts
+++ b/packages/local-file-shell/src/file/grep.ts
@@ -2,14 +2,27 @@ import { spawn } from 'node:child_process';
import type { GrepContentParams, GrepContentResult } from '../types';
import { expandTilde } from './expandTilde';
+import { hasHiddenSegment } from './hasHiddenSegment';
export async function grepContent({
pattern,
cwd,
filePattern,
}: GrepContentParams): Promise<GrepContentResult> {
+ // When the filePattern explicitly references a dot-prefixed segment, the
+ // caller wants to scan inside a hidden directory β€” pass `--hidden` to rg so
+ // it doesn't silently skip these paths. We still rely on rg's built-in
+ // `.git/` exclusion via .gitignore semantics, plus add an explicit guard.
+ const wantsHidden = hasHiddenSegment(filePattern);
+ const hint = wantsHidden
+ ? `Auto-enabled hidden-file matching because filePattern contains a dot-prefixed segment.`
+ : undefined;
+
return new Promise<GrepContentResult>((resolve) => {
const args = ['--json', '-n'];
+ if (wantsHidden) {
+ args.push('--hidden', '--glob', '!**/.git/**');
+ }
if (filePattern) args.push('--glob', filePattern);
args.push(pattern);
@@ -25,7 +38,7 @@ export async function grepContent({
child.on('close', (code) => {
if (code !== 0 && code !== 1) {
- resolve({ matches: [], success: false });
+ resolve({ hint, matches: [], success: false });
return;
}
@@ -42,14 +55,14 @@ export async function grepContent({
})
.filter(Boolean);
- resolve({ matches, success: true });
+ resolve({ hint, matches, success: true });
} catch {
- resolve({ matches: [], success: true });
+ resolve({ hint, matches: [], success: true });
}
});
child.on('error', () => {
- resolve({ matches: [], success: false });
+ resolve({ hint, matches: [], success: false });
});
});
}
diff --git a/packages/local-file-shell/src/file/hasHiddenSegment.ts b/packages/local-file-shell/src/file/hasHiddenSegment.ts
new file mode 100644
index 00000000000..a03778d6edb
--- /dev/null
+++ b/packages/local-file-shell/src/file/hasHiddenSegment.ts
@@ -0,0 +1,13 @@
+/**
+ * Detect whether a glob pattern (or path) contains a dot-prefixed segment such
+ * as `.github`, `.husky`, or `foo/.config`. Used to auto-enable hidden-file
+ * matching when the caller's intent is clearly to traverse a hidden directory
+ * β€” otherwise `fast-glob` (`dot: false`) and `ripgrep` (no `--hidden`) silently
+ * return zero results.
+ *
+ * Skips `.` and `..` (relative path indicators), which are not hidden segments.
+ */
+export const HIDDEN_SEGMENT_RE = /(?:^|\/)\.[^./]/;
+
+export const hasHiddenSegment = (pattern: string | undefined): boolean =>
+ !!pattern && HIDDEN_SEGMENT_RE.test(pattern);
diff --git a/packages/local-file-shell/src/file/search.ts b/packages/local-file-shell/src/file/search.ts
index 93c2c8aa4bf..d29a137a2a1 100644
--- a/packages/local-file-shell/src/file/search.ts
+++ b/packages/local-file-shell/src/file/search.ts
@@ -14,9 +14,12 @@ export async function searchLocalFiles({
}: SearchFilesParams): Promise<SearchFilesResult[]> {
try {
const cwd = expandTilde(directory) || process.cwd();
+ // If the caller is searching for a dot-prefixed name (e.g. `.env`, `.github`),
+ // auto-enable hidden matching so the file/directory is actually reachable.
+ const wantsHidden = keywords.startsWith('.');
const files = await fg(`**/*${keywords}*`, {
cwd,
- dot: false,
+ dot: wantsHidden,
ignore: ['**/node_modules/**', '**/.git/**'],
});
diff --git a/packages/local-file-shell/src/types.ts b/packages/local-file-shell/src/types.ts
index dba34ba3233..b7489485713 100644
--- a/packages/local-file-shell/src/types.ts
+++ b/packages/local-file-shell/src/types.ts
@@ -124,6 +124,8 @@ export interface GlobFilesParams {
export interface GlobFilesResult {
error?: string;
files: string[];
+ /** Diagnostic note returned when the engine had to adjust behavior, e.g. auto-enabling hidden-file matching. */
+ hint?: string;
}
export interface SearchFilesParams {
@@ -173,6 +175,8 @@ export interface GrepContentParams {
export interface GrepContentResult {
error?: string;
+ /** Diagnostic note returned when the engine had to adjust behavior, e.g. auto-enabling hidden-file matching. */
+ hint?: string;
matches: any[];
success: boolean;
}