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(builtin-tool-local-system): honor glob scope in local system tool (#13875)

Inneie487bcd8a1ea
diff --git a/packages/builtin-tool-local-system/src/ExecutionRuntime/index.ts b/packages/builtin-tool-local-system/src/ExecutionRuntime/index.ts
index 74c91a69950..70abe2df5e0 100644
--- a/packages/builtin-tool-local-system/src/ExecutionRuntime/index.ts
+++ b/packages/builtin-tool-local-system/src/ExecutionRuntime/index.ts
@@ -128,6 +128,13 @@ export class LocalSystemExecutionRuntime extends ComputerRuntime {
return { fullContent: params.fullContent, loc, path: params.path };
}
+ case 'globLocalFiles': {
+ return {
+ pattern: params.pattern,
+ scope: params.directory,
+ };
+ }
+
default: {
return params;
}
diff --git a/packages/builtin-tool-local-system/src/executor/index.test.ts b/packages/builtin-tool-local-system/src/executor/index.test.ts
new file mode 100644
index 00000000000..d8dba80db65
--- /dev/null
+++ b/packages/builtin-tool-local-system/src/executor/index.test.ts
@@ -0,0 +1,39 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { localSystemExecutor } from './index';
+
+const { globFilesMock } = vi.hoisted(() => ({
+ globFilesMock: vi.fn(),
+}));
+
+vi.mock('@/services/electron/localFileService', () => ({
+ localFileService: {
+ globFiles: globFilesMock,
+ },
+}));
+
+describe('LocalSystemExecutor', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ });
+
+ describe('globLocalFiles', () => {
+ it('should preserve scope and relative pattern when delegating glob search', async () => {
+ globFilesMock.mockResolvedValue({
+ files: ['/tmp/images/a.png'],
+ success: true,
+ total_files: 1,
+ });
+
+ await localSystemExecutor.globLocalFiles({
+ pattern: '**/*.{png,jpg,jpeg,gif,webp}',
+ scope: '/tmp/images',
+ });
+
+ expect(globFilesMock).toHaveBeenCalledWith({
+ pattern: '**/*.{png,jpg,jpeg,gif,webp}',
+ scope: '/tmp/images',
+ });
+ });
+ });
+});
diff --git a/packages/builtin-tool-local-system/src/executor/index.ts b/packages/builtin-tool-local-system/src/executor/index.ts
index f06eada6ccf..4612ec758e1 100644
--- a/packages/builtin-tool-local-system/src/executor/index.ts
+++ b/packages/builtin-tool-local-system/src/executor/index.ts
@@ -219,9 +219,9 @@ class LocalSystemExecutor extends BaseExecutor<typeof LocalSystemApiEnum> {
globLocalFiles = async (params: GlobFilesParams): Promise<BuiltinToolResult> => {
try {
- const resolvedParams = resolveArgsWithScope(params, 'pattern');
const result = await this.runtime.globFiles({
- pattern: resolvedParams.pattern,
+ directory: params.scope,
+ pattern: params.pattern,
});
return this.toResult(result);
} catch (error) {