import { WarpGrepProvider } from './tools/warp_grep/providers/types.js'; import { RetryConfig } from './tools/utils/resilience.js'; /** * Remote command executors for sandbox environments. * Each function returns raw stdout - SDK handles all parsing internally. * * @example * ```typescript * const tool = createWarpGrepTool({ * repoRoot: '/home/repo', * remoteCommands: { * grep: async (pattern, path) => { * const r = await sandbox.grep(pattern, path); * return r.content.map((item) => item.path); * }, * read: async (path, start, end) => { * const r = await sandbox.readFile(path); * return r.content.slice(start - 1, end); * }, * listDir: async (path, maxDepth) => { * const r = await sandbox.listDir(path, maxDepth); * return r.content.map((item) => item.path); * }, * }, * }); * ``` */ interface RemoteCommands { /** * Run ripgrep search. Return file paths. * * @param pattern - Regex pattern to search for * @param path - Directory or file path to search in * @param glob - Optional glob pattern to filter files (e.g., "*.ts") * @returns File paths */ grep: (pattern: string, path: string, glob?: string) => Promise; /** * Read file lines. Return raw file content. * SDK will add line numbers automatically. * * @param path - File path to read * @param start - Start line number (1-based) * @param end - End line number (1-based, inclusive) * @returns Raw file content (lines between start and end) */ read: (path: string, start: number, end: number) => Promise; /** * List directory contents. Return one path per line. * Expected format: output from `find` command (one absolute/relative path per line) * * @param path - Directory path to list * @param maxDepth - Maximum depth to traverse * @returns Raw stdout from find/ls command (one path per line) */ listDir: (path: string, maxDepth: number) => Promise; } /** * Configuration for WarpGrepClient */ interface WarpGrepClientConfig { /** Morph API key (defaults to MORPH_API_KEY env var) */ morphApiKey?: string; /** Morph API base URL */ morphApiUrl?: string; /** Code search base URL (defaults to https://api.morphllm.com) */ codeSearchUrl?: string; /** Enable debug logging */ debug?: boolean; /** Request timeout in milliseconds */ timeout?: number; /** Retry configuration */ retryConfig?: RetryConfig; } /** * Input for warp grep execution */ interface WarpGrepInput { /** Search term describing what to find in the codebase */ searchTerm: string; /** Root directory of the repository to search */ repoRoot: string; /** Remote command executors for sandbox environments */ remoteCommands?: RemoteCommands; /** Optional custom provider (defaults to LocalRipgrepProvider). Use remoteCommands for simpler remote setup. */ provider?: WarpGrepProvider; /** Glob patterns to exclude from search */ excludes?: string[]; /** Glob patterns to include in search */ includes?: string[]; /** Enable debug logging for this request */ debug?: boolean; /** * When true, returns an AsyncGenerator that yields WarpGrepStep for each turn, * allowing you to show the user what WarpGrep is doing in real-time. */ streamSteps?: boolean; /** Search type hint. Use 'node_modules' to search inside normally-excluded dependency directories. */ search_type?: 'default' | 'node_modules'; } /** * Input for searching a public GitHub repository */ interface GitHubSearchInput { /** Search term describing what to find in the repository */ searchTerm: string; /** GitHub URL or "owner/repo" shorthand */ github: string; /** Branch to search (defaults to repo's default branch) */ branch?: string; /** Stream intermediate steps */ streamSteps?: boolean; } /** * A single context result with file path and content */ interface WarpGrepContext { /** File path relative to repo root */ file: string; /** Content of the relevant code section */ content: string; /** Line ranges returned (e.g. [[1,50],[100,150]]) or '*' for full file */ lines?: '*' | Array<[number, number]>; } /** * Result from warp grep execution */ interface WarpGrepResult { /** Whether the search completed successfully */ success: boolean; /** Relevant code contexts found */ contexts?: WarpGrepContext[]; /** Summary of what was found */ summary?: string; /** Error message if search failed */ error?: string; } type GitHubSearchToolConfig = Pick; /** * Input for reading a single file from a public GitHub repository */ interface GitHubReadFileInput { /** GitHub URL or "owner/repo" shorthand */ github: string; /** File path within the repository */ path: string; /** Start line number (1-based). Omit to start from beginning. */ startLine?: number; /** End line number (1-based, inclusive). Omit to read to the end. */ endLine?: number; /** Branch to read from (defaults to main/master) */ branch?: string; } /** * Result from reading a GitHub file */ interface GitHubReadFileResult { success: boolean; /** File content with line numbers (format: " lineNum|content") */ content?: string; /** Resolved file path */ path?: string; /** Resolved owner/repo */ github?: string; /** Resolved branch */ branch?: string; /** Lines returned (startLine, endLine) */ lineRange?: [number, number]; /** Total lines in the file */ totalLines?: number; /** Error message if read failed */ error?: string; } type GitHubReadFileToolConfig = Pick; /** * Configuration for creating a warp grep tool */ interface WarpGrepToolConfig { /** Root directory of the repository to search */ repoRoot: string; /** Remote command executors for sandbox environments. Simplest way to run in remote sandboxes. */ remoteCommands?: RemoteCommands; /** Optional custom provider (defaults to LocalRipgrepProvider). Use remoteCommands for simpler remote setup. */ provider?: WarpGrepProvider; /** Glob patterns to exclude from search */ excludes?: string[]; /** Glob patterns to include in search */ includes?: string[]; /** Enable debug logging */ debug?: boolean; /** Morph API key (defaults to MORPH_API_KEY env var) */ morphApiKey?: string; /** Morph API base URL */ morphApiUrl?: string; /** Retry configuration */ retryConfig?: RetryConfig; /** Timeout for model calls in ms (defaults to MORPH_WARP_GREP_TIMEOUT env var, then 30000) */ timeout?: number; /** Custom tool name (defaults to 'codebase_search') */ name?: string; /** Custom tool description */ description?: string; /** Search type hint. Use 'node_modules' to search inside normally-excluded dependency directories. */ search_type?: 'default' | 'node_modules'; } export type { GitHubSearchInput as G, RemoteCommands as R, WarpGrepClientConfig as W, WarpGrepInput as a, WarpGrepResult as b, WarpGrepContext as c, WarpGrepToolConfig as d, GitHubReadFileInput as e, GitHubReadFileResult as f, GitHubSearchToolConfig as g, GitHubReadFileToolConfig as h };