@morphllm/morphsdk 0.2.21 → 0.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/dist/{chunk-BILUTNBC.js → chunk-4A7UBGLS.js} +2 -2
  2. package/dist/chunk-73RQWOQC.js +16 -0
  3. package/dist/chunk-73RQWOQC.js.map +1 -0
  4. package/dist/chunk-AFEPUNAO.js +15 -0
  5. package/dist/chunk-AFEPUNAO.js.map +1 -0
  6. package/dist/{chunk-VJK4PH5V.js → chunk-AG3ICTC5.js} +5 -2
  7. package/dist/chunk-AG3ICTC5.js.map +1 -0
  8. package/dist/chunk-EAA7D24N.js +201 -0
  9. package/dist/chunk-EAA7D24N.js.map +1 -0
  10. package/dist/chunk-EK7OQPWD.js +44 -0
  11. package/dist/chunk-EK7OQPWD.js.map +1 -0
  12. package/dist/chunk-G2RSY56Q.js +11 -0
  13. package/dist/chunk-G2RSY56Q.js.map +1 -0
  14. package/dist/chunk-GTOXMAF2.js +140 -0
  15. package/dist/chunk-GTOXMAF2.js.map +1 -0
  16. package/dist/chunk-HKZB23U7.js +85 -0
  17. package/dist/chunk-HKZB23U7.js.map +1 -0
  18. package/dist/{chunk-34F3D6JD.js → chunk-HWJN5AMA.js} +8 -8
  19. package/dist/chunk-LN4CTQZG.js +56 -0
  20. package/dist/chunk-LN4CTQZG.js.map +1 -0
  21. package/dist/chunk-NDZO5IPV.js +121 -0
  22. package/dist/chunk-NDZO5IPV.js.map +1 -0
  23. package/dist/chunk-RSLIOCOE.js +26 -0
  24. package/dist/chunk-RSLIOCOE.js.map +1 -0
  25. package/dist/chunk-S3GI7HNR.js +44 -0
  26. package/dist/chunk-S3GI7HNR.js.map +1 -0
  27. package/dist/chunk-SMGZ6A64.js +53 -0
  28. package/dist/chunk-SMGZ6A64.js.map +1 -0
  29. package/dist/chunk-TICMYDII.js +81 -0
  30. package/dist/chunk-TICMYDII.js.map +1 -0
  31. package/dist/chunk-UYBIKZPM.js +135 -0
  32. package/dist/chunk-UYBIKZPM.js.map +1 -0
  33. package/dist/chunk-VBBJGWHY.js +73 -0
  34. package/dist/chunk-VBBJGWHY.js.map +1 -0
  35. package/dist/chunk-W5CHJ6OX.js +53 -0
  36. package/dist/chunk-W5CHJ6OX.js.map +1 -0
  37. package/dist/{chunk-WXBUVKYL.js → chunk-WHZQDTM6.js} +2 -2
  38. package/dist/chunk-XYPMN4A3.js +1 -0
  39. package/dist/chunk-XYPMN4A3.js.map +1 -0
  40. package/dist/{chunk-YVGRWE7D.js → chunk-Y2IY7NYY.js} +2 -2
  41. package/dist/chunk-Z2FBMSNE.js +10 -0
  42. package/dist/chunk-Z2FBMSNE.js.map +1 -0
  43. package/dist/client.cjs +4 -1
  44. package/dist/client.cjs.map +1 -1
  45. package/dist/client.js +5 -5
  46. package/dist/index.cjs +4 -1
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.js +9 -9
  49. package/dist/tools/codebase_search/anthropic.cjs +4 -1
  50. package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
  51. package/dist/tools/codebase_search/anthropic.js +2 -2
  52. package/dist/tools/codebase_search/core.cjs +4 -1
  53. package/dist/tools/codebase_search/core.cjs.map +1 -1
  54. package/dist/tools/codebase_search/core.js +1 -1
  55. package/dist/tools/codebase_search/index.cjs +4 -1
  56. package/dist/tools/codebase_search/index.cjs.map +1 -1
  57. package/dist/tools/codebase_search/index.js +6 -6
  58. package/dist/tools/codebase_search/openai.cjs +4 -1
  59. package/dist/tools/codebase_search/openai.cjs.map +1 -1
  60. package/dist/tools/codebase_search/openai.js +2 -2
  61. package/dist/tools/codebase_search/types.cjs.map +1 -1
  62. package/dist/tools/codebase_search/vercel.cjs +4 -1
  63. package/dist/tools/codebase_search/vercel.cjs.map +1 -1
  64. package/dist/tools/codebase_search/vercel.js +2 -2
  65. package/dist/tools/warp_grep/agent/config.cjs +41 -0
  66. package/dist/tools/warp_grep/agent/config.cjs.map +1 -0
  67. package/dist/tools/warp_grep/agent/config.js +12 -0
  68. package/dist/tools/warp_grep/agent/config.js.map +1 -0
  69. package/dist/tools/warp_grep/agent/formatter.cjs +106 -0
  70. package/dist/tools/warp_grep/agent/formatter.cjs.map +1 -0
  71. package/dist/tools/warp_grep/agent/formatter.js +10 -0
  72. package/dist/tools/warp_grep/agent/formatter.js.map +1 -0
  73. package/dist/tools/warp_grep/agent/grep_helpers.cjs +148 -0
  74. package/dist/tools/warp_grep/agent/grep_helpers.cjs.map +1 -0
  75. package/dist/tools/warp_grep/agent/grep_helpers.js +14 -0
  76. package/dist/tools/warp_grep/agent/grep_helpers.js.map +1 -0
  77. package/dist/tools/warp_grep/agent/parser.cjs +165 -0
  78. package/dist/tools/warp_grep/agent/parser.cjs.map +1 -0
  79. package/dist/tools/warp_grep/agent/parser.js +10 -0
  80. package/dist/tools/warp_grep/agent/parser.js.map +1 -0
  81. package/dist/tools/warp_grep/agent/prompt.cjs +110 -0
  82. package/dist/tools/warp_grep/agent/prompt.cjs.map +1 -0
  83. package/dist/tools/warp_grep/agent/prompt.js +10 -0
  84. package/dist/tools/warp_grep/agent/prompt.js.map +1 -0
  85. package/dist/tools/warp_grep/agent/runner.cjs +744 -0
  86. package/dist/tools/warp_grep/agent/runner.cjs.map +1 -0
  87. package/dist/tools/warp_grep/agent/runner.js +17 -0
  88. package/dist/tools/warp_grep/agent/runner.js.map +1 -0
  89. package/dist/tools/warp_grep/agent/types.cjs +19 -0
  90. package/dist/tools/warp_grep/agent/types.cjs.map +1 -0
  91. package/dist/tools/warp_grep/agent/types.js +2 -0
  92. package/dist/tools/warp_grep/agent/types.js.map +1 -0
  93. package/dist/tools/warp_grep/anthropic.cjs +977 -0
  94. package/dist/tools/warp_grep/anthropic.cjs.map +1 -0
  95. package/dist/tools/warp_grep/anthropic.js +22 -0
  96. package/dist/tools/warp_grep/anthropic.js.map +1 -0
  97. package/dist/tools/warp_grep/index.cjs +1136 -0
  98. package/dist/tools/warp_grep/index.cjs.map +1 -0
  99. package/dist/tools/warp_grep/index.js +48 -0
  100. package/dist/tools/warp_grep/index.js.map +1 -0
  101. package/dist/tools/warp_grep/openai.cjs +980 -0
  102. package/dist/tools/warp_grep/openai.cjs.map +1 -0
  103. package/dist/tools/warp_grep/openai.js +22 -0
  104. package/dist/tools/warp_grep/openai.js.map +1 -0
  105. package/dist/tools/warp_grep/providers/command.cjs +98 -0
  106. package/dist/tools/warp_grep/providers/command.cjs.map +1 -0
  107. package/dist/tools/warp_grep/providers/command.js +9 -0
  108. package/dist/tools/warp_grep/providers/command.js.map +1 -0
  109. package/dist/tools/warp_grep/providers/local.cjs +232 -0
  110. package/dist/tools/warp_grep/providers/local.cjs.map +1 -0
  111. package/dist/tools/warp_grep/providers/local.js +12 -0
  112. package/dist/tools/warp_grep/providers/local.js.map +1 -0
  113. package/dist/tools/warp_grep/providers/types.cjs +19 -0
  114. package/dist/tools/warp_grep/providers/types.cjs.map +1 -0
  115. package/dist/tools/warp_grep/providers/types.js +1 -0
  116. package/dist/tools/warp_grep/providers/types.js.map +1 -0
  117. package/dist/tools/warp_grep/tools/analyse.cjs +40 -0
  118. package/dist/tools/warp_grep/tools/analyse.cjs.map +1 -0
  119. package/dist/tools/warp_grep/tools/analyse.js +8 -0
  120. package/dist/tools/warp_grep/tools/analyse.js.map +1 -0
  121. package/dist/tools/warp_grep/tools/finish.cjs +69 -0
  122. package/dist/tools/warp_grep/tools/finish.cjs.map +1 -0
  123. package/dist/tools/warp_grep/tools/finish.js +10 -0
  124. package/dist/tools/warp_grep/tools/finish.js.map +1 -0
  125. package/dist/tools/warp_grep/tools/grep.cjs +35 -0
  126. package/dist/tools/warp_grep/tools/grep.cjs.map +1 -0
  127. package/dist/tools/warp_grep/tools/grep.js +12 -0
  128. package/dist/tools/warp_grep/tools/grep.js.map +1 -0
  129. package/dist/tools/warp_grep/tools/read.cjs +34 -0
  130. package/dist/tools/warp_grep/tools/read.cjs.map +1 -0
  131. package/dist/tools/warp_grep/tools/read.js +8 -0
  132. package/dist/tools/warp_grep/tools/read.js.map +1 -0
  133. package/dist/tools/warp_grep/utils/files.cjs +45 -0
  134. package/dist/tools/warp_grep/utils/files.cjs.map +1 -0
  135. package/dist/tools/warp_grep/utils/files.js +8 -0
  136. package/dist/tools/warp_grep/utils/files.js.map +1 -0
  137. package/dist/tools/warp_grep/utils/format.cjs +42 -0
  138. package/dist/tools/warp_grep/utils/format.cjs.map +1 -0
  139. package/dist/tools/warp_grep/utils/format.js +18 -0
  140. package/dist/tools/warp_grep/utils/format.js.map +1 -0
  141. package/dist/tools/warp_grep/utils/paths.cjs +91 -0
  142. package/dist/tools/warp_grep/utils/paths.cjs.map +1 -0
  143. package/dist/tools/warp_grep/utils/paths.js +16 -0
  144. package/dist/tools/warp_grep/utils/paths.js.map +1 -0
  145. package/dist/tools/warp_grep/utils/ripgrep.cjs +50 -0
  146. package/dist/tools/warp_grep/utils/ripgrep.cjs.map +1 -0
  147. package/dist/tools/warp_grep/utils/ripgrep.js +8 -0
  148. package/dist/tools/warp_grep/utils/ripgrep.js.map +1 -0
  149. package/dist/tools/warp_grep/vercel.cjs +968 -0
  150. package/dist/tools/warp_grep/vercel.cjs.map +1 -0
  151. package/dist/tools/warp_grep/vercel.js +22 -0
  152. package/dist/tools/warp_grep/vercel.js.map +1 -0
  153. package/package.json +23 -3
  154. package/dist/anthropic-CknfcMoO.d.ts +0 -64
  155. package/dist/chunk-VJK4PH5V.js.map +0 -1
  156. package/dist/client.d.ts +0 -114
  157. package/dist/git/client.d.ts +0 -255
  158. package/dist/git/config.d.ts +0 -11
  159. package/dist/git/index.d.ts +0 -5
  160. package/dist/git/types.d.ts +0 -102
  161. package/dist/index.d.ts +0 -14
  162. package/dist/modelrouter/core.d.ts +0 -56
  163. package/dist/modelrouter/index.d.ts +0 -2
  164. package/dist/modelrouter/types.d.ts +0 -35
  165. package/dist/openai-BkKsS30n.d.ts +0 -111
  166. package/dist/tools/browser/anthropic.d.ts +0 -51
  167. package/dist/tools/browser/core.d.ts +0 -196
  168. package/dist/tools/browser/index.d.ts +0 -72
  169. package/dist/tools/browser/openai.d.ts +0 -69
  170. package/dist/tools/browser/prompts.d.ts +0 -7
  171. package/dist/tools/browser/types.d.ts +0 -227
  172. package/dist/tools/browser/vercel.d.ts +0 -69
  173. package/dist/tools/codebase_search/anthropic.d.ts +0 -40
  174. package/dist/tools/codebase_search/core.d.ts +0 -40
  175. package/dist/tools/codebase_search/index.d.ts +0 -10
  176. package/dist/tools/codebase_search/openai.d.ts +0 -87
  177. package/dist/tools/codebase_search/prompts.d.ts +0 -7
  178. package/dist/tools/codebase_search/types.d.ts +0 -46
  179. package/dist/tools/codebase_search/vercel.d.ts +0 -65
  180. package/dist/tools/fastapply/anthropic.d.ts +0 -4
  181. package/dist/tools/fastapply/core.d.ts +0 -41
  182. package/dist/tools/fastapply/index.d.ts +0 -10
  183. package/dist/tools/fastapply/openai.d.ts +0 -4
  184. package/dist/tools/fastapply/prompts.d.ts +0 -7
  185. package/dist/tools/fastapply/types.d.ts +0 -77
  186. package/dist/tools/fastapply/vercel.d.ts +0 -4
  187. package/dist/tools/index.d.ts +0 -10
  188. package/dist/tools/utils/resilience.d.ts +0 -58
  189. package/dist/vercel-B1GZ_g9N.d.ts +0 -69
  190. /package/dist/{chunk-BILUTNBC.js.map → chunk-4A7UBGLS.js.map} +0 -0
  191. /package/dist/{chunk-34F3D6JD.js.map → chunk-HWJN5AMA.js.map} +0 -0
  192. /package/dist/{chunk-WXBUVKYL.js.map → chunk-WHZQDTM6.js.map} +0 -0
  193. /package/dist/{chunk-YVGRWE7D.js.map → chunk-Y2IY7NYY.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../tools/codebase_search/vercel.ts","../../../tools/utils/resilience.ts","../../../tools/codebase_search/core.ts","../../../tools/codebase_search/prompts.ts"],"sourcesContent":["/**\n * Vercel AI SDK adapter for codebase_search tool\n */\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport { executeCodebaseSearch } from './core.js';\nimport { CODEBASE_SEARCH_DESCRIPTION } from './prompts.js';\nimport type { CodebaseSearchConfig } from './types.js';\n\n/**\n * Create Vercel AI SDK codebase_search tool\n * \n * @param config - Configuration with repoId\n * @returns Vercel AI SDK tool definition (execution built-in)\n * \n * @example\n * ```ts\n * import { generateText } from 'ai';\n * import { anthropic } from '@ai-sdk/anthropic';\n * import { createCodebaseSearchTool } from 'morphsdk/tools/codebase-search/vercel';\n * \n * const tool = createCodebaseSearchTool({ repoId: 'my-project' });\n * \n * const result = await generateText({\n * model: anthropic('claude-3-5-sonnet-20241022'),\n * tools: { codebaseSearch: tool },\n * prompt: \"Find authentication code\",\n * maxSteps: 5\n * });\n * \n * // Vercel AI SDK automatically executes and handles results\n * console.log(result.text);\n * ```\n */\nexport function createCodebaseSearchTool(config: CodebaseSearchConfig) {\n const schema = z.object({\n query: z.string().describe('A complete question about what you want to understand. Ask as if talking to a colleague: \"How does X work?\", \"What happens when Y?\", \"Where is Z handled?\"'),\n target_directories: z.array(z.string()).describe('Prefix directory paths to limit search scope (single directory only, no glob patterns). Use [] to search entire repo.'),\n explanation: z.string().describe('One sentence explanation as to why this tool is being used, and how it contributes to the goal.'),\n limit: z.number().optional().describe('Max results to return (default: 10)'),\n });\n\n return tool({\n description: CODEBASE_SEARCH_DESCRIPTION,\n inputSchema: schema,\n execute: async (params) => {\n const { query, target_directories, explanation, limit } = params;\n const result = await executeCodebaseSearch(\n { query, target_directories, explanation, limit },\n config\n );\n\n if (!result.success) {\n return {\n error: result.error,\n results: [],\n };\n }\n\n // Format results for Vercel AI SDK\n return {\n found: result.results.length,\n searchTime: `${result.stats.searchTimeMs}ms`,\n results: result.results.map(r => ({\n file: r.filepath,\n symbol: r.symbolPath,\n lines: `${r.startLine}-${r.endLine}`,\n language: r.language,\n relevance: `${(r.rerankScore * 100).toFixed(1)}%`,\n code: r.content,\n })),\n };\n },\n });\n}\n\n/**\n * Get system prompt for Vercel AI SDK\n */\nexport function getSystemPrompt(): string {\n return CODEBASE_SEARCH_DESCRIPTION;\n}\n\n/**\n * Default export\n */\nexport default { createCodebaseSearchTool, getSystemPrompt };\n\n","/**\n * Resilience utilities for retry logic and timeout handling\n */\n\nexport interface RetryConfig {\n maxRetries?: number; // Default: 3\n initialDelay?: number; // Default: 1000ms\n maxDelay?: number; // Default: 30000ms\n backoffMultiplier?: number; // Default: 2\n retryableErrors?: string[]; // Default: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND']\n onRetry?: (attempt: number, error: Error) => void;\n}\n\nconst DEFAULT_RETRY_CONFIG: Required<Omit<RetryConfig, 'onRetry'>> = {\n maxRetries: 3,\n initialDelay: 1000,\n maxDelay: 30000,\n backoffMultiplier: 2,\n retryableErrors: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND'],\n};\n\n/**\n * Retry a fetch request with exponential backoff\n * \n * @param url - Request URL\n * @param options - Fetch options\n * @param retryConfig - Retry configuration\n * @returns Response from fetch\n * \n * @example\n * ```typescript\n * const response = await fetchWithRetry(\n * 'https://api.example.com/data',\n * { method: 'POST', body: JSON.stringify(data) },\n * { maxRetries: 5, initialDelay: 500 }\n * );\n * ```\n */\nexport async function fetchWithRetry(\n url: string,\n options: RequestInit,\n retryConfig: RetryConfig = {}\n): Promise<Response> {\n const {\n maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,\n initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,\n maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,\n backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,\n retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,\n onRetry,\n } = retryConfig;\n\n let lastError: Error | null = null;\n let delay = initialDelay;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n const response = await fetch(url, options);\n \n // Retry on 429 (rate limit) or 503 (service unavailable)\n if (response.status === 429 || response.status === 503) {\n if (attempt < maxRetries) {\n // Check for Retry-After header\n const retryAfter = response.headers.get('Retry-After');\n const waitTime = retryAfter \n ? parseInt(retryAfter) * 1000 \n : Math.min(delay, maxDelay);\n \n const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);\n if (onRetry) {\n onRetry(attempt + 1, error);\n }\n \n await sleep(waitTime);\n delay *= backoffMultiplier;\n continue;\n }\n }\n\n return response;\n } catch (error) {\n lastError = error as Error;\n \n // Check if error is retryable\n const isRetryable = retryableErrors.some(errType => \n lastError?.message?.includes(errType)\n );\n\n if (!isRetryable || attempt === maxRetries) {\n throw lastError;\n }\n\n // Exponential backoff\n const waitTime = Math.min(delay, maxDelay);\n if (onRetry) {\n onRetry(attempt + 1, lastError);\n }\n \n await sleep(waitTime);\n delay *= backoffMultiplier;\n }\n }\n\n throw lastError || new Error('Max retries exceeded');\n}\n\n/**\n * Add timeout to any promise\n * \n * @param promise - Promise to wrap with timeout\n * @param timeoutMs - Timeout in milliseconds\n * @param errorMessage - Optional custom error message\n * @returns Promise that rejects if timeout is reached\n * \n * @example\n * ```typescript\n * const result = await withTimeout(\n * fetchData(),\n * 5000,\n * 'Data fetch timed out'\n * );\n * ```\n */\nexport async function withTimeout<T>(\n promise: Promise<T>,\n timeoutMs: number,\n errorMessage?: string\n): Promise<T> {\n let timeoutId: NodeJS.Timeout | number;\n \n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutId = setTimeout(() => {\n reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n });\n\n try {\n const result = await Promise.race([promise, timeoutPromise]);\n clearTimeout(timeoutId!);\n return result;\n } catch (error) {\n clearTimeout(timeoutId!);\n throw error;\n }\n}\n\n/**\n * Sleep for specified milliseconds\n */\nfunction sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Unified error type for all tools\n */\nexport class MorphError extends Error {\n constructor(\n message: string,\n public code: string,\n public statusCode?: number,\n public retryable: boolean = false\n ) {\n super(message);\n this.name = 'MorphError';\n }\n}\n\n\n","/**\n * Core implementation for codebase search\n * Calls Morph rerank service for two-stage semantic search\n */\n\nimport { fetchWithRetry, withTimeout } from '../utils/resilience.js';\nimport type { CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult } from './types.js';\n\n/**\n * CodebaseSearch client for programmatic semantic search\n */\nexport class CodebaseSearchClient {\n private config: { \n apiKey?: string; \n searchUrl?: string; \n debug?: boolean; \n timeout?: number; \n retryConfig?: any;\n };\n\n constructor(config: { apiKey?: string; debug?: boolean; timeout?: number; retryConfig?: any } = {}) {\n this.config = {\n apiKey: config.apiKey,\n searchUrl: process.env.MORPH_SEARCH_URL || 'http://embedrerank.morphllm.com:8081',\n debug: config.debug,\n timeout: config.timeout || 30000,\n retryConfig: config.retryConfig,\n };\n }\n\n /**\n * Execute a semantic code search\n * \n * @param input - Search parameters including query, repoId, and target directories\n * @param overrides - Optional config overrides for this operation\n * @returns Search results with ranked code matches\n */\n async search(\n input: { query: string; repoId: string; target_directories?: string[]; explanation?: string; limit?: number },\n overrides?: any\n ): Promise<CodebaseSearchResult> {\n return executeCodebaseSearch(\n {\n query: input.query,\n target_directories: input.target_directories,\n explanation: input.explanation,\n limit: input.limit,\n },\n { ...this.config, repoId: input.repoId, ...overrides }\n );\n }\n}\n\n/**\n * Execute semantic code search\n */\nexport async function executeCodebaseSearch(\n input: CodebaseSearchInput,\n config: CodebaseSearchConfig\n): Promise<CodebaseSearchResult> {\n const apiKey = config.apiKey || process.env.MORPH_API_KEY;\n if (!apiKey) {\n throw new Error('MORPH_API_KEY not found. Set environment variable or pass in config');\n }\n\n const searchUrl = config.searchUrl || process.env.MORPH_SEARCH_URL || 'http://embedrerank.morphllm.com:8081';\n const timeout = config.timeout || 30000;\n const debug = config.debug || false;\n\n if (debug) {\n console.log(`[CodebaseSearch] Query: \"${input.query.slice(0, 60)}...\" repo=${config.repoId}`);\n console.log(`[CodebaseSearch] URL: ${searchUrl}/v1/codebase_search`);\n }\n\n const startTime = Date.now();\n\n try {\n const fetchPromise = fetchWithRetry(\n `${searchUrl}/v1/codebase_search`,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${apiKey}`,\n },\n body: JSON.stringify({\n query: input.query,\n repoId: config.repoId,\n targetDirectories: input.target_directories || [],\n limit: input.limit || 10,\n candidateLimit: 50,\n }),\n },\n config.retryConfig\n );\n\n const response = await withTimeout(fetchPromise, timeout, `Codebase search timed out after ${timeout}ms`);\n\n if (!response.ok) {\n const errorText = await response.text();\n if (debug) console.error(`[CodebaseSearch] Error: ${response.status} - ${errorText}`);\n return {\n success: false,\n results: [],\n stats: { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 },\n error: `Search failed (${response.status}): ${errorText}`,\n };\n }\n\n const data = await response.json();\n const elapsed = Date.now() - startTime;\n\n if (debug) {\n console.log(`[CodebaseSearch] ✅ ${data.results?.length || 0} results in ${elapsed}ms`);\n }\n\n return {\n success: true,\n results: data.results || [],\n stats: data.stats || { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: elapsed },\n };\n\n } catch (error) {\n if (debug) console.error(`[CodebaseSearch] Exception: ${error instanceof Error ? error.message : error}`);\n return {\n success: false,\n results: [],\n stats: { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 },\n error: error instanceof Error ? error.message : 'Unknown error',\n };\n }\n}\n\n","/**\n * Tool descriptions and system prompts for codebase search\n */\n\nexport const CODEBASE_SEARCH_DESCRIPTION = `Semantic search that finds code by meaning, not exact text.\n\nUse this to explore unfamiliar codebases or ask \"how/where/what\" questions:\n- \"How does X work?\" - Find implementation details\n- \"Where is Y handled?\" - Locate specific functionality\n- \"What happens when Z?\" - Understand flow\n\nThe tool uses two-stage retrieval (embedding similarity + reranking) to find the most semantically relevant code chunks.\n\nReturns code chunks with file paths, line ranges, and full content ranked by relevance.`;\n\nexport const CODEBASE_SEARCH_SYSTEM_PROMPT = `You have access to the codebase_search tool that performs semantic code search.\n\nWhen searching:\n- Use natural language queries describing what you're looking for\n- Be specific about functionality, not variable names\n- Use target_directories to narrow search if you know the area\n- Results are ranked by relevance (rerank score is most important)\n\nThe tool returns:\n- File paths with symbol names (e.g. \"src/auth.ts::AuthService@L1-L17\")\n- Line ranges for precise navigation\n- Full code content for each match\n- Dual relevance scores: embedding similarity + rerank score\n\nUse results to understand code or answer questions. The content is provided in full - avoid re-reading unless you need more context.`;\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,gBAAqB;AACrB,iBAAkB;;;ACQlB,IAAM,uBAA+D;AAAA,EACnE,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,iBAAiB,CAAC,gBAAgB,aAAa,WAAW;AAC5D;AAmBA,eAAsB,eACpB,KACA,SACA,cAA2B,CAAC,GACT;AACnB,QAAM;AAAA,IACJ,aAAa,qBAAqB;AAAA,IAClC,eAAe,qBAAqB;AAAA,IACpC,WAAW,qBAAqB;AAAA,IAChC,oBAAoB,qBAAqB;AAAA,IACzC,kBAAkB,qBAAqB;AAAA,IACvC;AAAA,EACF,IAAI;AAEJ,MAAI,YAA0B;AAC9B,MAAI,QAAQ;AAEZ,WAAS,UAAU,GAAG,WAAW,YAAY,WAAW;AACtD,QAAI;AACF,YAAM,WAAW,MAAM,MAAM,KAAK,OAAO;AAGzC,UAAI,SAAS,WAAW,OAAO,SAAS,WAAW,KAAK;AACtD,YAAI,UAAU,YAAY;AAExB,gBAAM,aAAa,SAAS,QAAQ,IAAI,aAAa;AACrD,gBAAM,WAAW,aACb,SAAS,UAAU,IAAI,MACvB,KAAK,IAAI,OAAO,QAAQ;AAE5B,gBAAM,QAAQ,IAAI,MAAM,QAAQ,SAAS,MAAM,oBAAoB,QAAQ,IAAI;AAC/E,cAAI,SAAS;AACX,oBAAQ,UAAU,GAAG,KAAK;AAAA,UAC5B;AAEA,gBAAM,MAAM,QAAQ;AACpB,mBAAS;AACT;AAAA,QACF;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A,UAClC,UAAU,EAAE;AAAA,UACZ,WAAW,IAAI,EAAE,cAAc,KAAK,QAAQ,CAAC,CAAC;AAAA,UAC9C,MAAM,EAAE;AAAA,QACV,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAKO,SAAS,kBAA0B;AACxC,SAAO;AACT;AAKA,IAAO,iBAAQ,EAAE,0BAA0B,gBAAgB;","names":[]}
1
+ {"version":3,"sources":["../../../tools/codebase_search/vercel.ts","../../../tools/utils/resilience.ts","../../../tools/codebase_search/core.ts","../../../tools/codebase_search/prompts.ts"],"sourcesContent":["/**\n * Vercel AI SDK adapter for codebase_search tool\n */\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport { executeCodebaseSearch } from './core.js';\nimport { CODEBASE_SEARCH_DESCRIPTION } from './prompts.js';\nimport type { CodebaseSearchConfig } from './types.js';\n\n/**\n * Create Vercel AI SDK codebase_search tool\n * \n * @param config - Configuration with repoId\n * @returns Vercel AI SDK tool definition (execution built-in)\n * \n * @example\n * ```ts\n * import { generateText } from 'ai';\n * import { anthropic } from '@ai-sdk/anthropic';\n * import { createCodebaseSearchTool } from 'morphsdk/tools/codebase-search/vercel';\n * \n * const tool = createCodebaseSearchTool({ repoId: 'my-project' });\n * \n * const result = await generateText({\n * model: anthropic('claude-3-5-sonnet-20241022'),\n * tools: { codebaseSearch: tool },\n * prompt: \"Find authentication code\",\n * maxSteps: 5\n * });\n * \n * // Vercel AI SDK automatically executes and handles results\n * console.log(result.text);\n * ```\n */\nexport function createCodebaseSearchTool(config: CodebaseSearchConfig) {\n const schema = z.object({\n query: z.string().describe('A complete question about what you want to understand. Ask as if talking to a colleague: \"How does X work?\", \"What happens when Y?\", \"Where is Z handled?\"'),\n target_directories: z.array(z.string()).describe('Prefix directory paths to limit search scope (single directory only, no glob patterns). Use [] to search entire repo.'),\n explanation: z.string().describe('One sentence explanation as to why this tool is being used, and how it contributes to the goal.'),\n limit: z.number().optional().describe('Max results to return (default: 10)'),\n });\n\n return tool({\n description: CODEBASE_SEARCH_DESCRIPTION,\n inputSchema: schema,\n execute: async (params) => {\n const { query, target_directories, explanation, limit } = params;\n const result = await executeCodebaseSearch(\n { query, target_directories, explanation, limit },\n config\n );\n\n if (!result.success) {\n return {\n error: result.error,\n results: [],\n };\n }\n\n // Format results for Vercel AI SDK\n return {\n found: result.results.length,\n searchTime: `${result.stats.searchTimeMs}ms`,\n results: result.results.map(r => ({\n file: r.filepath,\n symbol: r.symbolPath,\n lines: `${r.startLine}-${r.endLine}`,\n language: r.language,\n relevance: `${(r.rerankScore * 100).toFixed(1)}%`,\n code: r.content,\n })),\n };\n },\n });\n}\n\n/**\n * Get system prompt for Vercel AI SDK\n */\nexport function getSystemPrompt(): string {\n return CODEBASE_SEARCH_DESCRIPTION;\n}\n\n/**\n * Default export\n */\nexport default { createCodebaseSearchTool, getSystemPrompt };\n\n","/**\n * Resilience utilities for retry logic and timeout handling\n */\n\nexport interface RetryConfig {\n maxRetries?: number; // Default: 3\n initialDelay?: number; // Default: 1000ms\n maxDelay?: number; // Default: 30000ms\n backoffMultiplier?: number; // Default: 2\n retryableErrors?: string[]; // Default: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND']\n onRetry?: (attempt: number, error: Error) => void;\n}\n\nconst DEFAULT_RETRY_CONFIG: Required<Omit<RetryConfig, 'onRetry'>> = {\n maxRetries: 3,\n initialDelay: 1000,\n maxDelay: 30000,\n backoffMultiplier: 2,\n retryableErrors: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND'],\n};\n\n/**\n * Retry a fetch request with exponential backoff\n * \n * @param url - Request URL\n * @param options - Fetch options\n * @param retryConfig - Retry configuration\n * @returns Response from fetch\n * \n * @example\n * ```typescript\n * const response = await fetchWithRetry(\n * 'https://api.example.com/data',\n * { method: 'POST', body: JSON.stringify(data) },\n * { maxRetries: 5, initialDelay: 500 }\n * );\n * ```\n */\nexport async function fetchWithRetry(\n url: string,\n options: RequestInit,\n retryConfig: RetryConfig = {}\n): Promise<Response> {\n const {\n maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,\n initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,\n maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,\n backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,\n retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,\n onRetry,\n } = retryConfig;\n\n let lastError: Error | null = null;\n let delay = initialDelay;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n const response = await fetch(url, options);\n \n // Retry on 429 (rate limit) or 503 (service unavailable)\n if (response.status === 429 || response.status === 503) {\n if (attempt < maxRetries) {\n // Check for Retry-After header\n const retryAfter = response.headers.get('Retry-After');\n const waitTime = retryAfter \n ? parseInt(retryAfter) * 1000 \n : Math.min(delay, maxDelay);\n \n const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);\n if (onRetry) {\n onRetry(attempt + 1, error);\n }\n \n await sleep(waitTime);\n delay *= backoffMultiplier;\n continue;\n }\n }\n\n return response;\n } catch (error) {\n lastError = error as Error;\n \n // Check if error is retryable\n const isRetryable = retryableErrors.some(errType => \n lastError?.message?.includes(errType)\n );\n\n if (!isRetryable || attempt === maxRetries) {\n throw lastError;\n }\n\n // Exponential backoff\n const waitTime = Math.min(delay, maxDelay);\n if (onRetry) {\n onRetry(attempt + 1, lastError);\n }\n \n await sleep(waitTime);\n delay *= backoffMultiplier;\n }\n }\n\n throw lastError || new Error('Max retries exceeded');\n}\n\n/**\n * Add timeout to any promise\n * \n * @param promise - Promise to wrap with timeout\n * @param timeoutMs - Timeout in milliseconds\n * @param errorMessage - Optional custom error message\n * @returns Promise that rejects if timeout is reached\n * \n * @example\n * ```typescript\n * const result = await withTimeout(\n * fetchData(),\n * 5000,\n * 'Data fetch timed out'\n * );\n * ```\n */\nexport async function withTimeout<T>(\n promise: Promise<T>,\n timeoutMs: number,\n errorMessage?: string\n): Promise<T> {\n let timeoutId: NodeJS.Timeout | number;\n \n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutId = setTimeout(() => {\n reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n });\n\n try {\n const result = await Promise.race([promise, timeoutPromise]);\n clearTimeout(timeoutId!);\n return result;\n } catch (error) {\n clearTimeout(timeoutId!);\n throw error;\n }\n}\n\n/**\n * Sleep for specified milliseconds\n */\nfunction sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Unified error type for all tools\n */\nexport class MorphError extends Error {\n constructor(\n message: string,\n public code: string,\n public statusCode?: number,\n public retryable: boolean = false\n ) {\n super(message);\n this.name = 'MorphError';\n }\n}\n\n\n","/**\n * Core implementation for codebase search\n * Calls Morph rerank service for two-stage semantic search\n */\n\nimport { fetchWithRetry, withTimeout } from '../utils/resilience.js';\nimport type { CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult } from './types.js';\n\n/**\n * CodebaseSearch client for programmatic semantic search\n */\nexport class CodebaseSearchClient {\n private config: { \n apiKey?: string; \n searchUrl?: string; \n debug?: boolean; \n timeout?: number; \n retryConfig?: any;\n };\n\n constructor(config: { apiKey?: string; debug?: boolean; timeout?: number; retryConfig?: any } = {}) {\n this.config = {\n apiKey: config.apiKey,\n searchUrl: process.env.MORPH_SEARCH_URL || 'http://embedrerank.morphllm.com:8081',\n debug: config.debug,\n timeout: config.timeout || 30000,\n retryConfig: config.retryConfig,\n };\n }\n\n /**\n * Execute a semantic code search\n * \n * @param input - Search parameters including query, repoId, and target directories\n * @param overrides - Optional config overrides for this operation\n * @returns Search results with ranked code matches\n */\n async search(\n input: { query: string; repoId: string; target_directories?: string[]; explanation?: string; limit?: number },\n overrides?: any\n ): Promise<CodebaseSearchResult> {\n return executeCodebaseSearch(\n {\n query: input.query,\n target_directories: input.target_directories,\n explanation: input.explanation,\n limit: input.limit,\n },\n { ...this.config, repoId: input.repoId, ...overrides }\n );\n }\n}\n\n/**\n * Execute semantic code search\n */\nexport async function executeCodebaseSearch(\n input: CodebaseSearchInput,\n config: CodebaseSearchConfig\n): Promise<CodebaseSearchResult> {\n const apiKey = config.apiKey || process.env.MORPH_API_KEY;\n if (!apiKey) {\n throw new Error('MORPH_API_KEY not found. Set environment variable or pass in config');\n }\n\n const searchUrl = config.searchUrl || process.env.MORPH_SEARCH_URL || 'http://embedrerank.morphllm.com:8081';\n const timeout = config.timeout || 30000;\n const debug = config.debug || false;\n\n if (debug) {\n const ref = config.commitHash ? `commit=${config.commitHash.slice(0, 8)}` : config.branch ? `branch=${config.branch}` : 'latest main';\n console.log(`[CodebaseSearch] Query: \"${input.query.slice(0, 60)}...\" repo=${config.repoId} (${ref})`);\n console.log(`[CodebaseSearch] URL: ${searchUrl}/v1/codebase_search`);\n }\n\n const startTime = Date.now();\n\n try {\n const fetchPromise = fetchWithRetry(\n `${searchUrl}/v1/codebase_search`,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${apiKey}`,\n },\n body: JSON.stringify({\n query: input.query,\n repoId: config.repoId,\n branch: config.branch,\n commitHash: config.commitHash,\n targetDirectories: input.target_directories || [],\n limit: input.limit || 10,\n candidateLimit: 50,\n }),\n },\n config.retryConfig\n );\n\n const response = await withTimeout(fetchPromise, timeout, `Codebase search timed out after ${timeout}ms`);\n\n if (!response.ok) {\n const errorText = await response.text();\n if (debug) console.error(`[CodebaseSearch] Error: ${response.status} - ${errorText}`);\n return {\n success: false,\n results: [],\n stats: { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 },\n error: `Search failed (${response.status}): ${errorText}`,\n };\n }\n\n const data = await response.json();\n const elapsed = Date.now() - startTime;\n\n if (debug) {\n console.log(`[CodebaseSearch] ✅ ${data.results?.length || 0} results in ${elapsed}ms`);\n }\n\n return {\n success: true,\n results: data.results || [],\n stats: data.stats || { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: elapsed },\n };\n\n } catch (error) {\n if (debug) console.error(`[CodebaseSearch] Exception: ${error instanceof Error ? error.message : error}`);\n return {\n success: false,\n results: [],\n stats: { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 },\n error: error instanceof Error ? error.message : 'Unknown error',\n };\n }\n}\n\n","/**\n * Tool descriptions and system prompts for codebase search\n */\n\nexport const CODEBASE_SEARCH_DESCRIPTION = `Semantic search that finds code by meaning, not exact text.\n\nUse this to explore unfamiliar codebases or ask \"how/where/what\" questions:\n- \"How does X work?\" - Find implementation details\n- \"Where is Y handled?\" - Locate specific functionality\n- \"What happens when Z?\" - Understand flow\n\nThe tool uses two-stage retrieval (embedding similarity + reranking) to find the most semantically relevant code chunks.\n\nReturns code chunks with file paths, line ranges, and full content ranked by relevance.`;\n\nexport const CODEBASE_SEARCH_SYSTEM_PROMPT = `You have access to the codebase_search tool that performs semantic code search.\n\nWhen searching:\n- Use natural language queries describing what you're looking for\n- Be specific about functionality, not variable names\n- Use target_directories to narrow search if you know the area\n- Results are ranked by relevance (rerank score is most important)\n\nThe tool returns:\n- File paths with symbol names (e.g. \"src/auth.ts::AuthService@L1-L17\")\n- Line ranges for precise navigation\n- Full code content for each match\n- Dual relevance scores: embedding similarity + rerank score\n\nUse results to understand code or answer questions. The content is provided in full - avoid re-reading unless you need more context.`;\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,gBAAqB;AACrB,iBAAkB;;;ACQlB,IAAM,uBAA+D;AAAA,EACnE,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,iBAAiB,CAAC,gBAAgB,aAAa,WAAW;AAC5D;AAmBA,eAAsB,eACpB,KACA,SACA,cAA2B,CAAC,GACT;AACnB,QAAM;AAAA,IACJ,aAAa,qBAAqB;AAAA,IAClC,eAAe,qBAAqB;AAAA,IACpC,WAAW,qBAAqB;AAAA,IAChC,oBAAoB,qBAAqB;AAAA,IAC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MAAM,aAAE,OAAO,CAAC,EAAE,SAAS,uHAAuH;AAAA,IACxK,aAAa,aAAE,OAAO,EAAE,SAAS,iGAAiG;AAAA,IAClI,OAAO,aAAE,OAAO,EAAE,SAAS,EAAE,SAAS,qCAAqC;AAAA,EAC7E,CAAC;AAED,aAAO,gBAAK;AAAA,IACV,aAAa;AAAA,IACb,aAAa;AAAA,IACb,SAAS,OAAO,WAAW;AACzB,YAAM,EAAE,OAAO,oBAAoB,aAAa,MAAM,IAAI;AAC1D,YAAM,SAAS,MAAM;AAAA,QACnB,EAAE,OAAO,oBAAoB,aAAa,MAAM;AAAA,QAChD;AAAA,MACF;AAEA,UAAI,CAAC,OAAO,SAAS;AACnB,eAAO;AAAA,UACL,OAAO,OAAO;AAAA,UACd,SAAS,CAAC;AAAA,QACZ;AAAA,MACF;AAGA,aAAO;AAAA,QACL,OAAO,OAAO,QAAQ;AAAA,QACtB,YAAY,GAAG,OAAO,MAAM,YAAY;AAAA,QACxC,SAAS,OAAO,QAAQ,IAAI,QAAM;AAAA,UAChC,MAAM,EAAE;AAAA,UACR,QAAQ,EAAE;AAAA,UACV,OAAO,GAAG,EAAE,SAAS,IAAI,EAAE,OAAO;AAAA,UAClC,UAAU,EAAE;AAAA,UACZ,WAAW,IAAI,EAAE,cAAc,KAAK,QAAQ,CAAC,CAAC;AAAA,UAC9C,MAAM,EAAE;AAAA,QACV,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAKO,SAAS,kBAA0B;AACxC,SAAO;AACT;AAKA,IAAO,iBAAQ,EAAE,0BAA0B,gBAAgB;","names":[]}
@@ -2,9 +2,9 @@ import {
2
2
  createCodebaseSearchTool,
3
3
  getSystemPrompt,
4
4
  vercel_default
5
- } from "../../chunk-YVGRWE7D.js";
5
+ } from "../../chunk-Y2IY7NYY.js";
6
6
  import "../../chunk-YQMPVJ2L.js";
7
- import "../../chunk-VJK4PH5V.js";
7
+ import "../../chunk-AG3ICTC5.js";
8
8
  import "../../chunk-4VWJFZVS.js";
9
9
  import "../../chunk-PZ5AY32C.js";
10
10
  export {
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // tools/warp_grep/agent/config.ts
21
+ var config_exports = {};
22
+ __export(config_exports, {
23
+ AGENT_CONFIG: () => AGENT_CONFIG,
24
+ DEFAULT_EXCLUDES: () => DEFAULT_EXCLUDES,
25
+ DEFAULT_MODEL: () => DEFAULT_MODEL
26
+ });
27
+ module.exports = __toCommonJS(config_exports);
28
+ var AGENT_CONFIG = {
29
+ // Give the model freedom; failsafe cap to prevent infinite loops
30
+ MAX_ROUNDS: 10,
31
+ TIMEOUT_MS: 3e4
32
+ };
33
+ var DEFAULT_EXCLUDES = (process.env.MORPH_WARP_GREP_EXCLUDE || "").split(",").map((s) => s.trim()).filter(Boolean).concat(["node_modules", ".git", "dist", "build", ".cache", "venv", "target"]);
34
+ var DEFAULT_MODEL = "morph-warp-grep";
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ AGENT_CONFIG,
38
+ DEFAULT_EXCLUDES,
39
+ DEFAULT_MODEL
40
+ });
41
+ //# sourceMappingURL=config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../tools/warp_grep/agent/config.ts"],"sourcesContent":["// Agent configuration defaults for morph-warp-grep\n// Hard-coded: SDK does not expose control over rounds or timeout.\nexport const AGENT_CONFIG = {\n // Give the model freedom; failsafe cap to prevent infinite loops\n MAX_ROUNDS: 10,\n TIMEOUT_MS: 30000,\n};\n\nexport const DEFAULT_EXCLUDES = (process.env.MORPH_WARP_GREP_EXCLUDE || '')\n .split(',')\n .map(s => s.trim())\n .filter(Boolean)\n .concat(['node_modules', '.git', 'dist', 'build', '.cache', 'venv', 'target']);\n\nexport const DEFAULT_MODEL = 'morph-warp-grep';\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAM,eAAe;AAAA;AAAA,EAE1B,YAAY;AAAA,EACZ,YAAY;AACd;AAEO,IAAM,oBAAoB,QAAQ,IAAI,2BAA2B,IACrE,MAAM,GAAG,EACT,IAAI,OAAK,EAAE,KAAK,CAAC,EACjB,OAAO,OAAO,EACd,OAAO,CAAC,gBAAgB,QAAQ,QAAQ,SAAS,UAAU,QAAQ,QAAQ,CAAC;AAExE,IAAM,gBAAgB;","names":[]}
@@ -0,0 +1,12 @@
1
+ import {
2
+ AGENT_CONFIG,
3
+ DEFAULT_EXCLUDES,
4
+ DEFAULT_MODEL
5
+ } from "../../../chunk-AFEPUNAO.js";
6
+ import "../../../chunk-PZ5AY32C.js";
7
+ export {
8
+ AGENT_CONFIG,
9
+ DEFAULT_EXCLUDES,
10
+ DEFAULT_MODEL
11
+ };
12
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // tools/warp_grep/agent/formatter.ts
21
+ var formatter_exports = {};
22
+ __export(formatter_exports, {
23
+ ToolOutputFormatter: () => ToolOutputFormatter,
24
+ formatAgentToolOutput: () => formatAgentToolOutput
25
+ });
26
+ module.exports = __toCommonJS(formatter_exports);
27
+ var ToolOutputFormatter = class {
28
+ format(toolName, args, output, options = {}) {
29
+ const name = (toolName ?? "").trim();
30
+ if (!name) {
31
+ return "";
32
+ }
33
+ const payload = output?.toString?.()?.trim?.() ?? "";
34
+ const isError = Boolean(options.isError);
35
+ const safeArgs = args ?? {};
36
+ if (!payload && !isError) {
37
+ return "";
38
+ }
39
+ switch (name) {
40
+ case "read":
41
+ return this.formatRead(safeArgs, payload, isError);
42
+ case "analyse":
43
+ return this.formatAnalyse(safeArgs, payload, isError);
44
+ case "grep":
45
+ return this.formatGrep(safeArgs, payload, isError);
46
+ default:
47
+ return payload ? `<tool_output>
48
+ ${payload}
49
+ </tool_output>` : "";
50
+ }
51
+ }
52
+ formatRead(args, payload, isError) {
53
+ if (isError) {
54
+ return payload;
55
+ }
56
+ const path = this.asString(args.path) || "...";
57
+ return `<file path="${path}">
58
+ ${payload}
59
+ </file>`;
60
+ }
61
+ formatAnalyse(args, payload, isError) {
62
+ const path = this.asString(args.path) || ".";
63
+ if (isError) {
64
+ return `<analyse_results path="${path}" status="error">
65
+ ${payload}
66
+ </analyse_results>`;
67
+ }
68
+ return `<analyse_results path="${path}">
69
+ ${payload}
70
+ </analyse_results>`;
71
+ }
72
+ formatGrep(args, payload, isError) {
73
+ const pattern = this.asString(args.pattern);
74
+ const path = this.asString(args.path);
75
+ const attributes = [];
76
+ if (pattern !== void 0) {
77
+ attributes.push(`pattern="${pattern}"`);
78
+ }
79
+ if (path !== void 0) {
80
+ attributes.push(`path="${path}"`);
81
+ }
82
+ if (isError) {
83
+ attributes.push('status="error"');
84
+ }
85
+ const attrText = attributes.length ? ` ${attributes.join(" ")}` : "";
86
+ return `<grep_output${attrText}>
87
+ ${payload}
88
+ </grep_output>`;
89
+ }
90
+ asString(value) {
91
+ if (value === null || value === void 0) {
92
+ return void 0;
93
+ }
94
+ return String(value);
95
+ }
96
+ };
97
+ var sharedFormatter = new ToolOutputFormatter();
98
+ function formatAgentToolOutput(toolName, args, output, options = {}) {
99
+ return sharedFormatter.format(toolName, args, output, options);
100
+ }
101
+ // Annotate the CommonJS export names for ESM import in node:
102
+ 0 && (module.exports = {
103
+ ToolOutputFormatter,
104
+ formatAgentToolOutput
105
+ });
106
+ //# sourceMappingURL=formatter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../tools/warp_grep/agent/formatter.ts"],"sourcesContent":["export class ToolOutputFormatter {\n\tformat(\n\t\ttoolName: string,\n\t\targs: Record<string, unknown> | null | undefined,\n\t\toutput: string,\n\t\toptions: { isError?: boolean } = {}\n\t): string {\n\t\tconst name = (toolName ?? \"\").trim();\n\t\tif (!name) {\n\t\t\treturn \"\";\n\t\t}\n\t\tconst payload = (output as any)?.toString?.()?.trim?.() ?? \"\";\n\t\tconst isError = Boolean(options.isError);\n\t\tconst safeArgs = args ?? {};\n\n\t\tif (!payload && !isError) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\tswitch (name) {\n\t\t\tcase \"read\":\n\t\t\t\treturn this.formatRead(safeArgs, payload, isError);\n\t\t\tcase \"analyse\":\n\t\t\t\treturn this.formatAnalyse(safeArgs, payload, isError);\n\t\t\tcase \"grep\":\n\t\t\t\treturn this.formatGrep(safeArgs, payload, isError);\n\t\t\tdefault:\n\t\t\t\treturn payload ? `<tool_output>\\n${payload}\\n</tool_output>` : \"\";\n\t\t}\n\t}\n\n\tprivate formatRead(args: Record<string, unknown>, payload: string, isError: boolean): string {\n\t\tif (isError) {\n\t\t\treturn payload;\n\t\t}\n\t\tconst path = this.asString(args.path) || \"...\";\n\t\treturn `<file path=\"${path}\">\\n${payload}\\n</file>`;\n\t}\n\n\tprivate formatAnalyse(args: Record<string, unknown>, payload: string, isError: boolean): string {\n\t\tconst path = this.asString(args.path) || \".\";\n\t\tif (isError) {\n\t\t\treturn `<analyse_results path=\"${path}\" status=\"error\">\\n${payload}\\n</analyse_results>`;\n\t\t}\n\t\treturn `<analyse_results path=\"${path}\">\\n${payload}\\n</analyse_results>`;\n\t}\n\n\tprivate formatGrep(args: Record<string, unknown>, payload: string, isError: boolean): string {\n\t\tconst pattern = this.asString(args.pattern);\n\t\tconst path = this.asString(args.path);\n\t\tconst attributes: string[] = [];\n\t\tif (pattern !== undefined) {\n\t\t\tattributes.push(`pattern=\"${pattern}\"`);\n\t\t}\n\t\tif (path !== undefined) {\n\t\t\tattributes.push(`path=\"${path}\"`);\n\t\t}\n\t\tif (isError) {\n\t\t\tattributes.push('status=\"error\"');\n\t\t}\n\t\tconst attrText = attributes.length ? ` ${attributes.join(\" \")}` : \"\";\n\t\treturn `<grep_output${attrText}>\\n${payload}\\n</grep_output>`;\n\t}\n\n\tprivate asString(value: unknown): string | undefined {\n\t\tif (value === null || value === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn String(value);\n\t}\n}\n\nconst sharedFormatter = new ToolOutputFormatter();\n\nexport function formatAgentToolOutput(\n\ttoolName: string,\n\targs: Record<string, unknown> | null | undefined,\n\toutput: string,\n\toptions: { isError?: boolean } = {}\n): string {\n\treturn sharedFormatter.format(toolName, args, output, options);\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AA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,QAAI,YAAY,QAAW;AAC1B,iBAAW,KAAK,YAAY,OAAO,GAAG;AAAA,IACvC;AACA,QAAI,SAAS,QAAW;AACvB,iBAAW,KAAK,SAAS,IAAI,GAAG;AAAA,IACjC;AACA,QAAI,SAAS;AACZ,iBAAW,KAAK,gBAAgB;AAAA,IACjC;AACA,UAAM,WAAW,WAAW,SAAS,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK;AAClE,WAAO,eAAe,QAAQ;AAAA,EAAM,OAAO;AAAA;AAAA,EAC5C;AAAA,EAEQ,SAAS,OAAoC;AACpD,QAAI,UAAU,QAAQ,UAAU,QAAW;AAC1C,aAAO;AAAA,IACR;AACA,WAAO,OAAO,KAAK;AAAA,EACpB;AACD;AAEA,IAAM,kBAAkB,IAAI,oBAAoB;AAEzC,SAAS,sBACf,UACA,MACA,QACA,UAAiC,CAAC,GACzB;AACT,SAAO,gBAAgB,OAAO,UAAU,MAAM,QAAQ,OAAO;AAC9D;","names":[]}
@@ -0,0 +1,10 @@
1
+ import {
2
+ ToolOutputFormatter,
3
+ formatAgentToolOutput
4
+ } from "../../../chunk-TICMYDII.js";
5
+ import "../../../chunk-PZ5AY32C.js";
6
+ export {
7
+ ToolOutputFormatter,
8
+ formatAgentToolOutput
9
+ };
10
+ //# sourceMappingURL=formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // tools/warp_grep/agent/grep_helpers.ts
21
+ var grep_helpers_exports = {};
22
+ __export(grep_helpers_exports, {
23
+ GrepState: () => GrepState,
24
+ MAX_GREP_OUTPUT_CHARS_PER_TURN: () => MAX_GREP_OUTPUT_CHARS_PER_TURN,
25
+ formatTurnGrepOutput: () => formatTurnGrepOutput,
26
+ parseAndFilterGrepOutput: () => parseAndFilterGrepOutput
27
+ });
28
+ module.exports = __toCommonJS(grep_helpers_exports);
29
+ var GrepState = class {
30
+ seenLines = /* @__PURE__ */ new Set();
31
+ isNew(path, lineNumber) {
32
+ const key = this.makeKey(path, lineNumber);
33
+ return !this.seenLines.has(key);
34
+ }
35
+ add(path, lineNumber) {
36
+ this.seenLines.add(this.makeKey(path, lineNumber));
37
+ }
38
+ makeKey(path, lineNumber) {
39
+ return `${path}:${lineNumber}`;
40
+ }
41
+ };
42
+ var MAX_GREP_OUTPUT_CHARS_PER_TURN = 6e4;
43
+ function extractMatchFields(payload) {
44
+ const text = payload.replace(/\r?\n$/, "");
45
+ if (!text || text.startsWith("[error]")) {
46
+ return null;
47
+ }
48
+ const firstSep = text.indexOf(":");
49
+ if (firstSep === -1) {
50
+ return null;
51
+ }
52
+ let filePath = text.slice(0, firstSep).trim();
53
+ if (!filePath) {
54
+ return null;
55
+ }
56
+ if (filePath.startsWith("./") || filePath.startsWith(".\\")) {
57
+ filePath = filePath.slice(2);
58
+ }
59
+ const remainder = text.slice(firstSep + 1);
60
+ const secondSep = remainder.indexOf(":");
61
+ if (secondSep === -1) {
62
+ return null;
63
+ }
64
+ const linePart = remainder.slice(0, secondSep);
65
+ const lineNumber = Number.parseInt(linePart, 10);
66
+ if (!Number.isInteger(lineNumber) || lineNumber <= 0) {
67
+ return null;
68
+ }
69
+ let contentSegment = remainder.slice(secondSep + 1);
70
+ const columnSep = contentSegment.indexOf(":");
71
+ if (columnSep !== -1 && /^\d+$/.test(contentSegment.slice(0, columnSep))) {
72
+ contentSegment = contentSegment.slice(columnSep + 1);
73
+ }
74
+ const content = contentSegment.trim();
75
+ if (!content) {
76
+ return null;
77
+ }
78
+ return { path: filePath, lineNumber, content };
79
+ }
80
+ function parseAndFilterGrepOutput(rawOutput, state) {
81
+ const matches = [];
82
+ if (typeof rawOutput !== "string" || !rawOutput.trim()) {
83
+ return matches;
84
+ }
85
+ for (const line of rawOutput.split(/\r?\n/)) {
86
+ const fields = extractMatchFields(line);
87
+ if (!fields) {
88
+ continue;
89
+ }
90
+ if (state.isNew(fields.path, fields.lineNumber)) {
91
+ matches.push(fields);
92
+ state.add(fields.path, fields.lineNumber);
93
+ }
94
+ }
95
+ return matches;
96
+ }
97
+ function truncateOutput(payload, maxChars) {
98
+ if (payload.length <= maxChars) {
99
+ return payload;
100
+ }
101
+ const note = "... (output truncated)";
102
+ const available = maxChars - note.length - 1;
103
+ if (available <= 0) {
104
+ return note;
105
+ }
106
+ if (payload.length <= available) {
107
+ return `${payload.slice(0, available).replace(/\n$/, "")}
108
+ ${note}`;
109
+ }
110
+ const core = payload.slice(0, Math.max(0, available - 1));
111
+ const trimmed = core.replace(/\n$/, "").replace(/\s+$/, "");
112
+ const snippet = trimmed ? `${trimmed}\u2026` : "\u2026";
113
+ return `${snippet}
114
+ ${note}`;
115
+ }
116
+ function formatTurnGrepOutput(matches, maxChars = MAX_GREP_OUTPUT_CHARS_PER_TURN) {
117
+ if (!matches || matches.length === 0) {
118
+ return "No new matches found.";
119
+ }
120
+ const matchesByFile = /* @__PURE__ */ new Map();
121
+ for (const match of matches) {
122
+ if (!matchesByFile.has(match.path)) {
123
+ matchesByFile.set(match.path, []);
124
+ }
125
+ matchesByFile.get(match.path).push(match);
126
+ }
127
+ const lines = [];
128
+ const sortedPaths = Array.from(matchesByFile.keys()).sort();
129
+ sortedPaths.forEach((filePath, index) => {
130
+ if (index > 0) {
131
+ lines.push("");
132
+ }
133
+ lines.push(filePath);
134
+ const sortedMatches = matchesByFile.get(filePath).slice().sort((a, b) => a.lineNumber - b.lineNumber);
135
+ for (const match of sortedMatches) {
136
+ lines.push(`${match.lineNumber}:${match.content}`);
137
+ }
138
+ });
139
+ return truncateOutput(lines.join("\n"), maxChars);
140
+ }
141
+ // Annotate the CommonJS export names for ESM import in node:
142
+ 0 && (module.exports = {
143
+ GrepState,
144
+ MAX_GREP_OUTPUT_CHARS_PER_TURN,
145
+ formatTurnGrepOutput,
146
+ parseAndFilterGrepOutput
147
+ });
148
+ //# sourceMappingURL=grep_helpers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../tools/warp_grep/agent/grep_helpers.ts"],"sourcesContent":["export interface GrepMatch {\n\tpath: string;\n\tlineNumber: number;\n\tcontent: string;\n}\n\nexport class GrepState {\n\tprivate readonly seenLines = new Set<string>();\n\n\tisNew(path: string, lineNumber: number): boolean {\n\t\tconst key = this.makeKey(path, lineNumber);\n\t\treturn !this.seenLines.has(key);\n\t}\n\n\tadd(path: string, lineNumber: number): void {\n\t\tthis.seenLines.add(this.makeKey(path, lineNumber));\n\t}\n\n\tprivate makeKey(path: string, lineNumber: number): string {\n\t\treturn `${path}:${lineNumber}`;\n\t}\n}\n\nexport const MAX_GREP_OUTPUT_CHARS_PER_TURN = 60_000;\n\nfunction extractMatchFields(payload: string): GrepMatch | null {\n\tconst text = payload.replace(/\\r?\\n$/, \"\");\n\tif (!text || text.startsWith(\"[error]\")) {\n\t\treturn null;\n\t}\n\n\tconst firstSep = text.indexOf(\":\");\n\tif (firstSep === -1) {\n\t\treturn null;\n\t}\n\tlet filePath = text.slice(0, firstSep).trim();\n\tif (!filePath) {\n\t\treturn null;\n\t}\n\tif (filePath.startsWith(\"./\") || filePath.startsWith(\".\\\\\")) {\n\t\tfilePath = filePath.slice(2);\n\t}\n\n\tconst remainder = text.slice(firstSep + 1);\n\tconst secondSep = remainder.indexOf(\":\");\n\tif (secondSep === -1) {\n\t\treturn null;\n\t}\n\n\tconst linePart = remainder.slice(0, secondSep);\n\tconst lineNumber = Number.parseInt(linePart, 10);\n\tif (!Number.isInteger(lineNumber) || lineNumber <= 0) {\n\t\treturn null;\n\t}\n\n\tlet contentSegment = remainder.slice(secondSep + 1);\n\tconst columnSep = contentSegment.indexOf(\":\");\n\tif (columnSep !== -1 && /^\\d+$/.test(contentSegment.slice(0, columnSep))) {\n\t\tcontentSegment = contentSegment.slice(columnSep + 1);\n\t}\n\n\tconst content = contentSegment.trim();\n\tif (!content) {\n\t\treturn null;\n\t}\n\n\treturn { path: filePath, lineNumber, content };\n}\n\nexport function parseAndFilterGrepOutput(rawOutput: string, state: GrepState): GrepMatch[] {\n\tconst matches: GrepMatch[] = [];\n\tif (typeof rawOutput !== \"string\" || !rawOutput.trim()) {\n\t\treturn matches;\n\t}\n\n\tfor (const line of rawOutput.split(/\\r?\\n/)) {\n\t\tconst fields = extractMatchFields(line);\n\t\tif (!fields) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (state.isNew(fields.path, fields.lineNumber)) {\n\t\t\tmatches.push(fields);\n\t\t\tstate.add(fields.path, fields.lineNumber);\n\t\t}\n\t}\n\n\treturn matches;\n}\n\nfunction truncateOutput(payload: string, maxChars: number): string {\n\tif (payload.length <= maxChars) {\n\t\treturn payload;\n\t}\n\n\tconst note = \"... (output truncated)\";\n\tconst available = maxChars - note.length - 1;\n\tif (available <= 0) {\n\t\treturn note;\n\t}\n\n\tif (payload.length <= available) {\n\t\treturn `${payload.slice(0, available).replace(/\\n$/, \"\")}\\n${note}`;\n\t}\n\n\tconst core = payload.slice(0, Math.max(0, available - 1));\n\tconst trimmed = core.replace(/\\n$/, \"\").replace(/\\s+$/, \"\");\n\tconst snippet = trimmed ? `${trimmed}…` : \"…\";\n\treturn `${snippet}\\n${note}`;\n}\n\nexport function formatTurnGrepOutput(\n\tmatches: GrepMatch[],\n\tmaxChars: number = MAX_GREP_OUTPUT_CHARS_PER_TURN\n): string {\n\tif (!matches || matches.length === 0) {\n\t\treturn \"No new matches found.\";\n\t}\n\n\tconst matchesByFile = new Map<string, GrepMatch[]>();\n\tfor (const match of matches) {\n\t\tif (!matchesByFile.has(match.path)) {\n\t\t\tmatchesByFile.set(match.path, []);\n\t\t}\n\t\tmatchesByFile.get(match.path)!.push(match);\n\t}\n\n\tconst lines: string[] = [];\n\tconst sortedPaths = Array.from(matchesByFile.keys()).sort();\n\tsortedPaths.forEach((filePath, index) => {\n\t\tif (index > 0) {\n\t\t\tlines.push(\"\");\n\t\t}\n\t\tlines.push(filePath);\n\t\tconst sortedMatches = matchesByFile\n\t\t\t.get(filePath)!\n\t\t\t.slice()\n\t\t\t.sort((a, b) => a.lineNumber - b.lineNumber);\n\t\tfor (const match of sortedMatches) {\n\t\t\tlines.push(`${match.lineNumber}:${match.content}`);\n\t\t}\n\t});\n\n\treturn truncateOutput(lines.join(\"\\n\"), maxChars);\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,IAAM,YAAN,MAAgB;AAAA,EACL,YAAY,oBAAI,IAAY;AAAA,EAE7C,MAAM,MAAc,YAA6B;AAChD,UAAM,MAAM,KAAK,QAAQ,MAAM,UAAU;AACzC,WAAO,CAAC,KAAK,UAAU,IAAI,GAAG;AAAA,EAC/B;AAAA,EAEA,IAAI,MAAc,YAA0B;AAC3C,SAAK,UAAU,IAAI,KAAK,QAAQ,MAAM,UAAU,CAAC;AAAA,EAClD;AAAA,EAEQ,QAAQ,MAAc,YAA4B;AACzD,WAAO,GAAG,IAAI,IAAI,UAAU;AAAA,EAC7B;AACD;AAEO,IAAM,iCAAiC;AAE9C,SAAS,mBAAmB,SAAmC;AAC9D,QAAM,OAAO,QAAQ,QAAQ,UAAU,EAAE;AACzC,MAAI,CAAC,QAAQ,KAAK,W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;AACnB,UAAM,gBAAgB,cACpB,IAAI,QAAQ,EACZ,MAAM,EACN,KAAK,CAAC,GAAG,MAAM,EAAE,aAAa,EAAE,UAAU;AAC5C,eAAW,SAAS,eAAe;AAClC,YAAM,KAAK,GAAG,MAAM,UAAU,IAAI,MAAM,OAAO,EAAE;AAAA,IAClD;AAAA,EACD,CAAC;AAED,SAAO,eAAe,MAAM,KAAK,IAAI,GAAG,QAAQ;AACjD;","names":[]}
@@ -0,0 +1,14 @@
1
+ import {
2
+ GrepState,
3
+ MAX_GREP_OUTPUT_CHARS_PER_TURN,
4
+ formatTurnGrepOutput,
5
+ parseAndFilterGrepOutput
6
+ } from "../../../chunk-NDZO5IPV.js";
7
+ import "../../../chunk-PZ5AY32C.js";
8
+ export {
9
+ GrepState,
10
+ MAX_GREP_OUTPUT_CHARS_PER_TURN,
11
+ formatTurnGrepOutput,
12
+ parseAndFilterGrepOutput
13
+ };
14
+ //# sourceMappingURL=grep_helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // tools/warp_grep/agent/parser.ts
21
+ var parser_exports = {};
22
+ __export(parser_exports, {
23
+ LLMResponseParseError: () => LLMResponseParseError,
24
+ LLMResponseParser: () => LLMResponseParser
25
+ });
26
+ module.exports = __toCommonJS(parser_exports);
27
+ var LLMResponseParseError = class extends Error {
28
+ constructor(message) {
29
+ super(message);
30
+ this.name = "LLMResponseParseError";
31
+ }
32
+ };
33
+ var LLMResponseParser = class {
34
+ finishSpecSplitRe = /,(?=[^,\s]+:)/;
35
+ parse(text) {
36
+ if (typeof text !== "string") {
37
+ throw new TypeError("Command text must be a string.");
38
+ }
39
+ const lines = text.split(/\r?\n/).map((l) => l.trim());
40
+ const commands = [];
41
+ let finishAccumulator = null;
42
+ lines.forEach((line, idx) => {
43
+ if (!line || line.startsWith("#")) return;
44
+ const ctx = { lineNumber: idx + 1, raw: line };
45
+ const parts = this.splitLine(line, ctx);
46
+ if (parts.length === 0) return;
47
+ const cmd = parts[0];
48
+ switch (cmd) {
49
+ case "analyse":
50
+ this.handleAnalyse(parts, ctx, commands);
51
+ break;
52
+ case "grep":
53
+ this.handleGrep(parts, ctx, commands);
54
+ break;
55
+ case "read":
56
+ this.handleRead(parts, ctx, commands);
57
+ break;
58
+ case "finish":
59
+ finishAccumulator = this.handleFinish(parts, ctx, finishAccumulator);
60
+ break;
61
+ default:
62
+ throw new LLMResponseParseError(`Line ${ctx.lineNumber}: Unsupported command '${cmd}'`);
63
+ }
64
+ });
65
+ if (finishAccumulator) {
66
+ const map = finishAccumulator;
67
+ const entries = [...map.entries()];
68
+ const filesPayload = entries.map(([path, ranges]) => ({
69
+ path,
70
+ lines: [...ranges].sort((a, b) => a[0] - b[0])
71
+ }));
72
+ commands.push({ name: "finish", arguments: { files: filesPayload } });
73
+ }
74
+ return commands;
75
+ }
76
+ splitLine(line, ctx) {
77
+ try {
78
+ const parts = [];
79
+ let current = "";
80
+ let inSingle = false;
81
+ for (let i = 0; i < line.length; i++) {
82
+ const ch = line[i];
83
+ if (ch === "'" && line[i - 1] !== "\\") {
84
+ inSingle = !inSingle;
85
+ current += ch;
86
+ } else if (!inSingle && /\s/.test(ch)) {
87
+ if (current) {
88
+ parts.push(current);
89
+ current = "";
90
+ }
91
+ } else {
92
+ current += ch;
93
+ }
94
+ }
95
+ if (current) parts.push(current);
96
+ return parts;
97
+ } catch {
98
+ throw new LLMResponseParseError(`Line ${ctx.lineNumber}: Unable to parse line.`);
99
+ }
100
+ }
101
+ handleAnalyse(parts, ctx, commands) {
102
+ if (parts.length < 2) {
103
+ throw new LLMResponseParseError(`Line ${ctx.lineNumber}: analyse requires <path>`);
104
+ }
105
+ const path = parts[1];
106
+ const pattern = parts[2]?.replace(/^"|"$/g, "") ?? null;
107
+ commands.push({ name: "analyse", arguments: { path, pattern } });
108
+ }
109
+ // no glob tool in MCP
110
+ handleGrep(parts, ctx, commands) {
111
+ if (parts.length < 3) {
112
+ throw new LLMResponseParseError(`Line ${ctx.lineNumber}: grep requires '<pattern>' and <path>`);
113
+ }
114
+ const pat = parts[1];
115
+ if (!pat.startsWith("'") || !pat.endsWith("'")) {
116
+ throw new LLMResponseParseError(`Line ${ctx.lineNumber}: grep pattern must be single-quoted`);
117
+ }
118
+ commands.push({ name: "grep", arguments: { pattern: pat.slice(1, -1), path: parts[2] } });
119
+ }
120
+ handleRead(parts, ctx, commands) {
121
+ if (parts.length < 2) {
122
+ throw new LLMResponseParseError(`Line ${ctx.lineNumber}: read requires <path> or <path>:<start-end>`);
123
+ }
124
+ const spec = parts[1];
125
+ const rangeIdx = spec.indexOf(":");
126
+ if (rangeIdx === -1) {
127
+ commands.push({ name: "read", arguments: { path: spec } });
128
+ return;
129
+ }
130
+ const path = spec.slice(0, rangeIdx);
131
+ const range = spec.slice(rangeIdx + 1);
132
+ const [s, e] = range.split("-").map((v) => parseInt(v, 10));
133
+ if (!Number.isFinite(s) || !Number.isFinite(e)) {
134
+ throw new LLMResponseParseError(`Line ${ctx.lineNumber}: invalid read range '${range}'`);
135
+ }
136
+ commands.push({ name: "read", arguments: { path, start: s, end: e } });
137
+ }
138
+ handleFinish(parts, ctx, acc) {
139
+ const map = acc ?? /* @__PURE__ */ new Map();
140
+ const args = parts.slice(1);
141
+ for (const token of args) {
142
+ const [path, rangesText] = token.split(":", 2);
143
+ if (!path || !rangesText) {
144
+ throw new LLMResponseParseError(`Line ${ctx.lineNumber}: invalid finish token '${token}'`);
145
+ }
146
+ const rangeSpecs = rangesText.split(",").filter(Boolean);
147
+ for (const spec of rangeSpecs) {
148
+ const [s, e] = spec.split("-").map((v) => parseInt(v, 10));
149
+ if (!Number.isFinite(s) || !Number.isFinite(e) || e < s) {
150
+ throw new LLMResponseParseError(`Line ${ctx.lineNumber}: invalid range '${spec}'`);
151
+ }
152
+ const arr = map.get(path) ?? [];
153
+ arr.push([s, e]);
154
+ map.set(path, arr);
155
+ }
156
+ }
157
+ return map;
158
+ }
159
+ };
160
+ // Annotate the CommonJS export names for ESM import in node:
161
+ 0 && (module.exports = {
162
+ LLMResponseParseError,
163
+ LLMResponseParser
164
+ });
165
+ //# sourceMappingURL=parser.cjs.map