diff --git a/packages/core/src/filesystem.ts b/packages/core/src/filesystem.ts index b159e0fc400..17db28145b1 100644 --- a/packages/core/src/filesystem.ts +++ b/packages/core/src/filesystem.ts @@ -32,6 +32,7 @@ export type ListInput = typeof ListInput.Type export { FindInput } export const DEFAULT_SEARCH_LIMIT = 100 +export const DEFAULT_SEARCH_TIMEOUT_MS = 30_000 export class GlobInput extends Schema.Class("FileSystem.GlobInput")({ pattern: Schema.String, diff --git a/packages/core/src/tool/plugin/glob.ts b/packages/core/src/tool/plugin/glob.ts index 0f75bf92d4f..71ea80bbff5 100644 --- a/packages/core/src/tool/plugin/glob.ts +++ b/packages/core/src/tool/plugin/glob.ts @@ -104,6 +104,15 @@ export const Plugin = { limit: limit + 1, }) .pipe( + Effect.timeoutOrElse({ + duration: FileSystem.DEFAULT_SEARCH_TIMEOUT_MS, + orElse: () => + Effect.fail( + new ToolFailure({ + message: `Search timed out after ${FileSystem.DEFAULT_SEARCH_TIMEOUT_MS / 1_000} seconds. Consider using a more specific path or pattern.`, + }), + ), + }), Effect.map((result) => result.map((entry) => FileSystem.Entry.make({ diff --git a/packages/core/src/tool/plugin/grep.ts b/packages/core/src/tool/plugin/grep.ts index 46e0de04a6d..3c6d9b77b4d 100644 --- a/packages/core/src/tool/plugin/grep.ts +++ b/packages/core/src/tool/plugin/grep.ts @@ -118,6 +118,15 @@ export const Plugin = { limit: limit + 1, }) .pipe( + Effect.timeoutOrElse({ + duration: FileSystem.DEFAULT_SEARCH_TIMEOUT_MS, + orElse: () => + Effect.fail( + new ToolFailure({ + message: `Search timed out after ${FileSystem.DEFAULT_SEARCH_TIMEOUT_MS / 1_000} seconds. Consider using a more specific path or pattern.`, + }), + ), + }), Effect.map((result) => result.map((match) => FileSystem.Match.make({